@@ -138,15 +138,73 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
138138 return nullptr ;
139139 }
140140
141+ if (texture->bind_callback != nullptr ) {
142+ return ResolveTextureImpellerSurface (aiks_context, std::move (texture));
143+ } else {
144+ return ResolveTextureImpellerPixelbuffer (aiks_context, std::move (texture));
145+ }
146+ }
147+
148+ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpellerPixelbuffer (
149+ impeller::AiksContext* aiks_context,
150+ std::unique_ptr<FlutterOpenGLTexture> texture) {
141151 impeller::TextureDescriptor desc;
142152 desc.size = impeller::ISize (texture->width , texture->height );
153+ desc.type = impeller::TextureType::kTexture2D ;
154+ desc.storage_mode = impeller::StorageMode::kDevicePrivate ;
155+ desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt ;
156+ impeller::ContextGLES& context =
157+ impeller::ContextGLES::Cast (*aiks_context->GetContext ());
158+ std::shared_ptr<impeller::TextureGLES> image =
159+ std::make_shared<impeller::TextureGLES>(context.GetReactor (), desc);
160+
161+ image->MarkContentsInitialized ();
162+ if (!image->SetContents (texture->buffer , texture->buffer_size )) {
163+ if (texture->destruction_callback ) {
164+ texture->destruction_callback (texture->user_data );
165+ }
166+ return nullptr ;
167+ }
143168
169+ if (!image) {
170+ // In case Skia rejects the image, call the release proc so that
171+ // embedders can perform collection of intermediates.
172+ if (texture->destruction_callback ) {
173+ texture->destruction_callback (texture->user_data );
174+ }
175+ FML_LOG (ERROR) << " Could not create external texture" ;
176+ return nullptr ;
177+ }
178+
179+ if (texture->destruction_callback ) {
180+ texture->destruction_callback (texture->user_data );
181+ }
182+
183+ return impeller::DlImageImpeller::Make (image);
184+ }
185+
186+ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpellerSurface (
187+ impeller::AiksContext* aiks_context,
188+ std::unique_ptr<FlutterOpenGLTexture> texture) {
189+ impeller::TextureDescriptor desc;
190+ desc.size = impeller::ISize (texture->width , texture->height );
191+ desc.storage_mode = impeller::StorageMode::kDevicePrivate ;
192+ desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt ;
193+ desc.type = impeller::TextureType::kTextureExternalOES ;
144194 impeller::ContextGLES& context =
145195 impeller::ContextGLES::Cast (*aiks_context->GetContext ());
146- impeller::HandleGLES handle = context.GetReactor ()->CreateHandle (
147- impeller::HandleType::kTexture , texture->target );
148196 std::shared_ptr<impeller::TextureGLES> image =
149- impeller::TextureGLES::WrapTexture (context.GetReactor (), desc, handle);
197+ std::make_shared<impeller::TextureGLES>(context.GetReactor (), desc);
198+ image->MarkContentsInitialized ();
199+ image->SetCoordinateSystem (
200+ impeller::TextureCoordinateSystem::kUploadFromHost );
201+ if (!image->Bind ()) {
202+ if (texture->destruction_callback ) {
203+ texture->destruction_callback (texture->user_data );
204+ }
205+ FML_LOG (ERROR) << " Could not bind texture" ;
206+ return nullptr ;
207+ }
150208
151209 if (!image) {
152210 // In case Skia rejects the image, call the release proc so that
@@ -157,15 +215,18 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
157215 FML_LOG (ERROR) << " Could not create external texture" ;
158216 return nullptr ;
159217 }
160- if (texture->destruction_callback &&
161- !context.GetReactor ()->RegisterCleanupCallback (
162- handle,
163- [callback = texture->destruction_callback ,
164- user_data = texture->user_data ]() { callback (user_data); })) {
165- FML_LOG (ERROR) << " Could not register destruction callback" ;
218+
219+ if (!texture->bind_callback (texture->user_data )) {
220+ if (texture->destruction_callback ) {
221+ texture->destruction_callback (texture->user_data );
222+ }
166223 return nullptr ;
167224 }
168225
226+ if (texture->destruction_callback ) {
227+ texture->destruction_callback (texture->user_data );
228+ }
229+
169230 return impeller::DlImageImpeller::Make (image);
170231}
171232
0 commit comments