9#include "flutter/impeller/entity/gles3/entity_shaders_gles.h"
22std::vector<std::shared_ptr<fml::Mapping>>
23ShaderLibraryMappingsForApplication() {
25 std::make_shared<fml::NonOwnedMapping>(
26 impeller_entity_shaders_gles3_data,
27 impeller_entity_shaders_gles3_length),
33 ReactorWorker() =
default;
34 ReactorWorker(
const ReactorWorker&) =
delete;
36 ReactorWorker& operator=(
const ReactorWorker&) =
delete;
44class ImpellerRenderContext;
45thread_local std::vector<ImpellerRenderContext*> active_contexts;
49 ImpellerRenderContext(std::shared_ptr<impeller::ContextGLES> context,
50 std::shared_ptr<ReactorWorker> worker)
51 : context_(
std::move(context)),
52 worker_(
std::move(worker)),
53 typographer_context_(
impeller::TypographerContextSkia::Make()),
55 std::make_unique<
impeller::ContentContext>(context_,
58 content_context_->SetTextureCachingEnabled(
true);
59 active_contexts.push_back(
this);
62 virtual ~ImpellerRenderContext() {
63 auto it = std::find(active_contexts.begin(), active_contexts.end(),
this);
64 if (it != active_contexts.end()) {
65 active_contexts.erase(it);
70 const sk_sp<flutter::DisplayList> display_list)
override {
72 *content_context_,
surface_->GetRenderTarget(), display_list,
78 void* out_pixels)
override {
79 auto impeller_image =
image ?
image->asImpellerImage() :
nullptr;
81 impeller_image ? impeller_image->GetImpellerTexture(context_) :
nullptr;
88 glGenFramebuffers(1, &fbo);
89 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
91 bool attached = gles_texture->SetAsFramebufferAttachment(
94 glDeleteFramebuffers(1, &fbo);
95 glBindFramebuffer(GL_FRAMEBUFFER, 0);
99 glReadPixels(0, 0,
image->width(),
image->height(), GL_RGBA,
100 GL_UNSIGNED_BYTE, out_pixels);
102 glDeleteFramebuffers(1, &fbo);
103 glBindFramebuffer(GL_FRAMEBUFFER, 0);
117 if (content_context_) {
118 content_context_->RemoveCachedTexture(
image);
127 void RecreateSurface() {
130 []() {
return true; },
136 std::shared_ptr<impeller::ContextGLES> context_;
137 std::shared_ptr<ReactorWorker> worker_;
138 std::shared_ptr<impeller::TypographerContext> typographer_context_;
139 std::unique_ptr<impeller::ContentContext> content_context_;
140 std::unique_ptr<impeller::Surface>
surface_;
149 auto clear_depth_emulated = [](
float depth) {};
150 auto depth_range_emulated = [](
float near_val,
float far_val) {};
152 std::map<std::string, void*> gl_procs;
154 gl_procs[
"glGetError"] = (
void*)&glGetError;
155 gl_procs[
"glClearDepthf"] = (
void*)&clear_depth_emulated;
156 gl_procs[
"glDepthRangef"] = (
void*)&depth_range_emulated;
158#define IMPELLER_PROC(name) gl_procs["gl" #name] = (void*)&gl##name;
170 auto gl = std::make_unique<impeller::ProcTableGLES>(
171 [gl_procs = std::move(gl_procs)](
const char* function_name) ->
void* {
172 auto found = gl_procs.find(function_name);
173 if (found == gl_procs.end()) {
176 return found->second;
180 impeller::Flags{}, std::move(gl), ShaderLibraryMappingsForApplication(),
183 auto worker = std::make_shared<ReactorWorker>();
184 context->AddReactorWorker(worker);
185 return std::make_unique<ImpellerRenderContext>(std::move(context),
192 for (
auto* context : active_contexts) {
193 context->RemoveImage(
image);
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
virtual bool RasterizeImage(flutter::DlImage *image, ImageByteFormat format, void *out_pixels)=0
Represents an image whose allocation is (usually) resident on device memory.
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
void skwasm_disposeDlImageOnWorker(void *dl_image_ptr)
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.
#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()
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)