Revert of change SkDraw and all Blitters to use pixmap instead of bitmap (patchset #6 id:100001 of https://codereview.chromium.org/1148793007/)

Reason for revert:
speculative revert to try to unblock DEPS roll

Original issue's description:
> change SkDraw and all Blitters to use pixmap instead of bitmap
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/c31af44336f5eb4a50e83e76e51962d46c3ed458

TBR=scroggo@google.com,jvanverth@google.com,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review URL: https://codereview.chromium.org/1164373003
This commit is contained in:
reed 2015-06-08 19:58:07 -07:00 committed by Commit bot
parent 86ae0a9e46
commit b3f0ec9f99
29 changed files with 374 additions and 305 deletions

View File

@ -19,7 +19,7 @@ class DrawPathBench : public Benchmark {
SkString fName; SkString fName;
SkPath fPath; SkPath fPath;
SkRasterClip fRC; SkRasterClip fRC;
SkAutoPixmapStorage fPixmap; SkBitmap fBitmap;
SkMatrix fIdentity; SkMatrix fIdentity;
SkDraw fDraw; SkDraw fDraw;
bool fDrawCoverage; bool fDrawCoverage;
@ -32,12 +32,12 @@ public:
fPath.quadTo(500, 0, 500, 500); fPath.quadTo(500, 0, 500, 500);
fPath.quadTo(250, 0, 0, 500); fPath.quadTo(250, 0, 0, 500);
fPixmap.alloc(SkImageInfo::MakeA8(500, 500)); fBitmap.allocPixels(SkImageInfo::MakeA8(500, 500));
fIdentity.setIdentity(); fIdentity.setIdentity();
fRC.setRect(fPath.getBounds().round()); fRC.setRect(fPath.getBounds().round());
fDraw.fDst = fPixmap; fDraw.fBitmap = &fBitmap;
fDraw.fMatrix = &fIdentity; fDraw.fMatrix = &fIdentity;
fDraw.fClip = &fRC.bwRgn(); fDraw.fClip = &fRC.bwRgn();
fDraw.fRC = &fRC; fDraw.fRC = &fRC;

View File

@ -31,17 +31,22 @@ static void draw_pixel_centers(SkCanvas* canvas) {
} }
} }
static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& path) { static void draw_fatpath(SkCanvas* canvas, SkSurface* surface,
const SkPath paths[], int count) {
SkPaint paint; SkPaint paint;
surface->getCanvas()->clear(SK_ColorTRANSPARENT); surface->getCanvas()->clear(SK_ColorTRANSPARENT);
surface->getCanvas()->drawPath(path, paint); for (int i = 0; i < count; ++i) {
surface->getCanvas()->drawPath(paths[i], paint);
}
surface->draw(canvas, 0, 0, NULL); surface->draw(canvas, 0, 0, NULL);
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setColor(SK_ColorRED); paint.setColor(SK_ColorRED);
paint.setStyle(SkPaint::kStroke_Style); paint.setStyle(SkPaint::kStroke_Style);
canvas->drawPath(path, paint); for (int j = 0; j < count; ++j) {
canvas->drawPath(paths[j], paint);
}
draw_pixel_centers(canvas); draw_pixel_centers(canvas);
} }
@ -52,15 +57,15 @@ public:
protected: protected:
SkString onShortName() override { virtual SkString onShortName() {
return SkString("fatpathfill"); return SkString("fatpathfill");
} }
SkISize onISize() override { virtual SkISize onISize() {
return SkISize::Make(SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP); return SkISize::Make(SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP);
} }
void onDraw(SkCanvas* canvas) override { virtual void onDraw(SkCanvas* canvas) {
SkAutoTUnref<SkSurface> surface(new_surface(SMALL_W, SMALL_H)); SkAutoTUnref<SkSurface> surface(new_surface(SMALL_W, SMALL_H));
canvas->scale(ZOOM, ZOOM); canvas->scale(ZOOM, ZOOM);
@ -71,10 +76,10 @@ protected:
for (int i = 0; i < REPEAT_LOOP; ++i) { for (int i = 0; i < REPEAT_LOOP; ++i) {
SkPath line, path; SkPath line, path;
line.moveTo(1, 2); line.moveTo(SkIntToScalar(1), SkIntToScalar(2));
line.lineTo(SkIntToScalar(4 + i), 1); line.lineTo(SkIntToScalar(4 + i), SkIntToScalar(1));
paint.getFillPath(line, &path); paint.getFillPath(line, &path);
draw_fatpath(canvas, surface, path); draw_fatpath(canvas, surface, &path, 1);
canvas->translate(0, SMALL_H); canvas->translate(0, SMALL_H);
} }

View File

@ -140,8 +140,7 @@ private:
computeConservativeLocalClipBounds(SkRect* bounds) const; computeConservativeLocalClipBounds(SkRect* bounds) const;
public: public:
// const SkBitmap* fBitmap; // required const SkBitmap* fBitmap; // required
SkPixmap fDst;
const SkMatrix* fMatrix; // required const SkMatrix* fMatrix; // required
const SkRegion* fClip; // DEPRECATED const SkRegion* fClip; // DEPRECATED
const SkRasterClip* fRC; // required const SkRasterClip* fRC; // required

View File

@ -1297,7 +1297,7 @@ public:
void blitMask(const SkMask&, const SkIRect& clip) override void blitMask(const SkMask&, const SkIRect& clip) override
{ unexpected(); } { unexpected(); }
const SkPixmap* justAnOpaqueColor(uint32_t*) override { const SkBitmap* justAnOpaqueColor(uint32_t*) override {
return NULL; return NULL;
} }
@ -2219,6 +2219,6 @@ void SkAAClipBlitter::blitMask(const SkMask& origMask, const SkIRect& clip) {
} while (y < stopY); } while (y < stopY);
} }
const SkPixmap* SkAAClipBlitter::justAnOpaqueColor(uint32_t* value) { const SkBitmap* SkAAClipBlitter::justAnOpaqueColor(uint32_t* value) {
return NULL; return NULL;
} }

View File

@ -110,11 +110,12 @@ public:
} }
void blitH(int x, int y, int width) override; void blitH(int x, int y, int width) override;
void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]) override; virtual void blitAntiH(int x, int y, const SkAlpha[],
const int16_t runs[]) override;
void blitV(int x, int y, int height, SkAlpha alpha) override; void blitV(int x, int y, int height, SkAlpha alpha) override;
void blitRect(int x, int y, int width, int height) override; void blitRect(int x, int y, int width, int height) override;
void blitMask(const SkMask&, const SkIRect& clip) override; void blitMask(const SkMask&, const SkIRect& clip) override;
const SkPixmap* justAnOpaqueColor(uint32_t* value) override; const SkBitmap* justAnOpaqueColor(uint32_t* value) override;
private: private:
SkBlitter* fBlitter; SkBlitter* fBlitter;

View File

@ -19,19 +19,19 @@
SK_BLITBWMASK_NAME name of function(const SkBitmap& bitmap, const SkMask& mask, const SkIRect& clip, SK_BLITBWMASK_ARGS) SK_BLITBWMASK_NAME name of function(const SkBitmap& bitmap, const SkMask& mask, const SkIRect& clip, SK_BLITBWMASK_ARGS)
SK_BLITBWMASK_ARGS list of additional arguments to SK_BLITBWMASK_NAME, beginning with a comma SK_BLITBWMASK_ARGS list of additional arguments to SK_BLITBWMASK_NAME, beginning with a comma
SK_BLITBWMASK_BLIT8 name of function(U8CPU byteMask, SK_BLITBWMASK_DEVTYPE* dst, int x, int y) SK_BLITBWMASK_BLIT8 name of function(U8CPU byteMask, SK_BLITBWMASK_DEVTYPE* dst, int x, int y)
SK_BLITBWMASK_GETADDR either writable_addr[8,16,32] SK_BLITBWMASK_GETADDR either getAddr32 or getAddr16 or getAddr8
SK_BLITBWMASK_DEVTYPE either U32 or U16 or U8 SK_BLITBWMASK_DEVTYPE either U32 or U16 or U8
*/ */
static void SK_BLITBWMASK_NAME(const SkPixmap& dst, const SkMask& srcMask, static void SK_BLITBWMASK_NAME(const SkBitmap& bitmap, const SkMask& srcMask, const SkIRect& clip SK_BLITBWMASK_ARGS)
const SkIRect& clip SK_BLITBWMASK_ARGS) { {
SkASSERT(clip.fRight <= srcMask.fBounds.fRight); SkASSERT(clip.fRight <= srcMask.fBounds.fRight);
int cx = clip.fLeft; int cx = clip.fLeft;
int cy = clip.fTop; int cy = clip.fTop;
int maskLeft = srcMask.fBounds.fLeft; int maskLeft = srcMask.fBounds.fLeft;
unsigned mask_rowBytes = srcMask.fRowBytes; unsigned mask_rowBytes = srcMask.fRowBytes;
size_t bitmap_rowBytes = dst.rowBytes(); size_t bitmap_rowBytes = bitmap.rowBytes();
unsigned height = clip.height(); unsigned height = clip.height();
SkASSERT(mask_rowBytes != 0); SkASSERT(mask_rowBytes != 0);
@ -39,7 +39,7 @@ static void SK_BLITBWMASK_NAME(const SkPixmap& dst, const SkMask& srcMask,
SkASSERT(height != 0); SkASSERT(height != 0);
const uint8_t* bits = srcMask.getAddr1(cx, cy); const uint8_t* bits = srcMask.getAddr1(cx, cy);
SK_BLITBWMASK_DEVTYPE* device = dst.SK_BLITBWMASK_GETADDR(cx, cy); SK_BLITBWMASK_DEVTYPE* device = bitmap.SK_BLITBWMASK_GETADDR(cx, cy);
if (cx == maskLeft && clip.fRight == srcMask.fBounds.fRight) if (cx == maskLeft && clip.fRight == srcMask.fBounds.fRight)
{ {

View File

@ -8,9 +8,9 @@
#ifndef SkBlitMask_DEFINED #ifndef SkBlitMask_DEFINED
#define SkBlitMask_DEFINED #define SkBlitMask_DEFINED
#include "SkBitmap.h"
#include "SkColor.h" #include "SkColor.h"
#include "SkMask.h" #include "SkMask.h"
#include "SkPixmap.h"
class SkBlitMask { class SkBlitMask {
public: public:
@ -18,7 +18,7 @@ public:
* Returns true if the device config and mask format were supported. * Returns true if the device config and mask format were supported.
* else return false (nothing was drawn) * else return false (nothing was drawn)
*/ */
static bool BlitColor(const SkPixmap& device, const SkMask& mask, static bool BlitColor(const SkBitmap& device, const SkMask& mask,
const SkIRect& clip, SkColor color); const SkIRect& clip, SkColor color);
/** /**

View File

@ -147,13 +147,13 @@ SkBlitMask::ColorProc SkBlitMask::ColorFactory(SkColorType ct,
return NULL; return NULL;
} }
bool SkBlitMask::BlitColor(const SkPixmap& device, const SkMask& mask, bool SkBlitMask::BlitColor(const SkBitmap& device, const SkMask& mask,
const SkIRect& clip, SkColor color) { const SkIRect& clip, SkColor color) {
ColorProc proc = ColorFactory(device.colorType(), mask.fFormat, color); ColorProc proc = ColorFactory(device.colorType(), mask.fFormat, color);
if (proc) { if (proc) {
int x = clip.fLeft; int x = clip.fLeft;
int y = clip.fTop; int y = clip.fTop;
proc(device.writable_addr32(x, y), device.rowBytes(), mask.getAddr(x, y), proc(device.getAddr32(x, y), device.rowBytes(), mask.getAddr(x, y),
mask.fRowBytes, color, clip.width(), clip.height()); mask.fRowBytes, color, clip.width(), clip.height());
return true; return true;
} }

View File

@ -33,7 +33,7 @@ SkShader::Context* SkBlitter::getShaderContext() const {
return NULL; return NULL;
} }
const SkPixmap* SkBlitter::justAnOpaqueColor(uint32_t* value) { const SkBitmap* SkBlitter::justAnOpaqueColor(uint32_t* value) {
return NULL; return NULL;
} }
@ -243,7 +243,7 @@ void SkNullBlitter::blitRect(int x, int y, int width, int height) {}
void SkNullBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {} void SkNullBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {}
const SkPixmap* SkNullBlitter::justAnOpaqueColor(uint32_t* value) { const SkBitmap* SkNullBlitter::justAnOpaqueColor(uint32_t* value) {
return NULL; return NULL;
} }
@ -404,7 +404,7 @@ void SkRectClipBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
} }
} }
const SkPixmap* SkRectClipBlitter::justAnOpaqueColor(uint32_t* value) { const SkBitmap* SkRectClipBlitter::justAnOpaqueColor(uint32_t* value) {
return fBlitter->justAnOpaqueColor(value); return fBlitter->justAnOpaqueColor(value);
} }
@ -540,7 +540,7 @@ void SkRgnClipBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
} }
} }
const SkPixmap* SkRgnClipBlitter::justAnOpaqueColor(uint32_t* value) { const SkBitmap* SkRgnClipBlitter::justAnOpaqueColor(uint32_t* value) {
return fBlitter->justAnOpaqueColor(value); return fBlitter->justAnOpaqueColor(value);
} }
@ -778,7 +778,7 @@ private:
#include "SkCoreBlitters.h" #include "SkCoreBlitters.h"
SkBlitter* SkBlitter::Choose(const SkPixmap& device, SkBlitter* SkBlitter::Choose(const SkBitmap& device,
const SkMatrix& matrix, const SkMatrix& matrix,
const SkPaint& origPaint, const SkPaint& origPaint,
SkTBlitterAllocator* allocator, SkTBlitterAllocator* allocator,
@ -944,7 +944,7 @@ private:
typedef SkShader::Context INHERITED; typedef SkShader::Context INHERITED;
}; };
SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext) SkShader::Context* shaderContext)
: INHERITED(device) : INHERITED(device)
, fShader(paint.getShader()) , fShader(paint.getShader())

View File

@ -8,11 +8,11 @@
#ifndef SkBlitter_DEFINED #ifndef SkBlitter_DEFINED
#define SkBlitter_DEFINED #define SkBlitter_DEFINED
#include "SkBitmap.h"
#include "SkBitmapProcShader.h" #include "SkBitmapProcShader.h"
#include "SkMask.h" #include "SkMask.h"
#include "SkMatrix.h" #include "SkMatrix.h"
#include "SkPaint.h" #include "SkPaint.h"
#include "SkPixmap.h"
#include "SkRefCnt.h" #include "SkRefCnt.h"
#include "SkRegion.h" #include "SkRegion.h"
#include "SkShader.h" #include "SkShader.h"
@ -51,7 +51,7 @@ public:
bitmap it draws into, and assign value. If not, return NULL and ignore bitmap it draws into, and assign value. If not, return NULL and ignore
the value parameter. the value parameter.
*/ */
virtual const SkPixmap* justAnOpaqueColor(uint32_t* value); virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
// (x, y), (x + 1, y) // (x, y), (x + 1, y)
virtual void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) { virtual void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
@ -122,7 +122,7 @@ public:
/** @name Factories /** @name Factories
Return the correct blitter to use given the specified context. Return the correct blitter to use given the specified context.
*/ */
static SkBlitter* Choose(const SkPixmap& dst, static SkBlitter* Choose(const SkBitmap& device,
const SkMatrix& matrix, const SkMatrix& matrix,
const SkPaint& paint, const SkPaint& paint,
SkTBlitterAllocator*, SkTBlitterAllocator*,
@ -152,7 +152,7 @@ public:
void blitV(int x, int y, int height, SkAlpha alpha) override; void blitV(int x, int y, int height, SkAlpha alpha) override;
void blitRect(int x, int y, int width, int height) override; void blitRect(int x, int y, int width, int height) override;
void blitMask(const SkMask&, const SkIRect& clip) override; void blitMask(const SkMask&, const SkIRect& clip) override;
const SkPixmap* justAnOpaqueColor(uint32_t* value) override; const SkBitmap* justAnOpaqueColor(uint32_t* value) override;
bool isNullBlitter() const override; bool isNullBlitter() const override;
}; };
@ -176,7 +176,7 @@ public:
virtual void blitAntiRect(int x, int y, int width, int height, virtual void blitAntiRect(int x, int y, int width, int height,
SkAlpha leftAlpha, SkAlpha rightAlpha) override; SkAlpha leftAlpha, SkAlpha rightAlpha) override;
void blitMask(const SkMask&, const SkIRect& clip) override; void blitMask(const SkMask&, const SkIRect& clip) override;
const SkPixmap* justAnOpaqueColor(uint32_t* value) override; const SkBitmap* justAnOpaqueColor(uint32_t* value) override;
int requestRowsPreserved() const override { int requestRowsPreserved() const override {
return fBlitter->requestRowsPreserved(); return fBlitter->requestRowsPreserved();
@ -211,7 +211,7 @@ public:
virtual void blitAntiRect(int x, int y, int width, int height, virtual void blitAntiRect(int x, int y, int width, int height,
SkAlpha leftAlpha, SkAlpha rightAlpha) override; SkAlpha leftAlpha, SkAlpha rightAlpha) override;
void blitMask(const SkMask&, const SkIRect& clip) override; void blitMask(const SkMask&, const SkIRect& clip) override;
const SkPixmap* justAnOpaqueColor(uint32_t* value) override; const SkBitmap* justAnOpaqueColor(uint32_t* value) override;
int requestRowsPreserved() const override { int requestRowsPreserved() const override {
return fBlitter->requestRowsPreserved(); return fBlitter->requestRowsPreserved();

View File

@ -12,11 +12,12 @@
#include "SkShader.h" #include "SkShader.h"
#include "SkXfermode.h" #include "SkXfermode.h"
SkA8_Blitter::SkA8_Blitter(const SkPixmap& device, const SkPaint& paint) : INHERITED(device) { SkA8_Blitter::SkA8_Blitter(const SkBitmap& device, const SkPaint& paint)
: INHERITED(device) {
fSrcA = paint.getAlpha(); fSrcA = paint.getAlpha();
} }
const SkPixmap* SkA8_Blitter::justAnOpaqueColor(uint32_t* value) { const SkBitmap* SkA8_Blitter::justAnOpaqueColor(uint32_t* value) {
if (255 == fSrcA) { if (255 == fSrcA) {
*value = 255; *value = 255;
return &fDevice; return &fDevice;
@ -32,7 +33,7 @@ void SkA8_Blitter::blitH(int x, int y, int width) {
return; return;
} }
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
if (fSrcA == 255) { if (fSrcA == 255) {
memset(device, 0xFF, width); memset(device, 0xFF, width);
@ -52,7 +53,7 @@ void SkA8_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
return; return;
} }
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
unsigned srcA = fSrcA; unsigned srcA = fSrcA;
for (;;) { for (;;) {
@ -96,7 +97,7 @@ void SkA8_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
#define SK_BLITBWMASK_NAME SkA8_BlitBW #define SK_BLITBWMASK_NAME SkA8_BlitBW
#define SK_BLITBWMASK_ARGS #define SK_BLITBWMASK_ARGS
#define SK_BLITBWMASK_BLIT8(mask, dst) solid_8_pixels(mask, dst) #define SK_BLITBWMASK_BLIT8(mask, dst) solid_8_pixels(mask, dst)
#define SK_BLITBWMASK_GETADDR writable_addr8 #define SK_BLITBWMASK_GETADDR getAddr8
#define SK_BLITBWMASK_DEVTYPE uint8_t #define SK_BLITBWMASK_DEVTYPE uint8_t
#include "SkBlitBWMaskTemplate.h" #include "SkBlitBWMaskTemplate.h"
@ -115,7 +116,7 @@ static inline void blend_8_pixels(U8CPU bw, uint8_t dst[], U8CPU sa,
#define SK_BLITBWMASK_NAME SkA8_BlendBW #define SK_BLITBWMASK_NAME SkA8_BlendBW
#define SK_BLITBWMASK_ARGS , U8CPU sa, unsigned dst_scale #define SK_BLITBWMASK_ARGS , U8CPU sa, unsigned dst_scale
#define SK_BLITBWMASK_BLIT8(mask, dst) blend_8_pixels(mask, dst, sa, dst_scale) #define SK_BLITBWMASK_BLIT8(mask, dst) blend_8_pixels(mask, dst, sa, dst_scale)
#define SK_BLITBWMASK_GETADDR writable_addr8 #define SK_BLITBWMASK_GETADDR getAddr8
#define SK_BLITBWMASK_DEVTYPE uint8_t #define SK_BLITBWMASK_DEVTYPE uint8_t
#include "SkBlitBWMaskTemplate.h" #include "SkBlitBWMaskTemplate.h"
@ -138,7 +139,7 @@ void SkA8_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) {
int y = clip.fTop; int y = clip.fTop;
int width = clip.width(); int width = clip.width();
int height = clip.height(); int height = clip.height();
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
const uint8_t* alpha = mask.getAddr8(x, y); const uint8_t* alpha = mask.getAddr8(x, y);
unsigned srcA = fSrcA; unsigned srcA = fSrcA;
@ -178,7 +179,7 @@ void SkA8_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
} }
unsigned sa = SkAlphaMul(fSrcA, SkAlpha255To256(alpha)); unsigned sa = SkAlphaMul(fSrcA, SkAlpha255To256(alpha));
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
size_t rowBytes = fDevice.rowBytes(); size_t rowBytes = fDevice.rowBytes();
if (sa == 0xFF) { if (sa == 0xFF) {
@ -205,7 +206,7 @@ void SkA8_Blitter::blitRect(int x, int y, int width, int height) {
return; return;
} }
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
unsigned srcA = fSrcA; unsigned srcA = fSrcA;
if (srcA == 255) { if (srcA == 255) {
@ -227,10 +228,9 @@ void SkA8_Blitter::blitRect(int x, int y, int width, int height) {
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
SkA8_Shader_Blitter::SkA8_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, SkA8_Shader_Blitter::SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext) SkShader::Context* shaderContext)
: INHERITED(device, paint, shaderContext) : INHERITED(device, paint, shaderContext) {
{
if ((fXfermode = paint.getXfermode()) != NULL) { if ((fXfermode = paint.getXfermode()) != NULL) {
fXfermode->ref(); fXfermode->ref();
SkASSERT(fShaderContext); SkASSERT(fShaderContext);
@ -250,7 +250,7 @@ void SkA8_Shader_Blitter::blitH(int x, int y, int width) {
SkASSERT(x >= 0 && y >= 0 && SkASSERT(x >= 0 && y >= 0 &&
(unsigned)(x + width) <= (unsigned)fDevice.width()); (unsigned)(x + width) <= (unsigned)fDevice.width());
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
if ((shaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode) { if ((shaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode) {
@ -288,7 +288,7 @@ void SkA8_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
SkXfermode* mode = fXfermode; SkXfermode* mode = fXfermode;
uint8_t* aaExpand = fAAExpand; uint8_t* aaExpand = fAAExpand;
SkPMColor* span = fBuffer; SkPMColor* span = fBuffer;
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
int opaque = shaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag; int opaque = shaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag;
for (;;) { for (;;) {
@ -329,7 +329,7 @@ void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) {
int y = clip.fTop; int y = clip.fTop;
int width = clip.width(); int width = clip.width();
int height = clip.height(); int height = clip.height();
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
const uint8_t* alpha = mask.getAddr8(x, y); const uint8_t* alpha = mask.getAddr8(x, y);
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
@ -353,7 +353,7 @@ void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkA8_Coverage_Blitter::SkA8_Coverage_Blitter(const SkPixmap& device, SkA8_Coverage_Blitter::SkA8_Coverage_Blitter(const SkBitmap& device,
const SkPaint& paint) : SkRasterBlitter(device) { const SkPaint& paint) : SkRasterBlitter(device) {
SkASSERT(NULL == paint.getShader()); SkASSERT(NULL == paint.getShader());
SkASSERT(NULL == paint.getXfermode()); SkASSERT(NULL == paint.getXfermode());
@ -362,7 +362,7 @@ SkA8_Coverage_Blitter::SkA8_Coverage_Blitter(const SkPixmap& device,
void SkA8_Coverage_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], void SkA8_Coverage_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
const int16_t runs[]) { const int16_t runs[]) {
uint8_t* device = fDevice.writable_addr8(x, y); uint8_t* device = fDevice.getAddr8(x, y);
SkDEBUGCODE(int totalCount = 0;) SkDEBUGCODE(int totalCount = 0;)
for (;;) { for (;;) {
@ -384,7 +384,7 @@ void SkA8_Coverage_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
} }
void SkA8_Coverage_Blitter::blitH(int x, int y, int width) { void SkA8_Coverage_Blitter::blitH(int x, int y, int width) {
memset(fDevice.writable_addr8(x, y), 0xFF, width); memset(fDevice.getAddr8(x, y), 0xFF, width);
} }
void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
@ -392,7 +392,7 @@ void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
return; return;
} }
uint8_t* dst = fDevice.writable_addr8(x, y); uint8_t* dst = fDevice.getAddr8(x, y);
const size_t dstRB = fDevice.rowBytes(); const size_t dstRB = fDevice.rowBytes();
while (--height >= 0) { while (--height >= 0) {
*dst = alpha; *dst = alpha;
@ -401,7 +401,7 @@ void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
} }
void SkA8_Coverage_Blitter::blitRect(int x, int y, int width, int height) { void SkA8_Coverage_Blitter::blitRect(int x, int y, int width, int height) {
uint8_t* dst = fDevice.writable_addr8(x, y); uint8_t* dst = fDevice.getAddr8(x, y);
const size_t dstRB = fDevice.rowBytes(); const size_t dstRB = fDevice.rowBytes();
while (--height >= 0) { while (--height >= 0) {
memset(dst, 0xFF, width); memset(dst, 0xFF, width);
@ -417,7 +417,7 @@ void SkA8_Coverage_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) {
int width = clip.width(); int width = clip.width();
int height = clip.height(); int height = clip.height();
uint8_t* dst = fDevice.writable_addr8(x, y); uint8_t* dst = fDevice.getAddr8(x, y);
const uint8_t* src = mask.getAddr8(x, y); const uint8_t* src = mask.getAddr8(x, y);
const size_t srcRB = mask.fRowBytes; const size_t srcRB = mask.fRowBytes;
const size_t dstRB = fDevice.rowBytes(); const size_t dstRB = fDevice.rowBytes();
@ -429,6 +429,6 @@ void SkA8_Coverage_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) {
} }
} }
const SkPixmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) { const SkBitmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) {
return NULL; return NULL;
} }

View File

@ -14,7 +14,7 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static void SkARGB32_Blit32(const SkPixmap& device, const SkMask& mask, static void SkARGB32_Blit32(const SkBitmap& device, const SkMask& mask,
const SkIRect& clip, SkPMColor srcColor) { const SkIRect& clip, SkPMColor srcColor) {
U8CPU alpha = SkGetPackedA32(srcColor); U8CPU alpha = SkGetPackedA32(srcColor);
unsigned flags = SkBlitRow::kSrcPixelAlpha_Flag32; unsigned flags = SkBlitRow::kSrcPixelAlpha_Flag32;
@ -28,7 +28,7 @@ static void SkARGB32_Blit32(const SkPixmap& device, const SkMask& mask,
int width = clip.width(); int width = clip.width();
int height = clip.height(); int height = clip.height();
SkPMColor* dstRow = device.writable_addr32(x, y); SkPMColor* dstRow = device.getAddr32(x, y);
const SkPMColor* srcRow = reinterpret_cast<const SkPMColor*>(mask.getAddr8(x, y)); const SkPMColor* srcRow = reinterpret_cast<const SkPMColor*>(mask.getAddr8(x, y));
do { do {
@ -40,7 +40,7 @@ static void SkARGB32_Blit32(const SkPixmap& device, const SkMask& mask,
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
SkARGB32_Blitter::SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint) SkARGB32_Blitter::SkARGB32_Blitter(const SkBitmap& device, const SkPaint& paint)
: INHERITED(device) { : INHERITED(device) {
SkColor color = paint.getColor(); SkColor color = paint.getColor();
fColor = color; fColor = color;
@ -54,7 +54,7 @@ SkARGB32_Blitter::SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint)
fPMColor = SkPackARGB32(fSrcA, fSrcR, fSrcG, fSrcB); fPMColor = SkPackARGB32(fSrcA, fSrcR, fSrcG, fSrcB);
} }
const SkPixmap* SkARGB32_Blitter::justAnOpaqueColor(uint32_t* value) { const SkBitmap* SkARGB32_Blitter::justAnOpaqueColor(uint32_t* value) {
if (255 == fSrcA) { if (255 == fSrcA) {
*value = fPMColor; *value = fPMColor;
return &fDevice; return &fDevice;
@ -70,7 +70,7 @@ const SkPixmap* SkARGB32_Blitter::justAnOpaqueColor(uint32_t* value) {
void SkARGB32_Blitter::blitH(int x, int y, int width) { void SkARGB32_Blitter::blitH(int x, int y, int width) {
SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width()); SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width());
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkBlitRow::Color32(device, device, width, fPMColor); SkBlitRow::Color32(device, device, width, fPMColor);
} }
@ -81,7 +81,7 @@ void SkARGB32_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
} }
uint32_t color = fPMColor; uint32_t color = fPMColor;
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
unsigned opaqueMask = fSrcA; // if fSrcA is 0xFF, then we will catch the fast opaque case unsigned opaqueMask = fSrcA; // if fSrcA is 0xFF, then we will catch the fast opaque case
for (;;) { for (;;) {
@ -106,16 +106,16 @@ void SkARGB32_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
} }
void SkARGB32_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) { void SkARGB32_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.writable_addr32(x + 1, y);) SkDEBUGCODE((void)fDevice.getAddr32(x + 1, y);)
device[0] = SkBlendARGB32(fPMColor, device[0], a0); device[0] = SkBlendARGB32(fPMColor, device[0], a0);
device[1] = SkBlendARGB32(fPMColor, device[1], a1); device[1] = SkBlendARGB32(fPMColor, device[1], a1);
} }
void SkARGB32_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) { void SkARGB32_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.writable_addr32(x, y + 1);) SkDEBUGCODE((void)fDevice.getAddr32(x, y + 1);)
device[0] = SkBlendARGB32(fPMColor, device[0], a0); device[0] = SkBlendARGB32(fPMColor, device[0], a0);
device = (uint32_t*)((char*)device + fDevice.rowBytes()); device = (uint32_t*)((char*)device + fDevice.rowBytes());
@ -139,7 +139,7 @@ void SkARGB32_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
#define SK_BLITBWMASK_NAME SkARGB32_BlitBW #define SK_BLITBWMASK_NAME SkARGB32_BlitBW
#define SK_BLITBWMASK_ARGS , SkPMColor color #define SK_BLITBWMASK_ARGS , SkPMColor color
#define SK_BLITBWMASK_BLIT8(mask, dst) solid_8_pixels(mask, dst, color) #define SK_BLITBWMASK_BLIT8(mask, dst) solid_8_pixels(mask, dst, color)
#define SK_BLITBWMASK_GETADDR writable_addr32 #define SK_BLITBWMASK_GETADDR getAddr32
#define SK_BLITBWMASK_DEVTYPE uint32_t #define SK_BLITBWMASK_DEVTYPE uint32_t
#include "SkBlitBWMaskTemplate.h" #include "SkBlitBWMaskTemplate.h"
@ -158,7 +158,7 @@ void SkARGB32_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
#define SK_BLITBWMASK_NAME SkARGB32_BlendBW #define SK_BLITBWMASK_NAME SkARGB32_BlendBW
#define SK_BLITBWMASK_ARGS , uint32_t sc, unsigned dst_scale #define SK_BLITBWMASK_ARGS , uint32_t sc, unsigned dst_scale
#define SK_BLITBWMASK_BLIT8(mask, dst) blend_8_pixels(mask, dst, sc, dst_scale) #define SK_BLITBWMASK_BLIT8(mask, dst) blend_8_pixels(mask, dst, sc, dst_scale)
#define SK_BLITBWMASK_GETADDR writable_addr32 #define SK_BLITBWMASK_GETADDR getAddr32
#define SK_BLITBWMASK_DEVTYPE uint32_t #define SK_BLITBWMASK_DEVTYPE uint32_t
#include "SkBlitBWMaskTemplate.h" #include "SkBlitBWMaskTemplate.h"
@ -197,16 +197,16 @@ void SkARGB32_Opaque_Blitter::blitMask(const SkMask& mask,
} }
void SkARGB32_Opaque_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) { void SkARGB32_Opaque_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.writable_addr32(x + 1, y);) SkDEBUGCODE((void)fDevice.getAddr32(x + 1, y);)
device[0] = SkFastFourByteInterp(fPMColor, device[0], a0); device[0] = SkFastFourByteInterp(fPMColor, device[0], a0);
device[1] = SkFastFourByteInterp(fPMColor, device[1], a1); device[1] = SkFastFourByteInterp(fPMColor, device[1], a1);
} }
void SkARGB32_Opaque_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) { void SkARGB32_Opaque_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.writable_addr32(x, y + 1);) SkDEBUGCODE((void)fDevice.getAddr32(x, y + 1);)
device[0] = SkFastFourByteInterp(fPMColor, device[0], a0); device[0] = SkFastFourByteInterp(fPMColor, device[0], a0);
device = (uint32_t*)((char*)device + fDevice.rowBytes()); device = (uint32_t*)((char*)device + fDevice.rowBytes());
@ -220,7 +220,7 @@ void SkARGB32_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
return; return;
} }
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
uint32_t color = fPMColor; uint32_t color = fPMColor;
if (alpha != 255) { if (alpha != 255) {
@ -242,7 +242,7 @@ void SkARGB32_Blitter::blitRect(int x, int y, int width, int height) {
return; return;
} }
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
uint32_t color = fPMColor; uint32_t color = fPMColor;
size_t rowBytes = fDevice.rowBytes(); size_t rowBytes = fDevice.rowBytes();
@ -260,7 +260,7 @@ void SkARGB32_Blitter::blitRect(int x, int y, int width, int height) {
void SkARGB32_Black_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], void SkARGB32_Black_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
const int16_t runs[]) { const int16_t runs[]) {
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkPMColor black = (SkPMColor)(SK_A32_MASK << SK_A32_SHIFT); SkPMColor black = (SkPMColor)(SK_A32_MASK << SK_A32_SHIFT);
for (;;) { for (;;) {
@ -290,16 +290,16 @@ void SkARGB32_Black_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
} }
void SkARGB32_Black_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) { void SkARGB32_Black_Blitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.writable_addr32(x + 1, y);) SkDEBUGCODE((void)fDevice.getAddr32(x + 1, y);)
device[0] = (a0 << SK_A32_SHIFT) + SkAlphaMulQ(device[0], 256 - a0); device[0] = (a0 << SK_A32_SHIFT) + SkAlphaMulQ(device[0], 256 - a0);
device[1] = (a1 << SK_A32_SHIFT) + SkAlphaMulQ(device[1], 256 - a1); device[1] = (a1 << SK_A32_SHIFT) + SkAlphaMulQ(device[1], 256 - a1);
} }
void SkARGB32_Black_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) { void SkARGB32_Black_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkDEBUGCODE((void)fDevice.writable_addr32(x, y + 1);) SkDEBUGCODE((void)fDevice.getAddr32(x, y + 1);)
device[0] = (a0 << SK_A32_SHIFT) + SkAlphaMulQ(device[0], 256 - a0); device[0] = (a0 << SK_A32_SHIFT) + SkAlphaMulQ(device[0], 256 - a0);
device = (uint32_t*)((char*)device + fDevice.rowBytes()); device = (uint32_t*)((char*)device + fDevice.rowBytes());
@ -319,7 +319,7 @@ static void blend_srcmode(SkPMColor* SK_RESTRICT device,
} }
} }
SkARGB32_Shader_Blitter::SkARGB32_Shader_Blitter(const SkPixmap& device, SkARGB32_Shader_Blitter::SkARGB32_Shader_Blitter(const SkBitmap& device,
const SkPaint& paint, SkShader::Context* shaderContext) const SkPaint& paint, SkShader::Context* shaderContext)
: INHERITED(device, paint, shaderContext) : INHERITED(device, paint, shaderContext)
{ {
@ -363,7 +363,7 @@ SkARGB32_Shader_Blitter::~SkARGB32_Shader_Blitter() {
void SkARGB32_Shader_Blitter::blitH(int x, int y, int width) { void SkARGB32_Shader_Blitter::blitH(int x, int y, int width) {
SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width()); SkASSERT(x >= 0 && y >= 0 && x + width <= fDevice.width());
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
if (fShadeDirectlyIntoDevice) { if (fShadeDirectlyIntoDevice) {
fShaderContext->shadeSpan(x, y, device, width); fShaderContext->shadeSpan(x, y, device, width);
@ -382,7 +382,7 @@ void SkARGB32_Shader_Blitter::blitRect(int x, int y, int width, int height) {
SkASSERT(x >= 0 && y >= 0 && SkASSERT(x >= 0 && y >= 0 &&
x + width <= fDevice.width() && y + height <= fDevice.height()); x + width <= fDevice.width() && y + height <= fDevice.height());
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
size_t deviceRB = fDevice.rowBytes(); size_t deviceRB = fDevice.rowBytes();
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
SkPMColor* span = fBuffer; SkPMColor* span = fBuffer;
@ -457,7 +457,7 @@ void SkARGB32_Shader_Blitter::blitRect(int x, int y, int width, int height) {
void SkARGB32_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], void SkARGB32_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[],
const int16_t runs[]) { const int16_t runs[]) {
SkPMColor* span = fBuffer; SkPMColor* span = fBuffer;
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
if (fXfermode && !fShadeDirectlyIntoDevice) { if (fXfermode && !fShadeDirectlyIntoDevice) {
@ -558,7 +558,7 @@ void SkARGB32_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip)
int y = clip.fTop; int y = clip.fTop;
int height = clip.height(); int height = clip.height();
char* dstRow = (char*)fDevice.writable_addr32(x, y); char* dstRow = (char*)fDevice.getAddr32(x, y);
const size_t dstRB = fDevice.rowBytes(); const size_t dstRB = fDevice.rowBytes();
const uint8_t* maskRow = (const uint8_t*)mask.getAddr(x, y); const uint8_t* maskRow = (const uint8_t*)mask.getAddr(x, y);
const size_t maskRB = mask.fRowBytes; const size_t maskRB = mask.fRowBytes;
@ -589,7 +589,7 @@ void SkARGB32_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip)
void SkARGB32_Shader_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { void SkARGB32_Shader_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
SkASSERT(x >= 0 && y >= 0 && y + height <= fDevice.height()); SkASSERT(x >= 0 && y >= 0 && y + height <= fDevice.height());
uint32_t* device = fDevice.writable_addr32(x, y); uint32_t* device = fDevice.getAddr32(x, y);
size_t deviceRB = fDevice.rowBytes(); size_t deviceRB = fDevice.rowBytes();
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;

View File

@ -1,3 +1,4 @@
/* /*
* Copyright 2006 The Android Open Source Project * Copyright 2006 The Android Open Source Project
* *
@ -5,6 +6,7 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "SkBlitRow.h" #include "SkBlitRow.h"
#include "SkCoreBlitters.h" #include "SkCoreBlitters.h"
#include "SkColorPriv.h" #include "SkColorPriv.h"
@ -56,14 +58,15 @@ void sk_dither_memset16(uint16_t dst[], uint16_t value, uint16_t other,
class SkRGB16_Blitter : public SkRasterBlitter { class SkRGB16_Blitter : public SkRasterBlitter {
public: public:
SkRGB16_Blitter(const SkPixmap& device, const SkPaint& paint); SkRGB16_Blitter(const SkBitmap& device, const SkPaint& paint);
void blitH(int x, int y, int width) override; void blitH(int x, int y, int width) override;
virtual void blitAntiH(int x, int y, const SkAlpha* antialias, virtual void blitAntiH(int x, int y, const SkAlpha* antialias,
const int16_t* runs) override; const int16_t* runs) override;
void blitV(int x, int y, int height, SkAlpha alpha) override; void blitV(int x, int y, int height, SkAlpha alpha) override;
void blitRect(int x, int y, int width, int height) override; void blitRect(int x, int y, int width, int height) override;
void blitMask(const SkMask&, const SkIRect&) override; virtual void blitMask(const SkMask&,
const SkPixmap* justAnOpaqueColor(uint32_t*) override; const SkIRect&) override;
const SkBitmap* justAnOpaqueColor(uint32_t*) override;
protected: protected:
SkPMColor fSrcColor32; SkPMColor fSrcColor32;
@ -84,12 +87,14 @@ protected:
class SkRGB16_Opaque_Blitter : public SkRGB16_Blitter { class SkRGB16_Opaque_Blitter : public SkRGB16_Blitter {
public: public:
SkRGB16_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint); SkRGB16_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint);
void blitH(int x, int y, int width) override; void blitH(int x, int y, int width) override;
void blitAntiH(int x, int y, const SkAlpha* antialias, const int16_t* runs) override; virtual void blitAntiH(int x, int y, const SkAlpha* antialias,
const int16_t* runs) override;
void blitV(int x, int y, int height, SkAlpha alpha) override; void blitV(int x, int y, int height, SkAlpha alpha) override;
void blitRect(int x, int y, int width, int height) override; void blitRect(int x, int y, int width, int height) override;
void blitMask(const SkMask&, const SkIRect&) override; virtual void blitMask(const SkMask&,
const SkIRect&) override;
private: private:
typedef SkRGB16_Blitter INHERITED; typedef SkRGB16_Blitter INHERITED;
@ -98,9 +103,10 @@ private:
#ifdef USE_BLACK_BLITTER #ifdef USE_BLACK_BLITTER
class SkRGB16_Black_Blitter : public SkRGB16_Opaque_Blitter { class SkRGB16_Black_Blitter : public SkRGB16_Opaque_Blitter {
public: public:
SkRGB16_Black_Blitter(const SkPixmap& device, const SkPaint& paint); SkRGB16_Black_Blitter(const SkBitmap& device, const SkPaint& paint);
void blitMask(const SkMask&, const SkIRect&) override; void blitMask(const SkMask&, const SkIRect&) override;
void blitAntiH(int x, int y, const SkAlpha* antialias, const int16_t* runs) override; virtual void blitAntiH(int x, int y, const SkAlpha* antialias,
const int16_t* runs) override;
private: private:
typedef SkRGB16_Opaque_Blitter INHERITED; typedef SkRGB16_Opaque_Blitter INHERITED;
@ -109,7 +115,7 @@ private:
class SkRGB16_Shader_Blitter : public SkShaderBlitter { class SkRGB16_Shader_Blitter : public SkShaderBlitter {
public: public:
SkRGB16_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, SkRGB16_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext); SkShader::Context* shaderContext);
virtual ~SkRGB16_Shader_Blitter(); virtual ~SkRGB16_Shader_Blitter();
void blitH(int x, int y, int width) override; void blitH(int x, int y, int width) override;
@ -132,7 +138,7 @@ private:
// used only if the shader can perform shadSpan16 // used only if the shader can perform shadSpan16
class SkRGB16_Shader16_Blitter : public SkRGB16_Shader_Blitter { class SkRGB16_Shader16_Blitter : public SkRGB16_Shader_Blitter {
public: public:
SkRGB16_Shader16_Blitter(const SkPixmap& device, const SkPaint& paint, SkRGB16_Shader16_Blitter(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext); SkShader::Context* shaderContext);
void blitH(int x, int y, int width) override; void blitH(int x, int y, int width) override;
virtual void blitAntiH(int x, int y, const SkAlpha* antialias, virtual void blitAntiH(int x, int y, const SkAlpha* antialias,
@ -145,7 +151,7 @@ private:
class SkRGB16_Shader_Xfermode_Blitter : public SkShaderBlitter { class SkRGB16_Shader_Xfermode_Blitter : public SkShaderBlitter {
public: public:
SkRGB16_Shader_Xfermode_Blitter(const SkPixmap& device, const SkPaint& paint, SkRGB16_Shader_Xfermode_Blitter(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext); SkShader::Context* shaderContext);
virtual ~SkRGB16_Shader_Xfermode_Blitter(); virtual ~SkRGB16_Shader_Xfermode_Blitter();
void blitH(int x, int y, int width) override; void blitH(int x, int y, int width) override;
@ -165,7 +171,7 @@ private:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#ifdef USE_BLACK_BLITTER #ifdef USE_BLACK_BLITTER
SkRGB16_Black_Blitter::SkRGB16_Black_Blitter(const SkPixmap& device, const SkPaint& paint) SkRGB16_Black_Blitter::SkRGB16_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
: INHERITED(device, paint) { : INHERITED(device, paint) {
SkASSERT(paint.getShader() == NULL); SkASSERT(paint.getShader() == NULL);
SkASSERT(paint.getColorFilter() == NULL); SkASSERT(paint.getColorFilter() == NULL);
@ -202,7 +208,7 @@ static inline black_8_pixels(U8CPU mask, uint16_t dst[])
#define SK_BLITBWMASK_NAME SkRGB16_Black_BlitBW #define SK_BLITBWMASK_NAME SkRGB16_Black_BlitBW
#define SK_BLITBWMASK_ARGS #define SK_BLITBWMASK_ARGS
#define SK_BLITBWMASK_BLIT8(mask, dst) black_8_pixels(mask, dst) #define SK_BLITBWMASK_BLIT8(mask, dst) black_8_pixels(mask, dst)
#define SK_BLITBWMASK_GETADDR writable_addr16 #define SK_BLITBWMASK_GETADDR getAddr16
#define SK_BLITBWMASK_DEVTYPE uint16_t #define SK_BLITBWMASK_DEVTYPE uint16_t
#include "SkBlitBWMaskTemplate.h" #include "SkBlitBWMaskTemplate.h"
@ -211,7 +217,7 @@ void SkRGB16_Black_Blitter::blitMask(const SkMask& mask,
if (mask.fFormat == SkMask::kBW_Format) { if (mask.fFormat == SkMask::kBW_Format) {
SkRGB16_Black_BlitBW(fDevice, mask, clip); SkRGB16_Black_BlitBW(fDevice, mask, clip);
} else { } else {
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(clip.fLeft, clip.fTop); uint16_t* SK_RESTRICT device = fDevice.getAddr16(clip.fLeft, clip.fTop);
const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop); const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop);
unsigned width = clip.width(); unsigned width = clip.width();
unsigned height = clip.height(); unsigned height = clip.height();
@ -239,7 +245,7 @@ void SkRGB16_Black_Blitter::blitMask(const SkMask& mask,
void SkRGB16_Black_Blitter::blitAntiH(int x, int y, void SkRGB16_Black_Blitter::blitAntiH(int x, int y,
const SkAlpha* SK_RESTRICT antialias, const SkAlpha* SK_RESTRICT antialias,
const int16_t* SK_RESTRICT runs) { const int16_t* SK_RESTRICT runs) {
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
for (;;) { for (;;) {
int count = runs[0]; int count = runs[0];
@ -271,13 +277,14 @@ void SkRGB16_Black_Blitter::blitAntiH(int x, int y,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkRGB16_Opaque_Blitter::SkRGB16_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint) SkRGB16_Opaque_Blitter::SkRGB16_Opaque_Blitter(const SkBitmap& device,
: INHERITED(device, paint) {} const SkPaint& paint)
: INHERITED(device, paint) {}
void SkRGB16_Opaque_Blitter::blitH(int x, int y, int width) { void SkRGB16_Opaque_Blitter::blitH(int x, int y, int width) {
SkASSERT(width > 0); SkASSERT(width > 0);
SkASSERT(x + width <= fDevice.width()); SkASSERT(x + width <= fDevice.width());
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
uint16_t srcColor = fColor16; uint16_t srcColor = fColor16;
SkASSERT(fRawColor16 == srcColor); SkASSERT(fRawColor16 == srcColor);
@ -300,7 +307,7 @@ static inline int Bool2Int(int value) {
void SkRGB16_Opaque_Blitter::blitAntiH(int x, int y, void SkRGB16_Opaque_Blitter::blitAntiH(int x, int y,
const SkAlpha* SK_RESTRICT antialias, const SkAlpha* SK_RESTRICT antialias,
const int16_t* SK_RESTRICT runs) { const int16_t* SK_RESTRICT runs) {
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
uint16_t srcColor = fRawColor16; uint16_t srcColor = fRawColor16;
uint32_t srcExpanded = fExpandedRaw16; uint32_t srcExpanded = fExpandedRaw16;
int ditherInt = Bool2Int(fDoDither); int ditherInt = Bool2Int(fDoDither);
@ -365,7 +372,7 @@ void SkRGB16_Opaque_Blitter::blitAntiH(int x, int y,
#define SK_BLITBWMASK_NAME SkRGB16_BlitBW #define SK_BLITBWMASK_NAME SkRGB16_BlitBW
#define SK_BLITBWMASK_ARGS , uint16_t color #define SK_BLITBWMASK_ARGS , uint16_t color
#define SK_BLITBWMASK_BLIT8(mask, dst) solid_8_pixels(mask, dst, color) #define SK_BLITBWMASK_BLIT8(mask, dst) solid_8_pixels(mask, dst, color)
#define SK_BLITBWMASK_GETADDR writable_addr16 #define SK_BLITBWMASK_GETADDR getAddr16
#define SK_BLITBWMASK_DEVTYPE uint16_t #define SK_BLITBWMASK_DEVTYPE uint16_t
#include "SkBlitBWMaskTemplate.h" #include "SkBlitBWMaskTemplate.h"
@ -382,7 +389,7 @@ void SkRGB16_Opaque_Blitter::blitMask(const SkMask& mask,
return; return;
} }
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(clip.fLeft, clip.fTop); uint16_t* SK_RESTRICT device = fDevice.getAddr16(clip.fLeft, clip.fTop);
const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop); const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop);
int width = clip.width(); int width = clip.width();
int height = clip.height(); int height = clip.height();
@ -477,7 +484,7 @@ void SkRGB16_Opaque_Blitter::blitMask(const SkMask& mask,
} }
void SkRGB16_Opaque_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { void SkRGB16_Opaque_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
size_t deviceRB = fDevice.rowBytes(); size_t deviceRB = fDevice.rowBytes();
// TODO: respect fDoDither // TODO: respect fDoDither
@ -493,7 +500,7 @@ void SkRGB16_Opaque_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
void SkRGB16_Opaque_Blitter::blitRect(int x, int y, int width, int height) { void SkRGB16_Opaque_Blitter::blitRect(int x, int y, int width, int height) {
SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height());
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
size_t deviceRB = fDevice.rowBytes(); size_t deviceRB = fDevice.rowBytes();
uint16_t color16 = fColor16; uint16_t color16 = fColor16;
@ -517,7 +524,7 @@ void SkRGB16_Opaque_Blitter::blitRect(int x, int y, int width, int height) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkRGB16_Blitter::SkRGB16_Blitter(const SkPixmap& device, const SkPaint& paint) SkRGB16_Blitter::SkRGB16_Blitter(const SkBitmap& device, const SkPaint& paint)
: INHERITED(device) { : INHERITED(device) {
SkColor color = paint.getColor(); SkColor color = paint.getColor();
@ -554,7 +561,7 @@ SkRGB16_Blitter::SkRGB16_Blitter(const SkPixmap& device, const SkPaint& paint)
fColorProc16 = SkBlitRow::ColorFactory16(flags); fColorProc16 = SkBlitRow::ColorFactory16(flags);
} }
const SkPixmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) {
if (!fDoDither && 256 == fScale) { if (!fDoDither && 256 == fScale) {
*value = fRawColor16; *value = fRawColor16;
return &fDevice; return &fDevice;
@ -565,7 +572,7 @@ const SkPixmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) {
void SkRGB16_Blitter::blitH(int x, int y, int width) { void SkRGB16_Blitter::blitH(int x, int y, int width) {
SkASSERT(width > 0); SkASSERT(width > 0);
SkASSERT(x + width <= fDevice.width()); SkASSERT(x + width <= fDevice.width());
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
fColorProc16(device, fSrcColor32, width, x, y); fColorProc16(device, fSrcColor32, width, x, y);
} }
@ -573,7 +580,7 @@ void SkRGB16_Blitter::blitH(int x, int y, int width) {
void SkRGB16_Blitter::blitAntiH(int x, int y, void SkRGB16_Blitter::blitAntiH(int x, int y,
const SkAlpha* SK_RESTRICT antialias, const SkAlpha* SK_RESTRICT antialias,
const int16_t* SK_RESTRICT runs) { const int16_t* SK_RESTRICT runs) {
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
uint32_t srcExpanded = fExpandedRaw16; uint32_t srcExpanded = fExpandedRaw16;
unsigned scale = fScale; unsigned scale = fScale;
@ -617,7 +624,7 @@ static inline void blend_8_pixels(U8CPU bw, uint16_t dst[], unsigned dst_scale,
#define SK_BLITBWMASK_NAME SkRGB16_BlendBW #define SK_BLITBWMASK_NAME SkRGB16_BlendBW
#define SK_BLITBWMASK_ARGS , unsigned dst_scale, U16CPU src_color #define SK_BLITBWMASK_ARGS , unsigned dst_scale, U16CPU src_color
#define SK_BLITBWMASK_BLIT8(mask, dst) blend_8_pixels(mask, dst, dst_scale, src_color) #define SK_BLITBWMASK_BLIT8(mask, dst) blend_8_pixels(mask, dst, dst_scale, src_color)
#define SK_BLITBWMASK_GETADDR writable_addr16 #define SK_BLITBWMASK_GETADDR getAddr16
#define SK_BLITBWMASK_DEVTYPE uint16_t #define SK_BLITBWMASK_DEVTYPE uint16_t
#include "SkBlitBWMaskTemplate.h" #include "SkBlitBWMaskTemplate.h"
@ -628,7 +635,7 @@ void SkRGB16_Blitter::blitMask(const SkMask& mask,
return; return;
} }
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(clip.fLeft, clip.fTop); uint16_t* SK_RESTRICT device = fDevice.getAddr16(clip.fLeft, clip.fTop);
const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop); const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop);
int width = clip.width(); int width = clip.width();
int height = clip.height(); int height = clip.height();
@ -652,7 +659,7 @@ void SkRGB16_Blitter::blitMask(const SkMask& mask,
} }
void SkRGB16_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { void SkRGB16_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
size_t deviceRB = fDevice.rowBytes(); size_t deviceRB = fDevice.rowBytes();
// TODO: respect fDoDither // TODO: respect fDoDither
@ -668,7 +675,7 @@ void SkRGB16_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) { void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) {
SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height()); SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height());
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
size_t deviceRB = fDevice.rowBytes(); size_t deviceRB = fDevice.rowBytes();
while (--height >= 0) { while (--height >= 0) {
@ -679,18 +686,17 @@ void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkPixmap& device, SkRGB16_Shader16_Blitter::SkRGB16_Shader16_Blitter(const SkBitmap& device,
const SkPaint& paint, const SkPaint& paint,
SkShader::Context* shaderContext) SkShader::Context* shaderContext)
: SkRGB16_Shader_Blitter(device, paint, shaderContext) : SkRGB16_Shader_Blitter(device, paint, shaderContext) {
{
SkASSERT(SkShader::CanCallShadeSpan16(fShaderFlags)); SkASSERT(SkShader::CanCallShadeSpan16(fShaderFlags));
} }
void SkRGB16_Shader16_Blitter::blitH(int x, int y, int width) { void SkRGB16_Shader16_Blitter::blitH(int x, int y, int width) {
SkASSERT(x + width <= fDevice.width()); SkASSERT(x + width <= fDevice.width());
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
int alpha = shaderContext->getSpan16Alpha(); int alpha = shaderContext->getSpan16Alpha();
@ -705,7 +711,7 @@ void SkRGB16_Shader16_Blitter::blitH(int x, int y, int width) {
void SkRGB16_Shader16_Blitter::blitRect(int x, int y, int width, int height) { void SkRGB16_Shader16_Blitter::blitRect(int x, int y, int width, int height) {
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
uint16_t* dst = fDevice.writable_addr16(x, y); uint16_t* dst = fDevice.getAddr16(x, y);
size_t dstRB = fDevice.rowBytes(); size_t dstRB = fDevice.rowBytes();
int alpha = shaderContext->getSpan16Alpha(); int alpha = shaderContext->getSpan16Alpha();
@ -753,7 +759,7 @@ void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y,
const int16_t* SK_RESTRICT runs) { const int16_t* SK_RESTRICT runs) {
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
SkPMColor* SK_RESTRICT span = fBuffer; SkPMColor* SK_RESTRICT span = fBuffer;
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
int alpha = shaderContext->getSpan16Alpha(); int alpha = shaderContext->getSpan16Alpha();
uint16_t* span16 = (uint16_t*)span; uint16_t* span16 = (uint16_t*)span;
@ -804,11 +810,10 @@ void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkRGB16_Shader_Blitter::SkRGB16_Shader_Blitter(const SkPixmap& device, SkRGB16_Shader_Blitter::SkRGB16_Shader_Blitter(const SkBitmap& device,
const SkPaint& paint, const SkPaint& paint,
SkShader::Context* shaderContext) SkShader::Context* shaderContext)
: INHERITED(device, paint, shaderContext) : INHERITED(device, paint, shaderContext) {
{
SkASSERT(paint.getXfermode() == NULL); SkASSERT(paint.getXfermode() == NULL);
fBuffer = (SkPMColor*)sk_malloc_throw(device.width() * sizeof(SkPMColor)); fBuffer = (SkPMColor*)sk_malloc_throw(device.width() * sizeof(SkPMColor));
@ -840,14 +845,14 @@ void SkRGB16_Shader_Blitter::blitH(int x, int y, int width) {
fShaderContext->shadeSpan(x, y, fBuffer, width); fShaderContext->shadeSpan(x, y, fBuffer, width);
// shaders take care of global alpha, so we pass 0xFF (should be ignored) // shaders take care of global alpha, so we pass 0xFF (should be ignored)
fOpaqueProc(fDevice.writable_addr16(x, y), fBuffer, width, 0xFF, x, y); fOpaqueProc(fDevice.getAddr16(x, y), fBuffer, width, 0xFF, x, y);
} }
void SkRGB16_Shader_Blitter::blitRect(int x, int y, int width, int height) { void SkRGB16_Shader_Blitter::blitRect(int x, int y, int width, int height) {
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
SkBlitRow::Proc16 proc = fOpaqueProc; SkBlitRow::Proc16 proc = fOpaqueProc;
SkPMColor* buffer = fBuffer; SkPMColor* buffer = fBuffer;
uint16_t* dst = fDevice.writable_addr16(x, y); uint16_t* dst = fDevice.getAddr16(x, y);
size_t dstRB = fDevice.rowBytes(); size_t dstRB = fDevice.rowBytes();
if (fShaderFlags & SkShader::kConstInY32_Flag) { if (fShaderFlags & SkShader::kConstInY32_Flag) {
@ -886,7 +891,7 @@ void SkRGB16_Shader_Blitter::blitAntiH(int x, int y,
const int16_t* SK_RESTRICT runs) { const int16_t* SK_RESTRICT runs) {
SkShader::Context* shaderContext = fShaderContext; SkShader::Context* shaderContext = fShaderContext;
SkPMColor* SK_RESTRICT span = fBuffer; SkPMColor* SK_RESTRICT span = fBuffer;
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
for (;;) { for (;;) {
int count = *runs; int count = *runs;
@ -932,10 +937,9 @@ void SkRGB16_Shader_Blitter::blitAntiH(int x, int y,
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
SkRGB16_Shader_Xfermode_Blitter::SkRGB16_Shader_Xfermode_Blitter( SkRGB16_Shader_Xfermode_Blitter::SkRGB16_Shader_Xfermode_Blitter(
const SkPixmap& device, const SkPaint& paint, const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext) SkShader::Context* shaderContext)
: INHERITED(device, paint, shaderContext) : INHERITED(device, paint, shaderContext) {
{
fXfermode = paint.getXfermode(); fXfermode = paint.getXfermode();
SkASSERT(fXfermode); SkASSERT(fXfermode);
fXfermode->ref(); fXfermode->ref();
@ -953,7 +957,7 @@ SkRGB16_Shader_Xfermode_Blitter::~SkRGB16_Shader_Xfermode_Blitter() {
void SkRGB16_Shader_Xfermode_Blitter::blitH(int x, int y, int width) { void SkRGB16_Shader_Xfermode_Blitter::blitH(int x, int y, int width) {
SkASSERT(x + width <= fDevice.width()); SkASSERT(x + width <= fDevice.width());
uint16_t* device = fDevice.writable_addr16(x, y); uint16_t* device = fDevice.getAddr16(x, y);
SkPMColor* span = fBuffer; SkPMColor* span = fBuffer;
fShaderContext->shadeSpan(x, y, span, width); fShaderContext->shadeSpan(x, y, span, width);
@ -967,7 +971,7 @@ void SkRGB16_Shader_Xfermode_Blitter::blitAntiH(int x, int y,
SkXfermode* mode = fXfermode; SkXfermode* mode = fXfermode;
SkPMColor* SK_RESTRICT span = fBuffer; SkPMColor* SK_RESTRICT span = fBuffer;
uint8_t* SK_RESTRICT aaExpand = fAAExpand; uint8_t* SK_RESTRICT aaExpand = fAAExpand;
uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
for (;;) { for (;;) {
int count = *runs; int count = *runs;
@ -1017,7 +1021,7 @@ void SkRGB16_Shader_Xfermode_Blitter::blitAntiH(int x, int y,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
SkBlitter* SkBlitter_ChooseD565(const SkPixmap& device, const SkPaint& paint, SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext, SkShader::Context* shaderContext,
SkTBlitterAllocator* allocator) { SkTBlitterAllocator* allocator) {
SkASSERT(allocator != NULL); SkASSERT(allocator != NULL);

View File

@ -271,9 +271,7 @@ public:
fClip = &((SkRasterClip*)&rec->fClip)->forceGetBW(); fClip = &((SkRasterClip*)&rec->fClip)->forceGetBW();
fRC = &rec->fClip; fRC = &rec->fClip;
fDevice = rec->fDevice; fDevice = rec->fDevice;
if (!fDevice->accessPixels(&fDst)) { fBitmap = &fDevice->accessBitmap(true);
fDst.reset(fDevice->imageInfo(), NULL, 0);
}
fPaint = rec->fPaint; fPaint = rec->fPaint;
SkDEBUGCODE(this->validate();) SkDEBUGCODE(this->validate();)

View File

@ -16,10 +16,10 @@
class SkRasterBlitter : public SkBlitter { class SkRasterBlitter : public SkBlitter {
public: public:
SkRasterBlitter(const SkPixmap& device) : fDevice(device) {} SkRasterBlitter(const SkBitmap& device) : fDevice(device) {}
protected: protected:
const SkPixmap fDevice; const SkBitmap& fDevice;
private: private:
typedef SkBlitter INHERITED; typedef SkBlitter INHERITED;
@ -32,7 +32,7 @@ public:
* The blitter only ensures that the storage always holds a live object, but it may * The blitter only ensures that the storage always holds a live object, but it may
* exchange that object. * exchange that object.
*/ */
SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, SkShaderBlitter(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext); SkShader::Context* shaderContext);
virtual ~SkShaderBlitter(); virtual ~SkShaderBlitter();
@ -61,24 +61,24 @@ private:
class SkA8_Coverage_Blitter : public SkRasterBlitter { class SkA8_Coverage_Blitter : public SkRasterBlitter {
public: public:
SkA8_Coverage_Blitter(const SkPixmap& device, const SkPaint& paint); SkA8_Coverage_Blitter(const SkBitmap& device, const SkPaint& paint);
void blitH(int x, int y, int width) override; void blitH(int x, int y, int width) override;
void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override; void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override;
void blitV(int x, int y, int height, SkAlpha alpha) override; void blitV(int x, int y, int height, SkAlpha alpha) override;
void blitRect(int x, int y, int width, int height) override; void blitRect(int x, int y, int width, int height) override;
void blitMask(const SkMask&, const SkIRect&) override; void blitMask(const SkMask&, const SkIRect&) override;
const SkPixmap* justAnOpaqueColor(uint32_t*) override; const SkBitmap* justAnOpaqueColor(uint32_t*) override;
}; };
class SkA8_Blitter : public SkRasterBlitter { class SkA8_Blitter : public SkRasterBlitter {
public: public:
SkA8_Blitter(const SkPixmap& device, const SkPaint& paint); SkA8_Blitter(const SkBitmap& device, const SkPaint& paint);
virtual void blitH(int x, int y, int width); virtual void blitH(int x, int y, int width);
virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]); virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
virtual void blitV(int x, int y, int height, SkAlpha alpha); virtual void blitV(int x, int y, int height, SkAlpha alpha);
virtual void blitRect(int x, int y, int width, int height); virtual void blitRect(int x, int y, int width, int height);
virtual void blitMask(const SkMask&, const SkIRect&); virtual void blitMask(const SkMask&, const SkIRect&);
virtual const SkPixmap* justAnOpaqueColor(uint32_t*); virtual const SkBitmap* justAnOpaqueColor(uint32_t*);
private: private:
unsigned fSrcA; unsigned fSrcA;
@ -91,7 +91,7 @@ private:
class SkA8_Shader_Blitter : public SkShaderBlitter { class SkA8_Shader_Blitter : public SkShaderBlitter {
public: public:
SkA8_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext); SkShader::Context* shaderContext);
virtual ~SkA8_Shader_Blitter(); virtual ~SkA8_Shader_Blitter();
virtual void blitH(int x, int y, int width); virtual void blitH(int x, int y, int width);
@ -113,13 +113,13 @@ private:
class SkARGB32_Blitter : public SkRasterBlitter { class SkARGB32_Blitter : public SkRasterBlitter {
public: public:
SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint); SkARGB32_Blitter(const SkBitmap& device, const SkPaint& paint);
virtual void blitH(int x, int y, int width); virtual void blitH(int x, int y, int width);
virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]); virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
virtual void blitV(int x, int y, int height, SkAlpha alpha); virtual void blitV(int x, int y, int height, SkAlpha alpha);
virtual void blitRect(int x, int y, int width, int height); virtual void blitRect(int x, int y, int width, int height);
virtual void blitMask(const SkMask&, const SkIRect&); virtual void blitMask(const SkMask&, const SkIRect&);
virtual const SkPixmap* justAnOpaqueColor(uint32_t*); virtual const SkBitmap* justAnOpaqueColor(uint32_t*);
void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override;
@ -138,7 +138,7 @@ private:
class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter { class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter {
public: public:
SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint) SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint)
: INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); } : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); }
virtual void blitMask(const SkMask&, const SkIRect&); virtual void blitMask(const SkMask&, const SkIRect&);
void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
@ -150,7 +150,7 @@ private:
class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter { class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter {
public: public:
SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint) SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
: INHERITED(device, paint) {} : INHERITED(device, paint) {}
virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]); virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]);
void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
@ -162,7 +162,7 @@ private:
class SkARGB32_Shader_Blitter : public SkShaderBlitter { class SkARGB32_Shader_Blitter : public SkShaderBlitter {
public: public:
SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext); SkShader::Context* shaderContext);
virtual ~SkARGB32_Shader_Blitter(); virtual ~SkARGB32_Shader_Blitter();
void blitH(int x, int y, int width) override; void blitH(int x, int y, int width) override;
@ -200,7 +200,7 @@ private:
SkBlitter::Choose(...) SkBlitter::Choose(...)
*/ */
SkBlitter* SkBlitter_ChooseD565(const SkPixmap& device, const SkPaint& paint, SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* shaderContext, SkShader::Context* shaderContext,
SkTBlitterAllocator* allocator); SkTBlitterAllocator* allocator);

View File

@ -7,16 +7,17 @@
#include "SkDeviceLooper.h" #include "SkDeviceLooper.h"
SkDeviceLooper::SkDeviceLooper(const SkPixmap& base, const SkRasterClip& rc, const SkIRect& bounds, SkDeviceLooper::SkDeviceLooper(const SkBitmap& base,
bool aa) const SkRasterClip& rc,
: fBaseDst(base) const SkIRect& bounds, bool aa)
: fBaseBitmap(base)
, fBaseRC(rc) , fBaseRC(rc)
, fSubsetRC(rc.isForceConservativeRects()) , fSubsetRC(rc.isForceConservativeRects())
, fDelta(aa ? kAA_Delta : kBW_Delta) , fDelta(aa ? kAA_Delta : kBW_Delta)
{ {
// sentinels that next() has not yet been called, and so our mapper functions // sentinels that next() has not yet been called, and so our mapper functions
// should not be called either. // should not be called either.
fCurrDst = NULL; fCurrBitmap = NULL;
fCurrRC = NULL; fCurrRC = NULL;
if (!rc.isEmpty()) { if (!rc.isEmpty()) {
@ -37,11 +38,12 @@ SkDeviceLooper::SkDeviceLooper(const SkPixmap& base, const SkRasterClip& rc, con
} }
} }
SkDeviceLooper::~SkDeviceLooper() {} SkDeviceLooper::~SkDeviceLooper() {
}
void SkDeviceLooper::mapRect(SkRect* dst, const SkRect& src) const { void SkDeviceLooper::mapRect(SkRect* dst, const SkRect& src) const {
SkASSERT(kDone_State != fState); SkASSERT(kDone_State != fState);
SkASSERT(fCurrDst); SkASSERT(fCurrBitmap);
SkASSERT(fCurrRC); SkASSERT(fCurrRC);
*dst = src; *dst = src;
@ -51,11 +53,12 @@ void SkDeviceLooper::mapRect(SkRect* dst, const SkRect& src) const {
void SkDeviceLooper::mapMatrix(SkMatrix* dst, const SkMatrix& src) const { void SkDeviceLooper::mapMatrix(SkMatrix* dst, const SkMatrix& src) const {
SkASSERT(kDone_State != fState); SkASSERT(kDone_State != fState);
SkASSERT(fCurrDst); SkASSERT(fCurrBitmap);
SkASSERT(fCurrRC); SkASSERT(fCurrRC);
*dst = src; *dst = src;
dst->postTranslate(SkIntToScalar(-fCurrOffset.fX), SkIntToScalar(-fCurrOffset.fY)); dst->postTranslate(SkIntToScalar(-fCurrOffset.fX),
SkIntToScalar(-fCurrOffset.fY));
} }
bool SkDeviceLooper::computeCurrBitmapAndClip() { bool SkDeviceLooper::computeCurrBitmapAndClip() {
@ -63,14 +66,16 @@ bool SkDeviceLooper::computeCurrBitmapAndClip() {
SkIRect r = SkIRect::MakeXYWH(fCurrOffset.x(), fCurrOffset.y(), SkIRect r = SkIRect::MakeXYWH(fCurrOffset.x(), fCurrOffset.y(),
fDelta, fDelta); fDelta, fDelta);
if (!fBaseDst.extractSubset(&fSubsetDst, r)) { if (!fBaseBitmap.extractSubset(&fSubsetBitmap, r)) {
fSubsetRC.setEmpty(); fSubsetRC.setEmpty();
} else { } else {
fSubsetBitmap.lockPixels();
fBaseRC.translate(-r.left(), -r.top(), &fSubsetRC); fBaseRC.translate(-r.left(), -r.top(), &fSubsetRC);
(void)fSubsetRC.op(SkIRect::MakeWH(fDelta, fDelta), SkRegion::kIntersect_Op); (void)fSubsetRC.op(SkIRect::MakeWH(fDelta, fDelta),
SkRegion::kIntersect_Op);
} }
fCurrDst = &fSubsetDst; fCurrBitmap = &fSubsetBitmap;
fCurrRC = &fSubsetRC; fCurrRC = &fSubsetRC;
return !fCurrRC->isEmpty(); return !fCurrRC->isEmpty();
} }
@ -102,8 +107,8 @@ bool SkDeviceLooper::next() {
case kSimple_State: case kSimple_State:
// first time for simple // first time for simple
if (NULL == fCurrDst) { if (NULL == fCurrBitmap) {
fCurrDst = &fBaseDst; fCurrBitmap = &fBaseBitmap;
fCurrRC = &fBaseRC; fCurrRC = &fBaseRC;
fCurrOffset.set(0, 0); fCurrOffset.set(0, 0);
return true; return true;

View File

@ -30,13 +30,14 @@
*/ */
class SkDeviceLooper { class SkDeviceLooper {
public: public:
SkDeviceLooper(const SkPixmap& base, const SkRasterClip&, const SkIRect& bounds, bool aa); SkDeviceLooper(const SkBitmap& base, const SkRasterClip&,
const SkIRect& bounds, bool aa);
~SkDeviceLooper(); ~SkDeviceLooper();
const SkPixmap& getPixmap() const { const SkBitmap& getBitmap() const {
SkASSERT(kDone_State != fState); SkASSERT(kDone_State != fState);
SkASSERT(fCurrDst); SkASSERT(fCurrBitmap);
return *fCurrDst; return *fCurrBitmap;
} }
const SkRasterClip& getRC() const { const SkRasterClip& getRC() const {
@ -60,7 +61,7 @@ public:
bool next(); bool next();
private: private:
const SkPixmap& fBaseDst; const SkBitmap& fBaseBitmap;
const SkRasterClip& fBaseRC; const SkRasterClip& fBaseRC;
enum State { enum State {
@ -70,10 +71,10 @@ private:
}; };
// storage for our tiled versions. Perhaps could use SkTLazy // storage for our tiled versions. Perhaps could use SkTLazy
SkPixmap fSubsetDst; SkBitmap fSubsetBitmap;
SkRasterClip fSubsetRC; SkRasterClip fSubsetRC;
const SkPixmap* fCurrDst; const SkBitmap* fCurrBitmap;
const SkRasterClip* fCurrRC; const SkRasterClip* fCurrRC;
SkIRect fClippedBounds; SkIRect fClippedBounds;
SkIPoint fCurrOffset; SkIPoint fCurrOffset;

View File

@ -44,18 +44,20 @@ public:
SkAutoBlitterChoose() { SkAutoBlitterChoose() {
fBlitter = NULL; fBlitter = NULL;
} }
SkAutoBlitterChoose(const SkPixmap& dst, const SkMatrix& matrix, SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix,
const SkPaint& paint, bool drawCoverage = false) { const SkPaint& paint, bool drawCoverage = false) {
fBlitter = SkBlitter::Choose(dst, matrix, paint, &fAllocator, drawCoverage); fBlitter = SkBlitter::Choose(device, matrix, paint, &fAllocator,
drawCoverage);
} }
SkBlitter* operator->() { return fBlitter; } SkBlitter* operator->() { return fBlitter; }
SkBlitter* get() const { return fBlitter; } SkBlitter* get() const { return fBlitter; }
void choose(const SkPixmap& dst, const SkMatrix& matrix, void choose(const SkBitmap& device, const SkMatrix& matrix,
const SkPaint& paint, bool drawCoverage = false) { const SkPaint& paint, bool drawCoverage = false) {
SkASSERT(!fBlitter); SkASSERT(!fBlitter);
fBlitter = SkBlitter::Choose(dst, matrix, paint, &fAllocator, drawCoverage); fBlitter = SkBlitter::Choose(device, matrix, paint, &fAllocator,
drawCoverage);
} }
private: private:
@ -150,7 +152,8 @@ static void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) {
memset(pixels, data, bytes); memset(pixels, data, bytes);
} }
static BitmapXferProc ChooseBitmapXferProc(const SkPixmap& dst, const SkPaint& paint, static BitmapXferProc ChooseBitmapXferProc(const SkBitmap& bitmap,
const SkPaint& paint,
uint32_t* data) { uint32_t* data) {
// todo: we can apply colorfilter up front if no shader, so we wouldn't // todo: we can apply colorfilter up front if no shader, so we wouldn't
// need to abort this fastpath // need to abort this fastpath
@ -187,7 +190,7 @@ static BitmapXferProc ChooseBitmapXferProc(const SkPixmap& dst, const SkPaint& p
should I worry about dithering for the lower depths? should I worry about dithering for the lower depths?
*/ */
SkPMColor pmc = SkPreMultiplyColor(color); SkPMColor pmc = SkPreMultiplyColor(color);
switch (dst.colorType()) { switch (bitmap.colorType()) {
case kN32_SkColorType: case kN32_SkColorType:
if (data) { if (data) {
*data = pmc; *data = pmc;
@ -217,10 +220,10 @@ static BitmapXferProc ChooseBitmapXferProc(const SkPixmap& dst, const SkPaint& p
return NULL; return NULL;
} }
static void CallBitmapXferProc(const SkPixmap& dst, const SkIRect& rect, BitmapXferProc proc, static void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect,
uint32_t procData) { BitmapXferProc proc, uint32_t procData) {
int shiftPerPixel; int shiftPerPixel;
switch (dst.colorType()) { switch (bitmap.colorType()) {
case kN32_SkColorType: case kN32_SkColorType:
shiftPerPixel = 2; shiftPerPixel = 2;
break; break;
@ -235,9 +238,9 @@ static void CallBitmapXferProc(const SkPixmap& dst, const SkIRect& rect, BitmapX
return; return;
} }
uint8_t* pixels = (uint8_t*)dst.writable_addr(); uint8_t* pixels = (uint8_t*)bitmap.getPixels();
SkASSERT(pixels); SkASSERT(pixels);
const size_t rowBytes = dst.rowBytes(); const size_t rowBytes = bitmap.rowBytes();
const int widthBytes = rect.width() << shiftPerPixel; const int widthBytes = rect.width() << shiftPerPixel;
// skip down to the first scanline and X position // skip down to the first scanline and X position
@ -256,7 +259,7 @@ void SkDraw::drawPaint(const SkPaint& paint) const {
} }
SkIRect devRect; SkIRect devRect;
devRect.set(0, 0, fDst.width(), fDst.height()); devRect.set(0, 0, fBitmap->width(), fBitmap->height());
if (fRC->isBW()) { if (fRC->isBW()) {
/* If we don't have a shader (i.e. we're just a solid color) we may /* If we don't have a shader (i.e. we're just a solid color) we may
@ -266,7 +269,7 @@ void SkDraw::drawPaint(const SkPaint& paint) const {
in the clip, we don't have to worry about antialiasing. in the clip, we don't have to worry about antialiasing.
*/ */
uint32_t procData = 0; // to avoid the warning uint32_t procData = 0; // to avoid the warning
BitmapXferProc proc = ChooseBitmapXferProc(fDst, paint, &procData); BitmapXferProc proc = ChooseBitmapXferProc(*fBitmap, paint, &procData);
if (proc) { if (proc) {
if (D_Dst_BitmapXferProc == proc) { // nothing to do if (D_Dst_BitmapXferProc == proc) { // nothing to do
return; return;
@ -274,7 +277,7 @@ void SkDraw::drawPaint(const SkPaint& paint) const {
SkRegion::Iterator iter(fRC->bwRgn()); SkRegion::Iterator iter(fRC->bwRgn());
while (!iter.done()) { while (!iter.done()) {
CallBitmapXferProc(fDst, iter.rect(), proc, procData); CallBitmapXferProc(*fBitmap, iter.rect(), proc, procData);
iter.next(); iter.next();
} }
return; return;
@ -282,7 +285,7 @@ void SkDraw::drawPaint(const SkPaint& paint) const {
} }
// normal case: use a blitter // normal case: use a blitter
SkAutoBlitterChoose blitter(fDst, *fMatrix, paint); SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint);
SkScan::FillIRect(devRect, *fRC, blitter.get()); SkScan::FillIRect(devRect, *fRC, blitter.get());
} }
@ -328,11 +331,11 @@ static void bw_pt_rect_16_hair_proc(const PtProcRec& rec,
SkASSERT(rec.fRC->isRect()); SkASSERT(rec.fRC->isRect());
const SkIRect& r = rec.fRC->getBounds(); const SkIRect& r = rec.fRC->getBounds();
uint32_t value; uint32_t value;
const SkPixmap* dst = blitter->justAnOpaqueColor(&value); const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value);
SkASSERT(dst); SkASSERT(bitmap);
uint16_t* addr = dst->writable_addr16(0, 0); uint16_t* addr = bitmap->getAddr16(0, 0);
size_t rb = dst->rowBytes(); size_t rb = bitmap->rowBytes();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
int x = SkScalarFloorToInt(devPts[i].fX); int x = SkScalarFloorToInt(devPts[i].fX);
@ -349,11 +352,11 @@ static void bw_pt_rect_32_hair_proc(const PtProcRec& rec,
SkASSERT(rec.fRC->isRect()); SkASSERT(rec.fRC->isRect());
const SkIRect& r = rec.fRC->getBounds(); const SkIRect& r = rec.fRC->getBounds();
uint32_t value; uint32_t value;
const SkPixmap* dst = blitter->justAnOpaqueColor(&value); const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value);
SkASSERT(dst); SkASSERT(bitmap);
SkPMColor* addr = dst->writable_addr32(0, 0); SkPMColor* addr = bitmap->getAddr32(0, 0);
size_t rb = dst->rowBytes(); size_t rb = bitmap->rowBytes();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
int x = SkScalarFloorToInt(devPts[i].fX); int x = SkScalarFloorToInt(devPts[i].fX);
@ -509,7 +512,7 @@ PtProcRec::Proc PtProcRec::chooseProc(SkBlitter** blitterPtr) {
if (fRadius <= SK_FixedHalf) { // small radii and hairline if (fRadius <= SK_FixedHalf) { // small radii and hairline
if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) { if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) {
uint32_t value; uint32_t value;
const SkPixmap* bm = blitter->justAnOpaqueColor(&value); const SkBitmap* bm = blitter->justAnOpaqueColor(&value);
if (bm && kRGB_565_SkColorType == bm->colorType()) { if (bm && kRGB_565_SkColorType == bm->colorType()) {
proc = bw_pt_rect_16_hair_proc; proc = bw_pt_rect_16_hair_proc;
} else if (bm && kN32_SkColorType == bm->colorType()) { } else if (bm && kN32_SkColorType == bm->colorType()) {
@ -556,7 +559,7 @@ void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count,
PtProcRec rec; PtProcRec rec;
if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) { if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) {
SkAutoBlitterChoose blitter(fDst, *fMatrix, paint); SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint);
SkPoint devPts[MAX_DEV_PTS]; SkPoint devPts[MAX_DEV_PTS];
const SkMatrix* matrix = fMatrix; const SkMatrix* matrix = fMatrix;
@ -850,14 +853,14 @@ void SkDraw::drawRect(const SkRect& prePaintRect, const SkPaint& paint,
return; return;
} }
SkDeviceLooper looper(fDst, *fRC, ir, paint.isAntiAlias()); SkDeviceLooper looper(*fBitmap, *fRC, ir, paint.isAntiAlias());
while (looper.next()) { while (looper.next()) {
SkRect localDevRect; SkRect localDevRect;
looper.mapRect(&localDevRect, devRect); looper.mapRect(&localDevRect, devRect);
SkMatrix localMatrix; SkMatrix localMatrix;
looper.mapMatrix(&localMatrix, *matrix); looper.mapMatrix(&localMatrix, *matrix);
SkAutoBlitterChoose blitterStorage(looper.getPixmap(), localMatrix, paint); SkAutoBlitterChoose blitterStorage(looper.getBitmap(), localMatrix, paint);
const SkRasterClip& clip = looper.getRC(); const SkRasterClip& clip = looper.getRC();
SkBlitter* blitter = blitterStorage.get(); SkBlitter* blitter = blitterStorage.get();
@ -908,7 +911,7 @@ void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const {
} }
SkAutoMaskFreeImage ami(dstM.fImage); SkAutoMaskFreeImage ami(dstM.fImage);
SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); SkAutoBlitterChoose blitterChooser(*fBitmap, *fMatrix, paint);
SkBlitter* blitter = blitterChooser.get(); SkBlitter* blitter = blitterChooser.get();
SkAAClipBlitterWrapper wrapper; SkAAClipBlitterWrapper wrapper;
@ -986,7 +989,7 @@ void SkDraw::drawRRect(const SkRRect& rrect, const SkPaint& paint) const {
// Transform the rrect into device space. // Transform the rrect into device space.
SkRRect devRRect; SkRRect devRRect;
if (rrect.transform(*fMatrix, &devRRect)) { if (rrect.transform(*fMatrix, &devRRect)) {
SkAutoBlitterChoose blitter(fDst, *fMatrix, paint); SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint);
if (paint.getMaskFilter()->filterRRect(devRRect, *fMatrix, *fRC, blitter.get(), if (paint.getMaskFilter()->filterRRect(devRRect, *fMatrix, *fRC, blitter.get(),
SkPaint::kFill_Style)) { SkPaint::kFill_Style)) {
return; // filterRRect() called the blitter, so we're done return; // filterRRect() called the blitter, so we're done
@ -1105,7 +1108,7 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint,
SkBlitter* blitter = NULL; SkBlitter* blitter = NULL;
SkAutoBlitterChoose blitterStorage; SkAutoBlitterChoose blitterStorage;
if (NULL == customBlitter) { if (NULL == customBlitter) {
blitterStorage.choose(fDst, *fMatrix, *paint, drawCoverage); blitterStorage.choose(*fBitmap, *fMatrix, *paint, drawCoverage);
blitter = blitterStorage.get(); blitter = blitterStorage.get();
} else { } else {
blitter = customBlitter; blitter = customBlitter;
@ -1179,7 +1182,7 @@ void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap,
// clipped to the actual device // clipped to the actual device
{ {
SkIRect devBounds; SkIRect devBounds;
devBounds.set(0, 0, fDst.width(), fDst.height()); devBounds.set(0, 0, fBitmap->width(), fBitmap->height());
// need intersect(l, t, r, b) on irect // need intersect(l, t, r, b) on irect
if (!mask.fBounds.intersect(devBounds)) { if (!mask.fBounds.intersect(devBounds)) {
return; return;
@ -1277,9 +1280,13 @@ void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
int ix = SkScalarRoundToInt(matrix.getTranslateX()); int ix = SkScalarRoundToInt(matrix.getTranslateX());
int iy = SkScalarRoundToInt(matrix.getTranslateY()); int iy = SkScalarRoundToInt(matrix.getTranslateY());
if (clipHandlesSprite(*fRC, ix, iy, pmap)) { if (clipHandlesSprite(*fRC, ix, iy, pmap)) {
SkPixmap dstPM;
if (!fBitmap->peekPixels(&dstPM)) {
return;
}
SkTBlitterAllocator allocator; SkTBlitterAllocator allocator;
// blitter will be owned by the allocator. // blitter will be owned by the allocator.
SkBlitter* blitter = SkBlitter::ChooseSprite(fDst, paint, pmap, ix, iy, &allocator); SkBlitter* blitter = SkBlitter::ChooseSprite(dstPM, paint, pmap, ix, iy, &allocator);
if (blitter) { if (blitter) {
SkScan::FillIRect(SkIRect::MakeXYWH(ix, iy, pmap.width(), pmap.height()), SkScan::FillIRect(SkIRect::MakeXYWH(ix, iy, pmap.width(), pmap.height()),
*fRC, blitter); *fRC, blitter);
@ -1334,9 +1341,13 @@ void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& ori
const SkPixmap& pmap = unlocker.pixmap(); const SkPixmap& pmap = unlocker.pixmap();
if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, pmap)) { if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, pmap)) {
SkPixmap dstPM;
if (!fBitmap->peekPixels(&dstPM)) {
return;
}
SkTBlitterAllocator allocator; SkTBlitterAllocator allocator;
// blitter will be owned by the allocator. // blitter will be owned by the allocator.
SkBlitter* blitter = SkBlitter::ChooseSprite(fDst, paint, pmap, x, y, &allocator); SkBlitter* blitter = SkBlitter::ChooseSprite(dstPM, paint, pmap, x, y, &allocator);
if (blitter) { if (blitter) {
SkScan::FillIRect(bounds, *fRC, blitter); SkScan::FillIRect(bounds, *fRC, blitter);
return; return;
@ -1635,7 +1646,7 @@ void SkDraw::drawText(const char text[], size_t byteLength,
SkAutoBlitterChoose blitterChooser; SkAutoBlitterChoose blitterChooser;
SkBlitter* blitter = NULL; SkBlitter* blitter = NULL;
if (needsRasterTextBlit(*this)) { if (needsRasterTextBlit(*this)) {
blitterChooser.choose(fDst, *fMatrix, paint); blitterChooser.choose(*fBitmap, *fMatrix, paint);
blitter = blitterChooser.get(); blitter = blitterChooser.get();
if (fRC->isAA()) { if (fRC->isAA()) {
aaBlitter.init(blitter, &fRC->aaRgn()); aaBlitter.init(blitter, &fRC->aaRgn());
@ -1754,7 +1765,7 @@ void SkDraw::drawPosText(const char text[], size_t byteLength,
SkAutoBlitterChoose blitterChooser; SkAutoBlitterChoose blitterChooser;
SkBlitter* blitter = NULL; SkBlitter* blitter = NULL;
if (needsRasterTextBlit(*this)) { if (needsRasterTextBlit(*this)) {
blitterChooser.choose(fDst, *fMatrix, paint); blitterChooser.choose(*fBitmap, *fMatrix, paint);
blitter = blitterChooser.get(); blitter = blitterChooser.get();
if (fRC->isAA()) { if (fRC->isAA()) {
wrapper.init(*fRC, blitter); wrapper.init(*fRC, blitter);
@ -2084,7 +2095,7 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
} }
} }
SkAutoBlitterChoose blitter(fDst, *fMatrix, p); SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p);
// Abort early if we failed to create a shader context. // Abort early if we failed to create a shader context.
if (blitter->isNullBlitter()) { if (blitter->isNullBlitter()) {
return; return;
@ -2155,6 +2166,7 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
#ifdef SK_DEBUG #ifdef SK_DEBUG
void SkDraw::validate() const { void SkDraw::validate() const {
SkASSERT(fBitmap != NULL);
SkASSERT(fMatrix != NULL); SkASSERT(fMatrix != NULL);
SkASSERT(fClip != NULL); SkASSERT(fClip != NULL);
SkASSERT(fRC != NULL); SkASSERT(fRC != NULL);
@ -2162,7 +2174,7 @@ void SkDraw::validate() const {
const SkIRect& cr = fRC->getBounds(); const SkIRect& cr = fRC->getBounds();
SkIRect br; SkIRect br;
br.set(0, 0, fDst.width(), fDst.height()); br.set(0, 0, fBitmap->width(), fBitmap->height());
SkASSERT(cr.isEmpty() || br.contains(cr)); SkASSERT(cr.isEmpty() || br.contains(cr));
} }
@ -2218,20 +2230,22 @@ static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds,
return true; return true;
} }
static void draw_into_mask(const SkMask& mask, const SkPath& devPath, SkPaint::Style style) { static void draw_into_mask(const SkMask& mask, const SkPath& devPath,
SkPaint::Style style) {
SkBitmap bm;
SkDraw draw; SkDraw draw;
if (!draw.fDst.reset(mask)) {
return;
}
SkRasterClip clip; SkRasterClip clip;
SkMatrix matrix; SkMatrix matrix;
SkPaint paint; SkPaint paint;
bm.installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), mask.fBounds.height()),
mask.fImage, mask.fRowBytes);
clip.setRect(SkIRect::MakeWH(mask.fBounds.width(), mask.fBounds.height())); clip.setRect(SkIRect::MakeWH(mask.fBounds.width(), mask.fBounds.height()));
matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft),
-SkIntToScalar(mask.fBounds.fTop)); -SkIntToScalar(mask.fBounds.fTop));
draw.fBitmap = &bm;
draw.fRC = &clip; draw.fRC = &clip;
draw.fClip = &clip.bwRgn(); draw.fClip = &clip.bwRgn();
draw.fMatrix = &matrix; draw.fMatrix = &matrix;

View File

@ -248,7 +248,7 @@ static void applyLUTToA8Mask(const SkMask& mask, const uint8_t* lut) {
} }
template<bool APPLY_PREBLEND> template<bool APPLY_PREBLEND>
static void pack4xHToLCD16(const SkPixmap& src, const SkMask& dst, static void pack4xHToLCD16(const SkBitmap& src, const SkMask& dst,
const SkMaskGamma::PreBlend& maskPreBlend) { const SkMaskGamma::PreBlend& maskPreBlend) {
#define SAMPLES_PER_PIXEL 4 #define SAMPLES_PER_PIXEL 4
#define LCD_PER_PIXEL 3 #define LCD_PER_PIXEL 3
@ -291,7 +291,7 @@ static void pack4xHToLCD16(const SkPixmap& src, const SkMask& dst,
}; };
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {
const uint8_t* srcP = src.addr8(0, y); const uint8_t* srcP = src.getAddr8(0, y);
// TODO: this fir filter implementation is straight forward, but slow. // TODO: this fir filter implementation is straight forward, but slow.
// It should be possible to make it much faster. // It should be possible to make it much faster.
@ -406,29 +406,29 @@ static void generateMask(const SkMask& mask, const SkPath& path,
clip.setRect(SkIRect::MakeWH(dstW, dstH)); clip.setRect(SkIRect::MakeWH(dstW, dstH));
const SkImageInfo info = SkImageInfo::MakeA8(dstW, dstH); const SkImageInfo info = SkImageInfo::MakeA8(dstW, dstH);
SkAutoPixmapStorage dst; SkBitmap bm;
if (0 == dstRB) { if (0 == dstRB) {
if (!dst.tryAlloc(info)) { if (!bm.tryAllocPixels(info)) {
// can't allocate offscreen, so empty the mask and return // can't allocate offscreen, so empty the mask and return
sk_bzero(mask.fImage, mask.computeImageSize()); sk_bzero(mask.fImage, mask.computeImageSize());
return; return;
} }
} else { } else {
dst.reset(info, mask.fImage, dstRB); bm.installPixels(info, mask.fImage, dstRB);
} }
sk_bzero(dst.writable_addr(), dst.getSafeSize()); sk_bzero(bm.getPixels(), bm.getSafeSize());
SkDraw draw; SkDraw draw;
draw.fDst = dst;
draw.fRC = &clip; draw.fRC = &clip;
draw.fClip = &clip.bwRgn(); draw.fClip = &clip.bwRgn();
draw.fMatrix = &matrix; draw.fMatrix = &matrix;
draw.fBitmap = &bm;
draw.drawPath(path, paint); draw.drawPath(path, paint);
switch (mask.fFormat) { switch (mask.fFormat) {
case SkMask::kBW_Format: case SkMask::kBW_Format:
packA8ToA1(mask, dst.addr8(0, 0), dst.rowBytes()); packA8ToA1(mask, bm.getAddr8(0, 0), bm.rowBytes());
break; break;
case SkMask::kA8_Format: case SkMask::kA8_Format:
if (maskPreBlend.isApplicable()) { if (maskPreBlend.isApplicable()) {
@ -437,9 +437,9 @@ static void generateMask(const SkMask& mask, const SkPath& path,
break; break;
case SkMask::kLCD16_Format: case SkMask::kLCD16_Format:
if (maskPreBlend.isApplicable()) { if (maskPreBlend.isApplicable()) {
pack4xHToLCD16<true>(dst, mask, maskPreBlend); pack4xHToLCD16<true>(bm, mask, maskPreBlend);
} else { } else {
pack4xHToLCD16<false>(dst, mask, maskPreBlend); pack4xHToLCD16<false>(bm, mask, maskPreBlend);
} }
break; break;
default: default:

View File

@ -344,7 +344,7 @@ public:
void blitMask(const SkMask&, const SkIRect& clip) override { void blitMask(const SkMask&, const SkIRect& clip) override {
SkDEBUGFAIL("blitMask unexpected"); SkDEBUGFAIL("blitMask unexpected");
} }
const SkPixmap* justAnOpaqueColor(uint32_t* value) override { const SkBitmap* justAnOpaqueColor(uint32_t* value) override {
SkDEBUGFAIL("justAnOpaqueColor unexpected"); SkDEBUGFAIL("justAnOpaqueColor unexpected");
return NULL; return NULL;
} }

View File

@ -116,12 +116,9 @@ bool SkLayerRasterizer::onRasterize(const SkPath& path, const SkMatrix& matrix,
} }
if (SkMask::kJustComputeBounds_CreateMode != mode) { if (SkMask::kJustComputeBounds_CreateMode != mode) {
SkDraw draw; SkBitmap device;
if (!draw.fDst.reset(*mask)) {
return false;
}
SkRasterClip rectClip; SkRasterClip rectClip;
SkDraw draw;
SkMatrix translatedMatrix; // this translates us to our local pixels SkMatrix translatedMatrix; // this translates us to our local pixels
SkMatrix drawMatrix; // this translates the path by each layer's offset SkMatrix drawMatrix; // this translates the path by each layer's offset
@ -131,6 +128,9 @@ bool SkLayerRasterizer::onRasterize(const SkPath& path, const SkMatrix& matrix,
translatedMatrix.postTranslate(-SkIntToScalar(mask->fBounds.fLeft), translatedMatrix.postTranslate(-SkIntToScalar(mask->fBounds.fLeft),
-SkIntToScalar(mask->fBounds.fTop)); -SkIntToScalar(mask->fBounds.fTop));
device.installMaskPixels(*mask);
draw.fBitmap = &device;
draw.fMatrix = &drawMatrix; draw.fMatrix = &drawMatrix;
draw.fRC = &rectClip; draw.fRC = &rectClip;
draw.fClip = &rectClip.bwRgn(); draw.fClip = &rectClip.bwRgn();

View File

@ -354,12 +354,14 @@ private:
SkIRect pathBounds = SkIRect::MakeWH(devPathBounds.width(), SkIRect pathBounds = SkIRect::MakeWH(devPathBounds.width(),
devPathBounds.height()); devPathBounds.height());
SkAutoPixmapStorage dst; SkBitmap bmp;
if (!dst.tryAlloc(SkImageInfo::MakeA8(pathBounds.width(), const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(pathBounds.fRight,
pathBounds.height()))) { pathBounds.fBottom);
if (!bmp.tryAllocPixels(bmImageInfo)) {
return false; return false;
} }
sk_bzero(dst.writable_addr(), dst.getSafeSize());
sk_bzero(bmp.getPixels(), bmp.getSafeSize());
// rasterize path // rasterize path
SkPaint paint; SkPaint paint;
@ -386,7 +388,7 @@ private:
draw.fRC = &rasterClip; draw.fRC = &rasterClip;
draw.fClip = &rasterClip.bwRgn(); draw.fClip = &rasterClip.bwRgn();
draw.fMatrix = &drawMatrix; draw.fMatrix = &drawMatrix;
draw.fDst = dst; draw.fBitmap = &bmp;
draw.drawPathCoverage(path, paint); draw.drawPathCoverage(path, paint);
@ -398,9 +400,13 @@ private:
SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char)); SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char));
// Generate signed distance field // Generate signed distance field
{
SkAutoLockPixels alp(bmp);
SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(),
(const unsigned char*)dst.addr(), (const unsigned char*)bmp.getPixels(),
dst.width(), dst.height(), dst.rowBytes()); bmp.width(), bmp.height(), bmp.rowBytes());
}
// add to atlas // add to atlas
SkIPoint16 atlasLocation; SkIPoint16 atlasLocation;

View File

@ -146,8 +146,7 @@ void GrSWMaskHelper::draw(const SkPath& path, const SkStrokeRec& stroke, SkRegio
if (kBlitter_CompressionMode == fCompressionMode) { if (kBlitter_CompressionMode == fCompressionMode) {
SkASSERT(fCompressedBuffer.get()); SkASSERT(fCompressedBuffer.get());
blitter = SkTextureCompressor::CreateBlitterForFormat( blitter = SkTextureCompressor::CreateBlitterForFormat(
fPixels.width(), fPixels.height(), fCompressedBuffer.get(), &allocator, fBM.width(), fBM.height(), fCompressedBuffer.get(), &allocator, fCompressedFormat);
fCompressedFormat);
} }
if (SkRegion::kReplace_Op == op && 0xFF == alpha) { if (SkRegion::kReplace_Op == op && 0xFF == alpha) {
@ -203,26 +202,28 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds,
} }
} }
sk_bzero(&fDraw, sizeof(fDraw));
// If we don't have a custom blitter, then we either need a bitmap to compress // If we don't have a custom blitter, then we either need a bitmap to compress
// from or a bitmap that we're going to use as a texture. In any case, we should // from or a bitmap that we're going to use as a texture. In any case, we should
// allocate the pixels for a bitmap // allocate the pixels for a bitmap
const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight); const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight);
if (kBlitter_CompressionMode != fCompressionMode) { if (kBlitter_CompressionMode != fCompressionMode) {
if (!fPixels.tryAlloc(bmImageInfo)) { if (!fBM.tryAllocPixels(bmImageInfo)) {
return false; return false;
} }
fPixels.erase(0);
sk_bzero(fBM.getPixels(), fBM.getSafeSize());
} else { } else {
// Otherwise, we just need to remember how big the buffer is... // Otherwise, we just need to remember how big the buffer is...
fPixels.reset(bmImageInfo); fBM.setInfo(bmImageInfo);
} }
fDraw.fDst = fPixels;
sk_bzero(&fDraw, sizeof(fDraw));
fRasterClip.setRect(bounds); fRasterClip.setRect(bounds);
fDraw.fRC = &fRasterClip; fDraw.fRC = &fRasterClip;
fDraw.fClip = &fRasterClip.bwRgn(); fDraw.fClip = &fRasterClip.bwRgn();
fDraw.fMatrix = &fMatrix; fDraw.fMatrix = &fMatrix;
fDraw.fBitmap = &fBM;
return true; return true;
} }
@ -231,8 +232,8 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds,
*/ */
GrTexture* GrSWMaskHelper::createTexture() { GrTexture* GrSWMaskHelper::createTexture() {
GrSurfaceDesc desc; GrSurfaceDesc desc;
desc.fWidth = fPixels.width(); desc.fWidth = fBM.width();
desc.fHeight = fPixels.height(); desc.fHeight = fBM.height();
desc.fConfig = kAlpha_8_GrPixelConfig; desc.fConfig = kAlpha_8_GrPixelConfig;
if (kNone_CompressionMode != fCompressionMode) { if (kNone_CompressionMode != fCompressionMode) {
@ -272,8 +273,7 @@ void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrSurfaceDesc
SkASSERT(GrPixelConfigIsCompressed(desc.fConfig)); SkASSERT(GrPixelConfigIsCompressed(desc.fConfig));
SkASSERT(fmt_to_config(fCompressedFormat) == desc.fConfig); SkASSERT(fmt_to_config(fCompressedFormat) == desc.fConfig);
SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fPixels, SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fBM, fCompressedFormat));
fCompressedFormat));
SkASSERT(cmpData); SkASSERT(cmpData);
this->sendTextureData(texture, desc, cmpData->data(), 0); this->sendTextureData(texture, desc, cmpData->data(), 0);
@ -283,15 +283,17 @@ void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrSurfaceDesc
* Move the result of the software mask generation back to the gpu * Move the result of the software mask generation back to the gpu
*/ */
void GrSWMaskHelper::toTexture(GrTexture *texture) { void GrSWMaskHelper::toTexture(GrTexture *texture) {
SkAutoLockPixels alp(fBM);
GrSurfaceDesc desc; GrSurfaceDesc desc;
desc.fWidth = fPixels.width(); desc.fWidth = fBM.width();
desc.fHeight = fPixels.height(); desc.fHeight = fBM.height();
desc.fConfig = texture->config(); desc.fConfig = texture->config();
// First see if we should compress this texture before uploading. // First see if we should compress this texture before uploading.
switch (fCompressionMode) { switch (fCompressionMode) {
case kNone_CompressionMode: case kNone_CompressionMode:
this->sendTextureData(texture, desc, fPixels.addr(), fPixels.rowBytes()); this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes());
break; break;
case kCompress_CompressionMode: case kCompress_CompressionMode:
@ -309,8 +311,10 @@ void GrSWMaskHelper::toTexture(GrTexture *texture) {
* Convert mask generation results to a signed distance field * Convert mask generation results to a signed distance field
*/ */
void GrSWMaskHelper::toSDF(unsigned char* sdf) { void GrSWMaskHelper::toSDF(unsigned char* sdf) {
SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fPixels.addr(), SkAutoLockPixels alp(fBM);
fPixels.width(), fPixels.height(), fPixels.rowBytes());
SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fBM.getPixels(),
fBM.width(), fBM.height(), fBM.rowBytes());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -69,7 +69,7 @@ public:
// Reset the internal bitmap // Reset the internal bitmap
void clear(uint8_t alpha) { void clear(uint8_t alpha) {
fPixels.erase(SkColorSetARGB(alpha, 0xFF, 0xFF, 0xFF)); fBM.eraseColor(SkColorSetARGB(alpha, alpha, alpha, alpha));
} }
// Canonical usage utility that draws a single path and uploads it // Canonical usage utility that draws a single path and uploads it
@ -105,7 +105,7 @@ private:
GrContext* fContext; GrContext* fContext;
SkMatrix fMatrix; SkMatrix fMatrix;
SkAutoPixmapStorage fPixels; SkBitmap fBM;
SkDraw fDraw; SkDraw fDraw;
SkRasterClip fRasterClip; SkRasterClip fRasterClip;

View File

@ -173,17 +173,19 @@ bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol
return false; return false;
} }
SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) { SkData* CompressBitmapToFormat(const SkBitmap &bitmap, Format format) {
int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixmap.height()); SkAutoLockPixels alp(bitmap);
int compressedDataSize = GetCompressedDataSize(format, bitmap.width(), bitmap.height());
if (compressedDataSize < 0) { if (compressedDataSize < 0) {
return NULL; return NULL;
} }
const uint8_t* src = reinterpret_cast<const uint8_t*>(pixmap.addr()); const uint8_t* src = reinterpret_cast<const uint8_t*>(bitmap.getPixels());
SkData* dst = SkData::NewUninitialized(compressedDataSize); SkData* dst = SkData::NewUninitialized(compressedDataSize);
if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, pixmap.colorType(), if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, bitmap.colorType(),
pixmap.width(), pixmap.height(), pixmap.rowBytes(), format)) { bitmap.width(), bitmap.height(), bitmap.rowBytes(), format)) {
dst->unref(); dst->unref();
dst = NULL; dst = NULL;
} }

View File

@ -55,10 +55,10 @@ namespace SkTextureCompressor {
int GetCompressedDataSize(Format fmt, int width, int height); int GetCompressedDataSize(Format fmt, int width, int height);
// Returns an SkData holding a blob of compressed data that corresponds // Returns an SkData holding a blob of compressed data that corresponds
// to the pixmap. If the pixmap colorType cannot be compressed using the // to the bitmap. If the bitmap colorType cannot be compressed using the
// associated format, then we return NULL. The caller is responsible for // associated format, then we return NULL. The caller is responsible for
// calling unref() on the returned data. // calling unref() on the returned data.
SkData* CompressBitmapToFormat(const SkPixmap&, Format format); SkData* CompressBitmapToFormat(const SkBitmap& bitmap, Format format);
// Compresses the given src data into dst. The src data is assumed to be // Compresses the given src data into dst. The src data is assumed to be
// large enough to hold width*height pixels. The dst data is expected to // large enough to hold width*height pixels. The dst data is expected to

View File

@ -368,7 +368,7 @@ public:
// If the blitter just sets a single value for each pixel, return the // If the blitter just sets a single value for each pixel, return the
// bitmap it draws into, and assign value. If not, return NULL and ignore // bitmap it draws into, and assign value. If not, return NULL and ignore
// the value parameter. // the value parameter.
const SkPixmap* justAnOpaqueColor(uint32_t* value) override { const SkBitmap* justAnOpaqueColor(uint32_t* value) override {
return NULL; return NULL;
} }

View File

@ -9,8 +9,9 @@
#include "SkRasterClip.h" #include "SkRasterClip.h"
#include "Test.h" #include "Test.h"
static void make_pm(SkAutoPixmapStorage* pixmap, int w, int h) { static void make_bm(SkBitmap* bm, int w, int h) {
pixmap->alloc(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, kPremul_SkAlphaType)); bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType,
kPremul_SkAlphaType));
} }
static bool equal(const SkRasterClip& a, const SkRasterClip& b) { static bool equal(const SkRasterClip& a, const SkRasterClip& b) {
@ -39,19 +40,19 @@ static const struct {
static void test_simple(skiatest::Reporter* reporter) { static void test_simple(skiatest::Reporter* reporter) {
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
SkAutoPixmapStorage pmap; SkBitmap bitmap;
make_pm(&pmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height()); make_bm(&bitmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height());
SkRasterClip rc(gRec[i].fRCBounds); SkRasterClip rc(gRec[i].fRCBounds);
for (int aa = 0; aa <= 1; ++aa) { for (int aa = 0; aa <= 1; ++aa) {
SkDeviceLooper looper(pmap, rc, gRec[i].fRect, SkToBool(aa)); SkDeviceLooper looper(bitmap, rc, gRec[i].fRect, SkToBool(aa));
bool valid = looper.next(); bool valid = looper.next();
REPORTER_ASSERT(reporter, valid); REPORTER_ASSERT(reporter, valid);
if (valid) { if (valid) {
REPORTER_ASSERT(reporter, looper.getPixmap().width() == pmap.width()); REPORTER_ASSERT(reporter, looper.getBitmap().width() == bitmap.width());
REPORTER_ASSERT(reporter, looper.getPixmap().height() == pmap.height()); REPORTER_ASSERT(reporter, looper.getBitmap().height() == bitmap.height());
REPORTER_ASSERT(reporter, equal(looper.getRC(), rc)); REPORTER_ASSERT(reporter, equal(looper.getRC(), rc));
REPORTER_ASSERT(reporter, !looper.next()); REPORTER_ASSERT(reporter, !looper.next());
@ -61,7 +62,7 @@ static void test_simple(skiatest::Reporter* reporter) {
{ {
SkIRect r = rc.getBounds(); SkIRect r = rc.getBounds();
r.offset(r.width(), 0); r.offset(r.width(), 0);
SkDeviceLooper looper(pmap, rc, r, false); SkDeviceLooper looper(bitmap, rc, r, false);
REPORTER_ASSERT(reporter, !looper.next()); REPORTER_ASSERT(reporter, !looper.next());
} }
} }
@ -108,8 +109,8 @@ static void test_complex(skiatest::Reporter* reporter) {
const int w = gRec[i].fSize.width(); const int w = gRec[i].fSize.width();
const int h = gRec[i].fSize.height(); const int h = gRec[i].fSize.height();
SkAutoPixmapStorage pmap; SkBitmap bitmap;
make_pm(&pmap, w, h); make_bm(&bitmap, w, h);
const SkIRect rect = SkIRect::MakeWH(w, h); const SkIRect rect = SkIRect::MakeWH(w, h);
@ -124,7 +125,7 @@ static void test_complex(skiatest::Reporter* reporter) {
SkRasterClip rc; SkRasterClip rc;
rc.op(rgn, SkRegion::kReplace_Op); rc.op(rgn, SkRegion::kReplace_Op);
SkDeviceLooper looper(pmap, rc, rect, gRec[i].fAA); SkDeviceLooper looper(bitmap, rc, rect, gRec[i].fAA);
while (looper.next()) { while (looper.next()) {
REPORTER_ASSERT(reporter, !looper.getRC().isEmpty()); REPORTER_ASSERT(reporter, !looper.getRC().isEmpty());
} }

View File

@ -42,8 +42,10 @@ static bool compresses_a8(SkTextureCompressor::Format fmt) {
* Make sure that we properly fail when we don't have multiple of four image dimensions. * Make sure that we properly fail when we don't have multiple of four image dimensions.
*/ */
DEF_TEST(CompressAlphaFailDimensions, reporter) { DEF_TEST(CompressAlphaFailDimensions, reporter) {
SkBitmap bitmap;
static const int kWidth = 17; static const int kWidth = 17;
static const int kHeight = 17; static const int kHeight = 17;
SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
// R11_EAC and LATC are both dimensions of 4, so we need to make sure that we // R11_EAC and LATC are both dimensions of 4, so we need to make sure that we
// are violating those assumptions. And if we are, then we're also violating the // are violating those assumptions. And if we are, then we're also violating the
@ -53,16 +55,18 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) {
REPORTER_ASSERT(reporter, kWidth % 4 != 0); REPORTER_ASSERT(reporter, kWidth % 4 != 0);
REPORTER_ASSERT(reporter, kHeight % 4 != 0); REPORTER_ASSERT(reporter, kHeight % 4 != 0);
SkAutoPixmapStorage pixmap; bool setInfoSuccess = bitmap.setInfo(info);
pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); REPORTER_ASSERT(reporter, setInfoSuccess);
// leaving the pixels uninitialized, as they don't affect the test...
bitmap.allocPixels(info);
bitmap.unlockPixels();
for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i); const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i);
if (!compresses_a8(fmt)) { if (!compresses_a8(fmt)) {
continue; continue;
} }
SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
REPORTER_ASSERT(reporter, NULL == data); REPORTER_ASSERT(reporter, NULL == data);
} }
} }
@ -72,8 +76,10 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) {
* compressed textures can (currently) only be created from A8 bitmaps. * compressed textures can (currently) only be created from A8 bitmaps.
*/ */
DEF_TEST(CompressAlphaFailColorType, reporter) { DEF_TEST(CompressAlphaFailColorType, reporter) {
SkBitmap bitmap;
static const int kWidth = 12; static const int kWidth = 12;
static const int kHeight = 12; static const int kHeight = 12;
SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
// ASTC is at most 12x12, and any dimension divisible by 12 is also divisible // ASTC is at most 12x12, and any dimension divisible by 12 is also divisible
// by 4, which is the dimensions of R11_EAC and LATC. In the future, we might // by 4, which is the dimensions of R11_EAC and LATC. In the future, we might
@ -82,16 +88,18 @@ DEF_TEST(CompressAlphaFailColorType, reporter) {
REPORTER_ASSERT(reporter, kWidth % 12 == 0); REPORTER_ASSERT(reporter, kWidth % 12 == 0);
REPORTER_ASSERT(reporter, kHeight % 12 == 0); REPORTER_ASSERT(reporter, kHeight % 12 == 0);
SkAutoPixmapStorage pixmap; bool setInfoSuccess = bitmap.setInfo(info);
pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight)); REPORTER_ASSERT(reporter, setInfoSuccess);
// leaving the pixels uninitialized, as they don't affect the test...
bitmap.allocPixels(info);
bitmap.unlockPixels();
for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) {
const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i); const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor::Format>(i);
if (!compresses_a8(fmt)) { if (!compresses_a8(fmt)) {
continue; continue;
} }
SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
REPORTER_ASSERT(reporter, NULL == data); REPORTER_ASSERT(reporter, NULL == data);
} }
} }
@ -101,8 +109,10 @@ DEF_TEST(CompressAlphaFailColorType, reporter) {
* then decompress it, you get what you started with. * then decompress it, you get what you started with.
*/ */
DEF_TEST(CompressCheckerboard, reporter) { DEF_TEST(CompressCheckerboard, reporter) {
SkBitmap bitmap;
static const int kWidth = 48; // We need the number to be divisible by both static const int kWidth = 48; // We need the number to be divisible by both
static const int kHeight = 48; // 12 (ASTC) and 16 (ARM NEON R11 EAC). static const int kHeight = 48; // 12 (ASTC) and 16 (ARM NEON R11 EAC).
SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
// ASTC is at most 12x12, and any dimension divisible by 12 is also divisible // ASTC is at most 12x12, and any dimension divisible by 12 is also divisible
// by 4, which is the dimensions of R11_EAC and LATC. In the future, we might // by 4, which is the dimensions of R11_EAC and LATC. In the future, we might
@ -113,12 +123,17 @@ DEF_TEST(CompressCheckerboard, reporter) {
REPORTER_ASSERT(reporter, kWidth % 48 == 0); REPORTER_ASSERT(reporter, kWidth % 48 == 0);
REPORTER_ASSERT(reporter, kHeight % 48 == 0); REPORTER_ASSERT(reporter, kHeight % 48 == 0);
SkAutoPixmapStorage pixmap; bool setInfoSuccess = bitmap.setInfo(info);
pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); REPORTER_ASSERT(reporter, setInfoSuccess);
// Populate the pixels bitmap.allocPixels(info);
bitmap.unlockPixels();
// Populate bitmap
{ {
uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); SkAutoLockPixels alp(bitmap);
uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
REPORTER_ASSERT(reporter, pixels); REPORTER_ASSERT(reporter, pixels);
if (NULL == pixels) { if (NULL == pixels) {
return; return;
@ -132,7 +147,7 @@ DEF_TEST(CompressCheckerboard, reporter) {
pixels[x] = 0; pixels[x] = 0;
} }
} }
pixels += pixmap.rowBytes(); pixels += bitmap.rowBytes();
} }
} }
@ -152,7 +167,7 @@ DEF_TEST(CompressCheckerboard, reporter) {
continue; continue;
} }
SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt));
REPORTER_ASSERT(reporter, data); REPORTER_ASSERT(reporter, data);
if (NULL == data) { if (NULL == data) {
continue; continue;
@ -165,7 +180,8 @@ DEF_TEST(CompressCheckerboard, reporter) {
kWidth, kHeight, fmt); kWidth, kHeight, fmt);
REPORTER_ASSERT(reporter, decompResult); REPORTER_ASSERT(reporter, decompResult);
const uint8_t* pixels = reinterpret_cast<const uint8_t*>(pixmap.addr()); SkAutoLockPixels alp(bitmap);
uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
REPORTER_ASSERT(reporter, pixels); REPORTER_ASSERT(reporter, pixels);
if (NULL == pixels) { if (NULL == pixels) {
continue; continue;
@ -173,7 +189,7 @@ DEF_TEST(CompressCheckerboard, reporter) {
for (int y = 0; y < kHeight; ++y) { for (int y = 0; y < kHeight; ++y) {
for (int x = 0; x < kWidth; ++x) { for (int x = 0; x < kWidth; ++x) {
bool ok = pixels[y*pixmap.rowBytes() + x] == decompBuffer[y*kWidth + x]; bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWidth + x];
REPORTER_ASSERT(reporter, ok); REPORTER_ASSERT(reporter, ok);
} }
} }
@ -188,11 +204,16 @@ DEF_TEST(CompressLATC, reporter) {
const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_Format; const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_Format;
static const int kLATCEncodedBlockSize = 8; static const int kLATCEncodedBlockSize = 8;
SkBitmap bitmap;
static const int kWidth = 8; static const int kWidth = 8;
static const int kHeight = 8; static const int kHeight = 8;
SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight);
SkAutoPixmapStorage pixmap; bool setInfoSuccess = bitmap.setInfo(info);
pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); REPORTER_ASSERT(reporter, setInfoSuccess);
bitmap.allocPixels(info);
bitmap.unlockPixels();
int latcDimX, latcDimY; int latcDimX, latcDimY;
SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY); SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY);
@ -205,13 +226,21 @@ DEF_TEST(CompressLATC, reporter) {
REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0); REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0);
for (int lum = 0; lum < 256; ++lum) { for (int lum = 0; lum < 256; ++lum) {
uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); bitmap.lockPixels();
uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
REPORTER_ASSERT(reporter, pixels);
if (NULL == pixels) {
bitmap.unlockPixels();
continue;
}
for (int i = 0; i < kWidth*kHeight; ++i) { for (int i = 0; i < kWidth*kHeight; ++i) {
pixels[i] = lum; pixels[i] = lum;
} }
bitmap.unlockPixels();
SkAutoDataUnref latcData( SkAutoDataUnref latcData(
SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat)); SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat));
REPORTER_ASSERT(reporter, latcData); REPORTER_ASSERT(reporter, latcData);
if (NULL == latcData) { if (NULL == latcData) {
continue; continue;