Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 47ac97f

Browse files
committed
Add test context for loading swiftshader so
1 parent 1dee294 commit 47ac97f

20 files changed

+228
-38
lines changed

shell/config.gni

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ declare_args() {
66
shell_enable_gl = !is_fuchsia
77
shell_enable_metal = false
88

9-
# TODO(dworsham): Enable once Fuchsia supports Vulkan through the embedder.
10-
shell_enable_vulkan = false
9+
shell_enable_vulkan = true
1110
shell_enable_software = true
1211
}
1312

1413
declare_args() {
1514
test_enable_gl = shell_enable_gl
1615
test_enable_metal = shell_enable_metal
17-
test_enable_vulkan = is_fuchsia
16+
test_enable_vulkan = shell_enable_vulkan
1817
test_enable_software = shell_enable_software
1918
}

shell/gpu/gpu_surface_vulkan.cc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,17 @@ namespace flutter {
1010

1111
GPUSurfaceVulkan::GPUSurfaceVulkan(
1212
GPUSurfaceVulkanDelegate* delegate,
13-
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface,
14-
bool render_to_surface)
13+
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface)
1514
: GPUSurfaceVulkan(/*context=*/nullptr,
1615
delegate,
17-
std::move(native_surface),
18-
render_to_surface) {}
16+
std::move(native_surface)) {}
1917

2018
GPUSurfaceVulkan::GPUSurfaceVulkan(
2119
const sk_sp<GrDirectContext>& context,
2220
GPUSurfaceVulkanDelegate* delegate,
23-
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface,
24-
bool render_to_surface)
25-
: window_(context,
26-
delegate->vk(),
27-
std::move(native_surface),
28-
render_to_surface),
29-
render_to_surface_(render_to_surface),
21+
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface)
22+
: window_(context, delegate->vk(), std::move(native_surface)),
23+
render_to_surface_(native_surface),
3024
weak_factory_(this) {}
3125

3226
GPUSurfaceVulkan::~GPUSurfaceVulkan() = default;

shell/gpu/gpu_surface_vulkan.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ class GPUSurfaceVulkan : public Surface {
2424
/// GrDirectContext for Skia.
2525
///
2626
GPUSurfaceVulkan(GPUSurfaceVulkanDelegate* delegate,
27-
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface,
28-
bool render_to_surface);
27+
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface);
2928

3029
//------------------------------------------------------------------------------
3130
/// @brief Create a GPUSurfaceVulkan while letting it reuse an existing
3231
/// GrDirectContext.
3332
///
3433
GPUSurfaceVulkan(const sk_sp<GrDirectContext>& context,
3534
GPUSurfaceVulkanDelegate* delegate,
36-
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface,
37-
bool render_to_surface);
35+
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface);
3836

3937
~GPUSurfaceVulkan() override;
4038

shell/platform/android/context/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ source_set("context") {
1414

1515
deps = [
1616
"//flutter/fml",
17+
"//flutter/vulkan", # TODO(bdero)
1718
"//third_party/skia",
1819
]
1920
}

shell/platform/android/surface/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ source_set("surface_mock") {
5050
deps = [
5151
":surface",
5252
"//flutter/shell/gpu:gpu_surface_gl",
53+
"//flutter/vulkan", # TODO(bdero)
5354
"//third_party/googletest:gmock",
5455
"//third_party/googletest:gtest",
5556
"//third_party/skia",

shell/platform/embedder/BUILD.gn

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ if (enable_unittests) {
228228
"tests/embedder_unittests_gl.cc",
229229
]
230230

231-
deps += [ "//flutter/testing:opengl" ]
231+
deps += [
232+
"//flutter/testing:opengl",
233+
]
232234
}
233235

234236
if (test_enable_metal) {
@@ -242,6 +244,18 @@ if (enable_unittests) {
242244

243245
deps += [ "//flutter/testing:metal" ]
244246
}
247+
248+
if (test_enable_vulkan) {
249+
sources += [
250+
"tests/embedder_test_context_vulkan.cc",
251+
"tests/embedder_test_context_vulkan.h",
252+
]
253+
254+
deps += [
255+
"//flutter/testing:vulkan",
256+
"//flutter/vulkan",
257+
]
258+
}
245259
}
246260

247261
# Tests the build in FLUTTER_ENGINE_NO_PROTOTYPES mode.

shell/platform/embedder/embedder.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,14 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
604604
#endif
605605
}
606606

607+
static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
608+
GrDirectContext* context,
609+
const FlutterBackingStoreConfig& config,
610+
const FlutterVulkanBackingStore* vulkan) {
611+
assert(false); // TODO(bdero)
612+
return nullptr;
613+
}
614+
607615
static std::unique_ptr<flutter::EmbedderRenderTarget>
608616
CreateEmbedderRenderTarget(const FlutterCompositor* compositor,
609617
const FlutterBackingStoreConfig& config,
@@ -665,6 +673,11 @@ CreateEmbedderRenderTarget(const FlutterCompositor* compositor,
665673
render_surface =
666674
MakeSkSurfaceFromBackingStore(context, config, &backing_store.metal);
667675
break;
676+
677+
case kFlutterBackingStoreTypeVulkan:
678+
render_surface =
679+
MakeSkSurfaceFromBackingStore(context, config, &backing_store.vulkan);
680+
break;
668681
};
669682

670683
if (!render_surface) {

shell/platform/embedder/embedder.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef enum {
7676
/// iOS version >= 10.0 (device), 13.0 (simulator)
7777
/// macOS version >= 10.14
7878
kMetal,
79+
kVulkan,
7980
} FlutterRendererType;
8081

8182
/// Additional accessibility features that may be enabled by the platform.
@@ -541,6 +542,33 @@ typedef struct {
541542
FlutterMetalTextureFrameCallback external_texture_frame_callback;
542543
} FlutterMetalRendererConfig;
543544

545+
typedef uintptr_t* (*FlutterVulkanGetNextImageCallback)(void* /* user data */);
546+
547+
typedef void* (*ProcAddressCallback)(void* user /* in */,
548+
const char* pName /* in */);
549+
typedef void* (*InstanceProcAddressCallback)(void* user /* in */,
550+
uintptr_t* instance /* in */,
551+
const char* pName /* in */);
552+
typedef uintptr_t* (*UintPtrCallback)(void* user /* in */);
553+
554+
typedef struct {
555+
/// The size of this struct. Must be sizeof(FlutterVulkanRendererConfig).
556+
size_t struct_size;
557+
558+
void* user_data;
559+
560+
/// Platform Callbacks
561+
ProcAddressCallback get_proc_address_callback;
562+
InstanceProcAddressCallback get_instance_proc_address_callback;
563+
UintPtrCallback get_instance_handle_callback;
564+
UintPtrCallback get_physical_device_handle_callback;
565+
UintPtrCallback get_device_handle_callback;
566+
567+
FlutterVulkanGetNextImageCallback acquire_next_image_callback;
568+
VoidCallback terminate_callback;
569+
570+
} FlutterVulkanRendererConfig;
571+
544572
typedef struct {
545573
/// The size of this struct. Must be sizeof(FlutterSoftwareRendererConfig).
546574
size_t struct_size;
@@ -557,6 +585,7 @@ typedef struct {
557585
FlutterOpenGLRendererConfig open_gl;
558586
FlutterSoftwareRendererConfig software;
559587
FlutterMetalRendererConfig metal;
588+
FlutterVulkanRendererConfig vulkan;
560589
};
561590
} FlutterRendererConfig;
562591

@@ -989,6 +1018,17 @@ typedef struct {
9891018
};
9901019
} FlutterMetalBackingStore;
9911020

1021+
typedef struct {
1022+
/// The size of this struct. Must be sizeof(FlutterVulkanBackingStore).
1023+
size_t struct_size;
1024+
1025+
/// VkImage handle.
1026+
uint64_t handle;
1027+
1028+
/// VkSemaphore signaled when engine is done writing image.
1029+
uint64_t image_ready;
1030+
} FlutterVulkanBackingStore;
1031+
9921032
typedef enum {
9931033
/// Indicates that the Flutter application requested that an opacity be
9941034
/// applied to the platform view.
@@ -1048,6 +1088,8 @@ typedef enum {
10481088
kFlutterBackingStoreTypeSoftware,
10491089
/// Specifies a Metal backing store. This is backed by a Metal texture.
10501090
kFlutterBackingStoreTypeMetal,
1091+
/// Specifies a Vulkan backing store. This is backed by a Vulkan VkImage.
1092+
kFlutterBackingStoreTypeVulkan,
10511093
} FlutterBackingStoreType;
10521094

10531095
typedef struct {
@@ -1069,6 +1111,8 @@ typedef struct {
10691111
FlutterSoftwareBackingStore software;
10701112
// The description of the Metal backing store.
10711113
FlutterMetalBackingStore metal;
1114+
// The description of the Vulkan backing store.
1115+
FlutterVulkanBackingStore vulkan;
10721116
};
10731117
} FlutterBackingStore;
10741118

shell/platform/embedder/tests/embedder_assertions.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ inline bool operator==(const FlutterMetalTexture& a,
7070
return a.texture_id == b.texture_id && a.texture == b.texture;
7171
}
7272

73+
inline bool operator==(const FlutterVulkanBackingStore& a,
74+
const FlutterVulkanBackingStore& b) {
75+
return a.handle == b.handle && a.image_ready == b.image_ready;
76+
}
77+
7378
inline bool operator==(const FlutterMetalBackingStore& a,
7479
const FlutterMetalBackingStore& b) {
7580
return a.texture == b.texture;
@@ -112,6 +117,8 @@ inline bool operator==(const FlutterBackingStore& a,
112117
return a.software == b.software;
113118
case kFlutterBackingStoreTypeMetal:
114119
return a.metal == b.metal;
120+
case kFlutterBackingStoreTypeVulkan:
121+
return a.vulkan == b.vulkan;
115122
}
116123

117124
return false;
@@ -230,6 +237,8 @@ inline std::string FlutterBackingStoreTypeToString(
230237
return "kFlutterBackingStoreTypeSoftware";
231238
case kFlutterBackingStoreTypeMetal:
232239
return "kFlutterBackingStoreTypeMetal";
240+
case kFlutterBackingStoreTypeVulkan:
241+
return "kFlutterBackingStoreTypeVulkan";
233242
}
234243
return "Unknown";
235244
}
@@ -347,6 +356,12 @@ inline std::ostream& operator<<(std::ostream& out,
347356
return out << "(FlutterMetalBackingStore) Texture: " << item.texture;
348357
}
349358

359+
inline std::ostream& operator<<(std::ostream& out,
360+
const FlutterVulkanBackingStore& item) {
361+
return out << "(FlutterVulkanBackingStore) Handle: " << item.handle
362+
<< "Image Ready Semaphore: " << item.image_ready;
363+
}
364+
350365
inline std::ostream& operator<<(std::ostream& out,
351366
const FlutterBackingStore& backing_store) {
352367
out << "(FlutterBackingStore) Struct size: " << backing_store.struct_size
@@ -366,6 +381,10 @@ inline std::ostream& operator<<(std::ostream& out,
366381
case kFlutterBackingStoreTypeMetal:
367382
out << backing_store.metal;
368383
break;
384+
385+
case kFlutterBackingStoreTypeVulkan:
386+
out << backing_store.vulkan;
387+
break;
369388
}
370389

371390
return out;

shell/platform/embedder/tests/embedder_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "flutter/shell/platform/embedder/tests/embedder_test.h"
66
#include "flutter/shell/platform/embedder/tests/embedder_test_context_software.h"
7+
#include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h"
78

89
#ifdef SHELL_ENABLE_GL
910
#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h"
@@ -33,6 +34,11 @@ EmbedderTestContext& EmbedderTest::GetEmbedderContext(
3334
std::make_unique<EmbedderTestContextSoftware>(
3435
GetFixturesDirectory());
3536
break;
37+
case EmbedderTestContextType::kVulkanContext:
38+
embedder_contexts_[type] =
39+
std::make_unique<EmbedderTestContextVulkan>(
40+
GetFixturesDirectory());
41+
break;
3642
#ifdef SHELL_ENABLE_GL
3743
case EmbedderTestContextType::kOpenGLContext:
3844
embedder_contexts_[type] =

0 commit comments

Comments
 (0)