9#define GLFW_INCLUDE_NONE
10#include "third_party/glfw/include/GLFW/glfw3.h"
17using CGContextPtr = std::unique_ptr<std::remove_pointer<CGContextRef>::type,
18 decltype(&CGContextRelease)>;
19using CGImagePtr = std::unique_ptr<std::remove_pointer<CGImageRef>::type,
20 decltype(&CGImageRelease)>;
21using CGColorSpacePtr =
22 std::unique_ptr<std::remove_pointer<CGColorSpaceRef>::type,
23 decltype(&CGColorSpaceRelease)>;
25std::unique_ptr<Screenshot> ReadTexture(
26 const std::shared_ptr<Context>& surface_context,
27 const std::shared_ptr<Texture>&
texture) {
28 DeviceBufferDescriptor buffer_desc;
31 texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
32 buffer_desc.readback =
true;
33 std::shared_ptr<DeviceBuffer> device_buffer =
34 surface_context->GetResourceAllocator()->CreateBuffer(buffer_desc);
37 auto command_buffer = surface_context->CreateCommandBuffer();
38 auto blit_pass = command_buffer->CreateBlitPass();
39 bool success = blit_pass->AddCopy(
texture, device_buffer);
42 success = blit_pass->EncodeCommands();
47 surface_context->GetCommandQueue()
48 ->Submit({command_buffer},
56 device_buffer->Invalidate();
61 CGColorSpacePtr color_space(CGColorSpaceCreateDeviceRGB(),
62 &CGColorSpaceRelease);
63 CGBitmapInfo bitmap_info =
65 ?
static_cast<uint32_t
>(kCGImageAlphaPremultipliedFirst) |
66 static_cast<uint32_t
>(kCGBitmapByteOrder32Little)
67 : kCGImageAlphaPremultipliedLast;
69 CGBitmapContextCreate(
70 device_buffer->OnGetContents(),
texture->GetSize().width,
73 texture->GetTextureDescriptor().GetBytesPerRow(),
74 color_space.get(), bitmap_info),
77 CGImagePtr
image(CGBitmapContextCreateImage(context.get()), &CGImageRelease);
80 return std::make_unique<MetalScreenshot>(
image.release());
85 const std::unique_ptr<PlaygroundImpl>& playground)
86 : playground_(playground) {
92 const std::shared_ptr<Texture>
texture) {
std::shared_ptr< Context > GetContext() const
VulkanScreenshotter(const std::unique_ptr< PlaygroundImpl > &playground)
std::unique_ptr< Screenshot > MakeScreenshot(AiksContext &aiks_context, const std::shared_ptr< Texture > texture) override
FlutterVulkanImage * image
#define FML_CHECK(condition)