Chromium Code Reviews| Index: src/core/SkBlitter_RGB16.cpp |
| diff --git a/src/core/SkBlitter_RGB16.cpp b/src/core/SkBlitter_RGB16.cpp |
| index b01800b51f52aec576a5fc61fa5dbb292d1f3ebb..6f14fb7d6775f291655a6bb25a71bcc390525b6b 100644 |
| --- a/src/core/SkBlitter_RGB16.cpp |
| +++ b/src/core/SkBlitter_RGB16.cpp |
| @@ -107,7 +107,8 @@ private: |
| class SkRGB16_Shader_Blitter : public SkShaderBlitter { |
| public: |
| - SkRGB16_Shader_Blitter(const SkBitmap& device, const SkPaint& paint); |
| + SkRGB16_Shader_Blitter(const SkBitmap& device, const SkPaint& paint, |
| + SkShader::Context* shaderContext); |
| virtual ~SkRGB16_Shader_Blitter(); |
| virtual void blitH(int x, int y, int width); |
| virtual void blitAntiH(int x, int y, const SkAlpha* antialias, |
| @@ -129,7 +130,8 @@ private: |
| // used only if the shader can perform shadSpan16 |
| class SkRGB16_Shader16_Blitter : public SkRGB16_Shader_Blitter { |
| public: |
| - SkRGB16_Shader16_Blitter(const SkBitmap& device, const SkPaint& paint); |
| + SkRGB16_Shader16_Blitter(const SkBitmap& device, const SkPaint& paint, |
| + SkShader::Context* shaderContext); |
| virtual void blitH(int x, int y, int width); |
| virtual void blitAntiH(int x, int y, const SkAlpha* antialias, |
| const int16_t* runs); |
| @@ -141,7 +143,8 @@ private: |
| class SkRGB16_Shader_Xfermode_Blitter : public SkShaderBlitter { |
| public: |
| - SkRGB16_Shader_Xfermode_Blitter(const SkBitmap& device, const SkPaint& paint); |
| + SkRGB16_Shader_Xfermode_Blitter(const SkBitmap& device, const SkPaint& paint, |
| + SkShader::Context* shaderContext); |
| virtual ~SkRGB16_Shader_Xfermode_Blitter(); |
| virtual void blitH(int x, int y, int width); |
| virtual void blitAntiH(int x, int y, const SkAlpha* antialias, |
| @@ -679,8 +682,9 @@ void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { |
| /////////////////////////////////////////////////////////////////////////////// |
| SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device, |
| - const SkPaint& paint) |
| - : SkRGB16_Shader_Blitter(device, paint) { |
| + const SkPaint& paint, |
| + SkShader::Context* shaderContext) |
| + : SkRGB16_Shader_Blitter(device, paint, shaderContext) { |
| SkASSERT(SkShader::CanCallShadeSpan16(fShaderFlags)); |
| } |
| @@ -688,28 +692,26 @@ void SkRGB16_Shader16_Blitter::blitH(int x, int y, int width) { |
| SkASSERT(x + width <= fDevice.width()); |
| uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
| - SkShader* shader = fShader; |
|
scroggo
2014/03/24 21:24:46
More instances of caching a value and not using th
Dominik Grewe
2014/03/26 17:22:22
I didn't realize we can't always rely on the compi
|
| - int alpha = shader->getSpan16Alpha(); |
| + int alpha = fShaderContext->getSpan16Alpha(); |
| if (0xFF == alpha) { |
| - shader->shadeSpan16(x, y, device, width); |
| + fShaderContext->shadeSpan16(x, y, device, width); |
| } else { |
| uint16_t* span16 = (uint16_t*)fBuffer; |
| - shader->shadeSpan16(x, y, span16, width); |
| + fShaderContext->shadeSpan16(x, y, span16, width); |
| SkBlendRGB16(span16, device, SkAlpha255To256(alpha), width); |
| } |
| } |
| void SkRGB16_Shader16_Blitter::blitRect(int x, int y, int width, int height) { |
| - SkShader* shader = fShader; |
| uint16_t* dst = fDevice.getAddr16(x, y); |
| size_t dstRB = fDevice.rowBytes(); |
| - int alpha = shader->getSpan16Alpha(); |
| + int alpha = fShaderContext->getSpan16Alpha(); |
| if (0xFF == alpha) { |
| if (fShaderFlags & SkShader::kConstInY16_Flag) { |
| // have the shader blit directly into the device the first time |
| - shader->shadeSpan16(x, y, dst, width); |
| + fShaderContext->shadeSpan16(x, y, dst, width); |
| // and now just memcpy that line on the subsequent lines |
| if (--height > 0) { |
| const uint16_t* orig = dst; |
| @@ -720,7 +722,7 @@ void SkRGB16_Shader16_Blitter::blitRect(int x, int y, int width, int height) { |
| } |
| } else { // need to call shadeSpan16 for every line |
| do { |
| - shader->shadeSpan16(x, y, dst, width); |
| + fShaderContext->shadeSpan16(x, y, dst, width); |
| y += 1; |
| dst = (uint16_t*)((char*)dst + dstRB); |
| } while (--height); |
| @@ -729,14 +731,14 @@ void SkRGB16_Shader16_Blitter::blitRect(int x, int y, int width, int height) { |
| int scale = SkAlpha255To256(alpha); |
| uint16_t* span16 = (uint16_t*)fBuffer; |
| if (fShaderFlags & SkShader::kConstInY16_Flag) { |
| - shader->shadeSpan16(x, y, span16, width); |
| + fShaderContext->shadeSpan16(x, y, span16, width); |
| do { |
| SkBlendRGB16(span16, dst, scale, width); |
| dst = (uint16_t*)((char*)dst + dstRB); |
| } while (--height); |
| } else { |
| do { |
| - shader->shadeSpan16(x, y, span16, width); |
| + fShaderContext->shadeSpan16(x, y, span16, width); |
| SkBlendRGB16(span16, dst, scale, width); |
| y += 1; |
| dst = (uint16_t*)((char*)dst + dstRB); |
| @@ -748,11 +750,10 @@ void SkRGB16_Shader16_Blitter::blitRect(int x, int y, int width, int height) { |
| void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y, |
| const SkAlpha* SK_RESTRICT antialias, |
| const int16_t* SK_RESTRICT runs) { |
| - SkShader* shader = fShader; |
| SkPMColor* SK_RESTRICT span = fBuffer; |
| uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
| - int alpha = shader->getSpan16Alpha(); |
| + int alpha = fShaderContext->getSpan16Alpha(); |
| uint16_t* span16 = (uint16_t*)span; |
| if (0xFF == alpha) { |
| @@ -766,9 +767,9 @@ void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y, |
| int aa = *antialias; |
| if (aa == 255) { |
| // go direct to the device! |
| - shader->shadeSpan16(x, y, device, count); |
| + fShaderContext->shadeSpan16(x, y, device, count); |
| } else if (aa) { |
| - shader->shadeSpan16(x, y, span16, count); |
| + fShaderContext->shadeSpan16(x, y, span16, count); |
| SkBlendRGB16(span16, device, SkAlpha255To256(aa), count); |
| } |
| device += count; |
| @@ -787,7 +788,7 @@ void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y, |
| int aa = SkAlphaMul(*antialias, alpha); |
| if (aa) { |
| - shader->shadeSpan16(x, y, span16, count); |
| + fShaderContext->shadeSpan16(x, y, span16, count); |
| SkBlendRGB16(span16, device, SkAlpha255To256(aa), count); |
| } |
| @@ -802,8 +803,9 @@ void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y, |
| /////////////////////////////////////////////////////////////////////////////// |
| SkRGB16_Shader_Blitter::SkRGB16_Shader_Blitter(const SkBitmap& device, |
| - const SkPaint& paint) |
| -: INHERITED(device, paint) { |
| + const SkPaint& paint, |
| + SkShader::Context* shaderContext) |
| +: INHERITED(device, paint, shaderContext) { |
| SkASSERT(paint.getXfermode() == NULL); |
| fBuffer = (SkPMColor*)sk_malloc_throw(device.width() * sizeof(SkPMColor)); |
| @@ -834,20 +836,19 @@ SkRGB16_Shader_Blitter::~SkRGB16_Shader_Blitter() { |
| void SkRGB16_Shader_Blitter::blitH(int x, int y, int width) { |
| SkASSERT(x + width <= fDevice.width()); |
| - fShader->shadeSpan(x, y, fBuffer, width); |
| + fShaderContext->shadeSpan(x, y, fBuffer, width); |
| // shaders take care of global alpha, so we pass 0xFF (should be ignored) |
| fOpaqueProc(fDevice.getAddr16(x, y), fBuffer, width, 0xFF, x, y); |
| } |
| void SkRGB16_Shader_Blitter::blitRect(int x, int y, int width, int height) { |
| - SkShader* shader = fShader; |
| SkBlitRow::Proc proc = fOpaqueProc; |
| SkPMColor* buffer = fBuffer; |
| uint16_t* dst = fDevice.getAddr16(x, y); |
| size_t dstRB = fDevice.rowBytes(); |
| if (fShaderFlags & SkShader::kConstInY32_Flag) { |
| - shader->shadeSpan(x, y, buffer, width); |
| + fShaderContext->shadeSpan(x, y, buffer, width); |
| do { |
| proc(dst, buffer, width, 0xFF, x, y); |
| y += 1; |
| @@ -855,7 +856,7 @@ void SkRGB16_Shader_Blitter::blitRect(int x, int y, int width, int height) { |
| } while (--height); |
| } else { |
| do { |
| - shader->shadeSpan(x, y, buffer, width); |
| + fShaderContext->shadeSpan(x, y, buffer, width); |
| proc(dst, buffer, width, 0xFF, x, y); |
| y += 1; |
| dst = (uint16_t*)((char*)dst + dstRB); |
| @@ -880,7 +881,6 @@ static inline int count_nonzero_span(const int16_t runs[], const SkAlpha aa[]) { |
| void SkRGB16_Shader_Blitter::blitAntiH(int x, int y, |
| const SkAlpha* SK_RESTRICT antialias, |
| const int16_t* SK_RESTRICT runs) { |
| - SkShader* shader = fShader; |
| SkPMColor* SK_RESTRICT span = fBuffer; |
| uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); |
| @@ -901,7 +901,7 @@ void SkRGB16_Shader_Blitter::blitAntiH(int x, int y, |
| int nonZeroCount = count + count_nonzero_span(runs + count, antialias + count); |
| SkASSERT(nonZeroCount <= fDevice.width()); // don't overrun fBuffer |
| - shader->shadeSpan(x, y, span, nonZeroCount); |
| + fShaderContext->shadeSpan(x, y, span, nonZeroCount); |
| SkPMColor* localSpan = span; |
| for (;;) { |
| @@ -928,8 +928,9 @@ void SkRGB16_Shader_Blitter::blitAntiH(int x, int y, |
| /////////////////////////////////////////////////////////////////////// |
| SkRGB16_Shader_Xfermode_Blitter::SkRGB16_Shader_Xfermode_Blitter( |
| - const SkBitmap& device, const SkPaint& paint) |
| -: INHERITED(device, paint) { |
| + const SkBitmap& device, const SkPaint& paint, |
| + SkShader::Context* shaderContext) |
| +: INHERITED(device, paint, shaderContext) { |
| fXfermode = paint.getXfermode(); |
| SkASSERT(fXfermode); |
| fXfermode->ref(); |
| @@ -950,14 +951,13 @@ void SkRGB16_Shader_Xfermode_Blitter::blitH(int x, int y, int width) { |
| uint16_t* device = fDevice.getAddr16(x, y); |
| SkPMColor* span = fBuffer; |
| - fShader->shadeSpan(x, y, span, width); |
| + fShaderContext->shadeSpan(x, y, span, width); |
| fXfermode->xfer16(device, span, width, NULL); |
| } |
| void SkRGB16_Shader_Xfermode_Blitter::blitAntiH(int x, int y, |
| const SkAlpha* SK_RESTRICT antialias, |
| const int16_t* SK_RESTRICT runs) { |
| - SkShader* shader = fShader; |
| SkXfermode* mode = fXfermode; |
| SkPMColor* SK_RESTRICT span = fBuffer; |
| uint8_t* SK_RESTRICT aaExpand = fAAExpand; |
| @@ -981,7 +981,7 @@ void SkRGB16_Shader_Xfermode_Blitter::blitAntiH(int x, int y, |
| antialias + count); |
| SkASSERT(nonZeroCount <= fDevice.width()); // don't overrun fBuffer |
| - shader->shadeSpan(x, y, span, nonZeroCount); |
| + fShaderContext->shadeSpan(x, y, span, nonZeroCount); |
| x += nonZeroCount; |
| SkPMColor* localSpan = span; |
| @@ -1012,6 +1012,7 @@ void SkRGB16_Shader_Xfermode_Blitter::blitAntiH(int x, int y, |
| /////////////////////////////////////////////////////////////////////////////// |
| SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint, |
| + SkShader::Context* shaderContext, |
| SkTBlitterAllocator* allocator) { |
| SkASSERT(allocator != NULL); |
| @@ -1023,12 +1024,14 @@ SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint, |
| SkASSERT(NULL == mode || NULL != shader); |
| if (shader) { |
| + SkASSERT(shaderContext != NULL); |
| if (mode) { |
| - blitter = allocator->createT<SkRGB16_Shader_Xfermode_Blitter>(device, paint); |
| - } else if (shader->canCallShadeSpan16()) { |
| - blitter = allocator->createT<SkRGB16_Shader16_Blitter>(device, paint); |
| + blitter = allocator->createT<SkRGB16_Shader_Xfermode_Blitter>(device, paint, |
| + shaderContext); |
| + } else if (shaderContext->canCallShadeSpan16()) { |
| + blitter = allocator->createT<SkRGB16_Shader16_Blitter>(device, paint, shaderContext); |
| } else { |
| - blitter = allocator->createT<SkRGB16_Shader_Blitter>(device, paint); |
| + blitter = allocator->createT<SkRGB16_Shader_Blitter>(device, paint, shaderContext); |
| } |
| } else { |
| // no shader, no xfermode, (and we always ignore colorfilter) |