@@ -139,22 +139,73 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
139139 return nullptr ;
140140 }
141141
142+ if (texture->bind_callback != nullptr ) {
143+ return ResolveTextureImpellerSurface (aiks_context, std::move (texture));
144+ } else {
145+ return ResolveTextureImpellerPixelbuffer (aiks_context, std::move (texture));
146+ }
147+ }
148+
149+ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpellerPixelbuffer (
150+ impeller::AiksContext* aiks_context,
151+ std::unique_ptr<FlutterOpenGLTexture> texture) {
142152 impeller::TextureDescriptor desc;
143- desc.type = impeller::TextureType::kTextureExternalOES ;
153+ desc.size = impeller::ISize (texture->width , texture->height );
154+ desc.type = impeller::TextureType::kTexture2D ;
144155 desc.storage_mode = impeller::StorageMode::kDevicePrivate ;
145156 desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt ;
146- desc.mip_count = 1 ;
147- desc.size = impeller::ISize (texture->width , texture->height );
157+ impeller::ContextGLES& context =
158+ impeller::ContextGLES::Cast (*aiks_context->GetContext ());
159+ std::shared_ptr<impeller::TextureGLES> image =
160+ std::make_shared<impeller::TextureGLES>(context.GetReactor (), desc);
148161
162+ image->MarkContentsInitialized ();
163+ if (!image->SetContents (texture->buffer , texture->buffer_size )) {
164+ if (texture->destruction_callback ) {
165+ texture->destruction_callback (texture->user_data );
166+ }
167+ return nullptr ;
168+ }
169+
170+ if (!image) {
171+ // In case Skia rejects the image, call the release proc so that
172+ // embedders can perform collection of intermediates.
173+ if (texture->destruction_callback ) {
174+ texture->destruction_callback (texture->user_data );
175+ }
176+ FML_LOG (ERROR) << " Could not create external texture" ;
177+ return nullptr ;
178+ }
179+
180+ if (texture->destruction_callback ) {
181+ texture->destruction_callback (texture->user_data );
182+ }
183+
184+ return impeller::DlImageImpeller::Make (image);
185+ }
186+
187+ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpellerSurface (
188+ impeller::AiksContext* aiks_context,
189+ std::unique_ptr<FlutterOpenGLTexture> texture) {
190+ impeller::TextureDescriptor desc;
191+ desc.size = impeller::ISize (texture->width , texture->height );
192+ desc.storage_mode = impeller::StorageMode::kDevicePrivate ;
193+ desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt ;
194+ desc.type = impeller::TextureType::kTextureExternalOES ;
149195 impeller::ContextGLES& context =
150196 impeller::ContextGLES::Cast (*aiks_context->GetContext ());
151- impeller::HandleGLES handle = context.GetReactor ()->CreateHandle (
152- impeller::HandleType::kTexture , texture->target );
153197 std::shared_ptr<impeller::TextureGLES> image =
154- impeller::TextureGLES::WrapTexture (context.GetReactor (), desc, handle );
198+ std::make_shared<impeller::TextureGLES> (context.GetReactor (), desc);
155199 image->MarkContentsInitialized ();
156200 image->SetCoordinateSystem (
157201 impeller::TextureCoordinateSystem::kUploadFromHost );
202+ if (!image->Bind ()) {
203+ if (texture->destruction_callback ) {
204+ texture->destruction_callback (texture->user_data );
205+ }
206+ FML_LOG (ERROR) << " Could not bind texture" ;
207+ return nullptr ;
208+ }
158209
159210 if (!image) {
160211 // In case Skia rejects the image, call the release proc so that
@@ -173,13 +224,8 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
173224 return nullptr ;
174225 }
175226
176- if (texture->destruction_callback &&
177- !context.GetReactor ()->RegisterCleanupCallback (
178- handle,
179- [callback = texture->destruction_callback ,
180- user_data = texture->user_data ]() { callback (user_data); })) {
181- FML_LOG (ERROR) << " Could not register destruction callback" ;
182- return nullptr ;
227+ if (texture->destruction_callback ) {
228+ texture->destruction_callback (texture->user_data );
183229 }
184230
185231 return impeller::DlImageImpeller::Make (image);
0 commit comments