Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3087090

Browse files
authored
Allow embedders to invalidate FBO bindings after present. (#6084)
1 parent a52724f commit 3087090

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

shell/gpu/gpu_surface_gl.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,25 @@ bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) {
234234
onscreen_surface_->getCanvas()->flush();
235235
}
236236

237-
delegate_->GLContextPresent();
237+
if (!delegate_->GLContextPresent()) {
238+
return false;
239+
}
240+
241+
if (delegate_->GLContextFBOResetAfterPresent()) {
242+
auto current_size =
243+
SkISize::Make(onscreen_surface_->width(), onscreen_surface_->height());
244+
245+
// The FBO has changed, ask the delegate for the new FBO and do a surface
246+
// re-wrap.
247+
auto new_onscreen_surface = WrapOnscreenSurface(
248+
context_.get(), current_size, delegate_->GLContextFBO());
249+
250+
if (!new_onscreen_surface) {
251+
return false;
252+
}
253+
254+
onscreen_surface_ = std::move(new_onscreen_surface);
255+
}
238256

239257
return true;
240258
}

shell/gpu/gpu_surface_gl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class GPUSurfaceGLDelegate {
2222

2323
virtual intptr_t GLContextFBO() const = 0;
2424

25+
virtual bool GLContextFBOResetAfterPresent() const { return false; }
26+
2527
virtual bool UseOffscreenSurface() const { return false; }
2628
};
2729

shell/platform/embedder/embedder.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ FlutterResult FlutterEngineRun(size_t version,
128128
user_data]() { return ptr(user_data); };
129129
}
130130

131+
bool fbo_reset_after_present =
132+
SAFE_ACCESS(open_gl_config, fbo_reset_after_present, false);
133+
131134
std::string icu_data_path;
132135
if (SAFE_ACCESS(args, icu_data_path, nullptr) != nullptr) {
133136
icu_data_path = SAFE_ACCESS(args, icu_data_path, nullptr);
@@ -194,11 +197,12 @@ FlutterResult FlutterEngineRun(size_t version,
194197
};
195198

196199
shell::Shell::CreateCallback<shell::PlatformView> on_create_platform_view =
197-
[dispatch_table](shell::Shell& shell) {
200+
[dispatch_table, fbo_reset_after_present](shell::Shell& shell) {
198201
return std::make_unique<shell::PlatformViewEmbedder>(
199202
shell, // delegate
200203
shell.GetTaskRunners(), // task runners
201-
dispatch_table // embedder dispatch table
204+
dispatch_table, // embedder dispatch table
205+
fbo_reset_after_present // fbo reset after present
202206
);
203207
};
204208

shell/platform/embedder/embedder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ typedef struct {
4242
BoolCallback present;
4343
UIntCallback fbo_callback;
4444
BoolCallback make_resource_current;
45+
// By default, the renderer config assumes that the FBO does not change for
46+
// the duration of the engine run. If this argument is true, the
47+
// engine will ask the embedder for an updated FBO target (via an fbo_callback
48+
// invocation) after a present call.
49+
bool fbo_reset_after_present;
4550
} FlutterOpenGLRendererConfig;
4651

4752
typedef struct {

shell/platform/embedder/platform_view_embedder.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,39 @@ namespace shell {
1010

1111
PlatformViewEmbedder::PlatformViewEmbedder(PlatformView::Delegate& delegate,
1212
blink::TaskRunners task_runners,
13-
DispatchTable dispatch_table)
13+
DispatchTable dispatch_table,
14+
bool fbo_reset_after_present)
1415
: PlatformView(delegate, std::move(task_runners)),
15-
dispatch_table_(dispatch_table) {}
16+
dispatch_table_(dispatch_table),
17+
fbo_reset_after_present_(fbo_reset_after_present) {}
1618

1719
PlatformViewEmbedder::~PlatformViewEmbedder() = default;
1820

21+
// |shell::GPUSurfaceGLDelegate|
1922
bool PlatformViewEmbedder::GLContextMakeCurrent() {
2023
return dispatch_table_.gl_make_current_callback();
2124
}
2225

26+
// |shell::GPUSurfaceGLDelegate|
2327
bool PlatformViewEmbedder::GLContextClearCurrent() {
2428
return dispatch_table_.gl_clear_current_callback();
2529
}
2630

31+
// |shell::GPUSurfaceGLDelegate|
2732
bool PlatformViewEmbedder::GLContextPresent() {
2833
return dispatch_table_.gl_present_callback();
2934
}
3035

36+
// |shell::GPUSurfaceGLDelegate|
3137
intptr_t PlatformViewEmbedder::GLContextFBO() const {
3238
return dispatch_table_.gl_fbo_callback();
3339
}
3440

41+
// |shell::GPUSurfaceGLDelegate|
42+
bool PlatformViewEmbedder::GLContextFBOResetAfterPresent() const {
43+
return fbo_reset_after_present_;
44+
}
45+
3546
void PlatformViewEmbedder::HandlePlatformMessage(
3647
fml::RefPtr<blink::PlatformMessage> message) {
3748
if (!message) {

shell/platform/embedder/platform_view_embedder.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class PlatformViewEmbedder final : public PlatformView,
2929

3030
PlatformViewEmbedder(PlatformView::Delegate& delegate,
3131
blink::TaskRunners task_runners,
32-
DispatchTable dispatch_table);
32+
DispatchTable dispatch_table,
33+
bool fbo_reset_after_present);
3334

3435
~PlatformViewEmbedder() override;
3536

@@ -45,12 +46,16 @@ class PlatformViewEmbedder final : public PlatformView,
4546
// |shell::GPUSurfaceGLDelegate|
4647
intptr_t GLContextFBO() const override;
4748

49+
// |shell::GPUSurfaceGLDelegate|
50+
bool GLContextFBOResetAfterPresent() const override;
51+
4852
// |shell::PlatformView|
4953
void HandlePlatformMessage(
5054
fml::RefPtr<blink::PlatformMessage> message) override;
5155

5256
private:
5357
DispatchTable dispatch_table_;
58+
bool fbo_reset_after_present_;
5459

5560
// |shell::PlatformView|
5661
std::unique_ptr<Surface> CreateRenderingSurface() override;

0 commit comments

Comments
 (0)