skia2/tests/MtlCopySurfaceTest.mm
Robert Phillips a1121331a4 Be more consistent about calling release procs in SkImage factories (take 2)
I will follow this up with a Chrome-side CL to fix the call sites of the following factories:
   MakeFromCompressedTexture
   MakeFromTexture
   MakeFromYUVATexturesCopyWithExternalBackend
   MakeFromYUVTexturesCopyWithExternalBackend
   MakeFromNV12TexturesCopyWithExternalBackend

Here is the Chrome-side CL: https://chromium-review.googlesource.com/c/chromium/src/+/2264598/ (Skia's SkImage::Make* factories now guarantee cleanup)

Here is the Chrome-side CL that adds the guard flag:
https://chromium-review.googlesource.com/c/chromium/src/+/2273067/ (Add flag in order to roll a Skia CL into Chrome)

TBR=bsalomon@google.com
Bug: 1097484
Change-Id: Ic2fcdc116f0f866b33d752b6d5abc784c7f65be6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299663
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2020-06-29 18:40:04 +00:00

71 lines
2.8 KiB
Plaintext

/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkSurface.h"
#include "include/gpu/GrContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/mtl/GrMtlGpu.h"
#include "tests/Test.h"
#import <Metal/Metal.h>
#import <MetalKit/MTKView.h>
#include "src/gpu/mtl/GrMtlCaps.h"
#include "src/gpu/mtl/GrMtlTextureRenderTarget.h"
DEF_GPUTEST_FOR_METAL_CONTEXT(MtlCopySurfaceTest, reporter, ctxInfo) {
static const int kWidth = 1024;
static const int kHeight = 768;
GrContext* context = ctxInfo.grContext();
// This is a bit weird, but it's the only way to get a framebufferOnly surface
GrMtlGpu* gpu = (GrMtlGpu*) context->priv().getGpu();
MTKView* view = [[MTKView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)
device:gpu->device()];
id<CAMetalDrawable> drawable = [view currentDrawable];
REPORTER_ASSERT(reporter, drawable.texture.framebufferOnly);
REPORTER_ASSERT(reporter, drawable.texture.usage & MTLTextureUsageRenderTarget);
// Test to see if we can initiate a copy via GrSurfaceProxys
SkSurfaceProps props(0, kRGB_H_SkPixelGeometry);
// TODO: check multisampled RT as well
GrMtlTextureInfo fbInfo;
fbInfo.fTexture.retain((__bridge const void*)(drawable.texture));
GrBackendRenderTarget backendRT(kWidth, kHeight, 1, fbInfo);
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrSurfaceProxy> srcProxy = proxyProvider->wrapBackendRenderTarget(backendRT, nullptr);
auto dstProxy = GrSurfaceProxy::Copy(context,
srcProxy.get(),
kTopLeft_GrSurfaceOrigin,
GrMipMapped::kNo,
SkBackingFit::kExact,
SkBudgeted::kYes);
// TODO: GrSurfaceProxy::Copy doesn't check to see if the framebufferOnly bit is set yet.
// Update this when it does -- it should fail.
if (!dstProxy) {
ERRORF(reporter, "Expected copy to succeed");
}
// Try direct copy via GPU (should fail)
GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(drawable.texture.pixelFormat);
GrSurface* src = srcProxy->peekSurface();
sk_sp<GrTexture> dst =
gpu->createTexture({kWidth, kHeight}, backendFormat, GrRenderable::kNo, 1,
GrMipMapped::kNo, SkBudgeted::kNo, GrProtected::kNo);
bool result = gpu->copySurface(dst.get(), src, SkIRect::MakeXYWH(0, 0, kWidth, kHeight),
SkIPoint::Make(0, 0));
REPORTER_ASSERT(reporter, !result);
}