From 22d77cb363cc67349ab4d51a51200da2434d322e Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Wed, 3 Jan 2018 13:22:51 -0500 Subject: [PATCH] use member version of skipT Bug: skia: Change-Id: I2a4ce9c959616a7a7121028b81c6d89a41a26bdd Reviewed-on: https://skia-review.googlesource.com/90484 Commit-Queue: Mike Reed Reviewed-by: Mike Klein --- src/pipe/SkPipeReader.cpp | 67 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/src/pipe/SkPipeReader.cpp b/src/pipe/SkPipeReader.cpp index f8dc23885d..c2ff0bfbb6 100644 --- a/src/pipe/SkPipeReader.cpp +++ b/src/pipe/SkPipeReader.cpp @@ -93,10 +93,6 @@ private: /////////////////////////////////////////////////////////////////////////////////////////////////// -template const T* skip(SkReadBuffer& reader, int count = 1) { - return (const T*)reader.skip(count * sizeof(T)); -} - static SkRRect read_rrect(SkReadBuffer& reader) { SkRRect rrect; rrect.readFromMemory(reader.skip(SkRRect::kSizeInMemory), SkRRect::kSizeInMemory); @@ -108,9 +104,9 @@ static SkMatrix read_sparse_matrix(SkReadBuffer& reader, SkMatrix::TypeMask tm) matrix.reset(); if (tm & SkMatrix::kPerspective_Mask) { - matrix.set9(skip(reader, 9)); + matrix.set9(reader.skipT(9)); } else if (tm & SkMatrix::kAffine_Mask) { - const SkScalar* tmp = skip(reader, 6); + const SkScalar* tmp = reader.skipT(6); matrix[SkMatrix::kMScaleX] = tmp[0]; matrix[SkMatrix::kMSkewX] = tmp[1]; matrix[SkMatrix::kMTransX] = tmp[2]; @@ -118,13 +114,13 @@ static SkMatrix read_sparse_matrix(SkReadBuffer& reader, SkMatrix::TypeMask tm) matrix[SkMatrix::kMSkewY] = tmp[4]; matrix[SkMatrix::kMTransY] = tmp[5]; } else if (tm & SkMatrix::kScale_Mask) { - const SkScalar* tmp = skip(reader, 4); + const SkScalar* tmp = reader.skipT(4); matrix[SkMatrix::kMScaleX] = tmp[0]; matrix[SkMatrix::kMTransX] = tmp[1]; matrix[SkMatrix::kMScaleY] = tmp[2]; matrix[SkMatrix::kMTransY] = tmp[3]; } else if (tm & SkMatrix::kTranslate_Mask) { - const SkScalar* tmp = skip(reader, 2); + const SkScalar* tmp = reader.skipT(2); matrix[SkMatrix::kMTransX] = tmp[0]; matrix[SkMatrix::kMTransY] = tmp[1]; } @@ -228,7 +224,7 @@ static void save_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* ca static void saveLayer_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) { SkASSERT(SkPipeVerb::kSaveLayer == unpack_verb(packedVerb)); unsigned extra = unpack_verb_extra(packedVerb); - const SkRect* bounds = (extra & kHasBounds_SaveLayerMask) ? skip(reader) : nullptr; + const SkRect* bounds = (extra & kHasBounds_SaveLayerMask) ? reader.skipT() : nullptr; SkPaint paintStorage, *paint = nullptr; if (extra & kHasPaint_SaveLayerMask) { paintStorage = read_paint(reader); @@ -277,7 +273,7 @@ static void clipRect_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas SkASSERT(SkPipeVerb::kClipRect == unpack_verb(packedVerb)); SkClipOp op = (SkClipOp)(unpack_verb_extra(packedVerb) >> 1); bool isAA = unpack_verb_extra(packedVerb) & 1; - canvas->clipRect(*skip(reader), op, isAA); + canvas->clipRect(*reader.skipT(), op, isAA); } static void clipRRect_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) { @@ -307,7 +303,7 @@ static void clipRegion_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanv static void drawArc_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) { SkASSERT(SkPipeVerb::kDrawArc == unpack_verb(packedVerb)); const bool useCenter = (bool)(unpack_verb_extra(packedVerb) & 1); - const SkScalar* scalars = skip(reader, 6); // bounds[0..3], start[4], sweep[5] + const SkScalar* scalars = reader.skipT(6); // bounds[0..3], start[4], sweep[5] const SkRect* bounds = (const SkRect*)scalars; canvas->drawArc(*bounds, scalars[4], scalars[5], useCenter, read_paint(reader)); } @@ -317,15 +313,15 @@ static void drawAtlas_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanva SkBlendMode mode = (SkBlendMode)(packedVerb & kMode_DrawAtlasMask); sk_sp image(reader.readImage()); int count = reader.read32(); - const SkRSXform* xform = skip(reader, count); - const SkRect* rect = skip(reader, count); + const SkRSXform* xform = reader.skipT(count); + const SkRect* rect = reader.skipT(count); const SkColor* color = nullptr; if (packedVerb & kHasColors_DrawAtlasMask) { - color = skip(reader, count); + color = reader.skipT(count); } const SkRect* cull = nullptr; if (packedVerb & kHasCull_DrawAtlasMask) { - cull = skip(reader); + cull = reader.skipT(); } SkPaint paintStorage, *paint = nullptr; if (packedVerb & kHasPaint_DrawAtlasMask) { @@ -362,7 +358,7 @@ static void drawPosText_handler(SkPipeReader& reader, uint32_t packedVerb, SkCan } const void* text = reader.skip(SkAlign4(len)); int count = reader.read32(); - const SkPoint* pos = skip(reader, count); + const SkPoint* pos = reader.skipT(count); SkPaint paint = read_paint(reader); SkASSERT(paint.countText(text, len) == count); canvas->drawPosText(text, len, pos, paint); @@ -376,7 +372,7 @@ static void drawPosTextH_handler(SkPipeReader& reader, uint32_t packedVerb, SkCa } const void* text = reader.skip(SkAlign4(len)); int count = reader.read32(); - const SkScalar* xpos = skip(reader, count); + const SkScalar* xpos = reader.skipT(count); SkScalar constY = reader.readScalar(); SkPaint paint = read_paint(reader); SkASSERT(paint.countText(text, len) == count); @@ -419,8 +415,8 @@ static void drawTextRSXform_handler(SkPipeReader& reader, uint32_t packedVerb, S } const void* text = reader.skip(SkAlign4(len)); int count = reader.read32(); - const SkRSXform* xform = skip(reader, count); - const SkRect* cull = (packedVerb & 1) ? skip(reader) : nullptr; + const SkRSXform* xform = reader.skipT(count); + const SkRect* cull = (packedVerb & 1) ? reader.skipT() : nullptr; SkPaint paint = read_paint(reader); SkASSERT(paint.countText(text, len) == count); canvas->drawTextRSXform(text, len, xform, cull, paint); @@ -430,12 +426,12 @@ static void drawPatch_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanva SkASSERT(SkPipeVerb::kDrawPatch == unpack_verb(packedVerb)); const SkColor* colors = nullptr; const SkPoint* tex = nullptr; - const SkPoint* cubics = skip(reader, 12); + const SkPoint* cubics = reader.skipT(12); if (packedVerb & kHasColors_DrawPatchExtraMask) { - colors = skip(reader, 4); + colors = reader.skipT(4); } if (packedVerb & kHasTexture_DrawPatchExtraMask) { - tex = skip(reader, 4); + tex = reader.skipT(4); } SkBlendMode mode = (SkBlendMode)(packedVerb & kModeEnum_DrawPatchExtraMask); canvas->drawPatch(cubics, colors, tex, mode, read_paint(reader)); @@ -448,7 +444,7 @@ static void drawPaint_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanva static void drawRect_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) { SkASSERT(SkPipeVerb::kDrawRect == unpack_verb(packedVerb)); - const SkRect* rect = skip(reader); + const SkRect* rect = reader.skipT(); canvas->drawRect(*rect, read_paint(reader)); } @@ -459,13 +455,13 @@ static void drawRegion_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanv size = reader.read32(); } SkRegion region; - region.readFromMemory(skip(reader, SkAlign4(size)), size); + region.readFromMemory(reader.skipT(size), size); canvas->drawRegion(region, read_paint(reader)); } static void drawOval_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) { SkASSERT(SkPipeVerb::kDrawOval == unpack_verb(packedVerb)); - const SkRect* rect = skip(reader); + const SkRect* rect = reader.skipT(); canvas->drawOval(*rect, read_paint(reader)); } @@ -495,7 +491,7 @@ static void drawPoints_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanv SkASSERT(SkPipeVerb::kDrawPoints == unpack_verb(packedVerb)); SkCanvas::PointMode mode = (SkCanvas::PointMode)unpack_verb_extra(packedVerb); int count = reader.read32(); - const SkPoint* points = skip(reader, count); + const SkPoint* points = reader.skipT(count); canvas->drawPoints(mode, count, points, read_paint(reader)); } @@ -518,8 +514,8 @@ static void drawImageRect_handler(SkPipeReader& reader, uint32_t packedVerb, SkC SkCanvas::SrcRectConstraint constraint = (SkCanvas::SrcRectConstraint)(packedVerb & kConstraint_DrawImageRectMask); const SkRect* src = (packedVerb & kHasSrcRect_DrawImageRectMask) ? - skip(reader) : nullptr; - const SkRect* dst = skip(reader); + reader.skipT() : nullptr; + const SkRect* dst = reader.skipT(); SkPaint paintStorage, *paint = nullptr; if (packedVerb & kHasPaint_DrawImageRectMask) { paintStorage = read_paint(reader); @@ -535,8 +531,8 @@ static void drawImageRect_handler(SkPipeReader& reader, uint32_t packedVerb, SkC static void drawImageNine_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) { SkASSERT(SkPipeVerb::kDrawImageNine == unpack_verb(packedVerb)); sk_sp image(reader.readImage()); - const SkIRect* center = skip(reader); - const SkRect* dst = skip(reader); + const SkIRect* center = reader.skipT(); + const SkRect* dst = reader.skipT(); SkPaint paintStorage, *paint = nullptr; if (packedVerb & kHasPaint_DrawImageNineMask) { paintStorage = read_paint(reader); @@ -553,7 +549,7 @@ static void drawImageLattice_handler(SkPipeReader& reader, uint32_t packedVerb, if (!SkCanvasPriv::ReadLattice(reader, &lattice)) { return; } - const SkRect* dst = skip(reader); + const SkRect* dst = reader.skipT(); SkPaint paintStorage, *paint = nullptr; if (packedVerb & kHasPaint_DrawImageLatticeMask) { @@ -590,14 +586,14 @@ static void drawPicture_handler(SkPipeReader& reader, uint32_t packedVerb, SkCan static void drawAnnotation_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) { SkASSERT(SkPipeVerb::kDrawAnnotation == unpack_verb(packedVerb)); - const SkRect* rect = skip(reader); + const SkRect* rect = reader.skipT(); // len includes the key's trailing 0 uint32_t len = unpack_verb_extra(packedVerb) >> 1; if (0 == len) { len = reader.read32(); } - const char* key = skip(reader, len); + const char* key = reader.skipT(len); sk_sp data; if (packedVerb & 1) { uint32_t size = reader.read32(); @@ -697,7 +693,10 @@ static void definePicture_handler(SkPipeReader& reader, uint32_t packedVerb, SkC } else { SkPictureRecorder recorder; int pictureIndex = -1; // invalid - const SkRect* cull = skip(reader); + const SkRect* cull = reader.skipT(); + if (!cull) { + return; + } do_playback(reader, recorder.beginRecording(*cull), &pictureIndex); SkASSERT(pictureIndex > 0); sk_sp picture = recorder.finishRecordingAsPicture();