2017-12-04 17:52:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
|
|
|
#include "include/core/SkDeferredDisplayListRecorder.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPromiseImageTexture.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
|
|
|
#include "include/core/SkSurfaceProps.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
|
|
#include "include/gpu/GrContext.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/gpu/GrContextThreadSafeProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
|
|
|
#include "include/gpu/gl/GrGLTypes.h"
|
|
|
|
#include "include/private/GrTypesPriv.h"
|
|
|
|
#include "include/private/SkDeferredDisplayList.h"
|
|
|
|
#include "src/core/SkDeferredDisplayListPriv.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrRenderTargetProxy.h"
|
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/SkGpuDevice.h"
|
|
|
|
#include "src/gpu/gl/GrGLDefines.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "src/image/SkImage_GpuBase.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/image/SkSurface_Gpu.h"
|
|
|
|
#include "tests/Test.h"
|
2019-05-07 17:29:22 +00:00
|
|
|
#include "tests/TestUtils.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2018-02-13 22:03:00 +00:00
|
|
|
|
2019-07-10 13:28:59 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
#include "src/gpu/vk/GrVkCaps.h"
|
|
|
|
#endif
|
|
|
|
|
2017-12-04 17:52:46 +00:00
|
|
|
class SurfaceParameters {
|
|
|
|
public:
|
2019-07-10 13:28:59 +00:00
|
|
|
static const int kNumParams = 12;
|
|
|
|
static const int kSampleCount = 5;
|
|
|
|
static const int kMipMipCount = 8;
|
|
|
|
static const int kFBO0Count = 9;
|
|
|
|
static const int kProtectedCount = 11;
|
|
|
|
|
|
|
|
SurfaceParameters(GrContext* context)
|
|
|
|
: fBackend(context->backend())
|
2019-02-03 22:17:54 +00:00
|
|
|
, fWidth(64)
|
2017-12-04 17:52:46 +00:00
|
|
|
, fHeight(64)
|
|
|
|
, fOrigin(kTopLeft_GrSurfaceOrigin)
|
|
|
|
, fColorType(kRGBA_8888_SkColorType)
|
|
|
|
, fColorSpace(SkColorSpace::MakeSRGB())
|
2018-02-03 01:32:49 +00:00
|
|
|
, fSampleCount(1)
|
2018-02-04 19:33:21 +00:00
|
|
|
, fSurfaceProps(0x0, kUnknown_SkPixelGeometry)
|
2019-02-03 22:17:54 +00:00
|
|
|
, fShouldCreateMipMaps(true)
|
|
|
|
, fUsesGLFBO0(false)
|
2019-07-10 13:28:59 +00:00
|
|
|
, fIsTextureable(true)
|
|
|
|
, fIsProtected(GrProtected::kNo) {
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
if (GrBackendApi::kVulkan == context->backend()) {
|
|
|
|
const GrVkCaps* vkCaps = (const GrVkCaps*) context->priv().caps();
|
|
|
|
|
|
|
|
fIsProtected = GrProtected(vkCaps->supportsProtectedMemory());
|
|
|
|
}
|
|
|
|
#endif
|
2018-02-04 19:33:21 +00:00
|
|
|
}
|
2017-12-04 17:52:46 +00:00
|
|
|
|
|
|
|
int sampleCount() const { return fSampleCount; }
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
void setColorType(SkColorType ct) { fColorType = ct; }
|
2019-06-24 17:25:42 +00:00
|
|
|
SkColorType colorType() const { return fColorType; }
|
2018-04-03 21:17:05 +00:00
|
|
|
void setColorSpace(sk_sp<SkColorSpace> cs) { fColorSpace = std::move(cs); }
|
2019-02-03 22:17:54 +00:00
|
|
|
void setTextureable(bool isTextureable) { fIsTextureable = isTextureable; }
|
2019-05-09 20:28:04 +00:00
|
|
|
void setShouldCreateMipMaps(bool shouldCreateMipMaps) {
|
|
|
|
fShouldCreateMipMaps = shouldCreateMipMaps;
|
|
|
|
}
|
2018-04-03 21:17:05 +00:00
|
|
|
|
2017-12-04 17:52:46 +00:00
|
|
|
// Modify the SurfaceParameters in just one way
|
|
|
|
void modify(int i) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
fWidth = 63;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fHeight = 63;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
fOrigin = kBottomLeft_GrSurfaceOrigin;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
fColorType = kRGBA_F16_SkColorType;
|
|
|
|
break;
|
|
|
|
case 4:
|
2018-08-09 14:26:57 +00:00
|
|
|
// This just needs to be a colorSpace different from that returned by MakeSRGB().
|
|
|
|
// In this case we just change the gamut.
|
2019-01-04 22:03:00 +00:00
|
|
|
fColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kAdobeRGB);
|
2017-12-04 17:52:46 +00:00
|
|
|
break;
|
|
|
|
case kSampleCount:
|
|
|
|
fSampleCount = 4;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
fSurfaceProps = SkSurfaceProps(0x0, kRGB_H_SkPixelGeometry);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
fSurfaceProps = SkSurfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
|
|
|
|
kUnknown_SkPixelGeometry);
|
|
|
|
break;
|
2018-02-04 19:33:21 +00:00
|
|
|
case 8:
|
|
|
|
fShouldCreateMipMaps = false;
|
|
|
|
break;
|
2019-02-03 22:17:54 +00:00
|
|
|
case 9:
|
|
|
|
if (GrBackendApi::kOpenGL == fBackend) {
|
|
|
|
fUsesGLFBO0 = true;
|
2019-07-01 14:34:03 +00:00
|
|
|
fShouldCreateMipMaps = false; // needs to changed in tandem w/ textureability
|
2019-02-03 22:17:54 +00:00
|
|
|
fIsTextureable = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
2019-07-01 14:34:03 +00:00
|
|
|
fShouldCreateMipMaps = false; // needs to changed in tandem w/ textureability
|
2019-02-03 22:17:54 +00:00
|
|
|
fIsTextureable = false;
|
|
|
|
break;
|
2019-07-10 13:28:59 +00:00
|
|
|
case 11:
|
|
|
|
fIsProtected = GrProtected::kYes == fIsProtected ? GrProtected::kNo
|
|
|
|
: GrProtected::kYes;
|
|
|
|
break;
|
2018-02-04 19:33:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-30 17:57:00 +00:00
|
|
|
SkSurfaceCharacterization createCharacterization(GrContext* context) const {
|
2019-09-03 14:29:20 +00:00
|
|
|
size_t maxResourceBytes = context->getResourceCacheLimit();
|
2018-02-13 22:03:00 +00:00
|
|
|
|
2019-09-04 19:05:35 +00:00
|
|
|
if (!context->colorTypeSupportedAsSurface(fColorType)) {
|
|
|
|
return SkSurfaceCharacterization();
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:03:00 +00:00
|
|
|
// Note that Ganesh doesn't make use of the SkImageInfo's alphaType
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType,
|
|
|
|
kPremul_SkAlphaType, fColorSpace);
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
GrBackendFormat backendFormat = context->defaultBackendFormat(fColorType,
|
|
|
|
GrRenderable::kYes);
|
2018-04-03 21:17:05 +00:00
|
|
|
if (!backendFormat.isValid()) {
|
|
|
|
return SkSurfaceCharacterization();
|
|
|
|
}
|
2018-02-13 22:03:00 +00:00
|
|
|
|
|
|
|
SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization(
|
|
|
|
maxResourceBytes, ii, backendFormat, fSampleCount,
|
2019-02-03 22:17:54 +00:00
|
|
|
fOrigin, fSurfaceProps, fShouldCreateMipMaps,
|
2019-07-10 13:28:59 +00:00
|
|
|
fUsesGLFBO0, fIsTextureable, fIsProtected);
|
2018-03-30 17:57:00 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a DDL whose characterization captures the current settings
|
|
|
|
std::unique_ptr<SkDeferredDisplayList> createDDL(GrContext* context) const {
|
|
|
|
SkSurfaceCharacterization c = this->createCharacterization(context);
|
2018-02-13 22:03:00 +00:00
|
|
|
SkAssertResult(c.isValid());
|
2018-02-04 19:33:21 +00:00
|
|
|
|
|
|
|
SkDeferredDisplayListRecorder r(c);
|
|
|
|
SkCanvas* canvas = r.getCanvas();
|
|
|
|
if (!canvas) {
|
|
|
|
return nullptr;
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
2018-02-04 19:33:21 +00:00
|
|
|
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(10, 10, 10, 10), SkPaint());
|
|
|
|
return r.detach();
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the surface with the current set of parameters
|
2019-02-03 22:17:54 +00:00
|
|
|
sk_sp<SkSurface> make(GrContext* context, GrBackendTexture* backend) const {
|
2019-06-24 17:25:42 +00:00
|
|
|
const SkSurfaceCharacterization c = this->createCharacterization(context);
|
|
|
|
|
2019-02-03 22:17:54 +00:00
|
|
|
GrMipMapped mipmapped = !fIsTextureable
|
2018-04-03 21:17:05 +00:00
|
|
|
? GrMipMapped::kNo
|
|
|
|
: GrMipMapped(fShouldCreateMipMaps);
|
2018-02-04 19:33:21 +00:00
|
|
|
|
2019-09-25 21:14:35 +00:00
|
|
|
#ifdef SK_GL
|
2019-02-03 22:17:54 +00:00
|
|
|
if (fUsesGLFBO0) {
|
|
|
|
if (GrBackendApi::kOpenGL != context->backend()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrGLFramebufferInfo fboInfo;
|
|
|
|
fboInfo.fFBOID = 0;
|
|
|
|
fboInfo.fFormat = GR_GL_RGBA8;
|
|
|
|
static constexpr int kStencilBits = 8;
|
|
|
|
GrBackendRenderTarget backendRT(fWidth, fHeight, 1, kStencilBits, fboInfo);
|
|
|
|
|
|
|
|
if (!backendRT.isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
sk_sp<SkSurface> result = SkSurface::MakeFromBackendRenderTarget(context, backendRT,
|
|
|
|
fOrigin, fColorType,
|
|
|
|
fColorSpace,
|
|
|
|
&fSurfaceProps);
|
2019-06-25 18:47:04 +00:00
|
|
|
SkASSERT(result->isCompatible(c));
|
2019-06-24 17:25:42 +00:00
|
|
|
return result;
|
2019-02-03 22:17:54 +00:00
|
|
|
}
|
2019-09-25 21:14:35 +00:00
|
|
|
#endif
|
2019-02-03 22:17:54 +00:00
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
*backend = context->createBackendTexture(fWidth, fHeight, fColorType,
|
|
|
|
SkColors::kTransparent,
|
2019-07-10 13:28:59 +00:00
|
|
|
mipmapped, GrRenderable::kYes, fIsProtected);
|
2019-07-08 19:55:24 +00:00
|
|
|
if (!backend->isValid()) {
|
2018-02-04 19:33:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-01 14:34:03 +00:00
|
|
|
// Even if a characterization couldn't be constructed we want to soldier on to make
|
|
|
|
// sure that surface creation will/would've also failed
|
|
|
|
SkASSERT(!c.isValid() || c.isCompatible(*backend));
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
sk_sp<SkSurface> surface;
|
2019-02-03 22:17:54 +00:00
|
|
|
if (!fIsTextureable) {
|
2018-04-03 21:17:05 +00:00
|
|
|
// Create a surface w/ the current parameters but make it non-textureable
|
|
|
|
surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
|
|
|
|
context, *backend, fOrigin, fSampleCount, fColorType,
|
|
|
|
fColorSpace, &fSurfaceProps);
|
|
|
|
} else {
|
|
|
|
surface = SkSurface::MakeFromBackendTexture(
|
|
|
|
context, *backend, fOrigin, fSampleCount, fColorType,
|
|
|
|
fColorSpace, &fSurfaceProps);
|
|
|
|
}
|
2018-02-04 19:33:21 +00:00
|
|
|
|
|
|
|
if (!surface) {
|
2019-07-01 14:34:03 +00:00
|
|
|
SkASSERT(!c.isValid());
|
2019-05-17 14:01:21 +00:00
|
|
|
this->cleanUpBackEnd(context, *backend);
|
2018-02-04 19:33:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-01 14:34:03 +00:00
|
|
|
SkASSERT(c.isValid());
|
2019-06-25 18:47:04 +00:00
|
|
|
SkASSERT(surface->isCompatible(c));
|
2018-02-04 19:33:21 +00:00
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
void cleanUpBackEnd(GrContext* context, const GrBackendTexture& backend) const {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backend);
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-02-03 22:17:54 +00:00
|
|
|
GrBackendApi fBackend;
|
2017-12-04 17:52:46 +00:00
|
|
|
int fWidth;
|
|
|
|
int fHeight;
|
|
|
|
GrSurfaceOrigin fOrigin;
|
|
|
|
SkColorType fColorType;
|
|
|
|
sk_sp<SkColorSpace> fColorSpace;
|
|
|
|
int fSampleCount;
|
|
|
|
SkSurfaceProps fSurfaceProps;
|
2018-02-04 19:33:21 +00:00
|
|
|
bool fShouldCreateMipMaps;
|
2019-02-03 22:17:54 +00:00
|
|
|
bool fUsesGLFBO0;
|
|
|
|
bool fIsTextureable;
|
2019-07-10 13:28:59 +00:00
|
|
|
GrProtected fIsProtected;
|
2017-12-04 17:52:46 +00:00
|
|
|
};
|
|
|
|
|
2018-04-04 15:12:39 +00:00
|
|
|
// Test out operator== && operator!=
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params1(context);
|
2018-04-04 15:12:39 +00:00
|
|
|
params1.modify(i);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization char1 = params1.createCharacterization(context);
|
|
|
|
if (!char1.isValid()) {
|
|
|
|
continue; // can happen on some platforms (ChromeOS)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < SurfaceParameters::kNumParams; ++j) {
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params2(context);
|
2018-04-04 15:12:39 +00:00
|
|
|
params2.modify(j);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization char2 = params2.createCharacterization(context);
|
|
|
|
if (!char2.isValid()) {
|
|
|
|
continue; // can happen on some platforms (ChromeOS)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == j) {
|
|
|
|
REPORTER_ASSERT(reporter, char1 == char2);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, char1 != char2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2018-04-04 15:12:39 +00:00
|
|
|
|
|
|
|
SkSurfaceCharacterization valid = params.createCharacterization(context);
|
|
|
|
SkASSERT(valid.isValid());
|
|
|
|
|
|
|
|
SkSurfaceCharacterization inval1, inval2;
|
|
|
|
SkASSERT(!inval1.isValid() && !inval2.isValid());
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, inval1 != inval2);
|
|
|
|
REPORTER_ASSERT(reporter, valid != inval1);
|
|
|
|
REPORTER_ASSERT(reporter, inval1 != valid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-30 17:57:00 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2017-12-04 17:52:46 +00:00
|
|
|
// This tests SkSurfaceCharacterization/SkSurface compatibility
|
2019-07-10 13:28:59 +00:00
|
|
|
void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter* reporter) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2019-06-24 17:25:42 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
2017-12-04 17:52:46 +00:00
|
|
|
|
2018-02-01 20:14:55 +00:00
|
|
|
// Create a bitmap that we can readback into
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(imageInfo);
|
|
|
|
|
2017-12-04 17:52:46 +00:00
|
|
|
std::unique_ptr<SkDeferredDisplayList> ddl;
|
|
|
|
|
|
|
|
// First, create a DDL using the stock SkSurface parameters
|
|
|
|
{
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2017-12-04 17:52:46 +00:00
|
|
|
|
2018-02-04 19:33:21 +00:00
|
|
|
ddl = params.createDDL(context);
|
2018-02-13 22:03:00 +00:00
|
|
|
SkAssertResult(ddl);
|
2018-02-04 19:33:21 +00:00
|
|
|
|
|
|
|
// The DDL should draw into an SkSurface created with the same parameters
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
2019-02-03 22:17:54 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
2017-12-04 17:52:46 +00:00
|
|
|
if (!s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl.get()));
|
2018-02-01 20:14:55 +00:00
|
|
|
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
|
2018-04-03 21:17:05 +00:00
|
|
|
context->flush();
|
|
|
|
gpu->testingOnly_flushGpuAndSync();
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Then, alter each parameter in turn and check that the DDL & surface are incompatible
|
|
|
|
for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2017-12-04 17:52:46 +00:00
|
|
|
params.modify(i);
|
|
|
|
|
2019-07-10 13:28:59 +00:00
|
|
|
if (SurfaceParameters::kProtectedCount == i) {
|
|
|
|
if (context->backend() != GrBackendApi::kVulkan) {
|
|
|
|
// Only the Vulkan backend respects the protected parameter
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
const GrVkCaps* vkCaps = (const GrVkCaps*) context->priv().caps();
|
|
|
|
|
|
|
|
// And, even then, only when it is a protected context
|
|
|
|
if (!vkCaps->supportsProtectedMemory()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
2019-02-03 22:17:54 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
2017-12-04 17:52:46 +00:00
|
|
|
if (!s) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SurfaceParameters::kSampleCount == i) {
|
2019-06-24 17:25:42 +00:00
|
|
|
int supportedSampleCount = caps->getRenderTargetSampleCount(
|
2019-08-07 19:52:37 +00:00
|
|
|
params.sampleCount(), backend.getBackendFormat());
|
2018-02-03 01:32:49 +00:00
|
|
|
if (1 == supportedSampleCount) {
|
2017-12-04 17:52:46 +00:00
|
|
|
// If changing the sample count won't result in a different
|
|
|
|
// surface characterization, skip this step
|
2018-04-03 21:17:05 +00:00
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2017-12-04 17:52:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
if (SurfaceParameters::kMipMipCount == i && !caps->mipMapSupport()) {
|
2018-03-30 17:57:00 +00:00
|
|
|
// If changing the mipmap setting won't result in a different surface characterization,
|
|
|
|
// skip this step
|
2018-04-03 21:17:05 +00:00
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2018-02-04 19:33:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-02-03 22:17:54 +00:00
|
|
|
if (SurfaceParameters::kFBO0Count == i && context->backend() != GrBackendApi::kOpenGL) {
|
|
|
|
// FBO0 only affects the surface characterization when using OpenGL
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-04 19:33:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, !s->draw(ddl.get()),
|
|
|
|
"DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
context->flush();
|
|
|
|
gpu->testingOnly_flushGpuAndSync();
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
2017-12-04 18:48:14 +00:00
|
|
|
|
|
|
|
// Next test the compatibility of resource cache parameters
|
|
|
|
{
|
2019-07-10 13:28:59 +00:00
|
|
|
const SurfaceParameters params(context);
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
|
|
|
|
2019-02-03 22:17:54 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
2017-12-04 18:48:14 +00:00
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
size_t maxResourceBytes = context->getResourceCacheLimit();
|
2017-12-04 18:48:14 +00:00
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(maxResourceBytes/2);
|
2017-12-04 18:48:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
|
|
|
|
|
2018-02-01 20:14:55 +00:00
|
|
|
// DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
|
|
|
|
// For now, DDLs are drawn once.
|
|
|
|
#if 0
|
2017-12-04 18:48:14 +00:00
|
|
|
// resource limits >= those at characterization time are accepted
|
|
|
|
context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes);
|
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl.get()));
|
2018-02-01 20:14:55 +00:00
|
|
|
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
|
2017-12-04 18:48:14 +00:00
|
|
|
|
|
|
|
context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes);
|
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl.get()));
|
2018-02-01 20:14:55 +00:00
|
|
|
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
|
2017-12-04 18:48:14 +00:00
|
|
|
|
|
|
|
context->setResourceCacheLimits(maxResourceCount, maxResourceBytes);
|
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl.get()));
|
2018-02-01 20:14:55 +00:00
|
|
|
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
|
|
|
|
#endif
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
context->flush();
|
|
|
|
gpu->testingOnly_flushGpuAndSync();
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2017-12-04 18:48:14 +00:00
|
|
|
}
|
|
|
|
|
2018-02-04 19:33:21 +00:00
|
|
|
// Test that the textureability of the DDL characterization can block a DDL draw
|
|
|
|
{
|
|
|
|
GrBackendTexture backend;
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2019-07-01 14:34:03 +00:00
|
|
|
params.setShouldCreateMipMaps(false);
|
2019-02-03 22:17:54 +00:00
|
|
|
params.setTextureable(false);
|
|
|
|
|
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
2018-02-04 19:33:21 +00:00
|
|
|
if (s) {
|
2019-02-03 22:17:54 +00:00
|
|
|
REPORTER_ASSERT(reporter, !s->draw(ddl.get())); // bc the DDL was made w/ textureability
|
2018-02-04 19:33:21 +00:00
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
context->flush();
|
|
|
|
gpu->testingOnly_flushGpuAndSync();
|
2018-02-04 19:33:21 +00:00
|
|
|
s = nullptr;
|
2018-03-09 14:33:19 +00:00
|
|
|
params.cleanUpBackEnd(context, backend);
|
2018-02-04 19:33:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 18:48:14 +00:00
|
|
|
// Make sure non-GPU-backed surfaces fail characterization
|
|
|
|
{
|
|
|
|
SkImageInfo ii = SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType);
|
|
|
|
|
|
|
|
sk_sp<SkSurface> rasterSurface = SkSurface::MakeRaster(ii);
|
|
|
|
SkSurfaceCharacterization c;
|
|
|
|
REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c));
|
|
|
|
}
|
2018-03-06 18:41:51 +00:00
|
|
|
|
|
|
|
// Exercise the createResized method
|
|
|
|
{
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
2018-03-06 18:41:51 +00:00
|
|
|
|
2019-02-03 22:17:54 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
2018-03-06 18:41:51 +00:00
|
|
|
if (!s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSurfaceCharacterization char0;
|
|
|
|
SkAssertResult(s->characterize(&char0));
|
|
|
|
|
|
|
|
// Too small
|
|
|
|
SkSurfaceCharacterization char1 = char0.createResized(-1, -1);
|
|
|
|
REPORTER_ASSERT(reporter, !char1.isValid());
|
|
|
|
|
|
|
|
// Too large
|
|
|
|
SkSurfaceCharacterization char2 = char0.createResized(1000000, 32);
|
|
|
|
REPORTER_ASSERT(reporter, !char2.isValid());
|
|
|
|
|
|
|
|
// Just right
|
|
|
|
SkSurfaceCharacterization char3 = char0.createResized(32, 32);
|
|
|
|
REPORTER_ASSERT(reporter, char3.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, 32 == char3.width());
|
|
|
|
REPORTER_ASSERT(reporter, 32 == char3.height());
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2018-03-06 18:41:51 +00:00
|
|
|
}
|
2019-10-03 15:09:17 +00:00
|
|
|
|
|
|
|
// Exercise the createColorSpace method
|
|
|
|
{
|
|
|
|
SurfaceParameters params(context);
|
|
|
|
GrBackendTexture backend;
|
|
|
|
|
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
|
|
|
if (!s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSurfaceCharacterization char0;
|
|
|
|
SkAssertResult(s->characterize(&char0));
|
|
|
|
|
|
|
|
// The default params create an sRGB color space
|
|
|
|
REPORTER_ASSERT(reporter, char0.colorSpace()->isSRGB());
|
|
|
|
REPORTER_ASSERT(reporter, !char0.colorSpace()->gammaIsLinear());
|
|
|
|
|
|
|
|
{
|
|
|
|
sk_sp<SkColorSpace> newCS = SkColorSpace::MakeSRGBLinear();
|
|
|
|
|
|
|
|
SkSurfaceCharacterization char1 = char0.createColorSpace(std::move(newCS));
|
|
|
|
REPORTER_ASSERT(reporter, char1.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, !char1.colorSpace()->isSRGB());
|
|
|
|
REPORTER_ASSERT(reporter, char1.colorSpace()->gammaIsLinear());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkSurfaceCharacterization char2 = char0.createColorSpace(nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, char2.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, !char2.colorSpace());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
sk_sp<SkColorSpace> newCS = SkColorSpace::MakeSRGBLinear();
|
|
|
|
|
|
|
|
SkSurfaceCharacterization invalid;
|
|
|
|
REPORTER_ASSERT(reporter, !invalid.isValid());
|
|
|
|
SkSurfaceCharacterization stillInvalid = invalid.createColorSpace(std::move(newCS));
|
|
|
|
REPORTER_ASSERT(reporter, !stillInvalid.isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
|
|
|
}
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 13:28:59 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
DDLSurfaceCharacterizationTestImpl(context, reporter);
|
|
|
|
}
|
|
|
|
|
2019-02-03 22:17:54 +00:00
|
|
|
// Test that a DDL created w/o textureability can be replayed into both a textureable and
|
|
|
|
// non-textureable destination. Note that DDLSurfaceCharacterizationTest tests that a
|
|
|
|
// textureable DDL cannot be played into a non-textureable destination but can be replayed
|
|
|
|
// into a textureable destination.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLNonTextureabilityTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2019-02-03 22:17:54 +00:00
|
|
|
|
|
|
|
// Create a bitmap that we can readback into
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(imageInfo);
|
|
|
|
|
|
|
|
for (bool textureability : { true, false }) {
|
|
|
|
std::unique_ptr<SkDeferredDisplayList> ddl;
|
|
|
|
|
2019-07-01 14:34:03 +00:00
|
|
|
// First, create a DDL w/o textureability (and thus no mipmaps). TODO: once we have
|
|
|
|
// reusable DDLs, move this outside of the loop.
|
2019-02-03 22:17:54 +00:00
|
|
|
{
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2019-07-01 14:34:03 +00:00
|
|
|
params.setShouldCreateMipMaps(false);
|
2019-02-03 22:17:54 +00:00
|
|
|
params.setTextureable(false);
|
|
|
|
|
|
|
|
ddl = params.createDDL(context);
|
|
|
|
SkAssertResult(ddl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then verify it can draw into either flavor of destination
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2019-07-01 14:34:03 +00:00
|
|
|
params.setShouldCreateMipMaps(textureability);
|
2019-02-03 22:17:54 +00:00
|
|
|
params.setTextureable(textureability);
|
|
|
|
|
|
|
|
GrBackendTexture backend;
|
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
|
|
|
if (!s) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl.get()));
|
|
|
|
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
|
|
|
|
context->flush();
|
|
|
|
gpu->testingOnly_flushGpuAndSync();
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
static void test_make_render_target(skiatest::Reporter* reporter,
|
|
|
|
GrContext* context,
|
|
|
|
const SurfaceParameters& params) {
|
|
|
|
{
|
|
|
|
const SkSurfaceCharacterization c = params.createCharacterization(context);
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
if (!c.isValid()) {
|
2019-06-24 17:25:42 +00:00
|
|
|
GrBackendTexture backend;
|
2019-02-03 22:17:54 +00:00
|
|
|
sk_sp<SkSurface> tmp = params.make(context, &backend);
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
// If we couldn't characterize the surface we shouldn't be able to create it either
|
|
|
|
REPORTER_ASSERT(reporter, !tmp);
|
|
|
|
if (tmp) {
|
|
|
|
tmp = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
|
|
|
}
|
2019-06-24 17:25:42 +00:00
|
|
|
return;
|
2018-04-03 21:17:05 +00:00
|
|
|
}
|
2019-06-24 17:25:42 +00:00
|
|
|
}
|
2018-03-30 17:57:00 +00:00
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
const SkSurfaceCharacterization c = params.createCharacterization(context);
|
|
|
|
GrBackendTexture backend;
|
|
|
|
|
|
|
|
{
|
2019-02-03 22:17:54 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
2019-06-24 17:25:42 +00:00
|
|
|
REPORTER_ASSERT(reporter, s);
|
2018-03-30 17:57:00 +00:00
|
|
|
if (!s) {
|
|
|
|
REPORTER_ASSERT(reporter, !c.isValid());
|
2019-06-24 17:25:42 +00:00
|
|
|
params.cleanUpBackEnd(context, backend);
|
|
|
|
return;
|
2018-03-30 17:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, c.isValid());
|
2019-07-01 14:34:03 +00:00
|
|
|
REPORTER_ASSERT(reporter, c.isCompatible(backend));
|
2019-06-25 18:47:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, s->isCompatible(c));
|
2019-06-24 17:25:42 +00:00
|
|
|
// Note that we're leaving 'backend' live here
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make an SkSurface from scratch
|
|
|
|
{
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
|
|
|
|
REPORTER_ASSERT(reporter, s);
|
2019-06-25 18:47:04 +00:00
|
|
|
REPORTER_ASSERT(reporter, s->isCompatible(c));
|
2019-06-24 17:25:42 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 21:58:27 +00:00
|
|
|
// Make an SkSurface that wraps the existing backend texture
|
|
|
|
{
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeFromBackendTexture(context, c, backend);
|
|
|
|
REPORTER_ASSERT(reporter, s);
|
|
|
|
REPORTER_ASSERT(reporter, s->isCompatible(c));
|
|
|
|
}
|
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
params.cleanUpBackEnd(context, backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// This tests the SkSurface::MakeRenderTarget variants that take an SkSurfaceCharacterization.
|
|
|
|
// In particular, the SkSurface, backendTexture and SkSurfaceCharacterization
|
|
|
|
// should always be compatible.
|
2019-07-10 13:28:59 +00:00
|
|
|
void DDLMakeRenderTargetTestImpl(GrContext* context, skiatest::Reporter* reporter) {
|
2019-06-24 17:25:42 +00:00
|
|
|
for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
|
2018-03-30 17:57:00 +00:00
|
|
|
|
2019-02-03 22:17:54 +00:00
|
|
|
if (SurfaceParameters::kFBO0Count == i) {
|
|
|
|
// MakeRenderTarget doesn't support FBO0
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-07-10 13:28:59 +00:00
|
|
|
if (SurfaceParameters::kProtectedCount == i) {
|
|
|
|
if (context->backend() != GrBackendApi::kVulkan) {
|
|
|
|
// Only the Vulkan backend respects the protected parameter
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
const GrVkCaps* vkCaps = (const GrVkCaps*) context->priv().caps();
|
|
|
|
|
|
|
|
// And, even then, only when it is a protected context
|
|
|
|
if (!vkCaps->supportsProtectedMemory()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SurfaceParameters params(context);
|
2019-06-24 17:25:42 +00:00
|
|
|
params.modify(i);
|
2018-03-30 17:57:00 +00:00
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
if (!context->priv().caps()->mipMapSupport()) {
|
|
|
|
params.setShouldCreateMipMaps(false);
|
|
|
|
}
|
2018-04-03 21:17:05 +00:00
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
test_make_render_target(reporter, context, params);
|
2018-03-30 17:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 13:28:59 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
DDLMakeRenderTargetTestImpl(context, reporter);
|
|
|
|
}
|
|
|
|
|
2018-03-30 17:57:00 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-01-23 21:38:14 +00:00
|
|
|
static constexpr int kSize = 8;
|
|
|
|
|
|
|
|
struct TextureReleaseChecker {
|
|
|
|
TextureReleaseChecker() : fReleaseCount(0) {}
|
|
|
|
int fReleaseCount;
|
|
|
|
static void Release(void* self) {
|
|
|
|
static_cast<TextureReleaseChecker*>(self)->fReleaseCount++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL };
|
|
|
|
|
|
|
|
// This tests the ability to create and use wrapped textures in a DDL world
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-05-17 14:01:21 +00:00
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture backendTex = context->createBackendTexture(
|
2019-06-04 11:16:10 +00:00
|
|
|
kSize, kSize, kRGBA_8888_SkColorType,
|
2019-07-01 19:04:06 +00:00
|
|
|
SkColors::kTransparent, GrMipMapped::kNo, GrRenderable::kNo, GrProtected::kNo);
|
2018-03-08 15:13:17 +00:00
|
|
|
if (!backendTex.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2019-02-03 22:17:54 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend);
|
2018-03-08 15:13:17 +00:00
|
|
|
if (!s) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2018-03-08 15:13:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2018-03-08 15:13:17 +00:00
|
|
|
SkSurfaceCharacterization c;
|
|
|
|
SkAssertResult(s->characterize(&c));
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2018-03-08 15:13:17 +00:00
|
|
|
std::unique_ptr<SkDeferredDisplayListRecorder> recorder(new SkDeferredDisplayListRecorder(c));
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2018-03-08 15:13:17 +00:00
|
|
|
SkCanvas* canvas = recorder->getCanvas();
|
|
|
|
if (!canvas) {
|
2018-04-03 21:17:05 +00:00
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2018-03-08 15:13:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2018-03-08 15:13:17 +00:00
|
|
|
GrContext* deferredContext = canvas->getGrContext();
|
|
|
|
if (!deferredContext) {
|
2018-04-03 21:17:05 +00:00
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2018-03-08 15:13:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2018-03-08 15:13:17 +00:00
|
|
|
// Wrapped Backend Textures are not supported in DDL
|
|
|
|
sk_sp<SkImage> image =
|
|
|
|
SkImage::MakeFromAdoptedTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, !image);
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2018-03-08 15:13:17 +00:00
|
|
|
TextureReleaseChecker releaseChecker;
|
|
|
|
image = SkImage::MakeFromTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr,
|
|
|
|
TextureReleaseChecker::Release, &releaseChecker);
|
|
|
|
REPORTER_ASSERT(reporter, !image);
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2018-01-23 21:38:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 17:20:56 +00:00
|
|
|
static sk_sp<SkPromiseImageTexture> dummy_fulfill_proc(void*) {
|
|
|
|
SkASSERT(0);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-15 20:53:06 +00:00
|
|
|
static void dummy_release_proc(void*) { SkASSERT(0); }
|
2019-01-30 17:20:56 +00:00
|
|
|
static void dummy_done_proc(void*) {}
|
2018-03-15 20:53:06 +00:00
|
|
|
|
2018-03-30 17:57:00 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-03-15 20:53:06 +00:00
|
|
|
// Test out the behavior of an invalid DDLRecorder
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLInvalidRecorder, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
{
|
|
|
|
SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization characterization;
|
|
|
|
SkAssertResult(s->characterize(&characterization));
|
|
|
|
|
|
|
|
// never calling getCanvas means the backing surface is never allocated
|
|
|
|
SkDeferredDisplayListRecorder recorder(characterization);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkSurfaceCharacterization invalid;
|
|
|
|
|
|
|
|
SkDeferredDisplayListRecorder recorder(invalid);
|
|
|
|
|
|
|
|
const SkSurfaceCharacterization c = recorder.characterization();
|
|
|
|
REPORTER_ASSERT(reporter, !c.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, !recorder.getCanvas());
|
|
|
|
REPORTER_ASSERT(reporter, !recorder.detach());
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
GrBackendFormat format = context->defaultBackendFormat(kRGBA_8888_SkColorType,
|
|
|
|
GrRenderable::kNo);
|
|
|
|
SkASSERT(format.isValid());
|
2019-02-12 18:38:44 +00:00
|
|
|
|
2019-01-30 22:28:20 +00:00
|
|
|
sk_sp<SkImage> image = recorder.makePromiseTexture(
|
|
|
|
format, 32, 32, GrMipMapped::kNo,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr,
|
|
|
|
dummy_fulfill_proc,
|
|
|
|
dummy_release_proc,
|
|
|
|
dummy_done_proc,
|
2019-03-08 18:28:46 +00:00
|
|
|
nullptr,
|
|
|
|
SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew);
|
2018-03-15 20:53:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, !image);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-30 17:57:00 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-03-16 12:48:24 +00:00
|
|
|
// Ensure that flushing while DDL recording doesn't cause a crash
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLFlushWhileRecording, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization characterization;
|
|
|
|
SkAssertResult(s->characterize(&characterization));
|
|
|
|
|
|
|
|
SkDeferredDisplayListRecorder recorder(characterization);
|
|
|
|
SkCanvas* canvas = recorder.getCanvas();
|
|
|
|
|
|
|
|
canvas->getGrContext()->flush();
|
|
|
|
}
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2019-05-07 17:29:22 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Test that flushing a DDL via SkSurface::flush works
|
|
|
|
|
|
|
|
struct FulfillInfo {
|
|
|
|
sk_sp<SkPromiseImageTexture> fTex;
|
|
|
|
bool fFulfilled = false;
|
|
|
|
bool fReleased = false;
|
|
|
|
bool fDone = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
static sk_sp<SkPromiseImageTexture> tracking_fulfill_proc(void* context) {
|
|
|
|
FulfillInfo* info = (FulfillInfo*) context;
|
|
|
|
info->fFulfilled = true;
|
|
|
|
return info->fTex;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tracking_release_proc(void* context) {
|
|
|
|
FulfillInfo* info = (FulfillInfo*) context;
|
|
|
|
info->fReleased = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tracking_done_proc(void* context) {
|
|
|
|
FulfillInfo* info = (FulfillInfo*) context;
|
|
|
|
info->fDone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSkSurfaceFlush, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization characterization;
|
|
|
|
SkAssertResult(s->characterize(&characterization));
|
|
|
|
|
|
|
|
GrBackendTexture backendTexture;
|
|
|
|
|
2019-11-06 17:19:30 +00:00
|
|
|
if (!CreateBackendTexture(context, &backendTexture, ii, SkColors::kCyan, GrMipMapped::kNo,
|
|
|
|
GrRenderable::kNo)) {
|
2019-05-07 17:29:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FulfillInfo fulfillInfo;
|
|
|
|
fulfillInfo.fTex = SkPromiseImageTexture::Make(backendTexture);
|
|
|
|
|
|
|
|
std::unique_ptr<SkDeferredDisplayList> ddl;
|
|
|
|
|
|
|
|
{
|
|
|
|
SkDeferredDisplayListRecorder recorder(characterization);
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
GrBackendFormat format = context->defaultBackendFormat(kRGBA_8888_SkColorType,
|
|
|
|
GrRenderable::kNo);
|
|
|
|
SkASSERT(format.isValid());
|
2019-05-07 17:29:22 +00:00
|
|
|
|
|
|
|
sk_sp<SkImage> promiseImage = recorder.makePromiseTexture(
|
|
|
|
format, 32, 32, GrMipMapped::kNo,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr,
|
|
|
|
tracking_fulfill_proc,
|
|
|
|
tracking_release_proc,
|
|
|
|
tracking_done_proc,
|
|
|
|
&fulfillInfo,
|
|
|
|
SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew);
|
|
|
|
|
|
|
|
SkCanvas* canvas = recorder.getCanvas();
|
|
|
|
|
|
|
|
canvas->clear(SK_ColorRED);
|
|
|
|
canvas->drawImage(promiseImage, 0, 0);
|
|
|
|
ddl = recorder.detach();
|
|
|
|
}
|
|
|
|
|
2019-05-07 20:54:48 +00:00
|
|
|
context->flush();
|
|
|
|
|
2019-05-07 17:29:22 +00:00
|
|
|
s->draw(ddl.get());
|
|
|
|
|
|
|
|
GrFlushInfo flushInfo;
|
2019-05-07 19:57:25 +00:00
|
|
|
s->flush(SkSurface::BackendSurfaceAccess::kPresent, flushInfo);
|
2019-05-07 17:29:22 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, fulfillInfo.fFulfilled);
|
|
|
|
REPORTER_ASSERT(reporter, fulfillInfo.fReleased);
|
|
|
|
|
2019-05-07 19:57:25 +00:00
|
|
|
if (GrBackendApi::kVulkan == context->backend() ||
|
|
|
|
GrBackendApi::kMetal == context->backend()) {
|
2019-05-07 20:54:48 +00:00
|
|
|
// In order to receive the done callback with Vulkan we need to perform the equivalent
|
2019-05-07 17:29:22 +00:00
|
|
|
// of a glFinish
|
|
|
|
GrFlushInfo flushInfoSyncCpu;
|
|
|
|
flushInfoSyncCpu.fFlags = kSyncCpu_GrFlushFlag;
|
2019-05-07 19:57:25 +00:00
|
|
|
s->flush(SkSurface::BackendSurfaceAccess::kPresent, flushInfoSyncCpu);
|
2019-05-07 17:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, fulfillInfo.fDone);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, fulfillInfo.fTex->unique());
|
|
|
|
fulfillInfo.fTex.reset();
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
DeleteBackendTexture(context, backendTexture);
|
2019-05-07 17:29:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 13:29:09 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Ensure that reusing a single DDLRecorder to create multiple DDLs works cleanly
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMultipleDDLs, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(ii);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization characterization;
|
|
|
|
SkAssertResult(s->characterize(&characterization));
|
|
|
|
|
|
|
|
SkDeferredDisplayListRecorder recorder(characterization);
|
|
|
|
|
|
|
|
SkCanvas* canvas1 = recorder.getCanvas();
|
|
|
|
|
|
|
|
canvas1->clear(SK_ColorRED);
|
|
|
|
|
|
|
|
canvas1->save();
|
|
|
|
canvas1->clipRect(SkRect::MakeXYWH(8, 8, 16, 16));
|
|
|
|
|
|
|
|
std::unique_ptr<SkDeferredDisplayList> ddl1 = recorder.detach();
|
|
|
|
|
|
|
|
SkCanvas* canvas2 = recorder.getCanvas();
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorGREEN);
|
|
|
|
canvas2->drawRect(SkRect::MakeWH(32, 32), p);
|
|
|
|
|
|
|
|
std::unique_ptr<SkDeferredDisplayList> ddl2 = recorder.detach();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData());
|
|
|
|
REPORTER_ASSERT(reporter, ddl2->priv().lazyProxyData());
|
|
|
|
|
|
|
|
// The lazy proxy data being different ensures that the SkSurface, SkCanvas and backing-
|
|
|
|
// lazy proxy are all different between the two DDLs
|
|
|
|
REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData() != ddl2->priv().lazyProxyData());
|
|
|
|
|
|
|
|
s->draw(ddl1.get());
|
|
|
|
s->draw(ddl2.get());
|
|
|
|
|
|
|
|
// Make sure the clipRect from DDL1 didn't percolate into DDL2
|
|
|
|
s->readPixels(ii, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
|
|
|
|
for (int y = 0; y < 32; ++y) {
|
|
|
|
for (int x = 0; x < 32; ++x) {
|
|
|
|
REPORTER_ASSERT(reporter, bitmap.getColor(x, y) == SK_ColorGREEN);
|
|
|
|
if (bitmap.getColor(x, y) != SK_ColorGREEN) {
|
|
|
|
return; // we only really need to report the error once
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 21:18:15 +00:00
|
|
|
#ifdef SK_GL
|
2018-03-30 17:57:00 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-03-21 16:13:37 +00:00
|
|
|
// Check that the texture-specific flags (i.e., for external & rectangle textures) work
|
|
|
|
// for promise images. As such, this is a GL-only test.
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization characterization;
|
|
|
|
SkAssertResult(s->characterize(&characterization));
|
|
|
|
|
|
|
|
SkDeferredDisplayListRecorder recorder(characterization);
|
|
|
|
|
|
|
|
for (GrGLenum target : { GR_GL_TEXTURE_EXTERNAL, GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_2D } ) {
|
2018-06-08 22:11:51 +00:00
|
|
|
for (auto mipMapped : { GrMipMapped::kNo, GrMipMapped::kYes }) {
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, target);
|
|
|
|
|
2019-01-30 22:28:20 +00:00
|
|
|
sk_sp<SkImage> image = recorder.makePromiseTexture(
|
|
|
|
format, 32, 32, mipMapped,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr,
|
|
|
|
dummy_fulfill_proc,
|
|
|
|
dummy_release_proc,
|
|
|
|
dummy_done_proc,
|
2019-03-08 18:28:46 +00:00
|
|
|
nullptr,
|
|
|
|
SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew);
|
2018-06-08 22:11:51 +00:00
|
|
|
if (GR_GL_TEXTURE_2D != target && mipMapped == GrMipMapped::kYes) {
|
|
|
|
REPORTER_ASSERT(reporter, !image);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, image);
|
2018-06-07 20:11:27 +00:00
|
|
|
|
2018-10-12 19:00:20 +00:00
|
|
|
GrTextureProxy* backingProxy = ((SkImage_GpuBase*) image.get())->peekProxy();
|
2018-06-08 22:01:16 +00:00
|
|
|
|
2018-06-08 22:11:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, backingProxy->mipMapped() == mipMapped);
|
|
|
|
if (GR_GL_TEXTURE_2D == target) {
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, !backingProxy->hasRestrictedSampling());
|
2018-06-08 22:11:51 +00:00
|
|
|
} else {
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, backingProxy->hasRestrictedSampling());
|
2018-06-08 22:11:51 +00:00
|
|
|
}
|
2018-03-21 16:13:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-03 21:17:05 +00:00
|
|
|
}
|
2019-11-08 21:18:15 +00:00
|
|
|
#endif // SK_GL
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2018-09-25 13:31:10 +00:00
|
|
|
// Test colorType and pixelConfig compatibility.
|
2018-04-03 21:17:05 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLCompatibilityTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
|
|
|
|
SkColorType colorType = static_cast<SkColorType>(ct);
|
|
|
|
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params(context);
|
2019-02-12 18:38:44 +00:00
|
|
|
params.setColorType(colorType);
|
|
|
|
params.setColorSpace(nullptr);
|
2018-04-03 21:17:05 +00:00
|
|
|
|
2019-05-09 20:28:04 +00:00
|
|
|
if (!context->priv().caps()->mipMapSupport()) {
|
|
|
|
params.setShouldCreateMipMaps(false);
|
|
|
|
}
|
2019-02-12 18:38:44 +00:00
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
test_make_render_target(reporter, context, params);
|
2018-04-03 21:17:05 +00:00
|
|
|
}
|
2018-03-21 16:13:37 +00:00
|
|
|
|
|
|
|
}
|