Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::CompositorOpenGL Class Reference

#include <compositor_opengl.h>

Inheritance diagram for flutter::CompositorOpenGL:
flutter::Compositor

Public Member Functions

 CompositorOpenGL (FlutterWindowsEngine *engine, impeller::ProcTableGLES::Resolver resolver, bool enable_impeller)
 
bool CreateBackingStore (const FlutterBackingStoreConfig &config, FlutterBackingStore *result) override
 |Compositor|
 
bool CollectBackingStore (const FlutterBackingStore *store) override
 |Compositor|
 
bool Present (FlutterWindowsView *view, const FlutterLayer **layers, size_t layers_count) override
 |Compositor|
 
- Public Member Functions inherited from flutter::Compositor
virtual ~Compositor ()=default
 

Detailed Description

Definition at line 19 of file compositor_opengl.h.

Constructor & Destructor Documentation

◆ CompositorOpenGL()

flutter::CompositorOpenGL::CompositorOpenGL ( FlutterWindowsEngine engine,
impeller::ProcTableGLES::Resolver  resolver,
bool  enable_impeller 
)

Definition at line 40 of file compositor_opengl.cc.

43 : engine_(engine), resolver_(resolver), enable_impeller_(enable_impeller) {}
FlutterEngine engine
Definition main.cc:84

Member Function Documentation

◆ CollectBackingStore()

bool flutter::CompositorOpenGL::CollectBackingStore ( const FlutterBackingStore store)
overridevirtual

|Compositor|

Implements flutter::Compositor.

Definition at line 112 of file compositor_opengl.cc.

112 {
113 FML_DCHECK(is_initialized_);
116
117 auto user_data = static_cast<FramebufferBackingStore*>(
119
120 gl_->DeleteFramebuffers(1, &user_data->framebuffer_id);
121 gl_->DeleteTextures(1, &user_data->texture_id);
122
123 if (user_data->depth_stencil_id != 0) {
124 gl_->DeleteRenderbuffers(1, &user_data->depth_stencil_id);
125 }
126
127 delete user_data;
128 return true;
129}
@ kFlutterOpenGLTargetTypeFramebuffer
Definition embedder.h:424
@ kFlutterBackingStoreTypeOpenGL
Definition embedder.h:2106
#define FML_DCHECK(condition)
Definition logging.h:122
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2126
FlutterOpenGLBackingStore open_gl
The description of the OpenGL backing store.
Definition embedder.h:2132
FlutterOpenGLTargetType type
Definition embedder.h:1969
FlutterOpenGLFramebuffer framebuffer
Definition embedder.h:1975
void * user_data
User data to be returned on the invocation of the destruction callback.
Definition embedder.h:554

References FML_DCHECK, FlutterOpenGLBackingStore::framebuffer, kFlutterBackingStoreTypeOpenGL, kFlutterOpenGLTargetTypeFramebuffer, FlutterBackingStore::open_gl, FlutterOpenGLBackingStore::type, FlutterBackingStore::type, user_data, and FlutterOpenGLFramebuffer::user_data.

◆ CreateBackingStore()

bool flutter::CompositorOpenGL::CreateBackingStore ( const FlutterBackingStoreConfig config,
FlutterBackingStore result 
)
overridevirtual

|Compositor|

Implements flutter::Compositor.

Definition at line 45 of file compositor_opengl.cc.

47 {
48 if (!is_initialized_ && !Initialize()) {
49 return false;
50 }
51
52 auto store = std::make_unique<FramebufferBackingStore>();
53
54 gl_->GenTextures(1, &store->texture_id);
55 gl_->GenFramebuffers(1, &store->framebuffer_id);
56
57 gl_->BindFramebuffer(GL_FRAMEBUFFER, store->framebuffer_id);
58
59 gl_->BindTexture(GL_TEXTURE_2D, store->texture_id);
60 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
61 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
62 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
63 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
64 gl_->TexImage2D(GL_TEXTURE_2D, 0, format_.general_format, config.size.width,
65 config.size.height, 0, format_.general_format,
66 GL_UNSIGNED_BYTE, nullptr);
67 gl_->BindTexture(GL_TEXTURE_2D, 0);
68
69 if (enable_impeller_) {
70 if (supports_implicit_msaa_) {
71 // MSAA color attachment
72 gl_->FramebufferTexture2DMultisampleEXT(
73 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
74 store->texture_id, 0, 4);
75 } else {
76 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
77 GL_TEXTURE_2D, store->texture_id, 0);
78 }
79
80 // Impeller always requires depth/stencil attachment.
81 gl_->GenRenderbuffers(1, &store->depth_stencil_id);
82 gl_->BindRenderbuffer(GL_RENDERBUFFER, store->depth_stencil_id);
83 if (supports_implicit_msaa_) {
84 gl_->RenderbufferStorageMultisampleEXT(
85 GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, config.size.width,
86 config.size.height);
87 } else {
88 gl_->RenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8,
89 config.size.width, config.size.height);
90 }
91 gl_->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
92 GL_RENDERBUFFER, store->depth_stencil_id);
93 gl_->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
94 GL_RENDERBUFFER, store->depth_stencil_id);
95 } else {
96 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
97 GL_TEXTURE_2D, store->texture_id, 0);
98 }
99
102 result->open_gl.framebuffer.name = store->framebuffer_id;
103 result->open_gl.framebuffer.target = format_.sized_format;
104 result->open_gl.framebuffer.user_data = store.release();
106 // Backing store destroyed in `CompositorOpenGL::CollectBackingStore`, set
107 // on FlutterCompositor.collect_backing_store_callback during engine start.
108 };
109 return true;
110}
FlutterSize size
The size of the render target the engine expects to render into.
Definition embedder.h:2148
uint32_t name
The name of the framebuffer.
Definition embedder.h:551
VoidCallback destruction_callback
Definition embedder.h:558
double height
Definition embedder.h:636
double width
Definition embedder.h:635

References FlutterOpenGLFramebuffer::destruction_callback, FlutterOpenGLBackingStore::framebuffer, FlutterSize::height, kFlutterBackingStoreTypeOpenGL, kFlutterOpenGLTargetTypeFramebuffer, FlutterOpenGLFramebuffer::name, FlutterBackingStore::open_gl, FlutterBackingStoreConfig::size, FlutterOpenGLFramebuffer::target, FlutterOpenGLBackingStore::type, FlutterBackingStore::type, user_data, FlutterOpenGLFramebuffer::user_data, and FlutterSize::width.

◆ Present()

bool flutter::CompositorOpenGL::Present ( FlutterWindowsView view,
const FlutterLayer **  layers,
size_t  layers_count 
)
overridevirtual

|Compositor|

Implements flutter::Compositor.

Definition at line 131 of file compositor_opengl.cc.

133 {
134 FML_DCHECK(view != nullptr);
135
136 // Clear the view if there are no layers to present.
137 if (layers_count == 0) {
138 // Normally the compositor is initialized when the first backing store is
139 // created. However, on an empty frame no backing stores are created and
140 // the present needs to initialize the compositor.
141 if (!is_initialized_ && !Initialize()) {
142 return false;
143 }
144
145 return Clear(view);
146 }
147
148 // TODO: Support compositing layers and platform views.
149 // See: https://github.com/flutter/flutter/issues/31713
150 FML_DCHECK(is_initialized_);
152 FML_DCHECK(layers[0]->offset.x == 0 && layers[0]->offset.y == 0);
155 FML_DCHECK(layers[0]->backing_store->open_gl.type ==
157
158 auto width = layers[0]->size.width;
159 auto height = layers[0]->size.height;
160
161 // Check if this frame can be presented. This resizes the surface if a resize
162 // is pending and |width| and |height| match the target size.
163 if (!view->OnFrameGenerated(width, height)) {
164 return false;
165 }
166
167 // |OnFrameGenerated| should return false if the surface isn't valid.
168 FML_DCHECK(view->surface() != nullptr);
169 FML_DCHECK(view->surface()->IsValid());
170
171 egl::WindowSurface* surface = view->surface();
172 if (!surface->MakeCurrent()) {
173 return false;
174 }
175
176 auto source_id = layers[0]->backing_store->open_gl.framebuffer.name;
177
178 // Disable the scissor test as it can affect blit operations.
179 // Prevents regressions like: https://github.com/flutter/flutter/issues/140828
180 // See OpenGL specification version 4.6, section 18.3.1.
181 gl_->Disable(GL_SCISSOR_TEST);
182 gl_->BindFramebuffer(GL_READ_FRAMEBUFFER, source_id);
183 gl_->BindFramebuffer(GL_DRAW_FRAMEBUFFER, kWindowFrameBufferId);
184
185 auto blitFramebuffer = GetBlitFramebufferProc(*gl_);
186 blitFramebuffer(0, // srcX0
187 0, // srcY0
188 width, // srcX1
189 height, // srcY1
190 0, // dstX0
191 0, // dstY0
192 width, // dstX1
193 height, // dstY1
194 GL_COLOR_BUFFER_BIT, // mask
195 GL_NEAREST // filter
196 );
197
198 if (!surface->SwapBuffers()) {
199 return false;
200 }
201
202 view->OnFramePresented();
203 return true;
204}
@ kFlutterLayerContentTypeBackingStore
Definition embedder.h:2157
VkSurfaceKHR surface
Definition main.cc:65
FlView * view
const FlutterLayer size_t layers_count
const FlutterLayer ** layers
impeller::ShaderType type
int32_t height
int32_t width
FlutterPoint offset
Definition embedder.h:2200
FlutterLayerContentType type
Definition embedder.h:2189
const FlutterBackingStore * backing_store
Definition embedder.h:2193
FlutterSize size
The size of the layer (in physical pixels).
Definition embedder.h:2202

References FlutterLayer::backing_store, FML_DCHECK, FlutterOpenGLBackingStore::framebuffer, height, FlutterSize::height, kFlutterBackingStoreTypeOpenGL, kFlutterLayerContentTypeBackingStore, kFlutterOpenGLTargetTypeFramebuffer, layers, layers_count, FlutterOpenGLFramebuffer::name, FlutterLayer::offset, FlutterBackingStore::open_gl, FlutterLayer::size, surface, type, FlutterLayer::type, view, width, FlutterSize::width, and FlutterPoint::y.


The documentation for this class was generated from the following files: