Index: src/core/SkShader.cpp |
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp |
index bebfc59912f51310b9305ca578959387bbed2816..bc3eb081620be8cb428821175e992bf2123c3b65 100644 |
--- a/src/core/SkShader.cpp |
+++ b/src/core/SkShader.cpp |
@@ -42,30 +42,50 @@ void SkShader::flatten(SkWriteBuffer& buffer) const { |
} |
} |
-bool SkShader::setContext(const SkBitmap& device, |
- const SkPaint& paint, |
- const SkMatrix& matrix) { |
+SkShader::Context::Context(const SkMatrix& matrix, uint8_t paintAlpha, |
+ SkBitmap::Config deviceConfig) |
+ : fTotalInverse(matrix) |
+ , fPaintAlpha(paintAlpha) |
+ , fDeviceConfig(SkToU8(deviceConfig)) |
+ , fTotalInverseClass((uint8_t) ComputeMatrixClass(fTotalInverse)) |
+ , fExtraStorage(NULL) |
+{ |
+ // debugcode... |
+ fStorageAllocated = false; |
+} |
+ |
+SkShader::Context* SkShader::setContext(const SkBitmap& device, |
+ const SkPaint& paint, |
+ const SkMatrix& matrix) { |
SkASSERT(!this->setContextHasBeenCalled()); |
const SkMatrix* m = &matrix; |
SkMatrix total; |
- fDeviceConfig = SkToU8(device.config()); |
- fPaintAlpha = paint.getAlpha(); |
+ // FIXME: Store localMatrix on paint. |
if (this->hasLocalMatrix()) { |
total.setConcat(matrix, this->getLocalMatrix()); |
m = &total; |
} |
- if (m->invert(&fTotalInverse)) { |
- fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse); |
+ SkMatrix totalInverse; |
+ if (m->invert(&totalInverse)) { |
+ Context* context = SkNEW_ARGS(Context, (totalInverse, paint.getAlpha(), device.config())); |
+ // Initialize the subclass storage space. |
+ context->reset(this); |
+ // Now call into subclasses. |
+ if (!this->onSetContext(context, device, paint, matrix)) { |
+ SkDELETE(context); |
+ return NULL; |
+ } |
SkDEBUGCODE(fInSetContext = true;) |
- return true; |
+ return context; |
} |
- return false; |
+ return NULL; |
} |
-void SkShader::endContext() { |
+void SkShader::endContext(Context* c) { |
SkASSERT(fInSetContext); |
+ SkDELETE(c); |
SkDEBUGCODE(fInSetContext = false;) |
} |
@@ -75,7 +95,7 @@ SkShader::ShadeProc SkShader::asAShadeProc(void** ctx) { |
#include "SkColorPriv.h" |
-void SkShader::shadeSpan16(int x, int y, uint16_t span16[], int count) { |
+void SkShader::shadeSpan16(Context* c, int x, int y, uint16_t span16[], int count) { |
SkASSERT(span16); |
SkASSERT(count > 0); |
SkASSERT(this->canCallShadeSpan16()); |
@@ -93,13 +113,13 @@ void SkShader::shadeSpan16(int x, int y, uint16_t span16[], int count) { |
#define SkU32BitShiftToByteOffset(shift) ((shift) >> 3) |
#endif |
-void SkShader::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) { |
+void SkShader::shadeSpanAlpha(Context* context, int x, int y, uint8_t alpha[], int count) { |
SkASSERT(count > 0); |
SkPMColor colors[kTempColorCount]; |
while ((count -= kTempColorCount) >= 0) { |
- this->shadeSpan(x, y, colors, kTempColorCount); |
+ this->shadeSpan(context, x, y, colors, kTempColorCount); |
x += kTempColorCount; |
const uint8_t* srcA = (const uint8_t*)colors + SkU32BitShiftToByteOffset(SK_A32_SHIFT); |
@@ -119,7 +139,7 @@ void SkShader::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) { |
SkASSERT(count < 0); |
SkASSERT(count + kTempColorCount >= 0); |
if (count += kTempColorCount) { |
- this->shadeSpan(x, y, colors, count); |
+ this->shadeSpan(context, x, y, colors, count); |
const uint8_t* srcA = (const uint8_t*)colors + SkU32BitShiftToByteOffset(SK_A32_SHIFT); |
do { |
@@ -237,13 +257,13 @@ uint32_t SkColorShader::getFlags() { |
return fFlags; |
} |
-uint8_t SkColorShader::getSpan16Alpha() const { |
+uint8_t SkColorShader::getSpan16Alpha(Context* c) const { |
return SkGetPackedA32(fPMColor); |
} |
-bool SkColorShader::setContext(const SkBitmap& device, const SkPaint& paint, |
- const SkMatrix& matrix) { |
- if (!this->INHERITED::setContext(device, paint, matrix)) { |
+bool SkColorShader::onSetContext(Context* context, const SkBitmap& device, |
+ const SkPaint& paint, const SkMatrix& matrix) { |
+ if (!this->INHERITED::onSetContext(context, device, paint, matrix)) { |
return false; |
} |
@@ -281,15 +301,15 @@ bool SkColorShader::setContext(const SkBitmap& device, const SkPaint& paint, |
return true; |
} |
-void SkColorShader::shadeSpan(int x, int y, SkPMColor span[], int count) { |
+void SkColorShader::shadeSpan(Context* c, int x, int y, SkPMColor span[], int count) { |
sk_memset32(span, fPMColor, count); |
} |
-void SkColorShader::shadeSpan16(int x, int y, uint16_t span[], int count) { |
+void SkColorShader::shadeSpan16(Context* c, int x, int y, uint16_t span[], int count) { |
sk_memset16(span, fColor16, count); |
} |
-void SkColorShader::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) { |
+void SkColorShader::shadeSpanAlpha(Context* c, int x, int y, uint8_t alpha[], int count) { |
memset(alpha, SkGetPackedA32(fPMColor), count); |
} |
@@ -332,20 +352,20 @@ void SkColorShader::toString(SkString* str) const { |
#include "SkEmptyShader.h" |
uint32_t SkEmptyShader::getFlags() { return 0; } |
-uint8_t SkEmptyShader::getSpan16Alpha() const { return 0; } |
+uint8_t SkEmptyShader::getSpan16Alpha(Context* c) const { return 0; } |
-bool SkEmptyShader::setContext(const SkBitmap&, const SkPaint&, |
- const SkMatrix&) { return false; } |
+bool SkEmptyShader::onSetContext(Context*, const SkBitmap&, const SkPaint&, |
+ const SkMatrix&) { return false; } |
-void SkEmptyShader::shadeSpan(int x, int y, SkPMColor span[], int count) { |
+void SkEmptyShader::shadeSpan(Context *c, int x, int y, SkPMColor span[], int count) { |
SkDEBUGFAIL("should never get called, since setContext() returned false"); |
} |
-void SkEmptyShader::shadeSpan16(int x, int y, uint16_t span[], int count) { |
+void SkEmptyShader::shadeSpan16(Context *c, int x, int y, uint16_t span[], int count) { |
SkDEBUGFAIL("should never get called, since setContext() returned false"); |
} |
-void SkEmptyShader::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) { |
+void SkEmptyShader::shadeSpanAlpha(Context *c, int x, int y, uint8_t alpha[], int count) { |
SkDEBUGFAIL("should never get called, since setContext() returned false"); |
} |