1 /* 2 * Copyright 2023 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 #ifndef skgpu_GpuTypesPriv_DEFINED 9 #define skgpu_GpuTypesPriv_DEFINED 10 11 #include "include/core/SkAlphaType.h" 12 #include "include/core/SkColorType.h" 13 #include "include/core/SkTextureCompressionType.h" 14 #include "include/gpu/GpuTypes.h" 15 #include "include/private/base/SkAssert.h" 16 #include "include/private/base/SkMacros.h" 17 18 #include <chrono> 19 20 namespace skgpu { 21 22 enum class ThreadSafe : bool { 23 kNo = false, 24 kYes = true, 25 }; 26 27 // The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might 28 // not actually be monotonic, depending on how libstdc++ was built. However, this is only currently 29 // used for idle resource purging so it shouldn't cause a correctness problem. 30 #if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000) 31 using StdSteadyClock = std::chrono::monotonic_clock; 32 #else 33 using StdSteadyClock = std::chrono::steady_clock; 34 #endif 35 36 // In general we try to not mix CompressionType and ColorType, but currently SkImage still requires 37 // an SkColorType even for CompressedTypes so we need some conversion. CompressionTypeToSkColorType(SkTextureCompressionType compression)38static constexpr SkColorType CompressionTypeToSkColorType(SkTextureCompressionType compression) { 39 switch (compression) { 40 case SkTextureCompressionType::kNone: return kUnknown_SkColorType; 41 case SkTextureCompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; 42 case SkTextureCompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; 43 case SkTextureCompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; 44 case SkTextureCompressionType::kASTC_RGBA8_4x4: return kRGBA_8888_SkColorType; 45 case SkTextureCompressionType::kASTC_RGBA8_6x6: return kRGBA_8888_SkColorType; 46 case SkTextureCompressionType::kASTC_RGBA8_8x8: return kRGBA_8888_SkColorType; 47 } 48 49 SkUNREACHABLE; 50 } 51 52 // modify for support astc texture format CompressionTypeToSkAlphaType(SkTextureCompressionType compression)53static constexpr SkAlphaType CompressionTypeToSkAlphaType(SkTextureCompressionType compression) { 54 switch (compression) { 55 case SkTextureCompressionType::kNone: 56 case SkTextureCompressionType::kETC2_RGB8_UNORM: 57 case SkTextureCompressionType::kBC1_RGB8_UNORM: 58 case SkTextureCompressionType::kBC1_RGBA8_UNORM: 59 return kOpaque_SkAlphaType; 60 case SkTextureCompressionType::kASTC_RGBA8_4x4: 61 case SkTextureCompressionType::kASTC_RGBA8_6x6: 62 case SkTextureCompressionType::kASTC_RGBA8_8x8: 63 return kPremul_SkAlphaType; 64 } 65 66 SkUNREACHABLE; 67 } 68 CompressionTypeToStr(SkTextureCompressionType compression)69static constexpr const char* CompressionTypeToStr(SkTextureCompressionType compression) { 70 switch (compression) { 71 case SkTextureCompressionType::kNone: return "kNone"; 72 case SkTextureCompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; 73 case SkTextureCompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; 74 case SkTextureCompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; 75 case SkTextureCompressionType::kASTC_RGBA8_4x4: return "kASTC_RGBA8_4x4"; 76 case SkTextureCompressionType::kASTC_RGBA8_6x6: return "kASTC_RGBA8_6x6"; 77 case SkTextureCompressionType::kASTC_RGBA8_8x8: return "kASTC_RGBA8_8x8"; 78 } 79 SkUNREACHABLE; 80 } 81 BackendApiToStr(BackendApi backend)82static constexpr const char* BackendApiToStr(BackendApi backend) { 83 switch (backend) { 84 case BackendApi::kDawn: return "kDawn"; 85 case BackendApi::kMetal: return "kMetal"; 86 case BackendApi::kVulkan: return "kVulkan"; 87 case BackendApi::kMock: return "kMock"; 88 case BackendApi::kUnsupported: return "kUnsupported"; 89 } 90 SkUNREACHABLE; 91 } 92 93 SK_MAKE_BITFIELD_CLASS_OPS(GpuStatsFlags) 94 95 } // namespace skgpu 96 97 #endif // skgpu_GpuTypesPriv_DEFINED 98