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

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

Issue 207683004: 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: rebase & cleanup 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
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 "SkTwoPointRadialGradient.h" 9 #include "SkTwoPointRadialGradient.h"
10 10
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if (info) { 213 if (info) {
214 commonAsAGradient(info); 214 commonAsAGradient(info);
215 info->fPoint[0] = fCenter1; 215 info->fPoint[0] = fCenter1;
216 info->fPoint[1] = fCenter2; 216 info->fPoint[1] = fCenter2;
217 info->fRadius[0] = fRadius1; 217 info->fRadius[0] = fRadius1;
218 info->fRadius[1] = fRadius2; 218 info->fRadius[1] = fRadius2;
219 } 219 }
220 return kRadial2_GradientType; 220 return kRadial2_GradientType;
221 } 221 }
222 222
223 void SkTwoPointRadialGradient::shadeSpan(int x, int y, SkPMColor* dstCParam, 223 size_t SkTwoPointRadialGradient::contextSize() const {
224 int count) { 224 return sizeof(TwoPointRadialGradientContext);
225 }
226
227 bool SkTwoPointRadialGradient::validContext(const SkBitmap& device, const SkPain t& paint,
228 const SkMatrix& matrix) const {
229 // For now, we might have divided by zero, so detect that.
230 if (0 == fDiffRadius) {
231 return false;
232 }
233
234 return this->INHERITED::validContext(device, paint, matrix);
235 }
236
237 SkShader::Context* SkTwoPointRadialGradient::createContext(
238 const SkBitmap& device, const SkPaint& paint,
239 const SkMatrix& matrix, void* storage) const {
240 if (!this->validContext(device, paint, matrix)) {
241 return NULL;
242 }
243
244 return SkNEW_PLACEMENT_ARGS(storage, TwoPointRadialGradientContext, (*this, device, paint, matrix));
scroggo 2014/04/03 15:35:54 100 chars.
Dominik Grewe 2014/04/04 10:59:41 Done.
245 }
246
247 SkTwoPointRadialGradient::TwoPointRadialGradientContext::TwoPointRadialGradientC ontext(
248 const SkTwoPointRadialGradient& shader, const SkBitmap& device,
249 const SkPaint& paint, const SkMatrix& matrix)
250 : INHERITED(shader, device, paint, matrix)
251 {
252 // we don't have a span16 proc
253 fFlags &= ~kHasSpan16_Flag;
254 }
255
256 void SkTwoPointRadialGradient::TwoPointRadialGradientContext::shadeSpan(
257 int x, int y, SkPMColor* dstCParam, int count) {
225 SkASSERT(count > 0); 258 SkASSERT(count > 0);
226 259
260 const SkTwoPointRadialGradient& twoPointRadialGradient =
261 static_cast<const SkTwoPointRadialGradient&>(fShader);
262
227 SkPMColor* SK_RESTRICT dstC = dstCParam; 263 SkPMColor* SK_RESTRICT dstC = dstCParam;
228 264
229 // Zero difference between radii: fill with transparent black. 265 // Zero difference between radii: fill with transparent black.
230 if (fDiffRadius == 0) { 266 if (twoPointRadialGradient.fDiffRadius == 0) {
231 sk_bzero(dstC, count * sizeof(*dstC)); 267 sk_bzero(dstC, count * sizeof(*dstC));
232 return; 268 return;
233 } 269 }
234 SkMatrix::MapXYProc dstProc = fDstToIndexProc; 270 SkMatrix::MapXYProc dstProc = fDstToIndexProc;
235 TileProc proc = fTileProc; 271 TileProc proc = twoPointRadialGradient.fTileProc;
236 const SkPMColor* SK_RESTRICT cache = this->getCache32(); 272 const SkPMColor* SK_RESTRICT cache = fCache.getCache32(twoPointRadialGradien t);
237 273
238 SkScalar foura = fA * 4; 274 SkScalar foura = twoPointRadialGradient.fA * 4;
239 bool posRoot = fDiffRadius < 0; 275 bool posRoot = twoPointRadialGradient.fDiffRadius < 0;
240 if (fDstToIndexClass != kPerspective_MatrixClass) { 276 if (fDstToIndexClass != kPerspective_MatrixClass) {
241 SkPoint srcPt; 277 SkPoint srcPt;
242 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, 278 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf,
243 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); 279 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
244 SkScalar dx, fx = srcPt.fX; 280 SkScalar dx, fx = srcPt.fX;
245 SkScalar dy, fy = srcPt.fY; 281 SkScalar dy, fy = srcPt.fY;
246 282
247 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { 283 if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
248 SkFixed fixedX, fixedY; 284 SkFixed fixedX, fixedY;
249 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &fixedX, &fixedY); 285 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &fixedX, &fixedY);
250 dx = SkFixedToScalar(fixedX); 286 dx = SkFixedToScalar(fixedX);
251 dy = SkFixedToScalar(fixedY); 287 dy = SkFixedToScalar(fixedY);
252 } else { 288 } else {
253 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); 289 SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
254 dx = fDstToIndex.getScaleX(); 290 dx = fDstToIndex.getScaleX();
255 dy = fDstToIndex.getSkewY(); 291 dy = fDstToIndex.getSkewY();
256 } 292 }
257 SkScalar b = (SkScalarMul(fDiff.fX, fx) + 293 SkScalar b = (SkScalarMul(twoPointRadialGradient.fDiff.fX, fx) +
258 SkScalarMul(fDiff.fY, fy) - fStartRadius) * 2; 294 SkScalarMul(twoPointRadialGradient.fDiff.fY, fy) -
259 SkScalar db = (SkScalarMul(fDiff.fX, dx) + 295 twoPointRadialGradient.fStartRadius) * 2;
260 SkScalarMul(fDiff.fY, dy)) * 2; 296 SkScalar db = (SkScalarMul(twoPointRadialGradient.fDiff.fX, dx) +
297 SkScalarMul(twoPointRadialGradient.fDiff.fY, dy)) * 2;
261 298
262 TwoPointRadialShadeProc shadeProc = shadeSpan_twopoint_repeat; 299 TwoPointRadialShadeProc shadeProc = shadeSpan_twopoint_repeat;
263 if (SkShader::kClamp_TileMode == fTileMode) { 300 if (SkShader::kClamp_TileMode == twoPointRadialGradient.fTileMode) {
264 shadeProc = shadeSpan_twopoint_clamp; 301 shadeProc = shadeSpan_twopoint_clamp;
265 } else if (SkShader::kMirror_TileMode == fTileMode) { 302 } else if (SkShader::kMirror_TileMode == twoPointRadialGradient.fTileMod e) {
266 shadeProc = shadeSpan_twopoint_mirror; 303 shadeProc = shadeSpan_twopoint_mirror;
267 } else { 304 } else {
268 SkASSERT(SkShader::kRepeat_TileMode == fTileMode); 305 SkASSERT(SkShader::kRepeat_TileMode == twoPointRadialGradient.fTileM ode);
269 } 306 }
270 (*shadeProc)(fx, dx, fy, dy, b, db, 307 (*shadeProc)(fx, dx, fy, dy, b, db,
271 fSr2D2, foura, fOneOverTwoA, posRoot, 308 twoPointRadialGradient.fSr2D2, foura,
309 twoPointRadialGradient.fOneOverTwoA, posRoot,
272 dstC, cache, count); 310 dstC, cache, count);
273 } else { // perspective case 311 } else { // perspective case
274 SkScalar dstX = SkIntToScalar(x); 312 SkScalar dstX = SkIntToScalar(x);
275 SkScalar dstY = SkIntToScalar(y); 313 SkScalar dstY = SkIntToScalar(y);
276 for (; count > 0; --count) { 314 for (; count > 0; --count) {
277 SkPoint srcPt; 315 SkPoint srcPt;
278 dstProc(fDstToIndex, dstX, dstY, &srcPt); 316 dstProc(fDstToIndex, dstX, dstY, &srcPt);
279 SkScalar fx = srcPt.fX; 317 SkScalar fx = srcPt.fX;
280 SkScalar fy = srcPt.fY; 318 SkScalar fy = srcPt.fY;
281 SkScalar b = (SkScalarMul(fDiff.fX, fx) + 319 SkScalar b = (SkScalarMul(twoPointRadialGradient.fDiff.fX, fx) +
282 SkScalarMul(fDiff.fY, fy) - fStartRadius) * 2; 320 SkScalarMul(twoPointRadialGradient.fDiff.fY, fy) -
283 SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, 321 twoPointRadialGradient.fStartRadius) * 2;
284 fOneOverTwoA, posRoot); 322 SkFixed t = two_point_radial(b, fx, fy, twoPointRadialGradient.fSr2D 2, foura,
323 twoPointRadialGradient.fOneOverTwoA, po sRoot);
285 SkFixed index = proc(t); 324 SkFixed index = proc(t);
286 SkASSERT(index <= 0xFFFF); 325 SkASSERT(index <= 0xFFFF);
287 *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift]; 326 *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift];
288 dstX += SK_Scalar1; 327 dstX += SK_Scalar1;
289 } 328 }
290 } 329 }
291 } 330 }
292 331
293 bool SkTwoPointRadialGradient::setContext( const SkBitmap& device,
294 const SkPaint& paint,
295 const SkMatrix& matrix){
296 // For now, we might have divided by zero, so detect that
297 if (0 == fDiffRadius) {
298 return false;
299 }
300
301 if (!this->INHERITED::setContext(device, paint, matrix)) {
302 return false;
303 }
304
305 // we don't have a span16 proc
306 fFlags &= ~kHasSpan16_Flag;
307 return true;
308 }
309
310 #ifndef SK_IGNORE_TO_STRING 332 #ifndef SK_IGNORE_TO_STRING
311 void SkTwoPointRadialGradient::toString(SkString* str) const { 333 void SkTwoPointRadialGradient::toString(SkString* str) const {
312 str->append("SkTwoPointRadialGradient: ("); 334 str->append("SkTwoPointRadialGradient: (");
313 335
314 str->append("center1: ("); 336 str->append("center1: (");
315 str->appendScalar(fCenter1.fX); 337 str->appendScalar(fCenter1.fX);
316 str->append(", "); 338 str->append(", ");
317 str->appendScalar(fCenter1.fY); 339 str->appendScalar(fCenter1.fY);
318 str->append(") radius1: "); 340 str->append(") radius1: ");
319 str->appendScalar(fRadius1); 341 str->appendScalar(fRadius1);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 704 }
683 705
684 #else 706 #else
685 707
686 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c onst { 708 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c onst {
687 SkDEBUGFAIL("Should not call in GPU-less build"); 709 SkDEBUGFAIL("Should not call in GPU-less build");
688 return NULL; 710 return NULL;
689 } 711 }
690 712
691 #endif 713 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698