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

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

Issue 1825333003: Planar ramp() for S32 linear gradients (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: 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/Sk4fGradientPriv.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 "SkXfermode.h" 10 #include "SkXfermode.h"
10 11
11 namespace { 12 namespace {
12 13
13 template<DstType dstType, ApplyPremul premul> 14 template<DstType dstType, ApplyPremul premul>
14 void ramp(const Sk4f& c, const Sk4f& dc, typename DstTraits<dstType, premul>::Ty pe dst[], int n) { 15 void ramp(const Sk4f& c, const Sk4f& dc, typename DstTraits<dstType, premul>::Ty pe dst[], int n) {
15 SkASSERT(n > 0); 16 SkASSERT(n > 0);
16 17
17 const Sk4f dc2 = dc + dc; 18 const Sk4f dc2 = dc + dc;
18 const Sk4f dc4 = dc2 + dc2; 19 const Sk4f dc4 = dc2 + dc2;
(...skipping 16 matching lines...) Expand all
35 if (n & 2) { 36 if (n & 2) {
36 DstTraits<dstType, premul>::store(c0, dst++); 37 DstTraits<dstType, premul>::store(c0, dst++);
37 DstTraits<dstType, premul>::store(c1, dst++); 38 DstTraits<dstType, premul>::store(c1, dst++);
38 c0 = c0 + dc2; 39 c0 = c0 + dc2;
39 } 40 }
40 if (n & 1) { 41 if (n & 1) {
41 DstTraits<dstType, premul>::store(c0, dst); 42 DstTraits<dstType, premul>::store(c0, dst);
42 } 43 }
43 } 44 }
44 45
46 // Planar version of ramp (S32 no-premul only).
47 template<>
48 void ramp<DstType::S32, ApplyPremul::False>(const Sk4f& c, const Sk4f& dc, SkPMC olor dst[], int n) {
49 SkASSERT(n > 0);
50
51 const Sk4f dc4 = dc * 4;
52 const Sk4x4f dc4x = { Sk4f(dc4[0]), Sk4f(dc4[1]), Sk4f(dc4[2]), Sk4f(dc4[3]) };
53 Sk4x4f c4x = Sk4x4f::Transpose(c, c + dc, c + dc * 2, c + dc * 3);
54
55 while (n >= 4) {
56 const Sk4x4f cx4s32 = { c4x.r.sqrt(), c4x.g.sqrt(), c4x.b.sqrt(), c4x.a };
57 cx4s32.transpose((uint8_t*)dst);
58
59 c4x.r += dc4x.r;
60 c4x.g += dc4x.g;
61 c4x.b += dc4x.b;
62 c4x.a += dc4x.a;
63
64 dst += 4;
65 n -= 4;
66 }
67
68 if (n & 2) {
69 DstTraits<DstType::S32, ApplyPremul::False>
70 ::store(Sk4f(c4x.r[0], c4x.g[0], c4x.b[0], c4x.a[0]), dst++);
71 DstTraits<DstType::S32, ApplyPremul::False>
72 ::store(Sk4f(c4x.r[1], c4x.g[1], c4x.b[1], c4x.a[1]), dst++);
73 }
74
75 if (n & 1) {
76 DstTraits<DstType::S32, ApplyPremul::False>
77 ::store(Sk4f(c4x.r[n & 2], c4x.g[n & 2], c4x.b[n & 2], c4x.a[n & 2]) , dst);
mtklein 2016/03/23 19:05:27 Wait, walk me through this one again?
mtklein 2016/03/23 19:12:57 ok, cute!
78 }
79 }
80
45 template<SkShader::TileMode> 81 template<SkShader::TileMode>
46 SkScalar pinFx(SkScalar); 82 SkScalar pinFx(SkScalar);
47 83
48 template<> 84 template<>
49 SkScalar pinFx<SkShader::kClamp_TileMode>(SkScalar fx) { 85 SkScalar pinFx<SkShader::kClamp_TileMode>(SkScalar fx) {
50 return fx; 86 return fx;
51 } 87 }
52 88
53 template<> 89 template<>
54 SkScalar pinFx<SkShader::kRepeat_TileMode>(SkScalar fx) { 90 SkScalar pinFx<SkShader::kRepeat_TileMode>(SkScalar fx) {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 static_cast<const LinearGradient4fContext*>(state->fCtx); 471 static_cast<const LinearGradient4fContext*>(state->fCtx);
436 472
437 if (ctx->fColorsArePremul) { 473 if (ctx->fColorsArePremul) {
438 ctx->shadePremulSpan<DstType::F16, ApplyPremul::False>( 474 ctx->shadePremulSpan<DstType::F16, ApplyPremul::False>(
439 x, y, dst.writable_addr64(x, y), count); 475 x, y, dst.writable_addr64(x, y), count);
440 } else { 476 } else {
441 ctx->shadePremulSpan<DstType::F16, ApplyPremul::True>( 477 ctx->shadePremulSpan<DstType::F16, ApplyPremul::True>(
442 x, y, dst.writable_addr64(x, y), count); 478 x, y, dst.writable_addr64(x, y), count);
443 } 479 }
444 } 480 }
OLDNEW
« no previous file with comments | « src/effects/gradients/Sk4fGradientPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698