Skip to content

Commit

Permalink
Move update size code to ResolveTexture method
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei-guan committed Jun 17, 2024
1 parent 2d70966 commit a8d3cad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
32 changes: 13 additions & 19 deletions shell/platform/embedder/embedder_external_texture_gl_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace flutter {

EmbedderExternalTextureGLImpeller::EmbedderExternalTextureGLImpeller(
int64_t texture_identifier,
const ExternalTextureCallback& callback)
const EmbedderExternalTextureGL::ExternalTextureCallback& callback)
: Texture(texture_identifier), external_texture_callback_(callback) {
FML_DCHECK(external_texture_callback_);
}
Expand Down Expand Up @@ -74,33 +74,34 @@ sk_sp<DlImage> EmbedderExternalTextureGLImpeller::ResolveTexture(
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;
}
if (texture->impeller_texture_type ==
FlutterGLImpellerTextureType::kFlutterGLImpellerTexturePixelBuffer) {
return ResolvePixelBufferTexture(texture.get(), context, size);
return ResolvePixelBufferTexture(texture.get(), context,
SkISize::Make(width, height));
} else {
return ResolveGpuSurfaceTexture(texture.get(), context, size);
return ResolveGpuSurfaceTexture(texture.get(), context,
SkISize::Make(width, height));
}
}

sk_sp<DlImage> EmbedderExternalTextureGLImpeller::ResolvePixelBufferTexture(
FlutterOpenGLTexture* texture,
PaintContext& context,
const SkISize& size) {
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::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.size = {static_cast<int>(size.width()), static_cast<int>(size.height())};
desc.mip_count = 1;

auto textureGLES =
Expand All @@ -121,21 +122,14 @@ sk_sp<DlImage> EmbedderExternalTextureGLImpeller::ResolveGpuSurfaceTexture(
FlutterOpenGLTexture* texture,
PaintContext& context,
const SkISize& size) {
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>(texture->width),
static_cast<int>(texture->height)};
desc.size = {static_cast<int>(size.width()), static_cast<int>(size.height())};
desc.mip_count = 1;
auto textureGLES = std::make_shared<impeller::TextureGLES>(
gl_context.GetReactor(), desc,
Expand Down
12 changes: 6 additions & 6 deletions shell/platform/embedder/embedder_external_texture_gl_impeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
#include "flutter/common/graphics/texture.h"
#include "flutter/fml/macros.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/embedder/embedder_external_texture_gl.h"
#include "third_party/skia/include/core/SkSize.h"

namespace flutter {

class EmbedderExternalTextureGLImpeller : public flutter::Texture {
public:
using ExternalTextureCallback = std::function<
std::unique_ptr<FlutterOpenGLTexture>(int64_t, size_t, size_t)>;

EmbedderExternalTextureGLImpeller(int64_t texture_identifier,
const ExternalTextureCallback& callback);
EmbedderExternalTextureGLImpeller(
int64_t texture_identifier,
const EmbedderExternalTextureGL::ExternalTextureCallback& callback);

~EmbedderExternalTextureGLImpeller();

private:
const ExternalTextureCallback& external_texture_callback_;
const EmbedderExternalTextureGL::ExternalTextureCallback&
external_texture_callback_;
sk_sp<DlImage> last_image_;

sk_sp<DlImage> ResolveTexture(int64_t texture_id,
Expand Down

0 comments on commit a8d3cad

Please sign in to comment.