| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 fCachedBitmapShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatr
ix)); | 99 fCachedBitmapShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatr
ix)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // 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. |
| 103 // 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 |
| 104 // ref count was incremented. | 104 // ref count was incremented. |
| 105 fCachedBitmapShader.get()->ref(); | 105 fCachedBitmapShader.get()->ref(); |
| 106 return fCachedBitmapShader; | 106 return fCachedBitmapShader; |
| 107 } | 107 } |
| 108 | 108 |
| 109 SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint&
paint, | 109 SkShader* SkPictureShader::validInternal(const ContextRec& rec, SkMatrix* totalI
nverse) const { |
| 110 const SkMatrix& matrix, SkMatrix* total
Inverse) const { | 110 if (!this->INHERITED::validContext(rec, totalInverse)) { |
| 111 if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) { | |
| 112 return NULL; | 111 return NULL; |
| 113 } | 112 } |
| 114 | 113 |
| 115 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(matrix)); | 114 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix)); |
| 116 if (!bitmapShader || !bitmapShader->validContext(device, paint, matrix)) { | 115 if (!bitmapShader || !bitmapShader->validContext(rec)) { |
| 117 return NULL; | 116 return NULL; |
| 118 } | 117 } |
| 119 | 118 |
| 120 return bitmapShader.detach(); | 119 return bitmapShader.detach(); |
| 121 } | 120 } |
| 122 | 121 |
| 123 bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint, | 122 bool SkPictureShader::validContext(const ContextRec& rec, SkMatrix* totalInverse
) const { |
| 124 const SkMatrix& matrix, SkMatrix* totalInvers
e) const { | 123 SkAutoTUnref<SkShader> shader(this->validInternal(rec, totalInverse)); |
| 125 SkAutoTUnref<SkShader> shader(this->validInternal(device, paint, matrix, tot
alInverse)); | |
| 126 return shader != NULL; | 124 return shader != NULL; |
| 127 } | 125 } |
| 128 | 126 |
| 129 SkShader::Context* SkPictureShader::createContext(const SkBitmap& device, const
SkPaint& paint, | 127 SkShader::Context* SkPictureShader::createContext(const ContextRec& rec, void* s
torage) const { |
| 130 const SkMatrix& matrix, void*
storage) const { | 128 SkAutoTUnref<SkShader> bitmapShader(this->validInternal(rec, NULL)); |
| 131 SkAutoTUnref<SkShader> bitmapShader(this->validInternal(device, paint, matri
x, NULL)); | |
| 132 if (!bitmapShader) { | 129 if (!bitmapShader) { |
| 133 return NULL; | 130 return NULL; |
| 134 } | 131 } |
| 135 | 132 |
| 136 return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext, | 133 return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext, (*this, rec, bitm
apShader.detach())); |
| 137 (*this, device, paint, matrix, bitmapShader.deta
ch())); | |
| 138 } | 134 } |
| 139 | 135 |
| 140 size_t SkPictureShader::contextSize() const { | 136 size_t SkPictureShader::contextSize() const { |
| 141 return sizeof(PictureShaderContext); | 137 return sizeof(PictureShaderContext); |
| 142 } | 138 } |
| 143 | 139 |
| 144 SkPictureShader::PictureShaderContext::PictureShaderContext( | 140 SkPictureShader::PictureShaderContext::PictureShaderContext( |
| 145 const SkPictureShader& shader, const SkBitmap& device, | 141 const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapSh
ader) |
| 146 const SkPaint& paint, const SkMatrix& matrix, SkShader* bitmapShader) | 142 : INHERITED(shader, rec) |
| 147 : INHERITED(shader, device, paint, matrix) | |
| 148 , fBitmapShader(bitmapShader) | 143 , fBitmapShader(bitmapShader) |
| 149 { | 144 { |
| 150 SkASSERT(fBitmapShader); | 145 SkASSERT(fBitmapShader); |
| 151 fBitmapShaderContextStorage = sk_malloc_throw(fBitmapShader->contextSize()); | 146 fBitmapShaderContextStorage = sk_malloc_throw(fBitmapShader->contextSize()); |
| 152 fBitmapShaderContext = fBitmapShader->createContext( | 147 fBitmapShaderContext = fBitmapShader->createContext(rec, fBitmapShaderContex
tStorage); |
| 153 device, paint, matrix, fBitmapShaderContextStorage); | |
| 154 SkASSERT(fBitmapShaderContext); | 148 SkASSERT(fBitmapShaderContext); |
| 155 } | 149 } |
| 156 | 150 |
| 157 SkPictureShader::PictureShaderContext::~PictureShaderContext() { | 151 SkPictureShader::PictureShaderContext::~PictureShaderContext() { |
| 158 fBitmapShaderContext->~Context(); | 152 fBitmapShaderContext->~Context(); |
| 159 sk_free(fBitmapShaderContextStorage); | 153 sk_free(fBitmapShaderContextStorage); |
| 160 } | 154 } |
| 161 | 155 |
| 162 uint32_t SkPictureShader::PictureShaderContext::getFlags() const { | 156 uint32_t SkPictureShader::PictureShaderContext::getFlags() const { |
| 163 return fBitmapShaderContext->getFlags(); | 157 return fBitmapShaderContext->getFlags(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 189 |
| 196 #if SK_SUPPORT_GPU | 190 #if SK_SUPPORT_GPU |
| 197 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { | 191 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai
nt) const { |
| 198 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
())); | 192 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix
())); |
| 199 if (!bitmapShader) { | 193 if (!bitmapShader) { |
| 200 return NULL; | 194 return NULL; |
| 201 } | 195 } |
| 202 return bitmapShader->asNewEffect(context, paint); | 196 return bitmapShader->asNewEffect(context, paint); |
| 203 } | 197 } |
| 204 #endif | 198 #endif |
| OLD | NEW |