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

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

Issue 249643002: Revert of Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 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/SkRadialGradient.h ('k') | src/effects/gradients/SkSweepGradient.h » ('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 2012 Google Inc. 3 * Copyright 2012 Google Inc.
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 #include "SkRadialGradient.h" 9 #include "SkRadialGradient.h"
10 #include "SkRadialGradient_Table.h" 10 #include "SkRadialGradient_Table.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 : SkGradientShaderBase(desc), 150 : SkGradientShaderBase(desc),
151 fCenter(center), 151 fCenter(center),
152 fRadius(radius) 152 fRadius(radius)
153 { 153 {
154 // make sure our table is insync with our current #define for kSQRT_TABLE_SI ZE 154 // make sure our table is insync with our current #define for kSQRT_TABLE_SI ZE
155 SkASSERT(sizeof(gSqrt8Table) == kSQRT_TABLE_SIZE); 155 SkASSERT(sizeof(gSqrt8Table) == kSQRT_TABLE_SIZE);
156 156
157 rad_to_unit_matrix(center, radius, &fPtsToUnit); 157 rad_to_unit_matrix(center, radius, &fPtsToUnit);
158 } 158 }
159 159
160 size_t SkRadialGradient::contextSize() const { 160 void SkRadialGradient::shadeSpan16(int x, int y, uint16_t* dstCParam,
161 return sizeof(RadialGradientContext); 161 int count) {
162 }
163
164 SkShader::Context* SkRadialGradient::createContext(const SkBitmap& device, const SkPaint& paint,
165 const SkMatrix& matrix, void* storage) const {
166 if (!this->validContext(device, paint, matrix)) {
167 return NULL;
168 }
169
170 return SkNEW_PLACEMENT_ARGS(storage, RadialGradientContext, (*this, device, paint, matrix));
171 }
172
173 SkRadialGradient::RadialGradientContext::RadialGradientContext(
174 const SkRadialGradient& shader, const SkBitmap& device,
175 const SkPaint& paint, const SkMatrix& matrix)
176 : INHERITED(shader, device, paint, matrix) {}
177
178 void SkRadialGradient::RadialGradientContext::shadeSpan16(int x, int y, uint16_t * dstCParam,
179 int count) {
180 SkASSERT(count > 0); 162 SkASSERT(count > 0);
181 163
182 const SkRadialGradient& radialGradient = static_cast<const SkRadialGradient& >(fShader);
183
184 uint16_t* SK_RESTRICT dstC = dstCParam; 164 uint16_t* SK_RESTRICT dstC = dstCParam;
185 165
186 SkPoint srcPt; 166 SkPoint srcPt;
187 SkMatrix::MapXYProc dstProc = fDstToIndexProc; 167 SkMatrix::MapXYProc dstProc = fDstToIndexProc;
188 TileProc proc = radialGradient.fTileProc; 168 TileProc proc = fTileProc;
189 const uint16_t* SK_RESTRICT cache = fCache->getCache16(); 169 const uint16_t* SK_RESTRICT cache = this->getCache16();
190 int toggle = init_dither_toggle16(x, y); 170 int toggle = init_dither_toggle16(x, y);
191 171
192 if (fDstToIndexClass != kPerspective_MatrixClass) { 172 if (fDstToIndexClass != kPerspective_MatrixClass) {
193 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, 173 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf,
194 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); 174 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
195 175
196 SkScalar sdx = fDstToIndex.getScaleX(); 176 SkScalar sdx = fDstToIndex.getScaleX();
197 SkScalar sdy = fDstToIndex.getSkewY(); 177 SkScalar sdy = fDstToIndex.getSkewY();
198 178
199 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { 179 if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
200 SkFixed storage[2]; 180 SkFixed storage[2];
201 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), 181 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y),
202 &storage[0], &storage[1]); 182 &storage[0], &storage[1]);
203 sdx = SkFixedToScalar(storage[0]); 183 sdx = SkFixedToScalar(storage[0]);
204 sdy = SkFixedToScalar(storage[1]); 184 sdy = SkFixedToScalar(storage[1]);
205 } else { 185 } else {
206 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); 186 SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
207 } 187 }
208 188
209 RadialShade16Proc shadeProc = shadeSpan16_radial_repeat; 189 RadialShade16Proc shadeProc = shadeSpan16_radial_repeat;
210 if (SkShader::kClamp_TileMode == radialGradient.fTileMode) { 190 if (SkShader::kClamp_TileMode == fTileMode) {
211 shadeProc = shadeSpan16_radial_clamp; 191 shadeProc = shadeSpan16_radial_clamp;
212 } else if (SkShader::kMirror_TileMode == radialGradient.fTileMode) { 192 } else if (SkShader::kMirror_TileMode == fTileMode) {
213 shadeProc = shadeSpan16_radial_mirror; 193 shadeProc = shadeSpan16_radial_mirror;
214 } else { 194 } else {
215 SkASSERT(SkShader::kRepeat_TileMode == radialGradient.fTileMode); 195 SkASSERT(SkShader::kRepeat_TileMode == fTileMode);
216 } 196 }
217 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, 197 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC,
218 cache, toggle, count); 198 cache, toggle, count);
219 } else { // perspective case 199 } else { // perspective case
220 SkScalar dstX = SkIntToScalar(x); 200 SkScalar dstX = SkIntToScalar(x);
221 SkScalar dstY = SkIntToScalar(y); 201 SkScalar dstY = SkIntToScalar(y);
222 do { 202 do {
223 dstProc(fDstToIndex, dstX, dstY, &srcPt); 203 dstProc(fDstToIndex, dstX, dstY, &srcPt);
224 unsigned fi = proc(SkScalarToFixed(srcPt.length())); 204 unsigned fi = proc(SkScalarToFixed(srcPt.length()));
225 SkASSERT(fi <= 0xFFFF); 205 SkASSERT(fi <= 0xFFFF);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 382 }
403 383
404 void shadeSpan_radial_repeat(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, 384 void shadeSpan_radial_repeat(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy,
405 SkPMColor* SK_RESTRICT dstC, const SkPMColor* SK_RE STRICT cache, 385 SkPMColor* SK_RESTRICT dstC, const SkPMColor* SK_RE STRICT cache,
406 int count, int toggle) { 386 int count, int toggle) {
407 shadeSpan_radial<repeat_tileproc_nonstatic>(fx, dx, fy, dy, dstC, cache, cou nt, toggle); 387 shadeSpan_radial<repeat_tileproc_nonstatic>(fx, dx, fy, dy, dstC, cache, cou nt, toggle);
408 } 388 }
409 389
410 } // namespace 390 } // namespace
411 391
412 void SkRadialGradient::RadialGradientContext::shadeSpan(int x, int y, 392 void SkRadialGradient::shadeSpan(int x, int y,
413 SkPMColor* SK_RESTRICT d stC, int count) { 393 SkPMColor* SK_RESTRICT dstC, int count) {
414 SkASSERT(count > 0); 394 SkASSERT(count > 0);
415 395
416 const SkRadialGradient& radialGradient = static_cast<const SkRadialGradient& >(fShader);
417
418 SkPoint srcPt; 396 SkPoint srcPt;
419 SkMatrix::MapXYProc dstProc = fDstToIndexProc; 397 SkMatrix::MapXYProc dstProc = fDstToIndexProc;
420 TileProc proc = radialGradient.fTileProc; 398 TileProc proc = fTileProc;
421 const SkPMColor* SK_RESTRICT cache = fCache->getCache32(); 399 const SkPMColor* SK_RESTRICT cache = this->getCache32();
422 int toggle = init_dither_toggle(x, y); 400 int toggle = init_dither_toggle(x, y);
423 401
424 if (fDstToIndexClass != kPerspective_MatrixClass) { 402 if (fDstToIndexClass != kPerspective_MatrixClass) {
425 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, 403 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf,
426 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); 404 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
427 SkScalar sdx = fDstToIndex.getScaleX(); 405 SkScalar sdx = fDstToIndex.getScaleX();
428 SkScalar sdy = fDstToIndex.getSkewY(); 406 SkScalar sdy = fDstToIndex.getSkewY();
429 407
430 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { 408 if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
431 SkFixed storage[2]; 409 SkFixed storage[2];
432 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), 410 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y),
433 &storage[0], &storage[1]); 411 &storage[0], &storage[1]);
434 sdx = SkFixedToScalar(storage[0]); 412 sdx = SkFixedToScalar(storage[0]);
435 sdy = SkFixedToScalar(storage[1]); 413 sdy = SkFixedToScalar(storage[1]);
436 } else { 414 } else {
437 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); 415 SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
438 } 416 }
439 417
440 RadialShadeProc shadeProc = shadeSpan_radial_repeat; 418 RadialShadeProc shadeProc = shadeSpan_radial_repeat;
441 if (SkShader::kClamp_TileMode == radialGradient.fTileMode) { 419 if (SkShader::kClamp_TileMode == fTileMode) {
442 shadeProc = shadeSpan_radial_clamp; 420 shadeProc = shadeSpan_radial_clamp;
443 } else if (SkShader::kMirror_TileMode == radialGradient.fTileMode) { 421 } else if (SkShader::kMirror_TileMode == fTileMode) {
444 shadeProc = shadeSpan_radial_mirror; 422 shadeProc = shadeSpan_radial_mirror;
445 } else { 423 } else {
446 SkASSERT(SkShader::kRepeat_TileMode == radialGradient.fTileMode); 424 SkASSERT(SkShader::kRepeat_TileMode == fTileMode);
447 } 425 }
448 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, cache, count, toggle); 426 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, cache, count, toggle);
449 } else { // perspective case 427 } else { // perspective case
450 SkScalar dstX = SkIntToScalar(x); 428 SkScalar dstX = SkIntToScalar(x);
451 SkScalar dstY = SkIntToScalar(y); 429 SkScalar dstY = SkIntToScalar(y);
452 do { 430 do {
453 dstProc(fDstToIndex, dstX, dstY, &srcPt); 431 dstProc(fDstToIndex, dstX, dstY, &srcPt);
454 unsigned fi = proc(SkScalarToFixed(srcPt.length())); 432 unsigned fi = proc(SkScalarToFixed(srcPt.length()));
455 SkASSERT(fi <= 0xFFFF); 433 SkASSERT(fi <= 0xFFFF);
456 *dstC++ = cache[fi >> SkGradientShaderBase::kCache32Shift]; 434 *dstC++ = cache[fi >> SkGradientShaderBase::kCache32Shift];
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 str->appendScalar(fCenter.fY); 573 str->appendScalar(fCenter.fY);
596 str->append(") radius: "); 574 str->append(") radius: ");
597 str->appendScalar(fRadius); 575 str->appendScalar(fRadius);
598 str->append(" "); 576 str->append(" ");
599 577
600 this->INHERITED::toString(str); 578 this->INHERITED::toString(str);
601 579
602 str->append(")"); 580 str->append(")");
603 } 581 }
604 #endif 582 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkRadialGradient.h ('k') | src/effects/gradients/SkSweepGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698