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
diff --git a/gm/extractbitmap.cpp b/gm/extractbitmap.cpp
index 6765796..050d7e7 100644
--- a/gm/extractbitmap.cpp
+++ b/gm/extractbitmap.cpp
@@ -45,13 +45,33 @@
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 066159f..5734a27 100644
--- a/src/pipe/SkGPipeWrite.cpp
+++ b/src/pipe/SkGPipeWrite.cpp
@@ -85,16 +85,19 @@
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;