diff --git a/bench/CoverageBench.cpp b/bench/CoverageBench.cpp index 135ef39233..96eafaaace 100644 --- a/bench/CoverageBench.cpp +++ b/bench/CoverageBench.cpp @@ -19,7 +19,7 @@ class DrawPathBench : public Benchmark { SkString fName; SkPath fPath; SkRasterClip fRC; - SkAutoPixmapStorage fPixmap; + SkBitmap fBitmap; SkMatrix fIdentity; SkDraw fDraw; bool fDrawCoverage; @@ -32,12 +32,12 @@ public: fPath.quadTo(500, 0, 500, 500); fPath.quadTo(250, 0, 0, 500); - fPixmap.alloc(SkImageInfo::MakeA8(500, 500)); + fBitmap.allocPixels(SkImageInfo::MakeA8(500, 500)); fIdentity.setIdentity(); fRC.setRect(fPath.getBounds().round()); - fDraw.fDst = fPixmap; + fDraw.fBitmap = &fBitmap; fDraw.fMatrix = &fIdentity; fDraw.fClip = &fRC.bwRgn(); fDraw.fRC = &fRC; diff --git a/gm/fatpathfill.cpp b/gm/fatpathfill.cpp index 43e10059c1..1d269a0289 100644 --- a/gm/fatpathfill.cpp +++ b/gm/fatpathfill.cpp @@ -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; 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); paint.setAntiAlias(true); paint.setColor(SK_ColorRED); 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); } @@ -52,15 +57,15 @@ public: protected: - SkString onShortName() override { + virtual SkString onShortName() { return SkString("fatpathfill"); } - SkISize onISize() override { + virtual SkISize onISize() { return SkISize::Make(SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP); } - void onDraw(SkCanvas* canvas) override { + virtual void onDraw(SkCanvas* canvas) { SkAutoTUnref surface(new_surface(SMALL_W, SMALL_H)); canvas->scale(ZOOM, ZOOM); @@ -71,10 +76,10 @@ protected: for (int i = 0; i < REPEAT_LOOP; ++i) { SkPath line, path; - line.moveTo(1, 2); - line.lineTo(SkIntToScalar(4 + i), 1); + line.moveTo(SkIntToScalar(1), SkIntToScalar(2)); + line.lineTo(SkIntToScalar(4 + i), SkIntToScalar(1)); paint.getFillPath(line, &path); - draw_fatpath(canvas, surface, path); + draw_fatpath(canvas, surface, &path, 1); canvas->translate(0, SMALL_H); } diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h index 1f7d8174c1..7b5514d13b 100644 --- a/include/core/SkDraw.h +++ b/include/core/SkDraw.h @@ -140,8 +140,7 @@ private: computeConservativeLocalClipBounds(SkRect* bounds) const; public: -// const SkBitmap* fBitmap; // required - SkPixmap fDst; + const SkBitmap* fBitmap; // required const SkMatrix* fMatrix; // required const SkRegion* fClip; // DEPRECATED const SkRasterClip* fRC; // required diff --git a/src/core/SkAAClip.cpp b/src/core/SkAAClip.cpp index 19e94c8c86..e55451e3d9 100644 --- a/src/core/SkAAClip.cpp +++ b/src/core/SkAAClip.cpp @@ -1297,7 +1297,7 @@ public: void blitMask(const SkMask&, const SkIRect& clip) override { unexpected(); } - const SkPixmap* justAnOpaqueColor(uint32_t*) override { + const SkBitmap* justAnOpaqueColor(uint32_t*) override { return NULL; } @@ -2219,6 +2219,6 @@ void SkAAClipBlitter::blitMask(const SkMask& origMask, const SkIRect& clip) { } while (y < stopY); } -const SkPixmap* SkAAClipBlitter::justAnOpaqueColor(uint32_t* value) { +const SkBitmap* SkAAClipBlitter::justAnOpaqueColor(uint32_t* value) { return NULL; } diff --git a/src/core/SkAAClip.h b/src/core/SkAAClip.h index 9f6a3d6012..1daeb38f59 100644 --- a/src/core/SkAAClip.h +++ b/src/core/SkAAClip.h @@ -110,11 +110,12 @@ public: } 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 blitRect(int x, int y, int width, int height) override; void blitMask(const SkMask&, const SkIRect& clip) override; - const SkPixmap* justAnOpaqueColor(uint32_t* value) override; + const SkBitmap* justAnOpaqueColor(uint32_t* value) override; private: SkBlitter* fBlitter; diff --git a/src/core/SkBlitBWMaskTemplate.h b/src/core/SkBlitBWMaskTemplate.h index accf498aba..798e44aaa4 100644 --- a/src/core/SkBlitBWMaskTemplate.h +++ b/src/core/SkBlitBWMaskTemplate.h @@ -19,19 +19,19 @@ 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_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 */ -static void SK_BLITBWMASK_NAME(const SkPixmap& dst, const SkMask& srcMask, - const SkIRect& clip SK_BLITBWMASK_ARGS) { +static void SK_BLITBWMASK_NAME(const SkBitmap& bitmap, const SkMask& srcMask, const SkIRect& clip SK_BLITBWMASK_ARGS) +{ SkASSERT(clip.fRight <= srcMask.fBounds.fRight); int cx = clip.fLeft; int cy = clip.fTop; int maskLeft = srcMask.fBounds.fLeft; unsigned mask_rowBytes = srcMask.fRowBytes; - size_t bitmap_rowBytes = dst.rowBytes(); + size_t bitmap_rowBytes = bitmap.rowBytes(); unsigned height = clip.height(); SkASSERT(mask_rowBytes != 0); @@ -39,7 +39,7 @@ static void SK_BLITBWMASK_NAME(const SkPixmap& dst, const SkMask& srcMask, SkASSERT(height != 0); 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) { diff --git a/src/core/SkBlitMask.h b/src/core/SkBlitMask.h index 3fc306f8c8..32db43c3d8 100644 --- a/src/core/SkBlitMask.h +++ b/src/core/SkBlitMask.h @@ -8,9 +8,9 @@ #ifndef SkBlitMask_DEFINED #define SkBlitMask_DEFINED +#include "SkBitmap.h" #include "SkColor.h" #include "SkMask.h" -#include "SkPixmap.h" class SkBlitMask { public: @@ -18,7 +18,7 @@ public: * Returns true if the device config and mask format were supported. * 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); /** diff --git a/src/core/SkBlitMask_D32.cpp b/src/core/SkBlitMask_D32.cpp index 210810801a..594a274d42 100644 --- a/src/core/SkBlitMask_D32.cpp +++ b/src/core/SkBlitMask_D32.cpp @@ -147,13 +147,13 @@ SkBlitMask::ColorProc SkBlitMask::ColorFactory(SkColorType ct, 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) { ColorProc proc = ColorFactory(device.colorType(), mask.fFormat, color); if (proc) { int x = clip.fLeft; 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()); return true; } diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index 59078d6a87..2ac7b51180 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -33,7 +33,7 @@ SkShader::Context* SkBlitter::getShaderContext() const { return NULL; } -const SkPixmap* SkBlitter::justAnOpaqueColor(uint32_t* value) { +const SkBitmap* SkBlitter::justAnOpaqueColor(uint32_t* value) { 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) {} -const SkPixmap* SkNullBlitter::justAnOpaqueColor(uint32_t* value) { +const SkBitmap* SkNullBlitter::justAnOpaqueColor(uint32_t* value) { 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); } @@ -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); } @@ -778,7 +778,7 @@ private: #include "SkCoreBlitters.h" -SkBlitter* SkBlitter::Choose(const SkPixmap& device, +SkBlitter* SkBlitter::Choose(const SkBitmap& device, const SkMatrix& matrix, const SkPaint& origPaint, SkTBlitterAllocator* allocator, @@ -944,7 +944,7 @@ private: typedef SkShader::Context INHERITED; }; -SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, +SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext) : INHERITED(device) , fShader(paint.getShader()) diff --git a/src/core/SkBlitter.h b/src/core/SkBlitter.h index b8126c24c6..695585a798 100644 --- a/src/core/SkBlitter.h +++ b/src/core/SkBlitter.h @@ -8,11 +8,11 @@ #ifndef SkBlitter_DEFINED #define SkBlitter_DEFINED +#include "SkBitmap.h" #include "SkBitmapProcShader.h" #include "SkMask.h" #include "SkMatrix.h" #include "SkPaint.h" -#include "SkPixmap.h" #include "SkRefCnt.h" #include "SkRegion.h" #include "SkShader.h" @@ -51,7 +51,7 @@ public: bitmap it draws into, and assign value. If not, return NULL and ignore the value parameter. */ - virtual const SkPixmap* justAnOpaqueColor(uint32_t* value); + virtual const SkBitmap* justAnOpaqueColor(uint32_t* value); // (x, y), (x + 1, y) virtual void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) { @@ -122,7 +122,7 @@ public: /** @name Factories 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 SkPaint& paint, SkTBlitterAllocator*, @@ -152,7 +152,7 @@ public: void blitV(int x, int y, int height, SkAlpha alpha) override; void blitRect(int x, int y, int width, int height) 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; }; @@ -176,7 +176,7 @@ public: virtual void blitAntiRect(int x, int y, int width, int height, SkAlpha leftAlpha, SkAlpha rightAlpha) 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 { return fBlitter->requestRowsPreserved(); @@ -211,7 +211,7 @@ public: virtual void blitAntiRect(int x, int y, int width, int height, SkAlpha leftAlpha, SkAlpha rightAlpha) 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 { return fBlitter->requestRowsPreserved(); diff --git a/src/core/SkBlitter_A8.cpp b/src/core/SkBlitter_A8.cpp index ce7d6e7ad2..11f425903b 100644 --- a/src/core/SkBlitter_A8.cpp +++ b/src/core/SkBlitter_A8.cpp @@ -12,11 +12,12 @@ #include "SkShader.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(); } -const SkPixmap* SkA8_Blitter::justAnOpaqueColor(uint32_t* value) { +const SkBitmap* SkA8_Blitter::justAnOpaqueColor(uint32_t* value) { if (255 == fSrcA) { *value = 255; return &fDevice; @@ -32,7 +33,7 @@ void SkA8_Blitter::blitH(int x, int y, int width) { return; } - uint8_t* device = fDevice.writable_addr8(x, y); + uint8_t* device = fDevice.getAddr8(x, y); if (fSrcA == 255) { memset(device, 0xFF, width); @@ -52,7 +53,7 @@ void SkA8_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], return; } - uint8_t* device = fDevice.writable_addr8(x, y); + uint8_t* device = fDevice.getAddr8(x, y); unsigned srcA = fSrcA; 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_ARGS #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 #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_ARGS , U8CPU sa, unsigned 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 #include "SkBlitBWMaskTemplate.h" @@ -138,7 +139,7 @@ void SkA8_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { int y = clip.fTop; int width = clip.width(); 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); 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)); - uint8_t* device = fDevice.writable_addr8(x, y); + uint8_t* device = fDevice.getAddr8(x, y); size_t rowBytes = fDevice.rowBytes(); if (sa == 0xFF) { @@ -205,7 +206,7 @@ void SkA8_Blitter::blitRect(int x, int y, int width, int height) { return; } - uint8_t* device = fDevice.writable_addr8(x, y); + uint8_t* device = fDevice.getAddr8(x, y); unsigned srcA = fSrcA; 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) - : INHERITED(device, paint, shaderContext) -{ + : INHERITED(device, paint, shaderContext) { if ((fXfermode = paint.getXfermode()) != NULL) { fXfermode->ref(); SkASSERT(fShaderContext); @@ -250,7 +250,7 @@ void SkA8_Shader_Blitter::blitH(int x, int y, int width) { SkASSERT(x >= 0 && y >= 0 && (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; 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; uint8_t* aaExpand = fAAExpand; 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; for (;;) { @@ -329,7 +329,7 @@ void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { int y = clip.fTop; int width = clip.width(); 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); 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) { SkASSERT(NULL == paint.getShader()); 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[], const int16_t runs[]) { - uint8_t* device = fDevice.writable_addr8(x, y); + uint8_t* device = fDevice.getAddr8(x, y); SkDEBUGCODE(int totalCount = 0;) 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) { - 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) { @@ -392,7 +392,7 @@ void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { return; } - uint8_t* dst = fDevice.writable_addr8(x, y); + uint8_t* dst = fDevice.getAddr8(x, y); const size_t dstRB = fDevice.rowBytes(); while (--height >= 0) { *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) { - uint8_t* dst = fDevice.writable_addr8(x, y); + uint8_t* dst = fDevice.getAddr8(x, y); const size_t dstRB = fDevice.rowBytes(); while (--height >= 0) { memset(dst, 0xFF, width); @@ -417,7 +417,7 @@ void SkA8_Coverage_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { int width = clip.width(); 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 size_t srcRB = mask.fRowBytes; 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; } diff --git a/src/core/SkBlitter_ARGB32.cpp b/src/core/SkBlitter_ARGB32.cpp index 683acf0aae..f2de82a2e9 100644 --- a/src/core/SkBlitter_ARGB32.cpp +++ b/src/core/SkBlitter_ARGB32.cpp @@ -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) { U8CPU alpha = SkGetPackedA32(srcColor); unsigned flags = SkBlitRow::kSrcPixelAlpha_Flag32; @@ -28,7 +28,7 @@ static void SkARGB32_Blit32(const SkPixmap& device, const SkMask& mask, int width = clip.width(); int height = clip.height(); - SkPMColor* dstRow = device.writable_addr32(x, y); + SkPMColor* dstRow = device.getAddr32(x, y); const SkPMColor* srcRow = reinterpret_cast(mask.getAddr8(x, y)); 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) { SkColor color = paint.getColor(); fColor = color; @@ -54,7 +54,7 @@ SkARGB32_Blitter::SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint) 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) { *value = fPMColor; return &fDevice; @@ -70,7 +70,7 @@ const SkPixmap* SkARGB32_Blitter::justAnOpaqueColor(uint32_t* value) { void SkARGB32_Blitter::blitH(int x, int y, int 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); } @@ -81,7 +81,7 @@ void SkARGB32_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], } 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 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) { - uint32_t* device = fDevice.writable_addr32(x, y); - SkDEBUGCODE((void)fDevice.writable_addr32(x + 1, y);) + uint32_t* device = fDevice.getAddr32(x, y); + SkDEBUGCODE((void)fDevice.getAddr32(x + 1, y);) device[0] = SkBlendARGB32(fPMColor, device[0], a0); device[1] = SkBlendARGB32(fPMColor, device[1], a1); } void SkARGB32_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) { - uint32_t* device = fDevice.writable_addr32(x, y); - SkDEBUGCODE((void)fDevice.writable_addr32(x, y + 1);) + uint32_t* device = fDevice.getAddr32(x, y); + SkDEBUGCODE((void)fDevice.getAddr32(x, y + 1);) device[0] = SkBlendARGB32(fPMColor, device[0], a0); 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_ARGS , SkPMColor 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 #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_ARGS , uint32_t sc, unsigned 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 #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) { - uint32_t* device = fDevice.writable_addr32(x, y); - SkDEBUGCODE((void)fDevice.writable_addr32(x + 1, y);) + uint32_t* device = fDevice.getAddr32(x, y); + SkDEBUGCODE((void)fDevice.getAddr32(x + 1, y);) device[0] = SkFastFourByteInterp(fPMColor, device[0], a0); device[1] = SkFastFourByteInterp(fPMColor, device[1], a1); } void SkARGB32_Opaque_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) { - uint32_t* device = fDevice.writable_addr32(x, y); - SkDEBUGCODE((void)fDevice.writable_addr32(x, y + 1);) + uint32_t* device = fDevice.getAddr32(x, y); + SkDEBUGCODE((void)fDevice.getAddr32(x, y + 1);) device[0] = SkFastFourByteInterp(fPMColor, device[0], a0); device = (uint32_t*)((char*)device + fDevice.rowBytes()); @@ -220,7 +220,7 @@ void SkARGB32_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { return; } - uint32_t* device = fDevice.writable_addr32(x, y); + uint32_t* device = fDevice.getAddr32(x, y); uint32_t color = fPMColor; if (alpha != 255) { @@ -242,7 +242,7 @@ void SkARGB32_Blitter::blitRect(int x, int y, int width, int height) { return; } - uint32_t* device = fDevice.writable_addr32(x, y); + uint32_t* device = fDevice.getAddr32(x, y); uint32_t color = fPMColor; 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[], 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); 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) { - uint32_t* device = fDevice.writable_addr32(x, y); - SkDEBUGCODE((void)fDevice.writable_addr32(x + 1, y);) + uint32_t* device = fDevice.getAddr32(x, y); + SkDEBUGCODE((void)fDevice.getAddr32(x + 1, y);) device[0] = (a0 << SK_A32_SHIFT) + SkAlphaMulQ(device[0], 256 - a0); device[1] = (a1 << SK_A32_SHIFT) + SkAlphaMulQ(device[1], 256 - a1); } void SkARGB32_Black_Blitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) { - uint32_t* device = fDevice.writable_addr32(x, y); - SkDEBUGCODE((void)fDevice.writable_addr32(x, y + 1);) + uint32_t* device = fDevice.getAddr32(x, y); + SkDEBUGCODE((void)fDevice.getAddr32(x, y + 1);) device[0] = (a0 << SK_A32_SHIFT) + SkAlphaMulQ(device[0], 256 - a0); 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) : 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) { 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) { 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 && 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(); SkShader::Context* shaderContext = fShaderContext; 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[], const int16_t runs[]) { SkPMColor* span = fBuffer; - uint32_t* device = fDevice.writable_addr32(x, y); + uint32_t* device = fDevice.getAddr32(x, y); SkShader::Context* shaderContext = fShaderContext; if (fXfermode && !fShadeDirectlyIntoDevice) { @@ -558,7 +558,7 @@ void SkARGB32_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) int y = clip.fTop; 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 uint8_t* maskRow = (const uint8_t*)mask.getAddr(x, y); 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) { 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(); SkShader::Context* shaderContext = fShaderContext; diff --git a/src/core/SkBlitter_RGB16.cpp b/src/core/SkBlitter_RGB16.cpp index 6724b12ace..ed9e103b6d 100644 --- a/src/core/SkBlitter_RGB16.cpp +++ b/src/core/SkBlitter_RGB16.cpp @@ -1,3 +1,4 @@ + /* * Copyright 2006 The Android Open Source Project * @@ -5,6 +6,7 @@ * found in the LICENSE file. */ + #include "SkBlitRow.h" #include "SkCoreBlitters.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 { 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; 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 blitRect(int x, int y, int width, int height) override; - void blitMask(const SkMask&, const SkIRect&) override; - const SkPixmap* justAnOpaqueColor(uint32_t*) override; + virtual void blitMask(const SkMask&, + const SkIRect&) override; + const SkBitmap* justAnOpaqueColor(uint32_t*) override; protected: SkPMColor fSrcColor32; @@ -84,12 +87,14 @@ protected: class SkRGB16_Opaque_Blitter : public SkRGB16_Blitter { 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 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 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: typedef SkRGB16_Blitter INHERITED; @@ -98,9 +103,10 @@ private: #ifdef USE_BLACK_BLITTER class SkRGB16_Black_Blitter : public SkRGB16_Opaque_Blitter { 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 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: typedef SkRGB16_Opaque_Blitter INHERITED; @@ -109,7 +115,7 @@ private: class SkRGB16_Shader_Blitter : public SkShaderBlitter { public: - SkRGB16_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, + SkRGB16_Shader_Blitter(const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext); virtual ~SkRGB16_Shader_Blitter(); void blitH(int x, int y, int width) override; @@ -132,7 +138,7 @@ private: // used only if the shader can perform shadSpan16 class SkRGB16_Shader16_Blitter : public SkRGB16_Shader_Blitter { public: - SkRGB16_Shader16_Blitter(const SkPixmap& device, const SkPaint& paint, + SkRGB16_Shader16_Blitter(const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext); void blitH(int x, int y, int width) override; virtual void blitAntiH(int x, int y, const SkAlpha* antialias, @@ -145,7 +151,7 @@ private: class SkRGB16_Shader_Xfermode_Blitter : public SkShaderBlitter { public: - SkRGB16_Shader_Xfermode_Blitter(const SkPixmap& device, const SkPaint& paint, + SkRGB16_Shader_Xfermode_Blitter(const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext); virtual ~SkRGB16_Shader_Xfermode_Blitter(); void blitH(int x, int y, int width) override; @@ -165,7 +171,7 @@ private: /////////////////////////////////////////////////////////////////////////////// #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) { SkASSERT(paint.getShader() == 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_ARGS #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 #include "SkBlitBWMaskTemplate.h" @@ -211,7 +217,7 @@ void SkRGB16_Black_Blitter::blitMask(const SkMask& mask, if (mask.fFormat == SkMask::kBW_Format) { SkRGB16_Black_BlitBW(fDevice, mask, clip); } 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); unsigned width = clip.width(); 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, const SkAlpha* SK_RESTRICT antialias, 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 (;;) { 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) - : INHERITED(device, paint) {} +SkRGB16_Opaque_Blitter::SkRGB16_Opaque_Blitter(const SkBitmap& device, + const SkPaint& paint) +: INHERITED(device, paint) {} void SkRGB16_Opaque_Blitter::blitH(int x, int y, int width) { SkASSERT(width > 0); 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; SkASSERT(fRawColor16 == srcColor); @@ -300,7 +307,7 @@ static inline int Bool2Int(int value) { void SkRGB16_Opaque_Blitter::blitAntiH(int x, int y, const SkAlpha* SK_RESTRICT antialias, 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; uint32_t srcExpanded = fExpandedRaw16; 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_ARGS , uint16_t 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 #include "SkBlitBWMaskTemplate.h" @@ -382,7 +389,7 @@ void SkRGB16_Opaque_Blitter::blitMask(const SkMask& mask, 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); int width = clip.width(); 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) { - uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); + uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); size_t deviceRB = fDevice.rowBytes(); // 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) { 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(); 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) { SkColor color = paint.getColor(); @@ -554,7 +561,7 @@ SkRGB16_Blitter::SkRGB16_Blitter(const SkPixmap& device, const SkPaint& paint) fColorProc16 = SkBlitRow::ColorFactory16(flags); } -const SkPixmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { +const SkBitmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { if (!fDoDither && 256 == fScale) { *value = fRawColor16; return &fDevice; @@ -565,7 +572,7 @@ const SkPixmap* SkRGB16_Blitter::justAnOpaqueColor(uint32_t* value) { void SkRGB16_Blitter::blitH(int x, int y, int width) { SkASSERT(width > 0); 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); } @@ -573,7 +580,7 @@ void SkRGB16_Blitter::blitH(int x, int y, int width) { void SkRGB16_Blitter::blitAntiH(int x, int y, const SkAlpha* SK_RESTRICT antialias, 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; 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_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_GETADDR writable_addr16 +#define SK_BLITBWMASK_GETADDR getAddr16 #define SK_BLITBWMASK_DEVTYPE uint16_t #include "SkBlitBWMaskTemplate.h" @@ -628,7 +635,7 @@ void SkRGB16_Blitter::blitMask(const SkMask& mask, 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); int width = clip.width(); 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) { - uint16_t* SK_RESTRICT device = fDevice.writable_addr16(x, y); + uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y); size_t deviceRB = fDevice.rowBytes(); // 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) { 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(); 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, SkShader::Context* shaderContext) - : SkRGB16_Shader_Blitter(device, paint, shaderContext) -{ + : SkRGB16_Shader_Blitter(device, paint, shaderContext) { SkASSERT(SkShader::CanCallShadeSpan16(fShaderFlags)); } void SkRGB16_Shader16_Blitter::blitH(int x, int y, int 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; 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) { SkShader::Context* shaderContext = fShaderContext; - uint16_t* dst = fDevice.writable_addr16(x, y); + uint16_t* dst = fDevice.getAddr16(x, y); size_t dstRB = fDevice.rowBytes(); int alpha = shaderContext->getSpan16Alpha(); @@ -753,7 +759,7 @@ void SkRGB16_Shader16_Blitter::blitAntiH(int x, int y, const int16_t* SK_RESTRICT runs) { SkShader::Context* shaderContext = fShaderContext; 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(); 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, SkShader::Context* shaderContext) - : INHERITED(device, paint, shaderContext) -{ +: INHERITED(device, paint, shaderContext) { SkASSERT(paint.getXfermode() == NULL); 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); // 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) { SkShader::Context* shaderContext = fShaderContext; SkBlitRow::Proc16 proc = fOpaqueProc; SkPMColor* buffer = fBuffer; - uint16_t* dst = fDevice.writable_addr16(x, y); + uint16_t* dst = fDevice.getAddr16(x, y); size_t dstRB = fDevice.rowBytes(); if (fShaderFlags & SkShader::kConstInY32_Flag) { @@ -886,7 +891,7 @@ void SkRGB16_Shader_Blitter::blitAntiH(int x, int y, const int16_t* SK_RESTRICT runs) { SkShader::Context* shaderContext = fShaderContext; 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 (;;) { int count = *runs; @@ -932,10 +937,9 @@ void SkRGB16_Shader_Blitter::blitAntiH(int x, int y, /////////////////////////////////////////////////////////////////////// SkRGB16_Shader_Xfermode_Blitter::SkRGB16_Shader_Xfermode_Blitter( - const SkPixmap& device, const SkPaint& paint, + const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext) - : INHERITED(device, paint, shaderContext) -{ +: INHERITED(device, paint, shaderContext) { fXfermode = paint.getXfermode(); SkASSERT(fXfermode); 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) { SkASSERT(x + width <= fDevice.width()); - uint16_t* device = fDevice.writable_addr16(x, y); + uint16_t* device = fDevice.getAddr16(x, y); SkPMColor* span = fBuffer; fShaderContext->shadeSpan(x, y, span, width); @@ -967,7 +971,7 @@ void SkRGB16_Shader_Xfermode_Blitter::blitAntiH(int x, int y, SkXfermode* mode = fXfermode; SkPMColor* SK_RESTRICT span = fBuffer; 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 (;;) { 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, SkTBlitterAllocator* allocator) { SkASSERT(allocator != NULL); diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 056a4e96d2..26b76df9be 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -271,9 +271,7 @@ public: fClip = &((SkRasterClip*)&rec->fClip)->forceGetBW(); fRC = &rec->fClip; fDevice = rec->fDevice; - if (!fDevice->accessPixels(&fDst)) { - fDst.reset(fDevice->imageInfo(), NULL, 0); - } + fBitmap = &fDevice->accessBitmap(true); fPaint = rec->fPaint; SkDEBUGCODE(this->validate();) diff --git a/src/core/SkCoreBlitters.h b/src/core/SkCoreBlitters.h index 31f33979db..18821dc0d1 100644 --- a/src/core/SkCoreBlitters.h +++ b/src/core/SkCoreBlitters.h @@ -16,10 +16,10 @@ class SkRasterBlitter : public SkBlitter { public: - SkRasterBlitter(const SkPixmap& device) : fDevice(device) {} + SkRasterBlitter(const SkBitmap& device) : fDevice(device) {} protected: - const SkPixmap fDevice; + const SkBitmap& fDevice; private: typedef SkBlitter INHERITED; @@ -32,7 +32,7 @@ public: * The blitter only ensures that the storage always holds a live object, but it may * exchange that object. */ - SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, + SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext); virtual ~SkShaderBlitter(); @@ -61,24 +61,24 @@ private: class SkA8_Coverage_Blitter : public SkRasterBlitter { 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 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 blitRect(int x, int y, int width, int height) 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 { 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 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 blitRect(int x, int y, int width, int height); virtual void blitMask(const SkMask&, const SkIRect&); - virtual const SkPixmap* justAnOpaqueColor(uint32_t*); + virtual const SkBitmap* justAnOpaqueColor(uint32_t*); private: unsigned fSrcA; @@ -91,7 +91,7 @@ private: class SkA8_Shader_Blitter : public SkShaderBlitter { public: - SkA8_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, + SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext); virtual ~SkA8_Shader_Blitter(); virtual void blitH(int x, int y, int width); @@ -113,13 +113,13 @@ private: class SkARGB32_Blitter : public SkRasterBlitter { 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 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 blitRect(int x, int y, int width, int height); 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 blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; @@ -138,7 +138,7 @@ private: class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter { 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); } virtual void blitMask(const SkMask&, const SkIRect&); void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; @@ -150,7 +150,7 @@ private: class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter { public: - SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint) + SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint) : INHERITED(device, paint) {} 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; @@ -162,7 +162,7 @@ private: class SkARGB32_Shader_Blitter : public SkShaderBlitter { public: - SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, + SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext); virtual ~SkARGB32_Shader_Blitter(); void blitH(int x, int y, int width) override; @@ -200,7 +200,7 @@ private: SkBlitter::Choose(...) */ -SkBlitter* SkBlitter_ChooseD565(const SkPixmap& device, const SkPaint& paint, +SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint, SkShader::Context* shaderContext, SkTBlitterAllocator* allocator); diff --git a/src/core/SkDeviceLooper.cpp b/src/core/SkDeviceLooper.cpp index 840a050436..a8350cc027 100644 --- a/src/core/SkDeviceLooper.cpp +++ b/src/core/SkDeviceLooper.cpp @@ -7,16 +7,17 @@ #include "SkDeviceLooper.h" -SkDeviceLooper::SkDeviceLooper(const SkPixmap& base, const SkRasterClip& rc, const SkIRect& bounds, - bool aa) - : fBaseDst(base) +SkDeviceLooper::SkDeviceLooper(const SkBitmap& base, + const SkRasterClip& rc, + const SkIRect& bounds, bool aa) + : fBaseBitmap(base) , fBaseRC(rc) , fSubsetRC(rc.isForceConservativeRects()) , fDelta(aa ? kAA_Delta : kBW_Delta) { // sentinels that next() has not yet been called, and so our mapper functions // should not be called either. - fCurrDst = NULL; + fCurrBitmap = NULL; fCurrRC = NULL; 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 { SkASSERT(kDone_State != fState); - SkASSERT(fCurrDst); + SkASSERT(fCurrBitmap); SkASSERT(fCurrRC); *dst = src; @@ -51,11 +53,12 @@ void SkDeviceLooper::mapRect(SkRect* dst, const SkRect& src) const { void SkDeviceLooper::mapMatrix(SkMatrix* dst, const SkMatrix& src) const { SkASSERT(kDone_State != fState); - SkASSERT(fCurrDst); + SkASSERT(fCurrBitmap); SkASSERT(fCurrRC); *dst = src; - dst->postTranslate(SkIntToScalar(-fCurrOffset.fX), SkIntToScalar(-fCurrOffset.fY)); + dst->postTranslate(SkIntToScalar(-fCurrOffset.fX), + SkIntToScalar(-fCurrOffset.fY)); } bool SkDeviceLooper::computeCurrBitmapAndClip() { @@ -63,14 +66,16 @@ bool SkDeviceLooper::computeCurrBitmapAndClip() { SkIRect r = SkIRect::MakeXYWH(fCurrOffset.x(), fCurrOffset.y(), fDelta, fDelta); - if (!fBaseDst.extractSubset(&fSubsetDst, r)) { + if (!fBaseBitmap.extractSubset(&fSubsetBitmap, r)) { fSubsetRC.setEmpty(); } else { + fSubsetBitmap.lockPixels(); 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; return !fCurrRC->isEmpty(); } @@ -102,8 +107,8 @@ bool SkDeviceLooper::next() { case kSimple_State: // first time for simple - if (NULL == fCurrDst) { - fCurrDst = &fBaseDst; + if (NULL == fCurrBitmap) { + fCurrBitmap = &fBaseBitmap; fCurrRC = &fBaseRC; fCurrOffset.set(0, 0); return true; diff --git a/src/core/SkDeviceLooper.h b/src/core/SkDeviceLooper.h index dd346d7445..a218345ae8 100644 --- a/src/core/SkDeviceLooper.h +++ b/src/core/SkDeviceLooper.h @@ -30,13 +30,14 @@ */ class SkDeviceLooper { public: - SkDeviceLooper(const SkPixmap& base, const SkRasterClip&, const SkIRect& bounds, bool aa); + SkDeviceLooper(const SkBitmap& base, const SkRasterClip&, + const SkIRect& bounds, bool aa); ~SkDeviceLooper(); - const SkPixmap& getPixmap() const { + const SkBitmap& getBitmap() const { SkASSERT(kDone_State != fState); - SkASSERT(fCurrDst); - return *fCurrDst; + SkASSERT(fCurrBitmap); + return *fCurrBitmap; } const SkRasterClip& getRC() const { @@ -60,7 +61,7 @@ public: bool next(); private: - const SkPixmap& fBaseDst; + const SkBitmap& fBaseBitmap; const SkRasterClip& fBaseRC; enum State { @@ -70,10 +71,10 @@ private: }; // storage for our tiled versions. Perhaps could use SkTLazy - SkPixmap fSubsetDst; + SkBitmap fSubsetBitmap; SkRasterClip fSubsetRC; - const SkPixmap* fCurrDst; + const SkBitmap* fCurrBitmap; const SkRasterClip* fCurrRC; SkIRect fClippedBounds; SkIPoint fCurrOffset; diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 0069087a92..ac69680811 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -44,18 +44,20 @@ public: SkAutoBlitterChoose() { fBlitter = NULL; } - SkAutoBlitterChoose(const SkPixmap& dst, const SkMatrix& matrix, + SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix, 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* 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) { SkASSERT(!fBlitter); - fBlitter = SkBlitter::Choose(dst, matrix, paint, &fAllocator, drawCoverage); + fBlitter = SkBlitter::Choose(device, matrix, paint, &fAllocator, + drawCoverage); } private: @@ -150,7 +152,8 @@ static void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { 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) { // todo: we can apply colorfilter up front if no shader, so we wouldn't // 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? */ SkPMColor pmc = SkPreMultiplyColor(color); - switch (dst.colorType()) { + switch (bitmap.colorType()) { case kN32_SkColorType: if (data) { *data = pmc; @@ -217,10 +220,10 @@ static BitmapXferProc ChooseBitmapXferProc(const SkPixmap& dst, const SkPaint& p return NULL; } -static void CallBitmapXferProc(const SkPixmap& dst, const SkIRect& rect, BitmapXferProc proc, - uint32_t procData) { +static void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect, + BitmapXferProc proc, uint32_t procData) { int shiftPerPixel; - switch (dst.colorType()) { + switch (bitmap.colorType()) { case kN32_SkColorType: shiftPerPixel = 2; break; @@ -235,9 +238,9 @@ static void CallBitmapXferProc(const SkPixmap& dst, const SkIRect& rect, BitmapX return; } - uint8_t* pixels = (uint8_t*)dst.writable_addr(); + uint8_t* pixels = (uint8_t*)bitmap.getPixels(); SkASSERT(pixels); - const size_t rowBytes = dst.rowBytes(); + const size_t rowBytes = bitmap.rowBytes(); const int widthBytes = rect.width() << shiftPerPixel; // skip down to the first scanline and X position @@ -256,7 +259,7 @@ void SkDraw::drawPaint(const SkPaint& paint) const { } SkIRect devRect; - devRect.set(0, 0, fDst.width(), fDst.height()); + devRect.set(0, 0, fBitmap->width(), fBitmap->height()); if (fRC->isBW()) { /* 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. */ uint32_t procData = 0; // to avoid the warning - BitmapXferProc proc = ChooseBitmapXferProc(fDst, paint, &procData); + BitmapXferProc proc = ChooseBitmapXferProc(*fBitmap, paint, &procData); if (proc) { if (D_Dst_BitmapXferProc == proc) { // nothing to do return; @@ -274,7 +277,7 @@ void SkDraw::drawPaint(const SkPaint& paint) const { SkRegion::Iterator iter(fRC->bwRgn()); while (!iter.done()) { - CallBitmapXferProc(fDst, iter.rect(), proc, procData); + CallBitmapXferProc(*fBitmap, iter.rect(), proc, procData); iter.next(); } return; @@ -282,7 +285,7 @@ void SkDraw::drawPaint(const SkPaint& paint) const { } // normal case: use a blitter - SkAutoBlitterChoose blitter(fDst, *fMatrix, paint); + SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); 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()); const SkIRect& r = rec.fRC->getBounds(); uint32_t value; - const SkPixmap* dst = blitter->justAnOpaqueColor(&value); - SkASSERT(dst); + const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value); + SkASSERT(bitmap); - uint16_t* addr = dst->writable_addr16(0, 0); - size_t rb = dst->rowBytes(); + uint16_t* addr = bitmap->getAddr16(0, 0); + size_t rb = bitmap->rowBytes(); for (int i = 0; i < count; i++) { 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()); const SkIRect& r = rec.fRC->getBounds(); uint32_t value; - const SkPixmap* dst = blitter->justAnOpaqueColor(&value); - SkASSERT(dst); + const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value); + SkASSERT(bitmap); - SkPMColor* addr = dst->writable_addr32(0, 0); - size_t rb = dst->rowBytes(); + SkPMColor* addr = bitmap->getAddr32(0, 0); + size_t rb = bitmap->rowBytes(); for (int i = 0; i < count; i++) { 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 (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) { uint32_t value; - const SkPixmap* bm = blitter->justAnOpaqueColor(&value); + const SkBitmap* bm = blitter->justAnOpaqueColor(&value); if (bm && kRGB_565_SkColorType == bm->colorType()) { proc = bw_pt_rect_16_hair_proc; } else if (bm && kN32_SkColorType == bm->colorType()) { @@ -556,7 +559,7 @@ void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count, PtProcRec rec; if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) { - SkAutoBlitterChoose blitter(fDst, *fMatrix, paint); + SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); SkPoint devPts[MAX_DEV_PTS]; const SkMatrix* matrix = fMatrix; @@ -850,14 +853,14 @@ void SkDraw::drawRect(const SkRect& prePaintRect, const SkPaint& paint, return; } - SkDeviceLooper looper(fDst, *fRC, ir, paint.isAntiAlias()); + SkDeviceLooper looper(*fBitmap, *fRC, ir, paint.isAntiAlias()); while (looper.next()) { SkRect localDevRect; looper.mapRect(&localDevRect, devRect); SkMatrix localMatrix; looper.mapMatrix(&localMatrix, *matrix); - SkAutoBlitterChoose blitterStorage(looper.getPixmap(), localMatrix, paint); + SkAutoBlitterChoose blitterStorage(looper.getBitmap(), localMatrix, paint); const SkRasterClip& clip = looper.getRC(); SkBlitter* blitter = blitterStorage.get(); @@ -908,7 +911,7 @@ void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const { } SkAutoMaskFreeImage ami(dstM.fImage); - SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); + SkAutoBlitterChoose blitterChooser(*fBitmap, *fMatrix, paint); SkBlitter* blitter = blitterChooser.get(); SkAAClipBlitterWrapper wrapper; @@ -986,7 +989,7 @@ void SkDraw::drawRRect(const SkRRect& rrect, const SkPaint& paint) const { // Transform the rrect into device space. SkRRect 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(), SkPaint::kFill_Style)) { 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; SkAutoBlitterChoose blitterStorage; if (NULL == customBlitter) { - blitterStorage.choose(fDst, *fMatrix, *paint, drawCoverage); + blitterStorage.choose(*fBitmap, *fMatrix, *paint, drawCoverage); blitter = blitterStorage.get(); } else { blitter = customBlitter; @@ -1179,7 +1182,7 @@ void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, // clipped to the actual device { 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 if (!mask.fBounds.intersect(devBounds)) { return; @@ -1277,9 +1280,13 @@ void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, int ix = SkScalarRoundToInt(matrix.getTranslateX()); int iy = SkScalarRoundToInt(matrix.getTranslateY()); if (clipHandlesSprite(*fRC, ix, iy, pmap)) { + SkPixmap dstPM; + if (!fBitmap->peekPixels(&dstPM)) { + return; + } SkTBlitterAllocator 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) { SkScan::FillIRect(SkIRect::MakeXYWH(ix, iy, pmap.width(), pmap.height()), *fRC, blitter); @@ -1334,9 +1341,13 @@ void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& ori const SkPixmap& pmap = unlocker.pixmap(); if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, pmap)) { + SkPixmap dstPM; + if (!fBitmap->peekPixels(&dstPM)) { + return; + } SkTBlitterAllocator 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) { SkScan::FillIRect(bounds, *fRC, blitter); return; @@ -1635,7 +1646,7 @@ void SkDraw::drawText(const char text[], size_t byteLength, SkAutoBlitterChoose blitterChooser; SkBlitter* blitter = NULL; if (needsRasterTextBlit(*this)) { - blitterChooser.choose(fDst, *fMatrix, paint); + blitterChooser.choose(*fBitmap, *fMatrix, paint); blitter = blitterChooser.get(); if (fRC->isAA()) { aaBlitter.init(blitter, &fRC->aaRgn()); @@ -1754,7 +1765,7 @@ void SkDraw::drawPosText(const char text[], size_t byteLength, SkAutoBlitterChoose blitterChooser; SkBlitter* blitter = NULL; if (needsRasterTextBlit(*this)) { - blitterChooser.choose(fDst, *fMatrix, paint); + blitterChooser.choose(*fBitmap, *fMatrix, paint); blitter = blitterChooser.get(); if (fRC->isAA()) { 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. if (blitter->isNullBlitter()) { return; @@ -2155,6 +2166,7 @@ void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, #ifdef SK_DEBUG void SkDraw::validate() const { + SkASSERT(fBitmap != NULL); SkASSERT(fMatrix != NULL); SkASSERT(fClip != NULL); SkASSERT(fRC != NULL); @@ -2162,7 +2174,7 @@ void SkDraw::validate() const { const SkIRect& cr = fRC->getBounds(); SkIRect br; - br.set(0, 0, fDst.width(), fDst.height()); + br.set(0, 0, fBitmap->width(), fBitmap->height()); SkASSERT(cr.isEmpty() || br.contains(cr)); } @@ -2218,20 +2230,22 @@ static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds, return true; } -static void draw_into_mask(const SkMask& mask, const SkPath& devPath, SkPaint::Style style) { - SkDraw draw; - if (!draw.fDst.reset(mask)) { - return; - } - +static void draw_into_mask(const SkMask& mask, const SkPath& devPath, + SkPaint::Style style) { + SkBitmap bm; + SkDraw draw; SkRasterClip clip; SkMatrix matrix; 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())); matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), -SkIntToScalar(mask.fBounds.fTop)); + draw.fBitmap = &bm; draw.fRC = &clip; draw.fClip = &clip.bwRgn(); draw.fMatrix = &matrix; diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index 4ce42ddc07..7747cae0df 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -248,7 +248,7 @@ static void applyLUTToA8Mask(const SkMask& mask, const uint8_t* lut) { } template -static void pack4xHToLCD16(const SkPixmap& src, const SkMask& dst, +static void pack4xHToLCD16(const SkBitmap& src, const SkMask& dst, const SkMaskGamma::PreBlend& maskPreBlend) { #define SAMPLES_PER_PIXEL 4 #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) { - 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. // 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)); const SkImageInfo info = SkImageInfo::MakeA8(dstW, dstH); - SkAutoPixmapStorage dst; + SkBitmap bm; if (0 == dstRB) { - if (!dst.tryAlloc(info)) { + if (!bm.tryAllocPixels(info)) { // can't allocate offscreen, so empty the mask and return sk_bzero(mask.fImage, mask.computeImageSize()); return; } } 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; - draw.fDst = dst; draw.fRC = &clip; draw.fClip = &clip.bwRgn(); draw.fMatrix = &matrix; + draw.fBitmap = &bm; draw.drawPath(path, paint); switch (mask.fFormat) { case SkMask::kBW_Format: - packA8ToA1(mask, dst.addr8(0, 0), dst.rowBytes()); + packA8ToA1(mask, bm.getAddr8(0, 0), bm.rowBytes()); break; case SkMask::kA8_Format: if (maskPreBlend.isApplicable()) { @@ -437,9 +437,9 @@ static void generateMask(const SkMask& mask, const SkPath& path, break; case SkMask::kLCD16_Format: if (maskPreBlend.isApplicable()) { - pack4xHToLCD16(dst, mask, maskPreBlend); + pack4xHToLCD16(bm, mask, maskPreBlend); } else { - pack4xHToLCD16(dst, mask, maskPreBlend); + pack4xHToLCD16(bm, mask, maskPreBlend); } break; default: diff --git a/src/core/SkScan_Path.cpp b/src/core/SkScan_Path.cpp index b7db3b410d..9b4b9fd897 100644 --- a/src/core/SkScan_Path.cpp +++ b/src/core/SkScan_Path.cpp @@ -344,7 +344,7 @@ public: void blitMask(const SkMask&, const SkIRect& clip) override { SkDEBUGFAIL("blitMask unexpected"); } - const SkPixmap* justAnOpaqueColor(uint32_t* value) override { + const SkBitmap* justAnOpaqueColor(uint32_t* value) override { SkDEBUGFAIL("justAnOpaqueColor unexpected"); return NULL; } diff --git a/src/effects/SkLayerRasterizer.cpp b/src/effects/SkLayerRasterizer.cpp index 8403d06147..d3e112c3a4 100644 --- a/src/effects/SkLayerRasterizer.cpp +++ b/src/effects/SkLayerRasterizer.cpp @@ -116,12 +116,9 @@ bool SkLayerRasterizer::onRasterize(const SkPath& path, const SkMatrix& matrix, } if (SkMask::kJustComputeBounds_CreateMode != mode) { - SkDraw draw; - if (!draw.fDst.reset(*mask)) { - return false; - } - + SkBitmap device; SkRasterClip rectClip; + SkDraw draw; SkMatrix translatedMatrix; // this translates us to our local pixels 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), -SkIntToScalar(mask->fBounds.fTop)); + device.installMaskPixels(*mask); + + draw.fBitmap = &device; draw.fMatrix = &drawMatrix; draw.fRC = &rectClip; draw.fClip = &rectClip.bwRgn(); diff --git a/src/gpu/GrAADistanceFieldPathRenderer.cpp b/src/gpu/GrAADistanceFieldPathRenderer.cpp index 3c7648aae3..21fbcb37fb 100755 --- a/src/gpu/GrAADistanceFieldPathRenderer.cpp +++ b/src/gpu/GrAADistanceFieldPathRenderer.cpp @@ -354,12 +354,14 @@ private: SkIRect pathBounds = SkIRect::MakeWH(devPathBounds.width(), devPathBounds.height()); - SkAutoPixmapStorage dst; - if (!dst.tryAlloc(SkImageInfo::MakeA8(pathBounds.width(), - pathBounds.height()))) { + SkBitmap bmp; + const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(pathBounds.fRight, + pathBounds.fBottom); + if (!bmp.tryAllocPixels(bmImageInfo)) { return false; } - sk_bzero(dst.writable_addr(), dst.getSafeSize()); + + sk_bzero(bmp.getPixels(), bmp.getSafeSize()); // rasterize path SkPaint paint; @@ -386,7 +388,7 @@ private: draw.fRC = &rasterClip; draw.fClip = &rasterClip.bwRgn(); draw.fMatrix = &drawMatrix; - draw.fDst = dst; + draw.fBitmap = &bmp; draw.drawPathCoverage(path, paint); @@ -398,9 +400,13 @@ private: SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char)); // Generate signed distance field - SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), - (const unsigned char*)dst.addr(), - dst.width(), dst.height(), dst.rowBytes()); + { + SkAutoLockPixels alp(bmp); + + SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), + (const unsigned char*)bmp.getPixels(), + bmp.width(), bmp.height(), bmp.rowBytes()); + } // add to atlas SkIPoint16 atlasLocation; diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp index 9b9865e92b..c13d2d839d 100644 --- a/src/gpu/GrSWMaskHelper.cpp +++ b/src/gpu/GrSWMaskHelper.cpp @@ -146,8 +146,7 @@ void GrSWMaskHelper::draw(const SkPath& path, const SkStrokeRec& stroke, SkRegio if (kBlitter_CompressionMode == fCompressionMode) { SkASSERT(fCompressedBuffer.get()); blitter = SkTextureCompressor::CreateBlitterForFormat( - fPixels.width(), fPixels.height(), fCompressedBuffer.get(), &allocator, - fCompressedFormat); + fBM.width(), fBM.height(), fCompressedBuffer.get(), &allocator, fCompressedFormat); } 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 // from or a bitmap that we're going to use as a texture. In any case, we should // allocate the pixels for a bitmap const SkImageInfo bmImageInfo = SkImageInfo::MakeA8(cmpWidth, cmpHeight); if (kBlitter_CompressionMode != fCompressionMode) { - if (!fPixels.tryAlloc(bmImageInfo)) { + if (!fBM.tryAllocPixels(bmImageInfo)) { return false; } - fPixels.erase(0); + + sk_bzero(fBM.getPixels(), fBM.getSafeSize()); } else { // 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); - fDraw.fRC = &fRasterClip; - fDraw.fClip = &fRasterClip.bwRgn(); - fDraw.fMatrix = &fMatrix; + fDraw.fRC = &fRasterClip; + fDraw.fClip = &fRasterClip.bwRgn(); + fDraw.fMatrix = &fMatrix; + fDraw.fBitmap = &fBM; return true; } @@ -231,8 +232,8 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds, */ GrTexture* GrSWMaskHelper::createTexture() { GrSurfaceDesc desc; - desc.fWidth = fPixels.width(); - desc.fHeight = fPixels.height(); + desc.fWidth = fBM.width(); + desc.fHeight = fBM.height(); desc.fConfig = kAlpha_8_GrPixelConfig; if (kNone_CompressionMode != fCompressionMode) { @@ -272,8 +273,7 @@ void GrSWMaskHelper::compressTextureData(GrTexture *texture, const GrSurfaceDesc SkASSERT(GrPixelConfigIsCompressed(desc.fConfig)); SkASSERT(fmt_to_config(fCompressedFormat) == desc.fConfig); - SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fPixels, - fCompressedFormat)); + SkAutoDataUnref cmpData(SkTextureCompressor::CompressBitmapToFormat(fBM, fCompressedFormat)); SkASSERT(cmpData); 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 */ void GrSWMaskHelper::toTexture(GrTexture *texture) { + SkAutoLockPixels alp(fBM); + GrSurfaceDesc desc; - desc.fWidth = fPixels.width(); - desc.fHeight = fPixels.height(); + desc.fWidth = fBM.width(); + desc.fHeight = fBM.height(); desc.fConfig = texture->config(); // First see if we should compress this texture before uploading. switch (fCompressionMode) { case kNone_CompressionMode: - this->sendTextureData(texture, desc, fPixels.addr(), fPixels.rowBytes()); + this->sendTextureData(texture, desc, fBM.getPixels(), fBM.rowBytes()); break; case kCompress_CompressionMode: @@ -309,8 +311,10 @@ void GrSWMaskHelper::toTexture(GrTexture *texture) { * Convert mask generation results to a signed distance field */ void GrSWMaskHelper::toSDF(unsigned char* sdf) { - SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fPixels.addr(), - fPixels.width(), fPixels.height(), fPixels.rowBytes()); + SkAutoLockPixels alp(fBM); + + SkGenerateDistanceFieldFromA8Image(sdf, (const unsigned char*)fBM.getPixels(), + fBM.width(), fBM.height(), fBM.rowBytes()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/GrSWMaskHelper.h b/src/gpu/GrSWMaskHelper.h index b90205b1a1..a69e4bec99 100644 --- a/src/gpu/GrSWMaskHelper.h +++ b/src/gpu/GrSWMaskHelper.h @@ -69,7 +69,7 @@ public: // Reset the internal bitmap 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 @@ -105,7 +105,7 @@ private: GrContext* fContext; SkMatrix fMatrix; - SkAutoPixmapStorage fPixels; + SkBitmap fBM; SkDraw fDraw; SkRasterClip fRasterClip; diff --git a/src/utils/SkTextureCompressor.cpp b/src/utils/SkTextureCompressor.cpp index 9d29d51d60..12621e118f 100644 --- a/src/utils/SkTextureCompressor.cpp +++ b/src/utils/SkTextureCompressor.cpp @@ -173,17 +173,19 @@ bool CompressBufferToFormat(uint8_t* dst, const uint8_t* src, SkColorType srcCol return false; } -SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) { - int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixmap.height()); +SkData* CompressBitmapToFormat(const SkBitmap &bitmap, Format format) { + SkAutoLockPixels alp(bitmap); + + int compressedDataSize = GetCompressedDataSize(format, bitmap.width(), bitmap.height()); if (compressedDataSize < 0) { return NULL; } - const uint8_t* src = reinterpret_cast(pixmap.addr()); + const uint8_t* src = reinterpret_cast(bitmap.getPixels()); SkData* dst = SkData::NewUninitialized(compressedDataSize); - if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, pixmap.colorType(), - pixmap.width(), pixmap.height(), pixmap.rowBytes(), format)) { + if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, bitmap.colorType(), + bitmap.width(), bitmap.height(), bitmap.rowBytes(), format)) { dst->unref(); dst = NULL; } diff --git a/src/utils/SkTextureCompressor.h b/src/utils/SkTextureCompressor.h index e31a5ab48d..e35bc957ac 100644 --- a/src/utils/SkTextureCompressor.h +++ b/src/utils/SkTextureCompressor.h @@ -55,10 +55,10 @@ namespace SkTextureCompressor { int GetCompressedDataSize(Format fmt, int width, int height); // 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 // 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 // large enough to hold width*height pixels. The dst data is expected to diff --git a/src/utils/SkTextureCompressor_Blitter.h b/src/utils/SkTextureCompressor_Blitter.h index e52237518f..73d8ee4ffb 100644 --- a/src/utils/SkTextureCompressor_Blitter.h +++ b/src/utils/SkTextureCompressor_Blitter.h @@ -368,7 +368,7 @@ public: // 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 // the value parameter. - const SkPixmap* justAnOpaqueColor(uint32_t* value) override { + const SkBitmap* justAnOpaqueColor(uint32_t* value) override { return NULL; } diff --git a/tests/DeviceLooperTest.cpp b/tests/DeviceLooperTest.cpp index 1a51b58980..5735043074 100644 --- a/tests/DeviceLooperTest.cpp +++ b/tests/DeviceLooperTest.cpp @@ -9,8 +9,9 @@ #include "SkRasterClip.h" #include "Test.h" -static void make_pm(SkAutoPixmapStorage* pixmap, int w, int h) { - pixmap->alloc(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, kPremul_SkAlphaType)); +static void make_bm(SkBitmap* bm, int w, int h) { + bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, + kPremul_SkAlphaType)); } static bool equal(const SkRasterClip& a, const SkRasterClip& b) { @@ -39,19 +40,19 @@ static const struct { static void test_simple(skiatest::Reporter* reporter) { for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { - SkAutoPixmapStorage pmap; - make_pm(&pmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height()); + SkBitmap bitmap; + make_bm(&bitmap, gRec[i].fDevSize.width(), gRec[i].fDevSize.height()); SkRasterClip rc(gRec[i].fRCBounds); 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(); REPORTER_ASSERT(reporter, valid); if (valid) { - REPORTER_ASSERT(reporter, looper.getPixmap().width() == pmap.width()); - REPORTER_ASSERT(reporter, looper.getPixmap().height() == pmap.height()); + REPORTER_ASSERT(reporter, looper.getBitmap().width() == bitmap.width()); + REPORTER_ASSERT(reporter, looper.getBitmap().height() == bitmap.height()); REPORTER_ASSERT(reporter, equal(looper.getRC(), rc)); REPORTER_ASSERT(reporter, !looper.next()); @@ -61,7 +62,7 @@ static void test_simple(skiatest::Reporter* reporter) { { SkIRect r = rc.getBounds(); r.offset(r.width(), 0); - SkDeviceLooper looper(pmap, rc, r, false); + SkDeviceLooper looper(bitmap, rc, r, false); 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 h = gRec[i].fSize.height(); - SkAutoPixmapStorage pmap; - make_pm(&pmap, w, h); + SkBitmap bitmap; + make_bm(&bitmap, w, h); const SkIRect rect = SkIRect::MakeWH(w, h); @@ -124,7 +125,7 @@ static void test_complex(skiatest::Reporter* reporter) { SkRasterClip rc; 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()) { REPORTER_ASSERT(reporter, !looper.getRC().isEmpty()); } diff --git a/tests/TextureCompressionTest.cpp b/tests/TextureCompressionTest.cpp index ca8da28858..568d4d14b6 100644 --- a/tests/TextureCompressionTest.cpp +++ b/tests/TextureCompressionTest.cpp @@ -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. */ DEF_TEST(CompressAlphaFailDimensions, reporter) { + SkBitmap bitmap; static const int kWidth = 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 // 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, kHeight % 4 != 0); - SkAutoPixmapStorage pixmap; - pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); - // leaving the pixels uninitialized, as they don't affect the test... + bool setInfoSuccess = bitmap.setInfo(info); + REPORTER_ASSERT(reporter, setInfoSuccess); + + bitmap.allocPixels(info); + bitmap.unlockPixels(); for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { const SkTextureCompressor::Format fmt = static_cast(i); if (!compresses_a8(fmt)) { continue; } - SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); + SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); REPORTER_ASSERT(reporter, NULL == data); } } @@ -72,8 +76,10 @@ DEF_TEST(CompressAlphaFailDimensions, reporter) { * compressed textures can (currently) only be created from A8 bitmaps. */ DEF_TEST(CompressAlphaFailColorType, reporter) { + SkBitmap bitmap; static const int kWidth = 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 // 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, kHeight % 12 == 0); - SkAutoPixmapStorage pixmap; - pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight)); - // leaving the pixels uninitialized, as they don't affect the test... + bool setInfoSuccess = bitmap.setInfo(info); + REPORTER_ASSERT(reporter, setInfoSuccess); + + bitmap.allocPixels(info); + bitmap.unlockPixels(); for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { const SkTextureCompressor::Format fmt = static_cast(i); if (!compresses_a8(fmt)) { continue; } - SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); + SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); REPORTER_ASSERT(reporter, NULL == data); } } @@ -101,8 +109,10 @@ DEF_TEST(CompressAlphaFailColorType, reporter) { * then decompress it, you get what you started with. */ DEF_TEST(CompressCheckerboard, reporter) { + SkBitmap bitmap; 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). + SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); // 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 @@ -113,12 +123,17 @@ DEF_TEST(CompressCheckerboard, reporter) { REPORTER_ASSERT(reporter, kWidth % 48 == 0); REPORTER_ASSERT(reporter, kHeight % 48 == 0); - SkAutoPixmapStorage pixmap; - pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); + bool setInfoSuccess = bitmap.setInfo(info); + REPORTER_ASSERT(reporter, setInfoSuccess); - // Populate the pixels + bitmap.allocPixels(info); + bitmap.unlockPixels(); + + // Populate bitmap { - uint8_t* pixels = reinterpret_cast(pixmap.writable_addr()); + SkAutoLockPixels alp(bitmap); + + uint8_t* pixels = reinterpret_cast(bitmap.getPixels()); REPORTER_ASSERT(reporter, pixels); if (NULL == pixels) { return; @@ -132,7 +147,7 @@ DEF_TEST(CompressCheckerboard, reporter) { pixels[x] = 0; } } - pixels += pixmap.rowBytes(); + pixels += bitmap.rowBytes(); } } @@ -152,7 +167,7 @@ DEF_TEST(CompressCheckerboard, reporter) { continue; } - SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap, fmt)); + SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap, fmt)); REPORTER_ASSERT(reporter, data); if (NULL == data) { continue; @@ -165,7 +180,8 @@ DEF_TEST(CompressCheckerboard, reporter) { kWidth, kHeight, fmt); REPORTER_ASSERT(reporter, decompResult); - const uint8_t* pixels = reinterpret_cast(pixmap.addr()); + SkAutoLockPixels alp(bitmap); + uint8_t* pixels = reinterpret_cast(bitmap.getPixels()); REPORTER_ASSERT(reporter, pixels); if (NULL == pixels) { continue; @@ -173,7 +189,7 @@ DEF_TEST(CompressCheckerboard, reporter) { for (int y = 0; y < kHeight; ++y) { 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); } } @@ -188,11 +204,16 @@ DEF_TEST(CompressLATC, reporter) { const SkTextureCompressor::Format kLATCFormat = SkTextureCompressor::kLATC_Format; static const int kLATCEncodedBlockSize = 8; + SkBitmap bitmap; static const int kWidth = 8; static const int kHeight = 8; + SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); - SkAutoPixmapStorage pixmap; - pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); + bool setInfoSuccess = bitmap.setInfo(info); + REPORTER_ASSERT(reporter, setInfoSuccess); + + bitmap.allocPixels(info); + bitmap.unlockPixels(); int latcDimX, latcDimY; SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY); @@ -205,13 +226,21 @@ DEF_TEST(CompressLATC, reporter) { REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0); for (int lum = 0; lum < 256; ++lum) { - uint8_t* pixels = reinterpret_cast(pixmap.writable_addr()); + bitmap.lockPixels(); + uint8_t* pixels = reinterpret_cast(bitmap.getPixels()); + REPORTER_ASSERT(reporter, pixels); + if (NULL == pixels) { + bitmap.unlockPixels(); + continue; + } + for (int i = 0; i < kWidth*kHeight; ++i) { pixels[i] = lum; } + bitmap.unlockPixels(); SkAutoDataUnref latcData( - SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat)); + SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); REPORTER_ASSERT(reporter, latcData); if (NULL == latcData) { continue;