• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_graphite_ReadSwizzle_DEFINED
9 #define skgpu_graphite_ReadSwizzle_DEFINED
10 
11 #include "src/gpu/Swizzle.h"
12 #include "src/gpu/graphite/Log.h"
13 
14 namespace skgpu::graphite {
15 /**
16  * Enumerate the few possible read and write swizzle options for smaller storage.
17 */
18 enum class ReadSwizzle {
19     kRGBA, // Default
20     kRGB1,
21     kRRR1,
22     kBGRA,
23     k000R,
24 };
25 
SwizzleClassToReadEnum(const skgpu::Swizzle & swizzle)26 inline skgpu::graphite::ReadSwizzle SwizzleClassToReadEnum(const skgpu::Swizzle& swizzle) {
27     if (swizzle == skgpu::Swizzle::RGBA()) {
28         return skgpu::graphite::ReadSwizzle::kRGBA;
29     } else if (swizzle == skgpu::Swizzle::RGB1()) {
30         return skgpu::graphite::ReadSwizzle::kRGB1;
31     } else if (swizzle == skgpu::Swizzle("rrr1")) {
32         return skgpu::graphite::ReadSwizzle::kRRR1;
33     } else if (swizzle == skgpu::Swizzle::BGRA()) {
34         return skgpu::graphite::ReadSwizzle::kBGRA;
35     } else if (swizzle == skgpu::Swizzle("000r")) {
36         return skgpu::graphite::ReadSwizzle::k000R;
37     } else {
38         SKGPU_LOG_W("%s is an unsupported read swizzle. Defaulting to RGBA.\n",
39                     swizzle.asString().data());
40         return skgpu::graphite::ReadSwizzle::kRGBA;
41     }
42 }
43 
44 } // namespace skgpu::graphite
45 
46 #endif // skgpu_graphite_ReadSwizzle_DEFINED
47