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" |
(...skipping 10 matching lines...) Expand all Loading... |
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, const SkRect* tile
) | 22 const SkMatrix* localMatrix, const SkRect* tile
) |
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 fTile = tile ? *tile : SkRect::MakeWH(SkIntToScalar(picture->width()), | 27 fTile = tile ? *tile : SkRect::MakeWH(SkIntToScalar(picture->width()), |
28 SkIntToScalar(picture->height())); | 28 SkIntToScalar(picture->height())); |
29 } | 29 } |
30 | 30 |
31 SkPictureShader::SkPictureShader(SkReadBuffer& buffer) | 31 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
32 : INHERITED(buffer) { | 32 SkPictureShader::SkPictureShader(SkReadBuffer& buffer) : INHERITED(buffer) { |
33 fTmx = static_cast<SkShader::TileMode>(buffer.read32()); | 33 fTmx = static_cast<SkShader::TileMode>(buffer.read32()); |
34 fTmy = static_cast<SkShader::TileMode>(buffer.read32()); | 34 fTmy = static_cast<SkShader::TileMode>(buffer.read32()); |
35 buffer.readRect(&fTile); | 35 buffer.readRect(&fTile); |
36 fPicture = SkPicture::CreateFromBuffer(buffer); | 36 fPicture = SkPicture::CreateFromBuffer(buffer); |
37 } | 37 } |
| 38 #endif |
38 | 39 |
39 SkPictureShader::~SkPictureShader() { | 40 SkPictureShader::~SkPictureShader() { |
40 fPicture->unref(); | 41 fPicture->unref(); |
41 } | 42 } |
42 | 43 |
43 SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx,
TileMode tmy, | 44 SkPictureShader* SkPictureShader::Create(const SkPicture* picture, TileMode tmx,
TileMode tmy, |
44 const SkMatrix* localMatrix, const SkRe
ct* tile) { | 45 const SkMatrix* localMatrix, const SkRe
ct* tile) { |
45 if (!picture || 0 == picture->width() || 0 == picture->height() | 46 if (!picture || 0 == picture->width() || 0 == picture->height() |
46 || (NULL != tile && tile->isEmpty())) { | 47 || (NULL != tile && tile->isEmpty())) { |
47 return NULL; | 48 return NULL; |
48 } | 49 } |
49 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile)); | 50 return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix, tile)); |
50 } | 51 } |
51 | 52 |
| 53 SkFlattenable* SkPictureShader::CreateProc(SkReadBuffer& buffer) { |
| 54 SkMatrix lm; |
| 55 buffer.readMatrix(&lm); |
| 56 TileMode mx = (TileMode)buffer.read32(); |
| 57 TileMode my = (TileMode)buffer.read32(); |
| 58 SkRect tile; |
| 59 buffer.readRect(&tile); |
| 60 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromBuffer(buffer)); |
| 61 return SkPictureShader::Create(picture, mx, my, &lm, &tile); |
| 62 } |
| 63 |
52 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { | 64 void SkPictureShader::flatten(SkWriteBuffer& buffer) const { |
53 this->INHERITED::flatten(buffer); | 65 buffer.writeMatrix(this->getLocalMatrix()); |
54 | |
55 buffer.write32(fTmx); | 66 buffer.write32(fTmx); |
56 buffer.write32(fTmy); | 67 buffer.write32(fTmy); |
57 buffer.writeRect(fTile); | 68 buffer.writeRect(fTile); |
58 fPicture->flatten(buffer); | 69 fPicture->flatten(buffer); |
59 } | 70 } |
60 | 71 |
61 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
x* localM) const { | 72 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
x* localM) const { |
62 SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); | 73 SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); |
63 | 74 |
64 SkMatrix m; | 75 SkMatrix m; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 return bitmapShader->asNewEffect(context, paint, NULL, paintColor, effect); | 222 return bitmapShader->asNewEffect(context, paint, NULL, paintColor, effect); |
212 } | 223 } |
213 #else | 224 #else |
214 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint, | 225 bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint, |
215 const SkMatrix* localMatrix, GrColor* paintCol
or, | 226 const SkMatrix* localMatrix, GrColor* paintCol
or, |
216 GrEffect** effect) const { | 227 GrEffect** effect) const { |
217 SkDEBUGFAIL("Should not call in GPU-less build"); | 228 SkDEBUGFAIL("Should not call in GPU-less build"); |
218 return false; | 229 return false; |
219 } | 230 } |
220 #endif | 231 #endif |
OLD | NEW |