Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::GPUSurfaceVulkan Class Reference

A GPU surface backed by VkImages provided by a GPUSurfaceVulkanDelegate. More...

#include <gpu_surface_vulkan.h>

Inheritance diagram for flutter::GPUSurfaceVulkan:
flutter::Surface

Public Member Functions

 GPUSurfaceVulkan (GPUSurfaceVulkanDelegate *delegate, const sk_sp< GrDirectContext > &context, bool render_to_surface)
 Create a GPUSurfaceVulkan while letting it reuse an existing GrDirectContext. More...
 
 ~GPUSurfaceVulkan () override
 
bool IsValid () override
 
std::unique_ptr< SurfaceFrameAcquireFrame (const SkISize &size) override
 
SkMatrix GetRootTransformation () const override
 
GrDirectContextGetContext () override
 
- Public Member Functions inherited from flutter::Surface
 Surface ()
 
virtual ~Surface ()
 
virtual bool IsValid ()=0
 
virtual std::unique_ptr< SurfaceFrameAcquireFrame (const SkISize &size)=0
 
virtual SkMatrix GetRootTransformation () const =0
 
virtual GrDirectContextGetContext ()=0
 
virtual std::unique_ptr< GLContextResultMakeRenderContextCurrent ()
 
virtual bool ClearRenderContext ()
 
virtual bool AllowsDrawingWhenGpuDisabled () const
 
virtual bool EnableRasterCache () const
 
virtual std::shared_ptr< impeller::AiksContextGetAiksContext () const
 
virtual SurfaceData GetSurfaceData () const
 

Static Public Member Functions

static SkColorType ColorTypeFromFormat (const VkFormat format)
 

Detailed Description

A GPU surface backed by VkImages provided by a GPUSurfaceVulkanDelegate.

Definition at line 27 of file gpu_surface_vulkan.h.

Constructor & Destructor Documentation

◆ GPUSurfaceVulkan()

flutter::GPUSurfaceVulkan::GPUSurfaceVulkan ( GPUSurfaceVulkanDelegate delegate,
const sk_sp< GrDirectContext > &  context,
bool  render_to_surface 
)

Create a GPUSurfaceVulkan while letting it reuse an existing GrDirectContext.

Definition at line 21 of file gpu_surface_vulkan.cc.

24 : delegate_(delegate),
25 skia_context_(skia_context),
26 render_to_surface_(render_to_surface),
27 weak_factory_(this) {}

◆ ~GPUSurfaceVulkan()

flutter::GPUSurfaceVulkan::~GPUSurfaceVulkan ( )
overridedefault

Member Function Documentation

◆ AcquireFrame()

std::unique_ptr< SurfaceFrame > flutter::GPUSurfaceVulkan::AcquireFrame ( const SkISize size)
overridevirtual

Implements flutter::Surface.

Definition at line 35 of file gpu_surface_vulkan.cc.

36 {
37 if (!IsValid()) {
38 FML_LOG(ERROR) << "Vulkan surface was invalid.";
39 return nullptr;
40 }
41
42 if (frame_size.isEmpty()) {
43 FML_LOG(ERROR) << "Vulkan surface was asked for an empty frame.";
44 return nullptr;
45 }
46
47 if (!render_to_surface_) {
48 return std::make_unique<SurfaceFrame>(
49 nullptr, SurfaceFrame::FramebufferInfo(),
50 [](const SurfaceFrame& surface_frame, DlCanvas* canvas) {
51 return true;
52 },
53 frame_size);
54 }
55
56 FlutterVulkanImage image = delegate_->AcquireImage(frame_size);
57 if (!image.image) {
58 FML_LOG(ERROR) << "Invalid VkImage given by the embedder.";
59 return nullptr;
60 }
61
62 sk_sp<SkSurface> surface = CreateSurfaceFromVulkanImage(
63 reinterpret_cast<VkImage>(image.image),
64 static_cast<VkFormat>(image.format), frame_size);
65 if (!surface) {
66 FML_LOG(ERROR) << "Could not create the SkSurface from the Vulkan image.";
67 return nullptr;
68 }
69
70 SurfaceFrame::SubmitCallback callback = [image = image, delegate = delegate_](
71 const SurfaceFrame&,
72 DlCanvas* canvas) -> bool {
73 TRACE_EVENT0("flutter", "GPUSurfaceVulkan::PresentImage");
74 if (canvas == nullptr) {
75 FML_DLOG(ERROR) << "Canvas not available.";
76 return false;
77 }
78
79 canvas->Flush();
80
81 return delegate->PresentImage(reinterpret_cast<VkImage>(image.image),
82 static_cast<VkFormat>(image.format));
83 };
84
85 SurfaceFrame::FramebufferInfo framebuffer_info{.supports_readback = true};
86
87 return std::make_unique<SurfaceFrame>(std::move(surface), framebuffer_info,
88 std::move(callback), frame_size);
89}
virtual FlutterVulkanImage AcquireImage(const SkISize &size)=0
Called by the engine to fetch a VkImage for writing the next frame.
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:27
VkSurfaceKHR surface
Definition: main.cc:49
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DLOG(severity)
Definition: logging.h:102
#define FML_LOG(severity)
Definition: logging.h:82
sk_sp< const SkImage > image
Definition: SkRecords.h:269
flutter::DlCanvas DlCanvas
#define ERROR(message)
Definition: elf_loader.cc:260
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131
VkFormat
Definition: vulkan_core.h:1458

◆ ColorTypeFromFormat()

SkColorType flutter::GPUSurfaceVulkan::ColorTypeFromFormat ( const VkFormat  format)
static

Definition at line 139 of file gpu_surface_vulkan.cc.

139 {
140 switch (format) {
147 default:
149 }
150}
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent Remove all existing persistent cache This is mainly for debugging purposes such as reproducing the shader compilation jank trace to Write the timeline trace to a file at the specified path The file will be in Perfetto s proto format
Definition: switches.h:203
@ VK_FORMAT_R8G8B8A8_SRGB
Definition: vulkan_core.h:1502
@ VK_FORMAT_B8G8R8A8_UNORM
Definition: vulkan_core.h:1503
@ VK_FORMAT_B8G8R8A8_SRGB
Definition: vulkan_core.h:1509
@ VK_FORMAT_R8G8B8A8_UNORM
Definition: vulkan_core.h:1496

◆ GetContext()

GrDirectContext * flutter::GPUSurfaceVulkan::GetContext ( )
overridevirtual

Implements flutter::Surface.

Definition at line 99 of file gpu_surface_vulkan.cc.

99 {
100 return skia_context_.get();
101}
T * get() const
Definition: SkRefCnt.h:303

◆ GetRootTransformation()

SkMatrix flutter::GPUSurfaceVulkan::GetRootTransformation ( ) const
overridevirtual

Implements flutter::Surface.

Definition at line 91 of file gpu_surface_vulkan.cc.

91 {
92 // This backend does not support delegating to the underlying platform to
93 // query for root surface transformations. Just return identity.
95 matrix.reset();
96 return matrix;
97}
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ IsValid()

bool flutter::GPUSurfaceVulkan::IsValid ( )
overridevirtual

Implements flutter::Surface.

Definition at line 31 of file gpu_surface_vulkan.cc.

31 {
32 return skia_context_ != nullptr;
33}

The documentation for this class was generated from the following files: