| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
| 9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
| 10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (kIndex_8_SkColorType == bm.colorType()) { | 90 if (kIndex_8_SkColorType == bm.colorType()) { |
| 91 // ugh, I have to lock-pixels to inspect the colortable | 91 // ugh, I have to lock-pixels to inspect the colortable |
| 92 SkAutoLockPixels alp(bm); | 92 SkAutoLockPixels alp(bm); |
| 93 if (!bm.getColorTable()) { | 93 if (!bm.getColorTable()) { |
| 94 return false; | 94 return false; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool SkBitmapProcShader::validInternal(const SkBitmap& device, | 100 bool SkBitmapProcShader::validInternal(const ContextRec& rec, SkMatrix* totalInv
erse, |
| 101 const SkPaint& paint, | |
| 102 const SkMatrix& matrix, | |
| 103 SkMatrix* totalInverse, | |
| 104 SkBitmapProcState* state) const { | 101 SkBitmapProcState* state) const { |
| 105 if (!fRawBitmap.getTexture() && !valid_for_drawing(fRawBitmap)) { | 102 if (!fRawBitmap.getTexture() && !valid_for_drawing(fRawBitmap)) { |
| 106 return false; | 103 return false; |
| 107 } | 104 } |
| 108 | 105 |
| 109 // Make sure we can use totalInverse as a cache. | 106 // Make sure we can use totalInverse as a cache. |
| 110 SkMatrix totalInverseLocal; | 107 SkMatrix totalInverseLocal; |
| 111 if (NULL == totalInverse) { | 108 if (NULL == totalInverse) { |
| 112 totalInverse = &totalInverseLocal; | 109 totalInverse = &totalInverseLocal; |
| 113 } | 110 } |
| 114 | 111 |
| 115 // Do this first, so we know the matrix can be inverted. | 112 // Do this first, so we know the matrix can be inverted. |
| 116 if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) { | 113 if (!this->INHERITED::validContext(rec, totalInverse)) { |
| 117 return false; | 114 return false; |
| 118 } | 115 } |
| 119 | 116 |
| 120 SkASSERT(state); | 117 SkASSERT(state); |
| 121 state->fTileModeX = fTileModeX; | 118 state->fTileModeX = fTileModeX; |
| 122 state->fTileModeY = fTileModeY; | 119 state->fTileModeY = fTileModeY; |
| 123 state->fOrigBitmap = fRawBitmap; | 120 state->fOrigBitmap = fRawBitmap; |
| 124 return state->chooseProcs(*totalInverse, paint); | 121 return state->chooseProcs(*totalInverse, *rec.fPaint); |
| 125 } | 122 } |
| 126 | 123 |
| 127 bool SkBitmapProcShader::validContext(const SkBitmap& device, | 124 bool SkBitmapProcShader::validContext(const ContextRec& rec, SkMatrix* totalInve
rse) const { |
| 128 const SkPaint& paint, | |
| 129 const SkMatrix& matrix, | |
| 130 SkMatrix* totalInverse) const { | |
| 131 SkBitmapProcState state; | 125 SkBitmapProcState state; |
| 132 return this->validInternal(device, paint, matrix, totalInverse, &state); | 126 return this->validInternal(rec, totalInverse, &state); |
| 133 } | 127 } |
| 134 | 128 |
| 135 SkShader::Context* SkBitmapProcShader::createContext(const SkBitmap& device, con
st SkPaint& paint, | 129 SkShader::Context* SkBitmapProcShader::createContext(const ContextRec& rec, void
* storage) const { |
| 136 const SkMatrix& matrix, voi
d* storage) const { | |
| 137 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); | 130 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); |
| 138 SkBitmapProcState* state = SkNEW_PLACEMENT(stateStorage, SkBitmapProcState); | 131 SkBitmapProcState* state = SkNEW_PLACEMENT(stateStorage, SkBitmapProcState); |
| 139 if (!this->validInternal(device, paint, matrix, NULL, state)) { | 132 if (!this->validInternal(rec, NULL, state)) { |
| 140 state->~SkBitmapProcState(); | 133 state->~SkBitmapProcState(); |
| 141 return NULL; | 134 return NULL; |
| 142 } | 135 } |
| 143 | 136 |
| 144 return SkNEW_PLACEMENT_ARGS(storage, BitmapProcShaderContext, | 137 return SkNEW_PLACEMENT_ARGS(storage, BitmapProcShaderContext, (*this, rec, s
tate)); |
| 145 (*this, device, paint, matrix, state)); | |
| 146 } | 138 } |
| 147 | 139 |
| 148 size_t SkBitmapProcShader::contextSize() const { | 140 size_t SkBitmapProcShader::contextSize() const { |
| 149 // The SkBitmapProcState is stored outside of the context object, with the c
ontext holding | 141 // The SkBitmapProcState is stored outside of the context object, with the c
ontext holding |
| 150 // a pointer to it. | 142 // a pointer to it. |
| 151 return sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState); | 143 return sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState); |
| 152 } | 144 } |
| 153 | 145 |
| 154 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext( | 146 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext( |
| 155 const SkBitmapProcShader& shader, const SkBitmap& device, | 147 const SkBitmapProcShader& shader, const ContextRec& rec, SkBitmapProcSta
te* state) |
| 156 const SkPaint& paint, const SkMatrix& matrix, SkBitmapProcState* state) | 148 : INHERITED(shader, rec) |
| 157 : INHERITED(shader, device, paint, matrix) | |
| 158 , fState(state) | 149 , fState(state) |
| 159 { | 150 { |
| 160 const SkBitmap& bitmap = *fState->fBitmap; | 151 const SkBitmap& bitmap = *fState->fBitmap; |
| 161 bool bitmapIsOpaque = bitmap.isOpaque(); | 152 bool bitmapIsOpaque = bitmap.isOpaque(); |
| 162 | 153 |
| 163 // update fFlags | 154 // update fFlags |
| 164 uint32_t flags = 0; | 155 uint32_t flags = 0; |
| 165 if (bitmapIsOpaque && (255 == this->getPaintAlpha())) { | 156 if (bitmapIsOpaque && (255 == this->getPaintAlpha())) { |
| 166 flags |= kOpaqueAlpha_Flag; | 157 flags |= kOpaqueAlpha_Flag; |
| 167 } | 158 } |
| 168 | 159 |
| 169 switch (bitmap.colorType()) { | 160 switch (bitmap.colorType()) { |
| 170 case kRGB_565_SkColorType: | 161 case kRGB_565_SkColorType: |
| 171 flags |= (kHasSpan16_Flag | kIntrinsicly16_Flag); | 162 flags |= (kHasSpan16_Flag | kIntrinsicly16_Flag); |
| 172 break; | 163 break; |
| 173 case kIndex_8_SkColorType: | 164 case kIndex_8_SkColorType: |
| 174 case kN32_SkColorType: | 165 case kN32_SkColorType: |
| 175 if (bitmapIsOpaque) { | 166 if (bitmapIsOpaque) { |
| 176 flags |= kHasSpan16_Flag; | 167 flags |= kHasSpan16_Flag; |
| 177 } | 168 } |
| 178 break; | 169 break; |
| 179 case kAlpha_8_SkColorType: | 170 case kAlpha_8_SkColorType: |
| 180 break; // never set kHasSpan16_Flag | 171 break; // never set kHasSpan16_Flag |
| 181 default: | 172 default: |
| 182 break; | 173 break; |
| 183 } | 174 } |
| 184 | 175 |
| 185 if (paint.isDither() && bitmap.colorType() != kRGB_565_SkColorType) { | 176 if (rec.fPaint->isDither() && bitmap.colorType() != kRGB_565_SkColorType) { |
| 186 // gradients can auto-dither in their 16bit sampler, but we don't so | 177 // gradients can auto-dither in their 16bit sampler, but we don't so |
| 187 // we clear the flag here. | 178 // we clear the flag here. |
| 188 flags &= ~kHasSpan16_Flag; | 179 flags &= ~kHasSpan16_Flag; |
| 189 } | 180 } |
| 190 | 181 |
| 191 // if we're only 1-pixel high, and we don't rotate, then we can claim this | 182 // if we're only 1-pixel high, and we don't rotate, then we can claim this |
| 192 if (1 == bitmap.height() && | 183 if (1 == bitmap.height() && |
| 193 only_scale_and_translate(this->getTotalInverse())) { | 184 only_scale_and_translate(this->getTotalInverse())) { |
| 194 flags |= kConstInY32_Flag; | 185 flags |= kConstInY32_Flag; |
| 195 if (flags & kHasSpan16_Flag) { | 186 if (flags & kHasSpan16_Flag) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 GrEffectRef* effect = NULL; | 478 GrEffectRef* effect = NULL; |
| 488 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { | 479 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { |
| 489 effect = GrBicubicEffect::Create(texture, matrix, tm); | 480 effect = GrBicubicEffect::Create(texture, matrix, tm); |
| 490 } else { | 481 } else { |
| 491 effect = GrSimpleTextureEffect::Create(texture, matrix, params); | 482 effect = GrSimpleTextureEffect::Create(texture, matrix, params); |
| 492 } | 483 } |
| 493 GrUnlockAndUnrefCachedBitmapTexture(texture); | 484 GrUnlockAndUnrefCachedBitmapTexture(texture); |
| 494 return effect; | 485 return effect; |
| 495 } | 486 } |
| 496 #endif | 487 #endif |
| OLD | NEW |