Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
MtlCopySurfaceTest.mm
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
16#include "tests/Test.h"
17
18#import <Metal/Metal.h>
19#import <MetalKit/MTKView.h>
20
21DEF_GANESH_TEST_FOR_METAL_CONTEXT(MtlCopySurfaceTest, reporter, ctxInfo) {
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,
51 skgpu::Mipmapped::kNo,
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,
68 GrRenderable::kNo,
69 1,
70 skgpu::Mipmapped::kNo,
72 GrProtected::kNo,
73 /*label=*/"MtlCopySurfaceTest");
74
75 bool result = gpu->copySurface(dst.get(),
77 src,
79 GrSamplerState::Filter::kNearest);
81 }
82}
reporter
@ 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
#define DEF_GANESH_TEST_FOR_METAL_CONTEXT(name, reporter, context_info)
Definition Test.h:462
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)
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)
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
constexpr size_t kHeight
constexpr size_t kWidth