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 {
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 FML_CHECK(status == kCVReturnSuccess && pxbuffer !=
nullptr) <<
"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>();
110 texture->textures = textures.data();
115 std::unique_ptr<flutter::Texture>
texture =
122 .gr_context = grContext,
126 ASSERT_TRUE(mtlTexture != nil);
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,
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,
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,
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,
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
sk_sp< SkImage > makeImageSnapshot()
Backend implementation of |DlCanvas| for |SkCanvas|.
std::function< std::unique_ptr< FlutterMetalExternalTexture >(int64_t, size_t, size_t)> ExternalTextureCallback
const void * FlutterMetalTextureHandle
Alias for id<MTLTexture>.
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_CHECK(condition)
sk_sp< GrDirectContext > mainContext
BOOL populateTexture:(nonnull FlutterMetalExternalTexture *metalTexture)
Optional< SkRect > bounds
SkSamplingOptions sampling
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)