|
156 | 156 | return reinterpret_cast<uint64_t>(pixelBuffer); |
157 | 157 | } |
158 | 158 |
|
| 159 | +#if !defined(SK_GRAPHITE) |
| 160 | +GrDirectContext *RNSkApplePlatformContext::getDirectContext() { |
| 161 | + return MetalContext::getInstance().getDirectContext(); |
| 162 | +} |
| 163 | + |
159 | 164 | const TextureInfo RNSkApplePlatformContext::getTexture(sk_sp<SkImage> image) { |
160 | | - GrBackendTexture texture; |
161 | 165 | TextureInfo result; |
| 166 | + GrBackendTexture texture; |
162 | 167 | if (!SkImages::GetBackendTextureFromImage(image, &texture, true)) { |
163 | 168 | throw std::runtime_error("Couldn't get backend texture"); |
164 | 169 | } |
|
175 | 180 |
|
176 | 181 | const TextureInfo |
177 | 182 | RNSkApplePlatformContext::getTexture(sk_sp<SkSurface> surface) { |
| 183 | + TextureInfo result; |
178 | 184 | GrBackendTexture texture = SkSurfaces::GetBackendTexture( |
179 | 185 | surface.get(), SkSurfaces::BackendHandleAccess::kFlushRead); |
180 | | - TextureInfo result; |
181 | 186 | if (!texture.isValid()) { |
182 | 187 | throw std::runtime_error("Invalid backend texture"); |
183 | 188 | } |
184 | 189 | GrMtlTextureInfo textureInfo; |
185 | 190 | if (!GrBackendTextures::GetMtlTextureInfo(texture, &textureInfo)) { |
186 | 191 | throw std::runtime_error("Couldn't get Metal texture info"); |
187 | 192 | } |
188 | | - result.mtlTexture = textureInfo.fTexture.get(); |
| 193 | + result.mtlTexture = textureInfo.fTexture.get(); |
189 | 194 | return result; |
190 | 195 | } |
191 | 196 |
|
| 197 | +sk_sp<SkImage> RNSkApplePlatformContext::makeImageFromNativeTexture( |
| 198 | + const TextureInfo &texInfo, int width, int height, bool mipMapped) { |
| 199 | + id<MTLTexture> mtlTexture = (__bridge id<MTLTexture>)(texInfo.mtlTexture); |
| 200 | + |
| 201 | + SkColorType colorType = mtlPixelFormatToSkColorType(mtlTexture.pixelFormat); |
| 202 | + if (colorType == SkColorType::kUnknown_SkColorType) { |
| 203 | + throw std::runtime_error("Unsupported pixelFormat"); |
| 204 | + } |
| 205 | + |
| 206 | + GrMtlTextureInfo textureInfo; |
| 207 | + textureInfo.fTexture.retain((__bridge const void *)mtlTexture); |
| 208 | + |
| 209 | + GrBackendTexture texture = GrBackendTextures::MakeMtl( |
| 210 | + width, height, mipMapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo, |
| 211 | + textureInfo); |
| 212 | + |
| 213 | + return SkImages::BorrowTextureFrom(getDirectContext(), texture, |
| 214 | + kTopLeft_GrSurfaceOrigin, colorType, |
| 215 | + kPremul_SkAlphaType, nullptr); |
| 216 | + return nullptr; |
| 217 | +} |
| 218 | +#endif |
| 219 | + |
192 | 220 | std::shared_ptr<RNSkVideo> |
193 | 221 | RNSkApplePlatformContext::createVideo(const std::string &url) { |
194 | 222 | return std::make_shared<RNSkAppleVideo>(url, this); |
|
227 | 255 | #endif |
228 | 256 | } |
229 | 257 |
|
230 | | -sk_sp<SkImage> RNSkApplePlatformContext::makeImageFromNativeTexture( |
231 | | - const TextureInfo &texInfo, int width, int height, bool mipMapped) { |
232 | | - id<MTLTexture> mtlTexture = (__bridge id<MTLTexture>)(texInfo.mtlTexture); |
233 | | - |
234 | | - SkColorType colorType = mtlPixelFormatToSkColorType(mtlTexture.pixelFormat); |
235 | | - if (colorType == SkColorType::kUnknown_SkColorType) { |
236 | | - throw std::runtime_error("Unsupported pixelFormat"); |
237 | | - } |
238 | | - |
239 | | - GrMtlTextureInfo textureInfo; |
240 | | - textureInfo.fTexture.retain((__bridge const void *)mtlTexture); |
241 | | - |
242 | | - GrBackendTexture texture = GrBackendTextures::MakeMtl( |
243 | | - width, height, mipMapped ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo, |
244 | | - textureInfo); |
245 | | - |
246 | | - return SkImages::BorrowTextureFrom(getDirectContext(), texture, |
247 | | - kTopLeft_GrSurfaceOrigin, colorType, |
248 | | - kPremul_SkAlphaType, nullptr); |
249 | | -} |
250 | | - |
251 | 258 | SkColorType RNSkApplePlatformContext::mtlPixelFormatToSkColorType( |
252 | 259 | MTLPixelFormat pixelFormat) { |
253 | 260 | switch (pixelFormat) { |
|
280 | 287 | } |
281 | 288 | } |
282 | 289 |
|
283 | | -#if !defined(SK_GRAPHITE) |
284 | | -GrDirectContext *RNSkApplePlatformContext::getDirectContext() { |
285 | | - return MetalContext::getInstance().getDirectContext(); |
286 | | -} |
287 | | -#endif |
288 | | - |
289 | 290 | sk_sp<SkFontMgr> RNSkApplePlatformContext::createFontMgr() { |
290 | 291 | return SkFontMgr_New_CoreText(nullptr); |
291 | 292 | } |
|
0 commit comments