@shopify/react-native-skia 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/android/CMakeLists.txt +4 -8
  2. package/android/build.gradle +9 -2
  3. package/android/cpp/jni/JniPlatformContext.cpp +7 -7
  4. package/android/cpp/jni/JniSkiaManager.cpp +1 -1
  5. package/android/cpp/jni/include/JniSkiaBaseView.h +2 -2
  6. package/android/cpp/jni/include/JniSkiaDomView.h +4 -4
  7. package/android/cpp/jni/include/JniSkiaManager.h +4 -4
  8. package/android/cpp/jni/include/JniSkiaPictureView.h +4 -4
  9. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +245 -0
  10. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +33 -0
  11. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +3 -3
  12. package/android/cpp/rnskia-android/RNSkAndroidView.h +1 -1
  13. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +2 -2
  14. package/android/cpp/rnskia-android/SkiaOpenGLHelper.h +4 -4
  15. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +32 -2
  16. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +7 -4
  17. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +16 -1
  18. package/cpp/api/JsiSkAnimatedImage.h +1 -1
  19. package/cpp/api/JsiSkCanvas.h +8 -8
  20. package/cpp/api/JsiSkColor.h +1 -1
  21. package/cpp/api/JsiSkColorFilter.h +1 -1
  22. package/cpp/api/JsiSkColorFilterFactory.h +2 -2
  23. package/cpp/api/JsiSkContourMeasure.h +1 -1
  24. package/cpp/api/JsiSkContourMeasureIter.h +1 -1
  25. package/cpp/api/JsiSkData.h +2 -2
  26. package/cpp/api/JsiSkFont.h +2 -2
  27. package/cpp/api/JsiSkFontMgr.h +1 -1
  28. package/cpp/api/JsiSkFontMgrFactory.h +1 -1
  29. package/cpp/api/JsiSkFontStyle.h +2 -2
  30. package/cpp/api/JsiSkImage.h +2 -2
  31. package/cpp/api/JsiSkImageFilter.h +1 -1
  32. package/cpp/api/JsiSkImageFilterFactory.h +1 -1
  33. package/cpp/api/JsiSkImageInfo.h +1 -1
  34. package/cpp/api/JsiSkMaskFilter.h +1 -1
  35. package/cpp/api/JsiSkMaskFilterFactory.h +1 -1
  36. package/cpp/api/JsiSkMatrix.h +1 -1
  37. package/cpp/api/JsiSkPaint.h +1 -1
  38. package/cpp/api/JsiSkParagraph.h +7 -7
  39. package/cpp/api/JsiSkParagraphBuilder.h +9 -9
  40. package/cpp/api/JsiSkParagraphBuilderFactory.h +4 -4
  41. package/cpp/api/JsiSkParagraphStyle.h +3 -3
  42. package/cpp/api/JsiSkPath.h +11 -11
  43. package/cpp/api/JsiSkPathEffect.h +1 -1
  44. package/cpp/api/JsiSkPathEffectFactory.h +4 -4
  45. package/cpp/api/JsiSkPathFactory.h +2 -2
  46. package/cpp/api/JsiSkPicture.h +1 -1
  47. package/cpp/api/JsiSkPictureFactory.h +2 -2
  48. package/cpp/api/JsiSkPictureRecorder.h +2 -2
  49. package/cpp/api/JsiSkPoint.h +1 -1
  50. package/cpp/api/JsiSkRRect.h +1 -1
  51. package/cpp/api/JsiSkRSXform.h +1 -1
  52. package/cpp/api/JsiSkRect.h +1 -1
  53. package/cpp/api/JsiSkRuntimeEffect.h +1 -1
  54. package/cpp/api/JsiSkRuntimeShaderBuilder.h +1 -1
  55. package/cpp/api/JsiSkSVGFactory.h +1 -1
  56. package/cpp/api/JsiSkShader.h +2 -2
  57. package/cpp/api/JsiSkShaderFactory.h +3 -3
  58. package/cpp/api/JsiSkStrutStyle.h +1 -1
  59. package/cpp/api/JsiSkSurface.h +1 -1
  60. package/cpp/api/JsiSkSurfaceFactory.h +1 -1
  61. package/cpp/api/JsiSkTextBlob.h +1 -1
  62. package/cpp/api/JsiSkTextBlobFactory.h +1 -1
  63. package/cpp/api/JsiSkTextStyle.h +2 -2
  64. package/cpp/api/JsiSkTypeface.h +3 -3
  65. package/cpp/api/JsiSkTypefaceFontProvider.h +2 -2
  66. package/cpp/api/JsiSkVertices.h +1 -1
  67. package/cpp/jsi/JsiHostObject.cpp +1 -1
  68. package/cpp/rnskia/RNSkDomView.cpp +1 -1
  69. package/cpp/rnskia/RNSkDomView.h +3 -3
  70. package/cpp/rnskia/RNSkManager.cpp +5 -5
  71. package/cpp/rnskia/RNSkPictureView.h +3 -3
  72. package/cpp/rnskia/RNSkPlatformContext.h +5 -5
  73. package/cpp/rnskia/RNSkView.h +2 -2
  74. package/cpp/rnskia/dom/base/ConcatablePaint.h +6 -6
  75. package/cpp/rnskia/dom/base/Declaration.h +1 -1
  76. package/cpp/rnskia/dom/base/DeclarationContext.h +7 -7
  77. package/cpp/rnskia/dom/base/DrawingContext.h +3 -3
  78. package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +2 -2
  79. package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +1 -1
  80. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +1 -1
  81. package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +1 -1
  82. package/cpp/rnskia/dom/nodes/JsiPathNode.h +1 -1
  83. package/cpp/rnskia/dom/nodes/JsiPointsNode.h +1 -1
  84. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +1 -1
  85. package/cpp/rnskia/dom/props/BlendModeProp.h +1 -1
  86. package/cpp/rnskia/dom/props/BoxShadowProps.h +1 -1
  87. package/cpp/rnskia/dom/props/CircleProp.h +1 -1
  88. package/cpp/rnskia/dom/props/ClipProp.h +2 -2
  89. package/cpp/rnskia/dom/props/PaintProps.h +1 -1
  90. package/cpp/rnskia/dom/props/PathProp.h +1 -1
  91. package/cpp/rnskia/dom/props/PointProp.h +1 -1
  92. package/cpp/rnskia/dom/props/PointsProp.h +1 -1
  93. package/cpp/rnskia/dom/props/RRectProp.h +2 -2
  94. package/cpp/rnskia/dom/props/RSXformProp.h +1 -1
  95. package/cpp/rnskia/dom/props/RadiusProp.h +1 -1
  96. package/cpp/rnskia/dom/props/RectProp.h +1 -1
  97. package/cpp/rnskia/dom/props/StrokeProps.h +1 -1
  98. package/cpp/rnskia/dom/props/TileModeProp.h +1 -1
  99. package/cpp/rnskia/dom/props/UniformsProp.h +1 -1
  100. package/cpp/rnskia/dom/props/VertexModeProp.h +1 -1
  101. package/cpp/rnskia/dom/props/VerticesProps.h +1 -1
  102. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +1158 -0
  103. package/cpp/utils/RNSkTypedArray.h +1 -1
  104. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +6 -6
  105. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +3 -3
  106. package/ios/RNSkia-iOS/SkiaDomView.mm +7 -7
  107. package/ios/RNSkia-iOS/SkiaDomViewManager.mm +7 -7
  108. package/ios/RNSkia-iOS/SkiaManager.h +1 -1
  109. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +1 -1
  110. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +5 -5
  111. package/ios/RNSkia-iOS/SkiaPictureView.mm +7 -7
  112. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +4 -4
  113. package/ios/RNSkia-iOS/SkiaUIView.h +3 -3
  114. package/ios/RNSkia-iOS/SkiaUIView.mm +2 -2
  115. package/ios/RNSkia-iOS/ViewScreenshotService.h +1 -1
  116. package/ios/RNSkia-iOS/ViewScreenshotService.mm +1 -1
  117. package/lib/commonjs/headless/index.d.ts +4 -1
  118. package/lib/commonjs/headless/index.js +12 -2
  119. package/lib/commonjs/headless/index.js.map +1 -1
  120. package/lib/commonjs/renderer/Offscreen.js +1 -0
  121. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  122. package/lib/commonjs/skia/web/JsiSkImage.d.ts +2 -1
  123. package/lib/commonjs/skia/web/JsiSkImage.js +27 -2
  124. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  125. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +2 -1
  126. package/lib/commonjs/skia/web/JsiSkSurface.js +5 -1
  127. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  128. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +13 -2
  129. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  130. package/lib/module/headless/index.d.ts +4 -1
  131. package/lib/module/headless/index.js +9 -2
  132. package/lib/module/headless/index.js.map +1 -1
  133. package/lib/module/renderer/Offscreen.js +1 -0
  134. package/lib/module/renderer/Offscreen.js.map +1 -1
  135. package/lib/module/skia/web/JsiSkImage.d.ts +2 -1
  136. package/lib/module/skia/web/JsiSkImage.js +27 -2
  137. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  138. package/lib/module/skia/web/JsiSkSurface.d.ts +2 -1
  139. package/lib/module/skia/web/JsiSkSurface.js +5 -1
  140. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  141. package/lib/module/skia/web/JsiSkSurfaceFactory.js +13 -2
  142. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  143. package/lib/typescript/src/headless/index.d.ts +4 -1
  144. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +2 -1
  145. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +2 -1
  146. package/package.json +1 -1
  147. package/src/headless/index.ts +9 -2
  148. package/src/renderer/Offscreen.tsx +1 -0
  149. package/src/skia/web/JsiSkImage.ts +36 -5
  150. package/src/skia/web/JsiSkSurface.ts +8 -1
  151. package/src/skia/web/JsiSkSurfaceFactory.ts +17 -2
@@ -46,6 +46,7 @@ add_library(
46
46
  "${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
47
47
  "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp"
48
48
  "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp"
49
+ "${PROJECT_SOURCE_DIR}/cpp/rnskia-android/GrAHardwareBufferUtils.cpp"
49
50
 
50
51
  "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiHostObject.cpp"
51
52
  "${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiValue.cpp"
@@ -80,14 +81,9 @@ target_include_directories(
80
81
  cpp/jni/include
81
82
  cpp/rnskia-android
82
83
 
83
- ../cpp/skia/include/config/
84
- ../cpp/skia/include/core/
85
- ../cpp/skia/include/effects/
86
- ../cpp/skia/include/utils/
87
- ../cpp/skia/include/pathops/
88
- ../cpp/skia/modules/
89
- ../cpp/skia/modules/skparagraph/include/
90
- ../cpp/skia/include/
84
+ # Skia headers have to be included with "fully"-qualified paths,
85
+ # so "include/core/SkRef.h" instead of "SkRef.h", as otherwise
86
+ # the prefab cannot be shipped.
91
87
  ../cpp/skia
92
88
 
93
89
  ../cpp/api
@@ -161,6 +161,9 @@ android {
161
161
  }
162
162
 
163
163
  sourceSets.main {
164
+ jniLibs {
165
+ srcDirs += ['../libs/android']
166
+ }
164
167
  java {
165
168
  if (!isNewArchitectureEnabled()) {
166
169
  srcDirs += [
@@ -309,16 +312,20 @@ extractJNIFiles.mustRunAfter extractAARHeaders
309
312
  if (ENABLE_PREFAB) {
310
313
  // Package all the cpp code in a flattened directory structure
311
314
  task prepareHeaders(type: Copy) {
315
+ from("../cpp")
312
316
  from("./cpp")
313
- into "${project.buildDir}/headers/rnskia/"
317
+ into "${project.buildDir}/headers/rnskia/react-native-skia"
314
318
  includeEmptyDirs = false
315
319
  include "**/*.h"
316
320
  eachFile {
317
321
  String path = it.path
318
322
 
319
- // Skip flattening third_party dir
320
323
  if (path.contains("api/third_party")) {
324
+ // Skip flattening third_party dir
321
325
  path = path.substring("api/".length())
326
+ } else if (path.contains("skia/include") || path.contains("skia/modules") || path.contains("skia/src")) {
327
+ // Skip flattening Skia dir
328
+ path = path.substring("skia/".length())
322
329
  } else {
323
330
  // flatten anything else
324
331
  path = path.substring(path.lastIndexOf("/") + 1)
@@ -4,18 +4,18 @@
4
4
  #include <thread>
5
5
  #include <utility>
6
6
 
7
- #include "SkData.h"
8
- #include "SkRefCnt.h"
9
- #include "SkStream.h"
10
- #include "SkTypes.h"
7
+ #include "include/core/SkData.h"
8
+ #include "include/core/SkRefCnt.h"
9
+ #include "include/core/SkStream.h"
10
+ #include "include/core/SkTypes.h"
11
11
 
12
12
  #include <android/bitmap.h>
13
13
 
14
14
  #pragma clang diagnostic push
15
15
  #pragma clang diagnostic ignored "-Wdocumentation"
16
16
 
17
- #include "SkBitmap.h"
18
- #include "SkPixmap.h"
17
+ #include "include/core/SkBitmap.h"
18
+ #include "include/core/SkPixmap.h"
19
19
 
20
20
  #pragma clang diagnostic pop
21
21
 
@@ -216,4 +216,4 @@ void JniPlatformContext::raiseError(const std::exception &err) {
216
216
  method(javaPart_.get(), std::string(err.what()));
217
217
  }
218
218
 
219
- } // namespace RNSkia
219
+ } // namespace RNSkia
@@ -5,7 +5,7 @@
5
5
  #include <string>
6
6
  #include <utility>
7
7
 
8
- #include <RNSkManager.h>
8
+ #include "RNSkManager.h"
9
9
 
10
10
  namespace {
11
11
 
@@ -7,8 +7,8 @@
7
7
  #include <jni.h>
8
8
  #include <jsi/jsi.h>
9
9
 
10
- #include <JniSkiaManager.h>
11
- #include <RNSkAndroidView.h>
10
+ #include "JniSkiaManager.h"
11
+ #include "RNSkAndroidView.h"
12
12
 
13
13
  #include <android/bitmap.h>
14
14
 
@@ -7,10 +7,10 @@
7
7
  #include <jni.h>
8
8
  #include <jsi/jsi.h>
9
9
 
10
- #include <JniSkiaBaseView.h>
11
- #include <JniSkiaManager.h>
12
- #include <RNSkAndroidView.h>
13
- #include <RNSkDomView.h>
10
+ #include "JniSkiaBaseView.h"
11
+ #include "JniSkiaManager.h"
12
+ #include "RNSkAndroidView.h"
13
+ #include "RNSkDomView.h"
14
14
 
15
15
  #include <android/native_window.h>
16
16
  #include <android/native_window_jni.h>
@@ -7,10 +7,10 @@
7
7
  #include <memory>
8
8
  #include <react/jni/JRuntimeExecutor.h>
9
9
 
10
- #include <JniPlatformContext.h>
11
- #include <RNSkAndroidPlatformContext.h>
12
- #include <RNSkLog.h>
13
- #include <RNSkManager.h>
10
+ #include "JniPlatformContext.h"
11
+ #include "RNSkAndroidPlatformContext.h"
12
+ #include "RNSkLog.h"
13
+ #include "RNSkManager.h"
14
14
 
15
15
  namespace RNSkia {
16
16
 
@@ -7,10 +7,10 @@
7
7
  #include <jni.h>
8
8
  #include <jsi/jsi.h>
9
9
 
10
- #include <JniSkiaBaseView.h>
11
- #include <JniSkiaManager.h>
12
- #include <RNSkAndroidView.h>
13
- #include <RNSkPictureView.h>
10
+ #include "JniSkiaBaseView.h"
11
+ #include "JniSkiaManager.h"
12
+ #include "RNSkAndroidView.h"
13
+ #include "RNSkPictureView.h"
14
14
 
15
15
  #include <android/native_window.h>
16
16
  #include <android/native_window_jni.h>
@@ -0,0 +1,245 @@
1
+ /*
2
+ * Copyright 2023 Google LLC
3
+ *
4
+ * Use of this source code is governed by a BSD-style license that can be
5
+ * found in the LICENSE file.
6
+ */
7
+
8
+ #include "GrAHardwareBufferUtils.h"
9
+ #if __ANDROID_API__ >= 26
10
+
11
+ #define GL_GLEXT_PROTOTYPES
12
+ #define EGL_EGLEXT_PROTOTYPES
13
+
14
+ #include "include/gpu/GrBackendSurface.h"
15
+ #include "include/gpu/GrDirectContext.h"
16
+ #include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
17
+ #include "include/gpu/gl/GrGLTypes.h"
18
+ #include "src/gpu/ganesh/gl/GrGLDefines.h"
19
+ // #include "src/gpu/ganesh/GrDirectContextPriv.h"
20
+ // #include "src/gpu/ganesh/gl/GrGLUtil.h"
21
+
22
+ #include <EGL/egl.h>
23
+ #include <EGL/eglext.h>
24
+ #include <GLES/gl.h>
25
+ #include <GLES/glext.h>
26
+ #include <android/hardware_buffer.h>
27
+
28
+ #define PROT_CONTENT_EXT_STR "EGL_EXT_protected_content"
29
+ #define EGL_PROTECTED_CONTENT_EXT 0x32C0
30
+
31
+ namespace RNSkia {
32
+
33
+ typedef EGLClientBuffer (*EGLGetNativeClientBufferANDROIDProc)(
34
+ const struct AHardwareBuffer *);
35
+ typedef EGLImageKHR (*EGLCreateImageKHRProc)(EGLDisplay, EGLContext, EGLenum,
36
+ EGLClientBuffer, const EGLint *);
37
+ typedef void (*EGLImageTargetTexture2DOESProc)(EGLenum, void *);
38
+
39
+ GrBackendFormat GetGLBackendFormat(GrDirectContext *dContext,
40
+ uint32_t bufferFormat,
41
+ bool requireKnownFormat) {
42
+ GrBackendApi backend = dContext->backend();
43
+ if (backend != GrBackendApi::kOpenGL) {
44
+ return GrBackendFormat();
45
+ }
46
+ switch (bufferFormat) {
47
+ // TODO: find out if we can detect, which graphic buffers support
48
+ // GR_GL_TEXTURE_2D
49
+ case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
50
+ case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
51
+ return GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
52
+ case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
53
+ return GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_EXTERNAL);
54
+ case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
55
+ return GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
56
+ case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
57
+ return GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_EXTERNAL);
58
+ case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
59
+ return GrBackendFormats::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_EXTERNAL);
60
+ #if __ANDROID_API__ >= 33
61
+ case AHARDWAREBUFFER_FORMAT_R8_UNORM:
62
+ return GrBackendFormats::MakeGL(GR_GL_R8, GR_GL_TEXTURE_EXTERNAL);
63
+ #endif
64
+ default:
65
+ if (requireKnownFormat) {
66
+ return GrBackendFormat();
67
+ } else {
68
+ return GrBackendFormats::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_EXTERNAL);
69
+ }
70
+ }
71
+ SkUNREACHABLE;
72
+ }
73
+
74
+ class GLTextureHelper {
75
+ public:
76
+ GLTextureHelper(GrGLuint texID, EGLImageKHR image, EGLDisplay display,
77
+ GrGLuint texTarget)
78
+ : fTexID(texID), fImage(image), fDisplay(display), fTexTarget(texTarget) {
79
+ }
80
+ ~GLTextureHelper() {
81
+ glDeleteTextures(1, &fTexID);
82
+ // eglDestroyImageKHR will remove a ref from the AHardwareBuffer
83
+ eglDestroyImageKHR(fDisplay, fImage);
84
+ }
85
+ void rebind(GrDirectContext *);
86
+
87
+ private:
88
+ GrGLuint fTexID;
89
+ EGLImageKHR fImage;
90
+ EGLDisplay fDisplay;
91
+ GrGLuint fTexTarget;
92
+ };
93
+
94
+ void GLTextureHelper::rebind(GrDirectContext *dContext) {
95
+ glBindTexture(fTexTarget, fTexID);
96
+ GLenum status = GL_NO_ERROR;
97
+ if ((status = glGetError()) != GL_NO_ERROR) {
98
+ SkDebugf("glBindTexture(%#x, %d) failed (%#x)",
99
+ static_cast<int>(fTexTarget), static_cast<int>(fTexID),
100
+ static_cast<int>(status));
101
+ return;
102
+ }
103
+ glEGLImageTargetTexture2DOES(fTexTarget, fImage);
104
+ if ((status = glGetError()) != GL_NO_ERROR) {
105
+ SkDebugf("glEGLImageTargetTexture2DOES failed (%#x)",
106
+ static_cast<int>(status));
107
+ return;
108
+ }
109
+ dContext->resetContext(kTextureBinding_GrGLBackendState);
110
+ }
111
+
112
+ void delete_gl_texture(void *context) {
113
+ GLTextureHelper *cleanupHelper = static_cast<GLTextureHelper *>(context);
114
+ delete cleanupHelper;
115
+ }
116
+
117
+ void update_gl_texture(void *context, GrDirectContext *dContext) {
118
+ GLTextureHelper *cleanupHelper = static_cast<GLTextureHelper *>(context);
119
+ cleanupHelper->rebind(dContext);
120
+ }
121
+
122
+ static GrBackendTexture make_gl_backend_texture(
123
+ GrDirectContext *dContext, AHardwareBuffer *hardwareBuffer, int width,
124
+ int height, DeleteImageProc *deleteProc, UpdateImageProc *updateProc,
125
+ TexImageCtx *imageCtx, bool isProtectedContent,
126
+ const GrBackendFormat &backendFormat, bool isRenderable) {
127
+ while (GL_NO_ERROR != glGetError()) {
128
+ } // clear GL errors
129
+
130
+ EGLGetNativeClientBufferANDROIDProc eglGetNativeClientBufferANDROID =
131
+ (EGLGetNativeClientBufferANDROIDProc)eglGetProcAddress(
132
+ "eglGetNativeClientBufferANDROID");
133
+ if (!eglGetNativeClientBufferANDROID) {
134
+ RNSkLogger::logToConsole(
135
+ "Failed to get the eglGetNativeClientBufferAndroid proc");
136
+ return GrBackendTexture();
137
+ }
138
+
139
+ EGLClientBuffer clientBuffer =
140
+ eglGetNativeClientBufferANDROID(hardwareBuffer);
141
+ EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
142
+ isProtectedContent ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE,
143
+ isProtectedContent ? EGL_TRUE : EGL_NONE, EGL_NONE};
144
+ EGLDisplay display = eglGetCurrentDisplay();
145
+ // eglCreateImageKHR will add a ref to the AHardwareBuffer
146
+ EGLImageKHR image =
147
+ eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
148
+ clientBuffer, attribs);
149
+ if (EGL_NO_IMAGE_KHR == image) {
150
+ SkDebugf("Could not create EGL image, err = (%#x)",
151
+ static_cast<int>(eglGetError()));
152
+ return GrBackendTexture();
153
+ }
154
+
155
+ GrGLuint texID;
156
+ glGenTextures(1, &texID);
157
+ if (!texID) {
158
+ eglDestroyImageKHR(display, image);
159
+ return GrBackendTexture();
160
+ }
161
+
162
+ GrGLuint target = isRenderable ? GR_GL_TEXTURE_2D : GR_GL_TEXTURE_EXTERNAL;
163
+
164
+ glBindTexture(target, texID);
165
+ GLenum status = GL_NO_ERROR;
166
+ if ((status = glGetError()) != GL_NO_ERROR) {
167
+ SkDebugf("glBindTexture failed (%#x)", static_cast<int>(status));
168
+ glDeleteTextures(1, &texID);
169
+ eglDestroyImageKHR(display, image);
170
+ return GrBackendTexture();
171
+ }
172
+ glEGLImageTargetTexture2DOES(target, image);
173
+ if ((status = glGetError()) != GL_NO_ERROR) {
174
+ SkDebugf("glEGLImageTargetTexture2DOES failed (%#x)",
175
+ static_cast<int>(status));
176
+ glDeleteTextures(1, &texID);
177
+ eglDestroyImageKHR(display, image);
178
+ return GrBackendTexture();
179
+ }
180
+ dContext->resetContext(kTextureBinding_GrGLBackendState);
181
+
182
+ GrGLTextureInfo textureInfo;
183
+ textureInfo.fID = texID;
184
+ SkASSERT(backendFormat.isValid());
185
+ textureInfo.fTarget = target;
186
+ textureInfo.fFormat = GrBackendFormats::AsGLFormatEnum(backendFormat);
187
+ textureInfo.fProtected = skgpu::Protected(isProtectedContent);
188
+
189
+ *deleteProc = delete_gl_texture;
190
+ *updateProc = update_gl_texture;
191
+ *imageCtx = new GLTextureHelper(texID, image, display, target);
192
+
193
+ return GrBackendTextures::MakeGL(width, height, skgpu::Mipmapped::kNo,
194
+ textureInfo);
195
+ }
196
+
197
+ static bool can_import_protected_content_eglimpl() {
198
+ EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
199
+ const char *exts = eglQueryString(dpy, EGL_EXTENSIONS);
200
+ size_t cropExtLen = strlen(PROT_CONTENT_EXT_STR);
201
+ size_t extsLen = strlen(exts);
202
+ bool equal = !strcmp(PROT_CONTENT_EXT_STR, exts);
203
+ bool atStart = !strncmp(PROT_CONTENT_EXT_STR " ", exts, cropExtLen + 1);
204
+ bool atEnd =
205
+ (cropExtLen + 1) < extsLen &&
206
+ !strcmp(" " PROT_CONTENT_EXT_STR, exts + extsLen - (cropExtLen + 1));
207
+ bool inMiddle = strstr(exts, " " PROT_CONTENT_EXT_STR " ");
208
+ return equal || atStart || atEnd || inMiddle;
209
+ }
210
+
211
+ static bool can_import_protected_content(GrDirectContext *dContext) {
212
+ SkASSERT(GrBackendApi::kOpenGL == dContext->backend());
213
+ // Only compute whether the extension is present once the first time this
214
+ // function is called.
215
+ static bool hasIt = can_import_protected_content_eglimpl();
216
+ return hasIt;
217
+ }
218
+
219
+ GrBackendTexture
220
+ MakeGLBackendTexture(GrDirectContext *dContext, AHardwareBuffer *hardwareBuffer,
221
+ int width, int height, DeleteImageProc *deleteProc,
222
+ UpdateImageProc *updateProc, TexImageCtx *imageCtx,
223
+ bool isProtectedContent,
224
+ const GrBackendFormat &backendFormat, bool isRenderable) {
225
+ SkASSERT(dContext);
226
+ if (!dContext || dContext->abandoned()) {
227
+ return GrBackendTexture();
228
+ }
229
+
230
+ if (GrBackendApi::kOpenGL != dContext->backend()) {
231
+ return GrBackendTexture();
232
+ }
233
+
234
+ if (isProtectedContent && !can_import_protected_content(dContext)) {
235
+ return GrBackendTexture();
236
+ }
237
+
238
+ return make_gl_backend_texture(
239
+ dContext, hardwareBuffer, width, height, deleteProc, updateProc, imageCtx,
240
+ isProtectedContent, backendFormat, isRenderable);
241
+ }
242
+
243
+ } // namespace RNSkia
244
+
245
+ #endif
@@ -0,0 +1,33 @@
1
+ #pragma once
2
+
3
+ #include "include/core/SkTypes.h"
4
+
5
+ #include "RNSkLog.h"
6
+
7
+ #if __ANDROID_API__ >= 26
8
+
9
+ #include "include/gpu/GrBackendSurface.h"
10
+ #include "include/gpu/GrTypes.h"
11
+
12
+ class GrDirectContext;
13
+
14
+ extern "C" {
15
+ typedef struct AHardwareBuffer AHardwareBuffer;
16
+ }
17
+
18
+ namespace RNSkia {
19
+
20
+ typedef void *TexImageCtx;
21
+ typedef void (*DeleteImageProc)(TexImageCtx);
22
+ typedef void (*UpdateImageProc)(TexImageCtx, GrDirectContext *);
23
+
24
+ GrBackendTexture
25
+ MakeGLBackendTexture(GrDirectContext *dContext, AHardwareBuffer *hardwareBuffer,
26
+ int width, int height, DeleteImageProc *deleteProc,
27
+ UpdateImageProc *updateProc, TexImageCtx *imageCtx,
28
+ bool isProtectedContent,
29
+ const GrBackendFormat &backendFormat, bool isRenderable);
30
+
31
+ } // namespace RNSkia
32
+
33
+ #endif
@@ -5,9 +5,9 @@
5
5
  #include <memory>
6
6
  #include <string>
7
7
 
8
- #include <JniPlatformContext.h>
9
- #include <RNSkPlatformContext.h>
10
- #include <SkiaOpenGLSurfaceFactory.h>
8
+ #include "JniPlatformContext.h"
9
+ #include "RNSkPlatformContext.h"
10
+ #include "SkiaOpenGLSurfaceFactory.h"
11
11
 
12
12
  #pragma clang diagnostic push
13
13
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -4,7 +4,7 @@
4
4
  #include <string>
5
5
  #include <vector>
6
6
 
7
- #include <RNSkOpenGLCanvasProvider.h>
7
+ #include "RNSkOpenGLCanvasProvider.h"
8
8
  #include <android/native_window.h>
9
9
 
10
10
  namespace RNSkia {
@@ -5,8 +5,8 @@
5
5
  #pragma clang diagnostic push
6
6
  #pragma clang diagnostic ignored "-Wdocumentation"
7
7
 
8
- #include "SkCanvas.h"
9
- #include "SkSurface.h"
8
+ #include "include/core/SkCanvas.h"
9
+ #include "include/core/SkSurface.h"
10
10
 
11
11
  #pragma clang diagnostic pop
12
12
 
@@ -12,9 +12,9 @@
12
12
  #pragma clang diagnostic push
13
13
  #pragma clang diagnostic ignored "-Wdocumentation"
14
14
 
15
- #include "SkCanvas.h"
16
- #include "SkColorSpace.h"
17
- #include "SkSurface.h"
15
+ #include "include/core/SkCanvas.h"
16
+ #include "include/core/SkColorSpace.h"
17
+ #include "include/core/SkSurface.h"
18
18
  #include "include/gpu/GrDirectContext.h"
19
19
  #include "include/gpu/ganesh/gl/GrGLDirectContext.h"
20
20
  #include "include/gpu/gl/GrGLInterface.h"
@@ -307,4 +307,4 @@ private:
307
307
  return true;
308
308
  }
309
309
  };
310
- } // namespace RNSkia
310
+ } // namespace RNSkia
@@ -1,9 +1,11 @@
1
+ #include "SkiaOpenGLSurfaceFactory.h"
2
+ #include "GrAHardwareBufferUtils.h"
1
3
  #include "SkiaOpenGLHelper.h"
2
- #include <SkiaOpenGLSurfaceFactory.h>
3
4
 
4
5
  #pragma clang diagnostic push
5
6
  #pragma clang diagnostic ignored "-Wdocumentation"
6
7
 
8
+ #include "include/gpu/ganesh/SkImageGanesh.h"
7
9
  #include "include/gpu/ganesh/gl/GrGLBackendSurface.h"
8
10
 
9
11
  #pragma clang diagnostic pop
@@ -12,6 +14,34 @@ namespace RNSkia {
12
14
 
13
15
  thread_local SkiaOpenGLContext ThreadContextHolder::ThreadSkiaOpenGLContext;
14
16
 
17
+ sk_sp<SkImage>
18
+ SkiaOpenGLSurfaceFactory::makeImageFromHardwareBuffer(const SkImageInfo &info,
19
+ void *buffer) {
20
+ #if __ANDROID_API__ >= 26
21
+ const AHardwareBuffer *hardwareBuffer =
22
+ static_cast<AHardwareBuffer *>(buffer);
23
+ DeleteImageProc deleteImageProc = nullptr;
24
+ UpdateImageProc updateImageProc = nullptr;
25
+ TexImageCtx deleteImageCtx = nullptr;
26
+ auto backendTex = MakeGLBackendTexture(
27
+ ThreadContextHolder::ThreadSkiaOpenGLContext.directContext.get(),
28
+ const_cast<AHardwareBuffer *>(hardwareBuffer), info.width(),
29
+ info.height(), &deleteImageProc, &updateImageProc, &deleteImageCtx, false,
30
+ // GR_GL_RGBA8 0x8058
31
+ // GR_GL_TEXTURE_EXTERNAL 0x8D65
32
+ GrBackendFormats::MakeGL(0x8058, 0x8D65), false);
33
+ sk_sp<SkImage> image = SkImages::BorrowTextureFrom(
34
+ ThreadContextHolder::ThreadSkiaOpenGLContext.directContext.get(),
35
+ backendTex, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
36
+ kPremul_SkAlphaType, nullptr);
37
+ return image;
38
+ #else
39
+ RNSkLogger::logToConsole(
40
+ "Hardware buffer in only supported on Android API level 26 and above.");
41
+ return nullptr;
42
+ #endif
43
+ }
44
+
15
45
  sk_sp<SkSurface> SkiaOpenGLSurfaceFactory::makeOffscreenSurface(int width,
16
46
  int height) {
17
47
  // Setup OpenGL and Skia:
@@ -150,4 +180,4 @@ sk_sp<SkSurface> WindowSurfaceHolder::getSurface() {
150
180
  return _skSurface;
151
181
  }
152
182
 
153
- } // namespace RNSkia
183
+ } // namespace RNSkia
@@ -1,6 +1,6 @@
1
1
  #pragma once
2
2
 
3
- #include <RNSkLog.h>
3
+ #include "RNSkLog.h"
4
4
 
5
5
  #include <fbjni/fbjni.h>
6
6
  #include <jni.h>
@@ -18,9 +18,9 @@
18
18
  #pragma clang diagnostic push
19
19
  #pragma clang diagnostic ignored "-Wdocumentation"
20
20
 
21
- #include "SkCanvas.h"
22
- #include "SkColorSpace.h"
23
- #include "SkSurface.h"
21
+ #include "include/core/SkCanvas.h"
22
+ #include "include/core/SkColorSpace.h"
23
+ #include "include/core/SkSurface.h"
24
24
  #include "include/gpu/GrBackendSurface.h"
25
25
  #include "include/gpu/GrDirectContext.h"
26
26
  #include "include/gpu/ganesh/SkSurfaceGanesh.h"
@@ -149,6 +149,9 @@ public:
149
149
  */
150
150
  static sk_sp<SkSurface> makeOffscreenSurface(int width, int height);
151
151
 
152
+ static sk_sp<SkImage> makeImageFromHardwareBuffer(const SkImageInfo &info,
153
+ void *buffer);
154
+
152
155
  /**
153
156
  * Creates a windowed Skia Surface holder.
154
157
  * @param width Initial width of surface
@@ -14,6 +14,7 @@ import android.view.SurfaceView;
14
14
  import android.view.TextureView;
15
15
  import android.view.View;
16
16
  import android.view.ViewGroup;
17
+ import android.widget.ScrollView;
17
18
  import androidx.annotation.NonNull;
18
19
  import com.facebook.react.bridge.ReactContext;
19
20
  import com.facebook.react.uimanager.UIManagerModule;
@@ -70,6 +71,17 @@ public class ViewScreenshotService {
70
71
  canvas.save();
71
72
  applyTransformations(canvas, view);
72
73
 
74
+ // If the view is a ScrollView or similar, clip to its bounds
75
+ if (view instanceof ScrollView) {
76
+ ScrollView scrollView = (ScrollView) view;
77
+ int clipLeft = scrollView.getScrollX();
78
+ int clipTop = scrollView.getScrollY();
79
+ int clipRight = clipLeft + scrollView.getWidth();
80
+ int clipBottom = clipTop + scrollView.getHeight();
81
+
82
+ canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom);
83
+ }
84
+
73
85
  if (view instanceof ViewGroup) {
74
86
  ViewGroup group = (ViewGroup) view;
75
87
  drawBackgroundIfPresent(canvas, view, combinedOpacity);
@@ -166,7 +178,10 @@ public class ViewScreenshotService {
166
178
  private static void applyTransformations(final Canvas c, @NonNull final View view) {
167
179
  final Matrix matrix = view.getMatrix();
168
180
  final Matrix translateMatrix = new Matrix();
169
- translateMatrix.setTranslate(view.getLeft() + view.getPaddingLeft(), view.getTop() + view.getPaddingTop());
181
+
182
+ translateMatrix.setTranslate(view.getLeft() + view.getPaddingLeft() - view.getScrollX(),
183
+ view.getTop() + view.getPaddingTop() - view.getScrollY());
184
+
170
185
  c.concat(translateMatrix);
171
186
  c.concat(matrix);
172
187
  }
@@ -11,8 +11,8 @@
11
11
  #pragma clang diagnostic ignored "-Wdocumentation"
12
12
 
13
13
  #include "JsiSkImage.h"
14
- #include "SkStream.h"
15
14
  #include "include/codec/SkEncodedImageFormat.h"
15
+ #include "include/core/SkStream.h"
16
16
 
17
17
  #include "include/android/SkAnimatedImage.h"
18
18
  #include "include/codec/SkAndroidCodec.h"
@@ -26,14 +26,14 @@
26
26
  #pragma clang diagnostic push
27
27
  #pragma clang diagnostic ignored "-Wdocumentation"
28
28
 
29
- #include "SkCanvas.h"
30
- #include "SkFont.h"
31
- #include "SkPaint.h"
32
- #include "SkPath.h"
33
- #include "SkPicture.h"
34
- #include "SkRegion.h"
35
- #include "SkSurface.h"
36
- #include "SkTypeface.h"
29
+ #include "include/core/SkCanvas.h"
30
+ #include "include/core/SkFont.h"
31
+ #include "include/core/SkPaint.h"
32
+ #include "include/core/SkPath.h"
33
+ #include "include/core/SkPicture.h"
34
+ #include "include/core/SkRegion.h"
35
+ #include "include/core/SkSurface.h"
36
+ #include "include/core/SkTypeface.h"
37
37
 
38
38
  #pragma clang diagnostic pop
39
39
 
@@ -12,7 +12,7 @@
12
12
  #pragma clang diagnostic push
13
13
  #pragma clang diagnostic ignored "-Wdocumentation"
14
14
 
15
- #include "SkColor.h"
15
+ #include "include/core/SkColor.h"
16
16
 
17
17
  #pragma clang diagnostic pop
18
18
 
@@ -8,7 +8,7 @@
8
8
  #pragma clang diagnostic push
9
9
  #pragma clang diagnostic ignored "-Wdocumentation"
10
10
 
11
- #include "SkColorFilter.h"
11
+ #include "include/core/SkColorFilter.h"
12
12
 
13
13
  #pragma clang diagnostic pop
14
14