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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2018-01-23 21:38:14 +00:00
|
|
|
#include "GrBackendSurface.h"
|
2018-05-22 14:48:08 +00:00
|
|
|
#include "GrCaps.h"
|
|
|
|
#include "GrContext.h"
|
|
|
|
#include "GrContextFactory.h"
|
2018-05-11 14:14:21 +00:00
|
|
|
#include "GrContextPriv.h"
|
2018-01-23 21:38:14 +00:00
|
|
|
#include "GrGpu.h"
|
2018-05-22 14:48:08 +00:00
|
|
|
#include "GrRenderTargetContext.h"
|
|
|
|
#include "GrRenderTargetProxy.h"
|
|
|
|
#include "GrTextureProxy.h"
|
2018-03-21 16:13:37 +00:00
|
|
|
#include "GrTextureProxyPriv.h"
|
2018-05-22 14:48:08 +00:00
|
|
|
#include "GrTypes.h"
|
|
|
|
#include "GrTypesPriv.h"
|
|
|
|
#include "SkBitmap.h"
|
2017-12-04 17:52:46 +00:00
|
|
|
#include "SkCanvas.h"
|
2018-05-22 14:48:08 +00:00
|
|
|
#include "SkColorSpace.h"
|
|
|
|
#include "SkDeferredDisplayList.h"
|
2017-12-04 17:52:46 +00:00
|
|
|
#include "SkDeferredDisplayListRecorder.h"
|
|
|
|
#include "SkGpuDevice.h"
|
2018-05-22 14:48:08 +00:00
|
|
|
#include "SkImage.h"
|
|
|
|
#include "SkImageInfo.h"
|
2018-03-21 16:13:37 +00:00
|
|
|
#include "SkImage_Gpu.h"
|
2018-05-22 14:48:08 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkRefCnt.h"
|
2017-12-04 17:52:46 +00:00
|
|
|
#include "SkSurface.h"
|
|
|
|
#include "SkSurfaceCharacterization.h"
|
|
|
|
#include "SkSurfaceProps.h"
|
2018-05-11 14:14:21 +00:00
|
|
|
#include "SkSurface_Gpu.h"
|
2017-12-04 17:52:46 +00:00
|
|
|
#include "Test.h"
|
2018-04-03 21:17:05 +00:00
|
|
|
#include "gl/GrGLCaps.h"
|
2018-05-11 14:14:21 +00:00
|
|
|
#include "gl/GrGLDefines.h"
|
2018-05-22 14:48:08 +00:00
|
|
|
#include "gl/GrGLTypes.h"
|
|
|
|
|
2018-02-13 22:03:00 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
#include "vk/GrVkDefines.h"
|
|
|
|
#endif
|
|
|
|
|
2018-05-22 14:48:08 +00:00
|
|
|
#include <initializer_list>
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
// Try to create a backend format from the provided colorType and config. Return an invalid
|
|
|
|
// backend format if the combination is infeasible.
|
|
|
|
static GrBackendFormat create_backend_format(GrContext* context,
|
2018-08-09 14:26:57 +00:00
|
|
|
SkColorType ct,
|
2018-04-03 21:17:05 +00:00
|
|
|
GrPixelConfig config) {
|
2018-05-11 14:14:21 +00:00
|
|
|
const GrCaps* caps = context->contextPriv().caps();
|
2018-02-13 22:03:00 +00:00
|
|
|
|
|
|
|
switch (context->contextPriv().getBackend()) {
|
2018-04-03 21:17:05 +00:00
|
|
|
case kOpenGL_GrBackend: {
|
2018-05-11 14:14:21 +00:00
|
|
|
const GrGLCaps* glCaps = static_cast<const GrGLCaps*>(caps);
|
2018-04-03 21:17:05 +00:00
|
|
|
GrGLStandard standard = glCaps->standard();
|
|
|
|
|
|
|
|
switch (ct) {
|
|
|
|
case kUnknown_SkColorType:
|
|
|
|
return GrBackendFormat();
|
|
|
|
case kAlpha_8_SkColorType:
|
|
|
|
if (kAlpha_8_as_Alpha_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_ALPHA8, GR_GL_TEXTURE_2D);
|
|
|
|
} else if (kAlpha_8_GrPixelConfig == config ||
|
|
|
|
kAlpha_8_as_Red_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_565_SkColorType:
|
|
|
|
if (kRGB_565_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kARGB_4444_SkColorType:
|
|
|
|
if (kRGBA_4444_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_RGBA4, GR_GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_8888_SkColorType:
|
|
|
|
if (kRGBA_8888_GrPixelConfig == config) {
|
2018-08-09 14:26:57 +00:00
|
|
|
return GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
|
2018-04-03 21:17:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_888x_SkColorType:
|
|
|
|
if (kRGB_888_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_RGB8, GR_GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kBGRA_8888_SkColorType:
|
|
|
|
if (kBGRA_8888_GrPixelConfig == config) {
|
|
|
|
if (kGL_GrGLStandard == standard) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_2D);
|
|
|
|
} else if (kGLES_GrGLStandard == standard) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_1010102_SkColorType:
|
|
|
|
if (kRGBA_1010102_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_101010x_SkColorType:
|
|
|
|
return GrBackendFormat();
|
|
|
|
case kGray_8_SkColorType:
|
|
|
|
if (kGray_8_as_Lum_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_LUMINANCE8, GR_GL_TEXTURE_2D);
|
|
|
|
} else if (kGray_8_GrPixelConfig == config ||
|
|
|
|
kGray_8_as_Red_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_R8, GR_GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_F16_SkColorType:
|
|
|
|
if (kRGBA_half_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
break;
|
2018-06-26 15:43:06 +00:00
|
|
|
case kRGBA_F32_SkColorType:
|
|
|
|
return GrBackendFormat();
|
2018-02-13 22:03:00 +00:00
|
|
|
}
|
2018-04-03 21:17:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-02-13 22:03:00 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
case kVulkan_GrBackend:
|
2018-04-03 21:17:05 +00:00
|
|
|
switch (ct) {
|
|
|
|
case kUnknown_SkColorType:
|
|
|
|
return GrBackendFormat();
|
|
|
|
case kAlpha_8_SkColorType:
|
|
|
|
// TODO: what about kAlpha_8_GrPixelConfig and kAlpha_8_as_Alpha_GrPixelConfig
|
|
|
|
if (kAlpha_8_as_Red_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_565_SkColorType:
|
|
|
|
if (kRGB_565_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_R5G6B5_UNORM_PACK16);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kARGB_4444_SkColorType:
|
|
|
|
if (kRGBA_4444_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_B4G4R4A4_UNORM_PACK16);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_8888_SkColorType:
|
|
|
|
if (kRGBA_8888_GrPixelConfig == config) {
|
2018-08-09 14:26:57 +00:00
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM);
|
2018-04-03 21:17:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_888x_SkColorType:
|
|
|
|
if (kRGB_888_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8_UNORM);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kBGRA_8888_SkColorType:
|
|
|
|
if (kBGRA_8888_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_1010102_SkColorType:
|
|
|
|
if (kRGBA_1010102_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_A2B10G10R10_UNORM_PACK32);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_101010x_SkColorType:
|
|
|
|
return GrBackendFormat();
|
|
|
|
case kGray_8_SkColorType:
|
|
|
|
// TODO: what about kAlpha_8_GrPixelConfig and kGray_8_as_Lum_GrPixelConfig?
|
|
|
|
if (kGray_8_as_Red_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_R8_UNORM);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_F16_SkColorType:
|
|
|
|
if (kRGBA_half_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeVk(VK_FORMAT_R16G16B16A16_SFLOAT);
|
|
|
|
}
|
|
|
|
break;
|
2018-06-26 15:43:06 +00:00
|
|
|
case kRGBA_F32_SkColorType:
|
|
|
|
return GrBackendFormat();
|
2018-02-13 22:03:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case kMock_GrBackend:
|
2018-04-03 21:17:05 +00:00
|
|
|
switch (ct) {
|
|
|
|
case kUnknown_SkColorType:
|
|
|
|
return GrBackendFormat();
|
|
|
|
case kAlpha_8_SkColorType:
|
|
|
|
if (kAlpha_8_GrPixelConfig == config ||
|
|
|
|
kAlpha_8_as_Alpha_GrPixelConfig == config ||
|
|
|
|
kAlpha_8_as_Red_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeMock(config);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_565_SkColorType:
|
|
|
|
if (kRGB_565_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeMock(config);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kARGB_4444_SkColorType:
|
|
|
|
if (kRGBA_4444_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeMock(config);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_8888_SkColorType:
|
|
|
|
if (kRGBA_8888_GrPixelConfig == config) {
|
2018-08-09 14:26:57 +00:00
|
|
|
return GrBackendFormat::MakeMock(config);
|
2018-04-03 21:17:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_888x_SkColorType:
|
|
|
|
if (kRGB_888_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeMock(config);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kBGRA_8888_SkColorType:
|
|
|
|
if (kBGRA_8888_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeMock(config);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_1010102_SkColorType:
|
|
|
|
if (kRGBA_1010102_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeMock(config);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGB_101010x_SkColorType:
|
|
|
|
return GrBackendFormat();
|
|
|
|
case kGray_8_SkColorType:
|
|
|
|
if (kGray_8_GrPixelConfig == config ||
|
|
|
|
kGray_8_as_Lum_GrPixelConfig == config ||
|
|
|
|
kGray_8_as_Red_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeMock(config);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRGBA_F16_SkColorType:
|
|
|
|
if (kRGBA_half_GrPixelConfig == config) {
|
|
|
|
return GrBackendFormat::MakeMock(config);
|
|
|
|
}
|
|
|
|
break;
|
2018-06-26 15:43:06 +00:00
|
|
|
case kRGBA_F32_SkColorType:
|
|
|
|
return GrBackendFormat();
|
2018-02-13 22:03:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return GrBackendFormat(); // return an invalid format
|
|
|
|
}
|
|
|
|
|
|
|
|
return GrBackendFormat(); // return an invalid format
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-04 17:52:46 +00:00
|
|
|
class SurfaceParameters {
|
|
|
|
public:
|
2018-02-04 19:33:21 +00:00
|
|
|
static const int kNumParams = 9;
|
2017-12-04 17:52:46 +00:00
|
|
|
static const int kSampleCount = 5;
|
2018-02-04 19:33:21 +00:00
|
|
|
static const int kMipMipCount = 8;
|
2017-12-04 17:52:46 +00:00
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
SurfaceParameters(const GrCaps* caps)
|
2017-12-04 17:52:46 +00:00
|
|
|
: fWidth(64)
|
|
|
|
, fHeight(64)
|
|
|
|
, fOrigin(kTopLeft_GrSurfaceOrigin)
|
|
|
|
, fColorType(kRGBA_8888_SkColorType)
|
2018-08-09 14:26:57 +00:00
|
|
|
, fConfig(kRGBA_8888_GrPixelConfig)
|
2017-12-04 17:52:46 +00:00
|
|
|
, 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)
|
|
|
|
, fShouldCreateMipMaps(true) {
|
|
|
|
}
|
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; }
|
|
|
|
void setColorSpace(sk_sp<SkColorSpace> cs) { fColorSpace = std::move(cs); }
|
|
|
|
void setConfig(GrPixelConfig config) { fConfig = config; }
|
|
|
|
|
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:
|
2018-04-04 15:12:39 +00:00
|
|
|
// The color type and config need to be changed together.
|
2017-12-04 17:52:46 +00:00
|
|
|
fColorType = kRGBA_F16_SkColorType;
|
2018-04-03 21:17:05 +00:00
|
|
|
fConfig = kRGBA_half_GrPixelConfig;
|
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.
|
2018-04-04 15:12:39 +00:00
|
|
|
fColorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
|
|
|
|
SkColorSpace::kAdobeRGB_Gamut);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-30 17:57:00 +00:00
|
|
|
SkSurfaceCharacterization createCharacterization(GrContext* context) const {
|
2018-02-13 22:03:00 +00:00
|
|
|
int maxResourceCount;
|
|
|
|
size_t maxResourceBytes;
|
|
|
|
context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
|
|
|
|
|
|
|
|
// Note that Ganesh doesn't make use of the SkImageInfo's alphaType
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType,
|
|
|
|
kPremul_SkAlphaType, fColorSpace);
|
|
|
|
|
2018-08-09 14:26:57 +00:00
|
|
|
GrBackendFormat backendFormat = create_backend_format(context, fColorType, fConfig);
|
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,
|
|
|
|
fOrigin, fSurfaceProps, fShouldCreateMipMaps);
|
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
|
2018-04-03 21:17:05 +00:00
|
|
|
sk_sp<SkSurface> make(GrContext* context, GrBackendTexture* backend,
|
|
|
|
bool nonTextureable) const {
|
2018-02-04 19:33:21 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
GrMipMapped mipmapped = nonTextureable
|
|
|
|
? GrMipMapped::kNo
|
|
|
|
: GrMipMapped(fShouldCreateMipMaps);
|
2018-02-04 19:33:21 +00:00
|
|
|
|
|
|
|
*backend = gpu->createTestingOnlyBackendTexture(nullptr, fWidth, fHeight,
|
2018-04-03 21:17:05 +00:00
|
|
|
fConfig, true, mipmapped);
|
2018-02-04 19:33:21 +00:00
|
|
|
if (!backend->isValid() || !gpu->isTestingOnlyBackendTexture(*backend)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
sk_sp<SkSurface> surface;
|
|
|
|
if (nonTextureable) {
|
|
|
|
// 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) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(*backend);
|
2018-02-04 19:33:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
void cleanUpBackEnd(GrContext* context, const GrBackendTexture& backend) const {
|
2018-02-04 19:33:21 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
|
|
|
|
|
|
|
gpu->deleteTestingOnlyBackendTexture(backend);
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int fWidth;
|
|
|
|
int fHeight;
|
|
|
|
GrSurfaceOrigin fOrigin;
|
|
|
|
SkColorType fColorType;
|
2018-04-03 21:17:05 +00:00
|
|
|
GrPixelConfig fConfig;
|
2017-12-04 17:52:46 +00:00
|
|
|
sk_sp<SkColorSpace> fColorSpace;
|
|
|
|
int fSampleCount;
|
|
|
|
SkSurfaceProps fSurfaceProps;
|
2018-02-04 19:33:21 +00:00
|
|
|
bool fShouldCreateMipMaps;
|
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) {
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params1(context->contextPriv().caps());
|
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) {
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params2(context->contextPriv().caps());
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params(context->contextPriv().caps());
|
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
|
2018-04-03 21:17:05 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
|
2017-12-04 17:52:46 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
2018-04-03 21:17:05 +00:00
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
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
|
|
|
|
{
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params(context->contextPriv().caps());
|
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;
|
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend, false);
|
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) {
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params(context->contextPriv().caps());
|
2017-12-04 17:52:46 +00:00
|
|
|
params.modify(i);
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend, false);
|
2017-12-04 17:52:46 +00:00
|
|
|
if (!s) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SurfaceParameters::kSampleCount == i) {
|
|
|
|
SkSurface_Gpu* gpuSurf = static_cast<SkSurface_Gpu*>(s.get());
|
|
|
|
|
2018-05-11 14:14:21 +00:00
|
|
|
int supportedSampleCount = context->contextPriv().caps()->getRenderTargetSampleCount(
|
|
|
|
params.sampleCount(),
|
|
|
|
gpuSurf->getDevice()
|
|
|
|
->accessRenderTargetContext()
|
|
|
|
->asRenderTargetProxy()
|
|
|
|
->config());
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:14:21 +00:00
|
|
|
if (SurfaceParameters::kMipMipCount == i &&
|
|
|
|
!context->contextPriv().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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2018-05-11 14:14:21 +00:00
|
|
|
const SurfaceParameters params(context->contextPriv().caps());
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
|
|
|
|
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend, false);
|
2017-12-04 18:48:14 +00:00
|
|
|
|
|
|
|
int maxResourceCount;
|
|
|
|
size_t maxResourceBytes;
|
|
|
|
context->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
|
|
|
|
|
|
|
|
context->setResourceCacheLimits(maxResourceCount, maxResourceBytes/2);
|
|
|
|
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;
|
2018-05-11 14:14:21 +00:00
|
|
|
const SurfaceParameters params(context->contextPriv().caps());
|
2018-04-03 21:17:05 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend, true);
|
2018-02-04 19:33:21 +00:00
|
|
|
if (s) {
|
|
|
|
REPORTER_ASSERT(reporter, !s->draw(ddl.get()));
|
|
|
|
|
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
|
|
|
|
{
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params(context->contextPriv().caps());
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
2018-03-06 18:41:51 +00:00
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend, false);
|
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
|
|
|
}
|
2017-12-04 17:52:46 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 17:57:00 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// This tests the SkSurface::MakeRenderTarget variant that takes an SkSurfaceCharacterization.
|
|
|
|
// In particular, the SkSurface and the SkSurfaceCharacterization should always be compatible.
|
2018-04-03 21:17:05 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLMakeRenderTargetTest, reporter, ctxInfo) {
|
2018-03-30 17:57:00 +00:00
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
|
|
|
for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params(context->contextPriv().caps());
|
2018-03-30 17:57:00 +00:00
|
|
|
params.modify(i);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization c = params.createCharacterization(context);
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
|
|
|
|
|
|
|
if (!c.isValid()) {
|
|
|
|
sk_sp<SkSurface> tmp = params.make(context, &backend, false);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-30 17:57:00 +00:00
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend, false);
|
2018-03-30 17:57:00 +00:00
|
|
|
if (!s) {
|
|
|
|
REPORTER_ASSERT(reporter, !c.isValid());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, c.isValid());
|
|
|
|
|
|
|
|
s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
|
|
|
|
REPORTER_ASSERT(reporter, s);
|
|
|
|
|
|
|
|
SkSurface_Gpu* g = static_cast<SkSurface_Gpu*>(s.get());
|
|
|
|
REPORTER_ASSERT(reporter, g->isCompatible(c));
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
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();
|
|
|
|
GrGpu* gpu = context->contextPriv().getGpu();
|
2018-03-08 15:13:17 +00:00
|
|
|
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
|
|
|
|
nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo);
|
|
|
|
if (!backendTex.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params(context->contextPriv().caps());
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendTexture backend;
|
2018-01-23 21:38:14 +00:00
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend, false);
|
2018-03-08 15:13:17 +00:00
|
|
|
if (!s) {
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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);
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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);
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(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
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
2018-04-03 21:17:05 +00:00
|
|
|
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
2018-01-23 21:38:14 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 20:53:06 +00:00
|
|
|
static void dummy_fulfill_proc(void*, GrBackendTexture*) { SkASSERT(0); }
|
|
|
|
static void dummy_release_proc(void*) { SkASSERT(0); }
|
2018-03-21 16:13:37 +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());
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
GrBackendFormat format = create_backend_format(context, kRGBA_8888_SkColorType,
|
2018-08-09 14:26:57 +00:00
|
|
|
kRGBA_8888_GrPixelConfig);
|
2018-03-15 20:53:06 +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,
|
2018-03-16 18:57:21 +00:00
|
|
|
dummy_done_proc,
|
2018-03-15 20:53:06 +00:00
|
|
|
nullptr);
|
|
|
|
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->flush();
|
|
|
|
canvas->getGrContext()->flush();
|
|
|
|
}
|
2018-01-23 21:38:14 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
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,
|
|
|
|
nullptr);
|
|
|
|
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-06-08 22:11:51 +00:00
|
|
|
GrTextureProxy* backingProxy = ((SkImage_Gpu*) 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
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Exhaustively test colorType and pixelConfig compatibility.
|
|
|
|
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);
|
|
|
|
|
|
|
|
for (int config = 0; config < kGrPixelConfigCnt; ++config) {
|
|
|
|
GrPixelConfig pixelConfig = static_cast<GrPixelConfig>(config);
|
|
|
|
|
2018-05-11 14:14:21 +00:00
|
|
|
SurfaceParameters params(context->contextPriv().caps());
|
2018-04-03 21:17:05 +00:00
|
|
|
params.setColorType(colorType);
|
|
|
|
params.setConfig(pixelConfig);
|
|
|
|
params.setColorSpace(nullptr);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization c = params.createCharacterization(context);
|
|
|
|
GrBackendTexture backend;
|
|
|
|
|
|
|
|
if (!c.isValid()) {
|
|
|
|
// TODO: this would be cool to enable but there is, currently, too much crossover
|
|
|
|
// allowed internally (e.g., kAlpha_8_SkColorType/kGray_8_as_Red_GrPixelConfig
|
|
|
|
// is permitted on GL).
|
|
|
|
#if 0
|
|
|
|
sk_sp<SkSurface> tmp = params.make(context, &backend, false);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_sp<SkSurface> s = params.make(context, &backend, false);
|
|
|
|
REPORTER_ASSERT(reporter, s);
|
|
|
|
if (!s) {
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSurface_Gpu* gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
|
|
|
|
REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
|
|
|
|
|
|
|
|
s = nullptr;
|
|
|
|
params.cleanUpBackEnd(context, backend);
|
|
|
|
|
|
|
|
s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes);
|
|
|
|
REPORTER_ASSERT(reporter, s);
|
|
|
|
if (!s) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpuSurface = static_cast<SkSurface_Gpu*>(s.get());
|
|
|
|
REPORTER_ASSERT(reporter, gpuSurface->isCompatible(c));
|
|
|
|
}
|
|
|
|
}
|
2018-03-21 16:13:37 +00:00
|
|
|
|
|
|
|
}
|