5#import <Foundation/Foundation.h>
11#import "flutter/display_list/skia/dl_sk_canvas.h"
12#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
13#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
14#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
15#include "flutter/shell/platform/embedder/embedder.h"
16#include "flutter/shell/platform/embedder/embedder_external_texture_metal.h"
17#include "flutter/testing/autoreleasepool_test.h"
18#include "flutter/testing/testing.h"
19#include "third_party/googletest/googletest/include/gtest/gtest.h"
27- (nonnull instancetype)initWidth:(
size_t)width
29 pixelFormatType:(OSType)pixelFormatType;
39- (nonnull instancetype)initWidth:(
size_t)width
41 pixelFormatType:(OSType)pixelFormatType {
42 if (
self = [super init]) {
50- (CVPixelBufferRef)copyPixelBuffer {
51 return [
self pixelBuffer];
54- (CVPixelBufferRef)pixelBuffer {
57 (NSString*)kCVPixelBufferMetalCompatibilityKey : @YES
59 CVPixelBufferRef pxbuffer = NULL;
60 CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, _width, _width,
_pixelFormatType,
61 (__bridge CFDictionaryRef)
options, &pxbuffer);
62 NSAssert(status == kCVReturnSuccess && pxbuffer != NULL,
@"Failed to create pixel buffer.");
75 const size_t width = 100;
87 MTLTextureDescriptor* textureDescriptor = [[MTLTextureDescriptor alloc] init];
88 textureDescriptor.pixelFormat = MTLPixelFormatBGRA8Unorm;
89 textureDescriptor.width =
width;
90 textureDescriptor.height =
height;
91 textureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
92 id<MTLTexture> mtlTexture =
93 [darwinContextMetal.device newTextureWithDescriptor:textureDescriptor];
94 std::vector<FlutterMetalTextureHandle>
textures = {
104 auto texture = std::make_unique<FlutterMetalExternalTexture>();
115 std::unique_ptr<flutter::Texture>
texture =
122 .gr_context = grContext,
124 texture->Paint(context, bounds,
false, sampling);
126 ASSERT_TRUE(mtlTexture != nil);
128 gpuSurface->makeImageSnapshot();
133 const size_t width = 100;
134 const size_t height = 100;
148 pixelFormatType:kCVPixelFormatType_32BGRA];
151 darwinMetalContext:darwinContextMetal];
159 auto texture = std::make_unique<FlutterMetalExternalTexture>();
169 std::unique_ptr<flutter::Texture>
texture =
176 .gr_context = grContext,
178 texture->Paint(context, bounds,
false, sampling);
180 gpuSurface->makeImageSnapshot();
185 const size_t width = 100;
186 const size_t height = 100;
200 pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange];
203 darwinMetalContext:darwinContextMetal];
211 auto texture = std::make_unique<FlutterMetalExternalTexture>();
223 std::unique_ptr<flutter::Texture>
texture =
230 .gr_context = grContext,
232 texture->Paint(context, bounds,
false, sampling);
234 gpuSurface->makeImageSnapshot();
239 const size_t width = 100;
240 const size_t height = 100;
254 pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange];
257 darwinMetalContext:darwinContextMetal];
265 auto texture = std::make_unique<FlutterMetalExternalTexture>();
277 std::unique_ptr<flutter::Texture>
texture =
284 .gr_context = grContext,
286 texture->Paint(context, bounds,
false, sampling);
288 gpuSurface->makeImageSnapshot();
293 const size_t width = 100;
294 const size_t height = 100;
308 pixelFormatType:kCVPixelFormatType_420YpCbCr8PlanarFullRange];
311 darwinMetalContext:darwinContextMetal];
319 auto texture = std::make_unique<FlutterMetalExternalTexture>();
320 EXPECT_FALSE([textureHolder populateTexture:
texture.get()]);
325 std::unique_ptr<flutter::Texture>
texture =
332 .gr_context = grContext,
334 texture->Paint(context, bounds,
false, sampling);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Backend implementation of |DlCanvas| for |SkCanvas|.
std::function< std::unique_ptr< FlutterMetalExternalTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
std::vector< std::shared_ptr< FakeTexture > > textures
const void * FlutterMetalTextureHandle
Alias for id<MTLTexture>.
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
sk_sp< GrDirectContext > mainContext
BOOL populateTexture:(nonnull FlutterMetalExternalTexture *metalTexture)
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)
TEST_F(DisplayListTest, Defaults)
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 h
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
#define EXPECT_TRUE(handle)