Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: src/core/SkPMFloat.h

Issue 973553004: Don't guarantee any particular color order for SkPMFloat. Hide fColor. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #ifndef SkPM_DEFINED 1 #ifndef SkPM_DEFINED
2 #define SkPM_DEFINED 2 #define SkPM_DEFINED
3 3
4 #include "SkTypes.h" 4 #include "SkTypes.h"
5 #include "SkColor.h" 5 #include "SkColor.h"
6 #include "Sk4x.h" 6 #include "Sk4x.h"
7 7
8 // A pre-multiplied color in the same order as SkPMColor storing each component as a float. 8 // A pre-multiplied color storing each component as a float.
9 struct SK_STRUCT_ALIGN(16) SkPMFloat { 9 class SK_STRUCT_ALIGN(16) SkPMFloat {
10 float fColor[4]; 10 public:
11
12 // Normal POD copies and do-nothing initialization. 11 // Normal POD copies and do-nothing initialization.
13 SkPMFloat() = default; 12 SkPMFloat() = default;
14 SkPMFloat(const SkPMFloat&) = default; 13 SkPMFloat(const SkPMFloat&) = default;
15 SkPMFloat& operator=(const SkPMFloat&) = default; 14 SkPMFloat& operator=(const SkPMFloat&) = default;
16 15
17 // Freely autoconvert between SkPMFloat and Sk4f. 16 // Freely autoconvert between SkPMFloat and Sk4f.
18 /*implicit*/ SkPMFloat(const Sk4f& fs) { fs.storeAligned(fColor); } 17 /*implicit*/ SkPMFloat(const Sk4f& fs) { fs.storeAligned(fColor); }
19 /*implicit*/ operator Sk4f() const { return Sk4f::LoadAligned(fColor); } 18 /*implicit*/ operator Sk4f() const { return Sk4f::LoadAligned(fColor); }
20 19
21 float a() const { return fColor[SK_A32_SHIFT / 8]; } 20 float a() const { return fColor[SK_A32_SHIFT / 8]; }
22 float r() const { return fColor[SK_R32_SHIFT / 8]; } 21 float r() const { return fColor[SK_R32_SHIFT / 8]; }
23 float g() const { return fColor[SK_G32_SHIFT / 8]; } 22 float g() const { return fColor[SK_G32_SHIFT / 8]; }
24 float b() const { return fColor[SK_B32_SHIFT / 8]; } 23 float b() const { return fColor[SK_B32_SHIFT / 8]; }
25 24
26 void setA(float val) { fColor[SK_A32_SHIFT / 8] = val; } 25 void setA(float val) { fColor[SK_A32_SHIFT / 8] = val; }
27 void setR(float val) { fColor[SK_R32_SHIFT / 8] = val; } 26 void setR(float val) { fColor[SK_R32_SHIFT / 8] = val; }
28 void setG(float val) { fColor[SK_G32_SHIFT / 8] = val; } 27 void setG(float val) { fColor[SK_G32_SHIFT / 8] = val; }
29 void setB(float val) { fColor[SK_B32_SHIFT / 8] = val; } 28 void setB(float val) { fColor[SK_B32_SHIFT / 8] = val; }
30 29
31 void set(SkPMColor); 30 void set(SkPMColor);
32 31
33 SkPMColor get() const; // May SkASSERT(this->isValid()). 32 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen tations may clamp.
34 SkPMColor clamped() const; // Will clamp all values to [0,1], then SkASSERT (this->isValid()). 33 SkPMColor clamped() const; // Will clamp all values to [0,1], then SkASSERT (this->isValid()).
35 34
36 bool isValid() const { 35 bool isValid() const {
37 return this->a() >= 0 && this->a() <= 1 36 return this->a() >= 0 && this->a() <= 1
38 && this->r() >= 0 && this->r() <= this->a() 37 && this->r() >= 0 && this->r() <= this->a()
39 && this->g() >= 0 && this->g() <= this->a() 38 && this->g() >= 0 && this->g() <= this->a()
40 && this->b() >= 0 && this->b() <= this->a(); 39 && this->b() >= 0 && this->b() <= this->a();
41 } 40 }
41
42 private:
43 // We mirror SkPMColor order only to make set()/get()/clamped() as fast as p ossible.
44 float fColor[4];
42 }; 45 };
43 46
44 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 47 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
45 #include "../opts/SkPMFloat_SSE2.h" 48 #include "../opts/SkPMFloat_SSE2.h"
46 #elif defined(__ARM_NEON__) 49 #elif defined(__ARM_NEON__)
47 #include "../opts/SkPMFloat_neon.h" 50 #include "../opts/SkPMFloat_neon.h"
48 #else 51 #else
49 #include "../opts/SkPMFloat_none.h" 52 #include "../opts/SkPMFloat_none.h"
50 #endif 53 #endif
51 54
52 #endif//SkPM_DEFINED 55 #endif//SkPM_DEFINED
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698