@@ -138,15 +138,73 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
138
138
return nullptr ;
139
139
}
140
140
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) {
141
151
impeller::TextureDescriptor desc;
142
152
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
+ }
143
168
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 ;
144
194
impeller::ContextGLES& context =
145
195
impeller::ContextGLES::Cast (*aiks_context->GetContext ());
146
- impeller::HandleGLES handle = context.GetReactor ()->CreateHandle (
147
- impeller::HandleType::kTexture , texture->target );
148
196
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
+ }
150
208
151
209
if (!image) {
152
210
// In case Skia rejects the image, call the release proc so that
@@ -157,15 +215,18 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
157
215
FML_LOG (ERROR) << " Could not create external texture" ;
158
216
return nullptr ;
159
217
}
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
+ }
166
223
return nullptr ;
167
224
}
168
225
226
+ if (texture->destruction_callback ) {
227
+ texture->destruction_callback (texture->user_data );
228
+ }
229
+
169
230
return impeller::DlImageImpeller::Make (image);
170
231
}
171
232
0 commit comments