| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkTwoPointConicalGradient.h" | 8 #include "SkTwoPointConicalGradient.h" |
| 9 | 9 |
| 10 static int valid_divide(float numer, float denom, float* ratio) { | 10 static int valid_divide(float numer, float denom, float* ratio) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (r <= 0) { | 108 if (r <= 0) { |
| 109 return kDontDrawT; | 109 return kDontDrawT; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 return SkFloatToFixed(t); | 112 return SkFloatToFixed(t); |
| 113 } | 113 } |
| 114 | 114 |
| 115 typedef void (*TwoPointConicalProc)(TwoPtRadial* rec, SkPMColor* dstC, | 115 typedef void (*TwoPointConicalProc)(TwoPtRadial* rec, SkPMColor* dstC, |
| 116 const SkPMColor* cache, int toggle, int coun
t); | 116 const SkPMColor* cache, int toggle, int coun
t); |
| 117 | 117 |
| 118 #if 0 |
| 118 static void twopoint_clamp(TwoPtRadial* rec, SkPMColor* SK_RESTRICT dstC, | 119 static void twopoint_clamp(TwoPtRadial* rec, SkPMColor* SK_RESTRICT dstC, |
| 119 const SkPMColor* SK_RESTRICT cache, int toggle, | 120 const SkPMColor* SK_RESTRICT cache, int toggle, |
| 120 int count) { | 121 int count) { |
| 121 for (; count > 0; --count) { | 122 for (; count > 0; --count) { |
| 122 SkFixed t = rec->nextT(); | 123 SkFixed t = rec->nextT(); |
| 123 if (TwoPtRadial::DontDrawT(t)) { | 124 if (TwoPtRadial::DontDrawT(t)) { |
| 124 *dstC++ = 0; | 125 *dstC++ = 0; |
| 125 } else { | 126 } else { |
| 126 SkFixed index = SkClampMax(t, 0xFFFF); | 127 SkFixed index = SkClampMax(t, 0xFFFF); |
| 127 SkASSERT(index <= 0xFFFF); | 128 SkASSERT(index <= 0xFFFF); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 158 *dstC++ = 0; | 159 *dstC++ = 0; |
| 159 } else { | 160 } else { |
| 160 SkFixed index = mirror_tileproc(t); | 161 SkFixed index = mirror_tileproc(t); |
| 161 SkASSERT(index <= 0xFFFF); | 162 SkASSERT(index <= 0xFFFF); |
| 162 *dstC++ = cache[toggle + | 163 *dstC++ = cache[toggle + |
| 163 (index >> SkGradientShaderBase::kCache32Shift)]; | 164 (index >> SkGradientShaderBase::kCache32Shift)]; |
| 164 } | 165 } |
| 165 toggle = next_dither_toggle(toggle); | 166 toggle = next_dither_toggle(toggle); |
| 166 } | 167 } |
| 167 } | 168 } |
| 169 #endif |
| 168 | 170 |
| 169 void SkTwoPointConicalGradient::init() { | 171 void SkTwoPointConicalGradient::init() { |
| 170 fRec.init(fCenter1, fRadius1, fCenter2, fRadius2); | 172 fRec.init(fCenter1, fRadius1, fCenter2, fRadius2); |
| 171 fPtsToUnit.reset(); | 173 fPtsToUnit.reset(); |
| 172 } | 174 } |
| 173 | 175 |
| 174 ///////////////////////////////////////////////////////////////////// | 176 ///////////////////////////////////////////////////////////////////// |
| 175 | 177 |
| 176 SkTwoPointConicalGradient::SkTwoPointConicalGradient( | 178 SkTwoPointConicalGradient::SkTwoPointConicalGradient( |
| 177 const SkPoint& start, SkScalar startRadius, | 179 const SkPoint& start, SkScalar startRadius, |
| 178 const SkPoint& end, SkScalar endRadius, | 180 const SkPoint& end, SkScalar endRadius, |
| 179 const Descriptor& desc) | 181 const Descriptor& desc) |
| 180 : SkGradientShaderBase(desc), | 182 : SkGradientShaderBase(desc), |
| 181 fCenter1(start), | 183 fCenter1(start), |
| 182 fCenter2(end), | 184 fCenter2(end), |
| 183 fRadius1(startRadius), | 185 fRadius1(startRadius), |
| 184 fRadius2(endRadius) { | 186 fRadius2(endRadius) { |
| 185 // this is degenerate, and should be caught by our caller | 187 // this is degenerate, and should be caught by our caller |
| 186 SkASSERT(fCenter1 != fCenter2 || fRadius1 != fRadius2); | 188 SkASSERT(fCenter1 != fCenter2 || fRadius1 != fRadius2); |
| 187 this->init(); | 189 this->init(); |
| 188 } | 190 } |
| 189 | 191 |
| 190 bool SkTwoPointConicalGradient::isOpaque() const { | 192 bool SkTwoPointConicalGradient::isOpaque() const { |
| 191 // Because areas outside the cone are left untouched, we cannot treat the | 193 // Because areas outside the cone are left untouched, we cannot treat the |
| 192 // shader as opaque even if the gradient itself is opaque. | 194 // shader as opaque even if the gradient itself is opaque. |
| 193 // TODO(junov): Compute whether the cone fills the plane crbug.com/222380 | 195 // TODO(junov): Compute whether the cone fills the plane crbug.com/222380 |
| 194 return false; | 196 return false; |
| 195 } | 197 } |
| 196 | 198 |
| 199 #if 0 |
| 197 void SkTwoPointConicalGradient::shadeSpan(int x, int y, SkPMColor* dstCParam, | 200 void SkTwoPointConicalGradient::shadeSpan(int x, int y, SkPMColor* dstCParam, |
| 198 int count) { | 201 int count) { |
| 199 int toggle = init_dither_toggle(x, y); | 202 int toggle = init_dither_toggle(x, y); |
| 200 | 203 |
| 201 SkASSERT(count > 0); | 204 SkASSERT(count > 0); |
| 202 | 205 |
| 203 SkPMColor* SK_RESTRICT dstC = dstCParam; | 206 SkPMColor* SK_RESTRICT dstC = dstCParam; |
| 204 | 207 |
| 205 SkMatrix::MapXYProc dstProc = fDstToIndexProc; | 208 SkMatrix::MapXYProc dstProc = fDstToIndexProc; |
| 206 | 209 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 263 |
| 261 // we don't have a span16 proc | 264 // we don't have a span16 proc |
| 262 fFlags &= ~kHasSpan16_Flag; | 265 fFlags &= ~kHasSpan16_Flag; |
| 263 | 266 |
| 264 // in general, we might discard based on computed-radius, so clear | 267 // in general, we might discard based on computed-radius, so clear |
| 265 // this flag (todo: sometimes we can detect that we never discard...) | 268 // this flag (todo: sometimes we can detect that we never discard...) |
| 266 fFlags &= ~kOpaqueAlpha_Flag; | 269 fFlags &= ~kOpaqueAlpha_Flag; |
| 267 | 270 |
| 268 return true; | 271 return true; |
| 269 } | 272 } |
| 273 #endif |
| 270 | 274 |
| 271 SkShader::BitmapType SkTwoPointConicalGradient::asABitmap( | 275 SkShader::BitmapType SkTwoPointConicalGradient::asABitmap( |
| 272 SkBitmap* bitmap, SkMatrix* matrix, SkShader::TileMode* xy) const { | 276 SkBitmap* bitmap, SkMatrix* matrix, SkShader::TileMode* xy) const { |
| 273 SkPoint diff = fCenter2 - fCenter1; | 277 SkPoint diff = fCenter2 - fCenter1; |
| 274 SkScalar diffLen = 0; | 278 SkScalar diffLen = 0; |
| 275 | 279 |
| 276 if (bitmap) { | 280 if (bitmap) { |
| 277 this->getGradientTableBitmap(bitmap); | 281 this->getGradientTableBitmap(bitmap); |
| 278 } | 282 } |
| 279 if (matrix) { | 283 if (matrix) { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 str->appendScalar(fCenter2.fY); | 732 str->appendScalar(fCenter2.fY); |
| 729 str->append(") radius2: "); | 733 str->append(") radius2: "); |
| 730 str->appendScalar(fRadius2); | 734 str->appendScalar(fRadius2); |
| 731 str->append(" "); | 735 str->append(" "); |
| 732 | 736 |
| 733 this->INHERITED::toString(str); | 737 this->INHERITED::toString(str); |
| 734 | 738 |
| 735 str->append(")"); | 739 str->append(")"); |
| 736 } | 740 } |
| 737 #endif | 741 #endif |
| OLD | NEW |