10#include "third_party/skia/include/core/SkColorSpace.h"
11#include "third_party/skia/include/core/SkSize.h"
12#include "third_party/skia/include/core/SkSurface.h"
13#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
14#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
15#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
16#include "third_party/skia/include/gpu/ganesh/vk/GrVkBackendSurface.h"
17#include "third_party/skia/include/gpu/ganesh/vk/GrVkTypes.h"
18#include "vulkan/vulkan_core.h"
23 const sk_sp<GrDirectContext>& skia_context,
24 bool render_to_surface)
26 skia_context_(skia_context),
27 render_to_surface_(render_to_surface),
28 weak_factory_(this) {}
33 return skia_context_ !=
nullptr;
39 FML_LOG(ERROR) <<
"Vulkan surface was invalid.";
44 FML_LOG(ERROR) <<
"Vulkan surface was asked for an empty frame.";
48 if (!render_to_surface_) {
49 return std::make_unique<SurfaceFrame>(
54 [](
const SurfaceFrame& surface_frame) {
return true; }, frame_size);
59 FML_LOG(ERROR) <<
"Invalid VkImage given by the embedder.";
63 sk_sp<SkSurface>
surface = CreateSurfaceFromVulkanImage(
67 FML_LOG(ERROR) <<
"Could not create the SkSurface from the Vulkan image.";
73 if (canvas ==
nullptr) {
74 FML_DLOG(ERROR) <<
"Canvas not available.";
83 TRACE_EVENT0(
"flutter",
"GPUSurfaceVulkan::PresentImage");
84 return delegate->PresentImage(
reinterpret_cast<VkImage
>(
image.
image),
90 return std::make_unique<SurfaceFrame>(std::move(
surface), framebuffer_info,
91 std::move(encode_callback),
92 std::move(submit_callback), frame_size);
102 return skia_context_.get();
105sk_sp<SkSurface> GPUSurfaceVulkan::CreateSurfaceFromVulkanImage(
107 const VkFormat format,
110 GrVkImageInfo image_info = {
112 .fImageTiling = VK_IMAGE_TILING_OPTIMAL,
113 .fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
115 .fImageUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
116 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
117 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
118 VK_IMAGE_USAGE_SAMPLED_BIT,
122 auto backend_texture =
123 GrBackendTextures::MakeVk(
size.width,
size.height, image_info);
125 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
127 return SkSurfaces::WrapBackendTexture(
130 kTopLeft_GrSurfaceOrigin,
133 SkColorSpace::MakeSRGB(),
143 case VK_FORMAT_R8G8B8A8_UNORM:
144 case VK_FORMAT_R8G8B8A8_SRGB:
145 return SkColorType::kRGBA_8888_SkColorType;
146 case VK_FORMAT_B8G8R8A8_UNORM:
147 case VK_FORMAT_B8G8R8A8_SRGB:
148 return SkColorType::kBGRA_8888_SkColorType;
150 return SkColorType::kUnknown_SkColorType;
Developer-facing API for rendering anything within the engine.
Interface implemented by all platform surfaces that can present a Vulkan backing store to the "screen...
virtual FlutterVulkanImage AcquireImage(const DlISize &size)=0
Called by the engine to fetch a VkImage for writing the next frame.
DlMatrix GetRootTransformation() const override
GrDirectContext * GetContext() override
static SkColorType ColorTypeFromFormat(const VkFormat format)
std::unique_ptr< SurfaceFrame > AcquireFrame(const DlISize &size) override
GPUSurfaceVulkan(GPUSurfaceVulkanDelegate *delegate, const sk_sp< GrDirectContext > &context, bool render_to_surface)
Create a GPUSurfaceVulkan while letting it reuse an existing GrDirectContext.
~GPUSurfaceVulkan() override
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> EncodeCallback
std::function< bool(SurfaceFrame &surface_frame)> SubmitCallback
FlutterVulkanImage * image
uint32_t uint32_t * format
#define FML_DLOG(severity)
#define FML_LOG(severity)
impeller::Matrix DlMatrix
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
FlutterVulkanImageHandle image
uint32_t format
The VkFormat of the image (for example: VK_FORMAT_R8G8B8A8_UNORM).
A 4x4 matrix using column-major storage.
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
#define TRACE_EVENT0(category_group, name)