Skip to content

Commit 9190d4c

Browse files
xiaowei-guanJSUYA
authored andcommitted
[Tizen] Support EmbedderExternalTextureGL for impeller
1 parent 6ed7a9e commit 9190d4c

File tree

3 files changed

+86
-10
lines changed

3 files changed

+86
-10
lines changed

engine/src/flutter/shell/platform/embedder/embedder.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ typedef struct {
309309
} FlutterTransformation;
310310

311311
typedef void (*VoidCallback)(void* /* user data */);
312+
typedef bool (*BoolCallback)(void* /* user data */);
312313

313314
typedef enum {
314315
/// Specifies an OpenGL texture target type. Textures are specified using
@@ -416,6 +417,13 @@ typedef struct {
416417
uint32_t name;
417418
/// The texture format (example GL_RGBA8).
418419
uint32_t format;
420+
/// The pixel data buffer.
421+
const uint8_t* buffer;
422+
/// The size of pixel buffer.
423+
size_t buffer_size;
424+
/// Callback invoked that the gpu surface texture start binding.
425+
BoolCallback bind_callback;
426+
419427
/// User data to be returned on the invocation of the destruction callback.
420428
void* user_data;
421429
/// Callback invoked (on an engine managed thread) that asks the embedder to
@@ -509,7 +517,6 @@ typedef struct {
509517
uint32_t format;
510518
} FlutterOpenGLSurface;
511519

512-
typedef bool (*BoolCallback)(void* /* user data */);
513520
typedef FlutterTransformation (*TransformationCallback)(void* /* user data */);
514521
typedef uint32_t (*UIntCallback)(void* /* user data */);
515522
typedef bool (*SoftwareSurfacePresentCallback)(void* /* user data */,

engine/src/flutter/shell/platform/embedder/embedder_external_texture_gl.cc

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

engine/src/flutter/shell/platform/embedder/embedder_external_texture_gl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ class EmbedderExternalTextureGL : public flutter::Texture {
3939
impeller::AiksContext* aiks_context,
4040
const SkISize& size);
4141

42+
sk_sp<DlImage> ResolveTextureImpellerPixelbuffer(
43+
impeller::AiksContext* aiks_context,
44+
std::unique_ptr<FlutterOpenGLTexture> texture);
45+
46+
sk_sp<DlImage> ResolveTextureImpellerSurface(
47+
impeller::AiksContext* aiks_context,
48+
std::unique_ptr<FlutterOpenGLTexture> texture);
49+
4250
// |flutter::Texture|
4351
void Paint(PaintContext& context,
4452
const DlRect& bounds,

0 commit comments

Comments
 (0)