Fix SkGPipe drawing, and turn it on by default.
A recent change broke SkGPipe. Fix it, and turn on pipe drawing
in GM by default so we will catch these in the future.
We already had a bug where SkGPipeWriter had to use its Cross Process
flag to work, so for a quick fix, force the reader to use the Cross
Process flag as well. The bug to allow both cross and non cross process
is http://code.google.com/p/skia/issues/detail?id=663
Review URL: https://codereview.appspot.com/6333071
git-svn-id: http://skia.googlecode.com/svn/trunk@4384 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/pipe/SkGPipeRead.cpp b/src/pipe/SkGPipeRead.cpp
index 7f05b31..a3afc03 100644
--- a/src/pipe/SkGPipeRead.cpp
+++ b/src/pipe/SkGPipeRead.cpp
@@ -67,9 +67,20 @@
SkGPipeState();
~SkGPipeState();
+ void setFlags(unsigned flags) {
+ if (fFlags != flags) {
+ fFlags = flags;
+ this->updateReader();
+ }
+ }
+
+ unsigned getFlags() const {
+ return fFlags;
+ }
+
void setReader(SkFlattenableReadBuffer* reader) {
fReader = reader;
- fReader->setFactoryArray(&fFactoryArray);
+ this->updateReader();
}
const SkPaint& paint() const { return fPaint; }
@@ -91,9 +102,7 @@
void addBitmap(int index) {
SkASSERT(fBitmaps.count() == index);
SkBitmap* bm = new SkBitmap();
- size_t size = fReader->readU32();
- SkOrderedReadBuffer readBuffer(fReader->skip(size), size);
- bm->unflatten(readBuffer);
+ bm->unflatten(*fReader);
*fBitmaps.append() = bm;
}
@@ -111,14 +120,27 @@
paint->setTypeface(id ? fTypefaces[id - 1] : NULL);
}
- SkFlattenableReadBuffer* fReader;
-
private:
+ void updateReader() {
+ if (NULL == fReader) {
+ return;
+ }
+ bool crossProcess = SkToBool(fFlags & SkGPipeWriter::kCrossProcess_Flag);
+ fReader->setFlags(SkSetClearMask(fReader->getFlags(), crossProcess,
+ SkFlattenableReadBuffer::kCrossProcess_Flag));
+ if (crossProcess) {
+ fReader->setFactoryArray(&fFactoryArray);
+ } else {
+ fReader->setFactoryArray(NULL);
+ }
+ }
+ SkFlattenableReadBuffer* fReader;
SkPaint fPaint;
SkTDArray<SkFlattenable*> fFlatArray;
SkTDArray<SkTypeface*> fTypefaces;
SkTDArray<SkFlattenable::Factory> fFactoryArray;
SkTDArray<SkBitmap*> fBitmaps;
+ unsigned fFlags;
};
///////////////////////////////////////////////////////////////////////////////
@@ -345,9 +367,17 @@
///////////////////////////////////////////////////////////////////////////////
+static const SkBitmap* getBitmap(SkReader32* reader, uint32_t op32, SkGPipeState* state) {
+ if (shouldFlattenBitmaps(state->getFlags())) {
+ unsigned index = DrawOp_unpackData(op32);
+ return state->getBitmap(index);
+ }
+ return static_cast<const SkBitmap*>(reader->readPtr());
+}
+
static void drawBitmap_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
- const SkBitmap* bm(static_cast<const SkBitmap*>(reader->readPtr()));
+ const SkBitmap* bm = getBitmap(reader, op32, state);
bool hasPaint = reader->readBool();
SkScalar left = reader->readScalar();
SkScalar top = reader->readScalar();
@@ -361,7 +391,7 @@
static void drawBitmapNine_rp(SkCanvas* canvas, SkReader32* reader,
uint32_t op32, SkGPipeState* state) {
- const SkBitmap* bm(static_cast<const SkBitmap*>(reader->readPtr()));
+ const SkBitmap* bm = getBitmap(reader, op32, state);
bool hasPaint = reader->readBool();
const SkIRect* center = skip<SkIRect>(reader);
const SkRect* dst = skip<SkRect>(reader);
@@ -371,7 +401,7 @@
static void drawBitmapRect_rp(SkCanvas* canvas, SkReader32* reader,
uint32_t op32, SkGPipeState* state) {
- const SkBitmap* bm(static_cast<const SkBitmap*>(reader->readPtr()));
+ const SkBitmap* bm = getBitmap(reader, op32, state);
bool hasPaint = reader->readBool();
bool hasSrc = reader->readBool();
const SkIRect* src;
@@ -386,7 +416,7 @@
static void drawSprite_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
- const SkBitmap* bm(static_cast<const SkBitmap*>(reader->readPtr()));
+ const SkBitmap* bm = getBitmap(reader, op32, state);
bool hasPaint = reader->readBool();
const SkIPoint* point = skip<SkIPoint>(reader);
canvas->drawSprite(*bm, point->fX, point->fY, hasPaint ? &state->paint() : NULL);
@@ -483,6 +513,12 @@
(void)reader->skip(bytes);
}
+static void reportflags_rp(SkCanvas*, SkReader32*, uint32_t op32,
+ SkGPipeState* state) {
+ unsigned flags = DrawOp_unpackFlags(op32);
+ state->setFlags(flags);
+}
+
static void done_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState*) {}
typedef void (*ReadProc)(SkCanvas*, SkReader32*, uint32_t op32, SkGPipeState*);
@@ -524,12 +560,13 @@
def_PaintFlat_rp,
def_Bitmap_rp,
+ reportflags_rp,
done_rp
};
///////////////////////////////////////////////////////////////////////////////
-SkGPipeState::SkGPipeState() {}
+SkGPipeState::SkGPipeState(): fReader(0), fFlags(0) {}
SkGPipeState::~SkGPipeState() {
fTypefaces.safeUnrefAll();