| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 this->INHERITED::flatten(buffer); | 48 this->INHERITED::flatten(buffer); |
| 49 | 49 |
| 50 buffer.write32(fTmx); | 50 buffer.write32(fTmx); |
| 51 buffer.write32(fTmy); | 51 buffer.write32(fTmy); |
| 52 buffer.writeBool(NULL != fPicture); | 52 buffer.writeBool(NULL != fPicture); |
| 53 if (fPicture) { | 53 if (fPicture) { |
| 54 fPicture->flatten(buffer); | 54 fPicture->flatten(buffer); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix) const { | 58 SkShader* SkPictureShader::buildBitmapShader(const SkMatrix& matrix) const { |
| 59 if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) { | 59 if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) { |
| 60 return NULL; | 60 return NULL; |
| 61 } | 61 } |
| 62 | 62 |
| 63 SkMatrix m; | 63 SkMatrix m; |
| 64 if (this->hasLocalMatrix()) { | 64 if (this->hasLocalMatrix()) { |
| 65 m.setConcat(matrix, this->getLocalMatrix()); | 65 m.setConcat(matrix, this->getLocalMatrix()); |
| 66 } else { | 66 } else { |
| 67 m = matrix; | 67 m = matrix; |
| 68 } | 68 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 fCachedBitmapShader.get()->ref(); | 114 fCachedBitmapShader.get()->ref(); |
| 115 return fCachedBitmapShader; | 115 return fCachedBitmapShader; |
| 116 } | 116 } |
| 117 | 117 |
| 118 SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint&
paint, | 118 SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint&
paint, |
| 119 const SkMatrix& matrix, SkMatrix* total
Inverse) const { | 119 const SkMatrix& matrix, SkMatrix* total
Inverse) const { |
| 120 if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) { | 120 if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) { |
| 121 return NULL; | 121 return NULL; |
| 122 } | 122 } |
| 123 | 123 |
| 124 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(matrix)); | 124 SkShader* bitmapShader = this->buildBitmapShader(matrix); |
| 125 if (!bitmapShader || !bitmapShader->validContext(device, paint, matrix)) { | 125 if (!bitmapShader) { |
| 126 return NULL; | 126 return NULL; |
| 127 } | 127 } |
| 128 | 128 |
| 129 return bitmapShader.detach(); | 129 if (!bitmapShader->validContext(device, paint, matrix)) { |
| 130 bitmapShader->unref(); |
| 131 return NULL; |
| 132 } |
| 133 |
| 134 return bitmapShader; |
| 130 } | 135 } |
| 131 | 136 |
| 132 bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint, | 137 bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint, |
| 133 const SkMatrix& matrix, SkMatrix* totalInvers
e) const { | 138 const SkMatrix& matrix, SkMatrix* totalInvers
e) const { |
| 134 SkAutoTUnref<SkShader> shader(this->validInternal(device, paint, matrix, tot
alInverse)); | 139 SkAutoTUnref<SkShader> shader(this->validInternal(device, paint, matrix, tot
alInverse)); |
| 135 return shader != NULL; | 140 return shader != NULL; |
| 136 } | 141 } |
| 137 | 142 |
| 138 SkShader::Context* SkPictureShader::createContext(const SkBitmap& device, const
SkPaint& paint, | 143 SkShader::Context* SkPictureShader::createContext(const SkBitmap& device, const
SkPaint& paint, |
| 139 const SkMatrix& matrix, void*
storage) const { | 144 const SkMatrix& matrix, void*
storage) const { |
| 140 SkAutoTUnref<SkShader> bitmapShader(this->validInternal(device, paint, matri
x, NULL)); | 145 SkShader* bitmapShader = this->validInternal(device, paint, matrix, NULL); |
| 141 if (!bitmapShader) { | 146 if (!bitmapShader) { |
| 142 return NULL; | 147 return NULL; |
| 143 } | 148 } |
| 144 | 149 |
| 145 return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext, | 150 return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext, |
| 146 (*this, device, paint, matrix, bitmapShader.deta
ch())); | 151 (*this, device, paint, matrix, bitmapShader)); |
| 147 } | 152 } |
| 148 | 153 |
| 149 size_t SkPictureShader::contextSize() const { | 154 size_t SkPictureShader::contextSize() const { |
| 150 return sizeof(PictureShaderContext); | 155 return sizeof(PictureShaderContext); |
| 151 } | 156 } |
| 152 | 157 |
| 153 SkPictureShader::PictureShaderContext::PictureShaderContext( | 158 SkPictureShader::PictureShaderContext::PictureShaderContext( |
| 154 const SkPictureShader& shader, const SkBitmap& device, | 159 const SkPictureShader& shader, const SkBitmap& device, |
| 155 const SkPaint& paint, const SkMatrix& matrix, SkShader* bitmapShader) | 160 const SkPaint& paint, const SkMatrix& matrix, SkShader* bitmapShader) |
| 156 : INHERITED(shader, device, paint, matrix) | 161 : INHERITED(shader, device, paint, matrix) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 fPicture ? fPicture->height() : 0); | 202 fPicture ? fPicture->height() : 0); |
| 198 | 203 |
| 199 str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]); | 204 str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]); |
| 200 | 205 |
| 201 this->INHERITED::toString(str); | 206 this->INHERITED::toString(str); |
| 202 } | 207 } |
| 203 #endif | 208 #endif |
| 204 | 209 |
| 205 #if SK_SUPPORT_GPU | 210 #if SK_SUPPORT_GPU |
| 206 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { | 211 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { |
| 207 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
())); | 212 SkAutoTUnref<SkShader> bitmapShader(this->buildBitmapShader(context->getMatr
ix())); |
| 208 if (!bitmapShader) { | 213 if (!bitmapShader) { |
| 209 return NULL; | 214 return NULL; |
| 210 } | 215 } |
| 211 return bitmapShader->asNewEffect(context, paint); | 216 return bitmapShader->asNewEffect(context, paint); |
| 212 } | 217 } |
| 213 #endif | 218 #endif |
| OLD | NEW |