Flutter Engine
 
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 39 of file compositor_opengl.cc.

42 : 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 108 of file compositor_opengl.cc.

108 {
109 FML_DCHECK(is_initialized_);
112
113 auto user_data = static_cast<FramebufferBackingStore*>(
115
116 gl_->DeleteFramebuffers(1, &user_data->framebuffer_id);
117 gl_->DeleteTextures(1, &user_data->texture_id);
118
119 delete user_data;
120 return true;
121}
@ kFlutterOpenGLTargetTypeFramebuffer
Definition embedder.h:417
@ kFlutterBackingStoreTypeOpenGL
Definition embedder.h:2051
#define FML_DCHECK(condition)
Definition logging.h:122
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2071
FlutterOpenGLBackingStore open_gl
The description of the OpenGL backing store.
Definition embedder.h:2077
FlutterOpenGLTargetType type
Definition embedder.h:1914
FlutterOpenGLFramebuffer framebuffer
Definition embedder.h:1920
void * user_data
User data to be returned on the invocation of the destruction callback.
Definition embedder.h:547

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 44 of file compositor_opengl.cc.

46 {
47 if (!is_initialized_ && !Initialize()) {
48 return false;
49 }
50
51 auto store = std::make_unique<FramebufferBackingStore>();
52
53 gl_->GenTextures(1, &store->texture_id);
54 gl_->GenFramebuffers(1, &store->framebuffer_id);
55
56 gl_->BindFramebuffer(GL_FRAMEBUFFER, store->framebuffer_id);
57
58 gl_->BindTexture(GL_TEXTURE_2D, store->texture_id);
59 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
60 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
61 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
62 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
63 gl_->TexImage2D(GL_TEXTURE_2D, 0, format_.general_format, config.size.width,
64 config.size.height, 0, format_.general_format,
65 GL_UNSIGNED_BYTE, nullptr);
66 gl_->BindTexture(GL_TEXTURE_2D, 0);
67
68 if (enable_impeller_) {
69 // Impeller requries that its onscreen surface is Multisampled and already
70 // has depth/stencil attached in order for anti-aliasing to work.
71 gl_->FramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER,
72 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
73 store->texture_id, 0, 4);
74
75 // Set up depth/stencil attachment for impeller renderer.
76 GLuint depth_stencil;
77 gl_->GenRenderbuffers(1, &depth_stencil);
78 gl_->BindRenderbuffer(GL_RENDERBUFFER, depth_stencil);
79 gl_->RenderbufferStorageMultisampleEXT(
80 GL_RENDERBUFFER, // target
81 4, // samples
82 GL_DEPTH24_STENCIL8, // internal format
83 config.size.width, // width
84 config.size.height // height
85 );
86 gl_->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
87 GL_RENDERBUFFER, depth_stencil);
88 gl_->FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
89 GL_RENDERBUFFER, depth_stencil);
90
91 } else {
92 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
93 GL_TEXTURE_2D, store->texture_id, 0);
94 }
95
98 result->open_gl.framebuffer.name = store->framebuffer_id;
99 result->open_gl.framebuffer.target = format_.sized_format;
100 result->open_gl.framebuffer.user_data = store.release();
102 // Backing store destroyed in `CompositorOpenGL::CollectBackingStore`, set
103 // on FlutterCompositor.collect_backing_store_callback during engine start.
104 };
105 return true;
106}
FlutterSize size
The size of the render target the engine expects to render into.
Definition embedder.h:2093
uint32_t name
The name of the framebuffer.
Definition embedder.h:544
VoidCallback destruction_callback
Definition embedder.h:551
double height
Definition embedder.h:629
double width
Definition embedder.h:628

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 123 of file compositor_opengl.cc.

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

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: