Revert "[Windows] Introduce egl::Surface and egl::WindowSurface" (flutter/engine#50104)

Reverts flutter/engine#49983
This commit is contained in:
Loïc Sharma
2024-01-27 11:15:04 -08:00
committed by GitHub
parent 26eed181ac
commit 7918e2046c
16 changed files with 215 additions and 453 deletions

View File

@@ -7242,10 +7242,6 @@ ORIGIN: ../../../flutter/shell/platform/windows/egl/manager.cc + ../../../flutte
ORIGIN: ../../../flutter/shell/platform/windows/egl/manager.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/egl/proc_table.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/egl/proc_table.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/egl/surface.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/egl/surface.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/egl/window_surface.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/egl/window_surface.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/event_watcher.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/event_watcher.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/external_texture.h + ../../../flutter/LICENSE
@@ -10121,10 +10117,6 @@ FILE: ../../../flutter/shell/platform/windows/egl/manager.cc
FILE: ../../../flutter/shell/platform/windows/egl/manager.h
FILE: ../../../flutter/shell/platform/windows/egl/proc_table.cc
FILE: ../../../flutter/shell/platform/windows/egl/proc_table.h
FILE: ../../../flutter/shell/platform/windows/egl/surface.cc
FILE: ../../../flutter/shell/platform/windows/egl/surface.h
FILE: ../../../flutter/shell/platform/windows/egl/window_surface.cc
FILE: ../../../flutter/shell/platform/windows/egl/window_surface.h
FILE: ../../../flutter/shell/platform/windows/event_watcher.cc
FILE: ../../../flutter/shell/platform/windows/event_watcher.h
FILE: ../../../flutter/shell/platform/windows/external_texture.h

View File

@@ -59,10 +59,6 @@ source_set("flutter_windows_source") {
"egl/manager.h",
"egl/proc_table.cc",
"egl/proc_table.h",
"egl/surface.cc",
"egl/surface.h",
"egl/window_surface.cc",
"egl/window_surface.h",
"event_watcher.cc",
"event_watcher.h",
"external_texture.h",
@@ -213,7 +209,6 @@ executable("flutter_windows_unittests") {
"testing/egl/mock_context.h",
"testing/egl/mock_manager.h",
"testing/egl/mock_proc_table.h",
"testing/egl/mock_window_surface.h",
"testing/engine_modifier.h",
"testing/flutter_window_test.cc",
"testing/flutter_window_test.h",

View File

@@ -97,11 +97,6 @@ bool CompositorOpenGL::Present(const FlutterLayer** layers,
return false;
}
if (!engine_->egl_manager()->surface() ||
!engine_->egl_manager()->surface()->IsValid()) {
return false;
}
// Clear the view if there are no layers to present.
if (layers_count == 0) {
// Normally the compositor is initialized when the first backing store is
@@ -133,7 +128,7 @@ bool CompositorOpenGL::Present(const FlutterLayer** layers,
return false;
}
if (!engine_->egl_manager()->surface()->MakeCurrent()) {
if (!engine_->egl_manager()->MakeCurrent()) {
return false;
}
@@ -159,7 +154,7 @@ bool CompositorOpenGL::Present(const FlutterLayer** layers,
GL_NEAREST // filter
);
if (!engine_->egl_manager()->surface()->SwapBuffers()) {
if (!engine_->egl_manager()->SwapBuffers()) {
return false;
}
@@ -170,7 +165,7 @@ bool CompositorOpenGL::Present(const FlutterLayer** layers,
bool CompositorOpenGL::Initialize() {
FML_DCHECK(!is_initialized_);
if (!engine_->egl_manager()->surface()->MakeCurrent()) {
if (!engine_->egl_manager()->MakeCurrent()) {
return false;
}
@@ -191,14 +186,14 @@ bool CompositorOpenGL::ClearSurface() {
// Resize the surface if needed.
engine_->view()->OnEmptyFrameGenerated();
if (!engine_->egl_manager()->surface()->MakeCurrent()) {
if (!engine_->egl_manager()->MakeCurrent()) {
return false;
}
gl_->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl_->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
if (!engine_->egl_manager()->surface()->SwapBuffers()) {
if (!engine_->egl_manager()->SwapBuffers()) {
return false;
}

View File

@@ -10,7 +10,6 @@
#include "flutter/shell/platform/windows/egl/manager.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/testing/egl/mock_manager.h"
#include "flutter/shell/platform/windows/testing/egl/mock_window_surface.h"
#include "flutter/shell/platform/windows/testing/engine_modifier.h"
#include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
@@ -66,14 +65,10 @@ class CompositorOpenGLTest : public WindowsTest {
protected:
FlutterWindowsEngine* engine() { return engine_.get(); }
egl::MockManager* egl_manager() { return egl_manager_; }
egl::MockWindowSurface* surface() { return surface_.get(); }
void UseHeadlessEngine() {
auto egl_manager = std::make_unique<egl::MockManager>();
egl_manager_ = egl_manager.get();
surface_ = std::make_unique<egl::MockWindowSurface>();
EXPECT_CALL(*egl_manager_, surface).WillRepeatedly(Return(surface_.get()));
FlutterWindowsEngineBuilder builder{GetContext()};
@@ -97,7 +92,6 @@ class CompositorOpenGLTest : public WindowsTest {
private:
std::unique_ptr<FlutterWindowsEngine> engine_;
std::unique_ptr<FlutterWindowsView> view_;
std::unique_ptr<egl::MockWindowSurface> surface_;
egl::MockManager* egl_manager_;
FML_DISALLOW_COPY_AND_ASSIGN(CompositorOpenGLTest);
@@ -113,7 +107,7 @@ TEST_F(CompositorOpenGLTest, CreateBackingStore) {
FlutterBackingStoreConfig config = {};
FlutterBackingStore backing_store = {};
EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
EXPECT_CALL(*egl_manager(), MakeCurrent).WillOnce(Return(true));
ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
}
@@ -126,7 +120,7 @@ TEST_F(CompositorOpenGLTest, InitializationFailure) {
FlutterBackingStoreConfig config = {};
FlutterBackingStore backing_store = {};
EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(false));
EXPECT_CALL(*egl_manager(), MakeCurrent).WillOnce(Return(false));
EXPECT_FALSE(compositor.CreateBackingStore(config, &backing_store));
}
@@ -138,7 +132,7 @@ TEST_F(CompositorOpenGLTest, Present) {
FlutterBackingStoreConfig config = {};
FlutterBackingStore backing_store = {};
EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
EXPECT_CALL(*egl_manager(), MakeCurrent).WillOnce(Return(true));
ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
FlutterLayer layer = {};
@@ -146,8 +140,8 @@ TEST_F(CompositorOpenGLTest, Present) {
layer.backing_store = &backing_store;
const FlutterLayer* layer_ptr = &layer;
EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
EXPECT_CALL(*surface(), SwapBuffers).WillOnce(Return(true));
EXPECT_CALL(*egl_manager(), MakeCurrent).WillOnce(Return(true));
EXPECT_CALL(*egl_manager(), SwapBuffers).WillOnce(Return(true));
EXPECT_TRUE(compositor.Present(&layer_ptr, 1));
ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
@@ -160,8 +154,10 @@ TEST_F(CompositorOpenGLTest, PresentEmpty) {
// The context will be bound twice: first to initialize the compositor, second
// to clear the surface.
EXPECT_CALL(*surface(), MakeCurrent).Times(2).WillRepeatedly(Return(true));
EXPECT_CALL(*surface(), SwapBuffers).WillOnce(Return(true));
EXPECT_CALL(*egl_manager(), MakeCurrent)
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(*egl_manager(), SwapBuffers).WillOnce(Return(true));
EXPECT_TRUE(compositor.Present(nullptr, 0));
}
@@ -173,7 +169,7 @@ TEST_F(CompositorOpenGLTest, HeadlessPresentIgnored) {
FlutterBackingStoreConfig config = {};
FlutterBackingStore backing_store = {};
EXPECT_CALL(*surface(), MakeCurrent).WillOnce(Return(true));
EXPECT_CALL(*egl_manager(), MakeCurrent).WillOnce(Return(true));
ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
FlutterLayer layer = {};

View File

@@ -14,7 +14,7 @@ namespace egl {
// An EGL context to interact with OpenGL.
//
// This enables automatic error logging and mocking.
// This enables automatic eror logging and mocking.
//
// Flutter Windows uses this to create render and resource contexts.
class Context {

View File

@@ -263,71 +263,92 @@ bool Manager::IsValid() const {
return is_valid_;
}
bool Manager::CreateWindowSurface(HWND hwnd, size_t width, size_t height) {
FML_DCHECK(surface_ == nullptr || !surface_->IsValid());
bool Manager::CreateSurface(HWND hwnd, EGLint width, EGLint height) {
if (!hwnd || !is_valid_) {
return false;
}
EGLSurface surface = EGL_NO_SURFACE;
// Disable ANGLE's automatic surface resizing and provide an explicit size.
// The surface will need to be destroyed and re-created if the HWND is
// resized.
const EGLint surface_attributes[] = {EGL_FIXED_SIZE_ANGLE,
EGL_TRUE,
EGL_WIDTH,
static_cast<EGLint>(width),
EGL_HEIGHT,
static_cast<EGLint>(height),
EGL_NONE};
const EGLint surface_attributes[] = {
EGL_FIXED_SIZE_ANGLE, EGL_TRUE, EGL_WIDTH, width,
EGL_HEIGHT, height, EGL_NONE};
auto const surface = ::eglCreateWindowSurface(
display_, config_, static_cast<EGLNativeWindowType>(hwnd),
surface_attributes);
surface = ::eglCreateWindowSurface(display_, config_,
static_cast<EGLNativeWindowType>(hwnd),
surface_attributes);
if (surface == EGL_NO_SURFACE) {
LogEGLError("Surface creation failed.");
return false;
}
surface_ = std::make_unique<WindowSurface>(
display_, render_context_->GetHandle(), surface, width, height);
surface_width_ = width;
surface_height_ = height;
surface_ = surface;
return true;
}
void Manager::ResizeWindowSurface(HWND hwnd, size_t width, size_t height) {
FML_CHECK(surface_ != nullptr);
auto const existing_width = surface_->width();
auto const existing_height = surface_->height();
auto const existing_vsync = surface_->vsync_enabled();
void Manager::ResizeSurface(HWND hwnd,
EGLint width,
EGLint height,
bool vsync_enabled) {
EGLint existing_width, existing_height;
GetSurfaceDimensions(&existing_width, &existing_height);
if (width != existing_width || height != existing_height) {
surface_width_ = width;
surface_height_ = height;
// TODO: Destroying the surface and re-creating it is expensive.
// Ideally this would use ANGLE's automatic surface sizing instead.
// See: https://github.com/flutter/flutter/issues/79427
if (!surface_->Destroy()) {
FML_LOG(ERROR) << "Manager::ResizeSurface failed to destroy surface";
return;
}
if (!CreateWindowSurface(hwnd, width, height)) {
render_context_->ClearCurrent();
DestroySurface();
if (!CreateSurface(hwnd, width, height)) {
FML_LOG(ERROR) << "Manager::ResizeSurface failed to create surface";
return;
}
if (!surface_->SetVSyncEnabled(existing_vsync)) {
// Surfaces block until the v-blank by default.
// Failing to update the vsync might result in unnecessary blocking.
// This regresses performance but not correctness.
FML_LOG(ERROR) << "Manager::ResizeSurface failed to set vsync";
}
}
SetVSyncEnabled(vsync_enabled);
}
void Manager::GetSurfaceDimensions(EGLint* width, EGLint* height) {
if (surface_ == EGL_NO_SURFACE || !is_valid_) {
*width = 0;
*height = 0;
return;
}
// This avoids eglQuerySurface as ideally surfaces would be automatically
// sized by ANGLE to avoid expensive surface destroy & re-create. With
// automatic sizing, ANGLE could resize the surface before Flutter asks it to,
// which would break resize redraw synchronization.
*width = surface_width_;
*height = surface_height_;
}
void Manager::DestroySurface() {
if (display_ != EGL_NO_DISPLAY && surface_ != EGL_NO_SURFACE) {
::eglDestroySurface(display_, surface_);
}
surface_ = EGL_NO_SURFACE;
}
bool Manager::HasContextCurrent() {
return ::eglGetCurrentContext() != EGL_NO_CONTEXT;
}
bool Manager::MakeCurrent() {
return (::eglMakeCurrent(display_, surface_, surface_,
render_context_->GetHandle()) == EGL_TRUE);
}
bool Manager::SwapBuffers() {
return (::eglSwapBuffers(display_, surface_));
}
EGLSurface Manager::CreateSurfaceFromHandle(EGLenum handle_type,
EGLClientBuffer handle,
const EGLint* attributes) const {
@@ -335,6 +356,23 @@ EGLSurface Manager::CreateSurfaceFromHandle(EGLenum handle_type,
config_, attributes);
}
void Manager::SetVSyncEnabled(bool enabled) {
if (!MakeCurrent()) {
LogEGLError("Unable to make surface current to update the swap interval");
return;
}
// OpenGL swap intervals can be used to prevent screen tearing.
// If enabled, the raster thread blocks until the v-blank.
// This is unnecessary if DWM composition is enabled.
// See: https://www.khronos.org/opengl/wiki/Swap_Interval
// See: https://learn.microsoft.com/windows/win32/dwm/composition-ovw
if (::eglSwapInterval(display_, enabled ? 1 : 0) != EGL_TRUE) {
LogEGLError("Unable to update the swap interval");
return;
}
}
bool Manager::GetDevice(ID3D11Device** device) {
if (!resolved_device_) {
if (!InitializeDevice()) {
@@ -354,9 +392,5 @@ Context* Manager::resource_context() const {
return resource_context_.get();
}
WindowSurface* Manager::surface() const {
return surface_.get();
}
} // namespace egl
} // namespace flutter

View File

@@ -20,8 +20,6 @@
#include "flutter/fml/macros.h"
#include "flutter/shell/platform/windows/egl/context.h"
#include "flutter/shell/platform/windows/egl/surface.h"
#include "flutter/shell/platform/windows/egl/window_surface.h"
namespace flutter {
namespace egl {
@@ -44,19 +42,37 @@ class Manager {
//
// After the surface is created, |SetVSyncEnabled| should be called on a
// thread that can bind the |render_context_|.
virtual bool CreateWindowSurface(HWND hwnd, size_t width, size_t height);
virtual bool CreateSurface(HWND hwnd, EGLint width, EGLint height);
// Resizes backing surface from current size to newly requested size
// based on width and height for the specific case when width and height do
// not match current surface dimensions. HWND is the window backing the
// surface.
// not match current surface dimensions. Target represents the visual entity
// to bind to.
//
// This binds |render_context_| to the current thread.
virtual void ResizeWindowSurface(HWND hwnd, size_t width, size_t height);
virtual void ResizeSurface(HWND hwnd,
EGLint width,
EGLint height,
bool enable_vsync);
// queries EGL for the dimensions of surface in physical
// pixels returning width and height as out params.
void GetSurfaceDimensions(EGLint* width, EGLint* height);
// Releases the pass-in EGLSurface wrapping and backing resources if not null.
virtual void DestroySurface();
// Check if the current thread has a context bound.
bool HasContextCurrent();
// Binds |render_context_| to the current rendering thread and to the draw and
// read surfaces returning a boolean result reflecting success.
virtual bool MakeCurrent();
// Swaps the front and back buffers of the DX11 swapchain backing surface if
// not null.
virtual bool SwapBuffers();
// Creates a |EGLSurface| from the provided handle.
EGLSurface CreateSurfaceFromHandle(EGLenum handle_type,
EGLClientBuffer handle,
@@ -65,6 +81,16 @@ class Manager {
// Gets the |EGLDisplay|.
EGLDisplay egl_display() const { return display_; };
// If enabled, makes the current surface's buffer swaps block until the
// v-blank.
//
// If disabled, allows one thread to swap multiple buffers per v-blank
// but can result in screen tearing if the system compositor is disabled.
//
// This binds |render_context_| to the current thread and makes the render
// surface current.
virtual void SetVSyncEnabled(bool enabled);
// Gets the |ID3D11Device| chosen by ANGLE.
bool GetDevice(ID3D11Device** device);
@@ -74,9 +100,6 @@ class Manager {
// Get the EGL context used for async texture uploads.
virtual Context* resource_context() const;
// Get the EGL surface that backs the Flutter view.
virtual WindowSurface* surface() const;
protected:
// Creates a new surface manager retaining reference to the passed-in target
// for the lifetime of the manager.
@@ -115,8 +138,12 @@ class Manager {
// The EGL context used for async texture uploads.
std::unique_ptr<Context> resource_context_;
// Th EGL surface used to render into the Flutter view.
std::unique_ptr<WindowSurface> surface_;
// Current render_surface that engine will draw into.
EGLSurface surface_ = EGL_NO_SURFACE;
// Requested dimensions for current surface
EGLint surface_width_ = 0;
EGLint surface_height_ = 0;
// The current D3D device.
Microsoft::WRL::ComPtr<ID3D11Device> resolved_device_ = nullptr;

View File

@@ -1,66 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/egl/surface.h"
#include "flutter/shell/platform/windows/egl/egl.h"
namespace flutter {
namespace egl {
Surface::Surface(EGLDisplay display, EGLContext context, EGLSurface surface)
: display_(display), context_(context), surface_(surface) {}
Surface::~Surface() {
Destroy();
}
bool Surface::IsValid() const {
return is_valid_;
}
bool Surface::Destroy() {
if (surface_ != EGL_NO_SURFACE) {
// Ensure the surface is not current before destroying it.
if (::eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT) != EGL_TRUE) {
WINDOWS_LOG_EGL_ERROR;
return false;
}
if (::eglDestroySurface(display_, surface_) != EGL_TRUE) {
WINDOWS_LOG_EGL_ERROR;
return false;
}
}
is_valid_ = false;
surface_ = EGL_NO_SURFACE;
return true;
}
bool Surface::MakeCurrent() const {
if (::eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) {
WINDOWS_LOG_EGL_ERROR;
return false;
}
return true;
}
bool Surface::SwapBuffers() const {
if (::eglSwapBuffers(display_, surface_) != EGL_TRUE) {
WINDOWS_LOG_EGL_ERROR;
return false;
}
return true;
}
const EGLSurface& Surface::GetHandle() const {
return surface_;
}
} // namespace egl
} // namespace flutter

View File

@@ -1,56 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_SURFACE_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_SURFACE_H_
#include <EGL/egl.h>
#include "flutter/fml/macros.h"
namespace flutter {
namespace egl {
// An EGL surface. This can be window surface or an off-screen buffer.
//
// This enables automatic error logging and mocking.
class Surface {
public:
Surface(EGLDisplay display, EGLContext context, EGLSurface surface);
~Surface();
// Destroy the EGL surface and invalidate this object.
//
// This also unbinds the current context from the thread.
virtual bool Destroy();
// Check whether the EGL surface is valid.
virtual bool IsValid() const;
// Bind the EGL surface's context and read and draw surfaces to the
// current thread. Returns true on success.
virtual bool MakeCurrent() const;
// Swap the surface's front the and back buffers. Used to present content.
// Returns true on success.
virtual bool SwapBuffers() const;
// Get the raw EGL surface.
virtual const EGLSurface& GetHandle() const;
protected:
bool is_valid_ = true;
EGLDisplay display_ = EGL_NO_DISPLAY;
EGLContext context_ = EGL_NO_CONTEXT;
EGLSurface surface_ = EGL_NO_SURFACE;
FML_DISALLOW_COPY_AND_ASSIGN(Surface);
};
} // namespace egl
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_SURFACE_H_

View File

@@ -1,46 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/windows/egl/window_surface.h"
#include "flutter/shell/platform/windows/egl/egl.h"
namespace flutter {
namespace egl {
WindowSurface::WindowSurface(EGLDisplay display,
EGLContext context,
EGLSurface surface,
size_t width,
size_t height)
: Surface(display, context, surface), width_(width), height_(height) {}
bool WindowSurface::SetVSyncEnabled(bool enabled) {
if (!MakeCurrent()) {
return false;
}
if (::eglSwapInterval(display_, enabled ? 1 : 0) != EGL_TRUE) {
WINDOWS_LOG_EGL_ERROR;
return false;
}
vsync_enabled_ = enabled;
return true;
}
size_t WindowSurface::width() const {
return width_;
}
size_t WindowSurface::height() const {
return height_;
}
bool WindowSurface::vsync_enabled() const {
return vsync_enabled_;
}
} // namespace egl
} // namespace flutter

View File

@@ -1,55 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_WINDOW_SURFACE_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_WINDOW_SURFACE_H_
#include <EGL/egl.h>
#include "flutter/fml/macros.h"
#include "flutter/shell/platform/windows/egl/surface.h"
namespace flutter {
namespace egl {
// An EGL surface used to render a Flutter view to a win32 HWND.
//
// This enables automatic error logging and mocking.
class WindowSurface : public Surface {
public:
WindowSurface(EGLDisplay display,
EGLContext context,
EGLSurface surface,
size_t width,
size_t height);
// If enabled, makes the surface's buffer swaps block until the v-blank.
//
// If disabled, allows one thread to swap multiple buffers per v-blank
// but can result in screen tearing if the system compositor is disabled.
//
// This binds the EGL context and surface to the current thread.
virtual bool SetVSyncEnabled(bool enabled);
// Get the surface's width in physical pixels.
virtual size_t width() const;
// Get the surface's height in physical pixels.
virtual size_t height() const;
// Get whether the surface's buffer swap blocks until the v-blank.
virtual bool vsync_enabled() const;
private:
size_t width_ = 0;
size_t height_ = 0;
bool vsync_enabled_ = true;
FML_DISALLOW_COPY_AND_ASSIGN(WindowSurface);
};
} // namespace egl
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_WINDOW_SURFACE_H_

View File

@@ -58,7 +58,7 @@ FlutterRendererConfig GetOpenGLRendererConfig() {
if (!host->egl_manager()) {
return false;
}
return host->egl_manager()->render_context()->MakeCurrent();
return host->egl_manager()->MakeCurrent();
};
config.open_gl.clear_current = [](void* user_data) -> bool {
auto host = static_cast<FlutterWindowsEngine*>(user_data);

View File

@@ -53,10 +53,10 @@ void UpdateVsync(const FlutterWindowsEngine& engine, bool needs_vsync) {
// thread.
if (engine.running()) {
engine.PostRasterThreadTask([egl_manager, needs_vsync]() {
egl_manager->surface()->SetVSyncEnabled(needs_vsync);
egl_manager->SetVSyncEnabled(needs_vsync);
});
} else {
egl_manager->surface()->SetVSyncEnabled(needs_vsync);
egl_manager->SetVSyncEnabled(needs_vsync);
// Release the EGL context so that the raster thread can use it.
if (!egl_manager->render_context()->ClearCurrent()) {
@@ -116,8 +116,8 @@ void FlutterWindowsView::OnEmptyFrameGenerated() {
// Platform thread is blocked for the entire duration until the
// resize_status_ is set to kDone.
engine_->egl_manager()->ResizeWindowSurface(
GetWindowHandle(), resize_target_width_, resize_target_height_);
engine_->egl_manager()->ResizeSurface(GetWindowHandle(), resize_target_width_,
resize_target_height_, NeedsVsync());
resize_status_ = ResizeState::kFrameGenerated;
}
@@ -132,8 +132,8 @@ bool FlutterWindowsView::OnFrameGenerated(size_t width, size_t height) {
if (resize_target_width_ == width && resize_target_height_ == height) {
// Platform thread is blocked for the entire duration until the
// resize_status_ is set to kDone.
engine_->egl_manager()->ResizeWindowSurface(GetWindowHandle(), width,
height);
engine_->egl_manager()->ResizeSurface(GetWindowHandle(), width, height,
NeedsVsync());
resize_status_ = ResizeState::kFrameGenerated;
return true;
}
@@ -167,8 +167,8 @@ bool FlutterWindowsView::OnWindowSizeChanged(size_t width, size_t height) {
// We're using OpenGL rendering. Resizing the surface must happen on the
// raster thread.
size_t surface_width = engine_->egl_manager()->surface()->width();
size_t surface_height = engine_->egl_manager()->surface()->height();
EGLint surface_width, surface_height;
engine_->egl_manager()->GetSurfaceDimensions(&surface_width, &surface_height);
bool surface_will_update =
SurfaceWillUpdate(surface_width, surface_height, width, height);
@@ -637,8 +637,8 @@ bool FlutterWindowsView::PresentSoftwareBitmap(const void* allocation,
void FlutterWindowsView::CreateRenderSurface() {
if (engine_ && engine_->egl_manager()) {
PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds();
engine_->egl_manager()->CreateWindowSurface(GetWindowHandle(), bounds.width,
bounds.height);
engine_->egl_manager()->CreateSurface(GetWindowHandle(), bounds.width,
bounds.height);
UpdateVsync(*engine_, NeedsVsync());
@@ -648,21 +648,9 @@ void FlutterWindowsView::CreateRenderSurface() {
}
void FlutterWindowsView::DestroyRenderSurface() {
if (!engine_) {
return;
if (engine_ && engine_->egl_manager()) {
engine_->egl_manager()->DestroySurface();
}
auto const manager = engine_->egl_manager();
if (!manager) {
return;
}
auto const surface = manager->surface();
if (!surface) {
return;
}
surface->Destroy();
}
void FlutterWindowsView::OnHighContrastChanged() {

View File

@@ -20,7 +20,6 @@
#include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h"
#include "flutter/shell/platform/windows/testing/egl/mock_context.h"
#include "flutter/shell/platform/windows/testing/egl/mock_manager.h"
#include "flutter/shell/platform/windows/testing/egl/mock_window_surface.h"
#include "flutter/shell/platform/windows/testing/engine_modifier.h"
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
#include "flutter/shell/platform/windows/testing/mock_windows_proc_table.h"
@@ -231,13 +230,12 @@ TEST(FlutterWindowsViewTest, SubMenuExpandedState) {
// The view's surface must be destroyed after the engine is shutdown.
// See: https://github.com/flutter/flutter/issues/124463
TEST(FlutterWindowsViewTest, Shutdown) {
auto engine = std::make_unique<MockFlutterWindowsEngine>();
std::unique_ptr<MockFlutterWindowsEngine> engine =
std::make_unique<MockFlutterWindowsEngine>();
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto egl_manager = std::make_unique<egl::MockManager>();
auto surface = std::make_unique<egl::MockWindowSurface>();
EXPECT_CALL(*egl_manager.get(), surface).WillOnce(Return(surface.get()));
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
EngineModifier modifier(engine.get());
FlutterWindowsView view(std::move(window_binding_handler));
@@ -245,7 +243,7 @@ TEST(FlutterWindowsViewTest, Shutdown) {
// The engine must be stopped before the surface can be destroyed.
InSequence s;
EXPECT_CALL(*engine.get(), Stop).Times(1);
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
modifier.SetEGLManager(std::move(egl_manager));
view.SetEngine(engine.get());
@@ -819,16 +817,16 @@ TEST(FlutterWindowsViewTest, WindowResizeTests) {
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
auto egl_manager = std::make_unique<egl::MockManager>();
auto surface = std::make_unique<egl::MockWindowSurface>();
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
EXPECT_CALL(*windows_proc_table.get(), DwmFlush).WillOnce(Return(S_OK));
EXPECT_CALL(*egl_manager.get(), surface)
.WillRepeatedly(Return(surface.get()));
EXPECT_CALL(*egl_manager.get(),
ResizeWindowSurface(_, /*width=*/500, /*height=*/500))
EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
.WillOnce(Return(true));
EXPECT_CALL(
*egl_manager.get(),
ResizeSurface(_, /*width=*/500, /*height=*/500, /*enable_vsync=*/false))
.Times(1);
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
FlutterWindowsView view(std::move(window_binding_handler),
std::move(windows_proc_table));
@@ -869,16 +867,16 @@ TEST(FlutterWindowsViewTest, TestEmptyFrameResizes) {
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
auto egl_manager = std::make_unique<egl::MockManager>();
auto surface = std::make_unique<egl::MockWindowSurface>();
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
EXPECT_CALL(*windows_proc_table.get(), DwmFlush).WillOnce(Return(S_OK));
EXPECT_CALL(*egl_manager.get(), surface)
.WillRepeatedly(Return(surface.get()));
EXPECT_CALL(*egl_manager.get(),
ResizeWindowSurface(_, /*width=*/500, /*height=*/500))
EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
.WillOnce(Return(true));
EXPECT_CALL(
*egl_manager.get(),
ResizeSurface(_, /*width=*/500, /*height=*/500, /*enable_vsync=*/false))
.Times(1);
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
FlutterWindowsView view(std::move(window_binding_handler),
std::move(windows_proc_table));
@@ -921,12 +919,10 @@ TEST(FlutterWindowsViewTest, WindowResizeRace) {
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
auto egl_manager = std::make_unique<egl::MockManager>();
auto surface = std::make_unique<egl::MockWindowSurface>();
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
EXPECT_CALL(*egl_manager.get(), surface)
.WillRepeatedly(Return(surface.get()));
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
FlutterWindowsView view(std::move(window_binding_handler),
std::move(windows_proc_table));
@@ -1303,13 +1299,14 @@ TEST(FlutterWindowsViewTest, TooltipNodeData) {
// Don't block until the v-blank if it is disabled by the window.
// The surface is updated on the platform thread at startup.
TEST(FlutterWindowsViewTest, DisablesVSyncAtStartup) {
auto engine = std::make_unique<MockFlutterWindowsEngine>();
std::unique_ptr<MockFlutterWindowsEngine> engine =
std::make_unique<MockFlutterWindowsEngine>();
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
auto egl_manager = std::make_unique<egl::MockManager>();
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
egl::MockContext render_context;
auto surface = std::make_unique<egl::MockWindowSurface>();
EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
@@ -1317,24 +1314,21 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAtStartup) {
EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
.WillOnce(Return(true));
EXPECT_CALL(*egl_manager.get(), render_context)
.WillOnce(Return(&render_context));
EXPECT_CALL(*egl_manager.get(), surface)
.WillRepeatedly(Return(surface.get()));
EngineModifier modifier(engine.get());
FlutterWindowsView view(std::move(window_binding_handler),
std::move(windows_proc_table));
InSequence s;
EXPECT_CALL(*egl_manager.get(), CreateWindowSurface(_, _, _))
EXPECT_CALL(*egl_manager.get(), CreateSurface(_, _, _))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*surface.get(), SetVSyncEnabled(false)).Times(1);
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(false)).Times(1);
EXPECT_CALL(*egl_manager.get(), render_context)
.WillOnce(Return(&render_context));
EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
EXPECT_CALL(*engine.get(), Stop).Times(1);
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
modifier.SetEGLManager(std::move(egl_manager));
view.SetEngine(engine.get());
@@ -1345,37 +1339,35 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAtStartup) {
// Blocks until the v-blank if it is enabled by the window.
// The surface is updated on the platform thread at startup.
TEST(FlutterWindowsViewTest, EnablesVSyncAtStartup) {
auto engine = std::make_unique<MockFlutterWindowsEngine>();
std::unique_ptr<MockFlutterWindowsEngine> engine =
std::make_unique<MockFlutterWindowsEngine>();
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
auto egl_manager = std::make_unique<egl::MockManager>();
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
egl::MockContext render_context;
auto surface = std::make_unique<egl::MockWindowSurface>();
EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
.WillOnce(Return(false));
EXPECT_CALL(*egl_manager.get(), render_context)
.WillOnce(Return(&render_context));
EXPECT_CALL(*egl_manager.get(), surface)
.WillRepeatedly(Return(surface.get()));
EngineModifier modifier(engine.get());
FlutterWindowsView view(std::move(window_binding_handler),
std::move(windows_proc_table));
InSequence s;
EXPECT_CALL(*egl_manager.get(), CreateWindowSurface(_, _, _))
EXPECT_CALL(*egl_manager.get(), CreateSurface(_, _, _))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*surface.get(), SetVSyncEnabled(true)).Times(1);
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(true)).Times(1);
EXPECT_CALL(*egl_manager.get(), render_context)
.WillOnce(Return(&render_context));
EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));
EXPECT_CALL(*engine.get(), Stop).Times(1);
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
modifier.SetEGLManager(std::move(egl_manager));
view.SetEngine(engine.get());
@@ -1386,27 +1378,24 @@ TEST(FlutterWindowsViewTest, EnablesVSyncAtStartup) {
// Don't block until the v-blank if it is disabled by the window.
// The surface is updated on the raster thread if the engine is running.
TEST(FlutterWindowsViewTest, DisablesVSyncAfterStartup) {
auto engine = std::make_unique<MockFlutterWindowsEngine>();
std::unique_ptr<MockFlutterWindowsEngine> engine =
std::make_unique<MockFlutterWindowsEngine>();
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
auto egl_manager = std::make_unique<egl::MockManager>();
auto surface = std::make_unique<egl::MockWindowSurface>();
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
.WillOnce(Return(true));
EXPECT_CALL(*egl_manager.get(), render_context).Times(0);
EXPECT_CALL(*egl_manager.get(), surface)
.WillRepeatedly(Return(surface.get()));
EngineModifier modifier(engine.get());
FlutterWindowsView view(std::move(window_binding_handler),
std::move(windows_proc_table));
InSequence s;
EXPECT_CALL(*egl_manager.get(), CreateWindowSurface(_, _, _))
EXPECT_CALL(*egl_manager.get(), CreateSurface(_, _, _))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*engine.get(), PostRasterThreadTask)
@@ -1414,9 +1403,11 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAfterStartup) {
callback();
return true;
});
EXPECT_CALL(*surface.get(), SetVSyncEnabled(false)).Times(1);
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(false)).Times(1);
EXPECT_CALL(*egl_manager.get(), render_context).Times(0);
EXPECT_CALL(*engine.get(), Stop).Times(1);
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
modifier.SetEGLManager(std::move(egl_manager));
view.SetEngine(engine.get());
@@ -1427,28 +1418,25 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAfterStartup) {
// Blocks until the v-blank if it is enabled by the window.
// The surface is updated on the raster thread if the engine is running.
TEST(FlutterWindowsViewTest, EnablesVSyncAfterStartup) {
auto engine = std::make_unique<MockFlutterWindowsEngine>();
std::unique_ptr<MockFlutterWindowsEngine> engine =
std::make_unique<MockFlutterWindowsEngine>();
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
auto egl_manager = std::make_unique<egl::MockManager>();
auto surface = std::make_unique<egl::MockWindowSurface>();
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
EXPECT_CALL(*windows_proc_table.get(), DwmIsCompositionEnabled)
.WillOnce(Return(false));
EXPECT_CALL(*egl_manager.get(), render_context).Times(0);
EXPECT_CALL(*egl_manager.get(), surface)
.WillRepeatedly(Return(surface.get()));
EngineModifier modifier(engine.get());
FlutterWindowsView view(std::move(window_binding_handler),
std::move(windows_proc_table));
InSequence s;
EXPECT_CALL(*egl_manager.get(), CreateWindowSurface(_, _, _))
EXPECT_CALL(*egl_manager.get(), CreateSurface(_, _, _))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*engine.get(), PostRasterThreadTask)
@@ -1456,10 +1444,11 @@ TEST(FlutterWindowsViewTest, EnablesVSyncAfterStartup) {
callback();
return true;
});
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(true)).Times(1);
EXPECT_CALL(*egl_manager.get(), render_context).Times(0);
EXPECT_CALL(*surface.get(), SetVSyncEnabled(true)).Times(1);
EXPECT_CALL(*engine.get(), Stop).Times(1);
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
modifier.SetEGLManager(std::move(egl_manager));
view.SetEngine(engine.get());
@@ -1471,12 +1460,13 @@ TEST(FlutterWindowsViewTest, EnablesVSyncAfterStartup) {
// If this happens, the app must synchronize with the vsync to prevent
// screen tearing.
TEST(FlutterWindowsViewTest, UpdatesVSyncOnDwmUpdates) {
auto engine = std::make_unique<MockFlutterWindowsEngine>();
std::unique_ptr<MockFlutterWindowsEngine> engine =
std::make_unique<MockFlutterWindowsEngine>();
auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
auto egl_manager = std::make_unique<egl::MockManager>();
auto surface = std::make_unique<egl::MockWindowSurface>();
std::unique_ptr<egl::MockManager> egl_manager =
std::make_unique<egl::MockManager>();
EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(true));
@@ -1491,19 +1481,17 @@ TEST(FlutterWindowsViewTest, UpdatesVSyncOnDwmUpdates) {
.WillOnce(Return(true));
EXPECT_CALL(*egl_manager.get(), render_context).Times(0);
EXPECT_CALL(*egl_manager.get(), surface)
.WillRepeatedly(Return(surface.get()));
EngineModifier modifier(engine.get());
FlutterWindowsView view(std::move(window_binding_handler),
std::move(windows_proc_table));
InSequence s;
EXPECT_CALL(*surface.get(), SetVSyncEnabled(true)).Times(1);
EXPECT_CALL(*surface.get(), SetVSyncEnabled(false)).Times(1);
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(true)).Times(1);
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(false)).Times(1);
EXPECT_CALL(*engine.get(), Stop).Times(1);
EXPECT_CALL(*surface.get(), Destroy).Times(1);
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
modifier.SetEGLManager(std::move(egl_manager));
view.SetEngine(engine.get());

View File

@@ -18,12 +18,17 @@ class MockManager : public flutter::egl::Manager {
public:
MockManager() : Manager(false) {}
MOCK_METHOD(bool, CreateWindowSurface, (HWND, size_t, size_t), (override));
MOCK_METHOD(void, ResizeWindowSurface, (HWND, size_t, size_t), (override));
MOCK_METHOD(bool, CreateSurface, (HWND, EGLint, EGLint), (override));
MOCK_METHOD(void, ResizeSurface, (HWND, EGLint, EGLint, bool), (override));
MOCK_METHOD(void, DestroySurface, (), (override));
MOCK_METHOD(bool, MakeCurrent, (), (override));
MOCK_METHOD(void, SetVSyncEnabled, (bool), (override));
MOCK_METHOD(bool, SwapBuffers, (), (override));
MOCK_METHOD(flutter::egl::Context*, render_context, (), (const, override));
MOCK_METHOD(flutter::egl::Context*, resource_context, (), (const, override));
MOCK_METHOD(flutter::egl::WindowSurface*, surface, (), (const, override));
private:
FML_DISALLOW_COPY_AND_ASSIGN(MockManager);

View File

@@ -1,35 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_EGL_MOCK_WINDOW_SURFACE_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_EGL_MOCK_WINDOW_SURFACE_H_
#include "flutter/fml/macros.h"
#include "flutter/shell/platform/windows/egl/window_surface.h"
#include "gmock/gmock.h"
namespace flutter {
namespace testing {
namespace egl {
/// Mock for the |WindowSurface| base class.
class MockWindowSurface : public flutter::egl::WindowSurface {
public:
MockWindowSurface()
: WindowSurface(EGL_NO_DISPLAY, EGL_NO_CONTEXT, EGL_NO_SURFACE, 0, 0) {}
MOCK_METHOD(bool, Destroy, (), (override));
MOCK_METHOD(bool, MakeCurrent, (), (const, override));
MOCK_METHOD(bool, SwapBuffers, (), (const, override));
MOCK_METHOD(bool, SetVSyncEnabled, (bool), (override));
private:
FML_DISALLOW_COPY_AND_ASSIGN(MockWindowSurface);
};
} // namespace egl
} // namespace testing
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_EGL_MOCK_WINDOW_SURFACE_H_