Revert "Fix eglPresentationTimeANDROID is no effective" (flutter/engine#30310)
* Revert "Fix eglPresentationTimeANDROID is no effective (#30182)" This reverts commit0d7ba05d34. * Revert "Use eglPresentationTimeANDROID to avoid bogging down the GPU (#29727)" This reverts commitedb87942de.
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "flutter/common/graphics/gl_context_switch.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/time/time_point.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
|
||||
@@ -67,12 +66,6 @@ class SurfaceFrame {
|
||||
//
|
||||
// Corresponds to EGL_KHR_partial_update
|
||||
std::optional<SkIRect> buffer_damage;
|
||||
|
||||
// The vsync target time.
|
||||
//
|
||||
// Backends may use this information to avoid overloading the GPU with
|
||||
// multiple frames per vsync.
|
||||
fml::TimePoint target_time;
|
||||
};
|
||||
|
||||
bool Submit();
|
||||
|
||||
@@ -548,60 +548,60 @@ RasterStatus Rasterizer::DrawToSurfaceUnsafe(
|
||||
.supports_readback, // surface supports pixel reads
|
||||
raster_thread_merger_ // thread merger
|
||||
);
|
||||
if (!compositor_frame) {
|
||||
return RasterStatus::kFailed;
|
||||
}
|
||||
if (compositor_frame) {
|
||||
compositor_context_->raster_cache().PrepareNewFrame();
|
||||
frame_timings_recorder.RecordRasterStart(fml::TimePoint::Now());
|
||||
|
||||
compositor_context_->raster_cache().PrepareNewFrame();
|
||||
frame_timings_recorder.RecordRasterStart(fml::TimePoint::Now());
|
||||
// Disable partial repaint if external_view_embedder_ SubmitFrame is
|
||||
// involved - ExternalViewEmbedder unconditionally clears the entire
|
||||
// surface and also partial repaint with platform view present is something
|
||||
// that still need to be figured out.
|
||||
bool disable_partial_repaint =
|
||||
external_view_embedder_ &&
|
||||
(!raster_thread_merger_ || raster_thread_merger_->IsMerged());
|
||||
|
||||
// Disable partial repaint if external_view_embedder_ SubmitFrame is
|
||||
// involved - ExternalViewEmbedder unconditionally clears the entire
|
||||
// surface and also partial repaint with platform view present is something
|
||||
// that still need to be figured out.
|
||||
bool disable_partial_repaint =
|
||||
external_view_embedder_ &&
|
||||
(!raster_thread_merger_ || raster_thread_merger_->IsMerged());
|
||||
FrameDamage damage;
|
||||
if (!disable_partial_repaint && frame->framebuffer_info().existing_damage) {
|
||||
damage.SetPreviousLayerTree(last_layer_tree_.get());
|
||||
damage.AddAdditonalDamage(*frame->framebuffer_info().existing_damage);
|
||||
}
|
||||
|
||||
FrameDamage damage;
|
||||
if (!disable_partial_repaint && frame->framebuffer_info().existing_damage) {
|
||||
damage.SetPreviousLayerTree(last_layer_tree_.get());
|
||||
damage.AddAdditonalDamage(*frame->framebuffer_info().existing_damage);
|
||||
}
|
||||
RasterStatus raster_status =
|
||||
compositor_frame->Raster(layer_tree, false, &damage);
|
||||
if (raster_status == RasterStatus::kFailed ||
|
||||
raster_status == RasterStatus::kSkipAndRetry) {
|
||||
return raster_status;
|
||||
}
|
||||
|
||||
SurfaceFrame::SubmitInfo submit_info;
|
||||
submit_info.frame_damage = damage.GetFrameDamage();
|
||||
submit_info.buffer_damage = damage.GetBufferDamage();
|
||||
|
||||
frame->set_submit_info(submit_info);
|
||||
|
||||
if (external_view_embedder_ &&
|
||||
(!raster_thread_merger_ || raster_thread_merger_->IsMerged())) {
|
||||
FML_DCHECK(!frame->IsSubmitted());
|
||||
external_view_embedder_->SubmitFrame(surface_->GetContext(),
|
||||
std::move(frame));
|
||||
} else {
|
||||
frame->Submit();
|
||||
}
|
||||
|
||||
compositor_context_->raster_cache().CleanupAfterFrame();
|
||||
frame_timings_recorder.RecordRasterEnd(
|
||||
&compositor_context_->raster_cache());
|
||||
FireNextFrameCallbackIfPresent();
|
||||
|
||||
if (surface_->GetContext()) {
|
||||
TRACE_EVENT0("flutter", "PerformDeferredSkiaCleanup");
|
||||
surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration);
|
||||
}
|
||||
|
||||
RasterStatus raster_status =
|
||||
compositor_frame->Raster(layer_tree, false, &damage);
|
||||
if (raster_status == RasterStatus::kFailed ||
|
||||
raster_status == RasterStatus::kSkipAndRetry) {
|
||||
return raster_status;
|
||||
}
|
||||
|
||||
SurfaceFrame::SubmitInfo submit_info;
|
||||
submit_info.frame_damage = damage.GetFrameDamage();
|
||||
submit_info.buffer_damage = damage.GetBufferDamage();
|
||||
submit_info.target_time = frame_timings_recorder.GetVsyncTargetTime();
|
||||
|
||||
frame->set_submit_info(submit_info);
|
||||
|
||||
if (external_view_embedder_ &&
|
||||
(!raster_thread_merger_ || raster_thread_merger_->IsMerged())) {
|
||||
FML_DCHECK(!frame->IsSubmitted());
|
||||
external_view_embedder_->SubmitFrame(surface_->GetContext(),
|
||||
std::move(frame));
|
||||
} else {
|
||||
frame->Submit();
|
||||
}
|
||||
|
||||
compositor_context_->raster_cache().CleanupAfterFrame();
|
||||
frame_timings_recorder.RecordRasterEnd(&compositor_context_->raster_cache());
|
||||
FireNextFrameCallbackIfPresent();
|
||||
|
||||
if (surface_->GetContext()) {
|
||||
TRACE_EVENT0("flutter", "PerformDeferredSkiaCleanup");
|
||||
surface_->GetContext()->performDeferredCleanup(kSkiaCleanupExpiration);
|
||||
}
|
||||
|
||||
return raster_status;
|
||||
return RasterStatus::kFailed;
|
||||
}
|
||||
|
||||
static sk_sp<SkData> ScreenshotLayerTreeAsPicture(
|
||||
|
||||
@@ -63,8 +63,7 @@ bool ShellTestPlatformViewGL::GLContextClearCurrent() {
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool ShellTestPlatformViewGL::GLContextPresent(fml::TimePoint target_time,
|
||||
uint32_t fbo_id) {
|
||||
bool ShellTestPlatformViewGL::GLContextPresent(uint32_t fbo_id) {
|
||||
return gl_surface_.Present();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class ShellTestPlatformViewGL : public ShellTestPlatformView,
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextPresent(fml::TimePoint target_time, uint32_t fbo_id) override;
|
||||
bool GLContextPresent(uint32_t fbo_id) override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t GLContextFBO(GLFrameInfo frame_info) const override;
|
||||
|
||||
@@ -242,9 +242,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
|
||||
SurfaceFrame::SubmitCallback submit_callback =
|
||||
[weak = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
|
||||
SkCanvas* canvas) {
|
||||
return weak ? weak->PresentSurface(
|
||||
surface_frame.submit_info().target_time, canvas)
|
||||
: false;
|
||||
return weak ? weak->PresentSurface(canvas) : false;
|
||||
};
|
||||
|
||||
framebuffer_info = delegate_->GLContextFramebufferInfo();
|
||||
@@ -253,8 +251,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
|
||||
std::move(context_switch));
|
||||
}
|
||||
|
||||
bool GPUSurfaceGL::PresentSurface(fml::TimePoint target_time,
|
||||
SkCanvas* canvas) {
|
||||
bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) {
|
||||
if (delegate_ == nullptr || canvas == nullptr || context_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -264,7 +261,7 @@ bool GPUSurfaceGL::PresentSurface(fml::TimePoint target_time,
|
||||
onscreen_surface_->getCanvas()->flush();
|
||||
}
|
||||
|
||||
if (!delegate_->GLContextPresent(target_time, fbo_id_)) {
|
||||
if (!delegate_->GLContextPresent(fbo_id_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class GPUSurfaceGL : public Surface {
|
||||
const SkISize& untransformed_size,
|
||||
const SkMatrix& root_surface_transformation);
|
||||
|
||||
bool PresentSurface(fml::TimePoint target_time, SkCanvas* canvas);
|
||||
bool PresentSurface(SkCanvas* canvas);
|
||||
|
||||
GPUSurfaceGLDelegate* delegate_;
|
||||
sk_sp<GrDirectContext> context_;
|
||||
@@ -77,7 +77,6 @@ class GPUSurfaceGL : public Surface {
|
||||
|
||||
// WeakPtrFactory must be the last member.
|
||||
fml::TaskRunnerAffineWeakPtrFactory<GPUSurfaceGL> weak_factory_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
|
||||
};
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ class GPUSurfaceGLDelegate {
|
||||
|
||||
// Called to present the main GL surface. This is only called for the main GL
|
||||
// context and not any of the contexts dedicated for IO.
|
||||
virtual bool GLContextPresent(fml::TimePoint target_time,
|
||||
uint32_t fbo_id) = 0;
|
||||
virtual bool GLContextPresent(uint32_t fbo_id) = 0;
|
||||
|
||||
// The ID of the main window bound framebuffer. Typically FBO0.
|
||||
virtual intptr_t GLContextFBO(GLFrameInfo frame_info) const = 0;
|
||||
|
||||
@@ -46,7 +46,6 @@ executable("flutter_shell_native_unittests") {
|
||||
public_configs = [ "//flutter:config" ]
|
||||
deps = [
|
||||
":flutter_shell_native_src",
|
||||
"//flutter/fml",
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest",
|
||||
]
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "android_environment_gl.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
|
||||
namespace flutter {
|
||||
@@ -106,14 +105,13 @@ static bool TeardownContext(EGLDisplay display, EGLContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
AndroidEGLSurface::AndroidEGLSurface(
|
||||
EGLSurface surface,
|
||||
fml::RefPtr<AndroidEnvironmentGL> environment,
|
||||
EGLContext context)
|
||||
: surface_(surface), environment_(environment), context_(context) {}
|
||||
AndroidEGLSurface::AndroidEGLSurface(EGLSurface surface,
|
||||
EGLDisplay display,
|
||||
EGLContext context)
|
||||
: surface_(surface), display_(display), context_(context) {}
|
||||
|
||||
AndroidEGLSurface::~AndroidEGLSurface() {
|
||||
auto result = eglDestroySurface(environment_->Display(), surface_);
|
||||
auto result = eglDestroySurface(display_, surface_);
|
||||
FML_DCHECK(result == EGL_TRUE);
|
||||
}
|
||||
|
||||
@@ -122,8 +120,7 @@ bool AndroidEGLSurface::IsValid() const {
|
||||
}
|
||||
|
||||
bool AndroidEGLSurface::MakeCurrent() const {
|
||||
if (eglMakeCurrent(environment_->Display(), surface_, surface_, context_) !=
|
||||
EGL_TRUE) {
|
||||
if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) {
|
||||
FML_LOG(ERROR) << "Could not make the context current";
|
||||
LogLastEGLError();
|
||||
return false;
|
||||
@@ -131,19 +128,17 @@ bool AndroidEGLSurface::MakeCurrent() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AndroidEGLSurface::SwapBuffers(fml::TimePoint target_time) {
|
||||
bool AndroidEGLSurface::SwapBuffers() {
|
||||
TRACE_EVENT0("flutter", "AndroidContextGL::SwapBuffers");
|
||||
environment_->SetPresentationTime(surface_, target_time);
|
||||
return eglSwapBuffers(environment_->Display(), surface_);
|
||||
return eglSwapBuffers(display_, surface_);
|
||||
}
|
||||
|
||||
SkISize AndroidEGLSurface::GetSize() const {
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
|
||||
if (!eglQuerySurface(environment_->Display(), surface_, EGL_WIDTH, &width) ||
|
||||
!eglQuerySurface(environment_->Display(), surface_, EGL_HEIGHT,
|
||||
&height)) {
|
||||
if (!eglQuerySurface(display_, surface_, EGL_WIDTH, &width) ||
|
||||
!eglQuerySurface(display_, surface_, EGL_HEIGHT, &height)) {
|
||||
FML_LOG(ERROR) << "Unable to query EGL surface size";
|
||||
LogLastEGLError();
|
||||
return SkISize::Make(0, 0);
|
||||
@@ -234,12 +229,14 @@ std::unique_ptr<AndroidEGLSurface> AndroidContextGL::CreateOnscreenSurface(
|
||||
if (window->IsFakeWindow()) {
|
||||
return CreatePbufferSurface();
|
||||
} else {
|
||||
EGLDisplay display = environment_->Display();
|
||||
|
||||
const EGLint attribs[] = {EGL_NONE};
|
||||
|
||||
EGLSurface surface = eglCreateWindowSurface(
|
||||
environment_->Display(), config_,
|
||||
display, config_,
|
||||
reinterpret_cast<EGLNativeWindowType>(window->handle()), attribs);
|
||||
return std::make_unique<AndroidEGLSurface>(surface, environment_, context_);
|
||||
return std::make_unique<AndroidEGLSurface>(surface, display, context_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,11 +244,12 @@ std::unique_ptr<AndroidEGLSurface> AndroidContextGL::CreateOffscreenSurface()
|
||||
const {
|
||||
// We only ever create pbuffer surfaces for background resource loading
|
||||
// contexts. We never bind the pbuffer to anything.
|
||||
EGLDisplay display = environment_->Display();
|
||||
|
||||
const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
|
||||
|
||||
EGLSurface surface =
|
||||
eglCreatePbufferSurface(environment_->Display(), config_, attribs);
|
||||
return std::make_unique<AndroidEGLSurface>(surface, environment_,
|
||||
EGLSurface surface = eglCreatePbufferSurface(display, config_, attribs);
|
||||
return std::make_unique<AndroidEGLSurface>(surface, display,
|
||||
resource_context_);
|
||||
}
|
||||
|
||||
@@ -262,7 +260,7 @@ std::unique_ptr<AndroidEGLSurface> AndroidContextGL::CreatePbufferSurface()
|
||||
const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
|
||||
|
||||
EGLSurface surface = eglCreatePbufferSurface(display, config_, attribs);
|
||||
return std::make_unique<AndroidEGLSurface>(surface, environment_, context_);
|
||||
return std::make_unique<AndroidEGLSurface>(surface, display, context_);
|
||||
}
|
||||
|
||||
fml::RefPtr<AndroidEnvironmentGL> AndroidContextGL::Environment() const {
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_GL_H_
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#define EGL_EGLEXT_PROTOTYPES
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/memory/ref_ptr.h"
|
||||
@@ -29,9 +25,7 @@ namespace flutter {
|
||||
///
|
||||
class AndroidEGLSurface {
|
||||
public:
|
||||
AndroidEGLSurface(EGLSurface surface,
|
||||
fml::RefPtr<AndroidEnvironmentGL> environment,
|
||||
EGLContext context);
|
||||
AndroidEGLSurface(EGLSurface surface, EGLDisplay display, EGLContext context);
|
||||
~AndroidEGLSurface();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -53,11 +47,9 @@ class AndroidEGLSurface {
|
||||
/// @brief This only applies to on-screen surfaces such as those created
|
||||
/// by `AndroidContextGL::CreateOnscreenSurface`.
|
||||
///
|
||||
/// @param target_time The vsync target time for the buffer.
|
||||
///
|
||||
/// @return Whether the EGL surface color buffer was swapped.
|
||||
///
|
||||
bool SwapBuffers(fml::TimePoint target_time);
|
||||
bool SwapBuffers();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @return The size of an `EGLSurface`.
|
||||
@@ -66,7 +58,7 @@ class AndroidEGLSurface {
|
||||
|
||||
private:
|
||||
const EGLSurface surface_;
|
||||
const fml::RefPtr<AndroidEnvironmentGL> environment_;
|
||||
const EGLDisplay display_;
|
||||
const EGLContext context_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#define FML_USED_ON_EMBEDDER
|
||||
|
||||
#include "android_environment_gl.h"
|
||||
|
||||
#include <memory>
|
||||
#include "flutter/shell/common/thread_host.h"
|
||||
#include "flutter/shell/platform/android/android_context_gl.h"
|
||||
@@ -25,22 +23,6 @@ TaskRunners MakeTaskRunners(const std::string& thread_label,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
class InterceptingAndroidEnvironmentGL : public AndroidEnvironmentGL {
|
||||
public:
|
||||
InterceptingAndroidEnvironmentGL() = default;
|
||||
~InterceptingAndroidEnvironmentGL() override = default;
|
||||
|
||||
bool SetPresentationTime(EGLSurface surface,
|
||||
fml::TimePoint time) const override {
|
||||
presentation_time_ = time;
|
||||
return AndroidEnvironmentGL::SetPresentationTime(surface, time);
|
||||
}
|
||||
|
||||
mutable std::optional<fml::TimePoint> presentation_time_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(InterceptingAndroidEnvironmentGL);
|
||||
};
|
||||
|
||||
TEST(AndroidContextGl, Create) {
|
||||
GrMockOptions main_context_options;
|
||||
sk_sp<GrDirectContext> main_context =
|
||||
@@ -80,27 +62,6 @@ TEST(AndroidContextGl, CreateSingleThread) {
|
||||
context.reset();
|
||||
EXPECT_TRUE(main_context->abandoned());
|
||||
}
|
||||
|
||||
TEST(AndroidEGLSurface, SwapBuffersNotifiesAboutPresentationTime) {
|
||||
auto environment = fml::MakeRefCounted<InterceptingAndroidEnvironmentGL>();
|
||||
std::string thread_label =
|
||||
::testing::UnitTest::GetInstance()->current_test_info()->name();
|
||||
fml::MessageLoop::EnsureInitializedForCurrentThread();
|
||||
fml::RefPtr<fml::TaskRunner> platform_runner =
|
||||
fml::MessageLoop::GetCurrent().GetTaskRunner();
|
||||
TaskRunners task_runners =
|
||||
TaskRunners(thread_label, platform_runner, platform_runner,
|
||||
platform_runner, platform_runner);
|
||||
auto context = std::make_unique<AndroidContextGL>(
|
||||
AndroidRenderingAPI::kOpenGLES, environment, task_runners);
|
||||
|
||||
auto surface = context->CreatePbufferSurface();
|
||||
EXPECT_TRUE(surface);
|
||||
EXPECT_FALSE(environment->presentation_time_.has_value());
|
||||
auto now = fml::TimePoint::Now();
|
||||
surface->SwapBuffers(now);
|
||||
EXPECT_EQ(environment->presentation_time_, now);
|
||||
}
|
||||
} // namespace android
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
@@ -20,26 +20,6 @@ AndroidEnvironmentGL::AndroidEnvironmentGL()
|
||||
return;
|
||||
}
|
||||
|
||||
// See if we can use the EGL_ANDROID_presentation_time extension. This
|
||||
// extension may be available from API18 onward.
|
||||
// If this extension is available, it will be invoked with the target vsync
|
||||
// for the current frame before calling eglSwapBuffers. This helps when the
|
||||
// engine over-stuffs the buffer queue. This can happen when a frame goes over
|
||||
// budget into the next vsync period, and a subsequent frame is quickly
|
||||
// submitted in the same vsync period. Dequeuing buffers will then be slow
|
||||
// until the engine stops submitting frames and lets the GPU catch up.
|
||||
// However, using this extension means the SurfaceFlinger will only use the
|
||||
// newest buffer for the current vsync, and the GPU and CPU will stay more
|
||||
// in sync.
|
||||
// See https://developer.android.com/games/sdk/frame-pacing for more
|
||||
// details and diagrams.
|
||||
auto* extensions = eglQueryString(display_, EGL_EXTENSIONS);
|
||||
if (strstr(extensions, "EGL_ANDROID_presentation_time")) {
|
||||
presentation_time_proc_ =
|
||||
reinterpret_cast<PFNEGLPRESENTATIONTIMEANDROIDPROC>(
|
||||
eglGetProcAddress("eglPresentationTimeANDROID"));
|
||||
}
|
||||
|
||||
valid_ = true;
|
||||
}
|
||||
|
||||
@@ -58,12 +38,4 @@ EGLDisplay AndroidEnvironmentGL::Display() const {
|
||||
return display_;
|
||||
}
|
||||
|
||||
bool AndroidEnvironmentGL::SetPresentationTime(EGLSurface surface,
|
||||
fml::TimePoint time) const {
|
||||
if (!presentation_time_proc_) {
|
||||
return false;
|
||||
}
|
||||
return presentation_time_proc_(display_, surface,
|
||||
time.ToEpochDelta().ToNanoseconds());
|
||||
}
|
||||
} // namespace flutter
|
||||
|
||||
@@ -7,44 +7,29 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/memory/ref_counted.h"
|
||||
#include "flutter/fml/time/time_delta.h"
|
||||
#include "flutter/fml/time/time_point.h"
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <KHR/khrplatform.h>
|
||||
|
||||
namespace flutter {
|
||||
namespace testing::android {
|
||||
class InterceptingAndroidEnvironmentGL;
|
||||
}
|
||||
|
||||
class AndroidEnvironmentGL
|
||||
: public fml::RefCountedThreadSafe<AndroidEnvironmentGL> {
|
||||
private:
|
||||
// MakeRefCounted
|
||||
AndroidEnvironmentGL();
|
||||
|
||||
// MakeRefCounted
|
||||
~AndroidEnvironmentGL();
|
||||
|
||||
public:
|
||||
bool IsValid() const;
|
||||
|
||||
EGLDisplay Display() const;
|
||||
|
||||
// Sets the presentation time for the surface.
|
||||
//
|
||||
// Returns false if there was a GL error or if eglPresentationTimeANDROID is
|
||||
// unavailable.
|
||||
virtual bool SetPresentationTime(EGLSurface surface,
|
||||
fml::TimePoint time) const;
|
||||
|
||||
protected:
|
||||
// MakeRefCounted
|
||||
AndroidEnvironmentGL();
|
||||
// MakeRefCounted
|
||||
virtual ~AndroidEnvironmentGL();
|
||||
|
||||
private:
|
||||
PFNEGLPRESENTATIONTIMEANDROIDPROC presentation_time_proc_;
|
||||
EGLDisplay display_;
|
||||
bool valid_;
|
||||
|
||||
friend class InterceptingAndroidEnvironmentGL;
|
||||
|
||||
FML_FRIEND_MAKE_REF_COUNTED(AndroidEnvironmentGL);
|
||||
FML_FRIEND_REF_COUNTED_THREAD_SAFE(AndroidEnvironmentGL);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(AndroidEnvironmentGL);
|
||||
|
||||
@@ -102,6 +102,10 @@ bool AndroidSurfaceGL::SetNativeWindow(
|
||||
FML_DCHECK(IsValid());
|
||||
FML_DCHECK(window);
|
||||
native_window_ = window;
|
||||
// Ensure the destructor is called since it destroys the `EGLSurface` before
|
||||
// creating a new onscreen surface.
|
||||
onscreen_surface_ = nullptr;
|
||||
// Create the onscreen surface.
|
||||
onscreen_surface_ = GLContextPtr()->CreateOnscreenSurface(window);
|
||||
if (!onscreen_surface_->IsValid()) {
|
||||
return false;
|
||||
@@ -122,11 +126,10 @@ bool AndroidSurfaceGL::GLContextClearCurrent() {
|
||||
return GLContextPtr()->ClearCurrent();
|
||||
}
|
||||
|
||||
bool AndroidSurfaceGL::GLContextPresent(fml::TimePoint target_time,
|
||||
uint32_t fbo_id) {
|
||||
bool AndroidSurfaceGL::GLContextPresent(uint32_t fbo_id) {
|
||||
FML_DCHECK(IsValid());
|
||||
FML_DCHECK(onscreen_surface_);
|
||||
return onscreen_surface_->SwapBuffers(target_time);
|
||||
return onscreen_surface_->SwapBuffers();
|
||||
}
|
||||
|
||||
intptr_t AndroidSurfaceGL::GLContextFBO(GLFrameInfo frame_info) const {
|
||||
@@ -164,6 +167,7 @@ sk_sp<const GrGLInterface> AndroidSurfaceGL::GetGLInterface() const {
|
||||
FML_DCHECK(result == EGL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
return GPUSurfaceGLDelegate::GetGLInterface();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class AndroidSurfaceGL final : public GPUSurfaceGLDelegate,
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextPresent(fml::TimePoint target_time, uint32_t fbo_id) override;
|
||||
bool GLContextPresent(uint32_t fbo_id) override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t GLContextFBO(GLFrameInfo frame_info) const override;
|
||||
|
||||
@@ -18,8 +18,7 @@ bool AndroidSurfaceMock::GLContextClearCurrent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AndroidSurfaceMock::GLContextPresent(fml::TimePoint target_time,
|
||||
uint32_t fbo_id) {
|
||||
bool AndroidSurfaceMock::GLContextPresent(uint32_t fbo_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class AndroidSurfaceMock final : public GPUSurfaceGLDelegate,
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextPresent(fml::TimePoint target_time, uint32_t fbo_id) override;
|
||||
bool GLContextPresent(uint32_t fbo_id) override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t GLContextFBO(GLFrameInfo frame_info) const override;
|
||||
|
||||
@@ -38,7 +38,7 @@ class IOSSurfaceGL final : public IOSSurface, public GPUSurfaceGLDelegate {
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextPresent(fml::TimePoint target_time, uint32_t fbo_id) override;
|
||||
bool GLContextPresent(uint32_t fbo_id) override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t GLContextFBO(GLFrameInfo frame_info) const override;
|
||||
|
||||
@@ -86,7 +86,7 @@ bool IOSSurfaceGL::GLContextClearCurrent() {
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool IOSSurfaceGL::GLContextPresent(fml::TimePoint target_time, uint32_t fbo_id) {
|
||||
bool IOSSurfaceGL::GLContextPresent(uint32_t fbo_id) {
|
||||
TRACE_EVENT0("flutter", "IOSSurfaceGL::GLContextPresent");
|
||||
return IsValid() && render_target_->PresentRenderBuffer();
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ bool EmbedderSurfaceGL::GLContextClearCurrent() {
|
||||
}
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool EmbedderSurfaceGL::GLContextPresent(fml::TimePoint target_time,
|
||||
uint32_t fbo_id) {
|
||||
bool EmbedderSurfaceGL::GLContextPresent(uint32_t fbo_id) {
|
||||
return gl_dispatch_table_.gl_present_callback(fbo_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class EmbedderSurfaceGL final : public EmbedderSurface,
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
bool GLContextPresent(fml::TimePoint target_time, uint32_t fbo_id) override;
|
||||
bool GLContextPresent(uint32_t fbo_id) override;
|
||||
|
||||
// |GPUSurfaceGLDelegate|
|
||||
intptr_t GLContextFBO(GLFrameInfo frame_info) const override;
|
||||
|
||||
Reference in New Issue
Block a user