diff options
author | 2015-06-08 19:58:07 -0700 | |
---|---|---|
committer | 2015-06-08 19:58:07 -0700 | |
commit | b3f0ec9f9967da2f80f0d842cb7fd53617b48de3 (patch) | |
tree | f00f2095e30e48180a2a3a073be5bf1a1fe3f4c2 /src/core/SkDraw.cpp | |
parent | 86ae0a9e465f157eaa263ef7515e10619946ff83 (diff) |
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
Diffstat (limited to 'src/core/SkDraw.cpp')
-rw-r--r-- | src/core/SkDraw.cpp | 102 |
1 files changed, 58 insertions, 44 deletions
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; |