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 (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)
overridevirtual

|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 
)
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 
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 ( const FlutterLayer **  layers,
size_t  layers_count 
)
overridevirtual

|Compositor|

Implements flutter::Compositor.

Definition at line 95 of file compositor_opengl.cc.

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

References flutter::egl::Surface::IsValid(), flutter::kImplicitViewId, 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:
flutter::kImplicitViewId
constexpr FlutterViewId kImplicitViewId
Definition: flutter_windows_engine.h:54
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