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

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

Issue 1770153002: Fix 4f gradient swizzle post http://crrev.com/1774523002 (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: float mult Created 4 years, 9 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/Sk4fGradientBase.cpp ('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 9
10 namespace { 10 namespace {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 template<> 154 template<>
155 float dst_component_scale<SkPM4f>() { 155 float dst_component_scale<SkPM4f>() {
156 return 1; 156 return 1;
157 } 157 }
158 158
159 template<> 159 template<>
160 float dst_component_scale<SkPMColor>() { 160 float dst_component_scale<SkPMColor>() {
161 return 255; 161 return 255;
162 } 162 }
163 163
164 template<typename DstType>
165 Sk4f dst_swizzle(const SkPM4f&);
166
167 template<>
168 Sk4f dst_swizzle<SkPM4f>(const SkPM4f& c) {
169 return c.to4f();
170 }
171
172 template<>
173 Sk4f dst_swizzle<SkPMColor>(const SkPM4f& c) {
174 return c.to4f_pmorder();
175 }
176
164 SkPMColor pack_color(SkColor c, bool premul) { 177 SkPMColor pack_color(SkColor c, bool premul) {
165 return premul 178 return premul
166 ? SkPreMultiplyColor(c) 179 ? SkPreMultiplyColor(c)
167 : SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), Sk ColorGetB(c)); 180 : SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), Sk ColorGetB(c));
168 } 181 }
169 182
170 // true when x is in [k1,k2) 183 // true when x is in [k1,k2)
171 bool in_range(SkScalar x, SkScalar k1, SkScalar k2) { 184 bool in_range(SkScalar x, SkScalar k1, SkScalar k2) {
172 SkASSERT(k1 != k2); 185 SkASSERT(k1 != k2);
173 return (k1 < k2) 186 return (k1 < k2)
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // interval series - then the iterator operates just as in the 310 // interval series - then the iterator operates just as in the
298 // kRepeat case: 311 // kRepeat case:
299 // 312 //
300 // ->[P0,P1)->..[Pn-1,Pn)->[2 - Pn,2 - Pn-1)->..[2 - P1,2 - P0)-> 313 // ->[P0,P1)->..[Pn-1,Pn)->[2 - Pn,2 - Pn-1)->..[2 - P1,2 - P0)->
301 // 314 //
302 // TODO: investigate collapsing intervals << 1px. 315 // TODO: investigate collapsing intervals << 1px.
303 316
304 SkASSERT(shader.fColorCount > 1); 317 SkASSERT(shader.fColorCount > 1);
305 SkASSERT(shader.fOrigColors); 318 SkASSERT(shader.fOrigColors);
306 319
307 const float kInv255Float = 1.0f / 255; 320 const float paintAlpha = rec.fPaint->getAlpha() * (1.0f / 255);
308 const float paintAlpha = rec.fPaint->getAlpha() * kInv255Float;
309 const Sk4f componentScale = fColorsArePremul 321 const Sk4f componentScale = fColorsArePremul
310 ? Sk4f(paintAlpha * kInv255Float) 322 ? Sk4f(paintAlpha)
311 : Sk4f(kInv255Float, kInv255Float, kInv255Float, paintAlpha * kInv255Flo at); 323 : Sk4f(1.0f, 1.0f, 1.0f, paintAlpha);
312 const bool dx_is_pos = fDstToPos.getScaleX() >= 0; 324 const bool dx_is_pos = fDstToPos.getScaleX() >= 0;
313 const int first_index = dx_is_pos ? 0 : shader.fColorCount - 1; 325 const int first_index = dx_is_pos ? 0 : shader.fColorCount - 1;
314 const int last_index = shader.fColorCount - 1 - first_index; 326 const int last_index = shader.fColorCount - 1 - first_index;
315 const SkScalar first_pos = dx_is_pos ? 0 : SK_Scalar1; 327 const SkScalar first_pos = dx_is_pos ? 0 : SK_Scalar1;
316 const SkScalar last_pos = 1 - first_pos; 328 const SkScalar last_pos = 1 - first_pos;
317 329
318 if (shader.fTileMode == SkShader::kClamp_TileMode) { 330 if (shader.fTileMode == SkShader::kClamp_TileMode) {
319 // synthetic edge interval: -/+inf .. P0 331 // synthetic edge interval: -/+inf .. P0
320 const SkPMColor clamp_color = pack_color(shader.fOrigColors[first_index] , 332 const SkPMColor clamp_color = pack_color(shader.fOrigColors[first_index] ,
321 fColorsArePremul); 333 fColorsArePremul);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 advX = this->advance_interval(advX); 567 advX = this->advance_interval(advX);
556 } 568 }
557 SkASSERT(advX < fAdvX); 569 SkASSERT(advX < fAdvX);
558 570
559 fCc = fCc + fDcDx * Sk4f(advX); 571 fCc = fCc + fDcDx * Sk4f(advX);
560 fAdvX -= advX; 572 fAdvX -= advX;
561 } 573 }
562 574
563 private: 575 private:
564 void compute_interval_props(SkScalar t) { 576 void compute_interval_props(SkScalar t) {
565 fDc = Sk4f::Load(fInterval->fDc.fVec); 577 fDc = dst_swizzle<DstType>(fInterval->fDc);
566 fCc = Sk4f::Load(fInterval->fC0.fVec); 578 fCc = dst_swizzle<DstType>(fInterval->fC0);
567 fCc = fCc + fDc * Sk4f(t); 579 fCc = fCc + fDc * Sk4f(t);
568 fCc = fCc * fDstComponentScale; 580 fCc = fCc * fDstComponentScale;
569 fDcDx = fDc * fDstComponentScale * Sk4f(fDx); 581 fDcDx = fDc * fDstComponentScale * Sk4f(fDx);
570 fZeroRamp = fIsVertical || fInterval->isZeroRamp(); 582 fZeroRamp = fIsVertical || fInterval->isZeroRamp();
571 } 583 }
572 584
573 const Interval* next_interval(const Interval* i) const { 585 const Interval* next_interval(const Interval* i) const {
574 SkASSERT(i >= fFirstInterval); 586 SkASSERT(i >= fFirstInterval);
575 SkASSERT(i <= fLastInterval); 587 SkASSERT(i <= fLastInterval);
576 i++; 588 i++;
(...skipping 30 matching lines...) Expand all
607 Sk4f fCc; // current color, interpolated in dst 619 Sk4f fCc; // current color, interpolated in dst
608 SkScalar fAdvX; // remaining interval advance in dst 620 SkScalar fAdvX; // remaining interval advance in dst
609 bool fZeroRamp; // current interval color grad is 0 621 bool fZeroRamp; // current interval color grad is 0
610 622
611 const Interval* fFirstInterval; 623 const Interval* fFirstInterval;
612 const Interval* fLastInterval; 624 const Interval* fLastInterval;
613 const Interval* fInterval; // current interval 625 const Interval* fInterval; // current interval
614 const SkScalar fDx; // 'dx' for consistency with other impls; actual ly dt/dx 626 const SkScalar fDx; // 'dx' for consistency with other impls; actual ly dt/dx
615 const bool fIsVertical; 627 const bool fIsVertical;
616 }; 628 };
OLDNEW
« no previous file with comments | « src/effects/gradients/Sk4fGradientBase.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698