2019-05-16 16:43:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-05-20 15:55:11 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2019-05-16 16:43:11 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2019-05-17 18:19:44 +00:00
|
|
|
#include "src/image/SkImage_Base.h"
|
2019-05-16 16:43:11 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
// Test wrapping of GrBackendObjects in SkSurfaces and SkImages
|
|
|
|
void test_wrapping(GrContext* context, skiatest::Reporter* reporter,
|
2019-05-17 18:19:44 +00:00
|
|
|
std::function<GrBackendTexture (GrContext*, GrMipMapped, GrRenderable)> create,
|
|
|
|
SkColorType colorType, GrMipMapped mipMapped, GrRenderable renderable) {
|
2019-05-16 16:43:11 +00:00
|
|
|
GrResourceCache* cache = context->priv().getResourceCache();
|
|
|
|
|
|
|
|
const int initialCount = cache->getResourceCount();
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
GrBackendTexture backendTex = create(context, mipMapped, renderable);
|
|
|
|
if (!backendTex.isValid()) {
|
2019-05-16 16:43:11 +00:00
|
|
|
ERRORF(reporter, "Couldn't create backendTexture for colorType %d renderable %s\n",
|
|
|
|
colorType,
|
|
|
|
GrRenderable::kYes == renderable ? "yes" : "no");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Skia proper should know nothing about the new backend object
|
|
|
|
REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
|
|
|
|
|
|
|
|
if (kUnknown_SkColorType != colorType) {
|
|
|
|
if (GrRenderable::kYes == renderable) {
|
2019-05-17 18:19:44 +00:00
|
|
|
sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(context,
|
|
|
|
backendTex,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
0,
|
|
|
|
colorType,
|
|
|
|
nullptr, nullptr);
|
|
|
|
if (!surf) {
|
2019-05-16 16:43:11 +00:00
|
|
|
ERRORF(reporter, "Couldn't make surface from backendTexture for colorType %d\n",
|
|
|
|
colorType);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, initialCount+1 == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-05-17 18:19:44 +00:00
|
|
|
sk_sp<SkImage> img = SkImage::MakeFromTexture(context,
|
|
|
|
backendTex,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
colorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
nullptr);
|
|
|
|
if (!img) {
|
2019-05-16 16:43:11 +00:00
|
|
|
ERRORF(reporter, "Couldn't make image from backendTexture for colorType %d\n",
|
|
|
|
colorType);
|
|
|
|
} else {
|
2019-05-17 18:19:44 +00:00
|
|
|
SkImage_Base* ib = as_IB(img);
|
|
|
|
|
|
|
|
GrTextureProxy* proxy = ib->peekProxy();
|
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, mipMapped == proxy->proxyMipMapped());
|
|
|
|
REPORTER_ASSERT(reporter, proxy->isInstantiated());
|
|
|
|
REPORTER_ASSERT(reporter, mipMapped == proxy->mipMapped());
|
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
REPORTER_ASSERT(reporter, initialCount+1 == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
|
|
|
|
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2019-05-16 16:43:11 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
|
|
|
|
struct {
|
|
|
|
SkColorType fColorType;
|
|
|
|
GrPixelConfig fConfig;
|
|
|
|
} combinations[] = {
|
|
|
|
{ kAlpha_8_SkColorType, kAlpha_8_GrPixelConfig },
|
|
|
|
{ kRGB_565_SkColorType, kRGB_565_GrPixelConfig },
|
|
|
|
{ kARGB_4444_SkColorType, kRGBA_4444_GrPixelConfig },
|
|
|
|
{ kRGBA_8888_SkColorType, kRGBA_8888_GrPixelConfig },
|
|
|
|
{ kRGB_888x_SkColorType, kRGB_888_GrPixelConfig },
|
|
|
|
{ kBGRA_8888_SkColorType, kBGRA_8888_GrPixelConfig },
|
|
|
|
{ kRGBA_1010102_SkColorType, kRGBA_1010102_GrPixelConfig },
|
|
|
|
{ kRGB_101010x_SkColorType, kUnknown_GrPixelConfig }, // No Ganesh correlate
|
|
|
|
{ kGray_8_SkColorType, kGray_8_GrPixelConfig },
|
|
|
|
{ kRGBA_F16Norm_SkColorType, kRGBA_half_Clamped_GrPixelConfig },
|
|
|
|
{ kRGBA_F16_SkColorType, kRGBA_half_GrPixelConfig },
|
|
|
|
{ kRGBA_F32_SkColorType, kRGBA_float_GrPixelConfig },
|
|
|
|
};
|
|
|
|
|
|
|
|
SkASSERT(kLastEnum_SkColorType == SK_ARRAY_COUNT(combinations));
|
|
|
|
|
|
|
|
for (auto combo : combinations) {
|
|
|
|
SkColorType colorType = combo.fColorType;
|
|
|
|
|
|
|
|
if (!caps->isConfigTexturable(combo.fConfig)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GrBackendApi::kMetal == context->backend()) {
|
|
|
|
// skbug.com/9086 (Metal caps may not be handling RGBA32 correctly)
|
|
|
|
if (kRGBA_F32_SkColorType == combo.fColorType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
for (auto mipMapped : { GrMipMapped::kNo, GrMipMapped::kYes }) {
|
|
|
|
if (GrMipMapped::kYes == mipMapped && !caps->mipMapSupport()) {
|
|
|
|
continue;
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
|
|
|
|
if (GrRenderable::kYes == renderable) {
|
|
|
|
if (kRGB_888x_SkColorType == combo.fColorType) {
|
|
|
|
// Ganesh can't perform the blends correctly when rendering this format
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!caps->isConfigRenderable(combo.fConfig)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto createMtd = [colorType](GrContext* context,
|
|
|
|
GrMipMapped mipMapped,
|
|
|
|
GrRenderable renderable) {
|
2019-05-20 12:38:07 +00:00
|
|
|
return context->createBackendTexture(32, 32, colorType, mipMapped, renderable);
|
2019-05-17 18:19:44 +00:00
|
|
|
};
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
test_wrapping(context, reporter, createMtd,
|
|
|
|
colorType, mipMapped, renderable);
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef SK_GL
|
|
|
|
|
|
|
|
#include "src/gpu/gl/GrGLCaps.h"
|
2019-05-16 16:43:11 +00:00
|
|
|
#include "src/gpu/gl/GrGLDefines.h"
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLBackendAllocationTest, reporter, ctxInfo) {
|
|
|
|
sk_gpu_test::GLTestContext* glCtx = ctxInfo.glContext();
|
|
|
|
GrGLStandard standard = glCtx->gl()->fStandard;
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-05-17 18:19:44 +00:00
|
|
|
const GrGLCaps* glCaps = static_cast<const GrGLCaps*>(context->priv().caps());
|
2019-05-16 16:43:11 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
SkColorType fColorType;
|
|
|
|
GrGLenum fFormat;
|
|
|
|
// TODO: remove 'fConfig' and directly use 'fFormat' in GrGLCaps::isFormatTexturable
|
|
|
|
GrPixelConfig fConfig;
|
|
|
|
} combinations[] = {
|
|
|
|
{ kRGBA_8888_SkColorType, GR_GL_RGBA8, kRGBA_8888_GrPixelConfig },
|
|
|
|
{ kRGBA_8888_SkColorType, GR_GL_SRGB8_ALPHA8, kSRGBA_8888_GrPixelConfig },
|
|
|
|
|
|
|
|
{ kRGB_888x_SkColorType, GR_GL_RGBA8, kRGBA_8888_GrPixelConfig },
|
|
|
|
{ kRGB_888x_SkColorType, GR_GL_RGB8, kRGB_888_GrPixelConfig },
|
|
|
|
|
|
|
|
{ kBGRA_8888_SkColorType, GR_GL_RGBA8, kRGBA_8888_GrPixelConfig },
|
|
|
|
{ kBGRA_8888_SkColorType, GR_GL_BGRA8, kBGRA_8888_GrPixelConfig },
|
|
|
|
{ kBGRA_8888_SkColorType, GR_GL_SRGB8_ALPHA8, kSBGRA_8888_GrPixelConfig },
|
|
|
|
|
|
|
|
{ kRGBA_1010102_SkColorType, GR_GL_RGB10_A2, kRGBA_1010102_GrPixelConfig },
|
|
|
|
{ kRGB_565_SkColorType, GR_GL_RGB565, kRGB_565_GrPixelConfig },
|
|
|
|
{ kARGB_4444_SkColorType, GR_GL_RGBA4, kRGBA_4444_GrPixelConfig },
|
|
|
|
|
|
|
|
{ kAlpha_8_SkColorType, GR_GL_ALPHA8, kAlpha_8_as_Alpha_GrPixelConfig },
|
|
|
|
{ kAlpha_8_SkColorType, GR_GL_R8, kAlpha_8_as_Red_GrPixelConfig },
|
|
|
|
|
|
|
|
{ kGray_8_SkColorType, GR_GL_LUMINANCE8, kGray_8_as_Lum_GrPixelConfig },
|
|
|
|
{ kGray_8_SkColorType, GR_GL_R8, kGray_8_as_Red_GrPixelConfig },
|
|
|
|
|
|
|
|
{ kRGBA_F32_SkColorType, GR_GL_RGBA32F, kRGBA_float_GrPixelConfig },
|
|
|
|
|
|
|
|
{ kRGBA_F16Norm_SkColorType, GR_GL_RGBA16F, kRGBA_half_Clamped_GrPixelConfig },
|
|
|
|
{ kRGBA_F16_SkColorType, GR_GL_RGBA16F, kRGBA_half_GrPixelConfig },
|
|
|
|
|
|
|
|
// These backend formats don't have SkColorType equivalents
|
|
|
|
{ kUnknown_SkColorType, GR_GL_RG32F, kRG_float_GrPixelConfig },
|
|
|
|
{ kUnknown_SkColorType, GR_GL_RG8, kRG_88_GrPixelConfig },
|
|
|
|
{ kUnknown_SkColorType, GR_GL_R16F, kAlpha_half_as_Red_GrPixelConfig },
|
|
|
|
{ kUnknown_SkColorType, GR_GL_COMPRESSED_RGB8_ETC2, kRGB_ETC1_GrPixelConfig },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto combo : combinations) {
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeGL(combo.fFormat, GR_GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
if (GR_GL_COMPRESSED_RGB8_ETC2 == combo.fFormat) {
|
|
|
|
// We current disallow uninitialized ETC1 textures in the GL backend
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-17 18:19:44 +00:00
|
|
|
if (!glCaps->isConfigTexturable(combo.fConfig)) {
|
2019-05-16 16:43:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kBGRA_8888_SkColorType == combo.fColorType) {
|
|
|
|
if (GR_GL_RGBA8 == combo.fFormat && kGL_GrGLStandard != standard) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (GR_GL_BGRA8 == combo.fFormat && kGL_GrGLStandard == standard) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
for (auto mipMapped : { GrMipMapped::kNo, GrMipMapped::kYes }) {
|
|
|
|
if (GrMipMapped::kYes == mipMapped && !glCaps->mipMapSupport()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
if (GrRenderable::kYes == renderable) {
|
|
|
|
if (kRGB_888x_SkColorType == combo.fColorType) {
|
|
|
|
// Ganesh can't perform the blends correctly when rendering this format
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!glCaps->isConfigRenderable(combo.fConfig)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
auto createMtd = [format](GrContext* context,
|
|
|
|
GrMipMapped mipMapped,
|
|
|
|
GrRenderable renderable) {
|
2019-05-20 12:38:07 +00:00
|
|
|
return context->createBackendTexture(32, 32, format, mipMapped, renderable);
|
2019-05-17 18:19:44 +00:00
|
|
|
};
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
test_wrapping(context, reporter, createMtd,
|
|
|
|
combo.fColorType, mipMapped, renderable);
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2019-05-16 16:43:11 +00:00
|
|
|
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
|
|
|
|
#include "src/gpu/vk/GrVkCaps.h"
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendAllocationTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
const GrVkCaps* vkCaps = static_cast<const GrVkCaps*>(context->priv().caps());
|
|
|
|
|
|
|
|
struct {
|
|
|
|
SkColorType fColorType;
|
|
|
|
VkFormat fFormat;
|
|
|
|
} combinations[] = {
|
|
|
|
{ kRGBA_8888_SkColorType, VK_FORMAT_R8G8B8A8_UNORM },
|
|
|
|
{ kRGBA_8888_SkColorType, VK_FORMAT_R8G8B8A8_SRGB },
|
|
|
|
|
|
|
|
{ kRGB_888x_SkColorType, VK_FORMAT_R8G8B8_UNORM },
|
|
|
|
{ kRGB_888x_SkColorType, VK_FORMAT_R8G8B8A8_UNORM },
|
|
|
|
|
|
|
|
{ kBGRA_8888_SkColorType, VK_FORMAT_B8G8R8A8_UNORM },
|
|
|
|
{ kBGRA_8888_SkColorType, VK_FORMAT_B8G8R8A8_SRGB },
|
|
|
|
|
|
|
|
{ kRGBA_1010102_SkColorType, VK_FORMAT_A2B10G10R10_UNORM_PACK32 },
|
|
|
|
{ kRGB_565_SkColorType, VK_FORMAT_R5G6B5_UNORM_PACK16 },
|
2019-05-17 18:19:44 +00:00
|
|
|
|
|
|
|
{ kARGB_4444_SkColorType, VK_FORMAT_R4G4B4A4_UNORM_PACK16 },
|
2019-05-16 16:43:11 +00:00
|
|
|
{ kARGB_4444_SkColorType, VK_FORMAT_B4G4R4A4_UNORM_PACK16 },
|
2019-05-17 18:19:44 +00:00
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
{ kAlpha_8_SkColorType, VK_FORMAT_R8_UNORM },
|
|
|
|
{ kGray_8_SkColorType, VK_FORMAT_R8_UNORM },
|
|
|
|
{ kRGBA_F32_SkColorType, VK_FORMAT_R32G32B32A32_SFLOAT },
|
|
|
|
|
|
|
|
{ kRGBA_F16Norm_SkColorType, VK_FORMAT_R16G16B16A16_SFLOAT },
|
|
|
|
{ kRGBA_F16_SkColorType, VK_FORMAT_R16G16B16A16_SFLOAT },
|
|
|
|
|
|
|
|
// These backend formats don't have SkColorType equivalents
|
|
|
|
{ kUnknown_SkColorType, VK_FORMAT_R32G32_SFLOAT },
|
|
|
|
{ kUnknown_SkColorType, VK_FORMAT_R8G8_UNORM },
|
|
|
|
{ kUnknown_SkColorType, VK_FORMAT_R16_SFLOAT },
|
|
|
|
{ kUnknown_SkColorType, VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto combo : combinations) {
|
|
|
|
if (!vkCaps->isFormatTexturable(combo.fFormat)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeVk(combo.fFormat);
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
for (auto mipMapped : { GrMipMapped::kNo, GrMipMapped::kYes }) {
|
|
|
|
if (GrMipMapped::kYes == mipMapped && !vkCaps->mipMapSupport()) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
|
|
|
|
|
|
|
|
if (GrRenderable::kYes == renderable) {
|
|
|
|
if (kRGB_888x_SkColorType == combo.fColorType) {
|
|
|
|
// Ganesh can't perform the blends correctly when rendering this format
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!vkCaps->isFormatRenderable(combo.fFormat)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
auto createMtd = [format](GrContext* context,
|
|
|
|
GrMipMapped mipMapped,
|
|
|
|
GrRenderable renderable) {
|
2019-05-20 12:38:07 +00:00
|
|
|
return context->createBackendTexture(32, 32, format, mipMapped, renderable);
|
2019-05-17 18:19:44 +00:00
|
|
|
};
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
test_wrapping(context, reporter, createMtd,
|
|
|
|
combo.fColorType, mipMapped, renderable);
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|