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

Side by Side Diff: src/animator/SkDrawGradient.cpp

Issue 283273002: remove unused (by clients) SkUnitMapper (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix legacy call Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/animator/SkDrawGradient.h ('k') | src/core/SkReadBuffer.cpp » ('j') | 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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkDrawGradient.h" 10 #include "SkDrawGradient.h"
11 #include "SkAnimateMaker.h" 11 #include "SkAnimateMaker.h"
12 #include "SkAnimatorScript.h" 12 #include "SkAnimatorScript.h"
13 #include "SkGradientShader.h" 13 #include "SkGradientShader.h"
14 #include "SkUnitMapper.h"
15
16 static SkScalar SkUnitToScalar(U16CPU x) {
17 return x / 65535.0f;
18 }
19
20 static U16CPU SkScalarToUnit(SkScalar x) {
21 SkScalar pin = SkScalarPin(x, 0, SK_Scalar1);
22 return (int) (pin * 65535.0f);
23 }
24
25 class SkDrawGradientUnitMapper : public SkUnitMapper {
26 public:
27 SkDrawGradientUnitMapper(SkAnimateMaker* maker, const char* script) : fMaker (maker), fScript(script) {
28 }
29
30 SK_DECLARE_UNFLATTENABLE_OBJECT()
31
32 protected:
33 virtual uint16_t mapUnit16(uint16_t x) {
34 fUnit = SkUnitToScalar(x);
35 SkScriptValue value;
36 SkAnimatorScript engine(*fMaker, NULL, SkType_Float);
37 engine.propertyCallBack(GetUnitValue, &fUnit);
38 if (engine.evaluate(fScript, &value, SkType_Float))
39 x = SkScalarToUnit(value.fOperand.fScalar);
40 return x;
41 }
42
43 static bool GetUnitValue(const char* token, size_t len, void* unitPtr, SkScr iptValue* value) {
44 if (SK_LITERAL_STR_EQUAL("unit", token, len)) {
45 value->fOperand.fScalar = *(SkScalar*) unitPtr;
46 value->fType = SkType_Float;
47 return true;
48 }
49 return false;
50 }
51
52 SkAnimateMaker* fMaker;
53 const char* fScript;
54 SkScalar fUnit;
55 };
56
57 14
58 #if SK_USE_CONDENSED_INFO == 0 15 #if SK_USE_CONDENSED_INFO == 0
59 16
60 const SkMemberInfo SkDrawGradient::fInfo[] = { 17 const SkMemberInfo SkDrawGradient::fInfo[] = {
61 SK_MEMBER_INHERITED, 18 SK_MEMBER_INHERITED,
62 SK_MEMBER_ARRAY(offsets, Float), 19 SK_MEMBER_ARRAY(offsets, Float),
63 SK_MEMBER(unitMapper, String) 20 SK_MEMBER(unitMapper, String)
64 }; 21 };
65 22
66 #endif 23 #endif
67 24
68 DEFINE_GET_MEMBER(SkDrawGradient); 25 DEFINE_GET_MEMBER(SkDrawGradient);
69 26
70 SkDrawGradient::SkDrawGradient() : fUnitMapper(NULL) { 27 SkDrawGradient::SkDrawGradient() {
71 } 28 }
72 29
73 SkDrawGradient::~SkDrawGradient() { 30 SkDrawGradient::~SkDrawGradient() {
74 for (int index = 0; index < fDrawColors.count(); index++) 31 for (int index = 0; index < fDrawColors.count(); index++)
75 delete fDrawColors[index]; 32 delete fDrawColors[index];
76 delete fUnitMapper;
77 } 33 }
78 34
79 bool SkDrawGradient::addChild(SkAnimateMaker& , SkDisplayable* child) { 35 bool SkDrawGradient::addChild(SkAnimateMaker& , SkDisplayable* child) {
80 SkASSERT(child); 36 SkASSERT(child);
81 if (child->isColor()) { 37 if (child->isColor()) {
82 SkDrawColor* color = (SkDrawColor*) child; 38 SkDrawColor* color = (SkDrawColor*) child;
83 *fDrawColors.append() = color; 39 *fDrawColors.append() = color;
84 return true; 40 return true;
85 } 41 }
86 return false; 42 return false;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (offsets[i] <= offsets[i-1]) { 87 if (offsets[i] <= offsets[i-1]) {
132 maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsMust Increase); 88 maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsMust Increase);
133 return; 89 return;
134 } 90 }
135 if (offsets[i] > SK_Scalar1) { 91 if (offsets[i] > SK_Scalar1) {
136 maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsMust BeNoMoreThanOne); 92 maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsMust BeNoMoreThanOne);
137 return; 93 return;
138 } 94 }
139 } 95 }
140 } 96 }
141 if (unitMapper.size() > 0)
142 fUnitMapper = new SkDrawGradientUnitMapper(&maker, unitMapper.c_str());
143 INHERITED::onEndElement(maker); 97 INHERITED::onEndElement(maker);
144 } 98 }
145 99
146 #if SK_USE_CONDENSED_INFO == 0 100 #if SK_USE_CONDENSED_INFO == 0
147 101
148 const SkMemberInfo SkDrawLinearGradient::fInfo[] = { 102 const SkMemberInfo SkDrawLinearGradient::fInfo[] = {
149 SK_MEMBER_INHERITED, 103 SK_MEMBER_INHERITED,
150 SK_MEMBER_ARRAY(points, Float), 104 SK_MEMBER_ARRAY(points, Float),
151 }; 105 };
152 106
(...skipping 16 matching lines...) Expand all
169 dumpBase(maker); 123 dumpBase(maker);
170 dumpRest(maker); 124 dumpRest(maker);
171 } 125 }
172 #endif 126 #endif
173 127
174 SkShader* SkDrawLinearGradient::getShader() { 128 SkShader* SkDrawLinearGradient::getShader() {
175 if (addPrelude() == 0 || points.count() != 4) 129 if (addPrelude() == 0 || points.count() != 4)
176 return NULL; 130 return NULL;
177 SkShader* shader = SkGradientShader::CreateLinear((SkPoint*)points.begin(), 131 SkShader* shader = SkGradientShader::CreateLinear((SkPoint*)points.begin(),
178 fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode, 132 fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode,
179 fUnitMapper, 0, getMatrix()); 133 0, getMatrix());
180 SkAutoTDelete<SkShader> autoDel(shader); 134 SkAutoTDelete<SkShader> autoDel(shader);
181 (void)autoDel.detach(); 135 (void)autoDel.detach();
182 return shader; 136 return shader;
183 } 137 }
184 138
185 139
186 #if SK_USE_CONDENSED_INFO == 0 140 #if SK_USE_CONDENSED_INFO == 0
187 141
188 const SkMemberInfo SkDrawRadialGradient::fInfo[] = { 142 const SkMemberInfo SkDrawRadialGradient::fInfo[] = {
189 SK_MEMBER_INHERITED, 143 SK_MEMBER_INHERITED,
(...skipping 14 matching lines...) Expand all
204 dumpBase(maker); 158 dumpBase(maker);
205 dumpRest(maker); 159 dumpRest(maker);
206 } 160 }
207 #endif 161 #endif
208 162
209 SkShader* SkDrawRadialGradient::getShader() { 163 SkShader* SkDrawRadialGradient::getShader() {
210 if (addPrelude() == 0) 164 if (addPrelude() == 0)
211 return NULL; 165 return NULL;
212 SkShader* shader = SkGradientShader::CreateRadial(center, 166 SkShader* shader = SkGradientShader::CreateRadial(center,
213 radius, fColors.begin(), offsets.begin(), fColors.count(), (SkShader::Ti leMode) tileMode, 167 radius, fColors.begin(), offsets.begin(), fColors.count(), (SkShader::Ti leMode) tileMode,
214 fUnitMapper, 0, getMatrix()); 168 0, getMatrix());
215 SkAutoTDelete<SkShader> autoDel(shader); 169 SkAutoTDelete<SkShader> autoDel(shader);
216 (void)autoDel.detach(); 170 (void)autoDel.detach();
217 return shader; 171 return shader;
218 } 172 }
OLDNEW
« no previous file with comments | « src/animator/SkDrawGradient.h ('k') | src/core/SkReadBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698