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/private/base/SkAssert.h" 14 15 #include <chrono> 16 17 namespace skgpu { 18 19 // The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might 20 // not actually be monotonic, depending on how libstdc++ was built. However, this is only currently 21 // used for idle resource purging so it shouldn't cause a correctness problem. 22 #if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000) 23 using StdSteadyClock = std::chrono::monotonic_clock; 24 #else 25 using StdSteadyClock = std::chrono::steady_clock; 26 #endif 27 28 // In general we try to not mix CompressionType and ColorType, but currently SkImage still requires 29 // an SkColorType even for CompressedTypes so we need some conversion. CompressionTypeToSkColorType(SkTextureCompressionType compression)30static constexpr SkColorType CompressionTypeToSkColorType(SkTextureCompressionType compression) { 31 switch (compression) { 32 case SkTextureCompressionType::kNone: return kUnknown_SkColorType; 33 case SkTextureCompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType; 34 case SkTextureCompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType; 35 case SkTextureCompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType; 36 } 37 38 SkUNREACHABLE; 39 } 40 CompressionTypeToStr(SkTextureCompressionType compression)41static constexpr const char* CompressionTypeToStr(SkTextureCompressionType compression) { 42 switch (compression) { 43 case SkTextureCompressionType::kNone: return "kNone"; 44 case SkTextureCompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM"; 45 case SkTextureCompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM"; 46 case SkTextureCompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM"; 47 } 48 SkUNREACHABLE; 49 } 50 51 } // namespace skgpu 52 53 #endif // skgpu_GpuTypesPriv_DEFINED 54