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 const SkMatrix* localMatrix) | 22 : fPicture(SkRef(picture)) |
23 : INHERITED(localMatrix) | |
24 , fPicture(SkRef(picture)) | |
25 , fTmx(tmx) | 23 , fTmx(tmx) |
26 , fTmy(tmy) { } | 24 , fTmy(tmy) { } |
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 fPicture = SkPicture::CreateFromBuffer(buffer); | 30 fPicture = SkPicture::CreateFromBuffer(buffer); |
33 } | 31 } |
34 | 32 |
35 SkPictureShader::~SkPictureShader() { | 33 SkPictureShader::~SkPictureShader() { |
36 fPicture->unref(); | 34 fPicture->unref(); |
37 } | 35 } |
38 | 36 |
39 SkPictureShader* SkPictureShader::Create(SkPicture* picture, TileMode tmx, TileM
ode tmy, | 37 SkPictureShader* SkPictureShader::Create(SkPicture* picture, TileMode tmx, TileM
ode tmy) { |
40 const SkMatrix* localMatrix) { | |
41 if (!picture || 0 == picture->width() || 0 == picture->height()) { | 38 if (!picture || 0 == picture->width() || 0 == picture->height()) { |
42 return NULL; | 39 return NULL; |
43 } | 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); |
(...skipping 24 matching lines...) Expand all Loading... |
75 if (tileSize.isEmpty()) { | 72 if (tileSize.isEmpty()) { |
76 return NULL; | 73 return NULL; |
77 } | 74 } |
78 | 75 |
79 // The actual scale, compensating for rounding. | 76 // The actual scale, compensating for rounding. |
80 SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fPicture->
width(), | 77 SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fPicture->
width(), |
81 SkIntToScalar(tileSize.height()) / fPicture-
>height()); | 78 SkIntToScalar(tileSize.height()) / fPicture-
>height()); |
82 | 79 |
83 SkAutoMutexAcquire ama(fCachedBitmapShaderMutex); | 80 SkAutoMutexAcquire ama(fCachedBitmapShaderMutex); |
84 | 81 |
85 // TODO(fmalita): remove fCachedLocalMatrix from this key after getLocalMatr
ix is removed. | |
86 if (!fCachedBitmapShader || tileScale != fCachedTileScale || | 82 if (!fCachedBitmapShader || tileScale != fCachedTileScale || |
87 this->getLocalMatrix() != fCachedLocalMatrix) { | 83 this->getLocalMatrix() != fCachedLocalMatrix) { |
88 SkBitmap bm; | 84 SkBitmap bm; |
89 if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) { | 85 if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) { |
90 return NULL; | 86 return NULL; |
91 } | 87 } |
92 bm.eraseColor(SK_ColorTRANSPARENT); | 88 bm.eraseColor(SK_ColorTRANSPARENT); |
93 | 89 |
94 SkCanvas canvas(bm); | 90 SkCanvas canvas(bm); |
95 canvas.scale(tileScale.width(), tileScale.height()); | 91 canvas.scale(tileScale.width(), tileScale.height()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 189 |
194 #if SK_SUPPORT_GPU | 190 #if SK_SUPPORT_GPU |
195 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { | 191 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { |
196 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
())); | 192 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
())); |
197 if (!bitmapShader) { | 193 if (!bitmapShader) { |
198 return NULL; | 194 return NULL; |
199 } | 195 } |
200 return bitmapShader->asNewEffect(context, paint); | 196 return bitmapShader->asNewEffect(context, paint); |
201 } | 197 } |
202 #endif | 198 #endif |
OLD | NEW |