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

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

Issue 2416233002: Faster 4f gradient premul path (Closed)
Patch Set: Created 4 years, 2 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/Sk4fLinearGradient.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 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Sk4fLinearGradient.h" 8 #include "Sk4fLinearGradient.h"
9 #include "Sk4x4f.h" 9 #include "Sk4x4f.h"
10 #include "SkXfermode.h" 10 #include "SkXfermode.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 LinearGradient4fContext::shadeSpanInternal(int x, int y, 233 LinearGradient4fContext::shadeSpanInternal(int x, int y,
234 typename DstTraits<dstType, premul>:: Type dst[], 234 typename DstTraits<dstType, premul>:: Type dst[],
235 int count) const { 235 int count) const {
236 SkPoint pt; 236 SkPoint pt;
237 fDstToPosProc(fDstToPos, 237 fDstToPosProc(fDstToPos,
238 x + SK_ScalarHalf, 238 x + SK_ScalarHalf,
239 y + SK_ScalarHalf, 239 y + SK_ScalarHalf,
240 &pt); 240 &pt);
241 const SkScalar fx = pinFx<tileMode>(pt.x()); 241 const SkScalar fx = pinFx<tileMode>(pt.x());
242 const SkScalar dx = fDstToPos.getScaleX(); 242 const SkScalar dx = fDstToPos.getScaleX();
243 LinearIntervalProcessor<dstType, tileMode> proc(fIntervals.begin(), 243 LinearIntervalProcessor<dstType, premul, tileMode> proc(fIntervals.begin(),
244 fIntervals.end() - 1, 244 fIntervals.end() - 1 ,
245 this->findInterval(fx), 245 this->findInterval(f x),
246 fx, 246 fx,
247 dx, 247 dx,
248 SkScalarNearlyZero(dx * coun t)); 248 SkScalarNearlyZero(d x * count));
249 while (count > 0) { 249 while (count > 0) {
250 // What we really want here is SkTPin(advance, 1, count) 250 // What we really want here is SkTPin(advance, 1, count)
251 // but that's a significant perf hit for >> stops; investigate. 251 // but that's a significant perf hit for >> stops; investigate.
252 const int n = SkScalarTruncToInt( 252 const int n = SkScalarTruncToInt(
253 SkTMin<SkScalar>(proc.currentAdvance() + 1, SkIntToScalar(count))); 253 SkTMin<SkScalar>(proc.currentAdvance() + 1, SkIntToScalar(count)));
254 254
255 // The current interval advance can be +inf (e.g. when reaching 255 // The current interval advance can be +inf (e.g. when reaching
256 // the clamp mode end intervals) - when that happens, we expect to 256 // the clamp mode end intervals) - when that happens, we expect to
257 // a) consume all remaining count in one swoop 257 // a) consume all remaining count in one swoop
258 // b) return a zero color gradient 258 // b) return a zero color gradient
259 SkASSERT(SkScalarIsFinite(proc.currentAdvance()) 259 SkASSERT(SkScalarIsFinite(proc.currentAdvance())
260 || (n == count && proc.currentRampIsZero())); 260 || (n == count && proc.currentRampIsZero()));
261 261
262 if (proc.currentRampIsZero()) { 262 if (proc.currentRampIsZero()) {
263 DstTraits<dstType, premul>::store(proc.currentColor(), 263 DstTraits<dstType, premul>::store(proc.currentColor(),
264 dst, n); 264 dst, n);
265 } else { 265 } else {
266 ramp<dstType, premul>(proc.currentColor(), 266 ramp<dstType, premul>(proc.currentColor(),
267 proc.currentColorGrad(), 267 proc.currentColorGrad(),
268 dst, n); 268 dst, n);
269 } 269 }
270 270
271 proc.advance(SkIntToScalar(n)); 271 proc.advance(SkIntToScalar(n));
272 count -= n; 272 count -= n;
273 dst += n; 273 dst += n;
274 } 274 }
275 } 275 }
276 276
277 template<DstType dstType, SkShader::TileMode tileMode> 277 template<DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode>
278 class SkLinearGradient:: 278 class SkLinearGradient::
279 LinearGradient4fContext::LinearIntervalProcessor { 279 LinearGradient4fContext::LinearIntervalProcessor {
280 public: 280 public:
281 LinearIntervalProcessor(const Interval* firstInterval, 281 LinearIntervalProcessor(const Interval* firstInterval,
282 const Interval* lastInterval, 282 const Interval* lastInterval,
283 const Interval* i, 283 const Interval* i,
284 SkScalar fx, 284 SkScalar fx,
285 SkScalar dx, 285 SkScalar dx,
286 bool is_vertical) 286 bool is_vertical)
287 : fAdvX((i->fP1 - fx) / dx) 287 : fAdvX((i->fP1 - fx) / dx)
(...skipping 27 matching lines...) Expand all
315 advX = this->advance_interval(advX); 315 advX = this->advance_interval(advX);
316 } 316 }
317 SkASSERT(advX < fAdvX); 317 SkASSERT(advX < fAdvX);
318 318
319 fCc = fCc + fDcDx * Sk4f(advX); 319 fCc = fCc + fDcDx * Sk4f(advX);
320 fAdvX -= advX; 320 fAdvX -= advX;
321 } 321 }
322 322
323 private: 323 private:
324 void compute_interval_props(SkScalar t) { 324 void compute_interval_props(SkScalar t) {
325 const Sk4f dC = DstTraits<dstType>::load(fInterval->fDc); 325 const Sk4f dC = DstTraits<dstType, premul>::load(fInterval->fDc);
326 fCc = DstTraits<dstType>::load(fInterval->fC0); 326 fCc = DstTraits<dstType, premul>::load(fInterval->fC0);
327 fCc = fCc + dC * Sk4f(t); 327 fCc = fCc + dC * Sk4f(t);
328 fDcDx = dC * fDx; 328 fDcDx = dC * fDx;
329 fZeroRamp = fIsVertical || fInterval->isZeroRamp(); 329 fZeroRamp = fIsVertical || fInterval->isZeroRamp();
330 } 330 }
331 331
332 const Interval* next_interval(const Interval* i) const { 332 const Interval* next_interval(const Interval* i) const {
333 SkASSERT(i >= fFirstInterval); 333 SkASSERT(i >= fFirstInterval);
334 SkASSERT(i <= fLastInterval); 334 SkASSERT(i <= fLastInterval);
335 i++; 335 i++;
336 336
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 static_cast<const LinearGradient4fContext*>(state->fCtx); 474 static_cast<const LinearGradient4fContext*>(state->fCtx);
475 475
476 if (ctx->fColorsArePremul) { 476 if (ctx->fColorsArePremul) {
477 ctx->shadePremulSpan<DstType::F16, ApplyPremul::False>( 477 ctx->shadePremulSpan<DstType::F16, ApplyPremul::False>(
478 x, y, dst.writable_addr64(x, y), count); 478 x, y, dst.writable_addr64(x, y), count);
479 } else { 479 } else {
480 ctx->shadePremulSpan<DstType::F16, ApplyPremul::True>( 480 ctx->shadePremulSpan<DstType::F16, ApplyPremul::True>(
481 x, y, dst.writable_addr64(x, y), count); 481 x, y, dst.writable_addr64(x, y), count);
482 } 482 }
483 } 483 }
OLDNEW
« no previous file with comments | « src/effects/gradients/Sk4fLinearGradient.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698