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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
#import <metal/metal.h>
|
2019-05-17 18:19:44 +00:00
|
|
|
#include "src/gpu/mtl/GrMtlCaps.h"
|
2019-05-16 16:43:11 +00:00
|
|
|
|
|
|
|
// In BackendAllocationTest.cpp
|
|
|
|
void test_wrapping(GrContext* context, skiatest::Reporter* reporter,
|
2019-05-23 13:38:27 +00:00
|
|
|
std::function<GrBackendTexture (GrContext*,
|
|
|
|
GrMipMapped,
|
|
|
|
GrRenderable)> create,
|
2019-05-17 18:19:44 +00:00
|
|
|
SkColorType colorType, GrMipMapped mipMapped, GrRenderable renderable);
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
void test_color_init(GrContext* context, skiatest::Reporter* reporter,
|
|
|
|
std::function<GrBackendTexture (GrContext*,
|
|
|
|
const SkColor4f&,
|
|
|
|
GrMipMapped,
|
|
|
|
GrRenderable)> create,
|
|
|
|
SkColorType colorType, const SkColor4f& color,
|
|
|
|
GrMipMapped mipMapped, GrRenderable renderable);
|
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
DEF_GPUTEST_FOR_METAL_CONTEXT(MtlBackendAllocationTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
2019-05-17 18:19:44 +00:00
|
|
|
const GrMtlCaps* mtlCaps = static_cast<const GrMtlCaps*>(context->priv().caps());
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
|
|
|
|
|
2019-05-16 16:43:11 +00:00
|
|
|
struct {
|
|
|
|
SkColorType fColorType;
|
|
|
|
GrMTLPixelFormat fFormat;
|
|
|
|
// TODO: remove 'fConfig' and directly use 'fFormat' in GrMtlCaps::isFormatTexturable
|
|
|
|
GrPixelConfig fConfig;
|
2019-05-23 13:38:27 +00:00
|
|
|
SkColor4f fColor;
|
2019-05-16 16:43:11 +00:00
|
|
|
} combinations[] = {
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kRGBA_8888_SkColorType, MTLPixelFormatRGBA8Unorm,
|
|
|
|
kRGBA_8888_GrPixelConfig, SkColors::kRed },
|
|
|
|
{ kRGBA_8888_SkColorType, MTLPixelFormatRGBA8Unorm_sRGB,
|
|
|
|
kSRGBA_8888_GrPixelConfig, SkColors::kRed },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kRGB_888x_SkColorType, MTLPixelFormatRGBA8Unorm,
|
|
|
|
kRGBA_8888_GrPixelConfig, { 1, 1, 0, 0.5f } },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kBGRA_8888_SkColorType, MTLPixelFormatBGRA8Unorm,
|
|
|
|
kBGRA_8888_GrPixelConfig, SkColors::kBlue },
|
|
|
|
{ kBGRA_8888_SkColorType, MTLPixelFormatBGRA8Unorm_sRGB,
|
|
|
|
kSBGRA_8888_GrPixelConfig, SkColors::kCyan },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kRGBA_1010102_SkColorType, MTLPixelFormatRGB10A2Unorm,
|
|
|
|
kRGBA_1010102_GrPixelConfig, { 0.5f, 0, 0, 1.0f } },
|
2019-05-16 16:43:11 +00:00
|
|
|
#ifdef SK_BUILD_FOR_IOS
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kRGB_565_SkColorType, MTLPixelFormatB5G6R5Unorm,
|
|
|
|
kRGB_565_GrPixelConfig, SkColors::kRed },
|
|
|
|
{ kARGB_4444_SkColorType, MTLPixelFormatABGR4Unorm,
|
|
|
|
kRGBA_4444_GrPixelConfig, SkColors::kGreen },
|
2019-05-16 16:43:11 +00:00
|
|
|
#endif
|
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kAlpha_8_SkColorType, MTLPixelFormatA8Unorm,
|
|
|
|
kAlpha_8_as_Alpha_GrPixelConfig, kTransCol },
|
|
|
|
{ kAlpha_8_SkColorType, MTLPixelFormatR8Unorm,
|
|
|
|
kAlpha_8_as_Red_GrPixelConfig, kTransCol },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kGray_8_SkColorType, MTLPixelFormatR8Unorm,
|
|
|
|
kGray_8_as_Red_GrPixelConfig, SkColors::kDkGray },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kRGBA_F32_SkColorType, MTLPixelFormatRGBA32Float,
|
|
|
|
kRGBA_float_GrPixelConfig, SkColors::kRed },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kRGBA_F16Norm_SkColorType, MTLPixelFormatRGBA16Float,
|
|
|
|
kRGBA_half_Clamped_GrPixelConfig, SkColors::kLtGray },
|
|
|
|
{ kRGBA_F16_SkColorType, MTLPixelFormatRGBA16Float,
|
|
|
|
kRGBA_half_GrPixelConfig, SkColors::kYellow },
|
2019-05-16 16:43:11 +00:00
|
|
|
|
|
|
|
// These backend formats don't have SkColorType equivalents
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kUnknown_SkColorType, MTLPixelFormatRG32Float,
|
|
|
|
kRG_float_GrPixelConfig, { 0.7f, 0.7f, 0, 0 }},
|
|
|
|
{ kUnknown_SkColorType, MTLPixelFormatRG8Unorm,
|
|
|
|
kRG_88_GrPixelConfig, { 0.5f, 0.5f, 0, 0 }},
|
|
|
|
{ kUnknown_SkColorType, MTLPixelFormatR16Float,
|
|
|
|
kAlpha_half_as_Red_GrPixelConfig, { 1.0f, 0, 0, 0.5f }},
|
2019-05-16 16:43:11 +00:00
|
|
|
#ifdef SK_BUILD_FOR_IOS
|
2019-05-23 13:38:27 +00:00
|
|
|
{ kUnknown_SkColorType, MTLPixelFormatETC2_RGB8,
|
|
|
|
kRGB_ETC1_GrPixelConfig, SkColors::kRed }
|
2019-05-16 16:43:11 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto combo : combinations) {
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeMtl(combo.fFormat);
|
|
|
|
|
2019-05-17 18:19:44 +00:00
|
|
|
if (!mtlCaps->isConfigTexturable(combo.fConfig)) {
|
2019-05-16 16:43:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 && !mtlCaps->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 (!mtlCaps->isConfigRenderable(combo.fConfig)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 21:24:31 +00:00
|
|
|
{
|
|
|
|
auto uninitCreateMtd = [format](GrContext* context,
|
|
|
|
GrMipMapped mipMapped,
|
|
|
|
GrRenderable renderable) {
|
|
|
|
return context->createBackendTexture(32, 32, format,
|
|
|
|
mipMapped, renderable);
|
|
|
|
};
|
|
|
|
|
|
|
|
test_wrapping(context, reporter, uninitCreateMtd,
|
|
|
|
combo.fColorType, mipMapped, renderable);
|
|
|
|
}
|
2019-05-23 13:38:27 +00:00
|
|
|
|
|
|
|
// Not implemented for Metal yet
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
auto createWithColorMtd = [format](GrContext* context,
|
|
|
|
const SkColor4f& color,
|
|
|
|
GrMipMapped mipMapped,
|
|
|
|
GrRenderable renderable) {
|
|
|
|
return context->priv().createBackendTexture(32, 32, format, color,
|
|
|
|
mipMapped, renderable);
|
|
|
|
};
|
|
|
|
|
|
|
|
test_color_init(context, reporter, createWithColorMtd,
|
|
|
|
combo.fColorType, combo.fColor, mipMapped, renderable);
|
|
|
|
}
|
|
|
|
#endif
|
2019-05-17 18:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-21 21:24:31 +00:00
|
|
|
}
|
2019-05-16 16:43:11 +00:00
|
|
|
}
|