| Flutter Windows Embedder |

Classes | Public Member Functions | List of all members
flutter::CompositorOpenGL Class Reference

`#include <compositor_opengl.h>`

Inheritance diagram for flutter::CompositorOpenGL:

## Public Member Functions
| CompositorOpenGL (FlutterWindowsEngine *engine, impeller::ProcTableGLES::Resolver resolver, bool enable_impeller)
bool | CreateBackingStore (const FlutterBackingStoreConfig &config, FlutterBackingStore *result) override
| |Compositor| More...
bool | CollectBackingStore (const FlutterBackingStore *store) override
| |Compositor| More...
bool | Present (FlutterWindowsView *view, const FlutterLayer **layers, size_t layers_count) override
| |Compositor| More...
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) {}

## 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_);
110 FML_DCHECK(store->type == kFlutterBackingStoreTypeOpenGL);
111 FML_DCHECK(store->open_gl.type == kFlutterOpenGLTargetTypeFramebuffer);
112
113 auto user_data = static_cast<FramebufferBackingStore*>(
114 store->open_gl.framebuffer.user_data);
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 }
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:53

References 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
96 result->type = kFlutterBackingStoreTypeOpenGL;
97 result->open_gl.type = kFlutterOpenGLTargetTypeFramebuffer;
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();
101 result->open_gl.framebuffer.destruction_callback = [](void* user_data) {
102 // Backing store destroyed in `CompositorOpenGL::CollectBackingStore`, set
103 // on FlutterCompositor.collect_backing_store_callback during engine start.
104 };
105 return true;
106 }

References user_data.

## ◆ 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_);
143 FML_DCHECK(layers_count == 1);
144 FML_DCHECK(layers[0]->offset.x == 0 && layers[0]->offset.y == 0);
145 FML_DCHECK(layers[0]->type == kFlutterLayerContentTypeBackingStore);
146 FML_DCHECK(layers[0]->backing_store->type == kFlutterBackingStoreTypeOpenGL);
147 FML_DCHECK(layers[0]->backing_store->open_gl.type ==
148 kFlutterOpenGLTargetTypeFramebuffer);
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 }
type
enum flutter::testing::@90::KeyboardChange::Type type

References flutter::egl::Surface::IsValid(), flutter::egl::Surface::MakeCurrent(), flutter::FlutterWindowsView::OnFrameGenerated(), flutter::FlutterWindowsView::OnFramePresented(), flutter::FlutterWindowsView::surface(), flutter::egl::Surface::SwapBuffers(), and type.

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

- shell/platform/windows/compositor_opengl.h
- shell/platform/windows/compositor_opengl.cc