/* * 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 #include "src/gpu/mtl/GrMtlCaps.h" // In BackendAllocationTest.cpp void test_wrapping(GrContext* context, skiatest::Reporter* reporter, std::function create, GrColorType colorType, GrMipMapped mipMapped, GrRenderable renderable); void test_color_init(GrContext* context, skiatest::Reporter* reporter, std::function create, GrColorType colorType, const SkColor4f& color, GrMipMapped mipMapped, GrRenderable renderable); DEF_GPUTEST_FOR_METAL_CONTEXT(MtlBackendAllocationTest, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); const GrMtlCaps* mtlCaps = static_cast(context->priv().caps()); constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f }; struct { GrColorType fColorType; MTLPixelFormat fFormat; SkColor4f fColor; } combinations[] = { { GrColorType::kRGBA_8888, MTLPixelFormatRGBA8Unorm, SkColors::kRed }, { GrColorType::kRGBA_8888_SRGB, MTLPixelFormatRGBA8Unorm_sRGB, SkColors::kRed }, { GrColorType::kRGB_888x, MTLPixelFormatRGBA8Unorm, { 1, 1, 0, 0.5f } }, { GrColorType::kBGRA_8888, MTLPixelFormatBGRA8Unorm, SkColors::kBlue }, { GrColorType::kRGBA_1010102, MTLPixelFormatRGB10A2Unorm, { 0.5f, 0, 0, 1.0f } }, #ifdef SK_BUILD_FOR_IOS { GrColorType::kBGR_565, MTLPixelFormatB5G6R5Unorm, SkColors::kRed }, { GrColorType::kABGR_4444, MTLPixelFormatABGR4Unorm, SkColors::kGreen }, #endif { GrColorType::kAlpha_8, MTLPixelFormatA8Unorm, kTransCol }, { GrColorType::kAlpha_8, MTLPixelFormatR8Unorm, kTransCol }, { GrColorType::kGray_8, MTLPixelFormatR8Unorm, SkColors::kDkGray }, { GrColorType::kRGBA_F32, MTLPixelFormatRGBA32Float, SkColors::kRed }, { GrColorType::kRGBA_F16_Clamped, MTLPixelFormatRGBA16Float, SkColors::kLtGray }, { GrColorType::kRGBA_F16, MTLPixelFormatRGBA16Float, SkColors::kYellow }, { GrColorType::kRG_88, MTLPixelFormatRG8Unorm, { 0.5f, 0.5f, 0, 0 } }, { GrColorType::kAlpha_F16, MTLPixelFormatR16Float, { 1.0f, 0, 0, 0.5f } }, { GrColorType::kR_16, MTLPixelFormatR16Unorm, SkColors::kRed }, { GrColorType::kRG_1616, MTLPixelFormatRG16Unorm, SkColors::kYellow }, // Experimental (for Y416 and mutant P016/P010) { GrColorType::kRGBA_16161616, MTLPixelFormatRGBA16Unorm, SkColors::kLtGray }, { GrColorType::kRG_F16, MTLPixelFormatRG16Float, SkColors::kYellow }, #ifdef SK_BUILD_FOR_IOS { GrColorType::kUnknown, MTLPixelFormatETC2_RGB8, SkColors::kRed } #endif }; for (auto combo : combinations) { GrBackendFormat format = GrBackendFormat::MakeMtl(combo.fFormat); if (!mtlCaps->isFormatTexturable(combo.fFormat)) { continue; } // skbug.com/9086 (Metal caps may not be handling RGBA32 correctly) if (GrColorType::kRGBA_F32 == combo.fColorType) { continue; } for (auto mipMapped : { GrMipMapped::kNo, GrMipMapped::kYes }) { if (GrMipMapped::kYes == mipMapped && !mtlCaps->mipMapSupport()) { continue; } for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) { if (GrRenderable::kYes == renderable) { if (GrColorType::kRGB_888x == combo.fColorType) { // Ganesh can't perform the blends correctly when rendering this format continue; } if (!mtlCaps->isFormatRenderable(combo.fFormat)) { continue; } } #ifdef SK_BUILD_FOR_IOS // We current disallow uninitialized compressed textures in the Metal backend if (combo.fFormat != MTLPixelFormatETC2_RGB8) #endif { auto uninitCreateMtd = [format](GrContext* context, GrMipMapped mipMapped, GrRenderable renderable) { return context->createBackendTexture(32, 32, format, mipMapped, renderable, GrProtected::kNo); }; test_wrapping(context, reporter, uninitCreateMtd, combo.fColorType, mipMapped, renderable); } // 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 } } } }