bool parseBuffer(SkReadBuffer& buffer);
public:
- const SkBitmap& getBitmap(SkReader32* reader) const {
+ const SkBitmap& getBitmap(SkReadBuffer* reader) const {
const int index = reader->readInt();
- return fBitmaps[index];
+ return reader->validateIndex(index, fBitmaps.count()) ? fBitmaps[index] : fEmptyBitmap;
}
- const SkImage* getImage(SkReader32* reader) const {
+ const SkImage* getImage(SkReadBuffer* reader) const {
const int index = reader->readInt();
- return fImageRefs[index];
+ return reader->validateIndex(index, fImageCount) ? fImageRefs[index] : nullptr;
}
- const SkPath& getPath(SkReader32* reader) const {
- int index = reader->readInt() - 1;
- return fPaths[index];
+ const SkPath& getPath(SkReadBuffer* reader) const {
+ const int index = reader->readInt() - 1;
+ return reader->validateIndex(index, fPaths.count()) ? fPaths[index] : fEmptyPath;
}
- const SkPicture* getPicture(SkReader32* reader) const {
- int index = reader->readInt();
- SkASSERT(index > 0 && index <= fPictureCount);
- return fPictureRefs[index - 1];
+ const SkPicture* getPicture(SkReadBuffer* reader) const {
+ const int index = reader->readInt() - 1;
+ return reader->validateIndex(index, fPictureCount) ? fPictureRefs[index] : nullptr;
}
- const SkPaint* getPaint(SkReader32* reader) const {
- int index = reader->readInt();
- if (index == 0) {
- return nullptr;
- }
- return &fPaints[index - 1];
+ const SkPaint* getPaint(SkReadBuffer* reader) const {
+ const int index = reader->readInt() - 1;
+ return reader->validateIndex(index, fPaints.count()) ? &fPaints[index] : nullptr;
}
- const SkTextBlob* getTextBlob(SkReader32* reader) const {
- int index = reader->readInt();
- SkASSERT(index > 0 && index <= fTextBlobCount);
- return fTextBlobRefs[index - 1];
+ const SkTextBlob* getTextBlob(SkReadBuffer* reader) const {
+ const int index = reader->readInt() - 1;
+ return reader->validateIndex(index, fTextBlobCount) ? fTextBlobRefs[index] : nullptr;
}
#if SK_SUPPORT_GPU
sk_sp<SkData> fOpData; // opcodes and parameters
+ const SkPath fEmptyPath;
+ const SkBitmap fEmptyBitmap;
+
const SkPicture** fPictureRefs;
int fPictureCount;
const SkTextBlob** fTextBlobRefs;
#include "SkPictureData.h"
#include "SkPicturePlayback.h"
#include "SkPictureRecord.h"
-#include "SkReader32.h"
+#include "SkReadBuffer.h"
#include "SkRSXform.h"
#include "SkTextBlob.h"
#include "SkTDArray.h"
* to the next chunk's op code. This also means that the size of a chunk
* with no arguments (just an opcode) will be 4.
*/
-DrawType SkPicturePlayback::ReadOpAndSize(SkReader32* reader, uint32_t* size) {
+DrawType SkPicturePlayback::ReadOpAndSize(SkReadBuffer* reader, uint32_t* size) {
uint32_t temp = reader->readInt();
uint32_t op;
if (((uint8_t)temp) == temp) {
}
-static const SkRect* get_rect_ptr(SkReader32* reader) {
+static const SkRect* get_rect_ptr(SkReadBuffer* reader, SkRect* storage) {
if (reader->readBool()) {
- return &reader->skipT<SkRect>();
+ reader->readRect(storage);
+ return storage;
} else {
return nullptr;
}
const char* fText;
};
-void get_text(SkReader32* reader, TextContainer* text) {
+void get_text(SkReadBuffer* reader, TextContainer* text) {
size_t length = text->fByteLength = reader->readInt();
text->fText = (const char*)reader->skip(length);
}
AutoResetOpID aroi(this);
SkASSERT(0 == fCurOffset);
- SkReader32 reader(fPictureData->opData()->bytes(), fPictureData->opData()->size());
+ SkReadBuffer reader(fPictureData->opData()->bytes(), fPictureData->opData()->size());
// Record this, so we can concat w/ it if we encounter a setMatrix()
SkMatrix initialMatrix = canvas->getTotalMatrix();
}
}
-void SkPicturePlayback::handleOp(SkReader32* reader,
+void SkPicturePlayback::handleOp(SkReadBuffer* reader,
DrawType op,
uint32_t size,
SkCanvas* canvas,
SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
canvas->clipPath(path, regionOp, doAA);
if (canvas->isClipEmpty() && offsetToRestore) {
- reader->setOffset(offsetToRestore);
+ reader->skip(offsetToRestore - reader->offset());
}
} break;
case CLIP_REGION: {
SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
canvas->clipRegion(region, regionOp);
if (canvas->isClipEmpty() && offsetToRestore) {
- reader->setOffset(offsetToRestore);
+ reader->skip(offsetToRestore - reader->offset());
}
} break;
case CLIP_RECT: {
- const SkRect& rect = reader->skipT<SkRect>();
+ SkRect rect;
+ reader->readRect(&rect);
uint32_t packed = reader->readInt();
SkRegion::Op regionOp = ClipParams_unpackRegionOp(packed);
bool doAA = ClipParams_unpackDoAA(packed);
SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
canvas->clipRect(rect, regionOp, doAA);
if (canvas->isClipEmpty() && offsetToRestore) {
- reader->setOffset(offsetToRestore);
+ reader->skip(offsetToRestore - reader->offset());
}
} break;
case CLIP_RRECT: {
SkASSERT(!offsetToRestore || offsetToRestore >= reader->offset());
canvas->clipRRect(rrect, regionOp, doAA);
if (canvas->isClipEmpty() && offsetToRestore) {
- reader->setOffset(offsetToRestore);
+ reader->skip(offsetToRestore - reader->offset());
}
} break;
case PUSH_CULL: break; // Deprecated, safe to ignore both push and pop.
break;
}
case DRAW_ANNOTATION: {
- const SkRect& rect = reader->skipT<SkRect>();
- const char* key = reader->readString();
- canvas->drawAnnotation(rect, key, reader->readData().get());
+ SkRect rect;
+ reader->readRect(&rect);
+ SkString key;
+ reader->readString(&key);
+ canvas->drawAnnotation(rect, key.c_str(), reader->readByteArrayAsData().get());
} break;
case DRAW_ATLAS: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* atlas = fPictureData->getImage(reader);
- const uint32_t flags = reader->readU32();
- const int count = reader->readU32();
+ const uint32_t flags = reader->readUInt();
+ const int count = reader->readUInt();
const SkRSXform* xform = (const SkRSXform*)reader->skip(count * sizeof(SkRSXform));
const SkRect* tex = (const SkRect*)reader->skip(count * sizeof(SkRect));
const SkColor* colors = nullptr;
SkXfermode::Mode mode = SkXfermode::kDst_Mode;
if (flags & DRAW_ATLAS_HAS_COLORS) {
colors = (const SkColor*)reader->skip(count * sizeof(SkColor));
- mode = (SkXfermode::Mode)reader->readU32();
+ mode = (SkXfermode::Mode)reader->readUInt();
}
const SkRect* cull = nullptr;
if (flags & DRAW_ATLAS_HAS_CULL) {
case DRAW_BITMAP: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader));
- const SkPoint& loc = reader->skipT<SkPoint>();
+ SkPoint loc;
+ reader->readPoint(&loc);
canvas->drawBitmap(bitmap, loc.fX, loc.fY, paint);
} break;
case DRAW_BITMAP_RECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader));
- const SkRect* src = get_rect_ptr(reader); // may be null
- const SkRect& dst = reader->skipT<SkRect>(); // required
+ SkRect storage;
+ const SkRect* src = get_rect_ptr(reader, &storage); // may be null
+ SkRect dst;
+ reader->readRect(&dst); // required
SkCanvas::SrcRectConstraint constraint = (SkCanvas::SrcRectConstraint)reader->readInt();
canvas->legacy_drawBitmapRect(bitmap, src, dst, paint, constraint);
} break;
case DRAW_BITMAP_NINE: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkBitmap bitmap = shallow_copy(fPictureData->getBitmap(reader));
- const SkIRect& src = reader->skipT<SkIRect>();
- const SkRect& dst = reader->skipT<SkRect>();
+ SkIRect src;
+ reader->readIRect(&src);
+ SkRect dst;
+ reader->readRect(&dst);
canvas->drawBitmapNine(bitmap, src, dst, paint);
} break;
case DRAW_CLEAR:
reader->readRRect(&inner);
canvas->drawDRRect(outer, inner, paint);
} break;
- case BEGIN_COMMENT_GROUP:
- reader->readString();
+ case BEGIN_COMMENT_GROUP: {
+ SkString tmp;
+ reader->readString(&tmp);
// deprecated (M44)
break;
- case COMMENT:
- reader->readString();
- reader->readString();
+ }
+ case COMMENT: {
+ SkString tmp;
+ reader->readString(&tmp);
+ reader->readString(&tmp);
// deprecated (M44)
break;
+ }
case END_COMMENT_GROUP:
// deprecated (M44)
break;
case DRAW_IMAGE: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getImage(reader);
- const SkPoint& loc = reader->skipT<SkPoint>();
+ SkPoint loc;
+ reader->readPoint(&loc);
canvas->drawImage(image, loc.fX, loc.fY, paint);
} break;
case DRAW_IMAGE_NINE: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getImage(reader);
- const SkIRect& center = reader->skipT<SkIRect>();
- const SkRect& dst = reader->skipT<SkRect>();
+ SkIRect center;
+ reader->readIRect(¢er);
+ SkRect dst;
+ reader->readRect(&dst);
canvas->drawImageNine(image, center, dst, paint);
} break;
case DRAW_IMAGE_RECT_STRICT:
case DRAW_IMAGE_RECT: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* image = fPictureData->getImage(reader);
- const SkRect* src = get_rect_ptr(reader); // may be null
- const SkRect& dst = reader->skipT<SkRect>(); // required
+ SkRect storage;
+ const SkRect* src = get_rect_ptr(reader, &storage); // may be null
+ SkRect dst;
+ reader->readRect(&dst); // required
// DRAW_IMAGE_RECT_STRICT assumes this constraint, and doesn't store it
SkCanvas::SrcRectConstraint constraint = SkCanvas::kStrict_SrcRectConstraint;
if (DRAW_IMAGE_RECT == op) {
} break;
case DRAW_OVAL: {
const SkPaint& paint = *fPictureData->getPaint(reader);
- canvas->drawOval(reader->skipT<SkRect>(), paint);
+ SkRect rect;
+ reader->readRect(&rect);
+ canvas->drawOval(rect, paint);
} break;
case DRAW_PAINT:
canvas->drawPaint(*fPictureData->getPaint(reader));
} break;
case DRAW_RECT: {
const SkPaint& paint = *fPictureData->getPaint(reader);
- canvas->drawRect(reader->skipT<SkRect>(), paint);
+ SkRect rect;
+ reader->readRect(&rect);
+ canvas->drawRect(rect, paint);
} break;
case DRAW_RRECT: {
const SkPaint& paint = *fPictureData->getPaint(reader);
canvas->save();
break;
case SAVE_LAYER_SAVEFLAGS_DEPRECATED: {
- const SkRect* boundsPtr = get_rect_ptr(reader);
+ SkRect storage;
+ const SkRect* boundsPtr = get_rect_ptr(reader, &storage);
const SkPaint* paint = fPictureData->getPaint(reader);
auto flags = SkCanvas::LegacySaveFlagsToSaveLayerFlags(reader->readInt());
canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint, flags));
} break;
case SAVE_LAYER_SAVELAYERFLAGS_DEPRECATED_JAN_2016: {
- const SkRect* boundsPtr = get_rect_ptr(reader);
+ SkRect storage;
+ const SkRect* boundsPtr = get_rect_ptr(reader, &storage);
const SkPaint* paint = fPictureData->getPaint(reader);
canvas->saveLayer(SkCanvas::SaveLayerRec(boundsPtr, paint, reader->readInt()));
} break;
case SAVE_LAYER_SAVELAYERREC: {
SkCanvas::SaveLayerRec rec(nullptr, nullptr, nullptr, 0);
const uint32_t flatFlags = reader->readInt();
+ SkRect bounds;
if (flatFlags & SAVELAYERREC_HAS_BOUNDS) {
- rec.fBounds = &reader->skipT<SkRect>();
+ reader->readRect(&bounds);
+ rec.fBounds = &bounds;
}
if (flatFlags & SAVELAYERREC_HAS_PAINT) {
rec.fPaint = fPictureData->getPaint(reader);