skia2/tests/MtlCopySurfaceTest.mm

72 lines
2.8 KiB
Plaintext
Raw Normal View History

/*
* 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/GrDirectContext.h"
#include "src/gpu/GrDirectContextPriv.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;
auto context = ctxInfo.directContext();
// 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, fbInfo);
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrSurfaceProxy> srcProxy = proxyProvider->wrapBackendRenderTarget(backendRT, nullptr);
auto dstProxy = GrSurfaceProxy::Copy(context,
srcProxy,
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 =
Reland "Remove GrBackendFormat's textureType use from isFormatTexturable call." This reverts commit d90777ada391dffa9a19101fe7917d0c13a606b3. Reason for revert: relanding with fix to GrBackendTexture Original change's description: > Revert "Remove GrBackendFormat's textureType use from isFormatTexturable call." > > This reverts commit 832c817bc8a9567aa379181e71e7c602d2480de8. > > Reason for revert: uninitialized value in GrBackendTexture > > Original change's description: > > Remove GrBackendFormat's textureType use from isFormatTexturable call. > > > > The goal of this change was to remove the use of GrBackendFormat::textureType() > > from GrCaps::isFormatTexturable call. Instead we will always pass in a > > GrTextureType into this call. > > > > To do this a lot of plumbing of GrTextureType was added to various call > > sites. However, this CL halts the plubming up at the proxy level where we > > get it from the GrBackendFormat still. Future CLs will continue removing > > these call sites and others that use GrBackendFormat::textureType(). > > > > Bug: skia:12342 > > Change-Id: Ic0f02b9c7f7402405623b8aa31aa32a9a7c22297 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439277 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com > > Change-Id: I354bbbf00be7a86c480009f3e7b36a8777a6bf3a > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:12342 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439338 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:12342 Change-Id: I151196f149f9e191d2975b8fe81334f4f8720744 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439339 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-08-13 20:20:18 +00:00
gpu->createTexture({kWidth, kHeight}, backendFormat, GrTextureType::k2D,
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);
}