5#include "flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.h"
7#include "flutter/fml/logging.h"
8#include "flutter/shell/platform/embedder/pixel_formats.h"
25#ifdef SHELL_ENABLE_VULKAN
29#ifdef SHELL_ENABLE_METAL
44 : context_(
std::move(context)),
46 software_pixfmt_(software_pixfmt)
47#ifdef SHELL_ENABLE_METAL
51#ifdef SHELL_ENABLE_VULKAN
53 test_vulkan_context_(nullptr)
58 FML_LOG(
ERROR) <<
"Expected pixel format to be the default "
59 "(kFlutterSoftwarePixelFormatNative32) when"
60 "backing store producer should produce deprecated v1 "
74 return CreateSoftware(config, renderer_out);
76 return CreateSoftware2(config, renderer_out);
79 return CreateTexture(config, renderer_out);
81 return CreateFramebuffer(config, renderer_out);
83#ifdef SHELL_ENABLE_METAL
85 return CreateMTLTexture(config, renderer_out);
87#ifdef SHELL_ENABLE_VULKAN
89 return CreateVulkanImage(config, renderer_out);
96bool EmbedderTestBackingStoreProducer::CreateFramebuffer(
100 const auto image_info =
114 FML_LOG(
ERROR) <<
"Could not create render target for compositor layer.";
121 if (!render_target.
isValid()) {
128 &framebuffer_info)) {
129 FML_LOG(
ERROR) <<
"Could not access backend framebuffer info.";
150bool EmbedderTestBackingStoreProducer::CreateTexture(
153#ifdef SHELL_ENABLE_GL
154 const auto image_info =
168 FML_LOG(
ERROR) <<
"Could not create render target for compositor layer.";
175 if (!render_texture.
isValid()) {
176 FML_LOG(
ERROR) <<
"Backend render texture was invalid.";
182 FML_LOG(
ERROR) <<
"Could not access backend texture info.";
204bool EmbedderTestBackingStoreProducer::CreateSoftware(
212 <<
"Could not create the render target for compositor layer.";
217 if (!
surface->peekPixels(&pixmap)) {
237bool EmbedderTestBackingStoreProducer::CreateSoftware2(
249 <<
"Could not create the render target for compositor layer.";
254 if (!
surface->peekPixels(&pixmap)) {
278bool EmbedderTestBackingStoreProducer::CreateMTLTexture(
281#ifdef SHELL_ENABLE_METAL
285 auto texture_info = test_metal_context_->CreateMetalTexture(surface_size);
287 GrMtlTextureInfo skia_texture_info;
288 skia_texture_info.fTexture.reset(SkCFSafeRetain(texture_info.texture));
298 FML_LOG(
ERROR) <<
"Could not create Skia surface from a Metal texture.";
319bool EmbedderTestBackingStoreProducer::CreateVulkanImage(
322#ifdef SHELL_ENABLE_VULKAN
323 if (!test_vulkan_context_) {
324 test_vulkan_context_ = fml::MakeRefCounted<TestVulkanContext>();
328 TestVulkanImage*
test_image =
new TestVulkanImage(
329 std::move(test_vulkan_context_->CreateImage(surface_size).value()));
344 surface_size.width(), surface_size.height(), image_info);
349 delete reinterpret_cast<TestVulkanImage*
>(
user_data);
365 FML_LOG(
ERROR) <<
"Could not create Skia surface from Vulkan image.";
371 image->image =
reinterpret_cast<uint64_t
>(image_info.
fImage);
384 UserData*
d =
reinterpret_cast<UserData*
>(
user_data);
@ kBottomLeft_GrSurfaceOrigin
@ kTopLeft_GrSurfaceOrigin
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kUnknown_SkPixelGeometry
static void test_image(const sk_sp< SkSpecialImage > &img, skiatest::Reporter *reporter, GrRecordingContext *rContext, bool isGPUBacked)
static sk_sp< SkColorSpace > MakeSRGB()
void * writable_addr() const
const void * addr() const
@ kDiscardWrite
back-end object must be overwritten
EmbedderTestBackingStoreProducer(sk_sp< GrDirectContext > context, RenderTargetType type, FlutterSoftwarePixelFormat software_pixfmt=kFlutterSoftwarePixelFormatNative32)
~EmbedderTestBackingStoreProducer()
bool Create(const FlutterBackingStoreConfig *config, FlutterBackingStore *renderer_out)
FlutterSoftwarePixelFormat
@ kFlutterSoftwarePixelFormatNative32
@ kFlutterOpenGLTargetTypeFramebuffer
@ kFlutterOpenGLTargetTypeTexture
@ kFlutterBackingStoreTypeSoftware2
@ kFlutterBackingStoreTypeMetal
Specifies a Metal backing store. This is backed by a Metal texture.
@ kFlutterBackingStoreTypeVulkan
Specifies a Vulkan backing store. This is backed by a Vulkan VkImage.
@ kFlutterBackingStoreTypeSoftware
Specified an software allocation for Flutter to render into using the CPU.
@ kFlutterBackingStoreTypeOpenGL
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
#define FML_LOG(severity)
SK_API bool GetGLFramebufferInfo(const GrBackendRenderTarget &, GrGLFramebufferInfo *)
SK_API GrBackendTexture MakeMtl(int width, int height, skgpu::Mipmapped, const GrMtlTextureInfo &mtlInfo, std::string_view label={})
SK_API GrBackendTexture MakeVk(int width, int height, const GrVkImageInfo &, std::string_view label={})
SK_API bool GetGLTextureInfo(const GrBackendTexture &, GrGLTextureInfo *)
sk_sp< const SkImage > image
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API GrBackendTexture GetBackendTexture(SkSurface *, BackendHandleAccess)
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)
SK_API GrBackendRenderTarget GetBackendRenderTarget(SkSurface *, BackendHandleAccess)
void(*)(ReleaseContext) TextureReleaseProc
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
FlutterSize size
The size of the render target the engine expects to render into.
FlutterVulkanBackingStore vulkan
FlutterMetalBackingStore metal
FlutterBackingStoreType type
Specifies the type of backing store.
FlutterOpenGLBackingStore open_gl
The description of the OpenGL backing store.
FlutterSoftwareBackingStore software
The description of the software backing store.
FlutterSoftwareBackingStore2 software2
The description of the software backing store.
FlutterMetalTextureHandle texture
VoidCallback destruction_callback
FlutterOpenGLTexture texture
A texture for Flutter to render into.
FlutterOpenGLTargetType type
FlutterOpenGLFramebuffer framebuffer
uint32_t name
The name of the framebuffer.
VoidCallback destruction_callback
void * user_data
User data to be returned on the invocation of the destruction callback.
uint32_t name
The name of the texture.
VoidCallback destruction_callback
void * user_data
User data to be returned on the invocation of the destruction callback.
uint32_t format
The texture format (example GL_RGBA8).
VoidCallback destruction_callback
size_t row_bytes
The number of bytes in a single row of the allocation.
size_t height
The number of rows in the allocation.
FlutterSoftwarePixelFormat pixel_format
VoidCallback destruction_callback
size_t row_bytes
The number of bytes in a single row of the allocation.
size_t height
The number of rows in the allocation.
VoidCallback destruction_callback
const FlutterVulkanImage * image
static constexpr SkISize Make(int32_t w, int32_t h)
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
@ 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