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

Unified Diff: src/effects/gradients/Sk4fGradientPriv.h

Issue 1808963005: 4f linear gradient shader blitters (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: src/effects/gradients/Sk4fGradientPriv.h
diff --git a/src/effects/gradients/Sk4fGradientPriv.h b/src/effects/gradients/Sk4fGradientPriv.h
index cf7a99b265d21e60abe5ccd7f8321c104b764c66..db3595e7f87a2dbc5d98ae24e60f7bf65dfa53bb 100644
--- a/src/effects/gradients/Sk4fGradientPriv.h
+++ b/src/effects/gradients/Sk4fGradientPriv.h
@@ -9,8 +9,11 @@
#define Sk4fGradientPriv_DEFINED
#include "SkColor.h"
+#include "SkHalf.h"
+#include "SkImageInfo.h"
#include "SkNx.h"
#include "SkPM4f.h"
+#include "SkPM4fPriv.h"
// Templates shared by various 4f gradient flavors.
@@ -33,61 +36,81 @@ inline SkPMColor trunc_from_255(const Sk4f& c) {
return pmc;
}
-template<typename DstType, bool do_premul>
+template<typename DstType, SkColorProfileType, bool do_premul>
void store(const Sk4f& color, DstType* dst);
template<>
-inline void store<SkPM4f, false>(const Sk4f& c, SkPM4f* dst) {
+inline void store<SkPM4f, kLinear_SkColorProfileType, false>(const Sk4f& c, SkPM4f* dst) {
reed1 2016/03/18 14:28:59 Getting hard to remember what true and false mean
f(malita) 2016/03/18 16:54:11 Done.
c.store(dst);
}
template<>
-inline void store<SkPM4f, true>(const Sk4f& c, SkPM4f* dst) {
- store<SkPM4f, false>(premul_4f(c), dst);
+inline void store<SkPM4f, kLinear_SkColorProfileType, true>(const Sk4f& c, SkPM4f* dst) {
+ store<SkPM4f, kLinear_SkColorProfileType, false>(premul_4f(c), dst);
}
template<>
-inline void store<SkPMColor, false>(const Sk4f& c, SkPMColor* dst) {
+inline void store<SkPMColor, kLinear_SkColorProfileType, false>(const Sk4f& c, SkPMColor* dst) {
*dst = trunc_from_255<false>(c);
}
template<>
-inline void store<SkPMColor, true>(const Sk4f& c, SkPMColor* dst) {
+inline void store<SkPMColor, kLinear_SkColorProfileType, true>(const Sk4f& c, SkPMColor* dst) {
*dst = trunc_from_255<true>(c);
}
-template<typename DstType, bool do_premul>
+template<>
+inline void store<SkPMColor, kSRGB_SkColorProfileType, false>(const Sk4f& c, SkPMColor* dst) {
+ // FIXME: this assumes opaque colors. Handle unpremultiplication.
+ *dst = Sk4f_toS32(c);
+}
+
+template<>
+inline void store<SkPMColor, kSRGB_SkColorProfileType, true>(const Sk4f& c, SkPMColor* dst) {
+ const SkPMColor s32 = Sk4f_toS32(c);
+ *dst = SkPreMultiplyARGB(SkGetPackedA32(s32), SkGetPackedR32(s32),
reed1 2016/03/18 14:28:59 why not Sk4f_toS32(premul_4f(c)) ?
f(malita) 2016/03/18 16:54:11 Done.
+ SkGetPackedG32(s32), SkGetPackedB32(s32));
+}
+
+template<>
+inline void store<uint64_t, kLinear_SkColorProfileType, false>(const Sk4f& c, uint64_t* dst) {
+ *dst = SkFloatToHalf_01(c);
+}
+
+template<>
+inline void store<uint64_t, kLinear_SkColorProfileType, true>(const Sk4f& c, uint64_t* dst) {
+ store<uint64_t, kLinear_SkColorProfileType, false>(premul_4f(c), dst);
+}
+
+template<typename DstType, SkColorProfileType profile, bool do_premul>
inline void store4x(const Sk4f& c0,
const Sk4f& c1,
const Sk4f& c2,
const Sk4f& c3,
DstType* dst) {
- store<DstType, do_premul>(c0, dst++);
- store<DstType, do_premul>(c1, dst++);
- store<DstType, do_premul>(c2, dst++);
- store<DstType, do_premul>(c3, dst++);
+ store<DstType, profile, do_premul>(c0, dst++);
+ store<DstType, profile, do_premul>(c1, dst++);
+ store<DstType, profile, do_premul>(c2, dst++);
+ store<DstType, profile, do_premul>(c3, dst++);
}
template<>
-inline void store4x<SkPMColor, false>(const Sk4f& c0,
- const Sk4f& c1,
- const Sk4f& c2,
- const Sk4f& c3,
- SkPMColor* dst) {
+inline void store4x<SkPMColor, kLinear_SkColorProfileType, false>(const Sk4f& c0,
+ const Sk4f& c1,
+ const Sk4f& c2,
+ const Sk4f& c3,
+ SkPMColor* dst) {
Sk4f_ToBytes((uint8_t*)dst, c0, c1, c2, c3);
}
-template<typename DstType>
-float dst_component_scale();
-
-template<>
-inline float dst_component_scale<SkPM4f>() {
- return 1;
+template<typename DstType, SkColorProfileType>
+Sk4f scale_for_dest(const Sk4f& c) {
+ return c;
}
template<>
-inline float dst_component_scale<SkPMColor>() {
- return 255;
+inline Sk4f scale_for_dest<SkPMColor, kLinear_SkColorProfileType>(const Sk4f& c) {
+ return c * 255;
}
template<typename DstType>
@@ -103,6 +126,11 @@ inline Sk4f dst_swizzle<SkPMColor>(const SkPM4f& c) {
return c.to4f_pmorder();
}
+template<>
+inline Sk4f dst_swizzle<uint64_t>(const SkPM4f& c) {
+ return c.to4f();
+}
+
}
#endif // Sk4fGradientPriv_DEFINED

Powered by Google App Engine
This is Rietveld 408576698