Skip to content

Commit

Permalink
[Tizen] Remove FlutterEngineRegisterExternalTextureWithType interface
Browse files Browse the repository at this point in the history
Add texture type to FlutterOpenGLTexture
  • Loading branch information
xiaowei-guan committed Jun 14, 2024
1 parent 567655c commit de73015
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 317 deletions.
2 changes: 2 additions & 0 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ template("embedder_source_set") {
sources += [
"embedder_external_texture_gl.cc",
"embedder_external_texture_gl.h",
"embedder_external_texture_gl_impeller.cc",
"embedder_external_texture_gl_impeller.h",
"embedder_surface_gl.cc",
"embedder_surface_gl.h",
]
Expand Down
26 changes: 2 additions & 24 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2029,8 +2029,8 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
}
return texture;
};
external_texture_resolver =
std::make_unique<ExternalTextureResolver>(external_texture_callback);
external_texture_resolver = std::make_unique<ExternalTextureResolver>(
external_texture_callback, settings.enable_impeller);
}
}
#endif
Expand Down Expand Up @@ -2712,26 +2712,6 @@ FlutterEngineResult FlutterEngineRegisterExternalTexture(
return kSuccess;
}

FlutterEngineResult FlutterEngineRegisterExternalTextureWithType(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier,
FlutterTextureType type) {
if (engine == nullptr) {
return LOG_EMBEDDER_ERROR(kInvalidArguments, "Engine handle was invalid.");
}

if (texture_identifier == 0) {
return LOG_EMBEDDER_ERROR(kInvalidArguments,
"Texture identifier was invalid.");
}
if (!reinterpret_cast<flutter::EmbedderEngine*>(engine)->RegisterTexture(
texture_identifier, type)) {
return LOG_EMBEDDER_ERROR(kInternalInconsistency,
"Could not register the specified texture.");
}
return kSuccess;
}

FlutterEngineResult FlutterEngineUnregisterExternalTexture(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier) {
Expand Down Expand Up @@ -3307,8 +3287,6 @@ FlutterEngineResult FlutterEngineGetProcAddresses(
SET_PROC(SendPlatformMessageResponse,
FlutterEngineSendPlatformMessageResponse);
SET_PROC(RegisterExternalTexture, FlutterEngineRegisterExternalTexture);
SET_PROC(RegisterExternalTextureWithType,
FlutterEngineRegisterExternalTextureWithType);
SET_PROC(UnregisterExternalTexture, FlutterEngineUnregisterExternalTexture);
SET_PROC(MarkExternalTextureFrameAvailable,
FlutterEngineMarkExternalTextureFrameAvailable);
Expand Down
61 changes: 13 additions & 48 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ typedef enum {
kFlutterSoftwarePixelFormatNative32,
} FlutterSoftwarePixelFormat;

typedef enum {
kFlutterGLImpellerTexturePixelBuffer,
kFlutterGLImpellerTextureGpuSuface,
} FlutterGLImpellerTextureType;

typedef struct {
/// Target texture of the active texture unit (example GL_TEXTURE_2D or
/// GL_TEXTURE_RECTANGLE).
Expand All @@ -370,10 +375,16 @@ typedef struct {
uint32_t name;
/// The texture format (example GL_RGBA8).
uint32_t format;
/// User data to be returned on the invocation of the destruction callback.
void* user_data;
/// The pixel data buffer.
const uint8_t* buffer;
/// The size of buffer.
size_t buffer_size;
/// Callback invoked that texture start binding.
BoolCallback bind_callback;
/// the type of the texture.
FlutterGLImpellerTextureType impeller_texture_type;
/// User data to be returned on the invocation of the destruction callback.
void* user_data;
/// Callback invoked (on an engine managed thread) that asks the embedder to
/// collect the texture.
VoidCallback destruction_callback;
Expand All @@ -385,10 +396,6 @@ typedef struct {
size_t width;
/// Height of the texture.
size_t height;
/// The pixel data buffer.
const uint8_t* buffer;
/// The size of buffer.
size_t buffer_size;
} FlutterOpenGLTexture;

typedef struct {
Expand All @@ -408,15 +415,6 @@ typedef struct {
VoidCallback destruction_callback;
} FlutterOpenGLFramebuffer;

// Possible values for the type specified in FlutterDesktopTextureInfo.
// Additional types may be added in the future.
typedef enum {
// A Pixel buffer-based texture.
kFlutterPixelBufferTexture,
// A platform-specific GPU surface-backed texture.
kFlutterGpuSurfaceTexture
} FlutterTextureType;

typedef FlutterTransformation (*TransformationCallback)(void* /* user data */);
typedef uint32_t (*UIntCallback)(void* /* user data */);
typedef bool (*SoftwareSurfacePresentCallback)(void* /* user data */,
Expand Down Expand Up @@ -2694,32 +2692,6 @@ FlutterEngineResult FlutterEngineRegisterExternalTexture(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);

//------------------------------------------------------------------------------
/// @brief Register an external texture with a unique (per engine)
/// identifier. Only rendering backends that support external
/// textures accept external texture registrations. After the
/// external texture is registered, the application can mark that a
/// frame is available by calling
/// `FlutterEngineMarkExternalTextureFrameAvailable`.
///
/// @see FlutterEngineUnregisterExternalTexture()
/// @see FlutterEngineMarkExternalTextureFrameAvailable()
///
/// @param[in] engine A running engine instance.
/// @param[in] texture_identifier The identifier of the texture to register
/// with the engine. The embedder may supply new
/// frames to this texture using the same
/// identifier.
/// @param[in] type The type of the texture.
///
/// @return The result of the call.
///
FLUTTER_EXPORT
FlutterEngineResult FlutterEngineRegisterExternalTextureWithType(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier,
FlutterTextureType type);

//------------------------------------------------------------------------------
/// @brief Unregister a previous texture registration.
///
Expand Down Expand Up @@ -3172,11 +3144,6 @@ typedef FlutterEngineResult (*FlutterEngineSendPlatformMessageResponseFnPtr)(
typedef FlutterEngineResult (*FlutterEngineRegisterExternalTextureFnPtr)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);
typedef FlutterEngineResult (
*FlutterEngineRegisterExternalTextureWithTypeFnPtr)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier,
FlutterTextureType type);
typedef FlutterEngineResult (*FlutterEngineUnregisterExternalTextureFnPtr)(
FLUTTER_API_SYMBOL(FlutterEngine) engine,
int64_t texture_identifier);
Expand Down Expand Up @@ -3263,8 +3230,6 @@ typedef struct {
PlatformMessageReleaseResponseHandle;
FlutterEngineSendPlatformMessageResponseFnPtr SendPlatformMessageResponse;
FlutterEngineRegisterExternalTextureFnPtr RegisterExternalTexture;
FlutterEngineRegisterExternalTextureWithTypeFnPtr
RegisterExternalTextureWithType;
FlutterEngineUnregisterExternalTextureFnPtr UnregisterExternalTexture;
FlutterEngineMarkExternalTextureFrameAvailableFnPtr
MarkExternalTextureFrameAvailable;
Expand Down
9 changes: 0 additions & 9 deletions shell/platform/embedder/embedder_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,6 @@ bool EmbedderEngine::RegisterTexture(int64_t texture) {
return true;
}

bool EmbedderEngine::RegisterTexture(int64_t texture, FlutterTextureType type) {
if (!IsValid()) {
return false;
}
shell_->GetPlatformView()->RegisterTexture(
external_texture_resolver_->ResolveExternalTexture(texture, type));
return true;
}

bool EmbedderEngine::UnregisterTexture(int64_t texture) {
if (!IsValid()) {
return false;
Expand Down
2 changes: 0 additions & 2 deletions shell/platform/embedder/embedder_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class EmbedderEngine {

bool RegisterTexture(int64_t texture);

bool RegisterTexture(int64_t texture, FlutterTextureType type);

bool UnregisterTexture(int64_t texture);

bool MarkTextureFrameAvailable(int64_t texture);
Expand Down
156 changes: 16 additions & 140 deletions shell/platform/embedder/embedder_external_texture_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
#include "flutter/shell/platform/embedder/embedder_external_texture_gl.h"

#include "flutter/fml/logging.h"
#include "flutter/impeller/display_list/dl_image_impeller.h"
#include "flutter/impeller/renderer/backend/gles/context_gles.h"
#include "flutter/impeller/renderer/backend/gles/texture_gles.h"
#include "impeller/aiks/aiks_context.h"
#include "impeller/renderer/backend/gles/gles.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "third_party/skia/include/core/SkAlphaType.h"
Expand Down Expand Up @@ -42,7 +37,7 @@ void EmbedderExternalTextureGL::Paint(PaintContext& context,
if (last_image_ == nullptr) {
last_image_ =
ResolveTexture(Id(), //
context, //
context.gr_context, //
SkISize::Make(bounds.width(), bounds.height()) //
);
}
Expand All @@ -60,34 +55,12 @@ void EmbedderExternalTextureGL::Paint(PaintContext& context,
}
}

// |flutter::Texture|
void EmbedderExternalTextureGL::OnGrContextCreated() {}

// |flutter::Texture|
void EmbedderExternalTextureGL::OnGrContextDestroyed() {}

// |flutter::Texture|
void EmbedderExternalTextureGL::MarkNewFrameAvailable() {
last_image_ = nullptr;
}

// |flutter::Texture|
void EmbedderExternalTextureGL::OnTextureUnregistered() {}

EmbedderExternalTextureSkiaGL::EmbedderExternalTextureSkiaGL(
int64_t texture_identifier,
const ExternalTextureCallback& callback)
: EmbedderExternalTextureGL(texture_identifier, callback) {}

EmbedderExternalTextureSkiaGL::~EmbedderExternalTextureSkiaGL() = default;

sk_sp<DlImage> EmbedderExternalTextureSkiaGL::ResolveTexture(
sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTexture(
int64_t texture_id,
PaintContext& context,
GrDirectContext* context,
const SkISize& size) {
GrDirectContext* gr_context = context.gr_context;
gr_context->flushAndSubmit();
gr_context->resetContext(kAll_GrBackendState);
context->flushAndSubmit();
context->resetContext(kAll_GrBackendState);
std::unique_ptr<FlutterOpenGLTexture> texture =
external_texture_callback_(texture_id, size.width(), size.height());

Expand All @@ -110,7 +83,7 @@ sk_sp<DlImage> EmbedderExternalTextureSkiaGL::ResolveTexture(
width, height, skgpu::Mipmapped::kNo, gr_texture_info);
SkImages::TextureReleaseProc release_proc = texture->destruction_callback;
auto image =
SkImages::BorrowTextureFrom(gr_context, // context
SkImages::BorrowTextureFrom(context, // context
gr_backend_texture, // texture handle
kTopLeft_GrSurfaceOrigin, // origin
kRGBA_8888_SkColorType, // color type
Expand All @@ -126,123 +99,26 @@ sk_sp<DlImage> EmbedderExternalTextureSkiaGL::ResolveTexture(
if (release_proc) {
release_proc(texture->user_data);
}
FML_LOG(ERROR) << "Could not create external texture->";
return nullptr;
}

// This image should not escape local use by EmbedderExternalTextureGL
return DlImage::Make(std::move(image));
}

EmbedderExternalTextureGLImpellerPixelBuffer::
EmbedderExternalTextureGLImpellerPixelBuffer(
int64_t texture_identifier,
const ExternalTextureCallback& callback)
: EmbedderExternalTextureGL(texture_identifier, callback) {}

sk_sp<DlImage> EmbedderExternalTextureGLImpellerPixelBuffer::ResolveTexture(
int64_t texture_id,
PaintContext& context,
const SkISize& size) {
std::unique_ptr<FlutterOpenGLTexture> texture =
external_texture_callback_(texture_id, size.width(), size.height());

if (!texture) {
return nullptr;
}

size_t width = size.width();
size_t height = size.height();
// |flutter::Texture|
void EmbedderExternalTextureGL::OnGrContextCreated() {}

if (texture->width != 0 && texture->height != 0) {
width = texture->width;
height = texture->height;
}
// |flutter::Texture|
void EmbedderExternalTextureGL::OnGrContextDestroyed() {}

impeller::TextureDescriptor desc;
desc.type = impeller::TextureType::kTexture2D;
impeller::AiksContext* aiks_context = context.aiks_context;
const auto& gl_context =
impeller::ContextGLES::Cast(*aiks_context->GetContext());
desc.storage_mode = impeller::StorageMode::kDevicePrivate;
desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt;
desc.size = {static_cast<int>(width), static_cast<int>(height)};
desc.mip_count = 1;
auto textureGLES =
std::make_shared<impeller::TextureGLES>(gl_context.GetReactor(), desc);
if (!textureGLES->SetContents(texture->buffer, texture->buffer_size)) {
if (texture->destruction_callback) {
texture->destruction_callback(texture->user_data);
}
return nullptr;
}
if (texture->destruction_callback) {
texture->destruction_callback(texture->user_data);
}
return impeller::DlImageImpeller::Make(textureGLES);
// |flutter::Texture|
void EmbedderExternalTextureGL::MarkNewFrameAvailable() {
last_image_ = nullptr;
}

EmbedderExternalTextureGLImpellerPixelBuffer::
~EmbedderExternalTextureGLImpellerPixelBuffer() = default;

EmbedderExternalTextureGLImpellerSurface::
EmbedderExternalTextureGLImpellerSurface(
int64_t texture_identifier,
const ExternalTextureCallback& callback)
: EmbedderExternalTextureGL(texture_identifier, callback) {}

sk_sp<DlImage> EmbedderExternalTextureGLImpellerSurface::ResolveTexture(
int64_t texture_id,
PaintContext& context,
const SkISize& size) {
std::unique_ptr<FlutterOpenGLTexture> texture =
external_texture_callback_(texture_id, size.width(), size.height());

if (!texture) {
return nullptr;
}
size_t width = size.width();
size_t height = size.height();

if (texture->width != 0 && texture->height != 0) {
width = texture->width;
height = texture->height;
}

impeller::TextureDescriptor desc;
desc.type = impeller::TextureType::kTextureExternalOES;
impeller::AiksContext* aiks_context = context.aiks_context;
const auto& gl_context =
impeller::ContextGLES::Cast(*aiks_context->GetContext());
desc.storage_mode = impeller::StorageMode::kDevicePrivate;
desc.format = impeller::PixelFormat::kR8G8B8A8UNormInt;
desc.size = {static_cast<int>(width), static_cast<int>(height)};
desc.mip_count = 1;
auto textureGLES = std::make_shared<impeller::TextureGLES>(
gl_context.GetReactor(), desc,
impeller::TextureGLES::IsWrapped::kWrapped);
textureGLES->SetCoordinateSystem(
impeller::TextureCoordinateSystem::kUploadFromHost);
if (!textureGLES->Bind()) {
if (texture->destruction_callback) {
texture->destruction_callback(texture->user_data);
}
return nullptr;
}

if (!texture->bind_callback(texture->user_data)) {
if (texture->destruction_callback) {
texture->destruction_callback(texture->user_data);
}
return nullptr;
}

if (texture->destruction_callback) {
texture->destruction_callback(texture->user_data);
}

return impeller::DlImageImpeller::Make(textureGLES);
}
// |flutter::Texture|
void EmbedderExternalTextureGL::OnTextureUnregistered() {}

EmbedderExternalTextureGLImpellerSurface::
~EmbedderExternalTextureGLImpellerSurface() = default;
} // namespace flutter
Loading

0 comments on commit de73015

Please sign in to comment.