Skip to content

Commit 86b86a4

Browse files
xiaowei-guanJSUYA
authored andcommitted
[Tizen] Support EmbedderExternalTextureGL for impeller
1 parent 2704830 commit 86b86a4

File tree

3 files changed

+86
-10
lines changed

3 files changed

+86
-10
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ typedef struct {
302302
} FlutterTransformation;
303303

304304
typedef void (*VoidCallback)(void* /* user data */);
305+
typedef bool (*BoolCallback)(void* /* user data */);
305306

306307
typedef enum {
307308
/// Specifies an OpenGL texture target type. Textures are specified using
@@ -409,6 +410,13 @@ typedef struct {
409410
uint32_t name;
410411
/// The texture format (example GL_RGBA8).
411412
uint32_t format;
413+
/// The pixel data buffer.
414+
const uint8_t* buffer;
415+
/// The size of pixel buffer.
416+
size_t buffer_size;
417+
/// Callback invoked that the gpu surface texture start binding.
418+
BoolCallback bind_callback;
419+
412420
/// User data to be returned on the invocation of the destruction callback.
413421
void* user_data;
414422
/// Callback invoked (on an engine managed thread) that asks the embedder to
@@ -502,7 +510,6 @@ typedef struct {
502510
uint32_t format;
503511
} FlutterOpenGLSurface;
504512

505-
typedef bool (*BoolCallback)(void* /* user data */);
506513
typedef FlutterTransformation (*TransformationCallback)(void* /* user data */);
507514
typedef uint32_t (*UIntCallback)(void* /* user data */);
508515
typedef bool (*SoftwareSurfacePresentCallback)(void* /* user data */,

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

+70-9
Original file line numberDiff line numberDiff line change
@@ -139,15 +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;
143153
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+
}
144169

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;
145195
impeller::ContextGLES& context =
146196
impeller::ContextGLES::Cast(*aiks_context->GetContext());
147-
impeller::HandleGLES handle = context.GetReactor()->CreateHandle(
148-
impeller::HandleType::kTexture, texture->target);
149197
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+
}
151209

152210
if (!image) {
153211
// In case Skia rejects the image, call the release proc so that
@@ -158,15 +216,18 @@ sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
158216
FML_LOG(ERROR) << "Could not create external texture";
159217
return nullptr;
160218
}
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+
}
167224
return nullptr;
168225
}
169226

227+
if (texture->destruction_callback) {
228+
texture->destruction_callback(texture->user_data);
229+
}
230+
170231
return impeller::DlImageImpeller::Make(image);
171232
}
172233

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

+8
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 SkRect& bounds,

0 commit comments

Comments
 (0)