summaryrefslogtreecommitdiff
path: root/pipe/SkGPipeRead.cpp
diff options
context:
space:
mode:
authorscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-17 16:10:34 +0000
committerscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-17 16:10:34 +0000
commit7549e37492896638598839fe3952e9d6823e2a92 (patch)
tree9188ff15fb09796d23780da865b7747fa8d9e871 /pipe/SkGPipeRead.cpp
parentb7f5ab22654dcfcdc3a78866e1fce63dd67f9a0b (diff)
downloadsrc-7549e37492896638598839fe3952e9d6823e2a92.tar.gz
Purge bitmaps from SkGPipe's shared heap.
BitmapInfo: Now in SkGPipePriv so it can be accessed by SkGPipeRead. Add the ability to essentially ref count BitmapInfos so that they can be purged to make room in the shared heap for a new one. SkGPipeWrite: Purge the least recently used bitmap if it has already been drawn by all readers. SkGPipeRead: Read the BitmapInfo (instead of the SkBitmap) and decrement its count after drawing. SkGPipeController: Added a method to tell how many readers will be used, so that when purging bitmaps each reader can be accounted for. Review URL: https://codereview.appspot.com/6374065 git-svn-id: http://skia.googlecode.com/svn/trunk/src@4638 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'pipe/SkGPipeRead.cpp')
-rw-r--r--pipe/SkGPipeRead.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/pipe/SkGPipeRead.cpp b/pipe/SkGPipeRead.cpp
index 9739ac09..6f79e51f 100644
--- a/pipe/SkGPipeRead.cpp
+++ b/pipe/SkGPipeRead.cpp
@@ -372,21 +372,40 @@ static void drawTextOnPath_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op3
///////////////////////////////////////////////////////////////////////////////
-static const SkBitmap* getBitmap(SkReader32* reader, uint32_t op32, SkGPipeState* state) {
+class BitmapHolder : SkNoncopyable {
+public:
+ BitmapHolder(SkReader32* reader, uint32_t op32, SkGPipeState* state);
+ ~BitmapHolder() {
+ if (fInfo != NULL) {
+ fInfo->decDraws();
+ }
+ }
+ const SkBitmap* getBitmap() {
+ return fBitmap;
+ }
+private:
+ BitmapInfo* fInfo;
+ const SkBitmap* fBitmap;
+};
+
+BitmapHolder::BitmapHolder(SkReader32* reader, uint32_t op32,
+ SkGPipeState* state) {
if (shouldFlattenBitmaps(state->getFlags())) {
- unsigned index = DrawOp_unpackData(op32);
- return state->getBitmap(index);
+ fInfo = NULL;
+ fBitmap = state->getBitmap(DrawOp_unpackData(op32));
+ } else {
+ fInfo = static_cast<BitmapInfo*>(reader->readPtr());
+ fBitmap = fInfo->fBitmap;
}
- return static_cast<const SkBitmap*>(reader->readPtr());
}
static void drawBitmap_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
- const SkBitmap* bm = getBitmap(reader, op32, state);
+ BitmapHolder holder(reader, op32, state);
bool hasPaint = reader->readBool();
SkScalar left = reader->readScalar();
SkScalar top = reader->readScalar();
- canvas->drawBitmap(*bm, left, top, hasPaint ? &state->paint() : NULL);
+ canvas->drawBitmap(*holder.getBitmap(), left, top, hasPaint ? &state->paint() : NULL);
}
static void drawBitmapMatrix_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
@@ -396,17 +415,17 @@ static void drawBitmapMatrix_rp(SkCanvas* canvas, SkReader32* reader, uint32_t o
static void drawBitmapNine_rp(SkCanvas* canvas, SkReader32* reader,
uint32_t op32, SkGPipeState* state) {
- const SkBitmap* bm = getBitmap(reader, op32, state);
+ BitmapHolder holder(reader, op32, state);
bool hasPaint = reader->readBool();
const SkIRect* center = skip<SkIRect>(reader);
const SkRect* dst = skip<SkRect>(reader);
- canvas->drawBitmapNine(*bm, *center, *dst,
+ canvas->drawBitmapNine(*holder.getBitmap(), *center, *dst,
hasPaint ? &state->paint() : NULL);
}
static void drawBitmapRect_rp(SkCanvas* canvas, SkReader32* reader,
uint32_t op32, SkGPipeState* state) {
- const SkBitmap* bm = getBitmap(reader, op32, state);
+ BitmapHolder holder(reader, op32, state);
bool hasPaint = reader->readBool();
bool hasSrc = reader->readBool();
const SkIRect* src;
@@ -416,15 +435,15 @@ static void drawBitmapRect_rp(SkCanvas* canvas, SkReader32* reader,
src = NULL;
}
const SkRect* dst = skip<SkRect>(reader);
- canvas->drawBitmapRect(*bm, src, *dst, hasPaint ? &state->paint() : NULL);
+ canvas->drawBitmapRect(*holder.getBitmap(), src, *dst, hasPaint ? &state->paint() : NULL);
}
static void drawSprite_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
- const SkBitmap* bm = getBitmap(reader, op32, state);
+ BitmapHolder holder(reader, op32, state);
bool hasPaint = reader->readBool();
const SkIPoint* point = skip<SkIPoint>(reader);
- canvas->drawSprite(*bm, point->fX, point->fY, hasPaint ? &state->paint() : NULL);
+ canvas->drawSprite(*holder.getBitmap(), point->fX, point->fY, hasPaint ? &state->paint() : NULL);
}
///////////////////////////////////////////////////////////////////////////////