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

Unified Diff: src/effects/gradients/SkLinearGradient.cpp

Issue 1725793003: Update 4f linear gradient selection heuristic (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: spelling Created 4 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 | « no previous file | tests/SkColor4fTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkLinearGradient.cpp
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 1fbd96e40ebc5a2a75b58a8983016f08c4f97de3..cc8875cf8e83c69b939f7c268a07270b9a7d25c2 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -9,7 +9,7 @@
#include "SkLinearGradient.h"
// define to test the 4f gradient path
-// #define USE_4fGRADIENTS
+// #define FORCE_4F_CONTEXT
static const float kInv255Float = 1.0f / 255;
@@ -47,11 +47,18 @@ static SkMatrix pts_to_unit_matrix(const SkPoint pts[2]) {
return matrix;
}
-static bool use_4f_context(uint32_t flags) {
-#ifdef USE_4fGRADIENTS
+static bool use_4f_context(const SkShader::ContextRec& rec, uint32_t flags) {
+#ifdef FORCE_4F_CONTEXT
return true;
#else
- return SkToBool(flags & SkLinearGradient::kForce4fContext_PrivateFlag);
+ // Perspective not supported in 4f yet.
+ if (rec.fMatrix->hasPerspective()
+ || (rec.fLocalMatrix && rec.fLocalMatrix->hasPerspective())) {
+ return false;
+ }
+
+ return rec.fPreferredDstType == SkShader::ContextRec::kPM4f_DstType
+ || SkToBool(flags & SkLinearGradient::kForce4fContext_PrivateFlag);
#endif
}
@@ -81,14 +88,14 @@ void SkLinearGradient::flatten(SkWriteBuffer& buffer) const {
buffer.writePoint(fEnd);
}
-size_t SkLinearGradient::contextSize(const ContextRec&) const {
- return use_4f_context(fGradFlags)
+size_t SkLinearGradient::contextSize(const ContextRec& rec) const {
+ return use_4f_context(rec, fGradFlags)
? sizeof(LinearGradient4fContext)
: sizeof(LinearGradientContext);
}
SkShader::Context* SkLinearGradient::onCreateContext(const ContextRec& rec, void* storage) const {
- return use_4f_context(fGradFlags)
+ return use_4f_context(rec, fGradFlags)
? static_cast<SkShader::Context*>(new (storage) LinearGradient4fContext(*this, rec))
: static_cast<SkShader::Context*>(new (storage) LinearGradientContext(*this, rec));
}
« no previous file with comments | « no previous file | tests/SkColor4fTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698