| 1 |
/* |
| 2 |
* Copyright 2019 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "src/gpu/ganesh/mock/GrMockCaps.h" |
| 9 |
|
| 10 |
#include "include/private/base/SkDebug.h" |
| 11 |
#include "src/base/SkMathPriv.h" |
| 12 |
#include "src/gpu/ganesh/GrProgramDesc.h" |
| 13 |
#include "src/gpu/ganesh/TestFormatColorTypeCombination.h" |
| 14 |
|
| 15 |
int GrMockCaps::getRenderTargetSampleCount(int requestCount, GrColorType ct) const { |
| 16 |
requestCount = std::max(requestCount, 1); |
| 17 |
|
| 18 |
switch (fOptions.fConfigOptions[(int)ct].fRenderability) { |
| 19 |
case GrMockOptions::ConfigOptions::Renderability::kNo: |
| 20 |
return 0; |
| 21 |
case GrMockOptions::ConfigOptions::Renderability::kNonMSAA: |
| 22 |
return requestCount > 1 ? 0 : 1; |
| 23 |
case GrMockOptions::ConfigOptions::Renderability::kMSAA: |
| 24 |
return requestCount > kMaxSampleCnt ? 0 : SkNextPow2(requestCount); |
| 25 |
} |
| 26 |
return 0; |
| 27 |
} |
| 28 |
|
| 29 |
GrProgramDesc GrMockCaps::makeDesc(GrRenderTarget* /* rt */, |
| 30 |
const GrProgramInfo& programInfo, |
| 31 |
ProgramDescOverrideFlags overrideFlags) const { |
| 32 |
SkASSERT(overrideFlags == ProgramDescOverrideFlags::kNone); |
| 33 |
GrProgramDesc desc; |
| 34 |
GrProgramDesc::Build(&desc, programInfo, *this); |
| 35 |
return desc; |
| 36 |
} |
| 37 |
|
| 38 |
uint64_t GrMockCaps::computeFormatKey(const GrBackendFormat& format) const { |
| 39 |
#ifdef SK_DEBUG |
| 40 |
SkTextureCompressionType compression = format.asMockCompressionType(); |
| 41 |
SkASSERT(compression == SkTextureCompressionType::kNone); |
| 42 |
#endif |
| 43 |
auto ct = format.asMockColorType(); |
| 44 |
return (uint64_t)ct; |
| 45 |
} |
| 46 |
|
| 47 |
#if defined(GPU_TEST_UTILS) |
| 48 |
std::vector<GrTest::TestFormatColorTypeCombination> GrMockCaps::getTestingCombinations() const { |
| 49 |
// TODO: need to add compressed formats to this list |
| 50 |
std::vector<GrTest::TestFormatColorTypeCombination> combos = { |
| 51 |
{ GrColorType::kAlpha_8, GrBackendFormat::MakeMock(GrColorType::kAlpha_8, |
| 52 |
SkTextureCompressionType::kNone)}, |
| 53 |
{ GrColorType::kBGR_565, GrBackendFormat::MakeMock(GrColorType::kBGR_565, |
| 54 |
SkTextureCompressionType::kNone)}, |
| 55 |
{ GrColorType::kRGB_565, GrBackendFormat::MakeMock(GrColorType::kRGB_565, |
| 56 |
SkTextureCompressionType::kNone)}, |
| 57 |
{ GrColorType::kABGR_4444, GrBackendFormat::MakeMock(GrColorType::kABGR_4444, |
| 58 |
SkTextureCompressionType::kNone)}, |
| 59 |
{ GrColorType::kRGBA_8888, GrBackendFormat::MakeMock(GrColorType::kRGBA_8888, |
| 60 |
SkTextureCompressionType::kNone)}, |
| 61 |
{ GrColorType::kRGBA_8888_SRGB, GrBackendFormat::MakeMock(GrColorType::kRGBA_8888_SRGB, |
| 62 |
SkTextureCompressionType::kNone)}, |
| 63 |
{ GrColorType::kRGB_888x, GrBackendFormat::MakeMock(GrColorType::kRGB_888x, |
| 64 |
SkTextureCompressionType::kNone)}, |
| 65 |
{ GrColorType::kRG_88, GrBackendFormat::MakeMock(GrColorType::kRG_88, |
| 66 |
SkTextureCompressionType::kNone)}, |
| 67 |
{ GrColorType::kBGRA_8888, GrBackendFormat::MakeMock(GrColorType::kBGRA_8888, |
| 68 |
SkTextureCompressionType::kNone)}, |
| 69 |
{ GrColorType::kRGBA_1010102, GrBackendFormat::MakeMock(GrColorType::kRGBA_1010102, |
| 70 |
SkTextureCompressionType::kNone)}, |
| 71 |
{ GrColorType::kBGRA_1010102, GrBackendFormat::MakeMock(GrColorType::kBGRA_1010102, |
| 72 |
SkTextureCompressionType::kNone)}, |
| 73 |
{ GrColorType::kGray_8, GrBackendFormat::MakeMock(GrColorType::kGray_8, |
| 74 |
SkTextureCompressionType::kNone)}, |
| 75 |
{ GrColorType::kAlpha_F16, GrBackendFormat::MakeMock(GrColorType::kAlpha_F16, |
| 76 |
SkTextureCompressionType::kNone)}, |
| 77 |
{ GrColorType::kRGBA_F16, GrBackendFormat::MakeMock(GrColorType::kRGBA_F16, |
| 78 |
SkTextureCompressionType::kNone)}, |
| 79 |
{ GrColorType::kRGBA_F16_Clamped,GrBackendFormat::MakeMock(GrColorType::kRGBA_F16_Clamped, |
| 80 |
SkTextureCompressionType::kNone)}, |
| 81 |
{ GrColorType::kRGB_F16F16F16x, GrBackendFormat::MakeMock(GrColorType::kRGB_F16F16F16x, |
| 82 |
SkTextureCompressionType::kNone)}, |
| 83 |
{ GrColorType::kAlpha_16, GrBackendFormat::MakeMock(GrColorType::kAlpha_16, |
| 84 |
SkTextureCompressionType::kNone)}, |
| 85 |
{ GrColorType::kRG_1616, GrBackendFormat::MakeMock(GrColorType::kRG_1616, |
| 86 |
SkTextureCompressionType::kNone)}, |
| 87 |
{ GrColorType::kRGBA_16161616, GrBackendFormat::MakeMock(GrColorType::kRGBA_16161616, |
| 88 |
SkTextureCompressionType::kNone)}, |
| 89 |
{ GrColorType::kRG_F16, GrBackendFormat::MakeMock(GrColorType::kRG_F16, |
| 90 |
SkTextureCompressionType::kNone)}, |
| 91 |
// For these two compressed image formats the color type will effectively be RGB_888x |
| 92 |
{ GrColorType::kRGB_888x, GrBackendFormat::MakeMock(GrColorType::kUnknown, |
| 93 |
SkTextureCompressionType::kETC2_RGB8_UNORM)}, |
| 94 |
{ GrColorType::kRGB_888x, GrBackendFormat::MakeMock(GrColorType::kUnknown, |
| 95 |
SkTextureCompressionType::kBC1_RGB8_UNORM)}, |
| 96 |
{ GrColorType::kRGBA_8888, GrBackendFormat::MakeMock(GrColorType::kUnknown, |
| 97 |
SkTextureCompressionType::kBC1_RGBA8_UNORM)}, |
| 98 |
}; |
| 99 |
|
| 100 |
#ifdef SK_DEBUG |
| 101 |
for (const GrTest::TestFormatColorTypeCombination& combo : combos) { |
| 102 |
SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat)); |
| 103 |
} |
| 104 |
#endif |
| 105 |
|
| 106 |
return combos; |
| 107 |
} |
| 108 |
|
| 109 |
#endif |