Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
render_context_impeller.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
6
8#include "flutter/impeller/entity/gles3/entity_shaders_gles.h"
14
16 return true;
17}
18
19namespace {
20std::vector<std::shared_ptr<fml::Mapping>>
21ShaderLibraryMappingsForApplication() {
22 return {
23 std::make_shared<fml::NonOwnedMapping>(
24 impeller_entity_shaders_gles3_data,
25 impeller_entity_shaders_gles3_length),
26 };
27}
28
29class ReactorWorker : public impeller::ReactorGLES::Worker {
30 public:
31 ReactorWorker() = default;
32 ReactorWorker(const ReactorWorker&) = delete;
33
34 ReactorWorker& operator=(const ReactorWorker&) = delete;
35
37 const impeller::ReactorGLES& reactor) const override {
38 return true;
39 }
40};
41
42class ImpellerRenderContext : public Skwasm::RenderContext {
43 public:
44 ImpellerRenderContext(std::shared_ptr<impeller::ContextGLES> context,
45 std::shared_ptr<ReactorWorker> worker)
46 : context_(std::move(context)),
47 worker_(std::move(worker)),
48 typographer_context_(impeller::TypographerContextSkia::Make()),
49 content_context_(
50 std::make_unique<impeller::ContentContext>(context_,
51 typographer_context_,
52 nullptr)) {}
53
54 virtual void RenderPicture(
55 const sk_sp<flutter::DisplayList> display_list) override {
57 *content_context_, surface_->GetRenderTarget(), display_list,
58 impeller::Rect::MakeLTRB(0, 0, width_, height_), true);
59 }
60
62 Skwasm::ImageByteFormat format) override {}
63
64 virtual void Resize(int width, int height) override {
65 if (width_ != width || height_ != height) {
66 width_ = width;
67 height_ = height;
68 RecreateSurface();
69 }
70 }
71
72 virtual void SetResourceCacheLimit(int bytes) override {
73 // No-op
74 }
75
76 private:
77 void RecreateSurface() {
79 /*context=*/context_,
80 /*swap_callback=*/[]() { return true; },
81 /*fbo=*/0u,
83 /*fbo_size=*/{width_, height_});
84 }
85
86 std::shared_ptr<impeller::ContextGLES> context_;
87 std::shared_ptr<ReactorWorker> worker_;
88 std::shared_ptr<impeller::TypographerContext> typographer_context_;
89 std::unique_ptr<impeller::ContentContext> content_context_;
90 std::unique_ptr<impeller::Surface> surface_;
91 int width_ = 0;
92 int height_ = 0;
93};
94} // namespace
95
96std::unique_ptr<Skwasm::RenderContext> Skwasm::RenderContext::Make(
97 int sample_count,
98 int stencil) {
99 auto clear_depth_emulated = [](float depth) {};
100 auto depth_range_emulated = [](float near_val, float far_val) {};
101
102 std::map<std::string, void*> gl_procs;
103
104 gl_procs["glGetError"] = (void*)&glGetError;
105 gl_procs["glClearDepthf"] = (void*)&clear_depth_emulated;
106 gl_procs["glDepthRangef"] = (void*)&depth_range_emulated;
107
108#define IMPELLER_PROC(name) gl_procs["gl" #name] = (void*)&gl##name;
112 IMPELLER_PROC(GenQueriesEXT);
113 IMPELLER_PROC(DeleteQueriesEXT);
114 IMPELLER_PROC(GetQueryObjectui64vEXT);
115 IMPELLER_PROC(BeginQueryEXT);
116 IMPELLER_PROC(EndQueryEXT);
117 IMPELLER_PROC(GetQueryObjectuivEXT);
118#undef IMPELLER_PROC
119
120 auto gl = std::make_unique<impeller::ProcTableGLES>(
121 [gl_procs = std::move(gl_procs)](const char* function_name) -> void* {
122 auto found = gl_procs.find(function_name);
123 if (found == gl_procs.end()) {
124 return nullptr;
125 }
126 return found->second;
127 });
128
129 auto context = impeller::ContextGLES::Create(
130 impeller::Flags{}, std::move(gl), ShaderLibraryMappingsForApplication(),
131 false);
132
133 auto worker = std::make_shared<ReactorWorker>();
134 context->AddReactorWorker(worker);
135 return std::make_unique<ImpellerRenderContext>(std::move(context),
136 std::move(worker));
137}
virtual void RenderImage(flutter::DlImage *image, ImageByteFormat format)=0
virtual void RenderPicture(const sk_sp< flutter::DisplayList > display_list)=0
static std::unique_ptr< RenderContext > Make(int sample_count, int stencil)
virtual void Resize(int width, int height)=0
virtual void SetResourceCacheLimit(int bytes)=0
Represents an image whose allocation is (usually) resident on device memory.
Definition dl_image.h:32
static std::shared_ptr< ContextGLES > Create(const Flags &flags, std::unique_ptr< ProcTableGLES > gl, const std::vector< std::shared_ptr< fml::Mapping > > &shader_libraries, bool enable_gpu_tracing)
A delegate implemented by a thread on which an OpenGL context is current. There may be multiple worke...
virtual bool CanReactorReactOnCurrentThreadNow(const ReactorGLES &reactor) const =0
Determines the ability of the worker to service a reaction on the current thread. The OpenGL context ...
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
static std::unique_ptr< Surface > WrapFBO(const std::shared_ptr< Context > &context, SwapCallback swap_callback, GLuint fbo, PixelFormat color_format, ISize fbo_size)
FlutterVulkanImage * image
EGLSurface surface_
ImageByteFormat
Definition helpers.h:75
bool RenderToTarget(ContentContext &context, RenderTarget render_target, const sk_sp< flutter::DisplayList > &display_list, Rect cull_rect, bool reset_host_buffer, bool is_onscreen)
Render the provided display list to the render target.
Definition ref_ptr.h:261
#define IMPELLER_PROC(proc_ivar)
#define FOR_EACH_IMPELLER_GLES3_PROC(PROC)
#define FOR_EACH_IMPELLER_ES_ONLY_PROC(PROC)
#define FOR_EACH_IMPELLER_PROC(PROC)
SKWASM_EXPORT bool skwasm_isWimp()
int32_t height
int32_t width
#define SKWASM_EXPORT
Definition export.h:10
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129