skia2/tools/gpu/BackendSurfaceFactory.cpp
Brian Salomon f9b0042423 Expose ManagedBackendTexture from BackendTextureImageFactory.
Add helper to create self-managed BackendTexture-backed SkSurface for
tests using MBET.

GrGpu::createTestingOnlyBackendRenderTarget supports protected.

Make SkSurfaceCharacterization tests use self-managed SkSurface
factories and a use case of MakeFromBackendTextureAsRenderTarget is
removed.

Use self-managed BackendTexture-backed SkSurface factory in DM sinks and
in fm.

Bug: skia:9832

Change-Id: I0c1dc49697f8b3c942864e18b9112a3552f431ba
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323559
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-10-08 20:35:32 +00:00

81 lines
3.5 KiB
C++

/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/gpu/BackendSurfaceFactory.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrGpu.h"
#include "tools/gpu/ManagedBackendTexture.h"
namespace sk_gpu_test {
sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* context,
SkISize dimensions,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
GrMipmapped mipMapped,
GrProtected isProtected,
const SkSurfaceProps* props) {
auto mbet = ManagedBackendTexture::MakeWithoutData(context,
dimensions.fWidth,
dimensions.fHeight,
colorType,
mipMapped,
GrRenderable::kYes,
isProtected);
if (!mbet) {
return nullptr;
}
return SkSurface::MakeFromBackendTexture(context,
mbet->texture(),
origin,
sampleCnt,
colorType,
std::move(colorSpace),
props,
ManagedBackendTexture::ReleaseProc,
mbet->releaseContext());
}
sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* context,
SkISize dimensions,
GrSurfaceOrigin origin,
int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
GrProtected isProtected,
const SkSurfaceProps* props) {
auto ct = SkColorTypeToGrColorType(colorType);
struct ReleaseContext {
GrDirectContext* fContext;
GrBackendRenderTarget fRenderTarget;
};
auto bert = context->priv().getGpu()->createTestingOnlyBackendRenderTarget(
dimensions, ct, sampleCnt, isProtected);
auto rc = new ReleaseContext{context, bert};
SkASSERT(!bert.isValid() || bert.sampleCnt() >= sampleCnt);
auto proc = [](void* c) {
const auto* rc = static_cast<ReleaseContext*>(c);
if (auto gpu = rc->fContext->priv().getGpu(); gpu && rc->fRenderTarget.isValid()) {
gpu->deleteTestingOnlyBackendRenderTarget(rc->fRenderTarget);
}
delete rc;
};
return SkSurface::MakeFromBackendRenderTarget(
context, bert, origin, colorType, std::move(colorSpace), props, proc, rc);
}
} // namespace sk_gpu_test