5#include "flutter/fml/synchronization/waitable_event.h"
6#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
7#include "flutter/shell/platform/windows/egl/proc_table.h"
8#include "flutter/shell/platform/windows/flutter_windows_engine.h"
9#include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h"
10#include "flutter/shell/platform/windows/testing/egl/mock_proc_table.h"
11#include "flutter/shell/platform/windows/testing/engine_modifier.h"
12#include "gtest/gtest.h"
18using ::testing::AtLeast;
20using Microsoft::WRL::ComPtr;
24std::unique_ptr<FlutterWindowsEngine> GetTestEngine() {
29 FlutterProjectBundle project(properties);
30 auto engine = std::make_unique<FlutterWindowsEngine>(project);
32 EngineModifier modifier(
engine.get());
33 modifier.embedder_api().RegisterExternalTexture =
41ComPtr<ID3D11Texture2D> CreateD3dTexture(FlutterWindowsEngine*
engine,
44 ComPtr<ID3D11Device> d3d_device;
45 ComPtr<ID3D11Texture2D> d3d_texture;
46 if (
engine->egl_manager()->GetDevice(d3d_device.GetAddressOf())) {
47 D3D11_TEXTURE2D_DESC texture_description = {};
48 texture_description.MipLevels = 1;
49 texture_description.SampleDesc.Count = 1;
50 texture_description.BindFlags = D3D11_BIND_RENDER_TARGET;
51 texture_description.Usage = D3D11_USAGE_DEFAULT;
52 texture_description.CPUAccessFlags = 0;
53 texture_description.ArraySize = 1;
54 texture_description.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
55 texture_description.Height =
width;
56 texture_description.Width =
height;
57 texture_description.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
59 d3d_device->CreateTexture2D(&texture_description,
nullptr,
60 d3d_texture.GetAddressOf());
67TEST(FlutterWindowsTextureRegistrarTest, CreateDestroy) {
68 std::unique_ptr<FlutterWindowsEngine>
engine = GetTestEngine();
69 auto gl = std::make_shared<egl::MockProcTable>();
75TEST(FlutterWindowsTextureRegistrarTest, RegisterUnregisterTexture) {
76 std::unique_ptr<FlutterWindowsEngine>
engine = GetTestEngine();
78 auto gl = std::make_shared<egl::MockProcTable>();
90 int64_t registered_texture_id = 0;
91 bool register_called =
false;
93 RegisterExternalTexture, ([®ister_called, ®istered_texture_id](
95 register_called =
true;
100 bool unregister_called =
false;
102 UnregisterExternalTexture, ([&unregister_called, ®istered_texture_id](
104 unregister_called =
true;
109 bool mark_frame_available_called =
false;
112 ([&mark_frame_available_called, ®istered_texture_id](
114 mark_frame_available_called =
true;
137 ASSERT_TRUE(unregister_called);
140TEST(FlutterWindowsTextureRegistrarTest, RegisterUnknownTextureType) {
141 std::unique_ptr<FlutterWindowsEngine>
engine = GetTestEngine();
142 auto gl = std::make_shared<egl::MockProcTable>();
154TEST(FlutterWindowsTextureRegistrarTest, PopulatePixelBufferTexture) {
155 std::unique_ptr<FlutterWindowsEngine>
engine = GetTestEngine();
156 auto gl = std::make_shared<egl::MockProcTable>();
160 bool release_callback_called =
false;
163 std::unique_ptr<uint8_t[]> pixels =
168 pixel_buffer.
buffer = pixels.get();
171 bool* called =
reinterpret_cast<bool*
>(release_context);
188 EXPECT_CALL(*
gl.get(), GenTextures(1, _))
190 .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; });
191 EXPECT_CALL(*
gl.get(), BindTexture).Times(1);
192 EXPECT_CALL(*
gl.get(), TexParameteri).Times(AtLeast(1));
193 EXPECT_CALL(*
gl.get(), TexImage2D).Times(1);
194 EXPECT_CALL(*
gl.get(), DeleteTextures(1, _)).Times(1);
201 EXPECT_EQ(flutter_texture.
target, GL_TEXTURE_2D);
205TEST(FlutterWindowsTextureRegistrarTest, PopulateD3dTextureWithHandle) {
206 std::unique_ptr<FlutterWindowsEngine>
engine = GetTestEngine();
207 auto gl = std::make_shared<egl::MockProcTable>();
215 ComPtr<IDXGIResource> shared_resource;
221 bool release_callback_called =
false;
224 surface_descriptor.
handle = shared_handle;
229 bool* called =
reinterpret_cast<bool*
>(release_context);
251 EXPECT_CALL(*
gl.get(), GenTextures(1, _))
253 .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; });
254 EXPECT_CALL(*
gl.get(), BindTexture).Times(1);
255 EXPECT_CALL(*
gl.get(), TexParameteri).Times(AtLeast(1));
256 EXPECT_CALL(*
gl.get(), DeleteTextures(1, _)).Times(1);
263 EXPECT_EQ(flutter_texture.
target, GL_TEXTURE_2D);
267TEST(FlutterWindowsTextureRegistrarTest, PopulateD3dTexture) {
268 std::unique_ptr<FlutterWindowsEngine>
engine = GetTestEngine();
269 auto gl = std::make_shared<egl::MockProcTable>();
277 bool release_callback_called =
false;
280 surface_descriptor.
handle = d3d_texture.Get();
285 bool* called =
reinterpret_cast<bool*
>(release_context);
307 EXPECT_CALL(*
gl.get(), GenTextures(1, _))
309 .WillOnce([](GLsizei n, GLuint* textures) { textures[0] = 1; });
310 EXPECT_CALL(*
gl.get(), BindTexture).Times(1);
311 EXPECT_CALL(*
gl.get(), TexParameteri).Times(AtLeast(1));
312 EXPECT_CALL(*
gl.get(), DeleteTextures(1, _)).Times(1);
319 EXPECT_EQ(flutter_texture.
target, GL_TEXTURE_2D);
323TEST(FlutterWindowsTextureRegistrarTest, PopulateInvalidTexture) {
324 std::unique_ptr<FlutterWindowsEngine>
engine = GetTestEngine();
325 auto gl = std::make_shared<egl::MockProcTable>();
333TEST(FlutterWindowsTextureRegistrarTest,
334 UnregisterTextureWithEngineDownInvokesCallback) {
335 std::unique_ptr<FlutterWindowsEngine>
engine = GetTestEngine();
336 auto gl = std::make_shared<egl::MockProcTable>();
FlutterEngineProcTable & embedder_api()
bool PopulateTexture(int64_t texture_id, size_t width, size_t height, FlutterOpenGLTexture *texture)
int64_t RegisterTexture(const FlutterDesktopTextureInfo *texture_info)
void UnregisterTexture(int64_t texture_id, fml::closure callback=nullptr)
bool MarkTextureFrameAvailable(int64_t texture_id)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
@ kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle
@ kFlutterDesktopGpuSurfaceTypeD3d11Texture2D
FlutterDesktopTextureType
@ kFlutterDesktopGpuSurfaceTexture
@ kFlutterDesktopPixelBufferTexture
TEST(DisplayListComplexity, EmptyDisplayList)
#define MOCK_ENGINE_PROC(proc, mock_impl)
const char * aot_library_path
const char * icu_data_path
void(* release_callback)(void *release_context)
FlutterDesktopGpuSurfaceTextureCallback callback
FlutterDesktopGpuSurfaceType type
FlutterDesktopPixelBufferTextureCallback callback
void(* release_callback)(void *release_context)
FlutterDesktopGpuSurfaceTextureConfig gpu_surface_config
FlutterDesktopTextureType type
FlutterDesktopPixelBufferTextureConfig pixel_buffer_config
FlutterEngineRegisterExternalTextureFnPtr RegisterExternalTexture
FlutterEngineUnregisterExternalTextureFnPtr UnregisterExternalTexture
FlutterEngineMarkExternalTextureFrameAvailableFnPtr MarkExternalTextureFrameAvailable
FlutterEnginePostRenderThreadTaskFnPtr PostRenderThreadTask
size_t height
Height of the texture.
#define EXPECT_TRUE(handle)