Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
flutter::testing::TestVulkanSurface Class Reference

#include <test_vulkan_surface.h>

Public Member Functions

bool IsValid () const
 
sk_sp< SkImageGetSurfaceSnapshot () const
 
VkImage GetImage ()
 

Static Public Member Functions

static std::unique_ptr< TestVulkanSurfaceCreate (const TestVulkanContext &context, const SkISize &surface_size)
 

Detailed Description

Definition at line 20 of file test_vulkan_surface.h.

Member Function Documentation

◆ Create()

std::unique_ptr< TestVulkanSurface > flutter::testing::TestVulkanSurface::Create ( const TestVulkanContext context,
const SkISize surface_size 
)
static

Definition at line 25 of file test_vulkan_surface.cc.

27 {
28 auto image_result = context.CreateImage(surface_size);
29
30 if (!image_result.has_value()) {
31 FML_LOG(ERROR) << "Could not create VkImage.";
32 return nullptr;
33 }
34
35 GrVkImageInfo image_info = {
36 .fImage = image_result.value().GetImage(),
37 .fImageTiling = VK_IMAGE_TILING_OPTIMAL,
38 .fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
39 .fFormat = VK_FORMAT_R8G8B8A8_UNORM,
40 .fImageUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
44 .fSampleCount = 1,
45 .fLevelCount = 1,
46 };
47 auto backend_texture = GrBackendTextures::MakeVk(
48 surface_size.width(), surface_size.height(), image_info);
49
50 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
51
52 auto result = std::unique_ptr<TestVulkanSurface>(
53 new TestVulkanSurface(std::move(image_result.value())));
55 context.GetGrDirectContext().get(), // context
56 backend_texture, // back-end texture
57 kTopLeft_GrSurfaceOrigin, // surface origin
58 1, // sample count
59 kRGBA_8888_SkColorType, // color type
60 SkColorSpace::MakeSRGB(), // color space
61 &surface_properties, // surface properties
62 nullptr, // release proc
63 nullptr // release context
64 );
65
66 if (!result->surface_) {
68 << "Could not wrap VkImage as an SkSurface Vulkan render texture.";
69 return nullptr;
70 }
71
72 return result;
73}
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kUnknown_SkPixelGeometry
static sk_sp< SkColorSpace > MakeSRGB()
GAsyncResult * result
#define FML_LOG(severity)
Definition logging.h:82
SK_API GrBackendTexture MakeVk(int width, int height, const GrVkImageInfo &, std::string_view label={})
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
VkImage fImage
Definition GrVkTypes.h:26
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37
#define ERROR(message)
@ VK_IMAGE_LAYOUT_UNDEFINED
@ VK_IMAGE_TILING_OPTIMAL
@ VK_IMAGE_USAGE_TRANSFER_DST_BIT
@ VK_IMAGE_USAGE_SAMPLED_BIT
@ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
@ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
@ VK_FORMAT_R8G8B8A8_UNORM

◆ GetImage()

VkImage flutter::testing::TestVulkanSurface::GetImage ( )

Definition at line 109 of file test_vulkan_surface.cc.

109 {
110 return image_.GetImage();
111}

◆ GetSurfaceSnapshot()

sk_sp< SkImage > flutter::testing::TestVulkanSurface::GetSurfaceSnapshot ( ) const

Definition at line 79 of file test_vulkan_surface.cc.

79 {
80 if (!IsValid()) {
81 return nullptr;
82 }
83
84 if (!surface_) {
85 FML_LOG(ERROR) << "Aborting snapshot because of on-screen surface "
86 "acquisition failure.";
87 return nullptr;
88 }
89
90 auto device_snapshot = surface_->makeImageSnapshot();
91
92 if (!device_snapshot) {
93 FML_LOG(ERROR) << "Could not create the device snapshot while attempting "
94 "to snapshot the Vulkan surface.";
95 return nullptr;
96 }
97
98 auto host_snapshot = device_snapshot->makeRasterImage();
99
100 if (!host_snapshot) {
101 FML_LOG(ERROR) << "Could not create the host snapshot while attempting to "
102 "snapshot the Vulkan surface.";
103 return nullptr;
104 }
105
106 return host_snapshot;
107}
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition SkImage.cpp:267
sk_sp< SkImage > makeImageSnapshot()
Definition SkSurface.cpp:90

◆ IsValid()

bool flutter::testing::TestVulkanSurface::IsValid ( ) const

Definition at line 75 of file test_vulkan_surface.cc.

75 {
76 return surface_ != nullptr;
77}

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