diff options
author | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-03 14:52:08 +0000 |
---|---|---|
committer | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-03 14:52:08 +0000 |
commit | 6ea165dd8fcd31e0fa56f43de4eadd022151c2aa (patch) | |
tree | cf73d1189426c138507ab8b7c42fe5cae2971fc5 | |
parent | 66ca2fba44fe04f3382a3e22096fe73b60ce19d7 (diff) |
Another fix for drawing bitmaps through an SkGPipe that share pixelrefs.
In addition to checking the offset, also check to ensure that the width
and height match, so that a subset which includes the upper left corner
will be handled properly as well.
Review URL: https://codereview.appspot.com/6352066
git-svn-id: http://skia.googlecode.com/svn/trunk@4448 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gm/extractbitmap.cpp | 26 | ||||
-rw-r--r-- | src/pipe/SkGPipeWrite.cpp | 15 |
2 files changed, 32 insertions, 9 deletions
diff --git a/gm/extractbitmap.cpp b/gm/extractbitmap.cpp index 67657968ae..050d7e7834 100644 --- a/gm/extractbitmap.cpp +++ b/gm/extractbitmap.cpp @@ -45,13 +45,33 @@ protected: create_bitmap(&bitmap); int x = bitmap.width() / 2; int y = bitmap.height() / 2; - SkBitmap subset; - bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y)); canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); canvas->drawBitmap(bitmap, 0, 0); - canvas->drawBitmap(subset, 0, 0); + + { + // Do some subset drawing. This will test that an SkGPipe properly + // handles the case where bitmaps share a pixelref + // Draw the bottom right fourth of the bitmap over the top left + SkBitmap subset; + bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y)); + canvas->drawBitmap(subset, 0, 0); + // Draw the top left corner over the bottom right + bitmap.extractSubset(&subset, SkIRect::MakeWH(x, y)); + canvas->drawBitmap(subset, SkIntToScalar(x), SkIntToScalar(y)); + // Draw a subset which has the same height and pixelref offset but a + // different width + bitmap.extractSubset(&subset, SkIRect::MakeWH(x, bitmap.height())); + SkAutoCanvasRestore autoRestore(canvas, true); + canvas->translate(0, SkIntToScalar(bitmap.height() + 20)); + canvas->drawBitmap(subset, 0, 0); + // Now draw a subet which has the same width and pixelref offset but + // a different height + bitmap.extractSubset(&subset, SkIRect::MakeWH(bitmap.height(), y)); + canvas->translate(0, SkIntToScalar(bitmap.height() + 20)); + canvas->drawBitmap(subset, 0, 0); + } /* // Now do the same but with a device bitmap as source image SkRefPtr<SkDevice> primaryDevice(canvas->getDevice()); diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp index 066159f10a..5734a27800 100644 --- a/src/pipe/SkGPipeWrite.cpp +++ b/src/pipe/SkGPipeWrite.cpp @@ -85,16 +85,19 @@ public: const uint32_t genID = orig.getGenerationID(); SkPixelRef* sharedPixelRef = NULL; for (int i = fBitmaps.count() - 1; i >= 0; i--) { + SkBitmap* storedBitmap = fBitmaps[i].fBitmap; if (genID == fBitmaps[i].fGenID) { - if (orig.pixelRefOffset() != fBitmaps[i].fBitmap->pixelRefOffset()) { + if (orig.pixelRefOffset() != storedBitmap->pixelRefOffset() + || orig.width() != storedBitmap->width() + || orig.height() != storedBitmap->height()) { // In this case, the bitmaps share a pixelRef, but have - // different offsets. Keep track of the other bitmap so that - // instead of making another copy of the pixelRef we can use - // the copy we already made. - sharedPixelRef = fBitmaps[i].fBitmap->pixelRef(); + // different offsets or sizes. Keep track of the other + // bitmap so that instead of making another copy of the + // pixelRef we can use the copy we already made. + sharedPixelRef = storedBitmap->pixelRef(); break; } - return fBitmaps[i].fBitmap; + return storedBitmap; } } SkBitmap* copy; |