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

Unified Diff: src/core/SkPMFloat.h

Issue 977773002: Update SkPMFloat API a bit. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 32 Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/PMFloatBench.cpp ('k') | src/opts/SkPMFloat_SSE2.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPMFloat.h
diff --git a/src/core/SkPMFloat.h b/src/core/SkPMFloat.h
index 585b6abb76cfd8b956fa24c3f14ce1dba4a33507..444cb78fc8c77d516ee5ccda2cf1aacbb2ba888a 100644
--- a/src/core/SkPMFloat.h
+++ b/src/core/SkPMFloat.h
@@ -5,13 +5,31 @@
#include "SkColor.h"
#include "Sk4x.h"
-// A pre-multiplied color storing each component as a float in the range [0, 255].
+// A pre-multiplied color storing each component in the same order as SkPMColor,
+// but as a float in the range [0, 255].
class SK_STRUCT_ALIGN(16) SkPMFloat {
public:
- // Normal POD copies and do-nothing initialization.
- SkPMFloat() = default;
- SkPMFloat(const SkPMFloat&) = default;
- SkPMFloat& operator=(const SkPMFloat&) = default;
+ static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); }
+ static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMFloat(a,r,g,b); }
+
+ explicit SkPMFloat(SkPMColor);
+ SkPMFloat(float a, float r, float g, float b) {
+ // TODO: faster when specialized?
+ fColor[SK_A32_SHIFT / 8] = a;
+ fColor[SK_R32_SHIFT / 8] = r;
+ fColor[SK_G32_SHIFT / 8] = g;
+ fColor[SK_B32_SHIFT / 8] = b;
+ }
+
+ // Uninitialized.
+ SkPMFloat() {}
+
+ // Copy and assign are fastest if we remind the compiler we work best as Sk4f.
+ SkPMFloat(const SkPMFloat& that) { Sk4f(that).storeAligned(fColor); }
+ SkPMFloat& operator=(const SkPMFloat& that) {
+ Sk4f(that).storeAligned(fColor);
+ return *this;
+ }
// Freely autoconvert between SkPMFloat and Sk4f.
/*implicit*/ SkPMFloat(const Sk4f& fs) { fs.storeAligned(fColor); }
@@ -22,13 +40,6 @@ public:
float g() const { return fColor[SK_G32_SHIFT / 8]; }
float b() const { return fColor[SK_B32_SHIFT / 8]; }
- void setA(float val) { fColor[SK_A32_SHIFT / 8] = val; }
- void setR(float val) { fColor[SK_R32_SHIFT / 8] = val; }
- void setG(float val) { fColor[SK_G32_SHIFT / 8] = val; }
- void setB(float val) { fColor[SK_B32_SHIFT / 8] = val; }
-
- void set(SkPMColor);
-
// get() and clamped() round component values to the nearest integer.
SkPMColor get() const; // May SkASSERT(this->isValid()). Some implementations may clamp.
SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may assert isValid().
@@ -41,7 +52,6 @@ public:
}
private:
- // We mirror SkPMColor order only to make set()/get()/clamped() as fast as possible.
float fColor[4];
};
« no previous file with comments | « bench/PMFloatBench.cpp ('k') | src/opts/SkPMFloat_SSE2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698