Index: src/core/SkBitmapProcShader.cpp |
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp |
index 55a772ec10ace94578a4be78cedbd508de1deb97..baf1e57b04edd40f063f4387b8799d6cdfa0b72c 100644 |
--- a/src/core/SkBitmapProcShader.cpp |
+++ b/src/core/SkBitmapProcShader.cpp |
@@ -34,18 +34,16 @@ bool SkBitmapProcShader::CanDo(const SkBitmap& bm, TileMode tx, TileMode ty) { |
SkBitmapProcShader::SkBitmapProcShader(const SkBitmap& src, |
TileMode tmx, TileMode tmy) { |
fRawBitmap = src; |
- fState.fTileModeX = (uint8_t)tmx; |
- fState.fTileModeY = (uint8_t)tmy; |
- fFlags = 0; // computed in setContext |
+ fTileModeX = (uint8_t)tmx; |
+ fTileModeY = (uint8_t)tmy; |
} |
SkBitmapProcShader::SkBitmapProcShader(SkReadBuffer& buffer) |
: INHERITED(buffer) { |
buffer.readBitmap(&fRawBitmap); |
fRawBitmap.setImmutable(); |
- fState.fTileModeX = buffer.readUInt(); |
- fState.fTileModeY = buffer.readUInt(); |
- fFlags = 0; // computed in setContext |
+ fTileModeX = buffer.readUInt(); |
+ fTileModeY = buffer.readUInt(); |
} |
SkShader::BitmapType SkBitmapProcShader::asABitmap(SkBitmap* texture, |
@@ -58,8 +56,8 @@ SkShader::BitmapType SkBitmapProcShader::asABitmap(SkBitmap* texture, |
texM->reset(); |
} |
if (xy) { |
- xy[0] = (TileMode)fState.fTileModeX; |
- xy[1] = (TileMode)fState.fTileModeY; |
+ xy[0] = (TileMode)fTileModeX; |
+ xy[1] = (TileMode)fTileModeY; |
} |
return kDefault_BitmapType; |
} |
@@ -68,8 +66,8 @@ void SkBitmapProcShader::flatten(SkWriteBuffer& buffer) const { |
this->INHERITED::flatten(buffer); |
buffer.writeBitmap(fRawBitmap); |
- buffer.writeUInt(fState.fTileModeX); |
- buffer.writeUInt(fState.fTileModeY); |
+ buffer.writeUInt(fTileModeX); |
+ buffer.writeUInt(fTileModeY); |
} |
static bool only_scale_and_translate(const SkMatrix& matrix) { |
@@ -98,24 +96,64 @@ static bool valid_for_drawing(const SkBitmap& bm) { |
return true; |
} |
-bool SkBitmapProcShader::setContext(const SkBitmap& device, |
- const SkPaint& paint, |
- const SkMatrix& matrix) { |
+bool SkBitmapProcShader::validInternal(const SkBitmap& device, |
+ const SkPaint& paint, |
+ const SkMatrix& matrix, |
+ SkMatrix* totalInverse, |
+ SkBitmapProcState* state) const { |
if (!fRawBitmap.getTexture() && !valid_for_drawing(fRawBitmap)) { |
return false; |
} |
- // do this first, so we have a correct inverse matrix |
- if (!this->INHERITED::setContext(device, paint, matrix)) { |
+ // Make sure we can use totalInverse as a cache. |
+ SkMatrix totalInverseLocal; |
+ if (totalInverse == NULL) { |
scroggo
2014/03/28 20:50:08
nit: Prefer putting NULL on the left of this check
Dominik Grewe
2014/04/01 10:49:55
Done.
|
+ totalInverse = &totalInverseLocal; |
+ } |
+ |
+ // Do this first, so we know the matrix can be inverted. |
+ if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) { |
return false; |
} |
- fState.fOrigBitmap = fRawBitmap; |
- if (!fState.chooseProcs(this->getTotalInverse(), paint)) { |
- this->INHERITED::endContext(); |
+ SkASSERT(state); |
+ state->fTileModeX = fTileModeX; |
+ state->fTileModeY = fTileModeY; |
+ state->fOrigBitmap = fRawBitmap; |
+ if (!state->chooseProcs(*totalInverse, paint)) { |
scroggo
2014/03/28 20:50:08
return state->chooseProcs(*totalInverse, paint);
Dominik Grewe
2014/04/01 10:49:55
Done.
|
return false; |
} |
+ return true; |
+} |
+ |
+bool SkBitmapProcShader::validContext(const SkBitmap& device, |
+ const SkPaint& paint, |
+ const SkMatrix& matrix, |
+ SkMatrix* totalInverse) const { |
+ SkBitmapProcState state; |
+ return this->validInternal(device, paint, matrix, totalInverse, &state); |
+} |
+ |
+SkShader::Context* SkBitmapProcShader::createContext(const SkBitmap& device, const SkPaint& paint, |
+ const SkMatrix& matrix, void* storage) const { |
+ SkBitmapProcState state; |
+ if (!this->validInternal(device, paint, matrix, NULL, &state)) { |
+ return NULL; |
+ } |
+ |
+ return SkNEW_PLACEMENT_ARGS(storage, BitmapProcShaderContext, (*this, device, paint, matrix, state)); |
scroggo
2014/03/28 20:50:08
nit: 100 chars.
Dominik Grewe
2014/04/01 10:49:55
Done.
|
+} |
+ |
+size_t SkBitmapProcShader::contextSize() const { |
+ return sizeof(BitmapProcShaderContext); |
+} |
+ |
+SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext( |
+ const SkBitmapProcShader& shader, const SkBitmap& device, |
+ const SkPaint& paint, const SkMatrix& matrix, const SkBitmapProcState& state) |
+ : INHERITED(shader, device, paint, matrix), fState(state) |
+{ |
const SkBitmap& bitmap = *fState.fBitmap; |
bool bitmapIsOpaque = bitmap.isOpaque(); |
@@ -157,12 +195,6 @@ bool SkBitmapProcShader::setContext(const SkBitmap& device, |
} |
fFlags = flags; |
- return true; |
-} |
- |
-void SkBitmapProcShader::endContext() { |
- fState.endContext(); |
- this->INHERITED::endContext(); |
} |
#define BUF_MAX 128 |
@@ -176,7 +208,8 @@ void SkBitmapProcShader::endContext() { |
#define TEST_BUFFER_EXTRA 0 |
#endif |
-void SkBitmapProcShader::shadeSpan(int x, int y, SkPMColor dstC[], int count) { |
+void SkBitmapProcShader::BitmapProcShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], |
+ int count) { |
const SkBitmapProcState& state = fState; |
if (state.getShaderProc32()) { |
state.getShaderProc32()(state, x, y, dstC, count); |
@@ -220,7 +253,7 @@ void SkBitmapProcShader::shadeSpan(int x, int y, SkPMColor dstC[], int count) { |
} |
} |
-SkShader::ShadeProc SkBitmapProcShader::asAShadeProc(void** ctx) { |
+SkShader::Context::ShadeProc SkBitmapProcShader::BitmapProcShaderContext::asAShadeProc(void** ctx) { |
if (fState.getShaderProc32()) { |
*ctx = &fState; |
return (ShadeProc)fState.getShaderProc32(); |
@@ -228,7 +261,8 @@ SkShader::ShadeProc SkBitmapProcShader::asAShadeProc(void** ctx) { |
return NULL; |
} |
-void SkBitmapProcShader::shadeSpan16(int x, int y, uint16_t dstC[], int count) { |
+void SkBitmapProcShader::BitmapProcShaderContext::shadeSpan16(int x, int y, uint16_t dstC[], |
+ int count) { |
const SkBitmapProcState& state = fState; |
if (state.getShaderProc16()) { |
state.getShaderProc16()(state, x, y, dstC, count); |
@@ -342,8 +376,8 @@ void SkBitmapProcShader::toString(SkString* str) const { |
str->append("BitmapShader: ("); |
str->appendf("(%s, %s)", |
- gTileModeName[fState.fTileModeX], |
- gTileModeName[fState.fTileModeY]); |
+ gTileModeName[fTileModeX], |
+ gTileModeName[fTileModeY]); |
str->append(" "); |
fRawBitmap.toString(str); |
@@ -384,8 +418,8 @@ GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& |
matrix.preConcat(lmInverse); |
SkShader::TileMode tm[] = { |
- (TileMode)fState.fTileModeX, |
- (TileMode)fState.fTileModeY, |
+ (TileMode)fTileModeX, |
+ (TileMode)fTileModeY, |
}; |
// Must set wrap and filter on the sampler before requesting a texture. In two places below |