8#include "flutter/impeller/renderer/backend/gles/gles.h"
9#include "flutter/shell/platform/windows/compositor_opengl.h"
10#include "flutter/shell/platform/windows/egl/manager.h"
11#include "flutter/shell/platform/windows/flutter_windows_view.h"
12#include "flutter/shell/platform/windows/testing/egl/mock_context.h"
13#include "flutter/shell/platform/windows/testing/egl/mock_manager.h"
14#include "flutter/shell/platform/windows/testing/egl/mock_window_surface.h"
15#include "flutter/shell/platform/windows/testing/engine_modifier.h"
16#include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
17#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
18#include "flutter/shell/platform/windows/testing/view_modifier.h"
19#include "flutter/shell/platform/windows/testing/windows_test.h"
20#include "gmock/gmock.h"
21#include "gtest/gtest.h"
27using ::testing::AnyNumber;
28using ::testing::Return;
30const unsigned char* MockGetString(GLenum
name) {
33 case GL_SHADING_LANGUAGE_VERSION:
34 return reinterpret_cast<const unsigned char*
>(
"3.0");
36 return reinterpret_cast<const unsigned char*
>(
"");
40void MockGetIntegerv(GLenum
name,
int*
value) {
44GLenum MockGetError() {
54 return reinterpret_cast<void*
>(&MockGetString);
56 return reinterpret_cast<void*
>(&MockGetIntegerv);
58 return reinterpret_cast<void*
>(&MockGetError);
60 return reinterpret_cast<void*
>(&DoNothing);
64class CompositorOpenGLTest :
public WindowsTest {
66 CompositorOpenGLTest() =
default;
67 virtual ~CompositorOpenGLTest() =
default;
70 FlutterWindowsEngine*
engine() {
return engine_.get(); }
71 FlutterWindowsView* view() {
return view_.get(); }
72 egl::MockManager* egl_manager() {
return egl_manager_; }
73 egl::MockContext* render_context() {
return render_context_.get(); }
76 void UseHeadlessEngine() {
77 auto egl_manager = std::make_unique<egl::MockManager>();
78 render_context_ = std::make_unique<egl::MockContext>();
79 egl_manager_ = egl_manager.get();
81 EXPECT_CALL(*egl_manager_, render_context)
83 .WillRepeatedly(Return(render_context_.get()));
88 EngineModifier modifier{engine_.get()};
89 modifier.SetEGLManager(std::move(egl_manager));
92 void UseEngineWithView(
bool add_surface =
true) {
95 auto window = std::make_unique<MockWindowBindingHandler>();
96 EXPECT_CALL(*
window.get(), SetView).Times(1);
97 EXPECT_CALL(*
window.get(), GetWindowHandle).WillRepeatedly(Return(
nullptr));
99 view_ = std::make_unique<FlutterWindowsView>(
kImplicitViewId, engine_.get(),
103 auto surface = std::make_unique<egl::MockWindowSurface>();
106 EXPECT_CALL(*
surface_, Destroy).Times(AnyNumber());
108 ViewModifier modifier{view_.get()};
109 modifier.SetSurface(std::move(
surface));
114 std::unique_ptr<FlutterWindowsEngine> engine_;
115 std::unique_ptr<FlutterWindowsView> view_;
116 std::unique_ptr<egl::MockContext> render_context_;
118 egl::MockManager* egl_manager_;
125TEST_F(CompositorOpenGLTest, CreateBackingStore) {
133 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(
true));
134 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
135 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
138TEST_F(CompositorOpenGLTest, InitializationFailure) {
146 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(
false));
147 EXPECT_FALSE(compositor.CreateBackingStore(config, &backing_store));
158 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(
true));
159 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
166 EXPECT_CALL(*
surface(), IsValid).WillRepeatedly(Return(
true));
167 EXPECT_CALL(*
surface(), MakeCurrent).WillOnce(Return(
true));
168 EXPECT_CALL(*
surface(), SwapBuffers).WillOnce(Return(
true));
169 EXPECT_TRUE(compositor.Present(view(), &layer_ptr, 1));
171 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
174TEST_F(CompositorOpenGLTest, PresentEmpty) {
181 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(
true));
182 EXPECT_CALL(*
surface(), IsValid).WillRepeatedly(Return(
true));
183 EXPECT_CALL(*
surface(), MakeCurrent).WillOnce(Return(
true));
184 EXPECT_CALL(*
surface(), SwapBuffers).WillOnce(Return(
true));
185 EXPECT_TRUE(compositor.Present(view(),
nullptr, 0));
188TEST_F(CompositorOpenGLTest, NoSurfaceIgnored) {
189 UseEngineWithView(
false);
196 EXPECT_CALL(*render_context(), MakeCurrent).WillOnce(Return(
true));
197 ASSERT_TRUE(compositor.CreateBackingStore(config, &backing_store));
204 EXPECT_FALSE(compositor.Present(view(), &layer_ptr, 1));
206 ASSERT_TRUE(compositor.CollectBackingStore(&backing_store));
std::function< void *(const char *function_name)> Resolver
@ kFlutterLayerContentTypeBackingStore
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
SK_API GrDirectContext * GetContext(const SkImage *src)
const char *const function_name
TEST_F(DisplayListTest, Defaults)
constexpr int64_t kImplicitViewId
DEF_SWITCHES_START aot vmservice shared library name
FlutterLayerContentType type
const FlutterBackingStore * backing_store
#define EXPECT_TRUE(handle)