17#include "third_party/skia/include/core/SkAlphaType.h"
18#include "third_party/skia/include/core/SkColorSpace.h"
19#include "third_party/skia/include/core/SkColorType.h"
20#include "third_party/skia/include/core/SkImage.h"
21#include "third_party/skia/include/core/SkPaint.h"
22#include "third_party/skia/include/core/SkSize.h"
23#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
24#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
25#include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
26#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
27#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
32 int64_t texture_identifier,
41void EmbedderExternalTextureGL::Paint(
PaintContext& context,
45 if (last_image_ ==
nullptr) {
54 DlCanvas* canvas = context.
canvas;
55 const DlPaint* paint = context.paint;
59 if (bounds != image_bounds) {
60 canvas->DrawImageRect(last_image_, image_bounds, bounds, sampling, paint);
62 canvas->DrawImage(last_image_, bounds.
GetOrigin(), sampling, paint);
67sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTexture(
69 GrDirectContext* context,
71 const SkISize&
size) {
79sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureSkia(
81 GrDirectContext* context,
82 const SkISize&
size) {
83 context->flushAndSubmit();
84 context->resetContext(kAll_GrBackendState);
85 std::unique_ptr<FlutterOpenGLTexture>
texture =
103 auto gr_backend_texture = GrBackendTextures::MakeGL(
104 width,
height, skgpu::Mipmapped::kNo, gr_texture_info);
105 SkImages::TextureReleaseProc release_proc =
texture->destruction_callback;
107 SkImages::BorrowTextureFrom(context,
109 kTopLeft_GrSurfaceOrigin,
110 kRGBA_8888_SkColorType,
121 release_proc(
texture->user_data);
123 FML_LOG(ERROR) <<
"Could not create external texture->";
131sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTextureImpeller(
134 const SkISize&
size) {
135 std::unique_ptr<FlutterOpenGLTexture>
texture =
144 if (
texture->destruction_callback) {
145 texture->destruction_callback(texture->user_data);
149 if (
texture->format != GL_RGBA8) {
150 FML_LOG(ERROR) <<
"Only support GL_RGBA8 format now";
162 std::shared_ptr<impeller::TextureGLES>
image =
166 FML_LOG(ERROR) <<
"Could not create external texture";
171 if (!destruction_callback) {
175 destruction_callback = [](
void*) {};
177 auto cleanup_callback = [
callback = destruction_callback,
181 if (!context.
GetReactor()->RegisterCleanupCallback(handle,
183 FML_LOG(ERROR) <<
"Could not register destruction callback";
187 image->SetCoordinateSystem(
190 scoped_cleanup.Release();
196void EmbedderExternalTextureGL::OnGrContextCreated() {}
199void EmbedderExternalTextureGL::OnGrContextDestroyed() {}
202void EmbedderExternalTextureGL::MarkNewFrameAvailable() {
203 last_image_ =
nullptr;
207void EmbedderExternalTextureGL::OnTextureUnregistered() {}
static sk_sp< DlImage > Make(const SkImage *image)
~EmbedderExternalTextureGL()
EmbedderExternalTextureGL(int64_t texture_identifier, const ExternalTextureCallback &callback)
std::function< std::unique_ptr< FlutterOpenGLTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
Wraps a closure that is invoked in the destructor unless released by the caller.
std::shared_ptr< Context > GetContext() const
static ContextGLES & Cast(Context &base)
const std::shared_ptr< ReactorGLES > & GetReactor() const
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
static std::shared_ptr< TextureGLES > WrapTexture(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, HandleGLES external_handle)
Create a texture by wrapping an external OpenGL texture handle. Ownership of the texture handle is as...
void(* VoidCallback)(void *)
FlutterVulkanImage * image
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
#define FML_DCHECK(condition)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
impeller::AiksContext * aiks_context
GrDirectContext * gr_context
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
static constexpr std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make(const TRect< U > &rect)
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
constexpr TPoint< Type > GetOrigin() const
Returns the upper left corner of the rectangle as specified by the left/top or x/y values when it was...
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...