| 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 ContextRec& rec, SkMatrix* totalInv
erse, | 100 SkShader::Context* SkBitmapProcShader::onCreateContext(const ContextRec& rec, vo
id* storage) const { |
| 101 SkBitmapProcState* state) const { | |
| 102 if (!fRawBitmap.getTexture() && !valid_for_drawing(fRawBitmap)) { | 101 if (!fRawBitmap.getTexture() && !valid_for_drawing(fRawBitmap)) { |
| 103 return false; | 102 return NULL; |
| 104 } | 103 } |
| 105 | 104 |
| 106 // Make sure we can use totalInverse as a cache. | 105 SkMatrix totalInverse; |
| 107 SkMatrix totalInverseLocal; | 106 // Do this first, so we know the matrix can be inverted. |
| 108 if (NULL == totalInverse) { | 107 if (!this->computeTotalInverse(rec, &totalInverse)) { |
| 109 totalInverse = &totalInverseLocal; | 108 return NULL; |
| 110 } | 109 } |
| 111 | 110 |
| 112 // Do this first, so we know the matrix can be inverted. | 111 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); |
| 113 if (!this->INHERITED::validContext(rec, totalInverse)) { | 112 SkBitmapProcState* state = SkNEW_PLACEMENT(stateStorage, SkBitmapProcState); |
| 114 return false; | |
| 115 } | |
| 116 | 113 |
| 117 SkASSERT(state); | 114 SkASSERT(state); |
| 118 state->fTileModeX = fTileModeX; | 115 state->fTileModeX = fTileModeX; |
| 119 state->fTileModeY = fTileModeY; | 116 state->fTileModeY = fTileModeY; |
| 120 state->fOrigBitmap = fRawBitmap; | 117 state->fOrigBitmap = fRawBitmap; |
| 121 return state->chooseProcs(*totalInverse, *rec.fPaint); | 118 if (!state->chooseProcs(totalInverse, *rec.fPaint)) { |
| 122 } | |
| 123 | |
| 124 bool SkBitmapProcShader::validContext(const ContextRec& rec, SkMatrix* totalInve
rse) const { | |
| 125 SkBitmapProcState state; | |
| 126 return this->validInternal(rec, totalInverse, &state); | |
| 127 } | |
| 128 | |
| 129 SkShader::Context* SkBitmapProcShader::createContext(const ContextRec& rec, void
* storage) const { | |
| 130 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); | |
| 131 SkBitmapProcState* state = SkNEW_PLACEMENT(stateStorage, SkBitmapProcState); | |
| 132 if (!this->validInternal(rec, NULL, state)) { | |
| 133 state->~SkBitmapProcState(); | 119 state->~SkBitmapProcState(); |
| 134 return NULL; | 120 return NULL; |
| 135 } | 121 } |
| 136 | 122 |
| 137 return SkNEW_PLACEMENT_ARGS(storage, BitmapProcShaderContext, (*this, rec, s
tate)); | 123 return SkNEW_PLACEMENT_ARGS(storage, BitmapProcShaderContext, (*this, rec, s
tate)); |
| 138 } | 124 } |
| 139 | 125 |
| 140 size_t SkBitmapProcShader::contextSize() const { | 126 size_t SkBitmapProcShader::contextSize() const { |
| 141 // The SkBitmapProcState is stored outside of the context object, with the c
ontext holding | 127 // The SkBitmapProcState is stored outside of the context object, with the c
ontext holding |
| 142 // a pointer to it. | 128 // a pointer to it. |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 GrEffectRef* effect = NULL; | 464 GrEffectRef* effect = NULL; |
| 479 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { | 465 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { |
| 480 effect = GrBicubicEffect::Create(texture, matrix, tm); | 466 effect = GrBicubicEffect::Create(texture, matrix, tm); |
| 481 } else { | 467 } else { |
| 482 effect = GrSimpleTextureEffect::Create(texture, matrix, params); | 468 effect = GrSimpleTextureEffect::Create(texture, matrix, params); |
| 483 } | 469 } |
| 484 GrUnlockAndUnrefCachedBitmapTexture(texture); | 470 GrUnlockAndUnrefCachedBitmapTexture(texture); |
| 485 return effect; | 471 return effect; |
| 486 } | 472 } |
| 487 #endif | 473 #endif |
| OLD | NEW |