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"
|
2020-02-21 19:24:40 +00:00
|
|
|
#include "include/core/SkDeferredDisplayList.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#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"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/gpu/GrContextThreadSafeProxy.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-07-20 14:56:01 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.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 "src/core/SkDeferredDisplayListPriv.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
2020-07-20 14:56:01 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.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/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"
|
2020-10-08 20:00:14 +00:00
|
|
|
#include "tools/gpu/BackendSurfaceFactory.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.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"
|
2020-11-04 15:50:39 +00:00
|
|
|
#include "src/gpu/vk/GrVkSecondaryCBDrawContext.h"
|
2019-07-10 13:28:59 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-04 17:52:46 +00:00
|
|
|
class SurfaceParameters {
|
|
|
|
public:
|
2020-11-04 15:50:39 +00:00
|
|
|
static const int kNumParams = 13;
|
2019-07-10 13:28:59 +00:00
|
|
|
static const int kFBO0Count = 9;
|
2020-11-04 15:50:39 +00:00
|
|
|
static const int kVkSCBCount = 12;
|
2019-07-10 13:28:59 +00:00
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
SurfaceParameters(GrRecordingContext* rContext)
|
|
|
|
: fBackend(rContext->backend())
|
2020-10-08 20:00:14 +00:00
|
|
|
, fCanBeProtected(false)
|
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)
|
2020-08-27 18:29:00 +00:00
|
|
|
, fIsProtected(GrProtected::kNo)
|
2020-11-04 15:50:39 +00:00
|
|
|
, fVkRTSupportsInputAttachment(false)
|
|
|
|
, fForVulkanSecondaryCommandBuffer(false) {
|
2019-07-10 13:28:59 +00:00
|
|
|
#ifdef SK_VULKAN
|
2020-10-08 20:00:14 +00:00
|
|
|
if (rContext->backend() == GrBackendApi::kVulkan) {
|
|
|
|
auto vkCaps = static_cast<const GrVkCaps*>(rContext->priv().caps());
|
|
|
|
fCanBeProtected = vkCaps->supportsProtectedMemory();
|
|
|
|
if (fCanBeProtected) {
|
|
|
|
fIsProtected = GrProtected::kYes;
|
|
|
|
}
|
2019-07-10 13:28:59 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-10-08 20:00:14 +00:00
|
|
|
if (!rContext->priv().caps()->mipmapSupport()) {
|
|
|
|
fShouldCreateMipMaps = false;
|
|
|
|
}
|
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); }
|
2020-10-08 20:00:14 +00:00
|
|
|
void disableTextureability() {
|
|
|
|
fIsTextureable = false;
|
|
|
|
fShouldCreateMipMaps = false;
|
|
|
|
}
|
2019-05-09 20:28:04 +00:00
|
|
|
void setShouldCreateMipMaps(bool shouldCreateMipMaps) {
|
|
|
|
fShouldCreateMipMaps = shouldCreateMipMaps;
|
|
|
|
}
|
2020-08-27 18:29:00 +00:00
|
|
|
void setVkRTInputAttachmentSupport(bool inputSupport) {
|
|
|
|
fVkRTSupportsInputAttachment = inputSupport;
|
|
|
|
}
|
2020-11-04 15:50:39 +00:00
|
|
|
void setForVulkanSecondaryCommandBuffer(bool forVkSCB) {
|
|
|
|
fForVulkanSecondaryCommandBuffer = forVkSCB;
|
|
|
|
}
|
2018-04-03 21:17:05 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
// Modify the SurfaceParameters in just one way. Returns false if the requested modification had
|
|
|
|
// no effect.
|
|
|
|
bool modify(int i) {
|
|
|
|
bool changed = false;
|
|
|
|
auto set = [&changed](auto& var, auto value) {
|
|
|
|
if (var != value) {
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
var = value;
|
|
|
|
};
|
2017-12-04 17:52:46 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fWidth, 63);
|
2017-12-04 17:52:46 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fHeight, 63);
|
2017-12-04 17:52:46 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fOrigin, kBottomLeft_GrSurfaceOrigin);
|
2017-12-04 17:52:46 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fColorType, kRGBA_F16_SkColorType);
|
2017-12-04 17:52:46 +00:00
|
|
|
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.
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fColorSpace, SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
|
|
|
|
SkNamedGamut::kAdobeRGB));
|
2017-12-04 17:52:46 +00:00
|
|
|
break;
|
2020-10-08 20:00:14 +00:00
|
|
|
case 5:
|
|
|
|
set(fSampleCount, 4);
|
2017-12-04 17:52:46 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fSurfaceProps, SkSurfaceProps(0x0, kRGB_H_SkPixelGeometry));
|
2017-12-04 17:52:46 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fSurfaceProps, SkSurfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
|
|
|
|
kUnknown_SkPixelGeometry));
|
2017-12-04 17:52:46 +00:00
|
|
|
break;
|
2018-02-04 19:33:21 +00:00
|
|
|
case 8:
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fShouldCreateMipMaps, false);
|
2018-02-04 19:33:21 +00:00
|
|
|
break;
|
2019-02-03 22:17:54 +00:00
|
|
|
case 9:
|
|
|
|
if (GrBackendApi::kOpenGL == fBackend) {
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fUsesGLFBO0, true);
|
|
|
|
set(fShouldCreateMipMaps, false); // needs to changed in tandem w/ textureability
|
|
|
|
set(fIsTextureable, false);
|
2019-02-03 22:17:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 10:
|
2020-10-08 20:00:14 +00:00
|
|
|
set(fShouldCreateMipMaps, false); // needs to changed in tandem w/ textureability
|
|
|
|
set(fIsTextureable, false);
|
2019-02-03 22:17:54 +00:00
|
|
|
break;
|
2019-07-10 13:28:59 +00:00
|
|
|
case 11:
|
2020-10-08 20:00:14 +00:00
|
|
|
if (fCanBeProtected) {
|
|
|
|
set(fIsProtected, GrProtected(!static_cast<bool>(fIsProtected)));
|
|
|
|
}
|
2019-07-10 13:28:59 +00:00
|
|
|
break;
|
2020-11-04 15:50:39 +00:00
|
|
|
case 12:
|
|
|
|
if (GrBackendApi::kVulkan == fBackend) {
|
|
|
|
set(fForVulkanSecondaryCommandBuffer, true);
|
|
|
|
set(fUsesGLFBO0, false);
|
|
|
|
set(fShouldCreateMipMaps, false); // needs to changed in tandem w/ textureability
|
|
|
|
set(fIsTextureable, false);
|
|
|
|
set(fVkRTSupportsInputAttachment, false);
|
|
|
|
}
|
|
|
|
break;
|
2018-02-04 19:33:21 +00:00
|
|
|
}
|
2020-10-08 20:00:14 +00:00
|
|
|
return changed;
|
2018-02-04 19:33:21 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
SkSurfaceCharacterization createCharacterization(GrDirectContext* dContext) const {
|
|
|
|
size_t maxResourceBytes = dContext->getResourceCacheLimit();
|
2018-02-13 22:03:00 +00:00
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
if (!dContext->colorTypeSupportedAsSurface(fColorType)) {
|
2019-09-04 19:05:35 +00:00
|
|
|
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);
|
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
GrBackendFormat backendFormat = dContext->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
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
SkSurfaceCharacterization c = dContext->threadSafeProxy()->createCharacterization(
|
2018-02-13 22:03:00 +00:00
|
|
|
maxResourceBytes, ii, backendFormat, fSampleCount,
|
2019-02-03 22:17:54 +00:00
|
|
|
fOrigin, fSurfaceProps, fShouldCreateMipMaps,
|
2020-08-27 18:29:00 +00:00
|
|
|
fUsesGLFBO0, fIsTextureable, fIsProtected,
|
2020-11-04 15:50:39 +00:00
|
|
|
fVkRTSupportsInputAttachment,
|
|
|
|
fForVulkanSecondaryCommandBuffer);
|
2018-03-30 17:57:00 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a DDL whose characterization captures the current settings
|
2020-07-20 14:56:01 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> createDDL(GrDirectContext* dContext) const {
|
|
|
|
SkSurfaceCharacterization c = this->createCharacterization(dContext);
|
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
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> make(GrDirectContext* dContext) const {
|
2020-07-20 14:56:01 +00:00
|
|
|
const SkSurfaceCharacterization c = this->createCharacterization(dContext);
|
2019-06-24 17:25:42 +00:00
|
|
|
|
2019-09-25 21:14:35 +00:00
|
|
|
#ifdef SK_GL
|
2019-02-03 22:17:54 +00:00
|
|
|
if (fUsesGLFBO0) {
|
2020-07-20 14:56:01 +00:00
|
|
|
if (GrBackendApi::kOpenGL != dContext->backend()) {
|
2019-02-03 22:17:54 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
sk_sp<SkSurface> result = SkSurface::MakeFromBackendRenderTarget(dContext, backendRT,
|
2019-06-24 17:25:42 +00:00
|
|
|
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-07-01 14:34:03 +00:00
|
|
|
|
2020-11-04 15:50:39 +00:00
|
|
|
// We can't make SkSurfaces for vulkan secondary command buffers.
|
|
|
|
if (fForVulkanSecondaryCommandBuffer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
sk_sp<SkSurface> surface;
|
2020-10-08 20:00:14 +00:00
|
|
|
if (fIsTextureable) {
|
|
|
|
surface = sk_gpu_test::MakeBackendTextureSurface(dContext,
|
|
|
|
{fWidth, fHeight},
|
|
|
|
fOrigin,
|
|
|
|
fSampleCount,
|
|
|
|
fColorType,
|
|
|
|
fColorSpace,
|
|
|
|
GrMipmapped(fShouldCreateMipMaps),
|
|
|
|
fIsProtected,
|
|
|
|
&fSurfaceProps);
|
2018-04-03 21:17:05 +00:00
|
|
|
} else {
|
2020-10-08 20:00:14 +00:00
|
|
|
// Create a surface w/ the current parameters but make it non-textureable
|
|
|
|
SkASSERT(!fShouldCreateMipMaps);
|
|
|
|
surface = sk_gpu_test::MakeBackendRenderTargetSurface(dContext,
|
|
|
|
{fWidth, fHeight},
|
|
|
|
fOrigin,
|
|
|
|
fSampleCount,
|
|
|
|
fColorType,
|
|
|
|
fColorSpace,
|
|
|
|
fIsProtected,
|
|
|
|
&fSurfaceProps);
|
2018-04-03 21:17:05 +00:00
|
|
|
}
|
2018-02-04 19:33:21 +00:00
|
|
|
|
|
|
|
if (!surface) {
|
2019-07-01 14:34:03 +00:00
|
|
|
SkASSERT(!c.isValid());
|
2018-02-04 19:33:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
GrBackendTexture texture =
|
|
|
|
surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
if (texture.isValid()) {
|
|
|
|
SkASSERT(c.isCompatible(texture));
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-04 15:50:39 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
sk_sp<GrVkSecondaryCBDrawContext> makeVkSCB(GrDirectContext* dContext) {
|
|
|
|
const SkSurfaceCharacterization c = this->createCharacterization(dContext);
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::Make({fWidth, fHeight},
|
|
|
|
{fColorType, kPremul_SkAlphaType, fColorSpace});
|
|
|
|
GrVkDrawableInfo vkInfo;
|
2021-06-16 19:28:00 +00:00
|
|
|
// putting in a bunch of placeholder values here
|
2020-11-04 15:50:39 +00:00
|
|
|
vkInfo.fSecondaryCommandBuffer = (VkCommandBuffer)1;
|
|
|
|
vkInfo.fColorAttachmentIndex = 0;
|
|
|
|
vkInfo.fCompatibleRenderPass = (VkRenderPass)1;
|
|
|
|
vkInfo.fFormat = VK_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
vkInfo.fDrawBounds = nullptr;
|
|
|
|
vkInfo.fImage = (VkImage)1;
|
|
|
|
|
|
|
|
return GrVkSecondaryCBDrawContext::Make(dContext, imageInfo, vkInfo, &fSurfaceProps);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-12-04 17:52:46 +00:00
|
|
|
private:
|
2019-02-03 22:17:54 +00:00
|
|
|
GrBackendApi fBackend;
|
2020-10-08 20:00:14 +00:00
|
|
|
bool fCanBeProtected;
|
|
|
|
|
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;
|
2020-08-27 18:29:00 +00:00
|
|
|
bool fVkRTSupportsInputAttachment;
|
2020-11-04 15:50:39 +00:00
|
|
|
bool fForVulkanSecondaryCommandBuffer;
|
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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2018-04-04 15:12:39 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
for (int i = -1; i < SurfaceParameters::kNumParams; ++i) {
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params1(context);
|
2020-10-08 20:00:14 +00:00
|
|
|
bool didModify1 = i >= 0 && params1.modify(i);
|
2018-04-04 15:12:39 +00:00
|
|
|
|
|
|
|
SkSurfaceCharacterization char1 = params1.createCharacterization(context);
|
|
|
|
if (!char1.isValid()) {
|
|
|
|
continue; // can happen on some platforms (ChromeOS)
|
|
|
|
}
|
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
for (int j = -1; j < SurfaceParameters::kNumParams; ++j) {
|
2019-07-10 13:28:59 +00:00
|
|
|
SurfaceParameters params2(context);
|
2020-10-08 20:00:14 +00:00
|
|
|
bool didModify2 = j >= 0 && params2.modify(j);
|
2018-04-04 15:12:39 +00:00
|
|
|
|
|
|
|
SkSurfaceCharacterization char2 = params2.createCharacterization(context);
|
|
|
|
if (!char2.isValid()) {
|
|
|
|
continue; // can happen on some platforms (ChromeOS)
|
|
|
|
}
|
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
if (i == j || (!didModify1 && !didModify2)) {
|
2018-04-04 15:12:39 +00:00
|
|
|
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
|
2020-07-20 14:56:01 +00:00
|
|
|
void DDLSurfaceCharacterizationTestImpl(GrDirectContext* dContext, skiatest::Reporter* reporter) {
|
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);
|
|
|
|
|
2020-06-29 14:00:08 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl;
|
2017-12-04 17:52:46 +00:00
|
|
|
|
|
|
|
// First, create a DDL using the stock SkSurface parameters
|
|
|
|
{
|
2020-07-20 14:56:01 +00:00
|
|
|
SurfaceParameters params(dContext);
|
2020-08-27 18:29:00 +00:00
|
|
|
if (dContext->backend() == GrBackendApi::kVulkan) {
|
|
|
|
params.setVkRTInputAttachmentSupport(true);
|
|
|
|
}
|
2020-07-20 14:56:01 +00:00
|
|
|
ddl = params.createDDL(dContext);
|
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
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
2017-12-04 17:52:46 +00:00
|
|
|
if (!s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-24 17:45:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl));
|
2018-02-01 20:14:55 +00:00
|
|
|
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
|
2020-10-08 20:00:14 +00:00
|
|
|
|
|
|
|
dContext->flush();
|
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) {
|
2020-07-20 14:56:01 +00:00
|
|
|
SurfaceParameters params(dContext);
|
2020-10-08 20:00:14 +00:00
|
|
|
if (!params.modify(i)) {
|
2018-02-04 19:33:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
|
|
|
if (!s) {
|
2019-02-03 22:17:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-24 17:45:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !s->draw(ddl),
|
2018-02-04 19:33:21 +00:00
|
|
|
"DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
|
2020-10-08 20:00:14 +00:00
|
|
|
dContext->flush();
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
2017-12-04 18:48:14 +00:00
|
|
|
|
|
|
|
// Next test the compatibility of resource cache parameters
|
|
|
|
{
|
2020-07-20 14:56:01 +00:00
|
|
|
const SurfaceParameters params(dContext);
|
2018-04-03 21:17:05 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
2017-12-04 18:48:14 +00:00
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
size_t maxResourceBytes = dContext->getResourceCacheLimit();
|
2017-12-04 18:48:14 +00:00
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
dContext->setResourceCacheLimit(maxResourceBytes/2);
|
2020-06-24 17:45:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !s->draw(ddl));
|
2017-12-04 18:48:14 +00:00
|
|
|
|
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);
|
2020-06-24 17:45:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl));
|
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);
|
2020-06-24 17:45:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl));
|
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);
|
2020-06-24 17:45:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl));
|
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
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
dContext->flush();
|
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
|
|
|
|
{
|
2020-07-20 14:56:01 +00:00
|
|
|
SurfaceParameters params(dContext);
|
2020-10-08 20:00:14 +00:00
|
|
|
params.disableTextureability();
|
2019-02-03 22:17:54 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
2018-02-04 19:33:21 +00:00
|
|
|
if (s) {
|
2020-06-24 17:45:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !s->draw(ddl)); // bc the DDL was made w/ textureability
|
2018-02-04 19:33:21 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
dContext->flush();
|
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
|
|
|
|
{
|
2020-07-20 14:56:01 +00:00
|
|
|
SurfaceParameters params(dContext);
|
2018-03-06 18:41:51 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
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());
|
|
|
|
}
|
2019-10-03 15:09:17 +00:00
|
|
|
|
|
|
|
// Exercise the createColorSpace method
|
|
|
|
{
|
2020-07-20 14:56:01 +00:00
|
|
|
SurfaceParameters params(dContext);
|
2019-10-03 15:09:17 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
2019-10-03 15:09:17 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 18:24:47 +00:00
|
|
|
|
|
|
|
// Exercise the createBackendFormat method
|
|
|
|
{
|
2020-07-20 14:56:01 +00:00
|
|
|
SurfaceParameters params(dContext);
|
2020-02-13 18:24:47 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
2020-02-13 18:24:47 +00:00
|
|
|
if (!s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSurfaceCharacterization char0;
|
|
|
|
SkAssertResult(s->characterize(&char0));
|
|
|
|
|
|
|
|
// The default params create a renderable RGBA8 surface
|
2020-07-20 14:56:01 +00:00
|
|
|
auto originalBackendFormat = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
|
|
|
|
GrRenderable::kYes);
|
2020-02-13 18:24:47 +00:00
|
|
|
REPORTER_ASSERT(reporter, originalBackendFormat.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, char0.backendFormat() == originalBackendFormat);
|
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
auto newBackendFormat = dContext->defaultBackendFormat(kRGB_565_SkColorType,
|
|
|
|
GrRenderable::kYes);
|
2020-02-13 18:24:47 +00:00
|
|
|
|
|
|
|
if (newBackendFormat.isValid()) {
|
|
|
|
SkSurfaceCharacterization char1 = char0.createBackendFormat(kRGB_565_SkColorType,
|
|
|
|
newBackendFormat);
|
|
|
|
REPORTER_ASSERT(reporter, char1.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, char1.backendFormat() == newBackendFormat);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization invalid;
|
|
|
|
REPORTER_ASSERT(reporter, !invalid.isValid());
|
|
|
|
auto stillInvalid = invalid.createBackendFormat(kRGB_565_SkColorType,
|
|
|
|
newBackendFormat);
|
|
|
|
REPORTER_ASSERT(reporter, !stillInvalid.isValid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exercise the createFBO0 method
|
2020-07-20 14:56:01 +00:00
|
|
|
if (dContext->backend() == GrBackendApi::kOpenGL) {
|
|
|
|
SurfaceParameters params(dContext);
|
2020-08-27 18:29:00 +00:00
|
|
|
// If the original characterization is textureable then we will fail trying to make an
|
|
|
|
// FBO0 characterization
|
2020-10-08 20:00:14 +00:00
|
|
|
params.disableTextureability();
|
2020-02-13 18:24:47 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
2020-02-13 18:24:47 +00:00
|
|
|
if (!s) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSurfaceCharacterization char0;
|
|
|
|
SkAssertResult(s->characterize(&char0));
|
|
|
|
|
|
|
|
// The default params create a non-FBO0 surface
|
|
|
|
REPORTER_ASSERT(reporter, !char0.usesGLFBO0());
|
|
|
|
|
|
|
|
{
|
|
|
|
SkSurfaceCharacterization char1 = char0.createFBO0(true);
|
|
|
|
REPORTER_ASSERT(reporter, char1.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, char1.usesGLFBO0());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkSurfaceCharacterization invalid;
|
|
|
|
REPORTER_ASSERT(reporter, !invalid.isValid());
|
|
|
|
SkSurfaceCharacterization stillInvalid = invalid.createFBO0(true);
|
|
|
|
REPORTER_ASSERT(reporter, !stillInvalid.isValid());
|
|
|
|
}
|
|
|
|
}
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 16:16:39 +00:00
|
|
|
#ifdef SK_GL
|
|
|
|
|
|
|
|
// Test out the surface compatibility checks regarding FBO0-ness. This test constructs
|
|
|
|
// two parallel arrays of characterizations and surfaces in the order:
|
|
|
|
// FBO0 w/ MSAA, FBO0 w/o MSAA, not-FBO0 w/ MSAA, not-FBO0 w/o MSAA
|
|
|
|
// and then tries all sixteen combinations to check the expected compatibility.
|
|
|
|
// Note: this is a GL-only test
|
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(CharacterizationFBO0nessTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2020-03-05 16:16:39 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
sk_sp<GrContextThreadSafeProxy> proxy = context->threadSafeProxy();
|
|
|
|
const size_t resourceCacheLimit = context->getResourceCacheLimit();
|
|
|
|
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
int availableSamples = caps->getRenderTargetSampleCount(4, format);
|
|
|
|
if (availableSamples <= 1) {
|
|
|
|
// This context doesn't support MSAA for RGBA8
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make({ 128, 128 }, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
|
|
|
static constexpr int kStencilBits = 8;
|
|
|
|
static constexpr bool kNotMipMapped = false;
|
|
|
|
static constexpr bool kNotTextureable = false;
|
|
|
|
const SkSurfaceProps surfaceProps(0x0, kRGB_H_SkPixelGeometry);
|
|
|
|
|
2020-03-05 18:21:12 +00:00
|
|
|
// Rows are characterizations and columns are surfaces
|
2020-03-05 16:16:39 +00:00
|
|
|
static const bool kExpectedCompatibility[4][4] = {
|
2020-03-05 18:21:12 +00:00
|
|
|
// FBO0 & MSAA, FBO0 & not-MSAA, not-FBO0 & MSAA, not-FBO0 & not-MSAA
|
|
|
|
/* FBO0 & MSAA */ { true, false, false, false },
|
|
|
|
/* FBO0 & not-MSAA */ { false, true, false, true },
|
|
|
|
/* not-FBO0 & MSAA */ { false, false, true, false },
|
|
|
|
/* not-FBO0 & not- */ { false, false, false, true }
|
2020-03-05 16:16:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkSurfaceCharacterization characterizations[4];
|
|
|
|
sk_sp<SkSurface> surfaces[4];
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
for (bool isFBO0 : { true, false }) {
|
|
|
|
for (int numSamples : { availableSamples, 1 }) {
|
|
|
|
characterizations[index] = proxy->createCharacterization(resourceCacheLimit,
|
|
|
|
ii, format, numSamples,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
surfaceProps, kNotMipMapped,
|
|
|
|
isFBO0, kNotTextureable);
|
|
|
|
SkASSERT(characterizations[index].sampleCount() == numSamples);
|
|
|
|
SkASSERT(characterizations[index].usesGLFBO0() == isFBO0);
|
|
|
|
|
|
|
|
GrGLFramebufferInfo fboInfo{ isFBO0 ? 0 : (GrGLuint) 1, GR_GL_RGBA8 };
|
|
|
|
GrBackendRenderTarget backendRT(128, 128, numSamples, kStencilBits, fboInfo);
|
|
|
|
SkAssertResult(backendRT.isValid());
|
|
|
|
|
|
|
|
surfaces[index] = SkSurface::MakeFromBackendRenderTarget(context, backendRT,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
nullptr, &surfaceProps);
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 18:21:12 +00:00
|
|
|
for (int c = 0; c < 4; ++c) {
|
|
|
|
for (int s = 0; s < 4; ++s) {
|
2020-03-05 16:16:39 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
2020-03-05 18:21:12 +00:00
|
|
|
kExpectedCompatibility[c][s] ==
|
|
|
|
surfaces[s]->isCompatible(characterizations[c]));
|
2020-03-05 16:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-11-04 15:50:39 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(CharacterizationVkSCBnessTest, reporter, ctxInfo) {
|
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
|
|
|
|
SurfaceParameters params(dContext);
|
|
|
|
params.modify(SurfaceParameters::kVkSCBCount);
|
|
|
|
SkSurfaceCharacterization characterization = params.createCharacterization(dContext);
|
|
|
|
REPORTER_ASSERT(reporter, characterization.isValid());
|
|
|
|
|
|
|
|
sk_sp<SkDeferredDisplayList> ddl = params.createDDL(dContext);
|
|
|
|
REPORTER_ASSERT(reporter, ddl.get());
|
|
|
|
|
|
|
|
sk_sp<GrVkSecondaryCBDrawContext> scbDrawContext = params.makeVkSCB(dContext);
|
|
|
|
REPORTER_ASSERT(reporter, scbDrawContext->isCompatible(characterization));
|
|
|
|
|
|
|
|
scbDrawContext->releaseResources();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-10 13:28:59 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-07-10 13:28:59 +00:00
|
|
|
|
|
|
|
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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
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 }) {
|
2020-06-29 14:00:08 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl;
|
2019-02-03 22:17:54 +00:00
|
|
|
|
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);
|
2020-10-08 20:00:14 +00:00
|
|
|
params.disableTextureability();
|
2020-08-27 18:29:00 +00:00
|
|
|
if (context->backend() == GrBackendApi::kVulkan) {
|
|
|
|
params.setVkRTInputAttachmentSupport(true);
|
|
|
|
}
|
2019-02-03 22:17:54 +00:00
|
|
|
|
|
|
|
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);
|
2020-10-08 20:00:14 +00:00
|
|
|
if (!textureability) {
|
|
|
|
params.disableTextureability();
|
|
|
|
}
|
2020-08-27 18:29:00 +00:00
|
|
|
if (context->backend() == GrBackendApi::kVulkan) {
|
|
|
|
params.setVkRTInputAttachmentSupport(true);
|
|
|
|
}
|
2019-02-03 22:17:54 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context);
|
2019-02-03 22:17:54 +00:00
|
|
|
if (!s) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-24 17:45:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, s->draw(ddl));
|
2019-02-03 22:17:54 +00:00
|
|
|
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
|
2020-10-08 20:00:14 +00:00
|
|
|
|
|
|
|
context->flush();
|
2019-02-03 22:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-24 17:25:42 +00:00
|
|
|
static void test_make_render_target(skiatest::Reporter* reporter,
|
2020-07-20 14:56:01 +00:00
|
|
|
GrDirectContext* dContext,
|
2019-06-24 17:25:42 +00:00
|
|
|
const SurfaceParameters& params) {
|
|
|
|
{
|
2020-07-20 14:56:01 +00:00
|
|
|
const SkSurfaceCharacterization c = params.createCharacterization(dContext);
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
if (!c.isValid()) {
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> tmp = params.make(dContext);
|
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);
|
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
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
const SkSurfaceCharacterization c = params.createCharacterization(dContext);
|
2019-06-24 17:25:42 +00:00
|
|
|
{
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
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
|
|
|
return;
|
2018-03-30 17:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, c.isValid());
|
2020-10-08 20:00:14 +00:00
|
|
|
GrBackendTexture backend = s->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess);
|
|
|
|
if (backend.isValid()) {
|
|
|
|
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
|
|
|
|
{
|
2020-07-20 14:56:01 +00:00
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(dContext, c, SkBudgeted::kYes);
|
2019-06-24 17:25:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// This tests the SkSurface::MakeRenderTarget variants that take an SkSurfaceCharacterization.
|
|
|
|
// In particular, the SkSurface, backendTexture and SkSurfaceCharacterization
|
|
|
|
// should always be compatible.
|
2020-07-20 14:56:01 +00:00
|
|
|
void DDLMakeRenderTargetTestImpl(GrDirectContext* dContext, skiatest::Reporter* reporter) {
|
2020-10-08 20:00:14 +00:00
|
|
|
for (int i = -1; i < SurfaceParameters::kNumParams; ++i) {
|
2020-11-04 15:50:39 +00:00
|
|
|
if (i == SurfaceParameters::kFBO0Count || i == SurfaceParameters::kVkSCBCount) {
|
|
|
|
// MakeRenderTarget doesn't support FBO0 or vulkan secondary command buffers
|
2019-02-03 22:17:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
SurfaceParameters params(dContext);
|
2020-10-08 20:00:14 +00:00
|
|
|
if (i >= 0 && !params.modify(i)) {
|
|
|
|
continue;
|
2019-06-24 17:25:42 +00:00
|
|
|
}
|
2018-04-03 21:17:05 +00:00
|
|
|
|
2020-07-20 14:56:01 +00:00
|
|
|
test_make_render_target(reporter, dContext, 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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-07-10 13:28:59 +00:00
|
|
|
|
|
|
|
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) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2019-05-17 14:01:21 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext,
|
|
|
|
kSize,
|
|
|
|
kSize,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
GrRenderable::kNo,
|
|
|
|
GrProtected::kNo);
|
|
|
|
if (!mbet) {
|
2018-03-08 15:13:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
SurfaceParameters params(dContext);
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2020-10-08 20:00:14 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(dContext);
|
2018-03-08 15:13:17 +00:00
|
|
|
if (!s) {
|
|
|
|
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
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
SkDeferredDisplayListRecorder recorder(c);
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
SkCanvas* canvas = recorder.getCanvas();
|
|
|
|
SkASSERT(canvas);
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
auto rContext = canvas->recordingContext();
|
|
|
|
if (!rContext) {
|
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
|
|
|
|
TextureReleaseChecker releaseChecker;
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromTexture(
|
|
|
|
rContext,
|
|
|
|
mbet->texture(),
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
nullptr,
|
|
|
|
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker));
|
2018-03-08 15:13:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, !image);
|
2018-01-23 21:38:14 +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) {
|
2020-08-13 17:34:27 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2018-03-15 20:53:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SkImageInfo ii = SkImageInfo::MakeN32Premul(32, 32);
|
2020-08-13 17:34:27 +00:00
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii);
|
2018-03-15 20:53:06 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2020-08-13 17:34:27 +00:00
|
|
|
}
|
2018-03-15 20:53:06 +00:00
|
|
|
|
2020-08-13 17:34:27 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLCreateCharacterizationFailures, reporter, ctxInfo) {
|
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
size_t maxResourceBytes = dContext->getResourceCacheLimit();
|
|
|
|
auto proxy = dContext->threadSafeProxy().get();
|
|
|
|
|
2020-08-27 18:29:00 +00:00
|
|
|
auto check_create_fails =
|
|
|
|
[proxy, reporter, maxResourceBytes](const GrBackendFormat& backendFormat,
|
|
|
|
int width, int height,
|
|
|
|
SkColorType ct, bool willUseGLFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
bool isTextureable,
|
2020-08-27 18:29:00 +00:00
|
|
|
GrProtected prot,
|
2020-11-04 15:50:39 +00:00
|
|
|
bool vkRTSupportsInputAttachment,
|
|
|
|
bool forVulkanSecondaryCommandBuffer) {
|
2020-08-13 17:34:27 +00:00
|
|
|
const SkSurfaceProps surfaceProps(0x0, kRGB_H_SkPixelGeometry);
|
|
|
|
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(width, height, ct,
|
|
|
|
kPremul_SkAlphaType, nullptr);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization c = proxy->createCharacterization(
|
|
|
|
maxResourceBytes, ii, backendFormat, 1,
|
|
|
|
kBottomLeft_GrSurfaceOrigin, surfaceProps, false,
|
2020-11-04 15:50:39 +00:00
|
|
|
willUseGLFBO0, isTextureable, prot,
|
|
|
|
vkRTSupportsInputAttachment,
|
|
|
|
forVulkanSecondaryCommandBuffer);
|
2020-08-13 17:34:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, !c.isValid());
|
|
|
|
};
|
|
|
|
|
|
|
|
GrBackendFormat goodBackendFormat = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
|
|
|
|
GrRenderable::kYes);
|
|
|
|
SkASSERT(goodBackendFormat.isValid());
|
|
|
|
|
|
|
|
GrBackendFormat badBackendFormat;
|
|
|
|
SkASSERT(!badBackendFormat.isValid());
|
|
|
|
|
|
|
|
SkColorType kGoodCT = kRGBA_8888_SkColorType;
|
|
|
|
SkColorType kBadCT = kUnknown_SkColorType;
|
|
|
|
|
2020-11-04 15:50:39 +00:00
|
|
|
static const bool kIsTextureable = true;
|
|
|
|
static const bool kIsNotTextureable = false;
|
|
|
|
|
2020-08-13 17:34:27 +00:00
|
|
|
static const bool kGoodUseFBO0 = false;
|
|
|
|
static const bool kBadUseFBO0 = true;
|
|
|
|
|
2020-08-27 18:29:00 +00:00
|
|
|
static const bool kGoodVkInputAttachment = false;
|
|
|
|
static const bool kBadVkInputAttachment = true;
|
|
|
|
|
2020-11-04 15:50:39 +00:00
|
|
|
static const bool kGoodForVkSCB = false;
|
|
|
|
static const bool kBadForVkSCB = true;
|
|
|
|
|
2020-08-13 17:34:27 +00:00
|
|
|
int goodWidth = 64;
|
|
|
|
int goodHeight = 64;
|
|
|
|
int badWidths[] = { 0, 1048576 };
|
|
|
|
int badHeights[] = { 0, 1048576 };
|
|
|
|
|
2020-08-27 18:29:00 +00:00
|
|
|
|
|
|
|
// In each of the check_create_fails calls there is one bad parameter that should cause the
|
|
|
|
// creation of the characterization to fail.
|
|
|
|
check_create_fails(goodBackendFormat, goodWidth, badHeights[0], kGoodCT, kGoodUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsTextureable, GrProtected::kNo, kGoodVkInputAttachment, kGoodForVkSCB);
|
2020-08-27 18:29:00 +00:00
|
|
|
check_create_fails(goodBackendFormat, goodWidth, badHeights[1], kGoodCT, kGoodUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsTextureable, GrProtected::kNo, kGoodVkInputAttachment, kGoodForVkSCB);
|
2020-08-27 18:29:00 +00:00
|
|
|
check_create_fails(goodBackendFormat, badWidths[0], goodHeight, kGoodCT, kGoodUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsTextureable, GrProtected::kNo, kGoodVkInputAttachment, kGoodForVkSCB);
|
2020-08-27 18:29:00 +00:00
|
|
|
check_create_fails(goodBackendFormat, badWidths[1], goodHeight, kGoodCT, kGoodUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsTextureable, GrProtected::kNo, kGoodVkInputAttachment, kGoodForVkSCB);
|
2020-08-27 18:29:00 +00:00
|
|
|
check_create_fails(badBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsTextureable, GrProtected::kNo, kGoodVkInputAttachment, kGoodForVkSCB);
|
2020-08-27 18:29:00 +00:00
|
|
|
check_create_fails(goodBackendFormat, goodWidth, goodHeight, kBadCT, kGoodUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsTextureable, GrProtected::kNo, kGoodVkInputAttachment, kGoodForVkSCB);
|
2020-08-27 18:29:00 +00:00
|
|
|
// This fails because we always try to make a characterization that is textureable and we can't
|
|
|
|
// have UseFBO0 be true and textureable.
|
|
|
|
check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kBadUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsTextureable, GrProtected::kNo, kGoodVkInputAttachment, kGoodForVkSCB);
|
2020-08-13 17:34:27 +00:00
|
|
|
if (dContext->backend() == GrBackendApi::kVulkan) {
|
2020-08-27 18:29:00 +00:00
|
|
|
// The bad parameter in this case is the GrProtected::kYes since none of our test contexts
|
|
|
|
// are made protected we can't have a protected surface.
|
|
|
|
check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsTextureable, GrProtected::kYes, kGoodVkInputAttachment,
|
|
|
|
kGoodForVkSCB);
|
|
|
|
// The following fails because forVulkanSecondaryCommandBuffer is true and
|
|
|
|
// isTextureable is true. This is not a legal combination.
|
|
|
|
check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
|
|
|
|
kIsTextureable, GrProtected::kNo, kGoodVkInputAttachment, kBadForVkSCB);
|
|
|
|
// The following fails because forVulkanSecondaryCommandBuffer is true and
|
|
|
|
// vkRTSupportsInputAttachment is true. This is not a legal combination.
|
|
|
|
check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
|
|
|
|
kIsNotTextureable, GrProtected::kNo, kBadVkInputAttachment,
|
|
|
|
kBadForVkSCB);
|
|
|
|
// The following fails because forVulkanSecondaryCommandBuffer is true and
|
|
|
|
// willUseGLFBO0 is true. This is not a legal combination.
|
|
|
|
check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kBadUseFBO0,
|
|
|
|
kIsNotTextureable, GrProtected::kNo, kGoodVkInputAttachment,
|
|
|
|
kBadForVkSCB);
|
2020-08-27 18:29:00 +00:00
|
|
|
} else {
|
2020-11-04 15:50:39 +00:00
|
|
|
// The following set vulkan only flags on non vulkan backends.
|
|
|
|
check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
|
|
|
|
kIsTextureable, GrProtected::kNo, kBadVkInputAttachment, kGoodForVkSCB);
|
2020-08-27 18:29:00 +00:00
|
|
|
check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
|
2020-11-04 15:50:39 +00:00
|
|
|
kIsNotTextureable, GrProtected::kNo, kGoodVkInputAttachment,
|
|
|
|
kBadForVkSCB);
|
2020-08-13 17:34:27 +00:00
|
|
|
}
|
2018-03-15 20:53:06 +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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSkSurfaceFlush, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-05-07 17:29:22 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(context, ii);
|
|
|
|
if (!mbet) {
|
|
|
|
ERRORF(reporter, "Could not make texture.");
|
2019-05-07 17:29:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FulfillInfo fulfillInfo;
|
2020-10-13 00:45:06 +00:00
|
|
|
fulfillInfo.fTex = SkPromiseImageTexture::Make(mbet->texture());
|
2019-05-07 17:29:22 +00:00
|
|
|
|
2020-06-29 14:00:08 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl;
|
2019-05-07 17:29:22 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2021-02-25 17:54:49 +00:00
|
|
|
SkCanvas* canvas = recorder.getCanvas();
|
2021-02-25 15:26:05 +00:00
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
sk_sp<SkImage> promiseImage = SkImage::MakePromiseTexture(
|
|
|
|
canvas->recordingContext()->threadSafeProxy(),
|
|
|
|
format,
|
|
|
|
SkISize::Make(32, 32),
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
nullptr,
|
|
|
|
tracking_fulfill_proc,
|
|
|
|
tracking_release_proc,
|
|
|
|
&fulfillInfo);
|
|
|
|
|
2019-05-07 17:29:22 +00:00
|
|
|
canvas->clear(SK_ColorRED);
|
|
|
|
canvas->drawImage(promiseImage, 0, 0);
|
|
|
|
ddl = recorder.detach();
|
|
|
|
}
|
|
|
|
|
2020-05-14 19:45:44 +00:00
|
|
|
context->flushAndSubmit();
|
2019-05-07 20:54:48 +00:00
|
|
|
|
2020-06-24 17:45:25 +00:00
|
|
|
s->draw(ddl);
|
2019-05-07 17:29:22 +00:00
|
|
|
|
|
|
|
GrFlushInfo flushInfo;
|
2019-05-07 19:57:25 +00:00
|
|
|
s->flush(SkSurface::BackendSurfaceAccess::kPresent, flushInfo);
|
2020-05-14 19:45:44 +00:00
|
|
|
context->submit();
|
2019-05-07 17:29:22 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, fulfillInfo.fFulfilled);
|
|
|
|
|
2021-05-07 20:25:49 +00:00
|
|
|
// In order to receive the done callback with the low-level APIs we need to re-flush
|
|
|
|
s->flush();
|
|
|
|
context->submit(true);
|
2019-05-07 17:29:22 +00:00
|
|
|
|
2020-11-09 20:40:27 +00:00
|
|
|
REPORTER_ASSERT(reporter, fulfillInfo.fReleased);
|
2019-05-07 17:29:22 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, fulfillInfo.fTex->unique());
|
|
|
|
fulfillInfo.fTex.reset();
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2018-12-18 13:29:09 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2020-06-29 14:00:08 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = recorder.detach();
|
2018-12-18 13:29:09 +00:00
|
|
|
|
|
|
|
SkCanvas* canvas2 = recorder.getCanvas();
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorGREEN);
|
|
|
|
canvas2->drawRect(SkRect::MakeWH(32, 32), p);
|
|
|
|
|
2020-06-29 14:00:08 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = recorder.detach();
|
2018-12-18 13:29:09 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
|
2020-06-24 17:45:25 +00:00
|
|
|
s->draw(ddl1);
|
|
|
|
s->draw(ddl2);
|
2018-12-18 13:29:09 +00:00
|
|
|
|
|
|
|
// 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
|
2021-03-03 23:12:56 +00:00
|
|
|
|
2021-06-16 19:28:00 +00:00
|
|
|
static sk_sp<SkPromiseImageTexture> noop_fulfill_proc(void*) {
|
2021-03-03 23:12:56 +00:00
|
|
|
SkASSERT(0);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2018-03-21 16:13:37 +00:00
|
|
|
|
|
|
|
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 } ) {
|
2020-07-21 13:27:25 +00:00
|
|
|
for (auto mipMapped : { GrMipmapped::kNo, GrMipmapped::kYes }) {
|
2018-06-08 22:11:51 +00:00
|
|
|
GrBackendFormat format = GrBackendFormat::MakeGL(GR_GL_RGBA8, target);
|
|
|
|
|
2021-03-03 23:12:56 +00:00
|
|
|
sk_sp<SkImage> image = SkImage::MakePromiseTexture(
|
|
|
|
recorder.getCanvas()->recordingContext()->threadSafeProxy(),
|
2020-11-09 20:40:27 +00:00
|
|
|
format,
|
2021-03-03 23:12:56 +00:00
|
|
|
SkISize::Make(32, 32),
|
2020-11-09 20:40:27 +00:00
|
|
|
mipMapped,
|
2019-01-30 22:28:20 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
2020-11-09 20:40:27 +00:00
|
|
|
kPremul_SkAlphaType,
|
2021-03-03 23:12:56 +00:00
|
|
|
/*color space*/nullptr,
|
2021-06-16 19:28:00 +00:00
|
|
|
noop_fulfill_proc,
|
2020-11-09 20:40:27 +00:00
|
|
|
/*release proc*/ nullptr,
|
2021-03-03 23:12:56 +00:00
|
|
|
/*context*/nullptr);
|
2020-07-21 13:27:25 +00:00
|
|
|
if (GR_GL_TEXTURE_2D != target && mipMapped == GrMipmapped::kYes) {
|
2018-06-08 22:11:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, !image);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, image);
|
2018-06-07 20:11:27 +00:00
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
GrTextureProxy* backingProxy = sk_gpu_test::GetTextureImageProxy(image.get(), context);
|
2018-06-08 22:01:16 +00:00
|
|
|
|
2020-07-21 16:09:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, backingProxy->mipmapped() == mipMapped);
|
2018-06-08 22:11:51 +00:00
|
|
|
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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
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-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
|
|
|
|
|
|
|
}
|