| 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 "SkLinearGradient.h" | 8 #include "SkLinearGradient.h" |
| 9 | 9 |
| 10 static inline int repeat_bits(int x, const int bits) { | 10 static inline int repeat_bits(int x, const int bits) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { | 69 void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { |
| 70 this->INHERITED::flatten(buffer); | 70 this->INHERITED::flatten(buffer); |
| 71 buffer.writePoint(fStart); | 71 buffer.writePoint(fStart); |
| 72 buffer.writePoint(fEnd); | 72 buffer.writePoint(fEnd); |
| 73 } | 73 } |
| 74 | 74 |
| 75 size_t SkLinearGradient::contextSize() const { | 75 size_t SkLinearGradient::contextSize() const { |
| 76 return sizeof(LinearGradientContext); | 76 return sizeof(LinearGradientContext); |
| 77 } | 77 } |
| 78 | 78 |
| 79 SkShader::Context* SkLinearGradient::createContext(const SkBitmap& device, const
SkPaint& paint, | 79 SkShader::Context* SkLinearGradient::createContext(const ContextRec& rec, void*
storage) const { |
| 80 const SkMatrix& matrix, void*
storage) const { | 80 if (!this->validContext(rec)) { |
| 81 if (!this->validContext(device, paint, matrix)) { | |
| 82 return NULL; | 81 return NULL; |
| 83 } | 82 } |
| 84 | 83 |
| 85 return SkNEW_PLACEMENT_ARGS(storage, LinearGradientContext, (*this, device,
paint, matrix)); | 84 return SkNEW_PLACEMENT_ARGS(storage, LinearGradientContext, (*this, rec)); |
| 86 } | 85 } |
| 87 | 86 |
| 88 SkLinearGradient::LinearGradientContext::LinearGradientContext( | 87 SkLinearGradient::LinearGradientContext::LinearGradientContext( |
| 89 const SkLinearGradient& shader, const SkBitmap& device, | 88 const SkLinearGradient& shader, const ContextRec& rec) |
| 90 const SkPaint& paint, const SkMatrix& matrix) | 89 : INHERITED(shader, rec) |
| 91 : INHERITED(shader, device, paint, matrix) | |
| 92 { | 90 { |
| 93 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask; | 91 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask; |
| 94 if ((fDstToIndex.getType() & ~mask) == 0) { | 92 if ((fDstToIndex.getType() & ~mask) == 0) { |
| 95 // when we dither, we are (usually) not const-in-Y | 93 // when we dither, we are (usually) not const-in-Y |
| 96 if ((fFlags & SkShader::kHasSpan16_Flag) && !paint.isDither()) { | 94 if ((fFlags & SkShader::kHasSpan16_Flag) && !rec.fPaint->isDither()) { |
| 97 // only claim this if we do have a 16bit mode (i.e. none of our | 95 // only claim this if we do have a 16bit mode (i.e. none of our |
| 98 // colors have alpha), and if we are not dithering (which obviously | 96 // colors have alpha), and if we are not dithering (which obviously |
| 99 // is not const in Y). | 97 // is not const in Y). |
| 100 fFlags |= SkShader::kConstInY16_Flag; | 98 fFlags |= SkShader::kConstInY16_Flag; |
| 101 } | 99 } |
| 102 } | 100 } |
| 103 } | 101 } |
| 104 | 102 |
| 105 #define NO_CHECK_ITER \ | 103 #define NO_CHECK_ITER \ |
| 106 do { \ | 104 do { \ |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 str->append("SkLinearGradient ("); | 575 str->append("SkLinearGradient ("); |
| 578 | 576 |
| 579 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 577 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
| 580 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 578 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
| 581 | 579 |
| 582 this->INHERITED::toString(str); | 580 this->INHERITED::toString(str); |
| 583 | 581 |
| 584 str->append(")"); | 582 str->append(")"); |
| 585 } | 583 } |
| 586 #endif | 584 #endif |
| OLD | NEW |