Little changes to SkAnnotation in pipe:
- store size in the op data field rather than separately (saves 4 bytes);
- trim out a malloc/memcpy in each of read and write;
- remove unused enum value;
- use the right _unpackOp function;
- make sure we call needOpBytes().
BUG=
R=reed@google.com, scroggo@google.com
Author: mtklein@google.com
Review URL: https://codereview.chromium.org/50523004
git-svn-id: http://skia.googlecode.com/svn/trunk/src@12007 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/pipe/SkGPipePriv.h b/pipe/SkGPipePriv.h
index 9272496..66b4366 100644
--- a/pipe/SkGPipePriv.h
+++ b/pipe/SkGPipePriv.h
@@ -236,8 +236,6 @@
kTextSkewX_PaintOp, // arg scalar - text
kTypeface_PaintOp, // arg inline (index) - text
- kAnnotation_PaintOp,// arg SkAnnotation_flat, data=bool-has-size
-
kFlatIndex_PaintOp, // flags=paintflat, data=index
};
diff --git a/pipe/SkGPipeRead.cpp b/pipe/SkGPipeRead.cpp
index 789c3ed..877d380 100644
--- a/pipe/SkGPipeRead.cpp
+++ b/pipe/SkGPipeRead.cpp
@@ -691,13 +691,11 @@
SkGPipeState* state) {
SkPaint* p = state->editPaint();
- if (SkToBool(PaintOp_unpackData(op32))) {
- const size_t size = reader->readU32();
- SkAutoMalloc storage(size);
-
- reader->read(storage.get(), size);
- SkOrderedReadBuffer buffer(storage.get(), size);
+ const size_t size = DrawOp_unpackData(op32);
+ if (size > 0) {
+ SkOrderedReadBuffer buffer(reader->skip(size), size);
p->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref();
+ SkASSERT(buffer.offset() == size);
} else {
p->setAnnotation(NULL);
}
diff --git a/pipe/SkGPipeWrite.cpp b/pipe/SkGPipeWrite.cpp
index 53b0ae5..50043c6 100644
--- a/pipe/SkGPipeWrite.cpp
+++ b/pipe/SkGPipeWrite.cpp
@@ -1128,18 +1128,17 @@
if (base.getAnnotation() != paint.getAnnotation()) {
if (NULL == paint.getAnnotation()) {
- this->writeOp(kSetAnnotation_DrawOp, 0, 0);
+ if (this->needOpBytes()) {
+ this->writeOp(kSetAnnotation_DrawOp, 0, 0);
+ }
} else {
SkOrderedWriteBuffer buffer(1024);
paint.getAnnotation()->writeToBuffer(buffer);
- size = buffer.bytesWritten();
-
- SkAutoMalloc storage(size);
- buffer.writeToMemory(storage.get());
-
- this->writeOp(kSetAnnotation_DrawOp, 0, 1);
- fWriter.write32(size);
- fWriter.write(storage.get(), size);
+ const size_t size = buffer.bytesWritten();
+ if (this->needOpBytes(size)) {
+ this->writeOp(kSetAnnotation_DrawOp, 0, size);
+ buffer.writeToMemory(fWriter.reserve(size));
+ }
}
base.setAnnotation(paint.getAnnotation());
}