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

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

Issue 793763003: Gradient shaders: make fPtsToUnit const, pre-cache getType(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift]; 160 *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift];
161 fx += dx; 161 fx += dx;
162 fy += dy; 162 fy += dy;
163 b += db; 163 b += db;
164 } 164 }
165 } 165 }
166 } 166 }
167 167
168 ///////////////////////////////////////////////////////////////////// 168 /////////////////////////////////////////////////////////////////////
169 169
170 static SkMatrix pts_to_unit(const SkPoint& start, SkScalar diffRadius) {
171 SkScalar inv = diffRadius ? SkScalarInvert(diffRadius) : 0;
172 SkMatrix matrix;
173 matrix.setTranslate(-start.fX, -start.fY);
174 matrix.postScale(inv, inv);
175 return matrix;
176 }
177
170 SkTwoPointRadialGradient::SkTwoPointRadialGradient(const SkPoint& start, SkScala r startRadius, 178 SkTwoPointRadialGradient::SkTwoPointRadialGradient(const SkPoint& start, SkScala r startRadius,
171 const SkPoint& end, SkScalar endRadius, 179 const SkPoint& end, SkScalar endRadius,
172 const Descriptor& desc) 180 const Descriptor& desc)
173 : SkGradientShaderBase(desc) 181 : SkGradientShaderBase(desc, pts_to_unit(start, endRadius - startRadius))
174 , fCenter1(start) 182 , fCenter1(start)
175 , fCenter2(end) 183 , fCenter2(end)
176 , fRadius1(startRadius) 184 , fRadius1(startRadius)
177 , fRadius2(endRadius) 185 , fRadius2(endRadius)
178 { 186 {
179 init(); 187 fDiff = fCenter1 - fCenter2;
188 fDiffRadius = fRadius2 - fRadius1;
189 // hack to avoid zero-divide for now
190 SkScalar inv = fDiffRadius ? SkScalarInvert(fDiffRadius) : 0;
191 fDiff.fX = SkScalarMul(fDiff.fX, inv);
192 fDiff.fY = SkScalarMul(fDiff.fY, inv);
193 fStartRadius = SkScalarMul(fRadius1, inv);
194 fSr2D2 = SkScalarSquare(fStartRadius);
195 fA = SkScalarSquare(fDiff.fX) + SkScalarSquare(fDiff.fY) - SK_Scalar1;
196 fOneOverTwoA = fA ? SkScalarInvert(fA * 2) : 0;
180 } 197 }
181 198
182 SkShader::BitmapType SkTwoPointRadialGradient::asABitmap( 199 SkShader::BitmapType SkTwoPointRadialGradient::asABitmap(
183 SkBitmap* bitmap, 200 SkBitmap* bitmap,
184 SkMatrix* matrix, 201 SkMatrix* matrix,
185 SkShader::TileMode* xy) const { 202 SkShader::TileMode* xy) const {
186 if (bitmap) { 203 if (bitmap) {
187 this->getGradientTableBitmap(bitmap); 204 this->getGradientTableBitmap(bitmap);
188 } 205 }
189 SkScalar diffL = 0; // just to avoid gcc warning 206 SkScalar diffL = 0; // just to avoid gcc warning
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 376
360 void SkTwoPointRadialGradient::flatten( 377 void SkTwoPointRadialGradient::flatten(
361 SkWriteBuffer& buffer) const { 378 SkWriteBuffer& buffer) const {
362 this->INHERITED::flatten(buffer); 379 this->INHERITED::flatten(buffer);
363 buffer.writePoint(fCenter1); 380 buffer.writePoint(fCenter1);
364 buffer.writePoint(fCenter2); 381 buffer.writePoint(fCenter2);
365 buffer.writeScalar(fRadius1); 382 buffer.writeScalar(fRadius1);
366 buffer.writeScalar(fRadius2); 383 buffer.writeScalar(fRadius2);
367 } 384 }
368 385
369 void SkTwoPointRadialGradient::init() {
370 fDiff = fCenter1 - fCenter2;
371 fDiffRadius = fRadius2 - fRadius1;
372 // hack to avoid zero-divide for now
373 SkScalar inv = fDiffRadius ? SkScalarInvert(fDiffRadius) : 0;
374 fDiff.fX = SkScalarMul(fDiff.fX, inv);
375 fDiff.fY = SkScalarMul(fDiff.fY, inv);
376 fStartRadius = SkScalarMul(fRadius1, inv);
377 fSr2D2 = SkScalarSquare(fStartRadius);
378 fA = SkScalarSquare(fDiff.fX) + SkScalarSquare(fDiff.fY) - SK_Scalar1;
379 fOneOverTwoA = fA ? SkScalarInvert(fA * 2) : 0;
380
381 fPtsToUnit.setTranslate(-fCenter1.fX, -fCenter1.fY);
382 fPtsToUnit.postScale(inv, inv);
383 }
384
385 ///////////////////////////////////////////////////////////////////// 386 /////////////////////////////////////////////////////////////////////
386 387
387 #if SK_SUPPORT_GPU 388 #if SK_SUPPORT_GPU
388 389
389 #include "SkGr.h" 390 #include "SkGr.h"
390 #include "gl/builders/GrGLProgramBuilder.h" 391 #include "gl/builders/GrGLProgramBuilder.h"
391 392
392 // For brevity 393 // For brevity
393 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 394 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
394 395
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 711
711 #else 712 #else
712 713
713 bool SkTwoPointRadialGradient::asFragmentProcessor(GrContext*, const SkPaint&, c onst SkMatrix*, 714 bool SkTwoPointRadialGradient::asFragmentProcessor(GrContext*, const SkPaint&, c onst SkMatrix*,
714 GrColor*, GrFragmentProcessor **) const { 715 GrColor*, GrFragmentProcessor **) const {
715 SkDEBUGFAIL("Should not call in GPU-less build"); 716 SkDEBUGFAIL("Should not call in GPU-less build");
716 return false; 717 return false;
717 } 718 }
718 719
719 #endif 720 #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