@@ -139,15 +139,73 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
139
139
return nullptr ;
140
140
}
141
141
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) {
142
152
impeller::TextureDescriptor desc;
143
153
desc.size = impeller::ISize (texture->width , texture->height );
154
+ desc.type = impeller::TextureType::kTexture2D ;
155
+ desc.storage_mode = impeller::StorageMode::kDevicePrivate ;
156
+ desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt ;
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);
161
+
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
+ }
144
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 ;
145
195
impeller::ContextGLES& context =
146
196
impeller::ContextGLES::Cast (*aiks_context->GetContext ());
147
- impeller::HandleGLES handle = context.GetReactor ()->CreateHandle (
148
- impeller::HandleType::kTexture , texture->target );
149
197
std::shared_ptr<impeller::TextureGLES> image =
150
- impeller::TextureGLES::WrapTexture (context.GetReactor (), desc, handle);
198
+ std::make_shared<impeller::TextureGLES>(context.GetReactor (), desc);
199
+ image->MarkContentsInitialized ();
200
+ image->SetCoordinateSystem (
201
+ 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
+ }
151
209
152
210
if (!image) {
153
211
// In case Skia rejects the image, call the release proc so that
@@ -158,15 +216,18 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
158
216
FML_LOG (ERROR) << " Could not create external texture" ;
159
217
return nullptr ;
160
218
}
161
- if (texture->destruction_callback &&
162
- !context.GetReactor ()->RegisterCleanupCallback (
163
- handle,
164
- [callback = texture->destruction_callback ,
165
- user_data = texture->user_data ]() { callback (user_data); })) {
166
- FML_LOG (ERROR) << " Could not register destruction callback" ;
219
+
220
+ if (!texture->bind_callback (texture->user_data )) {
221
+ if (texture->destruction_callback ) {
222
+ texture->destruction_callback (texture->user_data );
223
+ }
167
224
return nullptr ;
168
225
}
169
226
227
+ if (texture->destruction_callback ) {
228
+ texture->destruction_callback (texture->user_data );
229
+ }
230
+
170
231
return impeller::DlImageImpeller::Make (image);
171
232
}
172
233
0 commit comments