Flutter Engine
The Flutter Engine
Functions
MtlCopySurfaceTest.mm File Reference
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/mtl/GrMtlBackendSurface.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/mtl/GrMtlCaps.h"
#include "src/gpu/ganesh/mtl/GrMtlGpu.h"
#include "src/gpu/ganesh/mtl/GrMtlTextureRenderTarget.h"
#include "tests/Test.h"
#import <Metal/Metal.h>
#import <MetalKit/MTKView.h>

Go to the source code of this file.

Functions

 DEF_GANESH_TEST_FOR_METAL_CONTEXT (MtlCopySurfaceTest, reporter, ctxInfo)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_METAL_CONTEXT()

DEF_GANESH_TEST_FOR_METAL_CONTEXT ( MtlCopySurfaceTest  ,
reporter  ,
ctxInfo   
)

Definition at line 21 of file MtlCopySurfaceTest.mm.

21 {
22 if (@available(macOS 11.0, iOS 9.0, tvOS 9.0, *)) {
23 static const int kWidth = 1024;
24 static const int kHeight = 768;
25
26 auto context = ctxInfo.directContext();
27
28 // This is a bit weird, but it's the only way to get a framebufferOnly surface
29 GrMtlGpu* gpu = (GrMtlGpu*) context->priv().getGpu();
30
31 MTKView* view = [[MTKView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)
32 device:gpu->device()];
33 id<CAMetalDrawable> drawable = [view currentDrawable];
34 REPORTER_ASSERT(reporter, drawable.texture.framebufferOnly);
35 REPORTER_ASSERT(reporter, drawable.texture.usage & MTLTextureUsageRenderTarget);
36
37 // Test to see if we can initiate a copy via GrSurfaceProxys
39
40 // TODO: check multisampled RT as well
41 GrMtlTextureInfo fbInfo;
42 fbInfo.fTexture.retain((__bridge const void*)(drawable.texture));
44
45 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
46 sk_sp<GrSurfaceProxy> srcProxy = proxyProvider->wrapBackendRenderTarget(backendRT, nullptr);
47
48 auto dstProxy = GrSurfaceProxy::Copy(context,
49 srcProxy,
54 /*label=*/{});
55
56 // TODO: GrSurfaceProxy::Copy doesn't check to see if the framebufferOnly bit is set yet.
57 // Update this when it does -- it should fail.
58 if (!dstProxy) {
59 ERRORF(reporter, "Expected copy to succeed");
60 }
61
62 // Try direct copy via GPU (should fail)
63 GrBackendFormat backendFormat = GrBackendFormats::MakeMtl(drawable.texture.pixelFormat);
64 GrSurface* src = srcProxy->peekSurface();
66 backendFormat,
69 1,
73 /*label=*/"MtlCopySurfaceTest");
74
75 bool result = gpu->copySurface(dst.get(),
77 src,
81 }
82}
reporter
Definition: FontMgrTest.cpp:39
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ kRGB_H_SkPixelGeometry
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
bool copySurface(GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter filter)
Definition: GrGpu.cpp:410
sk_sp< GrTexture > createTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Budgeted budgeted, GrProtected isProtected, GrColorType textureColorType, GrColorType srcColorType, const GrMipLevel texels[], int texelLevelCount, std::string_view label)
Definition: GrGpu.cpp:189
id< MTLDevice > device() const
Definition: GrMtlGpu.h:49
sk_sp< GrSurfaceProxy > wrapBackendRenderTarget(const GrBackendRenderTarget &, sk_sp< skgpu::RefCntedCallback > releaseHelper)
static sk_sp< GrSurfaceProxy > Copy(GrRecordingContext *, sk_sp< GrSurfaceProxy > src, GrSurfaceOrigin, skgpu::Mipmapped, SkIRect srcRect, SkBackingFit, skgpu::Budgeted, std::string_view label, RectsMustMatch=RectsMustMatch::kNo, sk_sp< GrRenderTask > *outTask=nullptr)
GrSurface * peekSurface() const
VkDevice device
Definition: main.cc:53
GAsyncResult * result
instancetype initWithFrame
SK_API GrBackendFormat MakeMtl(GrMTLPixelFormat format)
SK_API GrBackendRenderTarget MakeMtl(int width, int height, const GrMtlTextureInfo &mtlInfo)
dst
Definition: cp.py:12
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
constexpr size_t kHeight
constexpr size_t kWidth