Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
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 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 
)

Definition at line 38 of file compositor_opengl.cc.

40 : engine_(engine), resolver_(resolver) {}
FlutterEngine engine
Definition main.cc:68

Member Function Documentation

◆ CollectBackingStore()

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

|Compositor|

Implements flutter::Compositor.

Definition at line 80 of file compositor_opengl.cc.

80 {
81 FML_DCHECK(is_initialized_);
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}
SI void store(P *ptr, const T &val)
@ kFlutterOpenGLTargetTypeFramebuffer
Definition embedder.h:304
@ kFlutterBackingStoreTypeOpenGL
Definition embedder.h:1740
#define FML_DCHECK(condition)
Definition logging.h:103

◆ CreateBackingStore()

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

|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
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}
GAsyncResult * result
FlutterSize size
The size of the render target the engine expects to render into.
Definition embedder.h:1782
double height
Definition embedder.h:423
double width
Definition embedder.h:422

◆ Present()

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

|Compositor|

Implements flutter::Compositor.

Definition at line 95 of file compositor_opengl.cc.

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

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