OLD | NEW |
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 "SkRadialGradient.h" | 9 #include "SkRadialGradient.h" |
10 #include "SkRadialGradient_Table.h" | 10 #include "SkRadialGradient_Table.h" |
11 | 11 |
12 #define kSQRT_TABLE_BITS 11 | 12 #define kSQRT_TABLE_BITS 11 |
13 #define kSQRT_TABLE_SIZE (1 << kSQRT_TABLE_BITS) | 13 #define kSQRT_TABLE_SIZE (1 << kSQRT_TABLE_BITS) |
14 | 14 |
| 15 SK_COMPILE_ASSERT(sizeof(gSqrt8Table) == kSQRT_TABLE_SIZE, SqrtTableSizesMatch); |
| 16 |
15 #if 0 | 17 #if 0 |
16 | 18 |
17 #include <stdio.h> | 19 #include <stdio.h> |
18 | 20 |
19 void SkRadialGradient_BuildTable() { | 21 void SkRadialGradient_BuildTable() { |
20 // build it 0..127 x 0..127, so we use 2^15 - 1 in the numerator for our "fi
xed" table | 22 // build it 0..127 x 0..127, so we use 2^15 - 1 in the numerator for our "fi
xed" table |
21 | 23 |
22 FILE* file = ::fopen("SkRadialGradient_Table.h", "w"); | 24 FILE* file = ::fopen("SkRadialGradient_Table.h", "w"); |
23 SkASSERT(file); | 25 SkASSERT(file); |
24 ::fprintf(file, "static const uint8_t gSqrt8Table[] = {\n"); | 26 ::fprintf(file, "static const uint8_t gSqrt8Table[] = {\n"); |
(...skipping 23 matching lines...) Expand all Loading... |
48 | 50 |
49 // GCC doesn't like using static functions as template arguments. So force thes
e to be non-static. | 51 // GCC doesn't like using static functions as template arguments. So force thes
e to be non-static. |
50 inline SkFixed mirror_tileproc_nonstatic(SkFixed x) { | 52 inline SkFixed mirror_tileproc_nonstatic(SkFixed x) { |
51 return mirror_tileproc(x); | 53 return mirror_tileproc(x); |
52 } | 54 } |
53 | 55 |
54 inline SkFixed repeat_tileproc_nonstatic(SkFixed x) { | 56 inline SkFixed repeat_tileproc_nonstatic(SkFixed x) { |
55 return repeat_tileproc(x); | 57 return repeat_tileproc(x); |
56 } | 58 } |
57 | 59 |
58 void rad_to_unit_matrix(const SkPoint& center, SkScalar radius, | 60 SkMatrix rad_to_unit_matrix(const SkPoint& center, SkScalar radius) { |
59 SkMatrix* matrix) { | |
60 SkScalar inv = SkScalarInvert(radius); | 61 SkScalar inv = SkScalarInvert(radius); |
61 | 62 |
62 matrix->setTranslate(-center.fX, -center.fY); | 63 SkMatrix matrix; |
63 matrix->postScale(inv, inv); | 64 matrix.setTranslate(-center.fX, -center.fY); |
| 65 matrix.postScale(inv, inv); |
| 66 return matrix; |
64 } | 67 } |
65 | 68 |
66 typedef void (* RadialShade16Proc)(SkScalar sfx, SkScalar sdx, | 69 typedef void (* RadialShade16Proc)(SkScalar sfx, SkScalar sdx, |
67 SkScalar sfy, SkScalar sdy, | 70 SkScalar sfy, SkScalar sdy, |
68 uint16_t* dstC, const uint16_t* cache, | 71 uint16_t* dstC, const uint16_t* cache, |
69 int toggle, int count); | 72 int toggle, int count); |
70 | 73 |
71 void shadeSpan16_radial_clamp(SkScalar sfx, SkScalar sdx, | 74 void shadeSpan16_radial_clamp(SkScalar sfx, SkScalar sdx, |
72 SkScalar sfy, SkScalar sdy, | 75 SkScalar sfy, SkScalar sdy, |
73 uint16_t* SK_RESTRICT dstC, const uint16_t* SK_RESTRICT cache, | 76 uint16_t* SK_RESTRICT dstC, const uint16_t* SK_RESTRICT cache, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 uint16_t* SK_RESTRICT dstC, const uint16_t* SK_RE
STRICT cache, | 142 uint16_t* SK_RESTRICT dstC, const uint16_t* SK_RE
STRICT cache, |
140 int toggle, int count) { | 143 int toggle, int count) { |
141 shadeSpan16_radial<repeat_tileproc_nonstatic>(fx, dx, fy, dy, dstC, cache, t
oggle, count); | 144 shadeSpan16_radial<repeat_tileproc_nonstatic>(fx, dx, fy, dy, dstC, cache, t
oggle, count); |
142 } | 145 } |
143 | 146 |
144 } // namespace | 147 } // namespace |
145 | 148 |
146 ///////////////////////////////////////////////////////////////////// | 149 ///////////////////////////////////////////////////////////////////// |
147 | 150 |
148 SkRadialGradient::SkRadialGradient(const SkPoint& center, SkScalar radius, const
Descriptor& desc) | 151 SkRadialGradient::SkRadialGradient(const SkPoint& center, SkScalar radius, const
Descriptor& desc) |
149 : SkGradientShaderBase(desc) | 152 : SkGradientShaderBase(desc, rad_to_unit_matrix(center, radius)) |
150 , fCenter(center) | 153 , fCenter(center) |
151 , fRadius(radius) | 154 , fRadius(radius) { |
152 { | |
153 // make sure our table is insync with our current #define for kSQRT_TABLE_SI
ZE | |
154 SkASSERT(sizeof(gSqrt8Table) == kSQRT_TABLE_SIZE); | |
155 | |
156 rad_to_unit_matrix(center, radius, &fPtsToUnit); | |
157 } | 155 } |
158 | 156 |
159 size_t SkRadialGradient::contextSize() const { | 157 size_t SkRadialGradient::contextSize() const { |
160 return sizeof(RadialGradientContext); | 158 return sizeof(RadialGradientContext); |
161 } | 159 } |
162 | 160 |
163 SkShader::Context* SkRadialGradient::onCreateContext(const ContextRec& rec, void
* storage) const { | 161 SkShader::Context* SkRadialGradient::onCreateContext(const ContextRec& rec, void
* storage) const { |
164 return SkNEW_PLACEMENT_ARGS(storage, RadialGradientContext, (*this, rec)); | 162 return SkNEW_PLACEMENT_ARGS(storage, RadialGradientContext, (*this, rec)); |
165 } | 163 } |
166 | 164 |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 str->appendScalar(fCenter.fY); | 611 str->appendScalar(fCenter.fY); |
614 str->append(") radius: "); | 612 str->append(") radius: "); |
615 str->appendScalar(fRadius); | 613 str->appendScalar(fRadius); |
616 str->append(" "); | 614 str->append(" "); |
617 | 615 |
618 this->INHERITED::toString(str); | 616 this->INHERITED::toString(str); |
619 | 617 |
620 str->append(")"); | 618 str->append(")"); |
621 } | 619 } |
622 #endif | 620 #endif |
OLD | NEW |