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

Unified Diff: include/gpu/GrColor.h

Issue 2088303002: Add GrColor4f type, store that in GrPaint. Linearize based on global flag. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix conversion to SkColor4f with new channel order Created 4 years, 6 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 | « no previous file | include/gpu/GrPaint.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/gpu/GrColor.h
diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h
index 77f1a6cb0841aa84d1f073ea7265d28438cc2b02..911b18fc16024cf44381006fbce4f25346db1f7d 100644
--- a/include/gpu/GrColor.h
+++ b/include/gpu/GrColor.h
@@ -169,6 +169,54 @@ static inline GrColor GrUnpremulColor(GrColor color) {
return GrColorPackRGBA(r, g, b, a);
}
+
+/**
+* Similarly, GrColor4f is 4 floats for R, G, B, A, in that order. And like GrColor, whether
+* the color is premultiplied or not depends on the context.
+*/
+struct GrColor4f {
+ float fRGBA[4];
+
+ GrColor4f() {}
+ GrColor4f(float r, float g, float b, float a) {
+ fRGBA[0] = r;
+ fRGBA[1] = g;
+ fRGBA[2] = b;
+ fRGBA[3] = a;
+ }
+
+ static GrColor4f FromGrColor(GrColor color) {
+ GrColor4f result;
+ GrColorToRGBAFloat(color, result.fRGBA);
+ return result;
+ }
+
+ static GrColor4f FromSkColor4f(const SkColor4f& color) {
+ return GrColor4f(color.fR, color.fG, color.fB, color.fA);
+ }
+
+ GrColor toGrColor() const {
+ return GrColorPackRGBA(
+ SkTPin<unsigned>(static_cast<unsigned>(fRGBA[0] * 255.0f + 0.5f), 0, 255),
+ SkTPin<unsigned>(static_cast<unsigned>(fRGBA[1] * 255.0f + 0.5f), 0, 255),
+ SkTPin<unsigned>(static_cast<unsigned>(fRGBA[2] * 255.0f + 0.5f), 0, 255),
+ SkTPin<unsigned>(static_cast<unsigned>(fRGBA[3] * 255.0f + 0.5f), 0, 255));
+ }
+
+ SkColor4f toSkColor4f() const {
+ return SkColor4f { fRGBA[0], fRGBA[1], fRGBA[2], fRGBA[3] };
+ }
+
+ GrColor4f opaque() const {
+ return GrColor4f(fRGBA[0], fRGBA[1], fRGBA[2], 1.0f);
+ }
+
+ GrColor4f premul() const {
+ float a = fRGBA[3];
+ return GrColor4f(fRGBA[0] * a, fRGBA[1] * a, fRGBA[2] * a, a);
+ }
+};
+
/**
* Flags used for bitfields of color components. They are defined so that the bit order reflects the
* GrColor shift order.
« no previous file with comments | « no previous file | include/gpu/GrPaint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698