|
20 | 20 | #include "MainThreadDispatcher.h"
|
21 | 21 | #include "RNSkAndroidVideo.h"
|
22 | 22 | #include "RNSkPlatformContext.h"
|
23 |
| - |
24 | 23 | #pragma clang diagnostic push
|
25 | 24 | #pragma clang diagnostic ignored "-Wdocumentation"
|
26 | 25 |
|
@@ -78,26 +77,15 @@ class RNSkAndroidPlatformContext : public RNSkPlatformContext {
|
78 | 77 | #endif
|
79 | 78 | }
|
80 | 79 |
|
81 |
| - sk_sp<SkImage> makeImageFromNativeTexture(jsi::Runtime &runtime, |
82 |
| - jsi::Value jsiTextureInfo, |
| 80 | + sk_sp<SkImage> makeImageFromNativeTexture(const TextureInfo &texInfo, |
83 | 81 | int width, int height,
|
84 | 82 | bool mipMapped) override {
|
85 |
| - if (!jsiTextureInfo.isObject()) { |
86 |
| - throw new std::runtime_error("Invalid textureInfo"); |
87 |
| - } |
88 |
| - auto jsiTextureInfoObj = jsiTextureInfo.asObject(runtime); |
89 |
| - |
90 | 83 | GrGLTextureInfo textureInfo;
|
91 |
| - textureInfo.fTarget = |
92 |
| - (GrGLenum)jsiTextureInfoObj.getProperty(runtime, "fTarget").asNumber(); |
93 |
| - textureInfo.fID = |
94 |
| - (GrGLuint)jsiTextureInfoObj.getProperty(runtime, "fID").asNumber(); |
95 |
| - textureInfo.fFormat = |
96 |
| - (GrGLenum)jsiTextureInfoObj.getProperty(runtime, "fFormat").asNumber(); |
| 84 | + textureInfo.fTarget = (GrGLenum)texInfo.glTarget; |
| 85 | + textureInfo.fID = (GrGLuint)texInfo.glID; |
| 86 | + textureInfo.fFormat = (GrGLenum)texInfo.glFormat; |
97 | 87 | textureInfo.fProtected =
|
98 |
| - jsiTextureInfoObj.getProperty(runtime, "fProtected").asBool() |
99 |
| - ? skgpu::Protected::kYes |
100 |
| - : skgpu::Protected::kNo; |
| 88 | + texInfo.glProtected ? skgpu::Protected::kYes : skgpu::Protected::kNo; |
101 | 89 |
|
102 | 90 | OpenGLContext::getInstance().makeCurrent();
|
103 | 91 | if (glIsTexture(textureInfo.fID) == GL_FALSE) {
|
@@ -185,42 +173,38 @@ class RNSkAndroidPlatformContext : public RNSkPlatformContext {
|
185 | 173 | #endif
|
186 | 174 | }
|
187 | 175 |
|
188 |
| - jsi::Value getTexture(jsi::Runtime &runtime, sk_sp<SkImage> image) override { |
| 176 | + const TextureInfo getTexture(sk_sp<SkImage> image) override { |
189 | 177 | GrBackendTexture texture;
|
190 | 178 | if (!SkImages::GetBackendTextureFromImage(image, &texture, true)) {
|
191 |
| - return jsi::Value::null(); |
| 179 | + throw std::runtime_error("Couldn't get backend texture from image."); |
192 | 180 | }
|
193 |
| - return getJSITextureInfo(runtime, texture); |
| 181 | + return getJSITextureInfo(texture); |
194 | 182 | }
|
195 | 183 |
|
196 |
| - jsi::Value getTexture(jsi::Runtime &runtime, |
197 |
| - sk_sp<SkSurface> surface) override { |
| 184 | + const TextureInfo getTexture(sk_sp<SkSurface> surface) override { |
198 | 185 | GrBackendTexture texture = SkSurfaces::GetBackendTexture(
|
199 | 186 | surface.get(), SkSurface::BackendHandleAccess::kFlushRead);
|
200 |
| - return getJSITextureInfo(runtime, texture); |
| 187 | + return getJSITextureInfo(texture); |
201 | 188 | }
|
202 | 189 |
|
203 |
| - static jsi::Value getJSITextureInfo(jsi::Runtime &runtime, |
204 |
| - const GrBackendTexture &texture) { |
| 190 | + static const TextureInfo getJSITextureInfo(const GrBackendTexture &texture) { |
205 | 191 | if (!texture.isValid()) {
|
206 |
| - return jsi::Value::null(); |
| 192 | + throw std::runtime_error("invalid backend texture"); |
207 | 193 | }
|
208 | 194 | GrGLTextureInfo textureInfo;
|
209 | 195 | if (!GrBackendTextures::GetGLTextureInfo(texture, &textureInfo)) {
|
210 |
| - return jsi::Value::null(); |
| 196 | + throw std::runtime_error("couldn't get OpenGL texture"); |
211 | 197 | }
|
212 | 198 |
|
213 | 199 | OpenGLContext::getInstance().makeCurrent();
|
214 | 200 | glFlush();
|
215 | 201 |
|
216 |
| - jsi::Object jsiTextureInfo = jsi::Object(runtime); |
217 |
| - jsiTextureInfo.setProperty(runtime, "fTarget", (int)textureInfo.fTarget); |
218 |
| - jsiTextureInfo.setProperty(runtime, "fFormat", (int)textureInfo.fFormat); |
219 |
| - jsiTextureInfo.setProperty(runtime, "fID", (int)textureInfo.fID); |
220 |
| - jsiTextureInfo.setProperty(runtime, "fProtected", |
221 |
| - (bool)textureInfo.fProtected); |
222 |
| - |
223 |
| - return jsiTextureInfo; |
| 202 | + TextureInfo texInfo; |
| 203 | + texInfo.glProtected = textureInfo.isProtected(); |
| 204 | + texInfo.glID = textureInfo.fID; |
| 205 | + texInfo.glFormat = textureInfo.fFormat; |
| 206 | + texInfo.glTarget = textureInfo.fTarget; |
| 207 | + return texInfo; |
224 | 208 | }
|
225 | 209 |
|
226 | 210 | #if !defined(SK_GRAPHITE)
|
|
0 commit comments