| 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(const SkPicture* picture, TileMode tmx, TileMod
e tmy, | 21 SkPictureShader::SkPictureShader(const SkPicture* picture, TileMode tmx, TileMod
e tmy, |
| 22 const SkMatrix* localMatrix) | 22 const SkMatrix* localMatrix) |
| 23 : INHERITED(localMatrix) | 23 : INHERITED(localMatrix) |
| 24 , fPicture(SkRef(picture)) | 24 , fPicture(SkRef(picture)) |
| 25 , fTmx(tmx) | 25 , fTmx(tmx) |
| 26 , fTmy(tmy) { } | 26 , fTmy(tmy) { } |
| 27 | 27 |
| 28 SkPictureShader::SkPictureShader(SkReadBuffer& buffer) | 28 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
| 29 : INHERITED(buffer) { | 29 SkPictureShader::SkPictureShader(SkReadBuffer& buffer) : INHERITED(buffer) { |
| 30 fTmx = static_cast<SkShader::TileMode>(buffer.read32()); | 30 fTmx = static_cast<SkShader::TileMode>(buffer.read32()); |
| 31 fTmy = static_cast<SkShader::TileMode>(buffer.read32()); | 31 fTmy = static_cast<SkShader::TileMode>(buffer.read32()); |
| 32 fPicture = SkPicture::CreateFromBuffer(buffer); | 32 fPicture = SkPicture::CreateFromBuffer(buffer); |
| 33 } | 33 } |
| 34 #endif |
| 34 | 35 |
| 35 SkPictureShader::~SkPictureShader() { | 36 SkPictureShader::~SkPictureShader() { |
| 36 fPicture->unref(); | 37 fPicture->unref(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx,
TileMode tmy, | 40 SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx,
TileMode tmy, |
| 40 const SkMatrix* localMatrix) { | 41 const SkMatrix* localMatrix) { |
| 41 if (!picture || 0 == picture->width() || 0 == picture->height()) { | 42 if (!picture || 0 == picture->width() || 0 == picture->height()) { |
| 42 return NULL; | 43 return NULL; |
| 43 } | 44 } |
| 44 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix)); | 45 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix)); |
| 45 } | 46 } |
| 46 | 47 |
| 48 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { |
| 49 SkMatrix lm; |
| 50 buffer.readMatrix(&lm); |
| 51 TileMode mx = (TileMode)buffer.read32(); |
| 52 TileMode my = (TileMode)buffer.read32(); |
| 53 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromBuffer(buffer)); |
| 54 return SkPictureShader::Create(picture, mx, my, &lm); |
| 55 } |
| 56 |
| 47 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { | 57 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { |
| 48 this->INHERITED::flatten(buffer); | 58 buffer.writeMatrix(this->getLocalMatrix()); |
| 49 | |
| 50 buffer.write32(fTmx); | 59 buffer.write32(fTmx); |
| 51 buffer.write32(fTmy); | 60 buffer.write32(fTmy); |
| 52 fPicture->flatten(buffer); | 61 fPicture->flatten(buffer); |
| 53 } | 62 } |
| 54 | 63 |
| 55 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
x* localM) const { | 64 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
x* localM) const { |
| 56 SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); | 65 SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); |
| 57 | 66 |
| 58 SkMatrix m; | 67 SkMatrix m; |
| 59 m.setConcat(matrix, this->getLocalMatrix()); | 68 m.setConcat(matrix, this->getLocalMatrix()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return bitmapShader->asNewEffect(context, paint, NULL, paintColor, effect); | 204 return bitmapShader->asNewEffect(context, paint, NULL, paintColor, effect); |
| 196 } | 205 } |
| 197 #else | 206 #else |
| 198 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint, | 207 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint, |
| 199 const SkMatrix* localMatrix, GrColor* paintCol
or, | 208 const SkMatrix* localMatrix, GrColor* paintCol
or, |
| 200 GrEffect** effect) const { | 209 GrEffect** effect) const { |
| 201 SkDEBUGFAIL("Should not call in GPU-less build"); | 210 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 202 return false; | 211 return false; |
| 203 } | 212 } |
| 204 #endif | 213 #endif |
| OLD | NEW |