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

Side by Side Diff: src/effects/gradients/SkLinearGradient.cpp

Issue 1688543002: Initial linear gradient 4f impl (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « src/effects/gradients/SkLinearGradient.h ('k') | 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 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Sk4fLinearGradient.h"
8 #include "SkLinearGradient.h" 9 #include "SkLinearGradient.h"
9 10
11 // define to test the 4f gradient path
12 // #define USE_4fGRADIENTS
13
10 static const float kInv255Float = 1.0f / 255; 14 static const float kInv255Float = 1.0f / 255;
11 15
12 static inline int repeat_8bits(int x) { 16 static inline int repeat_8bits(int x) {
13 return x & 0xFF; 17 return x & 0xFF;
14 } 18 }
15 19
16 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly. 20 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly.
17 // See http://code.google.com/p/skia/issues/detail?id=472 21 // See http://code.google.com/p/skia/issues/detail?id=472
18 #if defined(_MSC_VER) && (_MSC_VER >= 1600) 22 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
19 #pragma optimize("", off) 23 #pragma optimize("", off)
(...skipping 16 matching lines...) Expand all
36 SkScalar inv = mag ? SkScalarInvert(mag) : 0; 40 SkScalar inv = mag ? SkScalarInvert(mag) : 0;
37 41
38 vec.scale(inv); 42 vec.scale(inv);
39 SkMatrix matrix; 43 SkMatrix matrix;
40 matrix.setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); 44 matrix.setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY);
41 matrix.postTranslate(-pts[0].fX, -pts[0].fY); 45 matrix.postTranslate(-pts[0].fX, -pts[0].fY);
42 matrix.postScale(inv, inv); 46 matrix.postScale(inv, inv);
43 return matrix; 47 return matrix;
44 } 48 }
45 49
50 static bool use_4f_context(uint32_t flags) {
51 #ifdef USE_4fGRADIENTS
52 return true;
53 #else
54 return SkToBool(flags & SkLinearGradient::kForce4fContext_PrivateFlag);
55 #endif
56 }
57
46 /////////////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////////////
47 59
48 SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc) 60 SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc)
49 : SkGradientShaderBase(desc, pts_to_unit_matrix(pts)) 61 : SkGradientShaderBase(desc, pts_to_unit_matrix(pts))
50 , fStart(pts[0]) 62 , fStart(pts[0])
51 , fEnd(pts[1]) { 63 , fEnd(pts[1]) {
52 } 64 }
53 65
54 SkFlattenable* SkLinearGradient::CreateProc(SkReadBuffer& buffer) { 66 SkFlattenable* SkLinearGradient::CreateProc(SkReadBuffer& buffer) {
55 DescriptorScope desc; 67 DescriptorScope desc;
56 if (!desc.unflatten(buffer)) { 68 if (!desc.unflatten(buffer)) {
57 return nullptr; 69 return nullptr;
58 } 70 }
59 SkPoint pts[2]; 71 SkPoint pts[2];
60 pts[0] = buffer.readPoint(); 72 pts[0] = buffer.readPoint();
61 pts[1] = buffer.readPoint(); 73 pts[1] = buffer.readPoint();
62 return SkGradientShader::CreateLinear(pts, desc.fColors, desc.fPos, desc.fCo unt, 74 return SkGradientShader::CreateLinear(pts, desc.fColors, desc.fPos, desc.fCo unt,
63 desc.fTileMode, desc.fGradFlags, desc. fLocalMatrix); 75 desc.fTileMode, desc.fGradFlags, desc. fLocalMatrix);
64 } 76 }
65 77
66 void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { 78 void SkLinearGradient::flatten(SkWriteBuffer& buffer) const {
67 this->INHERITED::flatten(buffer); 79 this->INHERITED::flatten(buffer);
68 buffer.writePoint(fStart); 80 buffer.writePoint(fStart);
69 buffer.writePoint(fEnd); 81 buffer.writePoint(fEnd);
70 } 82 }
71 83
72 size_t SkLinearGradient::contextSize() const { 84 size_t SkLinearGradient::contextSize() const {
73 return sizeof(LinearGradientContext); 85 return use_4f_context(fGradFlags)
86 ? sizeof(LinearGradient4fContext)
87 : sizeof(LinearGradientContext);
74 } 88 }
75 89
76 SkShader::Context* SkLinearGradient::onCreateContext(const ContextRec& rec, void * storage) const { 90 SkShader::Context* SkLinearGradient::onCreateContext(const ContextRec& rec, void * storage) const {
77 return new (storage) LinearGradientContext(*this, rec); 91 return use_4f_context(fGradFlags)
92 ? static_cast<SkShader::Context*>(new (storage) LinearGradient4fContext( *this, rec))
93 : static_cast<SkShader::Context*>(new (storage) LinearGradientContext(*t his, rec));
78 } 94 }
79 95
80 // This swizzles SkColor into the same component order as SkPMColor, but does no t actually 96 // This swizzles SkColor into the same component order as SkPMColor, but does no t actually
81 // "pre" multiply the color components. 97 // "pre" multiply the color components.
82 // 98 //
83 // This allows us to map directly to Sk4f, and eventually scale down to bytes to output a 99 // This allows us to map directly to Sk4f, and eventually scale down to bytes to output a
84 // SkPMColor from the floats, without having to swizzle each time. 100 // SkPMColor from the floats, without having to swizzle each time.
85 // 101 //
86 static uint32_t SkSwizzle_Color_to_PMColor(SkColor c) { 102 static uint32_t SkSwizzle_Color_to_PMColor(SkColor c) {
87 return SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), S kColorGetB(c)); 103 return SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), S kColorGetB(c));
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r); 755 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r);
740 } 756 }
741 } else { 757 } else {
742 if (fApplyAlphaAfterInterp) { 758 if (fApplyAlphaAfterInterp) {
743 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r); 759 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r);
744 } else { 760 } else {
745 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er); 761 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er);
746 } 762 }
747 } 763 }
748 } 764 }
OLDNEW
« no previous file with comments | « src/effects/gradients/SkLinearGradient.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698