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.
|
|
|
|
*/
|
|
|
|
|
2020-04-06 17:57:30 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-20 15:55:11 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2019-07-02 21:58:27 +00:00
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-05-23 13:38:27 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2020-12-16 20:55:25 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrSurfaceFillContext.h"
|
|
|
|
#include "src/gpu/effects/GrBlendFragmentProcessor.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"
|
2019-09-11 15:26:46 +00:00
|
|
|
#include "tests/TestUtils.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2020-12-16 01:23:03 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-06-03 16:59:40 +00:00
|
|
|
#ifdef SK_GL
|
2019-12-18 16:16:17 +00:00
|
|
|
#include "src/gpu/gl/GrGLCaps.h"
|
|
|
|
#include "src/gpu/gl/GrGLDefines.h"
|
2019-06-03 16:59:40 +00:00
|
|
|
#include "src/gpu/gl/GrGLGpu.h"
|
|
|
|
#include "src/gpu/gl/GrGLUtil.h"
|
|
|
|
#endif
|
|
|
|
|
2019-09-26 18:01:36 +00:00
|
|
|
#ifdef SK_METAL
|
|
|
|
#include "include/gpu/mtl/GrMtlTypes.h"
|
|
|
|
#include "src/gpu/mtl/GrMtlCppUtil.h"
|
|
|
|
#endif
|
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
using sk_gpu_test::ManagedBackendTexture;
|
2020-05-13 19:32:04 +00:00
|
|
|
|
2019-09-24 20:32:35 +00:00
|
|
|
// Test wrapping of GrBackendObjects in SkSurfaces and SkImages (non-static since used in Mtl test)
|
2020-07-17 18:15:51 +00:00
|
|
|
void test_wrapping(GrDirectContext* dContext,
|
|
|
|
skiatest::Reporter* reporter,
|
2020-12-16 01:23:03 +00:00
|
|
|
std::function<sk_sp<ManagedBackendTexture>(GrDirectContext*,
|
|
|
|
GrMipmapped,
|
|
|
|
GrRenderable)> create,
|
2020-07-17 18:15:51 +00:00
|
|
|
GrColorType grColorType,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped mipMapped,
|
2020-12-16 01:23:03 +00:00
|
|
|
GrRenderable renderable) {
|
2020-07-17 18:15:51 +00:00
|
|
|
GrResourceCache* cache = dContext->priv().getResourceCache();
|
2019-05-16 16:43:11 +00:00
|
|
|
|
|
|
|
const int initialCount = cache->getResourceCount();
|
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
sk_sp<ManagedBackendTexture> mbet = create(dContext, mipMapped, renderable);
|
|
|
|
if (!mbet) {
|
2019-07-26 15:13:19 +00:00
|
|
|
ERRORF(reporter, "Couldn't create backendTexture for grColorType %d renderable %s\n",
|
|
|
|
grColorType,
|
2019-05-16 16:43:11 +00:00
|
|
|
GrRenderable::kYes == renderable ? "yes" : "no");
|
|
|
|
return;
|
|
|
|
}
|
2019-05-21 21:24:31 +00:00
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
// Skia proper should know nothing about the new backend object
|
|
|
|
REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
|
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
SkColorType skColorType = GrColorTypeToSkColorType(grColorType);
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
// Wrapping a backendTexture in an SkImage/SkSurface requires an SkColorType
|
|
|
|
if (skColorType == kUnknown_SkColorType) {
|
2019-05-21 21:24:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-12 21:29:40 +00:00
|
|
|
// As we transition to using attachments instead of GrTextures and GrRenderTargets individual
|
|
|
|
// proxy instansiations may add multiple things to the cache. There would be an entry for the
|
|
|
|
// GrTexture/GrRenderTarget and entries for one or more attachments.
|
|
|
|
int cacheEntriesPerProxy = 1;
|
|
|
|
// We currently only have attachments on the vulkan backend
|
|
|
|
if (dContext->backend() == GrBackend::kVulkan) {
|
|
|
|
// If we ever make a rt with multisamples this would have an additional
|
|
|
|
// attachment as well.
|
|
|
|
cacheEntriesPerProxy++;
|
|
|
|
}
|
|
|
|
|
2020-07-17 18:15:51 +00:00
|
|
|
if (GrRenderable::kYes == renderable && dContext->colorTypeSupportedAsSurface(skColorType)) {
|
|
|
|
sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(dContext,
|
2020-12-16 01:23:03 +00:00
|
|
|
mbet->texture(),
|
2019-05-23 13:38:27 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
0,
|
2019-07-26 15:13:19 +00:00
|
|
|
skColorType,
|
2019-05-23 13:38:27 +00:00
|
|
|
nullptr, nullptr);
|
2019-05-21 21:24:31 +00:00
|
|
|
if (!surf) {
|
2020-12-16 20:55:25 +00:00
|
|
|
ERRORF(reporter, "Couldn't make SkSurface from backendTexture for %s\n",
|
2020-04-29 12:58:39 +00:00
|
|
|
ToolUtils::colortype_name(skColorType));
|
2019-05-21 21:24:31 +00:00
|
|
|
} else {
|
2021-03-05 22:50:08 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
initialCount + cacheEntriesPerProxy == cache->getResourceCount());
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
2019-05-21 21:24:31 +00:00
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-21 21:24:31 +00:00
|
|
|
{
|
2020-07-17 18:15:51 +00:00
|
|
|
sk_sp<SkImage> img = SkImage::MakeFromTexture(dContext,
|
2020-12-16 01:23:03 +00:00
|
|
|
mbet->texture(),
|
2019-05-23 13:38:27 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin,
|
2019-07-26 15:13:19 +00:00
|
|
|
skColorType,
|
2020-12-16 20:55:25 +00:00
|
|
|
kUnpremul_SkAlphaType,
|
2019-05-23 13:38:27 +00:00
|
|
|
nullptr);
|
2019-05-21 21:24:31 +00:00
|
|
|
if (!img) {
|
2020-12-16 20:55:25 +00:00
|
|
|
ERRORF(reporter, "Couldn't make SkImage from backendTexture for %s\n",
|
2020-04-29 12:58:39 +00:00
|
|
|
ToolUtils::colortype_name(skColorType));
|
2019-05-21 21:24:31 +00:00
|
|
|
} else {
|
2021-02-23 15:45:39 +00:00
|
|
|
GrTextureProxy* proxy = sk_gpu_test::GetTextureImageProxy(img.get(), dContext);
|
2019-05-21 21:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
|
2020-07-21 16:09:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipMapped == proxy->proxyMipmapped());
|
2019-05-21 21:24:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy->isInstantiated());
|
2020-07-21 16:09:58 +00:00
|
|
|
REPORTER_ASSERT(reporter, mipMapped == proxy->mipmapped());
|
2019-05-21 21:24:31 +00:00
|
|
|
|
2021-03-12 21:29:40 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
initialCount + cacheEntriesPerProxy == cache->getResourceCount());
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
|
2020-04-29 12:58:39 +00:00
|
|
|
static bool isBGRA8(const GrBackendFormat& format) {
|
2019-09-26 18:01:36 +00:00
|
|
|
switch (format.backend()) {
|
|
|
|
case GrBackendApi::kOpenGL:
|
|
|
|
#ifdef SK_GL
|
|
|
|
return format.asGLFormat() == GrGLFormat::kBGRA8;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
case GrBackendApi::kVulkan: {
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
VkFormat vkFormat;
|
|
|
|
format.asVkFormat(&vkFormat);
|
|
|
|
return vkFormat == VK_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2020-02-18 19:34:38 +00:00
|
|
|
case GrBackendApi::kMetal:
|
|
|
|
#ifdef SK_METAL
|
2020-04-29 12:58:39 +00:00
|
|
|
return GrMtlFormatIsBGRA8(format.asMtlFormat());
|
2020-02-18 19:34:38 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
case GrBackendApi::kDirect3D:
|
|
|
|
#ifdef SK_DIRECT3D
|
|
|
|
return false; // TODO
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
case GrBackendApi::kDawn:
|
2020-06-11 02:24:57 +00:00
|
|
|
#ifdef SK_DAWN
|
|
|
|
wgpu::TextureFormat dawnFormat;
|
|
|
|
format.asDawnFormat(&dawnFormat);
|
|
|
|
return dawnFormat == wgpu::TextureFormat::BGRA8Unorm;
|
|
|
|
#else
|
2020-02-18 19:34:38 +00:00
|
|
|
return false;
|
2020-06-11 02:24:57 +00:00
|
|
|
#endif
|
2019-12-10 19:48:36 +00:00
|
|
|
case GrBackendApi::kMock: {
|
|
|
|
SkImage::CompressionType compression = format.asMockCompressionType();
|
|
|
|
if (compression != SkImage::CompressionType::kNone) {
|
|
|
|
return false; // No compressed formats are BGRA
|
|
|
|
}
|
|
|
|
|
2019-09-26 18:01:36 +00:00
|
|
|
return format.asMockColorType() == GrColorType::kBGRA_8888;
|
2019-12-10 19:48:36 +00:00
|
|
|
}
|
2019-09-26 18:01:36 +00:00
|
|
|
}
|
|
|
|
SkUNREACHABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isRGB(const GrBackendFormat& format) {
|
|
|
|
switch (format.backend()) {
|
|
|
|
case GrBackendApi::kOpenGL:
|
|
|
|
#ifdef SK_GL
|
|
|
|
return format.asGLFormat() == GrGLFormat::kRGB8;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
case GrBackendApi::kVulkan: {
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
VkFormat vkFormat;
|
|
|
|
format.asVkFormat(&vkFormat);
|
|
|
|
return vkFormat == VK_FORMAT_R8G8B8_UNORM;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2020-02-18 19:34:38 +00:00
|
|
|
case GrBackendApi::kMetal:
|
|
|
|
return false; // Metal doesn't even pretend to support this
|
|
|
|
case GrBackendApi::kDirect3D:
|
|
|
|
return false; // Not supported in Direct3D 12
|
|
|
|
case GrBackendApi::kDawn:
|
|
|
|
return false;
|
2019-09-26 18:01:36 +00:00
|
|
|
case GrBackendApi::kMock:
|
|
|
|
return false; // No GrColorType::kRGB_888
|
|
|
|
}
|
|
|
|
SkUNREACHABLE;
|
|
|
|
}
|
|
|
|
|
2019-09-11 15:26:46 +00:00
|
|
|
static void check_solid_pixmap(skiatest::Reporter* reporter,
|
2020-12-16 20:55:25 +00:00
|
|
|
const SkColor4f& expected,
|
|
|
|
const SkPixmap& actual,
|
|
|
|
GrColorType ct,
|
|
|
|
const char* label1,
|
|
|
|
const char* label2) {
|
2019-09-11 15:26:46 +00:00
|
|
|
// we need 0.001f across the board just for noise
|
|
|
|
// we need 0.01f across the board for 1010102
|
2019-09-26 18:01:36 +00:00
|
|
|
const float tols[4] = { 0.01f, 0.01f, 0.01f, 0.01f };
|
2019-09-11 15:26:46 +00:00
|
|
|
|
|
|
|
auto error = std::function<ComparePixmapsErrorReporter>(
|
2019-09-26 18:01:36 +00:00
|
|
|
[reporter, ct, label1, label2](int x, int y, const float diffs[4]) {
|
2019-09-11 15:26:46 +00:00
|
|
|
SkASSERT(x >= 0 && y >= 0);
|
2020-12-16 20:55:25 +00:00
|
|
|
ERRORF(reporter, "%s %s %s - mismatch at %d, %d (%f, %f, %f %f)", GrColorTypeToStr(ct),
|
|
|
|
label1, label2, x, y, diffs[0], diffs[1], diffs[2], diffs[3]);
|
2019-09-11 15:26:46 +00:00
|
|
|
});
|
|
|
|
|
2019-10-25 00:07:39 +00:00
|
|
|
CheckSolidPixels(expected, actual, tols, error);
|
2019-06-03 16:59:40 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
// Determine what color we expect if we store 'orig' in 'ct' converted back to SkColor4f.
|
|
|
|
static SkColor4f get_expected_color(SkColor4f orig, GrColorType ct) {
|
|
|
|
GrImageInfo ii(ct, kUnpremul_SkAlphaType, nullptr, {1, 1});
|
|
|
|
std::unique_ptr<char[]> data(new char[ii.minRowBytes()]);
|
2021-04-08 16:45:58 +00:00
|
|
|
GrClearImage(ii, data.get(), ii.minRowBytes(), orig.array());
|
2020-12-16 20:55:25 +00:00
|
|
|
|
|
|
|
// Read back to SkColor4f.
|
|
|
|
SkColor4f result;
|
|
|
|
GrImageInfo resultII(GrColorType::kRGBA_F32, kUnpremul_SkAlphaType, nullptr, {1, 1});
|
2021-03-30 20:14:37 +00:00
|
|
|
GrConvertPixels(GrPixmap(resultII, &result.fR, sizeof(result)),
|
|
|
|
GrPixmap( ii, data.get(), ii.minRowBytes()));
|
2020-12-16 20:55:25 +00:00
|
|
|
return result;
|
2019-05-23 13:38:27 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
static void check_mipmaps(GrDirectContext*,
|
|
|
|
const GrBackendTexture&,
|
|
|
|
GrColorType,
|
|
|
|
const SkColor4f expectedColors[6],
|
|
|
|
skiatest::Reporter*,
|
|
|
|
const char* label);
|
|
|
|
|
|
|
|
static void check_base_readbacks(GrDirectContext* dContext,
|
|
|
|
const GrBackendTexture& backendTex,
|
|
|
|
GrColorType colorType,
|
|
|
|
GrRenderable renderableTexture,
|
|
|
|
const SkColor4f& color,
|
|
|
|
skiatest::Reporter* reporter,
|
2019-09-26 18:01:36 +00:00
|
|
|
const char* label) {
|
|
|
|
if (isRGB(backendTex.getBackendFormat())) {
|
|
|
|
// readPixels is busted for the RGB backend format (skbug.com/8862)
|
|
|
|
// TODO: add a GrColorType::kRGB_888 to fix the situation
|
|
|
|
return;
|
|
|
|
}
|
2019-05-23 13:38:27 +00:00
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
SkColor4f expectedColor = get_expected_color(color, colorType);
|
2019-06-03 16:59:40 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
SkAutoPixmapStorage actual;
|
2019-09-25 13:55:16 +00:00
|
|
|
|
|
|
|
{
|
2020-12-16 20:55:25 +00:00
|
|
|
SkImageInfo readBackII = SkImageInfo::Make(32, 32,
|
|
|
|
kRGBA_8888_SkColorType,
|
2019-09-26 18:01:36 +00:00
|
|
|
kUnpremul_SkAlphaType);
|
2019-09-25 13:55:16 +00:00
|
|
|
|
|
|
|
SkAssertResult(actual.tryAlloc(readBackII));
|
|
|
|
}
|
2020-12-16 20:55:25 +00:00
|
|
|
for (GrRenderable renderableCtx : {GrRenderable::kNo, GrRenderable::kYes}) {
|
|
|
|
if (renderableCtx == GrRenderable::kYes && renderableTexture == GrRenderable::kNo) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sk_sp<GrSurfaceProxy> proxy;
|
|
|
|
if (renderableCtx == GrRenderable::kYes) {
|
|
|
|
proxy = dContext->priv().proxyProvider()->wrapRenderableBackendTexture(
|
|
|
|
backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, nullptr);
|
|
|
|
} else {
|
|
|
|
proxy = dContext->priv().proxyProvider()->wrapBackendTexture(
|
|
|
|
backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
|
|
|
|
}
|
|
|
|
if (!proxy) {
|
|
|
|
ERRORF(reporter, "Could not make proxy from backend texture");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto swizzle = dContext->priv().caps()->getReadSwizzle(backendTex.getBackendFormat(),
|
|
|
|
colorType);
|
|
|
|
GrSurfaceProxyView readView(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
|
|
|
|
GrColorInfo info(colorType, kUnpremul_SkAlphaType, nullptr);
|
|
|
|
auto surfaceContext = GrSurfaceContext::Make(dContext, readView, info);
|
|
|
|
if (!surfaceContext) {
|
|
|
|
ERRORF(reporter, "Could not create surface context for colorType: %d\n", colorType);
|
|
|
|
}
|
2019-05-23 13:38:27 +00:00
|
|
|
|
2020-12-24 01:36:44 +00:00
|
|
|
if (!surfaceContext->readPixels(dContext, actual, {0, 0})) {
|
2020-12-16 20:55:25 +00:00
|
|
|
// TODO: we need a better way to tell a priori if readPixels will work for an
|
|
|
|
// arbitrary colorType
|
2019-05-23 13:38:27 +00:00
|
|
|
#if 0
|
2020-12-16 20:55:25 +00:00
|
|
|
ERRORF(reporter, "Couldn't readback from GrSurfaceContext for colorType: %d\n",
|
|
|
|
colorType);
|
2019-06-03 16:59:40 +00:00
|
|
|
#endif
|
2020-12-16 20:55:25 +00:00
|
|
|
} else {
|
|
|
|
auto name = SkStringPrintf("%s::readPixels",
|
|
|
|
(renderableCtx == GrRenderable::kYes ? "GrSurfaceFillContext"
|
|
|
|
: "GrSurfaceContext"));
|
|
|
|
check_solid_pixmap(reporter, expectedColor, actual, colorType, label, name.c_str());
|
2019-09-26 18:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 13:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test initialization of GrBackendObjects to a specific color (non-static since used in Mtl test)
|
2020-07-17 18:15:51 +00:00
|
|
|
void test_color_init(GrDirectContext* dContext,
|
|
|
|
skiatest::Reporter* reporter,
|
2020-12-16 01:23:03 +00:00
|
|
|
std::function<sk_sp<ManagedBackendTexture>(GrDirectContext*,
|
|
|
|
const SkColor4f&,
|
|
|
|
GrMipmapped,
|
|
|
|
GrRenderable)> create,
|
2020-12-16 20:55:25 +00:00
|
|
|
GrColorType colorType,
|
2020-07-17 18:15:51 +00:00
|
|
|
const SkColor4f& color,
|
2020-12-15 21:06:26 +00:00
|
|
|
GrMipmapped mipmapped,
|
2020-12-16 01:23:03 +00:00
|
|
|
GrRenderable renderable) {
|
2020-12-15 21:06:26 +00:00
|
|
|
sk_sp<ManagedBackendTexture> mbet = create(dContext, color, mipmapped, renderable);
|
2020-12-16 01:23:03 +00:00
|
|
|
if (!mbet) {
|
2019-09-25 13:55:16 +00:00
|
|
|
// errors here should be reported by the test_wrapping test
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-13 19:32:04 +00:00
|
|
|
auto checkBackendTexture = [&](const SkColor4f& testColor) {
|
2020-12-15 21:06:26 +00:00
|
|
|
if (mipmapped == GrMipmapped::kYes) {
|
2020-12-16 20:55:25 +00:00
|
|
|
SkColor4f expectedColor = get_expected_color(testColor, colorType);
|
2020-05-13 19:32:04 +00:00
|
|
|
SkColor4f expectedColors[6] = {expectedColor, expectedColor, expectedColor,
|
|
|
|
expectedColor, expectedColor, expectedColor};
|
2020-12-16 01:23:03 +00:00
|
|
|
check_mipmaps(dContext, mbet->texture(), colorType, expectedColors, reporter,
|
|
|
|
"colorinit");
|
2020-05-13 19:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The last step in this test will dirty the mipmaps so do it last
|
2020-12-16 01:23:03 +00:00
|
|
|
check_base_readbacks(dContext, mbet->texture(), colorType, renderable, testColor, reporter,
|
2020-12-16 20:55:25 +00:00
|
|
|
"colorinit");
|
2020-05-13 19:32:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
checkBackendTexture(color);
|
|
|
|
|
|
|
|
SkColor4f newColor = {color.fB , color.fR, color.fG, color.fA };
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
SkColorType skColorType = GrColorTypeToSkColorType(colorType);
|
|
|
|
// Our update method only works with SkColorTypes.
|
|
|
|
if (skColorType != kUnknown_SkColorType) {
|
2020-12-16 01:23:03 +00:00
|
|
|
dContext->updateBackendTexture(mbet->texture(),
|
|
|
|
skColorType,
|
|
|
|
newColor,
|
|
|
|
ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext());
|
2020-12-16 20:55:25 +00:00
|
|
|
checkBackendTexture(newColor);
|
|
|
|
}
|
2019-09-24 20:32:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
// Draw the backend texture into an RGBA surface fill context, attempting to access all the mipMap
|
|
|
|
// levels.
|
|
|
|
static void check_mipmaps(GrDirectContext* dContext,
|
|
|
|
const GrBackendTexture& backendTex,
|
|
|
|
GrColorType colorType,
|
|
|
|
const SkColor4f expectedColors[6],
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
const char* label) {
|
2019-06-03 16:59:40 +00:00
|
|
|
#ifdef SK_GL
|
2019-09-24 20:32:35 +00:00
|
|
|
// skbug.com/9141 (RGBA_F32 mipmaps appear to be broken on some Mali devices)
|
2020-07-17 18:15:51 +00:00
|
|
|
if (GrBackendApi::kOpenGL == dContext->backend()) {
|
|
|
|
GrGLGpu* glGPU = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
2019-09-24 20:32:35 +00:00
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
if (colorType == GrColorType::kRGBA_F32 &&
|
|
|
|
glGPU->ctxInfo().standard() == kGLES_GrGLStandard) {
|
2019-09-24 20:32:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 13:38:27 +00:00
|
|
|
#endif
|
2019-06-03 16:59:40 +00:00
|
|
|
|
2019-09-26 18:01:36 +00:00
|
|
|
if (isRGB(backendTex.getBackendFormat())) {
|
|
|
|
// readPixels is busted for the RGB backend format (skbug.com/8862)
|
|
|
|
// TODO: add a GrColorType::kRGB_888 to fix the situation
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
GrImageInfo info(GrColorType::kRGBA_8888, kUnpremul_SkAlphaType, nullptr, {32, 32});
|
|
|
|
auto dstFillContext = GrSurfaceFillContext::Make(dContext, info);
|
|
|
|
if (!dstFillContext) {
|
|
|
|
ERRORF(reporter, "Could not make dst fill context.");
|
2019-09-24 20:32:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
int numMipLevels = 6;
|
2019-09-24 20:32:35 +00:00
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
auto proxy = dContext->priv().proxyProvider()->wrapBackendTexture(backendTex,
|
|
|
|
kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo,
|
|
|
|
kRW_GrIOType);
|
|
|
|
if (!proxy) {
|
|
|
|
ERRORF(reporter, "Could not make proxy from backend texture");
|
2019-09-24 20:32:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-12-16 20:55:25 +00:00
|
|
|
auto swizzle = dContext->priv().caps()->getReadSwizzle(backendTex.getBackendFormat(),
|
|
|
|
colorType);
|
|
|
|
GrSurfaceProxyView readView(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
|
2019-06-03 16:59:40 +00:00
|
|
|
|
2019-09-24 20:32:35 +00:00
|
|
|
for (int i = 0, rectSize = 32; i < numMipLevels; ++i, rectSize /= 2) {
|
|
|
|
SkASSERT(rectSize >= 1);
|
2020-12-16 20:55:25 +00:00
|
|
|
dstFillContext->clear(SK_PMColor4fTRANSPARENT);
|
|
|
|
|
|
|
|
SkMatrix texMatrix;
|
|
|
|
texMatrix.setScale(1 << i, 1 << i);
|
|
|
|
static constexpr GrSamplerState kNearestNearest(GrSamplerState::Filter::kNearest,
|
|
|
|
GrSamplerState::MipmapMode::kNearest);
|
|
|
|
auto fp = GrTextureEffect::Make(readView,
|
|
|
|
kUnpremul_SkAlphaType,
|
|
|
|
texMatrix,
|
|
|
|
kNearestNearest,
|
|
|
|
*dstFillContext->caps());
|
|
|
|
// Our swizzles for alpha color types currently produce (a, a, a, a) in the shader. Remove
|
|
|
|
// this once they are correctly (0, 0, 0, a).
|
|
|
|
if (GrColorTypeIsAlphaOnly(colorType)) {
|
2021-04-14 15:15:05 +00:00
|
|
|
auto black = GrFragmentProcessor::MakeColor(SK_PMColor4fBLACK);
|
2020-12-16 20:55:25 +00:00
|
|
|
fp = GrBlendFragmentProcessor::Make(std::move(fp),
|
|
|
|
std::move(black),
|
|
|
|
SkBlendMode::kModulate);
|
|
|
|
}
|
|
|
|
dstFillContext->fillRectWithFP(SkIRect::MakeWH(rectSize, rectSize), std::move(fp));
|
2019-06-03 16:59:40 +00:00
|
|
|
|
2019-09-24 20:32:35 +00:00
|
|
|
SkImageInfo readbackII = SkImageInfo::Make(rectSize, rectSize,
|
|
|
|
kRGBA_8888_SkColorType,
|
2019-09-26 18:01:36 +00:00
|
|
|
kUnpremul_SkAlphaType);
|
2020-12-16 20:55:25 +00:00
|
|
|
SkAutoPixmapStorage actual;
|
|
|
|
SkAssertResult(actual.tryAlloc(readbackII));
|
|
|
|
actual.erase(SkColors::kTransparent);
|
|
|
|
|
2020-12-24 01:36:44 +00:00
|
|
|
bool result = dstFillContext->readPixels(dContext, actual, {0, 0});
|
2019-09-24 20:32:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, result);
|
2019-06-03 16:59:40 +00:00
|
|
|
|
2019-12-18 16:16:17 +00:00
|
|
|
SkString str;
|
|
|
|
str.appendf("mip-level %d", i);
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
check_solid_pixmap(reporter, expectedColors[i], actual, colorType, label, str.c_str());
|
2019-05-23 13:38:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 18:16:39 +00:00
|
|
|
static int make_pixmaps(SkColorType skColorType,
|
|
|
|
GrMipmapped mipmapped,
|
|
|
|
const SkColor4f colors[6],
|
|
|
|
SkPixmap pixmaps[6],
|
|
|
|
std::unique_ptr<char[]>* mem) {
|
2019-09-26 18:01:36 +00:00
|
|
|
int levelSize = 32;
|
2021-01-31 18:16:39 +00:00
|
|
|
int numMipLevels = mipmapped == GrMipmapped::kYes ? 6 : 1;
|
|
|
|
size_t size = 0;
|
|
|
|
SkImageInfo ii[6];
|
|
|
|
size_t rowBytes[6];
|
2019-09-26 18:01:36 +00:00
|
|
|
for (int level = 0; level < numMipLevels; ++level) {
|
2021-01-31 18:16:39 +00:00
|
|
|
ii[level] = SkImageInfo::Make(levelSize, levelSize, skColorType, kUnpremul_SkAlphaType);
|
|
|
|
rowBytes[level] = ii[level].minRowBytes();
|
|
|
|
// Make sure we test row bytes that aren't tight.
|
|
|
|
if (!(level % 2)) {
|
|
|
|
rowBytes[level] += (level + 1)*SkColorTypeBytesPerPixel(ii[level].colorType());
|
|
|
|
}
|
|
|
|
size += rowBytes[level]*ii[level].height();
|
|
|
|
levelSize /= 2;
|
|
|
|
}
|
|
|
|
mem->reset(new char[size]);
|
|
|
|
char* addr = mem->get();
|
|
|
|
for (int level = 0; level < numMipLevels; ++level) {
|
|
|
|
pixmaps[level].reset(ii[level], addr, rowBytes[level]);
|
|
|
|
addr += rowBytes[level]*ii[level].height();
|
2019-09-26 18:01:36 +00:00
|
|
|
pixmaps[level].erase(colors[level]);
|
|
|
|
levelSize /= 2;
|
|
|
|
}
|
|
|
|
return numMipLevels;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test initialization of GrBackendObjects using SkPixmaps
|
2020-07-17 18:15:51 +00:00
|
|
|
static void test_pixmap_init(GrDirectContext* dContext,
|
|
|
|
skiatest::Reporter* reporter,
|
2020-12-16 01:23:03 +00:00
|
|
|
std::function<sk_sp<ManagedBackendTexture>(GrDirectContext*,
|
|
|
|
const SkPixmap srcData[],
|
|
|
|
int numLevels,
|
|
|
|
GrSurfaceOrigin,
|
|
|
|
GrRenderable)> create,
|
2020-07-17 18:15:51 +00:00
|
|
|
SkColorType skColorType,
|
2020-12-07 16:30:16 +00:00
|
|
|
GrSurfaceOrigin origin,
|
2021-01-31 18:16:39 +00:00
|
|
|
GrMipmapped mipmapped,
|
2020-12-16 01:23:03 +00:00
|
|
|
GrRenderable renderable) {
|
2021-01-31 18:16:39 +00:00
|
|
|
SkPixmap pixmaps[6];
|
|
|
|
std::unique_ptr<char[]> memForPixmaps;
|
2019-09-26 18:01:36 +00:00
|
|
|
SkColor4f colors[6] = {
|
|
|
|
{ 1.0f, 0.0f, 0.0f, 1.0f }, // R
|
|
|
|
{ 0.0f, 1.0f, 0.0f, 0.9f }, // G
|
|
|
|
{ 0.0f, 0.0f, 1.0f, 0.7f }, // B
|
|
|
|
{ 0.0f, 1.0f, 1.0f, 0.5f }, // C
|
|
|
|
{ 1.0f, 0.0f, 1.0f, 0.3f }, // M
|
|
|
|
{ 1.0f, 1.0f, 0.0f, 0.2f }, // Y
|
|
|
|
};
|
|
|
|
|
2021-01-31 18:16:39 +00:00
|
|
|
int numMipLevels = make_pixmaps(skColorType, mipmapped, colors, pixmaps, &memForPixmaps);
|
2019-09-26 18:01:36 +00:00
|
|
|
SkASSERT(numMipLevels);
|
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
sk_sp<ManagedBackendTexture> mbet = create(dContext, pixmaps, numMipLevels, origin, renderable);
|
|
|
|
if (!mbet) {
|
2019-09-26 18:01:36 +00:00
|
|
|
// errors here should be reported by the test_wrapping test
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
if (skColorType == kBGRA_8888_SkColorType && !isBGRA8(mbet->texture().getBackendFormat())) {
|
2019-09-26 18:01:36 +00:00
|
|
|
// When kBGRA is backed by an RGBA something goes wrong in the swizzling
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-13 19:32:04 +00:00
|
|
|
auto checkBackendTexture = [&](SkColor4f colors[6]) {
|
2020-12-16 20:55:25 +00:00
|
|
|
GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
|
2021-01-31 18:16:39 +00:00
|
|
|
if (mipmapped == GrMipmapped::kYes) {
|
2020-05-13 19:32:04 +00:00
|
|
|
SkColor4f expectedColors[6] = {
|
2020-12-16 20:55:25 +00:00
|
|
|
get_expected_color(colors[0], grColorType),
|
|
|
|
get_expected_color(colors[1], grColorType),
|
|
|
|
get_expected_color(colors[2], grColorType),
|
|
|
|
get_expected_color(colors[3], grColorType),
|
|
|
|
get_expected_color(colors[4], grColorType),
|
|
|
|
get_expected_color(colors[5], grColorType),
|
2020-05-13 19:32:04 +00:00
|
|
|
};
|
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
check_mipmaps(dContext, mbet->texture(), grColorType, expectedColors, reporter,
|
|
|
|
"pixmap");
|
2020-05-13 19:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The last step in this test will dirty the mipmaps so do it last
|
2020-12-16 01:23:03 +00:00
|
|
|
check_base_readbacks(dContext, mbet->texture(), grColorType, renderable, colors[0],
|
|
|
|
reporter, "pixmap");
|
2020-05-13 19:32:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
checkBackendTexture(colors);
|
|
|
|
|
|
|
|
SkColor4f colorsNew[6] = {
|
|
|
|
{1.0f, 1.0f, 0.0f, 0.2f}, // Y
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, // R
|
|
|
|
{0.0f, 1.0f, 0.0f, 0.9f}, // G
|
|
|
|
{0.0f, 0.0f, 1.0f, 0.7f}, // B
|
|
|
|
{0.0f, 1.0f, 1.0f, 0.5f}, // C
|
|
|
|
{1.0f, 0.0f, 1.0f, 0.3f}, // M
|
|
|
|
};
|
2021-01-31 18:16:39 +00:00
|
|
|
make_pixmaps(skColorType, mipmapped, colorsNew, pixmaps, &memForPixmaps);
|
2019-09-26 18:01:36 +00:00
|
|
|
|
2020-05-13 19:32:04 +00:00
|
|
|
// Upload new data and make sure everything still works
|
2020-12-16 01:23:03 +00:00
|
|
|
dContext->updateBackendTexture(mbet->texture(),
|
|
|
|
pixmaps,
|
|
|
|
numMipLevels,
|
|
|
|
origin,
|
|
|
|
ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext());
|
2020-05-13 19:32:04 +00:00
|
|
|
|
|
|
|
checkBackendTexture(colorsNew);
|
2019-09-26 18:01:36 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 21:58:27 +00:00
|
|
|
enum class VkLayout {
|
|
|
|
kUndefined,
|
|
|
|
kReadOnlyOptimal,
|
|
|
|
};
|
|
|
|
|
2021-04-06 19:04:35 +00:00
|
|
|
void check_vk_tiling(const GrBackendTexture& backendTex) {
|
2019-07-02 21:58:27 +00:00
|
|
|
#if defined(SK_VULKAN) && defined(SK_DEBUG)
|
|
|
|
GrVkImageInfo vkII;
|
|
|
|
if (backendTex.getVkImageInfo(&vkII)) {
|
|
|
|
SkASSERT(VK_IMAGE_TILING_OPTIMAL == vkII.fImageTiling);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2021-01-31 18:16:39 +00:00
|
|
|
void color_type_backend_allocation_test(const sk_gpu_test::ContextInfo& ctxInfo,
|
|
|
|
skiatest::Reporter* reporter) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-05-16 16:43:11 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
|
2019-05-31 16:48:49 +00:00
|
|
|
constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 0.75f };
|
2019-05-23 13:38:27 +00:00
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
struct {
|
|
|
|
SkColorType fColorType;
|
2019-05-23 13:38:27 +00:00
|
|
|
SkColor4f fColor;
|
2019-05-16 16:43:11 +00:00
|
|
|
} combinations[] = {
|
2019-09-19 20:05:48 +00:00
|
|
|
{ kAlpha_8_SkColorType, kTransCol },
|
|
|
|
{ kRGB_565_SkColorType, SkColors::kRed },
|
|
|
|
{ kARGB_4444_SkColorType, SkColors::kGreen },
|
|
|
|
{ kRGBA_8888_SkColorType, SkColors::kBlue },
|
|
|
|
{ kRGB_888x_SkColorType, SkColors::kCyan },
|
2019-05-23 13:38:27 +00:00
|
|
|
// TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul)
|
2019-09-19 20:05:48 +00:00
|
|
|
{ kBGRA_8888_SkColorType, { 1, 0, 0, 1.0f } },
|
2020-04-29 12:58:39 +00:00
|
|
|
// TODO: readback is busted for *10A2 when alpha = 0.5f (perhaps premul vs. unpremul)
|
|
|
|
{ kRGBA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
|
|
|
|
{ kBGRA_1010102_SkColorType, { 0.25f, 0.5f, 0.75f, 1.0f }},
|
|
|
|
// RGB/BGR 101010x have no Ganesh correlate
|
2019-09-19 20:05:48 +00:00
|
|
|
{ kRGB_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } },
|
2020-02-11 18:19:08 +00:00
|
|
|
{ kBGR_101010x_SkColorType, { 0, 0.5f, 0, 0.5f } },
|
2019-09-19 20:05:48 +00:00
|
|
|
{ kGray_8_SkColorType, kGrayCol },
|
|
|
|
{ kRGBA_F16Norm_SkColorType, SkColors::kLtGray },
|
|
|
|
{ kRGBA_F16_SkColorType, SkColors::kYellow },
|
|
|
|
{ kRGBA_F32_SkColorType, SkColors::kGray },
|
2019-09-26 18:01:36 +00:00
|
|
|
{ kR8G8_unorm_SkColorType, { .25f, .75f, 0, 1 } },
|
2019-09-19 20:05:48 +00:00
|
|
|
{ kR16G16_unorm_SkColorType, SkColors::kGreen },
|
|
|
|
{ kA16_unorm_SkColorType, kTransCol },
|
|
|
|
{ kA16_float_SkColorType, kTransCol },
|
2019-09-26 18:01:36 +00:00
|
|
|
{ kR16G16_float_SkColorType, { .25f, .75f, 0, 1 } },
|
2019-09-19 20:05:48 +00:00
|
|
|
{ kR16G16B16A16_unorm_SkColorType,{ .25f, .5f, .75f, 1 } },
|
2019-05-16 16:43:11 +00:00
|
|
|
};
|
|
|
|
|
2019-12-18 15:43:10 +00:00
|
|
|
static_assert(kLastEnum_SkColorType == SK_ARRAY_COUNT(combinations));
|
2019-05-16 16:43:11 +00:00
|
|
|
|
|
|
|
for (auto combo : combinations) {
|
|
|
|
SkColorType colorType = combo.fColorType;
|
|
|
|
|
|
|
|
if (GrBackendApi::kMetal == context->backend()) {
|
|
|
|
// skbug.com/9086 (Metal caps may not be handling RGBA32 correctly)
|
|
|
|
if (kRGBA_F32_SkColorType == combo.fColorType) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 20:55:25 +00:00
|
|
|
for (auto mipmapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
|
|
|
|
if (GrMipmapped::kYes == mipmapped && !caps->mipmapSupport()) {
|
2019-05-17 18:19:44 +00:00
|
|
|
continue;
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) {
|
2019-08-14 18:23:53 +00:00
|
|
|
if (!caps->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType),
|
|
|
|
renderable).isValid()) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-09-26 18:01:36 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 21:24:31 +00:00
|
|
|
{
|
2020-07-17 18:15:51 +00:00
|
|
|
auto uninitCreateMtd = [colorType](GrDirectContext* dContext,
|
2020-12-16 20:55:25 +00:00
|
|
|
GrMipmapped mipmapped,
|
2019-05-21 21:24:31 +00:00
|
|
|
GrRenderable renderable) {
|
2020-12-16 01:23:03 +00:00
|
|
|
auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
|
|
|
|
32, 32,
|
|
|
|
colorType,
|
|
|
|
mipmapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2021-04-06 19:04:35 +00:00
|
|
|
check_vk_tiling(mbet->texture());
|
2019-07-29 18:11:35 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
{
|
2020-07-17 18:15:51 +00:00
|
|
|
GrBackendFormat format = dContext->defaultBackendFormat(colorType,
|
|
|
|
renderable);
|
2020-12-16 01:23:03 +00:00
|
|
|
SkASSERT(format == mbet->texture().getBackendFormat());
|
2019-07-29 18:11:35 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
return mbet;
|
2019-05-21 21:24:31 +00:00
|
|
|
};
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-21 21:24:31 +00:00
|
|
|
test_wrapping(context, reporter, uninitCreateMtd,
|
2020-12-16 01:23:03 +00:00
|
|
|
SkColorTypeToGrColorType(colorType), mipmapped, renderable);
|
2019-05-21 21:24:31 +00:00
|
|
|
}
|
2019-05-23 13:38:27 +00:00
|
|
|
|
|
|
|
{
|
2020-12-16 01:23:03 +00:00
|
|
|
auto createWithColorMtd = [colorType](GrDirectContext* dContext,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipmapped mipmapped,
|
|
|
|
GrRenderable renderable) {
|
|
|
|
auto mbet = ManagedBackendTexture::MakeWithData(dContext,
|
|
|
|
32, 32,
|
|
|
|
colorType,
|
|
|
|
color,
|
|
|
|
mipmapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2021-04-06 19:04:35 +00:00
|
|
|
check_vk_tiling(mbet->texture());
|
2019-07-29 18:11:35 +00:00
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
{
|
2020-07-17 18:15:51 +00:00
|
|
|
GrBackendFormat format = dContext->defaultBackendFormat(colorType,
|
2019-07-29 18:11:35 +00:00
|
|
|
renderable);
|
2020-12-16 01:23:03 +00:00
|
|
|
SkASSERT(format == mbet->texture().getBackendFormat());
|
2019-07-29 18:11:35 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
return mbet;
|
2019-05-23 13:38:27 +00:00
|
|
|
};
|
|
|
|
test_color_init(context, reporter, createWithColorMtd,
|
2020-12-16 20:55:25 +00:00
|
|
|
SkColorTypeToGrColorType(colorType), combo.fColor, mipmapped,
|
2020-12-16 01:23:03 +00:00
|
|
|
renderable);
|
2019-05-23 13:38:27 +00:00
|
|
|
}
|
2019-09-26 18:01:36 +00:00
|
|
|
|
2020-12-07 16:30:16 +00:00
|
|
|
for (auto origin : {kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin}) {
|
2020-12-16 01:23:03 +00:00
|
|
|
auto createWithSrcDataMtd = [](GrDirectContext* dContext,
|
|
|
|
const SkPixmap srcData[],
|
|
|
|
int numLevels,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
GrRenderable renderable) {
|
2020-04-29 12:58:39 +00:00
|
|
|
SkASSERT(srcData && numLevels);
|
2020-12-16 01:23:03 +00:00
|
|
|
auto mbet = ManagedBackendTexture::MakeWithData(dContext,
|
|
|
|
srcData,
|
|
|
|
numLevels,
|
|
|
|
origin,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2021-04-06 19:04:35 +00:00
|
|
|
check_vk_tiling(mbet->texture());
|
2019-09-26 18:01:36 +00:00
|
|
|
#ifdef SK_DEBUG
|
2020-04-29 12:58:39 +00:00
|
|
|
{
|
2020-07-17 18:15:51 +00:00
|
|
|
auto format = dContext->defaultBackendFormat(srcData[0].colorType(),
|
|
|
|
renderable);
|
2020-12-16 01:23:03 +00:00
|
|
|
SkASSERT(format == mbet->texture().getBackendFormat());
|
2020-04-29 12:58:39 +00:00
|
|
|
}
|
2019-09-26 18:01:36 +00:00
|
|
|
#endif
|
2020-12-16 01:23:03 +00:00
|
|
|
return mbet;
|
2020-04-29 12:58:39 +00:00
|
|
|
};
|
2019-09-26 18:01:36 +00:00
|
|
|
|
2020-12-07 16:30:16 +00:00
|
|
|
test_pixmap_init(context,
|
|
|
|
reporter,
|
|
|
|
createWithSrcDataMtd,
|
|
|
|
colorType,
|
|
|
|
origin,
|
2020-12-16 20:55:25 +00:00
|
|
|
mipmapped,
|
2020-12-16 01:23:03 +00:00
|
|
|
renderable);
|
2020-04-29 12:58:39 +00:00
|
|
|
}
|
2019-05-17 18:19:44 +00:00
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 18:16:39 +00:00
|
|
|
DEF_GPUTEST(ColorTypeBackendAllocationTest, reporter, options) {
|
|
|
|
for (int t = 0; t < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++t) {
|
|
|
|
auto type = static_cast<sk_gpu_test::GrContextFactory::ContextType>(t);
|
|
|
|
if (!sk_gpu_test::GrContextFactory::IsRenderingContext(type)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sk_gpu_test::GrContextFactory factory(options);
|
|
|
|
sk_gpu_test::ContextInfo info = factory.getContextInfo(type);
|
|
|
|
if (!info.directContext()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
color_type_backend_allocation_test(info, reporter);
|
|
|
|
// The GL backend must support contexts that don't allow GL_UNPACK_ROW_LENGTH. Other
|
|
|
|
// backends are not required to work with this cap disabled.
|
|
|
|
if (info.directContext()->priv().caps()->writePixelsRowBytesSupport() &&
|
|
|
|
info.directContext()->backend() == GrBackendApi::kOpenGL) {
|
|
|
|
GrContextOptions overrideOptions = options;
|
2021-06-07 17:39:27 +00:00
|
|
|
overrideOptions.fDisallowWriteAndTransferPixelRowBytes = true;
|
2021-01-31 18:16:39 +00:00
|
|
|
sk_gpu_test::GrContextFactory overrideFactory(overrideOptions);
|
|
|
|
info = overrideFactory.getContextInfo(type);
|
|
|
|
color_type_backend_allocation_test(info, reporter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef SK_GL
|
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLBackendAllocationTest, reporter, ctxInfo) {
|
|
|
|
sk_gpu_test::GLTestContext* glCtx = ctxInfo.glContext();
|
|
|
|
GrGLStandard standard = glCtx->gl()->fStandard;
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
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
|
|
|
|
2020-12-15 21:06:26 +00:00
|
|
|
constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
|
|
|
|
constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 1.f };
|
|
|
|
constexpr SkColor4f kTransGrayCol { 0.5f, 0.5f, 0.5f, .8f };
|
2019-05-23 13:38:27 +00:00
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
struct {
|
2019-07-26 15:13:19 +00:00
|
|
|
GrColorType fColorType;
|
2019-05-16 16:43:11 +00:00
|
|
|
GrGLenum fFormat;
|
2019-05-23 13:38:27 +00:00
|
|
|
SkColor4f fColor;
|
2019-05-16 16:43:11 +00:00
|
|
|
} combinations[] = {
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGBA_8888, GR_GL_RGBA8, SkColors::kRed },
|
|
|
|
{ GrColorType::kRGBA_8888_SRGB, GR_GL_SRGB8_ALPHA8, SkColors::kRed },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGB_888x, GR_GL_RGBA8, SkColors::kYellow },
|
|
|
|
{ GrColorType::kRGB_888x, GR_GL_RGB8, SkColors::kCyan },
|
|
|
|
|
|
|
|
{ GrColorType::kBGRA_8888, GR_GL_RGBA8, SkColors::kBlue },
|
|
|
|
{ GrColorType::kBGRA_8888, GR_GL_BGRA8, SkColors::kBlue },
|
|
|
|
// TODO: readback is busted when alpha = 0.5f (perhaps premul vs. unpremul)
|
2020-04-29 12:58:39 +00:00
|
|
|
{ GrColorType::kRGBA_1010102, GR_GL_RGB10_A2, { 0.25f, 0.5f, 0.75f, 1.f }},
|
|
|
|
{ GrColorType::kBGRA_1010102, GR_GL_RGB10_A2, { 0.25f, 0.5f, 0.75f, 1.f }},
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kBGR_565, GR_GL_RGB565, SkColors::kRed },
|
|
|
|
{ GrColorType::kABGR_4444, GR_GL_RGBA4, SkColors::kGreen },
|
|
|
|
|
|
|
|
{ GrColorType::kAlpha_8, GR_GL_ALPHA8, kTransCol },
|
|
|
|
{ GrColorType::kAlpha_8, GR_GL_R8, kTransCol },
|
|
|
|
|
|
|
|
{ GrColorType::kGray_8, GR_GL_LUMINANCE8, kGrayCol },
|
|
|
|
{ GrColorType::kGray_8, GR_GL_R8, kGrayCol },
|
|
|
|
|
2020-12-15 21:06:26 +00:00
|
|
|
{ GrColorType::kGrayAlpha_88, GR_GL_LUMINANCE8_ALPHA8, kTransGrayCol },
|
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGBA_F32, GR_GL_RGBA32F, SkColors::kRed },
|
|
|
|
|
|
|
|
{ GrColorType::kRGBA_F16_Clamped, GR_GL_RGBA16F, SkColors::kLtGray },
|
|
|
|
{ GrColorType::kRGBA_F16, GR_GL_RGBA16F, SkColors::kYellow },
|
|
|
|
|
2019-09-04 19:05:35 +00:00
|
|
|
{ GrColorType::kRG_88, GR_GL_RG8, { 1, 0.5f, 0, 1 } },
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kAlpha_F16, GR_GL_R16F, { 1.0f, 0, 0, 0.5f } },
|
|
|
|
{ GrColorType::kAlpha_F16, GR_GL_LUMINANCE16F, kGrayCol },
|
|
|
|
|
2019-09-11 21:03:28 +00:00
|
|
|
{ GrColorType::kAlpha_16, GR_GL_R16, kTransCol },
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRG_1616, GR_GL_RG16, SkColors::kYellow },
|
2019-06-18 12:00:42 +00:00
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGBA_16161616, GR_GL_RGBA16, SkColors::kLtGray },
|
|
|
|
{ GrColorType::kRG_F16, GR_GL_RG16F, SkColors::kYellow },
|
2019-05-16 16:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto combo : combinations) {
|
2020-06-19 23:51:21 +00:00
|
|
|
for (GrGLenum target : {GR_GL_TEXTURE_2D, GR_GL_TEXTURE_RECTANGLE}) {
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeGL(combo.fFormat, target);
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2020-06-19 23:51:21 +00:00
|
|
|
if (!glCaps->isFormatTexturable(format)) {
|
2019-05-16 16:43:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-19 23:51:21 +00:00
|
|
|
if (GrColorType::kBGRA_8888 == combo.fColorType ||
|
|
|
|
GrColorType::kBGRA_1010102 == combo.fColorType) {
|
|
|
|
// We allow using a GL_RGBA8 or GR_GL_RGB10_A2 texture as BGRA on desktop GL but not
|
|
|
|
// ES
|
|
|
|
if (kGL_GrGLStandard != standard &&
|
|
|
|
(GR_GL_RGBA8 == combo.fFormat || GR_GL_RGB10_A2 == combo.fFormat)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-17 18:19:44 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 13:27:25 +00:00
|
|
|
for (auto mipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
|
|
|
|
if (GrMipmapped::kYes == mipMapped &&
|
2020-07-21 14:49:25 +00:00
|
|
|
(!glCaps->mipmapSupport() || target == GR_GL_TEXTURE_RECTANGLE)) {
|
2020-06-19 23:51:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2020-06-19 23:51:21 +00:00
|
|
|
for (auto renderable : {GrRenderable::kNo, GrRenderable::kYes}) {
|
|
|
|
if (GrRenderable::kYes == renderable) {
|
|
|
|
if (!glCaps->isFormatAsColorTypeRenderable(combo.fColorType, format)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-17 18:19:44 +00:00
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2020-06-19 23:51:21 +00:00
|
|
|
{
|
2020-07-17 18:15:51 +00:00
|
|
|
auto uninitCreateMtd = [format](GrDirectContext* dContext,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped mipMapped,
|
2020-06-19 23:51:21 +00:00
|
|
|
GrRenderable renderable) {
|
2020-12-16 01:23:03 +00:00
|
|
|
return ManagedBackendTexture::MakeWithoutData(dContext,
|
|
|
|
32, 32,
|
|
|
|
format,
|
|
|
|
mipMapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2020-06-19 23:51:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
test_wrapping(context, reporter, uninitCreateMtd, combo.fColorType,
|
2020-12-16 01:23:03 +00:00
|
|
|
mipMapped, renderable);
|
2020-06-19 23:51:21 +00:00
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2020-06-19 23:51:21 +00:00
|
|
|
{
|
|
|
|
// We're creating backend textures without specifying a color type "view" of
|
|
|
|
// them at the public API level. Therefore, Ganesh will not apply any
|
|
|
|
// swizzles before writing the color to the texture. However, our validation
|
|
|
|
// code does rely on interpreting the texture contents via a SkColorType and
|
|
|
|
// therefore swizzles may be applied during the read step. Ideally we'd
|
|
|
|
// update our validation code to use a "raw" read that doesn't impose a
|
|
|
|
// color type but for now we just munge the data we upload to match the
|
|
|
|
// expectation.
|
|
|
|
GrSwizzle swizzle;
|
|
|
|
switch (combo.fColorType) {
|
|
|
|
case GrColorType::kAlpha_8:
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
|
|
|
case GrColorType::kAlpha_16:
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
|
|
|
case GrColorType::kAlpha_F16:
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-12-16 01:23:03 +00:00
|
|
|
auto createWithColorMtd = [format, swizzle](GrDirectContext* dContext,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipmapped mipmapped,
|
|
|
|
GrRenderable renderable) {
|
2020-06-19 23:51:21 +00:00
|
|
|
auto swizzledColor = swizzle.applyTo(color);
|
2020-12-16 01:23:03 +00:00
|
|
|
return ManagedBackendTexture::MakeWithData(dContext,
|
|
|
|
32, 32,
|
|
|
|
format,
|
|
|
|
swizzledColor,
|
|
|
|
mipmapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2020-06-19 23:51:21 +00:00
|
|
|
};
|
|
|
|
test_color_init(context, reporter, createWithColorMtd, combo.fColorType,
|
2020-12-16 01:23:03 +00:00
|
|
|
combo.fColor, mipMapped, renderable);
|
2019-11-04 20:04:54 +00:00
|
|
|
}
|
2019-05-23 13:38:27 +00:00
|
|
|
}
|
2019-05-17 18:19:44 +00:00
|
|
|
}
|
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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-05-16 16:43:11 +00:00
|
|
|
const GrVkCaps* vkCaps = static_cast<const GrVkCaps*>(context->priv().caps());
|
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
|
2019-09-26 18:01:36 +00:00
|
|
|
constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 1 };
|
2019-05-23 13:38:27 +00:00
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
struct {
|
2019-07-26 15:13:19 +00:00
|
|
|
GrColorType fColorType;
|
2019-05-16 16:43:11 +00:00
|
|
|
VkFormat fFormat;
|
2019-05-23 13:38:27 +00:00
|
|
|
SkColor4f fColor;
|
2019-05-16 16:43:11 +00:00
|
|
|
} combinations[] = {
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGBA_8888, VK_FORMAT_R8G8B8A8_UNORM, SkColors::kRed },
|
|
|
|
{ GrColorType::kRGBA_8888_SRGB, VK_FORMAT_R8G8B8A8_SRGB, SkColors::kRed },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-31 16:48:49 +00:00
|
|
|
// In this configuration (i.e., an RGB_888x colortype with an RGBA8 backing format),
|
|
|
|
// there is nothing to tell Skia to make the provided color opaque. Clients will need
|
|
|
|
// to provide an opaque initialization color in this case.
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGB_888x, VK_FORMAT_R8G8B8A8_UNORM, SkColors::kYellow },
|
|
|
|
{ GrColorType::kRGB_888x, VK_FORMAT_R8G8B8_UNORM, SkColors::kCyan },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kBGRA_8888, VK_FORMAT_B8G8R8A8_UNORM, SkColors::kBlue },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2020-04-29 12:58:39 +00:00
|
|
|
{ GrColorType::kRGBA_1010102, VK_FORMAT_A2B10G10R10_UNORM_PACK32,
|
|
|
|
{ 0.25f, 0.5f, 0.75f, 1.0f }},
|
|
|
|
{ GrColorType::kBGRA_1010102, VK_FORMAT_A2R10G10B10_UNORM_PACK32,
|
|
|
|
{ 0.25f, 0.5f, 0.75f, 1.0f }},
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kBGR_565, VK_FORMAT_R5G6B5_UNORM_PACK16, SkColors::kRed },
|
2019-05-17 18:19:44 +00:00
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kABGR_4444, VK_FORMAT_R4G4B4A4_UNORM_PACK16, SkColors::kCyan },
|
|
|
|
{ GrColorType::kABGR_4444, VK_FORMAT_B4G4R4A4_UNORM_PACK16, SkColors::kYellow },
|
2019-05-17 18:19:44 +00:00
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kAlpha_8, VK_FORMAT_R8_UNORM, kTransCol },
|
2019-05-31 16:48:49 +00:00
|
|
|
// In this config (i.e., a Gray8 color type with an R8 backing format), there is nothing
|
|
|
|
// to tell Skia this isn't an Alpha8 color type (so it will initialize the texture with
|
|
|
|
// the alpha channel of the color). Clients should, in general, fill all the channels
|
|
|
|
// of the provided color with the same value in such cases.
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kGray_8, VK_FORMAT_R8_UNORM, kGrayCol },
|
2019-05-31 16:48:49 +00:00
|
|
|
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRGBA_F16_Clamped, VK_FORMAT_R16G16B16A16_SFLOAT, SkColors::kLtGray },
|
|
|
|
{ GrColorType::kRGBA_F16, VK_FORMAT_R16G16B16A16_SFLOAT, SkColors::kYellow },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-09-04 19:05:35 +00:00
|
|
|
{ GrColorType::kRG_88, VK_FORMAT_R8G8_UNORM, { 1, 0.5f, 0, 1 } },
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kAlpha_F16, VK_FORMAT_R16_SFLOAT, { 1.0f, 0, 0, 0.5f }},
|
|
|
|
|
2019-09-11 21:03:28 +00:00
|
|
|
{ GrColorType::kAlpha_16, VK_FORMAT_R16_UNORM, kTransCol },
|
2019-07-26 15:13:19 +00:00
|
|
|
{ GrColorType::kRG_1616, VK_FORMAT_R16G16_UNORM, SkColors::kYellow },
|
|
|
|
{ GrColorType::kRGBA_16161616, VK_FORMAT_R16G16B16A16_UNORM, SkColors::kLtGray },
|
|
|
|
{ GrColorType::kRG_F16, VK_FORMAT_R16G16_SFLOAT, SkColors::kYellow },
|
2019-05-16 16:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto combo : combinations) {
|
2019-07-08 18:24:47 +00:00
|
|
|
if (!vkCaps->isVkFormatTexturable(combo.fFormat)) {
|
2019-05-16 16:43:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeVk(combo.fFormat);
|
|
|
|
|
2020-07-21 13:27:25 +00:00
|
|
|
for (auto mipMapped : { GrMipmapped::kNo, GrMipmapped::kYes }) {
|
2020-07-21 14:49:25 +00:00
|
|
|
if (GrMipmapped::kYes == mipMapped && !vkCaps->mipmapSupport()) {
|
2019-05-17 18:19:44 +00:00
|
|
|
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) {
|
2019-08-05 16:58:39 +00:00
|
|
|
// We must also check whether we allow rendering to the format using the
|
|
|
|
// color type.
|
2019-08-06 16:05:31 +00:00
|
|
|
if (!vkCaps->isFormatAsColorTypeRenderable(
|
|
|
|
combo.fColorType, GrBackendFormat::MakeVk(combo.fFormat), 1)) {
|
2019-08-05 16:58:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 17:38:43 +00:00
|
|
|
{
|
2020-07-17 18:15:51 +00:00
|
|
|
auto uninitCreateMtd = [format](GrDirectContext* dContext,
|
2020-07-21 13:27:25 +00:00
|
|
|
GrMipmapped mipMapped,
|
2019-05-23 13:38:27 +00:00
|
|
|
GrRenderable renderable) {
|
2020-12-16 01:23:03 +00:00
|
|
|
auto mbet = ManagedBackendTexture::MakeWithoutData(dContext,
|
|
|
|
32, 32,
|
|
|
|
format,
|
|
|
|
mipMapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2021-04-06 19:04:35 +00:00
|
|
|
check_vk_tiling(mbet->texture());
|
2020-12-16 01:23:03 +00:00
|
|
|
return mbet;
|
2019-05-21 21:24:31 +00:00
|
|
|
};
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
test_wrapping(context, reporter, uninitCreateMtd, combo.fColorType, mipMapped,
|
|
|
|
renderable);
|
2019-05-21 21:24:31 +00:00
|
|
|
}
|
2019-05-23 13:38:27 +00:00
|
|
|
|
|
|
|
{
|
2019-07-09 13:36:51 +00:00
|
|
|
// We're creating backend textures without specifying a color type "view" of
|
|
|
|
// them at the public API level. Therefore, Ganesh will not apply any swizzles
|
|
|
|
// before writing the color to the texture. However, our validation code does
|
|
|
|
// rely on interpreting the texture contents via a SkColorType and therefore
|
|
|
|
// swizzles may be applied during the read step.
|
|
|
|
// Ideally we'd update our validation code to use a "raw" read that doesn't
|
|
|
|
// impose a color type but for now we just munge the data we upload to match the
|
|
|
|
// expectation.
|
|
|
|
GrSwizzle swizzle;
|
|
|
|
switch (combo.fColorType) {
|
2019-07-26 15:13:19 +00:00
|
|
|
case GrColorType::kAlpha_8:
|
2019-07-09 13:36:51 +00:00
|
|
|
SkASSERT(combo.fFormat == VK_FORMAT_R8_UNORM);
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
2019-09-11 21:03:28 +00:00
|
|
|
case GrColorType::kAlpha_16:
|
|
|
|
SkASSERT(combo.fFormat == VK_FORMAT_R16_UNORM);
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
2019-09-18 17:56:54 +00:00
|
|
|
case GrColorType::kAlpha_F16:
|
|
|
|
SkASSERT(combo.fFormat == VK_FORMAT_R16_SFLOAT);
|
|
|
|
swizzle = GrSwizzle("aaaa");
|
|
|
|
break;
|
2019-07-26 15:13:19 +00:00
|
|
|
case GrColorType::kABGR_4444:
|
2019-07-09 13:36:51 +00:00
|
|
|
if (combo.fFormat == VK_FORMAT_B4G4R4A4_UNORM_PACK16) {
|
|
|
|
swizzle = GrSwizzle("bgra");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
swizzle = GrSwizzle("rgba");
|
|
|
|
break;
|
|
|
|
}
|
2020-05-06 15:40:03 +00:00
|
|
|
|
2020-12-16 01:23:03 +00:00
|
|
|
auto createWithColorMtd = [format, swizzle](GrDirectContext* dContext,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipmapped mipMapped,
|
|
|
|
GrRenderable renderable) {
|
2019-07-09 13:36:51 +00:00
|
|
|
auto swizzledColor = swizzle.applyTo(color);
|
2020-12-16 01:23:03 +00:00
|
|
|
auto mbet = ManagedBackendTexture::MakeWithData(dContext,
|
|
|
|
32, 32,
|
|
|
|
format,
|
|
|
|
swizzledColor,
|
|
|
|
mipMapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2021-04-06 19:04:35 +00:00
|
|
|
check_vk_tiling(mbet->texture());
|
2020-12-16 01:23:03 +00:00
|
|
|
return mbet;
|
2019-05-23 13:38:27 +00:00
|
|
|
};
|
2020-12-16 01:23:03 +00:00
|
|
|
test_color_init(context, reporter, createWithColorMtd, combo.fColorType,
|
|
|
|
combo.fColor, mipMapped, renderable);
|
2019-05-23 13:38:27 +00:00
|
|
|
}
|
2019-05-17 18:19:44 +00:00
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|