| Flutter Windows Embedder |

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 | CreateBackingStore (const FlutterBackingStoreConfig &config, FlutterBackingStore *result) override
| |Compositor| More...
bool | CollectBackingStore (const FlutterBackingStore *store) override
| |Compositor| More...
bool | Present (FlutterViewId view_id, 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 18 of file compositor_opengl.h.

## Constructor & Destructor Documentation

## ◆ CompositorOpenGL()

flutter::CompositorOpenGL::CompositorOpenGL | ( | FlutterWindowsEngine * | engine,
|  | impeller::ProcTableGLES::Resolver | resolver
| ) |  |

Definition at line 38 of file compositor_opengl.cc.

40 : engine_(engine), resolver_(resolver) {}

## Member Function Documentation

## ◆ CollectBackingStore()

bool flutter::CompositorOpenGL::CollectBackingStore | ( | const FlutterBackingStore * | store | ) |
| override virtual

|Compositor|

Implements flutter::Compositor.

Definition at line 80 of file compositor_opengl.cc.

80 {
81 FML_DCHECK(is_initialized_);
82 FML_DCHECK(store->type == kFlutterBackingStoreTypeOpenGL);
83 FML_DCHECK(store->open_gl.type == kFlutterOpenGLTargetTypeFramebuffer);
84
85 auto user_data = static_cast<FramebufferBackingStore*>(
86 store->open_gl.framebuffer.user_data);
87
88 gl_->DeleteFramebuffers(1, &user_data->framebuffer_id);
89 gl_->DeleteTextures(1, &user_data->texture_id);
90
91 delete user_data;
92 return true;
93 }

References user_data.

## ◆ CreateBackingStore()

bool flutter::CompositorOpenGL::CreateBackingStore | ( | const FlutterBackingStoreConfig & | config,
|  | FlutterBackingStore * | result
| ) |  |
| override virtual

|Compositor|

Implements flutter::Compositor.

Definition at line 42 of file compositor_opengl.cc.

44 {
45 if (!is_initialized_ && !Initialize()) {
46 return false;
47 }
48
49 auto store = std::make_unique<FramebufferBackingStore>();
50
51 gl_->GenTextures(1, &store->texture_id);
52 gl_->GenFramebuffers(1, &store->framebuffer_id);
53
54 gl_->BindFramebuffer(GL_FRAMEBUFFER, store->framebuffer_id);
55
56 gl_->BindTexture(GL_TEXTURE_2D, store->texture_id);
57 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
58 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
59 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
60 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
61 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, config.size.width,
62 config.size.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
63 gl_->BindTexture(GL_TEXTURE_2D, 0);
64
65 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT,
66 GL_TEXTURE_2D, store->texture_id, 0);
67
68 result->type = kFlutterBackingStoreTypeOpenGL;
69 result->open_gl.type = kFlutterOpenGLTargetTypeFramebuffer;
70 result->open_gl.framebuffer.name = store->framebuffer_id;
71 result->open_gl.framebuffer.target = format_;
72 result->open_gl.framebuffer.user_data = store.release();
73 result->open_gl.framebuffer.destruction_callback = [](void* user_data) {
74 // Backing store destroyed in `CompositorOpenGL::CollectBackingStore`, set
75 // on FlutterCompositor.collect_backing_store_callback during engine start.
76 };
77 return true;
78 }

References user_data.

## ◆ Present()

bool flutter::CompositorOpenGL::Present | ( | FlutterViewId | view_id,
|  | const FlutterLayer ** | layers,
|  | size_t | layers_count
| ) |  |
| override virtual

|Compositor|

Implements flutter::Compositor.

Definition at line 95 of file compositor_opengl.cc.

97 {
98 FlutterWindowsView* view = engine_->view(view_id);
99 if (!view) {
100 return false;
101 }
102
103 // Clear the view if there are no layers to present.
104 if (layers_count == 0) {
105 // Normally the compositor is initialized when the first backing store is
106 // created. However, on an empty frame no backing stores are created and
107 // the present needs to initialize the compositor.
108 if (!is_initialized_ && !Initialize()) {
109 return false;
110 }
111
112 return Clear(view);
113 }
114
115 // TODO: Support compositing layers and platform views.
116 // See: https://github.com/flutter/flutter/issues/31713
117 FML_DCHECK(is_initialized_);
118 FML_DCHECK(layers_count == 1);
119 FML_DCHECK(layers[0]->offset.x == 0 && layers[0]->offset.y == 0);
120 FML_DCHECK(layers[0]->type == kFlutterLayerContentTypeBackingStore);
121 FML_DCHECK(layers[0]->backing_store->type == kFlutterBackingStoreTypeOpenGL);
122 FML_DCHECK(layers[0]->backing_store->open_gl.type ==
123 kFlutterOpenGLTargetTypeFramebuffer);
124
125 auto width = layers[0]->size.width;
126 auto height = layers[0]->size.height;
127
128 // Check if this frame can be presented. This resizes the surface if a resize
129 // is pending and |width| and |height| match the target size.
130 if (!view->OnFrameGenerated(width, height)) {
131 return false;
132 }
133
134 // |OnFrameGenerated| should return false if the surface isn't valid.
135 FML_DCHECK(view->surface() != nullptr);
136 FML_DCHECK(view->surface()->IsValid());
137
138 egl::WindowSurface* surface = view->surface();
139 if (!surface->MakeCurrent()) {
140 return false;
141 }
142
143 auto source_id = layers[0]->backing_store->open_gl.framebuffer.name;
144
145 // Disable the scissor test as it can affect blit operations.
146 // Prevents regressions like: https://github.com/flutter/flutter/issues/140828
147 // See OpenGL specification version 4.6, section 18.3.1.
148 gl_->Disable(GL_SCISSOR_TEST);
149
150 gl_->BindFramebuffer(GL_READ_FRAMEBUFFER, source_id);
151 gl_->BindFramebuffer(GL_DRAW_FRAMEBUFFER, kWindowFrameBufferId);
152
153 gl_->BlitFramebuffer(0, // srcX0
154 0, // srcY0
155 width, // srcX1
156 height, // srcY1
157 0, // dstX0
158 0, // dstY0
159 width, // dstX1
160 height, // dstY1
161 GL_COLOR_BUFFER_BIT, // mask
162 GL_NEAREST // filter
163 );
164
165 if (!surface->SwapBuffers()) {
166 return false;
167 }
168
169 view->OnFramePresented();
170 return true;
171 }

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

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

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

flutter::FlutterWindowsEngine::view
FlutterWindowsView * view(FlutterViewId view_id) const
Definition: flutter_windows_engine.cc:533
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:52
type
enum flutter::testing::@87::KeyboardChange::Type type