5#include "flutter/shell/gpu/gpu_surface_gl_skia.h"
7#include "flutter/common/graphics/persistent_cache.h"
8#include "flutter/fml/base32.h"
9#include "flutter/fml/logging.h"
10#include "flutter/fml/size.h"
11#include "flutter/fml/trace_event.h"
12#include "flutter/shell/common/context_options.h"
13#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
30#define GPU_GL_RGBA8 0x8058
31#define GPU_GL_RGBA4 0x8056
32#define GPU_GL_RGB565 0x8D62
46 if (!context_switch->GetResult()) {
48 <<
"Could not make the context current to set up the Gr context.";
70 bool render_to_surface)
72 context_owner_ =
true;
77 bool render_to_surface)
81 render_to_surface_(render_to_surface),
84 if (!context_switch->GetResult()) {
86 <<
"Could not make the context current to set up the Gr context.";
92 valid_ = gr_context !=
nullptr;
100 if (!context_switch->GetResult()) {
101 FML_LOG(
ERROR) <<
"Could not make the context current to destroy the "
102 "GrDirectContext resources.";
106 onscreen_surface_ =
nullptr;
108 if (context_owner_) {
123#define RETURN_IF_RENDERABLE(x, y) \
124 if (context->colorTypeSupportedAsSurface((x))) { \
165bool GPUSurfaceGLSkia::CreateOrUpdateSurfaces(
const SkISize&
size) {
166 if (onscreen_surface_ !=
nullptr &&
168 onscreen_surface_->
height())) {
177 onscreen_surface_ =
nullptr;
180 if (
size.isEmpty()) {
181 FML_LOG(
ERROR) <<
"Cannot create surfaces of empty size.";
187 GLFrameInfo frame_info = {
static_cast<uint32_t
>(
size.width()),
188 static_cast<uint32_t
>(
size.height())};
189 const GLFBOInfo fbo_info = delegate_->
GLContextFBO(frame_info);
195 if (onscreen_surface ==
nullptr) {
202 onscreen_surface_ = std::move(onscreen_surface);
203 fbo_id_ = fbo_info.fbo_id;
204 existing_damage_ = fbo_info.existing_damage;
217 if (delegate_ ==
nullptr) {
221 if (!context_switch->GetResult()) {
223 <<
"Could not make the context current to acquire the frame.";
231 if (!render_to_surface_) {
233 return std::make_unique<SurfaceFrame>(
234 nullptr, framebuffer_info,
244 AcquireRenderSurface(
size, root_surface_transformation);
250 surface->getCanvas()->setMatrix(root_surface_transformation);
252 [weak = weak_factory_.GetWeakPtr()](
const SurfaceFrame& surface_frame,
254 return weak ? weak->PresentSurface(surface_frame, canvas) :
false;
261 return std::make_unique<SurfaceFrame>(
surface, framebuffer_info,
262 submit_callback,
size,
263 std::move(context_switch));
268 if (delegate_ ==
nullptr || canvas ==
nullptr || context_ ==
nullptr) {
275 TRACE_EVENT0(
"flutter",
"GrDirectContext::flushAndSubmit");
279 GLPresentInfo present_info = {
281 .frame_damage =
frame.submit_info().frame_damage,
282 .presentation_time =
frame.submit_info().presentation_time,
283 .buffer_damage =
frame.submit_info().buffer_damage,
293 GLFrameInfo frame_info = {
static_cast<uint32_t
>(current_size.width()),
294 static_cast<uint32_t
>(current_size.height())};
298 const GLFBOInfo fbo_info = delegate_->
GLContextFBO(frame_info);
299 auto new_onscreen_surface =
305 if (!new_onscreen_surface) {
309 onscreen_surface_ = std::move(new_onscreen_surface);
310 fbo_id_ = fbo_info.fbo_id;
311 existing_damage_ = fbo_info.existing_damage;
318 const SkISize& untransformed_size,
319 const SkMatrix& root_surface_transformation) {
320 const auto transformed_rect = root_surface_transformation.
mapRect(
323 const auto transformed_size =
324 SkISize::Make(transformed_rect.width(), transformed_rect.height());
326 if (!CreateOrUpdateSurfaces(transformed_size)) {
330 return onscreen_surface_;
335 return context_.
get();
@ kBottomLeft_GrSurfaceOrigin
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kUnknown_SkColorType
uninitialized
@ kUnknown_SkPixelGeometry
void releaseResourcesAndAbandonContext()
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
static sk_sp< SkColorSpace > MakeSRGB()
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Developer-facing API for rendering anything within the engine.
virtual bool AllowsDrawingWhenGpuDisabled() const
virtual std::unique_ptr< GLContextResult > GLContextMakeCurrent()=0
virtual bool GLContextClearCurrent()=0
virtual bool GLContextPresent(const GLPresentInfo &present_info)=0
virtual SkMatrix GLContextSurfaceTransformation() const
virtual sk_sp< const GrGLInterface > GetGLInterface() const
virtual bool GLContextFBOResetAfterPresent() const
virtual SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() const
virtual GLFBOInfo GLContextFBO(GLFrameInfo frame_info) const =0
virtual void GLContextSetDamageRegion(const std::optional< SkIRect > ®ion)
GrDirectContext * GetContext() override
bool AllowsDrawingWhenGpuDisabled() const override
SkMatrix GetRootTransformation() const override
bool ClearRenderContext() override
static sk_sp< GrDirectContext > MakeGLContext(GPUSurfaceGLDelegate *delegate)
GPUSurfaceGLSkia(GPUSurfaceGLDelegate *delegate, bool render_to_surface)
~GPUSurfaceGLSkia() override
std::unique_ptr< GLContextResult > MakeRenderContextCurrent() override
std::unique_ptr< SurfaceFrame > AcquireFrame(const SkISize &size) override
static PersistentCache * GetCacheForProcess()
size_t PrecompileKnownSkSLs(GrDirectContext *context) const
Precompile SkSLs packaged with the application and gathered during previous runs in the given context...
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
#define FML_LOG(severity)
#define RETURN_IF_RENDERABLE(x, y)
SK_API GrBackendRenderTarget MakeGL(int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo &glInfo)
SK_API sk_sp< GrDirectContext > MakeGL(sk_sp< const GrGLInterface >, const GrContextOptions &)
SK_API sk_sp< SkSurface > WrapBackendRenderTarget(GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
static SkColorType FirstSupportedColorType(GrDirectContext *context, GrGLenum *format)
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...
static const size_t kGrCacheMaxByteSize
@ kRender
The context is used to render to a texture or renderbuffer.
static sk_sp< SkSurface > WrapOnscreenSurface(GrDirectContext *context, const SkISize &size, intptr_t fbo)
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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent Remove all existing persistent cache This is mainly for debugging purposes such as reproducing the shader compilation jank trace to Write the timeline trace to a file at the specified path The file will be in Perfetto s proto format
static constexpr SkISize Make(int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const
static constexpr SkRect MakeWH(float w, float h)
std::optional< SkIRect > existing_damage
#define TRACE_EVENT0(category_group, name)