[Windows] Introduce egl::Context (flutter/engine#49954)
This introduces a new `egl::Context` type that abstracts a raw `EGLContext`. This also removes the EGL context logic out from `EGLManager`. Part of https://github.com/flutter/flutter/issues/141996 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -7233,6 +7233,10 @@ ORIGIN: ../../../flutter/shell/platform/windows/direct_manipulation.cc + ../../.
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/direct_manipulation.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/dpi_utils.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/dpi_utils.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/egl/context.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/egl/context.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/egl/egl.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/egl/egl.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/egl/manager.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/egl/manager.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/windows/egl/proc_table.cc + ../../../flutter/LICENSE
|
||||
@@ -10103,6 +10107,10 @@ FILE: ../../../flutter/shell/platform/windows/direct_manipulation.cc
|
||||
FILE: ../../../flutter/shell/platform/windows/direct_manipulation.h
|
||||
FILE: ../../../flutter/shell/platform/windows/dpi_utils.cc
|
||||
FILE: ../../../flutter/shell/platform/windows/dpi_utils.h
|
||||
FILE: ../../../flutter/shell/platform/windows/egl/context.cc
|
||||
FILE: ../../../flutter/shell/platform/windows/egl/context.h
|
||||
FILE: ../../../flutter/shell/platform/windows/egl/egl.cc
|
||||
FILE: ../../../flutter/shell/platform/windows/egl/egl.h
|
||||
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
|
||||
|
||||
@@ -51,6 +51,10 @@ source_set("flutter_windows_source") {
|
||||
"direct_manipulation.h",
|
||||
"dpi_utils.cc",
|
||||
"dpi_utils.h",
|
||||
"egl/context.cc",
|
||||
"egl/context.h",
|
||||
"egl/egl.cc",
|
||||
"egl/egl.h",
|
||||
"egl/manager.cc",
|
||||
"egl/manager.h",
|
||||
"egl/proc_table.cc",
|
||||
@@ -202,6 +206,7 @@ executable("flutter_windows_unittests") {
|
||||
"settings_plugin_unittests.cc",
|
||||
"system_utils_unittests.cc",
|
||||
"task_runner_unittests.cc",
|
||||
"testing/egl/mock_context.h",
|
||||
"testing/egl/mock_manager.h",
|
||||
"testing/egl/mock_proc_table.h",
|
||||
"testing/engine_modifier.h",
|
||||
|
||||
56
engine/src/flutter/shell/platform/windows/egl/context.cc
Normal file
56
engine/src/flutter/shell/platform/windows/egl/context.cc
Normal file
@@ -0,0 +1,56 @@
|
||||
// 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/context.h"
|
||||
|
||||
#include "flutter/shell/platform/windows/egl/egl.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace egl {
|
||||
|
||||
Context::Context(EGLDisplay display, EGLContext context)
|
||||
: display_(display), context_(context) {}
|
||||
|
||||
Context::~Context() {
|
||||
if (display_ == EGL_NO_DISPLAY && context_ == EGL_NO_CONTEXT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (::eglDestroyContext(display_, context_) != EGL_TRUE) {
|
||||
WINDOWS_LOG_EGL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
bool Context::IsCurrent() const {
|
||||
return ::eglGetCurrentContext() == context_;
|
||||
}
|
||||
|
||||
bool Context::MakeCurrent() const {
|
||||
const auto result =
|
||||
::eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, context_);
|
||||
if (result != EGL_TRUE) {
|
||||
WINDOWS_LOG_EGL_ERROR;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Context::ClearCurrent() const {
|
||||
const auto result = ::eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
EGL_NO_CONTEXT);
|
||||
if (result != EGL_TRUE) {
|
||||
WINDOWS_LOG_EGL_ERROR;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const EGLContext& Context::GetHandle() const {
|
||||
return context_;
|
||||
}
|
||||
|
||||
} // namespace egl
|
||||
} // namespace flutter
|
||||
51
engine/src/flutter/shell/platform/windows/egl/context.h
Normal file
51
engine/src/flutter/shell/platform/windows/egl/context.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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_CONTEXT_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_CONTEXT_H_
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace egl {
|
||||
|
||||
// An EGL context to interact with OpenGL.
|
||||
//
|
||||
// This enables automatic eror logging and mocking.
|
||||
//
|
||||
// Flutter Windows uses this to create render and resource contexts.
|
||||
class Context {
|
||||
public:
|
||||
Context(EGLDisplay display, EGLContext context);
|
||||
~Context();
|
||||
|
||||
// Check if this context is currently bound to the thread.
|
||||
virtual bool IsCurrent() const;
|
||||
|
||||
// Bind the context to the thread without any read or draw surfaces.
|
||||
//
|
||||
// Returns true on success.
|
||||
virtual bool MakeCurrent() const;
|
||||
|
||||
// Unbind any context and surfaces from the thread.
|
||||
//
|
||||
// Returns true on success.
|
||||
virtual bool ClearCurrent() const;
|
||||
|
||||
// Get the raw EGL context.
|
||||
virtual const EGLContext& GetHandle() const;
|
||||
|
||||
private:
|
||||
EGLDisplay display_ = EGL_NO_DISPLAY;
|
||||
EGLContext context_ = EGL_NO_CONTEXT;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Context);
|
||||
};
|
||||
|
||||
} // namespace egl
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_CONTEXT_H_
|
||||
68
engine/src/flutter/shell/platform/windows/egl/egl.cc
Normal file
68
engine/src/flutter/shell/platform/windows/egl/egl.cc
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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/egl.h"
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace egl {
|
||||
|
||||
namespace {
|
||||
|
||||
const char* EGLErrorToString(EGLint error) {
|
||||
switch (error) {
|
||||
case EGL_SUCCESS:
|
||||
return "Success";
|
||||
case EGL_NOT_INITIALIZED:
|
||||
return "Not Initialized";
|
||||
case EGL_BAD_ACCESS:
|
||||
return "Bad Access";
|
||||
case EGL_BAD_ALLOC:
|
||||
return "Bad Alloc";
|
||||
case EGL_BAD_ATTRIBUTE:
|
||||
return "Bad Attribute";
|
||||
case EGL_BAD_CONTEXT:
|
||||
return "Bad Context";
|
||||
case EGL_BAD_CONFIG:
|
||||
return "Bad Config";
|
||||
case EGL_BAD_CURRENT_SURFACE:
|
||||
return "Bad Current Surface";
|
||||
case EGL_BAD_DISPLAY:
|
||||
return "Bad Display";
|
||||
case EGL_BAD_SURFACE:
|
||||
return "Bad Surface";
|
||||
case EGL_BAD_MATCH:
|
||||
return "Bad Match";
|
||||
case EGL_BAD_PARAMETER:
|
||||
return "Bad Parameter";
|
||||
case EGL_BAD_NATIVE_PIXMAP:
|
||||
return "Bad Native Pixmap";
|
||||
case EGL_BAD_NATIVE_WINDOW:
|
||||
return "Bad Native Window";
|
||||
case EGL_CONTEXT_LOST:
|
||||
return "Context Lost";
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void LogEGLError(std::string_view message) {
|
||||
const EGLint error = ::eglGetError();
|
||||
return FML_LOG(ERROR) << "EGL Error: " << EGLErrorToString(error) << " ("
|
||||
<< error << ") " << message;
|
||||
}
|
||||
|
||||
void LogEGLError(std::string_view file, int line) {
|
||||
std::stringstream stream;
|
||||
stream << "in " << file << ":" << line;
|
||||
LogEGLError(stream.str());
|
||||
}
|
||||
|
||||
} // namespace egl
|
||||
} // namespace flutter
|
||||
24
engine/src/flutter/shell/platform/windows/egl/egl.h
Normal file
24
engine/src/flutter/shell/platform/windows/egl/egl.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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_EGL_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_EGL_H_
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace flutter {
|
||||
namespace egl {
|
||||
|
||||
/// Log the last EGL error with an error message.
|
||||
void LogEGLError(std::string_view message);
|
||||
|
||||
/// Log the last EGL error.
|
||||
void LogEGLError(std::string_view file, int line);
|
||||
|
||||
#define WINDOWS_LOG_EGL_ERROR LogEGLError(__FILE__, __LINE__);
|
||||
|
||||
} // namespace egl
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EGL_EGL_H_
|
||||
@@ -7,14 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
// Logs an EGL error to stderr. This automatically calls eglGetError()
|
||||
// and logs the error code.
|
||||
static void LogEglError(std::string message) {
|
||||
EGLint error = ::eglGetError();
|
||||
FML_LOG(ERROR) << "EGL: " << message;
|
||||
FML_LOG(ERROR) << "EGL: eglGetError returned " << error;
|
||||
}
|
||||
#include "flutter/shell/platform/windows/egl/egl.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace egl {
|
||||
@@ -109,7 +102,7 @@ bool Manager::InitializeDisplay() {
|
||||
reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
|
||||
::eglGetProcAddress("eglGetPlatformDisplayEXT"));
|
||||
if (!egl_get_platform_display_EXT) {
|
||||
LogEglError("eglGetPlatformDisplayEXT not available");
|
||||
LogEGLError("eglGetPlatformDisplayEXT not available");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -123,7 +116,7 @@ bool Manager::InitializeDisplay() {
|
||||
|
||||
if (display_ == EGL_NO_DISPLAY) {
|
||||
if (is_last) {
|
||||
LogEglError("Failed to get a compatible EGLdisplay");
|
||||
LogEGLError("Failed to get a compatible EGLdisplay");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -133,7 +126,7 @@ bool Manager::InitializeDisplay() {
|
||||
|
||||
if (::eglInitialize(display_, nullptr, nullptr) == EGL_FALSE) {
|
||||
if (is_last) {
|
||||
LogEglError("Failed to initialize EGL via ANGLE");
|
||||
LogEGLError("Failed to initialize EGL via ANGLE");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -189,27 +182,29 @@ bool Manager::InitializeConfig(bool enable_impeller) {
|
||||
}
|
||||
}
|
||||
|
||||
LogEglError("Failed to choose EGL config");
|
||||
LogEGLError("Failed to choose EGL config");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Manager::InitializeContexts() {
|
||||
const EGLint context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
|
||||
|
||||
render_context_ =
|
||||
auto const render_context =
|
||||
::eglCreateContext(display_, config_, EGL_NO_CONTEXT, context_attributes);
|
||||
if (render_context_ == EGL_NO_CONTEXT) {
|
||||
LogEglError("Failed to create EGL render context");
|
||||
if (render_context == EGL_NO_CONTEXT) {
|
||||
LogEGLError("Failed to create EGL render context");
|
||||
return false;
|
||||
}
|
||||
|
||||
resource_context_ = ::eglCreateContext(display_, config_, render_context_,
|
||||
context_attributes);
|
||||
if (resource_context_ == EGL_NO_CONTEXT) {
|
||||
LogEglError("Failed to create EGL resource context");
|
||||
auto const resource_context =
|
||||
::eglCreateContext(display_, config_, render_context, context_attributes);
|
||||
if (resource_context == EGL_NO_CONTEXT) {
|
||||
LogEGLError("Failed to create EGL resource context");
|
||||
return false;
|
||||
}
|
||||
|
||||
render_context_ = std::make_unique<Context>(display_, render_context);
|
||||
resource_context_ = std::make_unique<Context>(display_, resource_context);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -247,26 +242,12 @@ bool Manager::InitializeDevice() {
|
||||
void Manager::CleanUp() {
|
||||
EGLBoolean result = EGL_FALSE;
|
||||
|
||||
// Needs to be reset before destroying the EGLContext.
|
||||
// Needs to be reset before destroying the contexts.
|
||||
resolved_device_.Reset();
|
||||
|
||||
if (display_ != EGL_NO_DISPLAY && render_context_ != EGL_NO_CONTEXT) {
|
||||
result = ::eglDestroyContext(display_, render_context_);
|
||||
render_context_ = EGL_NO_CONTEXT;
|
||||
|
||||
if (result == EGL_FALSE) {
|
||||
LogEglError("Failed to destroy context");
|
||||
}
|
||||
}
|
||||
|
||||
if (display_ != EGL_NO_DISPLAY && resource_context_ != EGL_NO_CONTEXT) {
|
||||
result = ::eglDestroyContext(display_, resource_context_);
|
||||
resource_context_ = EGL_NO_CONTEXT;
|
||||
|
||||
if (result == EGL_FALSE) {
|
||||
LogEglError("Failed to destroy resource context");
|
||||
}
|
||||
}
|
||||
// Needs to be reset before destroying the EGLDisplay.
|
||||
render_context_.reset();
|
||||
resource_context_.reset();
|
||||
|
||||
if (display_ != EGL_NO_DISPLAY) {
|
||||
// Display is reused between instances so only terminate display
|
||||
@@ -300,7 +281,7 @@ bool Manager::CreateSurface(HWND hwnd, EGLint width, EGLint height) {
|
||||
static_cast<EGLNativeWindowType>(hwnd),
|
||||
surface_attributes);
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
LogEglError("Surface creation failed.");
|
||||
LogEGLError("Surface creation failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -323,7 +304,7 @@ void Manager::ResizeSurface(HWND hwnd,
|
||||
// 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
|
||||
ClearContext();
|
||||
render_context_->ClearCurrent();
|
||||
DestroySurface();
|
||||
if (!CreateSurface(hwnd, width, height)) {
|
||||
FML_LOG(ERROR) << "Manager::ResizeSurface failed to create surface";
|
||||
@@ -360,23 +341,8 @@ bool Manager::HasContextCurrent() {
|
||||
}
|
||||
|
||||
bool Manager::MakeCurrent() {
|
||||
return (::eglMakeCurrent(display_, surface_, surface_, render_context_) ==
|
||||
EGL_TRUE);
|
||||
}
|
||||
|
||||
bool Manager::ClearCurrent() {
|
||||
return (::eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
EGL_NO_CONTEXT) == EGL_TRUE);
|
||||
}
|
||||
|
||||
bool Manager::ClearContext() {
|
||||
return (::eglMakeCurrent(display_, nullptr, nullptr, render_context_) ==
|
||||
EGL_TRUE);
|
||||
}
|
||||
|
||||
bool Manager::MakeResourceCurrent() {
|
||||
return (::eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
resource_context_) == EGL_TRUE);
|
||||
return (::eglMakeCurrent(display_, surface_, surface_,
|
||||
render_context_->GetHandle()) == EGL_TRUE);
|
||||
}
|
||||
|
||||
bool Manager::SwapBuffers() {
|
||||
@@ -392,7 +358,7 @@ EGLSurface Manager::CreateSurfaceFromHandle(EGLenum handle_type,
|
||||
|
||||
void Manager::SetVSyncEnabled(bool enabled) {
|
||||
if (!MakeCurrent()) {
|
||||
LogEglError("Unable to make surface current to update the swap interval");
|
||||
LogEGLError("Unable to make surface current to update the swap interval");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -402,7 +368,7 @@ void Manager::SetVSyncEnabled(bool 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");
|
||||
LogEGLError("Unable to update the swap interval");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -418,5 +384,13 @@ bool Manager::GetDevice(ID3D11Device** device) {
|
||||
return (resolved_device_ != nullptr);
|
||||
}
|
||||
|
||||
Context* Manager::render_context() const {
|
||||
return render_context_.get();
|
||||
}
|
||||
|
||||
Context* Manager::resource_context() const {
|
||||
return resource_context_.get();
|
||||
}
|
||||
|
||||
} // namespace egl
|
||||
} // namespace flutter
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/platform/windows/egl/context.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace egl {
|
||||
@@ -40,7 +41,7 @@ class Manager {
|
||||
// dimensions surface is created at.
|
||||
//
|
||||
// After the surface is created, |SetVSyncEnabled| should be called on a
|
||||
// thread that can bind the |egl_context_|.
|
||||
// thread that can bind the |render_context_|.
|
||||
virtual bool CreateSurface(HWND hwnd, EGLint width, EGLint height);
|
||||
|
||||
// Resizes backing surface from current size to newly requested size
|
||||
@@ -48,7 +49,7 @@ class Manager {
|
||||
// not match current surface dimensions. Target represents the visual entity
|
||||
// to bind to.
|
||||
//
|
||||
// This binds |egl_context_| to the current thread.
|
||||
// This binds |render_context_| to the current thread.
|
||||
virtual void ResizeSurface(HWND hwnd,
|
||||
EGLint width,
|
||||
EGLint height,
|
||||
@@ -64,20 +65,10 @@ class Manager {
|
||||
// Check if the current thread has a context bound.
|
||||
bool HasContextCurrent();
|
||||
|
||||
// Binds |egl_context_| to the current rendering thread and to the draw and
|
||||
// Binds |render_context_| to the current rendering thread and to the draw and
|
||||
// read surfaces returning a boolean result reflecting success.
|
||||
virtual bool MakeCurrent();
|
||||
|
||||
// Unbinds the current EGL context from the current thread.
|
||||
virtual bool ClearCurrent();
|
||||
|
||||
// Clears the |egl_context_| draw and read surfaces.
|
||||
bool ClearContext();
|
||||
|
||||
// Binds egl_resource_context_ to the current rendering thread and to the draw
|
||||
// and read surfaces returning a boolean result reflecting success.
|
||||
bool MakeResourceCurrent();
|
||||
|
||||
// Swaps the front and back buffers of the DX11 swapchain backing surface if
|
||||
// not null.
|
||||
virtual bool SwapBuffers();
|
||||
@@ -96,13 +87,19 @@ class Manager {
|
||||
// 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 |egl_context_| to the current thread and makes the render
|
||||
// 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);
|
||||
|
||||
// Get the EGL context used to render Flutter views.
|
||||
virtual Context* render_context() const;
|
||||
|
||||
// Get the EGL context used for async texture uploads.
|
||||
virtual Context* resource_context() const;
|
||||
|
||||
protected:
|
||||
// Creates a new surface manager retaining reference to the passed-in target
|
||||
// for the lifetime of the manager.
|
||||
@@ -135,12 +132,11 @@ class Manager {
|
||||
// EGL framebuffer configuration.
|
||||
EGLConfig config_ = nullptr;
|
||||
|
||||
// EGL representation of current rendering context.
|
||||
EGLContext render_context_ = EGL_NO_CONTEXT;
|
||||
// The EGL context used to render Flutter views.
|
||||
std::unique_ptr<Context> render_context_;
|
||||
|
||||
// EGL representation of current rendering context used for async texture
|
||||
// uploads.
|
||||
EGLContext resource_context_ = EGL_NO_CONTEXT;
|
||||
// The EGL context used for async texture uploads.
|
||||
std::unique_ptr<Context> resource_context_;
|
||||
|
||||
// Current render_surface that engine will draw into.
|
||||
EGLSurface surface_ = EGL_NO_SURFACE;
|
||||
|
||||
@@ -65,7 +65,7 @@ FlutterRendererConfig GetOpenGLRendererConfig() {
|
||||
if (!host->egl_manager()) {
|
||||
return false;
|
||||
}
|
||||
return host->egl_manager()->ClearContext();
|
||||
return host->egl_manager()->render_context()->ClearCurrent();
|
||||
};
|
||||
config.open_gl.present = [](void* user_data) -> bool { FML_UNREACHABLE(); };
|
||||
config.open_gl.fbo_reset_after_present = true;
|
||||
@@ -82,7 +82,7 @@ FlutterRendererConfig GetOpenGLRendererConfig() {
|
||||
if (!host->egl_manager()) {
|
||||
return false;
|
||||
}
|
||||
return host->egl_manager()->MakeResourceCurrent();
|
||||
return host->egl_manager()->resource_context()->MakeCurrent();
|
||||
};
|
||||
config.open_gl.gl_external_texture_frame_callback =
|
||||
[](void* user_data, int64_t texture_id, size_t width, size_t height,
|
||||
|
||||
@@ -59,7 +59,7 @@ void UpdateVsync(const FlutterWindowsEngine& engine, bool needs_vsync) {
|
||||
egl_manager->SetVSyncEnabled(needs_vsync);
|
||||
|
||||
// Release the EGL context so that the raster thread can use it.
|
||||
if (!egl_manager->ClearCurrent()) {
|
||||
if (!egl_manager->render_context()->ClearCurrent()) {
|
||||
FML_LOG(ERROR)
|
||||
<< "Unable to clear current surface after updating the swap interval";
|
||||
return;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "flutter/shell/platform/windows/flutter_window.h"
|
||||
#include "flutter/shell/platform/windows/flutter_windows_engine.h"
|
||||
#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/engine_modifier.h"
|
||||
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
|
||||
@@ -1305,6 +1306,7 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAtStartup) {
|
||||
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
|
||||
std::unique_ptr<egl::MockManager> egl_manager =
|
||||
std::make_unique<egl::MockManager>();
|
||||
egl::MockContext render_context;
|
||||
|
||||
EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
|
||||
@@ -1321,7 +1323,9 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAtStartup) {
|
||||
.Times(1)
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(false)).Times(1);
|
||||
EXPECT_CALL(*egl_manager.get(), ClearCurrent).WillOnce(Return(true));
|
||||
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(*egl_manager.get(), DestroySurface).Times(1);
|
||||
@@ -1342,6 +1346,7 @@ TEST(FlutterWindowsViewTest, EnablesVSyncAtStartup) {
|
||||
auto windows_proc_table = std::make_shared<MockWindowsProcTable>();
|
||||
std::unique_ptr<egl::MockManager> egl_manager =
|
||||
std::make_unique<egl::MockManager>();
|
||||
egl::MockContext render_context;
|
||||
|
||||
EXPECT_CALL(*engine.get(), running).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(*engine.get(), PostRasterThreadTask).Times(0);
|
||||
@@ -1357,7 +1362,9 @@ TEST(FlutterWindowsViewTest, EnablesVSyncAtStartup) {
|
||||
.Times(1)
|
||||
.WillOnce(Return(true));
|
||||
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(true)).Times(1);
|
||||
EXPECT_CALL(*egl_manager.get(), ClearCurrent).WillOnce(Return(true));
|
||||
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(*egl_manager.get(), DestroySurface).Times(1);
|
||||
@@ -1397,7 +1404,7 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAfterStartup) {
|
||||
return true;
|
||||
});
|
||||
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(false)).Times(1);
|
||||
EXPECT_CALL(*egl_manager.get(), ClearCurrent).Times(0);
|
||||
EXPECT_CALL(*egl_manager.get(), render_context).Times(0);
|
||||
|
||||
EXPECT_CALL(*engine.get(), Stop).Times(1);
|
||||
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
|
||||
@@ -1438,7 +1445,7 @@ TEST(FlutterWindowsViewTest, EnablesVSyncAfterStartup) {
|
||||
return true;
|
||||
});
|
||||
EXPECT_CALL(*egl_manager.get(), SetVSyncEnabled(true)).Times(1);
|
||||
EXPECT_CALL(*egl_manager.get(), ClearCurrent).Times(0);
|
||||
EXPECT_CALL(*egl_manager.get(), render_context).Times(0);
|
||||
|
||||
EXPECT_CALL(*engine.get(), Stop).Times(1);
|
||||
EXPECT_CALL(*egl_manager.get(), DestroySurface).Times(1);
|
||||
@@ -1473,7 +1480,7 @@ TEST(FlutterWindowsViewTest, UpdatesVSyncOnDwmUpdates) {
|
||||
.WillOnce(Return(false))
|
||||
.WillOnce(Return(true));
|
||||
|
||||
EXPECT_CALL(*egl_manager.get(), ClearCurrent).Times(0);
|
||||
EXPECT_CALL(*egl_manager.get(), render_context).Times(0);
|
||||
|
||||
EngineModifier modifier(engine.get());
|
||||
FlutterWindowsView view(std::move(window_binding_handler),
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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_CONTEXT_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_EGL_MOCK_CONTEXT_H_
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/platform/windows/egl/context.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
namespace egl {
|
||||
|
||||
/// Mock for the |Context| base class.
|
||||
class MockContext : public flutter::egl::Context {
|
||||
public:
|
||||
MockContext() : Context(EGL_NO_DISPLAY, EGL_NO_CONTEXT) {}
|
||||
|
||||
MOCK_METHOD(bool, ClearCurrent, (), (const, override));
|
||||
|
||||
private:
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(MockContext);
|
||||
};
|
||||
|
||||
} // namespace egl
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TESTING_EGL_MOCK_CONTEXT_H_
|
||||
@@ -23,11 +23,13 @@ class MockManager : public flutter::egl::Manager {
|
||||
MOCK_METHOD(void, DestroySurface, (), (override));
|
||||
|
||||
MOCK_METHOD(bool, MakeCurrent, (), (override));
|
||||
MOCK_METHOD(bool, ClearCurrent, (), (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));
|
||||
|
||||
private:
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(MockManager);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user