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

Commit 30f048d

Browse files
authored
Revert "Fix eglPresentationTimeANDROID is no effective" (#30310)
* Revert "Fix eglPresentationTimeANDROID is no effective (#30182)" This reverts commit 5502a0a. * Revert "Use eglPresentationTimeANDROID to avoid bogging down the GPU (#29727)" This reverts commit 88948de.
1 parent 001f3ef commit 30f048d

21 files changed

+96
-200
lines changed

flow/surface_frame.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include "flutter/common/graphics/gl_context_switch.h"
1212
#include "flutter/fml/macros.h"
13-
#include "flutter/fml/time/time_point.h"
1413
#include "third_party/skia/include/core/SkCanvas.h"
1514
#include "third_party/skia/include/core/SkSurface.h"
1615

@@ -67,12 +66,6 @@ class SurfaceFrame {
6766
//
6867
// Corresponds to EGL_KHR_partial_update
6968
std::optional<SkIRect> buffer_damage;
70-
71-
// The vsync target time.
72-
//
73-
// Backends may use this information to avoid overloading the GPU with
74-
// multiple frames per vsync.
75-
fml::TimePoint target_time;
7669
};
7770

7871
bool Submit();

shell/common/rasterizer.cc

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -548,60 +548,60 @@ RasterStatus Rasterizer::DrawToSurfaceUnsafe(
548548
.supports_readback, // surface supports pixel reads
549549
raster_thread_merger_ // thread merger
550550
);
551-
if (!compositor_frame) {
552-
return RasterStatus::kFailed;
553-
}
551+
if (compositor_frame) {
552+
compositor_context_->raster_cache().PrepareNewFrame();
553+
frame_timings_recorder.RecordRasterStart(fml::TimePoint::Now());
554+
555+
// Disable partial repaint if external_view_embedder_ SubmitFrame is
556+
// involved - ExternalViewEmbedder unconditionally clears the entire
557+
// surface and also partial repaint with platform view present is something
558+
// that still need to be figured out.
559+
bool disable_partial_repaint =
560+
external_view_embedder_ &&
561+
(!raster_thread_merger_ || raster_thread_merger_->IsMerged());
562+
563+
FrameDamage damage;
564+
if (!disable_partial_repaint && frame->framebuffer_info().existing_damage) {
565+
damage.SetPreviousLayerTree(last_layer_tree_.get());
566+
damage.AddAdditonalDamage(*frame->framebuffer_info().existing_damage);
567+
}
554568

555-
compositor_context_->raster_cache().PrepareNewFrame();
556-
frame_timings_recorder.RecordRasterStart(fml::TimePoint::Now());
569+
RasterStatus raster_status =
570+
compositor_frame->Raster(layer_tree, false, &damage);
571+
if (raster_status == RasterStatus::kFailed ||
572+
raster_status == RasterStatus::kSkipAndRetry) {
573+
return raster_status;
574+
}
557575

558-
// Disable partial repaint if external_view_embedder_ SubmitFrame is
559-
// involved - ExternalViewEmbedder unconditionally clears the entire
560-
// surface and also partial repaint with platform view present is something
561-
// that still need to be figured out.
562-
bool disable_partial_repaint =
563-
external_view_embedder_ &&
564-
(!raster_thread_merger_ || raster_thread_merger_->IsMerged());
576+
SurfaceFrame::SubmitInfo submit_info;
577+
submit_info.frame_damage = damage.GetFrameDamage();
578+
submit_info.buffer_damage = damage.GetBufferDamage();
565579

566-
FrameDamage damage;
567-
if (!disable_partial_repaint && frame->framebuffer_info().existing_damage) {
568-
damage.SetPreviousLayerTree(last_layer_tree_.get());
569-
damage.AddAdditonalDamage(*frame->framebuffer_info().existing_damage);
570-
}
571-
572-
RasterStatus raster_status =
573-
compositor_frame->Raster(layer_tree, false, &damage);
574-
if (raster_status == RasterStatus::kFailed ||
575-
raster_status == RasterStatus::kSkipAndRetry) {
576-
return raster_status;
577-
}
580+
frame->set_submit_info(submit_info);
578581

579-
SurfaceFrame::SubmitInfo submit_info;
580-
submit_info.frame_damage = damage.GetFrameDamage();
581-
submit_info.buffer_damage = damage.GetBufferDamage();
582-
submit_info.target_time = frame_timings_recorder.GetVsyncTargetTime();
583-
584-
frame->set_submit_info(submit_info);
582+
if (external_view_embedder_ &&
583+
(!raster_thread_merger_ || raster_thread_merger_->IsMerged())) {
584+
FML_DCHECK(!frame->IsSubmitted());
585+
external_view_embedder_->SubmitFrame(surface_->GetContext(),
586+
std::move(frame));
587+
} else {
588+
frame->Submit();
589+
}
585590

586-
if (external_view_embedder_ &&
587-
(!raster_thread_merger_ || raster_thread_merger_->IsMerged())) {
588-
FML_DCHECK(!frame->IsSubmitted());
589-
external_view_embedder_->SubmitFrame(surface_->GetContext(),
590-
std::move(frame));
591-
} else {
592-
frame->Submit();
593-
}
591+
compositor_context_->raster_cache().CleanupAfterFrame();
592+
frame_timings_recorder.RecordRasterEnd(
593+
&compositor_context_->raster_cache());
594+
FireNextFrameCallbackIfPresent();
594595

595-
compositor_context_->raster_cache().CleanupAfterFrame();
596-
frame_timings_recorder.RecordRasterEnd(&compositor_context_->raster_cache());
597-
FireNextFrameCallbackIfPresent();
596+
if (surface_->GetContext()) {
597+
TRACE_EVENT0("flutter", "PerformDeferredSkiaCleanup");
598+
surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration);
599+
}
598600

599-
if (surface_->GetContext()) {
600-
TRACE_EVENT0("flutter", "PerformDeferredSkiaCleanup");
601-
surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration);
601+
return raster_status;
602602
}
603603

604-
return raster_status;
604+
return RasterStatus::kFailed;
605605
}
606606

607607
static sk_sp<SkData> ScreenshotLayerTreeAsPicture(

shell/common/shell_test_platform_view_gl.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ bool ShellTestPlatformViewGL::GLContextClearCurrent() {
6363
}
6464

6565
// |GPUSurfaceGLDelegate|
66-
bool ShellTestPlatformViewGL::GLContextPresent(fml::TimePoint target_time,
67-
uint32_t fbo_id) {
66+
bool ShellTestPlatformViewGL::GLContextPresent(uint32_t fbo_id) {
6867
return gl_surface_.Present();
6968
}
7069

shell/common/shell_test_platform_view_gl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ShellTestPlatformViewGL : public ShellTestPlatformView,
5858
bool GLContextClearCurrent() override;
5959

6060
// |GPUSurfaceGLDelegate|
61-
bool GLContextPresent(fml::TimePoint target_time, uint32_t fbo_id) override;
61+
bool GLContextPresent(uint32_t fbo_id) override;
6262

6363
// |GPUSurfaceGLDelegate|
6464
intptr_t GLContextFBO(GLFrameInfo frame_info) const override;

shell/gpu/gpu_surface_gl.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
242242
SurfaceFrame::SubmitCallback submit_callback =
243243
[weak = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
244244
SkCanvas* canvas) {
245-
return weak ? weak->PresentSurface(
246-
surface_frame.submit_info().target_time, canvas)
247-
: false;
245+
return weak ? weak->PresentSurface(canvas) : false;
248246
};
249247

250248
framebuffer_info = delegate_->GLContextFramebufferInfo();
@@ -253,8 +251,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
253251
std::move(context_switch));
254252
}
255253

256-
bool GPUSurfaceGL::PresentSurface(fml::TimePoint target_time,
257-
SkCanvas* canvas) {
254+
bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) {
258255
if (delegate_ == nullptr || canvas == nullptr || context_ == nullptr) {
259256
return false;
260257
}
@@ -264,7 +261,7 @@ bool GPUSurfaceGL::PresentSurface(fml::TimePoint target_time,
264261
onscreen_surface_->getCanvas()->flush();
265262
}
266263

267-
if (!delegate_->GLContextPresent(target_time, fbo_id_)) {
264+
if (!delegate_->GLContextPresent(fbo_id_)) {
268265
return false;
269266
}
270267

shell/gpu/gpu_surface_gl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class GPUSurfaceGL : public Surface {
6060
const SkISize& untransformed_size,
6161
const SkMatrix& root_surface_transformation);
6262

63-
bool PresentSurface(fml::TimePoint target_time, SkCanvas* canvas);
63+
bool PresentSurface(SkCanvas* canvas);
6464

6565
GPUSurfaceGLDelegate* delegate_;
6666
sk_sp<GrDirectContext> context_;
@@ -77,7 +77,6 @@ class GPUSurfaceGL : public Surface {
7777

7878
// WeakPtrFactory must be the last member.
7979
fml::TaskRunnerAffineWeakPtrFactory<GPUSurfaceGL> weak_factory_;
80-
8180
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
8281
};
8382

shell/gpu/gpu_surface_gl_delegate.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class GPUSurfaceGLDelegate {
3333

3434
// Called to present the main GL surface. This is only called for the main GL
3535
// context and not any of the contexts dedicated for IO.
36-
virtual bool GLContextPresent(fml::TimePoint target_time,
37-
uint32_t fbo_id) = 0;
36+
virtual bool GLContextPresent(uint32_t fbo_id) = 0;
3837

3938
// The ID of the main window bound framebuffer. Typically FBO0.
4039
virtual intptr_t GLContextFBO(GLFrameInfo frame_info) const = 0;

shell/platform/android/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ executable("flutter_shell_native_unittests") {
4646
public_configs = [ "//flutter:config" ]
4747
deps = [
4848
":flutter_shell_native_src",
49-
"//flutter/fml",
5049
"//third_party/googletest:gmock",
5150
"//third_party/googletest:gtest",
5251
]

shell/platform/android/android_context_gl.cc

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <utility>
1010

11-
#include "android_environment_gl.h"
1211
#include "flutter/fml/trace_event.h"
1312

1413
namespace flutter {
@@ -106,14 +105,13 @@ static bool TeardownContext(EGLDisplay display, EGLContext context) {
106105
return true;
107106
}
108107

109-
AndroidEGLSurface::AndroidEGLSurface(
110-
EGLSurface surface,
111-
fml::RefPtr<AndroidEnvironmentGL> environment,
112-
EGLContext context)
113-
: surface_(surface), environment_(environment), context_(context) {}
108+
AndroidEGLSurface::AndroidEGLSurface(EGLSurface surface,
109+
EGLDisplay display,
110+
EGLContext context)
111+
: surface_(surface), display_(display), context_(context) {}
114112

115113
AndroidEGLSurface::~AndroidEGLSurface() {
116-
auto result = eglDestroySurface(environment_->Display(), surface_);
114+
auto result = eglDestroySurface(display_, surface_);
117115
FML_DCHECK(result == EGL_TRUE);
118116
}
119117

@@ -122,28 +120,25 @@ bool AndroidEGLSurface::IsValid() const {
122120
}
123121

124122
bool AndroidEGLSurface::MakeCurrent() const {
125-
if (eglMakeCurrent(environment_->Display(), surface_, surface_, context_) !=
126-
EGL_TRUE) {
123+
if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) {
127124
FML_LOG(ERROR) << "Could not make the context current";
128125
LogLastEGLError();
129126
return false;
130127
}
131128
return true;
132129
}
133130

134-
bool AndroidEGLSurface::SwapBuffers(fml::TimePoint target_time) {
131+
bool AndroidEGLSurface::SwapBuffers() {
135132
TRACE_EVENT0("flutter", "AndroidContextGL::SwapBuffers");
136-
environment_->SetPresentationTime(surface_, target_time);
137-
return eglSwapBuffers(environment_->Display(), surface_);
133+
return eglSwapBuffers(display_, surface_);
138134
}
139135

140136
SkISize AndroidEGLSurface::GetSize() const {
141137
EGLint width = 0;
142138
EGLint height = 0;
143139

144-
if (!eglQuerySurface(environment_->Display(), surface_, EGL_WIDTH, &width) ||
145-
!eglQuerySurface(environment_->Display(), surface_, EGL_HEIGHT,
146-
&height)) {
140+
if (!eglQuerySurface(display_, surface_, EGL_WIDTH, &width) ||
141+
!eglQuerySurface(display_, surface_, EGL_HEIGHT, &height)) {
147142
FML_LOG(ERROR) << "Unable to query EGL surface size";
148143
LogLastEGLError();
149144
return SkISize::Make(0, 0);
@@ -234,24 +229,27 @@ std::unique_ptr<AndroidEGLSurface> AndroidContextGL::CreateOnscreenSurface(
234229
if (window->IsFakeWindow()) {
235230
return CreatePbufferSurface();
236231
} else {
232+
EGLDisplay display = environment_->Display();
233+
237234
const EGLint attribs[] = {EGL_NONE};
238235

239236
EGLSurface surface = eglCreateWindowSurface(
240-
environment_->Display(), config_,
237+
display, config_,
241238
reinterpret_cast<EGLNativeWindowType>(window->handle()), attribs);
242-
return std::make_unique<AndroidEGLSurface>(surface, environment_, context_);
239+
return std::make_unique<AndroidEGLSurface>(surface, display, context_);
243240
}
244241
}
245242

246243
std::unique_ptr<AndroidEGLSurface> AndroidContextGL::CreateOffscreenSurface()
247244
const {
248245
// We only ever create pbuffer surfaces for background resource loading
249246
// contexts. We never bind the pbuffer to anything.
247+
EGLDisplay display = environment_->Display();
248+
250249
const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
251250

252-
EGLSurface surface =
253-
eglCreatePbufferSurface(environment_->Display(), config_, attribs);
254-
return std::make_unique<AndroidEGLSurface>(surface, environment_,
251+
EGLSurface surface = eglCreatePbufferSurface(display, config_, attribs);
252+
return std::make_unique<AndroidEGLSurface>(surface, display,
255253
resource_context_);
256254
}
257255

@@ -262,7 +260,7 @@ std::unique_ptr<AndroidEGLSurface> AndroidContextGL::CreatePbufferSurface()
262260
const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
263261

264262
EGLSurface surface = eglCreatePbufferSurface(display, config_, attribs);
265-
return std::make_unique<AndroidEGLSurface>(surface, environment_, context_);
263+
return std::make_unique<AndroidEGLSurface>(surface, display, context_);
266264
}
267265

268266
fml::RefPtr<AndroidEnvironmentGL> AndroidContextGL::Environment() const {

shell/platform/android/android_context_gl.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_H_
66
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_H_
77

8-
#include <EGL/egl.h>
9-
#define EGL_EGLEXT_PROTOTYPES
10-
#include <EGL/eglext.h>
11-
128
#include "flutter/fml/macros.h"
139
#include "flutter/fml/memory/ref_counted.h"
1410
#include "flutter/fml/memory/ref_ptr.h"
@@ -29,9 +25,7 @@ namespace flutter {
2925
///
3026
class AndroidEGLSurface {
3127
public:
32-
AndroidEGLSurface(EGLSurface surface,
33-
fml::RefPtr<AndroidEnvironmentGL> environment,
34-
EGLContext context);
28+
AndroidEGLSurface(EGLSurface surface, EGLDisplay display, EGLContext context);
3529
~AndroidEGLSurface();
3630

3731
//----------------------------------------------------------------------------
@@ -53,11 +47,9 @@ class AndroidEGLSurface {
5347
/// @brief This only applies to on-screen surfaces such as those created
5448
/// by `AndroidContextGL::CreateOnscreenSurface`.
5549
///
56-
/// @param target_time The vsync target time for the buffer.
57-
///
5850
/// @return Whether the EGL surface color buffer was swapped.
5951
///
60-
bool SwapBuffers(fml::TimePoint target_time);
52+
bool SwapBuffers();
6153

6254
//----------------------------------------------------------------------------
6355
/// @return The size of an `EGLSurface`.
@@ -66,7 +58,7 @@ class AndroidEGLSurface {
6658

6759
private:
6860
const EGLSurface surface_;
69-
const fml::RefPtr<AndroidEnvironmentGL> environment_;
61+
const EGLDisplay display_;
7062
const EGLContext context_;
7163
};
7264

0 commit comments

Comments
 (0)