Flutter Engine
The Flutter Engine
embedder_external_texture_gl.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/shell/platform/embedder/embedder_external_texture_gl.h"
6
7#include "flutter/fml/logging.h"
20
21namespace flutter {
22
24 int64_t texture_identifier,
26 : Texture(texture_identifier), external_texture_callback_(callback) {
27 FML_DCHECK(external_texture_callback_);
28}
29
31
32// |flutter::Texture|
33void EmbedderExternalTextureGL::Paint(PaintContext& context,
34 const SkRect& bounds,
35 bool freeze,
37 if (last_image_ == nullptr) {
38 last_image_ =
39 ResolveTexture(Id(), //
40 context.gr_context, //
41 SkISize::Make(bounds.width(), bounds.height()) //
42 );
43 }
44
45 DlCanvas* canvas = context.canvas;
46 const DlPaint* paint = context.paint;
47
48 if (last_image_) {
49 SkRect image_bounds = SkRect::Make(last_image_->bounds());
50 if (bounds != image_bounds) {
51 canvas->DrawImageRect(last_image_, image_bounds, bounds, sampling, paint);
52 } else {
53 canvas->DrawImage(last_image_, {bounds.x(), bounds.y()}, sampling, paint);
54 }
55 }
56}
57
58sk_sp<DlImage> EmbedderExternalTextureGL::ResolveTexture(
59 int64_t texture_id,
60 GrDirectContext* context,
61 const SkISize& size) {
62 context->flushAndSubmit();
64 std::unique_ptr<FlutterOpenGLTexture> texture =
65 external_texture_callback_(texture_id, size.width(), size.height());
66
67 if (!texture) {
68 return nullptr;
69 }
70
71 GrGLTextureInfo gr_texture_info = {texture->target, texture->name,
72 texture->format};
73
74 size_t width = size.width();
75 size_t height = size.height();
76
77 if (texture->width != 0 && texture->height != 0) {
78 width = texture->width;
79 height = texture->height;
80 }
81
82 auto gr_backend_texture = GrBackendTextures::MakeGL(
83 width, height, skgpu::Mipmapped::kNo, gr_texture_info);
84 SkImages::TextureReleaseProc release_proc = texture->destruction_callback;
85 auto image =
86 SkImages::BorrowTextureFrom(context, // context
87 gr_backend_texture, // texture handle
89 kRGBA_8888_SkColorType, // color type
90 kPremul_SkAlphaType, // alpha type
91 nullptr, // colorspace
92 release_proc, // texture release proc
93 texture->user_data // texture release context
94 );
95
96 if (!image) {
97 // In case Skia rejects the image, call the release proc so that
98 // embedders can perform collection of intermediates.
99 if (release_proc) {
100 release_proc(texture->user_data);
101 }
102 FML_LOG(ERROR) << "Could not create external texture->";
103 return nullptr;
104 }
105
106 // This image should not escape local use by EmbedderExternalTextureGL
107 return DlImage::Make(std::move(image));
108}
109
110// |flutter::Texture|
111void EmbedderExternalTextureGL::OnGrContextCreated() {}
112
113// |flutter::Texture|
114void EmbedderExternalTextureGL::OnGrContextDestroyed() {}
115
116// |flutter::Texture|
117void EmbedderExternalTextureGL::MarkNewFrameAvailable() {
118 last_image_ = nullptr;
119}
120
121// |flutter::Texture|
122void EmbedderExternalTextureGL::OnTextureUnregistered() {}
123
124} // namespace flutter
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
static const uint32_t kAll_GrBackendState
Definition: GrTypes.h:176
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
void resetContext(uint32_t state=kAll_GrBackendState)
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
static sk_sp< DlImage > Make(const SkImage *image)
Definition: dl_image.cc:11
EmbedderExternalTextureGL(int64_t texture_identifier, const ExternalTextureCallback &callback)
std::function< std::unique_ptr< FlutterOpenGLTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
int64_t Id()
Definition: texture.h:63
const Paint & paint
Definition: color_source.cc:38
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_DCHECK(condition)
Definition: logging.h:103
FlTexture * texture
SK_API GrBackendTexture MakeGL(int width, int height, skgpu::Mipmapped, const GrGLTextureInfo &glInfo, std::string_view label={})
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
void(*)(ReleaseContext) TextureReleaseProc
Definition: SkImageGanesh.h:45
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions sampling
Definition: SkRecords.h:337
it will be possible to load the file into Perfetto s trace viewer 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
Definition: switches.h:259
flutter::DlCanvas DlCanvas
flutter::DlPaint DlPaint
int32_t height
int32_t width
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
DlCanvas * canvas
Definition: layer.h:102
GrDirectContext * gr_context
Definition: layer.h:109
int64_t texture_id
#define ERROR(message)
Definition: elf_loader.cc:260