2020-10-06 14:07:38 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2020-10-06 14:07:38 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
2020-10-08 20:00:14 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* dContext,
|
|
|
|
const SkImageInfo& ii,
|
2020-10-08 20:00:14 +00:00
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
int sampleCnt,
|
|
|
|
GrMipmapped mipMapped,
|
|
|
|
GrProtected isProtected,
|
|
|
|
const SkSurfaceProps* props) {
|
2020-10-13 00:45:06 +00:00
|
|
|
if (ii.alphaType() == kUnpremul_SkAlphaType) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
|
|
|
|
ii.width(),
|
|
|
|
ii.height(),
|
|
|
|
ii.colorType(),
|
2020-10-08 20:00:14 +00:00
|
|
|
mipMapped,
|
|
|
|
GrRenderable::kYes,
|
|
|
|
isProtected);
|
|
|
|
if (!mbet) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-13 00:45:06 +00:00
|
|
|
return SkSurface::MakeFromBackendTexture(dContext,
|
2020-10-08 20:00:14 +00:00
|
|
|
mbet->texture(),
|
|
|
|
origin,
|
|
|
|
sampleCnt,
|
2020-10-13 00:45:06 +00:00
|
|
|
ii.colorType(),
|
|
|
|
ii.refColorSpace(),
|
2020-10-08 20:00:14 +00:00
|
|
|
props,
|
|
|
|
ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext());
|
|
|
|
}
|
2020-10-06 14:07:38 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<SkSurface> MakeBackendTextureSurface(GrDirectContext* dContext,
|
|
|
|
SkISize dimensions,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
int sampleCnt,
|
|
|
|
SkColorType colorType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
|
|
|
GrMipmapped mipMapped,
|
|
|
|
GrProtected isProtected,
|
|
|
|
const SkSurfaceProps* props) {
|
|
|
|
auto ii = SkImageInfo::Make(dimensions, colorType, kPremul_SkAlphaType, std::move(colorSpace));
|
|
|
|
return MakeBackendTextureSurface(
|
|
|
|
dContext, ii, origin, sampleCnt, mipMapped, isProtected, props);
|
|
|
|
}
|
|
|
|
sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* dContext,
|
|
|
|
const SkImageInfo& ii,
|
2020-10-06 14:07:38 +00:00
|
|
|
GrSurfaceOrigin origin,
|
2020-10-08 20:00:14 +00:00
|
|
|
int sampleCnt,
|
|
|
|
GrProtected isProtected,
|
2020-10-06 14:07:38 +00:00
|
|
|
const SkSurfaceProps* props) {
|
2021-01-22 00:48:00 +00:00
|
|
|
if (ii.alphaType() == kUnpremul_SkAlphaType || ii.alphaType() == kUnknown_SkAlphaType) {
|
2020-10-13 00:45:06 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto ct = SkColorTypeToGrColorType(ii.colorType());
|
2020-10-06 14:07:38 +00:00
|
|
|
|
|
|
|
struct ReleaseContext {
|
2020-10-15 14:38:19 +00:00
|
|
|
sk_sp<GrDirectContext> fContext;
|
2020-10-06 14:07:38 +00:00
|
|
|
GrBackendRenderTarget fRenderTarget;
|
|
|
|
};
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto bert = dContext->priv().getGpu()->createTestingOnlyBackendRenderTarget(
|
|
|
|
ii.dimensions(), ct, sampleCnt, isProtected);
|
2020-10-15 14:38:19 +00:00
|
|
|
auto rc = new ReleaseContext{sk_ref_sp(dContext), bert};
|
2020-10-06 14:07:38 +00:00
|
|
|
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(
|
2020-10-13 00:45:06 +00:00
|
|
|
dContext, bert, origin, ii.colorType(), ii.refColorSpace(), props, proc, rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* dContext,
|
|
|
|
SkISize dimensions,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
int sampleCnt,
|
|
|
|
SkColorType colorType,
|
|
|
|
sk_sp<SkColorSpace> colorSpace,
|
|
|
|
GrProtected isProtected,
|
|
|
|
const SkSurfaceProps* props) {
|
|
|
|
auto ii = SkImageInfo::Make(dimensions, colorType, kPremul_SkAlphaType, std::move(colorSpace));
|
|
|
|
return MakeBackendRenderTargetSurface(dContext, ii, origin, sampleCnt, isProtected, props);
|
2020-10-06 14:07:38 +00:00
|
|
|
}
|
2020-10-08 20:00:14 +00:00
|
|
|
|
|
|
|
} // namespace sk_gpu_test
|