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