Flutter Engine
 
Loading...
Searching...
No Matches
flutter::testing::TestVulkanSurface Class Reference

#include <test_vulkan_surface.h>

Public Member Functions

bool IsValid () const
 
sk_sp< SkImage > GetSurfaceSnapshot () const
 
VkImage GetImage ()
 

Static Public Member Functions

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

Detailed Description

Definition at line 19 of file test_vulkan_surface.h.

Member Function Documentation

◆ Create()

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

Definition at line 24 of file test_vulkan_surface.cc.

26 {
27 auto image_result = context.CreateImage(surface_size);
28
29 if (!image_result.has_value()) {
30 FML_LOG(ERROR) << "Could not create VkImage.";
31 return nullptr;
32 }
33
34 GrVkImageInfo image_info = {
35 .fImage = image_result.value().GetImage(),
36 .fImageTiling = VK_IMAGE_TILING_OPTIMAL,
37 .fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
38 .fFormat = VK_FORMAT_R8G8B8A8_UNORM,
39 .fImageUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
40 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
41 VK_IMAGE_USAGE_TRANSFER_DST_BIT |
42 VK_IMAGE_USAGE_SAMPLED_BIT,
43 .fSampleCount = 1,
44 .fLevelCount = 1,
45 };
46 auto backend_texture = GrBackendTextures::MakeVk(
47 surface_size.width, surface_size.height, image_info);
48
49 SkSurfaceProps surface_properties(0, kUnknown_SkPixelGeometry);
50
51 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
52 auto result = std::unique_ptr<TestVulkanSurface>(
53 new TestVulkanSurface(std::move(image_result.value())));
54 result->surface_ = SkSurfaces::WrapBackendTexture(
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_) {
67 FML_LOG(ERROR)
68 << "Could not wrap VkImage as an SkSurface Vulkan render texture.";
69 return nullptr;
70 }
71
72 return result;
73}
#define FML_LOG(severity)
Definition logging.h:101

References flutter::testing::TestVulkanContext::CreateImage(), FML_LOG, flutter::testing::TestVulkanContext::GetGrDirectContext(), impeller::TSize< T >::height, and impeller::TSize< T >::width.

◆ 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(nullptr);
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}

References FML_LOG, and surface_.

◆ IsValid()

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

Definition at line 75 of file test_vulkan_surface.cc.

75 {
76 return surface_ != nullptr;
77}

References surface_.


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