| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 | 8 |
| 9 #include "SkScalar.h" | 9 #include "SkScalar.h" |
| 10 #include "SkShader.h" | 10 #include "SkShader.h" |
| 11 #include "SkFlattenableBuffers.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" |
| 12 #include "SkPaint.h" | 13 #include "SkPaint.h" |
| 13 #include "SkMallocPixelRef.h" | 14 #include "SkMallocPixelRef.h" |
| 14 | 15 |
| 15 SkShader::SkShader() { | 16 SkShader::SkShader() { |
| 16 fLocalMatrix.reset(); | 17 fLocalMatrix.reset(); |
| 17 SkDEBUGCODE(fInSetContext = false;) | 18 SkDEBUGCODE(fInSetContext = false;) |
| 18 } | 19 } |
| 19 | 20 |
| 20 SkShader::SkShader(SkFlattenableReadBuffer& buffer) | 21 SkShader::SkShader(SkReadBuffer& buffer) |
| 21 : INHERITED(buffer) { | 22 : INHERITED(buffer) { |
| 22 if (buffer.readBool()) { | 23 if (buffer.readBool()) { |
| 23 buffer.readMatrix(&fLocalMatrix); | 24 buffer.readMatrix(&fLocalMatrix); |
| 24 } else { | 25 } else { |
| 25 fLocalMatrix.reset(); | 26 fLocalMatrix.reset(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 SkDEBUGCODE(fInSetContext = false;) | 29 SkDEBUGCODE(fInSetContext = false;) |
| 29 } | 30 } |
| 30 | 31 |
| 31 SkShader::~SkShader() { | 32 SkShader::~SkShader() { |
| 32 SkASSERT(!fInSetContext); | 33 SkASSERT(!fInSetContext); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void SkShader::flatten(SkFlattenableWriteBuffer& buffer) const { | 36 void SkShader::flatten(SkWriteBuffer& buffer) const { |
| 36 this->INHERITED::flatten(buffer); | 37 this->INHERITED::flatten(buffer); |
| 37 bool hasLocalM = this->hasLocalMatrix(); | 38 bool hasLocalM = this->hasLocalMatrix(); |
| 38 buffer.writeBool(hasLocalM); | 39 buffer.writeBool(hasLocalM); |
| 39 if (hasLocalM) { | 40 if (hasLocalM) { |
| 40 buffer.writeMatrix(fLocalMatrix); | 41 buffer.writeMatrix(fLocalMatrix); |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 bool SkShader::setContext(const SkBitmap& device, | 45 bool SkShader::setContext(const SkBitmap& device, |
| 45 const SkPaint& paint, | 46 const SkPaint& paint, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 207 |
| 207 SkColorShader::~SkColorShader() {} | 208 SkColorShader::~SkColorShader() {} |
| 208 | 209 |
| 209 bool SkColorShader::isOpaque() const { | 210 bool SkColorShader::isOpaque() const { |
| 210 if (fInheritColor) { | 211 if (fInheritColor) { |
| 211 return true; // using paint's alpha | 212 return true; // using paint's alpha |
| 212 } | 213 } |
| 213 return SkColorGetA(fColor) == 255; | 214 return SkColorGetA(fColor) == 255; |
| 214 } | 215 } |
| 215 | 216 |
| 216 SkColorShader::SkColorShader(SkFlattenableReadBuffer& b) : INHERITED(b) { | 217 SkColorShader::SkColorShader(SkReadBuffer& b) : INHERITED(b) { |
| 217 fFlags = 0; // computed in setContext | 218 fFlags = 0; // computed in setContext |
| 218 | 219 |
| 219 fInheritColor = b.readBool(); | 220 fInheritColor = b.readBool(); |
| 220 if (fInheritColor) { | 221 if (fInheritColor) { |
| 221 return; | 222 return; |
| 222 } | 223 } |
| 223 fColor = b.readColor(); | 224 fColor = b.readColor(); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void SkColorShader::flatten(SkFlattenableWriteBuffer& buffer) const { | 227 void SkColorShader::flatten(SkWriteBuffer& buffer) const { |
| 227 this->INHERITED::flatten(buffer); | 228 this->INHERITED::flatten(buffer); |
| 228 buffer.writeBool(fInheritColor); | 229 buffer.writeBool(fInheritColor); |
| 229 if (fInheritColor) { | 230 if (fInheritColor) { |
| 230 return; | 231 return; |
| 231 } | 232 } |
| 232 buffer.writeColor(fColor); | 233 buffer.writeColor(fColor); |
| 233 } | 234 } |
| 234 | 235 |
| 235 uint32_t SkColorShader::getFlags() { | 236 uint32_t SkColorShader::getFlags() { |
| 236 return fFlags; | 237 return fFlags; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 351 |
| 351 #ifdef SK_DEVELOPER | 352 #ifdef SK_DEVELOPER |
| 352 void SkEmptyShader::toString(SkString* str) const { | 353 void SkEmptyShader::toString(SkString* str) const { |
| 353 str->append("SkEmptyShader: ("); | 354 str->append("SkEmptyShader: ("); |
| 354 | 355 |
| 355 this->INHERITED::toString(str); | 356 this->INHERITED::toString(str); |
| 356 | 357 |
| 357 str->append(")"); | 358 str->append(")"); |
| 358 } | 359 } |
| 359 #endif | 360 #endif |
| OLD | NEW |