| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 SkBitmap bm; | 84 SkBitmap bm; |
| 85 if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) { | 85 if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) { |
| 86 return NULL; | 86 return NULL; |
| 87 } | 87 } |
| 88 bm.eraseColor(SK_ColorTRANSPARENT); | 88 bm.eraseColor(SK_ColorTRANSPARENT); |
| 89 | 89 |
| 90 SkCanvas canvas(bm); | 90 SkCanvas canvas(bm); |
| 91 canvas.scale(tileScale.width(), tileScale.height()); | 91 canvas.scale(tileScale.width(), tileScale.height()); |
| 92 canvas.drawPicture(*fPicture); | 92 canvas.drawPicture(*fPicture); |
| 93 | 93 |
| 94 fCachedBitmapShader.reset(CreateBitmapShader(bm, fTmx, fTmy)); | |
| 95 fCachedTileScale = tileScale; | 94 fCachedTileScale = tileScale; |
| 96 fCachedLocalMatrix = this->getLocalMatrix(); | 95 fCachedLocalMatrix = this->getLocalMatrix(); |
| 97 | 96 |
| 98 SkMatrix shaderMatrix = this->getLocalMatrix(); | 97 SkMatrix shaderMatrix = this->getLocalMatrix(); |
| 99 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); | 98 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); |
| 100 fCachedBitmapShader->setLocalMatrix(shaderMatrix); | 99 fCachedBitmapShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatr
ix)); |
| 101 } | 100 } |
| 102 | 101 |
| 103 // Increment the ref counter inside the mutex to ensure the returned pointer
is still valid. | 102 // Increment the ref counter inside the mutex to ensure the returned pointer
is still valid. |
| 104 // Otherwise, the pointer may have been overwritten on a different thread be
fore the object's | 103 // Otherwise, the pointer may have been overwritten on a different thread be
fore the object's |
| 105 // ref count was incremented. | 104 // ref count was incremented. |
| 106 fCachedBitmapShader.get()->ref(); | 105 fCachedBitmapShader.get()->ref(); |
| 107 return fCachedBitmapShader; | 106 return fCachedBitmapShader; |
| 108 } | 107 } |
| 109 | 108 |
| 110 SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint&
paint, | 109 SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint&
paint, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 195 |
| 197 #if SK_SUPPORT_GPU | 196 #if SK_SUPPORT_GPU |
| 198 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { | 197 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { |
| 199 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
())); | 198 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
())); |
| 200 if (!bitmapShader) { | 199 if (!bitmapShader) { |
| 201 return NULL; | 200 return NULL; |
| 202 } | 201 } |
| 203 return bitmapShader->asNewEffect(context, paint); | 202 return bitmapShader->asNewEffect(context, paint); |
| 204 } | 203 } |
| 205 #endif | 204 #endif |
| OLD | NEW |