8#include "flutter/shell/platform/windows/compositor_software.h"
9#include "flutter/shell/platform/windows/flutter_windows_view.h"
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"
21using ::testing::Return;
23class 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));
40class 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() {
52 auto window = std::make_unique<MockWindowBindingHandler>();
53 EXPECT_CALL(*
window.get(), SetView).Times(1);
54 EXPECT_CALL(*
window.get(), GetWindowHandle).WillRepeatedly(Return(
nullptr));
57 view_ = std::make_unique<MockFlutterWindowsView>(engine_.get(),
62 std::unique_ptr<FlutterWindowsEngine> engine_;
63 std::unique_ptr<MockFlutterWindowsView> view_;
70TEST_F(CompositorSoftwareTest, CreateBackingStore) {
80TEST_F(CompositorSoftwareTest, Present) {
95 EXPECT_CALL(*view(), PresentSoftwareBitmap).WillOnce(Return(
true));
101TEST_F(CompositorSoftwareTest, PresentEmpty) {
106 EXPECT_CALL(*view(), ClearSoftwareBitmap).WillOnce(Return(
true));
117TEST_F(CompositorSoftwareTest, PresentMultiLayers) {
129 uint32_t pixels0[4] = {0xff000000, 0xff0000ff, 0xff00ff00, 0xffffffff};
130 uint32_t pixels1[4] = {0x7f0000ff, 0x00ffffff, 0x7fff0000, 0xff000000};
133 sizeof(uint32_t) * 4);
135 sizeof(uint32_t) * 4);
141 layer0.
size = {2, 2};
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));
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);
167TEST_F(CompositorSoftwareTest, PresentOffsetLayers) {
182 uint32_t pixels0 = 0xff0000ff;
183 uint32_t pixels1[2] = {0xffff0000, 0xffff0000};
186 sizeof(uint32_t) * 1);
188 sizeof(uint32_t) * 2);
194 layer0.
size = {1, 1};
199 layer1.
size = {2, 1};
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));
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);
bool CollectBackingStore(const FlutterBackingStore *store) override
|Compositor|
bool Present(FlutterWindowsView *view, const FlutterLayer **layers, size_t layers_count) override
|Compositor|
bool CreateBackingStore(const FlutterBackingStoreConfig &config, FlutterBackingStore *result) override
|Compositor|
FlutterWindowsView(FlutterViewId view_id, FlutterWindowsEngine *engine, std::unique_ptr< WindowBindingHandler > window_binding, std::shared_ptr< WindowsProcTable > windows_proc_table=nullptr)
~MockFlutterWindowsView()
MOCK_METHOD(void, NotifyWinEventWrapper,(ui::AXPlatformNodeWin *, ax::mojom::Event),(override))
MockFlutterWindowsView(FlutterWindowsEngine *engine, std::unique_ptr< WindowBindingHandler > wbh)
@ kFlutterLayerContentTypeBackingStore
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
SK_API GrDirectContext * GetContext(const SkImage *src)
TEST_F(DisplayListTest, Defaults)
constexpr int64_t kImplicitViewId
FlutterSoftwareBackingStore software
The description of the software backing store.
FlutterLayerContentType type
const FlutterBackingStore * backing_store
FlutterSize size
The size of the layer (in physical pixels).
#define EXPECT_TRUE(handle)