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

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

Powered by Google App Engine
This is Rietveld 408576698