| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrSwizzle_DEFINED | 8 #ifndef GrSwizzle_DEFINED |
| 9 #define GrSwizzle_DEFINED | 9 #define GrSwizzle_DEFINED |
| 10 | 10 |
| 11 #include "GrTypes.h" | |
| 12 #include "GrColor.h" | 11 #include "GrColor.h" |
| 12 #include "SkRandom.h" |
| 13 | 13 |
| 14 /** Represents a rgba swizzle. It can be converted either into a string or a eig
ht bit int. | 14 /** Represents a rgba swizzle. It can be converted either into a string or a eig
ht bit int. |
| 15 Currently there is no way to specify an arbitrary swizzle, just some static
swizzles and an | 15 Currently there is no way to specify an arbitrary swizzle, just some static
swizzles and an |
| 16 assignment operator. That could be relaxed. */ | 16 assignment operator. That could be relaxed. */ |
| 17 class GrSwizzle { | 17 class GrSwizzle { |
| 18 public: | 18 public: |
| 19 GrSwizzle() { *this = RGBA(); } | 19 GrSwizzle() { *this = RGBA(); } |
| 20 | 20 |
| 21 GrSwizzle(const GrSwizzle& that) { *this = that; } | 21 GrSwizzle(const GrSwizzle& that) { *this = that; } |
| 22 | 22 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 static const GrSwizzle& RRRR() { | 77 static const GrSwizzle& RRRR() { |
| 78 static GrSwizzle gRRRR("rrrr"); | 78 static GrSwizzle gRRRR("rrrr"); |
| 79 return gRRRR; | 79 return gRRRR; |
| 80 } | 80 } |
| 81 | 81 |
| 82 static const GrSwizzle& BGRA() { | 82 static const GrSwizzle& BGRA() { |
| 83 static GrSwizzle gBGRA("bgra"); | 83 static GrSwizzle gBGRA("bgra"); |
| 84 return gBGRA; | 84 return gBGRA; |
| 85 } | 85 } |
| 86 | 86 |
| 87 static const GrSwizzle& CreateRandom(SkRandom* random) { |
| 88 switch (random->nextU() % 4) { |
| 89 case 0: |
| 90 return RGBA(); |
| 91 case 1: |
| 92 return BGRA(); |
| 93 case 2: |
| 94 return RRRR(); |
| 95 case 3: |
| 96 return AAAA(); |
| 97 default: |
| 98 SkFAIL("Mod is broken?!?"); |
| 99 return RGBA(); |
| 100 } |
| 101 } |
| 102 |
| 87 private: | 103 private: |
| 88 char fSwiz[5]; | 104 char fSwiz[5]; |
| 89 uint8_t fKey; | 105 uint8_t fKey; |
| 90 | 106 |
| 91 static int CharToIdx(char c) { | 107 static int CharToIdx(char c) { |
| 92 switch (c) { | 108 switch (c) { |
| 93 case 'r': | 109 case 'r': |
| 94 return (GrColor_SHIFT_R / 8); | 110 return (GrColor_SHIFT_R / 8); |
| 95 case 'g': | 111 case 'g': |
| 96 return (GrColor_SHIFT_G / 8); | 112 return (GrColor_SHIFT_G / 8); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 127 (CharToIdx(fSwiz[2]) << 4) | (CharToIdx(fSwiz[3]) << 6)); | 143 (CharToIdx(fSwiz[2]) << 4) | (CharToIdx(fSwiz[3]) << 6)); |
| 128 } | 144 } |
| 129 | 145 |
| 130 uint32_t* asUIntPtr() { return SkTCast<uint32_t*>(fSwiz); } | 146 uint32_t* asUIntPtr() { return SkTCast<uint32_t*>(fSwiz); } |
| 131 uint32_t asUInt() const { return *SkTCast<const uint32_t*>(fSwiz); } | 147 uint32_t asUInt() const { return *SkTCast<const uint32_t*>(fSwiz); } |
| 132 | 148 |
| 133 GR_STATIC_ASSERT(sizeof(char[4]) == sizeof(uint32_t)); | 149 GR_STATIC_ASSERT(sizeof(char[4]) == sizeof(uint32_t)); |
| 134 }; | 150 }; |
| 135 | 151 |
| 136 #endif | 152 #endif |
| OLD | NEW |