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