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

Commit 351508c

Browse files
committed
update
1 parent 47ac97f commit 351508c

File tree

7 files changed

+211
-92
lines changed

7 files changed

+211
-92
lines changed

shell/platform/embedder/embedder.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,42 @@ InferMetalPlatformViewCreationCallback(
368368
#endif
369369
}
370370

371+
static flutter::Shell::CreateCallback<flutter::PlatformView>
372+
InferVulkanPlatformViewCreationCallback(
373+
const FlutterRendererConfig* config,
374+
void* user_data,
375+
flutter::PlatformViewEmbedder::PlatformDispatchTable
376+
platform_dispatch_table,
377+
std::unique_ptr<flutter::EmbedderExternalViewEmbedder>
378+
external_view_embedder) {
379+
if (config->type != kVulkan) {
380+
return nullptr;
381+
}
382+
assert(false); // TODO(bdero)
383+
384+
//#ifdef SHELL_ENABLE_VULKAN
385+
std::shared_ptr<flutter::EmbedderExternalViewEmbedder> view_embedder =
386+
std::move(external_view_embedder);
387+
388+
std::unique_ptr<flutter::EmbedderSurfaceVulkan> embedder_surface =
389+
std::make_unique<flutter::EmbedderSurfaceVulkan>(view_embedder);
390+
391+
return fml::MakeCopyable(
392+
[embedder_surface = std::move(embedder_surface), platform_dispatch_table,
393+
external_view_embedder = view_embedder](flutter::Shell& shell) mutable {
394+
return std::make_unique<flutter::PlatformViewEmbedder>(
395+
shell, // delegate
396+
shell.GetTaskRunners(), // task runners
397+
std::move(embedder_surface), // embedder surface
398+
platform_dispatch_table, // platform dispatch table
399+
std::move(external_view_embedder) // external view embedder
400+
);
401+
});
402+
//#else
403+
return nullptr;
404+
//#endif
405+
}
406+
371407
static flutter::Shell::CreateCallback<flutter::PlatformView>
372408
InferSoftwarePlatformViewCreationCallback(
373409
const FlutterRendererConfig* config,
@@ -430,6 +466,10 @@ InferPlatformViewCreationCallback(
430466
return InferMetalPlatformViewCreationCallback(
431467
config, user_data, platform_dispatch_table,
432468
std::move(external_view_embedder));
469+
case kVulkan:
470+
return InferVulkanPlatformViewCreationCallback(
471+
config, user_data, platform_dispatch_table,
472+
std::move(external_view_embedder));
433473
default:
434474
return nullptr;
435475
}

shell/platform/embedder/embedder.h

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ typedef struct {
495495
size_t struct_size;
496496
/// Embedder provided unique identifier to the texture buffer. Given that the
497497
/// `texture` handle is passed to the engine to render to, the texture buffer
498-
/// is itseld owned by the embedder. This `texture_id` is then also given to
498+
/// is itself owned by the embedder. This `texture_id` is then also given to
499499
/// the embedder in the present callback.
500500
int64_t texture_id;
501501
/// Handle to the MTLTexture that is owned by the embedder. Engine will render
@@ -542,30 +542,80 @@ typedef struct {
542542
FlutterMetalTextureFrameCallback external_texture_frame_callback;
543543
} FlutterMetalRendererConfig;
544544

545-
typedef uintptr_t* (*FlutterVulkanGetNextImageCallback)(void* /* user data */);
545+
/// Alias for VkInstance.
546+
typedef const uint64_t* FlutterVulkanInstanceHandle;
546547

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 */);
548+
/// Alias for VkPhysicalDevice.
549+
typedef const uint64_t* FlutterVulkanPhysicalDeviceHandle;
550+
551+
/// Alias for VkDevice.
552+
typedef const uint64_t* FlutterVulkanDeviceHandle;
553+
554+
/// Alias for VkImage.
555+
typedef const uint64_t* FlutterVulkanImageHandle;
553556

554557
typedef struct {
555-
/// The size of this struct. Must be sizeof(FlutterVulkanRendererConfig).
558+
/// The size of this struct. Must be sizeof(FlutterVulkanImage).
556559
size_t struct_size;
557-
560+
/// Embedder provided unique identifier to the image. Given that the `image`
561+
/// handle is passed to the engine to render to, the image is itself owned by
562+
/// the embedder. This `image_id` is then also given to the embedder in the
563+
/// present callback.
564+
int64_t image_id;
565+
/// Handle to the VkImage that is owned by the embedder. The engine will
566+
/// bind this image for writing the frame.
567+
FlutterVulkanImageHandle image;
568+
/// A baton that is not interpreted by the engine in any way. It will be given
569+
/// back to the embedder in the destruction callback below. Embedder resources
570+
/// may be associated with this baton.
558571
void* user_data;
572+
/// The callback invoked by the engine when it no longer needs this backing
573+
/// store.
574+
VoidCallback destruction_callback;
575+
} FlutterVulkanImage;
559576

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;
577+
/// Callback to fetch a Vulkan function pointer for a given instance. Normally,
578+
/// this should return the results of vkGetInstanceProcAddr.
579+
typedef void* (*FlutterVulkanInstanceProcAddressCallback)(
580+
void* /* user data */,
581+
FlutterVulkanInstanceHandle /* instance */,
582+
const char* /* name */);
566583

567-
FlutterVulkanGetNextImageCallback acquire_next_image_callback;
568-
VoidCallback terminate_callback;
584+
/// Callback for when a VkImage is requested.
585+
typedef FlutterVulkanImage (*FlutterVulkanImageCallback)(
586+
void* /* user data */,
587+
const FlutterFrameInfo* /* frame info */);
588+
589+
/// Callback for when a VkImage has been written to and is ready for use by the
590+
/// embedder. The `image_id` here corresponds to the image_id provided by the
591+
/// embedder in the `FlutterVulkanImageCallback` callback.
592+
typedef bool (*FlutterVulkanPresentCallback)(
593+
void* /* user data */,
594+
const FlutterVulkanImage* /* image */);
595+
typedef uint64_t* (*Uint64Callback)(void* /* user data */);
596+
597+
typedef uint64_t* (*FlutterVulkanPresentImageCallback)(void* /* user data */,
598+
uint64_t* /* image */);
599+
600+
typedef struct {
601+
/// The size of this struct. Must be sizeof(FlutterVulkanRendererConfig).
602+
size_t struct_size;
603+
// VkInstance handle.
604+
FlutterVulkanInstanceHandle instance;
605+
// VkPhysicalDevice handle.
606+
FlutterVulkanPhysicalDeviceHandle physical_device;
607+
// VkDevice handle.
608+
FlutterVulkanDeviceHandle device;
609+
ProcResolver get_proc_address_callback;
610+
FlutterVulkanInstanceProcAddressCallback get_instance_proc_address_callback;
611+
/// The callback invoked when the engine requests a VkImage from the embedder
612+
/// for rendering the next frame.
613+
FlutterVulkanImageCallback get_next_image_callback;
614+
/// The callback invoked when a VkImage has been written to and is ready for
615+
/// use by the embedder. Prior to calling this callback, the engine performs
616+
/// a host sync, and so the VkImage can be used in a pipeline by the embedder
617+
/// without any additional synchronization.
618+
FlutterVulkanPresentCallback present_image_callback;
569619

570620
} FlutterVulkanRendererConfig;
571621

@@ -1022,11 +1072,13 @@ typedef struct {
10221072
/// The size of this struct. Must be sizeof(FlutterVulkanBackingStore).
10231073
size_t struct_size;
10241074

1025-
/// VkImage handle.
1026-
uint64_t handle;
1027-
1028-
/// VkSemaphore signaled when engine is done writing image.
1029-
uint64_t image_ready;
1075+
/// The Vulkan image that the layer will be rendered to. This image must
1076+
/// already be available for the engine to bind for writing when it's given to
1077+
/// the engine via the backing store creation callback. The engine will
1078+
/// perform a host sync for all layers prior to calling the compositor present
1079+
/// callback, and so the written layer images can be freely bound by the
1080+
/// embedder without any additional synchronization.
1081+
FlutterVulkanImage image;
10301082
} FlutterVulkanBackingStore;
10311083

10321084
typedef enum {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h"
6+
7+
#include <memory>
8+
9+
#include "embedder.h"
10+
#include "flutter/fml/logging.h"
11+
//#include "flutter/shell/platform/embedder/tests/embedder_test_compositor_vulkan.h"
12+
13+
namespace flutter {
14+
namespace testing {
15+
16+
EmbedderTestContextVulkan::EmbedderTestContextVulkan(std::string assets_path)
17+
: EmbedderTestContext(assets_path) {
18+
//vulkan_context_ = std::make_unique<TestVulkanContext>();
19+
}
20+
21+
EmbedderTestContextVulkan::~EmbedderTestContextVulkan() {}
22+
23+
void EmbedderTestContextVulkan::SetupSurface(SkISize surface_size) {
24+
FML_CHECK(surface_size_.isEmpty());
25+
surface_size_ = surface_size;
26+
27+
assert(false); // TODO(bdero)
28+
//vulkan_surface_ = TestVulkanSurface::Create(*vulkan_context_, surface_size_);
29+
}
30+
31+
size_t EmbedderTestContextVulkan::GetSurfacePresentCount() const {
32+
return present_count_;
33+
}
34+
35+
EmbedderTestContextType EmbedderTestContextVulkan::GetContextType() const {
36+
return EmbedderTestContextType::kVulkanContext;
37+
}
38+
39+
void EmbedderTestContextVulkan::SetupCompositor() {
40+
FML_CHECK(!compositor_) << "Already set up a compositor in this context.";
41+
42+
assert(false); // TODO(bdero)
43+
//FML_CHECK(vulkan_surface_)
44+
// << "Set up the Vulkan surface before setting up a compositor.";
45+
//compositor_ = std::make_unique<EmbedderTestCompositorVulkan>(
46+
// surface_size_, vulkan_surface_->GetGrContext());
47+
}
48+
49+
} // namespace testing
50+
} // namespace flutter
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_CONTEXT_VULKAN_H_
6+
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_CONTEXT_VULKAN_H_
7+
8+
#include "flutter/shell/platform/embedder/tests/embedder_test_context.h"
9+
#include "flutter/testing/test_vulkan_context.h"
10+
11+
namespace flutter {
12+
namespace testing {
13+
14+
class EmbedderTestContextVulkan : public EmbedderTestContext {
15+
public:
16+
explicit EmbedderTestContextVulkan(std::string assets_path = "");
17+
18+
~EmbedderTestContextVulkan() override;
19+
20+
// |EmbedderTestContext|
21+
EmbedderTestContextType GetContextType() const override;
22+
23+
// |EmbedderTestContext|
24+
size_t GetSurfacePresentCount() const override;
25+
26+
// |EmbedderTestContext|
27+
void SetupCompositor() override;
28+
29+
TestVulkanContext* GetTestVulkanContext();
30+
31+
private:
32+
// This allows the builder to access the hooks.
33+
friend class EmbedderConfigBuilder;
34+
SkISize surface_size_ = SkISize::MakeEmpty();
35+
//std::unique_ptr<TestVulkanContext> vulkan_context_;
36+
size_t present_count_ = 0;
37+
38+
void SetupSurface(SkISize surface_size) override;
39+
40+
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTestContextVulkan);
41+
};
42+
43+
} // namespace testing
44+
} // namespace flutter
45+
46+
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_CONTEXT_VULKAN_H_

testing/BUILD.gn

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ if (enable_unittests) {
109109
source_set("vulkan") {
110110
testonly = true
111111

112-
sources = [
113-
"test_vulkan_context.h",
114-
"test_vulkan_context.cc",
115-
]
116-
117112
deps = [
118113
":skia",
119114
"//flutter/fml",

testing/test_vulkan_context.cc

Lines changed: 0 additions & 35 deletions
This file was deleted.

testing/test_vulkan_context.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)