10 #include "flutter/shell/platform/windows/testing/engine_modifier.h"
11 #include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
12 #include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
13 #include "flutter/shell/platform/windows/testing/windows_test.h"
14 #include "gmock/gmock.h"
15 #include "gtest/gtest.h"
21 using ::testing::Return;
23 class MockFlutterWindowsView :
public FlutterWindowsView {
26 std::unique_ptr<WindowBindingHandler> window)
31 PresentSoftwareBitmap,
32 (
const void* allocation,
size_t row_bytes,
size_t height),
34 MOCK_METHOD(
bool, ClearSoftwareBitmap, (), (
override));
37 FML_DISALLOW_COPY_AND_ASSIGN(MockFlutterWindowsView);
40 class CompositorSoftwareTest :
public WindowsTest {
42 CompositorSoftwareTest() =
default;
43 virtual ~CompositorSoftwareTest() =
default;
46 FlutterWindowsEngine* engine() {
return engine_.get(); }
47 MockFlutterWindowsView* view() {
return view_.get(); }
49 void UseEngineWithView() {
50 FlutterWindowsEngineBuilder builder{GetContext()};
52 auto window = std::make_unique<MockWindowBindingHandler>();
53 EXPECT_CALL(*window.get(), SetView).Times(1);
54 EXPECT_CALL(*window.get(), GetWindowHandle).WillRepeatedly(Return(
nullptr));
56 engine_ = builder.Build();
57 view_ = std::make_unique<MockFlutterWindowsView>(engine_.get(),
62 std::unique_ptr<FlutterWindowsEngine> engine_;
63 std::unique_ptr<MockFlutterWindowsView> view_;
65 FML_DISALLOW_COPY_AND_ASSIGN(CompositorSoftwareTest);
70 TEST_F(CompositorSoftwareTest, CreateBackingStore) {
73 FlutterBackingStoreConfig config = {};
74 FlutterBackingStore backing_store = {};
80 TEST_F(CompositorSoftwareTest, Present) {
85 FlutterBackingStoreConfig config = {};
86 FlutterBackingStore backing_store = {};
90 FlutterLayer layer = {};
91 layer.type = kFlutterLayerContentTypeBackingStore;
92 layer.backing_store = &backing_store;
93 const FlutterLayer* layer_ptr = &layer;
95 EXPECT_CALL(*view(), PresentSoftwareBitmap).WillOnce(Return(
true));
96 EXPECT_TRUE(compositor.
Present(view(), &layer_ptr, 1));
101 TEST_F(CompositorSoftwareTest, PresentEmpty) {
106 EXPECT_CALL(*view(), ClearSoftwareBitmap).WillOnce(Return(
true));
107 EXPECT_TRUE(compositor.
Present(view(),
nullptr, 0));
117 TEST_F(CompositorSoftwareTest, PresentMultiLayers) {
122 FlutterBackingStoreConfig config = {
sizeof(config), {2, 2}};
123 FlutterBackingStore backing_store0 = {
sizeof(FlutterBackingStore),
nullptr};
124 FlutterBackingStore backing_store1 = {
sizeof(FlutterBackingStore),
nullptr};
129 uint32_t pixels0[4] = {0xff000000, 0xff0000ff, 0xff00ff00, 0xffffffff};
130 uint32_t pixels1[4] = {0x7f0000ff, 0x00ffffff, 0x7fff0000, 0xff000000};
132 std::memcpy(
const_cast<void*
>(backing_store0.software.allocation), pixels0,
133 sizeof(uint32_t) * 4);
134 std::memcpy(
const_cast<void*
>(backing_store1.software.allocation), pixels1,
135 sizeof(uint32_t) * 4);
137 FlutterLayer layer0 = {};
138 layer0.type = kFlutterLayerContentTypeBackingStore;
139 layer0.backing_store = &backing_store0;
140 layer0.offset = {0, 0};
141 layer0.size = {2, 2};
143 FlutterLayer layer1 = layer0;
144 layer1.backing_store = &backing_store1;
145 const FlutterLayer* layer_ptr[2] = {&layer0, &layer1};
147 EXPECT_CALL(*view(), PresentSoftwareBitmap)
148 .WillOnce([&](
const void* allocation,
size_t row_bytes,
size_t height) {
149 auto pixel_data =
static_cast<const uint32_t*
>(allocation);
150 EXPECT_EQ(row_bytes, 2 *
sizeof(uint32_t));
151 EXPECT_EQ(height, 2);
152 EXPECT_EQ(pixel_data[0], 0xff00007f);
153 EXPECT_EQ(pixel_data[1], 0xff0000ff);
154 EXPECT_EQ(pixel_data[2], 0xff7f8000);
155 EXPECT_EQ(pixel_data[3], 0xff000000);
158 EXPECT_TRUE(compositor.
Present(view(), layer_ptr, 2));
167 TEST_F(CompositorSoftwareTest, PresentOffsetLayers) {
172 FlutterBackingStoreConfig config0 = {
sizeof(FlutterBackingStoreConfig),
174 FlutterBackingStore backing_store0 = {
sizeof(FlutterBackingStore),
nullptr};
175 FlutterBackingStoreConfig config1 = {
sizeof(FlutterBackingStoreConfig),
177 FlutterBackingStore backing_store1 = {
sizeof(FlutterBackingStore),
nullptr};
182 uint32_t pixels0 = 0xff0000ff;
183 uint32_t pixels1[2] = {0xffff0000, 0xffff0000};
185 std::memcpy(
const_cast<void*
>(backing_store0.software.allocation), &pixels0,
186 sizeof(uint32_t) * 1);
187 std::memcpy(
const_cast<void*
>(backing_store1.software.allocation), pixels1,
188 sizeof(uint32_t) * 2);
190 FlutterLayer layer0 = {};
191 layer0.type = kFlutterLayerContentTypeBackingStore;
192 layer0.backing_store = &backing_store0;
193 layer0.offset = {0, 0};
194 layer0.size = {1, 1};
196 FlutterLayer layer1 = layer0;
197 layer1.backing_store = &backing_store1;
198 layer1.offset = {0, 1};
199 layer1.size = {2, 1};
200 const FlutterLayer* layer_ptr[2] = {&layer0, &layer1};
202 EXPECT_CALL(*view(), PresentSoftwareBitmap)
203 .WillOnce([&](
const void* allocation,
size_t row_bytes,
size_t height) {
204 auto pixel_data =
static_cast<const uint32_t*
>(allocation);
205 EXPECT_EQ(row_bytes, 2 *
sizeof(uint32_t));
206 EXPECT_EQ(height, 2);
207 EXPECT_EQ(pixel_data[0], 0xff0000ff);
208 EXPECT_EQ(pixel_data[1], 0xff000000);
209 EXPECT_EQ(pixel_data[2], 0xffff0000);
210 EXPECT_EQ(pixel_data[3], 0xffff0000);
213 EXPECT_TRUE(compositor.
Present(view(), layer_ptr, 2));