Flutter Windows Embedder
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| 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 
)

Definition at line 25 of file compositor_opengl.cc.

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

Member Function Documentation

◆ CollectBackingStore()

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

|Compositor|

Implements flutter::Compositor.

Definition at line 68 of file compositor_opengl.cc.

68  {
69  FML_DCHECK(is_initialized_);
70  FML_DCHECK(store->type == kFlutterBackingStoreTypeOpenGL);
71  FML_DCHECK(store->open_gl.type == kFlutterOpenGLTargetTypeFramebuffer);
72 
73  auto user_data = static_cast<FramebufferBackingStore*>(
74  store->open_gl.framebuffer.user_data);
75 
76  gl_->DeleteFramebuffers(1, &user_data->framebuffer_id);
77  gl_->DeleteTextures(1, &user_data->texture_id);
78 
79  delete user_data;
80  return true;
81 }

References user_data.

◆ CreateBackingStore()

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

|Compositor|

Implements flutter::Compositor.

Definition at line 29 of file compositor_opengl.cc.

31  {
32  if (!is_initialized_ && !Initialize()) {
33  return false;
34  }
35 
36  auto store = std::make_unique<FramebufferBackingStore>();
37 
38  gl_->GenTextures(1, &store->texture_id);
39  gl_->GenFramebuffers(1, &store->framebuffer_id);
40 
41  gl_->BindFramebuffer(GL_FRAMEBUFFER, store->framebuffer_id);
42 
43  gl_->BindTexture(GL_TEXTURE_2D, store->texture_id);
44  gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
45  gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
46  gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
47  gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
48  gl_->TexImage2D(GL_TEXTURE_2D, 0, format_.general_format, config.size.width,
49  config.size.height, 0, format_.general_format,
50  GL_UNSIGNED_BYTE, nullptr);
51  gl_->BindTexture(GL_TEXTURE_2D, 0);
52 
53  gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
54  store->texture_id, 0);
55 
56  result->type = kFlutterBackingStoreTypeOpenGL;
57  result->open_gl.type = kFlutterOpenGLTargetTypeFramebuffer;
58  result->open_gl.framebuffer.name = store->framebuffer_id;
59  result->open_gl.framebuffer.target = format_.sized_format;
60  result->open_gl.framebuffer.user_data = store.release();
61  result->open_gl.framebuffer.destruction_callback = [](void* user_data) {
62  // Backing store destroyed in `CompositorOpenGL::CollectBackingStore`, set
63  // on FlutterCompositor.collect_backing_store_callback during engine start.
64  };
65  return true;
66 }

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

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

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:
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:53
type
enum flutter::testing::@88::KeyboardChange::Type type