| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkPictureShader.h" | 8 #include "SkPictureShader.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkBitmapProcShader.h" | 11 #include "SkBitmapProcShader.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkMatrixUtils.h" | 13 #include "SkMatrixUtils.h" |
| 14 #include "SkPicture.h" | 14 #include "SkPicture.h" |
| 15 #include "SkReadBuffer.h" | 15 #include "SkReadBuffer.h" |
| 16 | 16 |
| 17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 18 #include "GrContext.h" | 18 #include "GrContext.h" |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 SkPictureShader::SkPictureShader(SkPicture* picture, TileMode tmx, TileMode tmy) | 21 SkPictureShader::SkPictureShader(SkPicture* picture, TileMode tmx, TileMode tmy) |
| 22 : fPicture(picture) | 22 : fPicture(SkRef(picture)) |
| 23 , fTmx(tmx) | 23 , fTmx(tmx) |
| 24 , fTmy(tmy) { | 24 , fTmy(tmy) { } |
| 25 SkSafeRef(fPicture); | |
| 26 } | |
| 27 | 25 |
| 28 SkPictureShader::SkPictureShader(SkReadBuffer& buffer) | 26 SkPictureShader::SkPictureShader(SkReadBuffer& buffer) |
| 29 : INHERITED(buffer) { | 27 : INHERITED(buffer) { |
| 30 fTmx = static_cast<SkShader::TileMode>(buffer.read32()); | 28 fTmx = static_cast<SkShader::TileMode>(buffer.read32()); |
| 31 fTmy = static_cast<SkShader::TileMode>(buffer.read32()); | 29 fTmy = static_cast<SkShader::TileMode>(buffer.read32()); |
| 32 if (buffer.readBool()) { | 30 fPicture = SkPicture::CreateFromBuffer(buffer); |
| 33 fPicture = SkPicture::CreateFromBuffer(buffer); | |
| 34 } else { | |
| 35 fPicture = NULL; | |
| 36 } | |
| 37 } | 31 } |
| 38 | 32 |
| 39 SkPictureShader::~SkPictureShader() { | 33 SkPictureShader::~SkPictureShader() { |
| 40 SkSafeUnref(fPicture); | 34 fPicture->unref(); |
| 41 } | 35 } |
| 42 | 36 |
| 43 SkPictureShader* SkPictureShader::Create(SkPicture* picture, TileMode tmx, TileM
ode tmy) { | 37 SkPictureShader* SkPictureShader::Create(SkPicture* picture, TileMode tmx, TileM
ode tmy) { |
| 38 if (!picture || 0 == picture->width() || 0 == picture->height()) { |
| 39 return NULL; |
| 40 } |
| 44 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy)); | 41 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy)); |
| 45 } | 42 } |
| 46 | 43 |
| 47 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { | 44 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { |
| 48 this->INHERITED::flatten(buffer); | 45 this->INHERITED::flatten(buffer); |
| 49 | 46 |
| 50 buffer.write32(fTmx); | 47 buffer.write32(fTmx); |
| 51 buffer.write32(fTmy); | 48 buffer.write32(fTmy); |
| 52 buffer.writeBool(NULL != fPicture); | 49 fPicture->flatten(buffer); |
| 53 if (fPicture) { | |
| 54 fPicture->flatten(buffer); | |
| 55 } | |
| 56 } | 50 } |
| 57 | 51 |
| 58 bool SkPictureShader::buildBitmapShader(const SkMatrix& matrix) const { | 52 bool SkPictureShader::buildBitmapShader(const SkMatrix& matrix) const { |
| 59 if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) { | 53 SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); |
| 60 return false; | |
| 61 } | |
| 62 | 54 |
| 63 SkMatrix m; | 55 SkMatrix m; |
| 64 if (this->hasLocalMatrix()) { | 56 if (this->hasLocalMatrix()) { |
| 65 m.setConcat(matrix, this->getLocalMatrix()); | 57 m.setConcat(matrix, this->getLocalMatrix()); |
| 66 } else { | 58 } else { |
| 67 m = matrix; | 59 m = matrix; |
| 68 } | 60 } |
| 69 | 61 |
| 70 // Use a rotation-invariant scale | 62 // Use a rotation-invariant scale |
| 71 SkPoint scale; | 63 SkPoint scale; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 168 |
| 177 #if SK_SUPPORT_GPU | 169 #if SK_SUPPORT_GPU |
| 178 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { | 170 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { |
| 179 if (!this->buildBitmapShader(context->getMatrix())) { | 171 if (!this->buildBitmapShader(context->getMatrix())) { |
| 180 return NULL; | 172 return NULL; |
| 181 } | 173 } |
| 182 SkASSERT(fCachedShader); | 174 SkASSERT(fCachedShader); |
| 183 return fCachedShader->asNewEffect(context, paint); | 175 return fCachedShader->asNewEffect(context, paint); |
| 184 } | 176 } |
| 185 #endif | 177 #endif |
| OLD | NEW |