commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame^] | 1 | #ifndef SkRecordDraw_DEFINED |
| 2 | #define SkRecordDraw_DEFINED |
| 3 | |
| 4 | #include "SkRecord.h" |
| 5 | #include "SkRecords.h" |
| 6 | #include "SkCanvas.h" |
| 7 | |
| 8 | // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. |
| 9 | |
| 10 | struct SkRecordDraw { |
| 11 | explicit SkRecordDraw(SkCanvas* canvas) : canvas(canvas) {} |
| 12 | |
| 13 | // No base case, so we'll be compile-time checked that we implemented all possibilities below. |
| 14 | template <typename T> void operator()(const T& record); |
| 15 | |
| 16 | SkCanvas* canvas; |
| 17 | }; |
| 18 | |
| 19 | // Nothing fancy here. |
| 20 | // The structs in SkRecord are completely isomorphic to their corresponding SkCanvas calls. |
| 21 | |
| 22 | #define CASE(T) template <> void SkRecordDraw::operator()(const SkRecords::T& r) |
| 23 | |
| 24 | CASE(Restore) { canvas->restore(); } |
| 25 | CASE(Save) { canvas->save(r.flags); } |
| 26 | CASE(SaveLayer) { canvas->saveLayer(r.bounds, r.paint, r.flags); } |
| 27 | |
| 28 | CASE(Concat) { canvas->concat(r.matrix); } |
| 29 | CASE(SetMatrix) { canvas->setMatrix(r.matrix); } |
| 30 | |
| 31 | CASE(ClipPath) { canvas->clipPath(r.path, r.op, r.doAA); } |
| 32 | CASE(ClipRRect) { canvas->clipRRect(r.rrect, r.op, r.doAA); } |
| 33 | CASE(ClipRect) { canvas->clipRect(r.rect, r.op, r.doAA); } |
| 34 | CASE(ClipRegion) { canvas->clipRegion(r.region, r.op); } |
| 35 | |
| 36 | CASE(Clear) { canvas->clear(r.color); } |
| 37 | CASE(DrawBitmap) { canvas->drawBitmap(r.bitmap, r.left, r.top, r.paint); } |
| 38 | CASE(DrawBitmapMatrix) { canvas->drawBitmapMatrix(r.bitmap, r.matrix, r.paint); } |
| 39 | CASE(DrawBitmapNine) { canvas->drawBitmapNine(r.bitmap, r.center, r.dst, r.paint); } |
| 40 | CASE(DrawBitmapRectToRect) { |
| 41 | canvas->drawBitmapRectToRect(r.bitmap, r.src, r.dst, r.paint, r.flags); |
| 42 | } |
| 43 | CASE(DrawDRRect) { canvas->drawDRRect(r.outer, r.inner, r.paint); } |
| 44 | CASE(DrawOval) { canvas->drawOval(r.oval, r.paint); } |
| 45 | CASE(DrawPaint) { canvas->drawPaint(r.paint); } |
| 46 | CASE(DrawPath) { canvas->drawPath(r.path, r.paint); } |
| 47 | CASE(DrawPoints) { canvas->drawPoints(r.mode, r.count, r.pts, r.paint); } |
| 48 | CASE(DrawPosText) { canvas->drawPosText(r.text, r.byteLength, r.pos, r.paint); } |
| 49 | CASE(DrawPosTextH) { canvas->drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint); } |
| 50 | CASE(DrawRRect) { canvas->drawRRect(r.rrect, r.paint); } |
| 51 | CASE(DrawRect) { canvas->drawRect(r.rect, r.paint); } |
| 52 | CASE(DrawSprite) { canvas->drawSprite(r.bitmap, r.left, r.top, r.paint); } |
| 53 | CASE(DrawText) { canvas->drawText(r.text, r.byteLength, r.x, r.y, r.paint); } |
| 54 | CASE(DrawTextOnPath) { canvas->drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.paint); } |
| 55 | CASE(DrawVertices) { |
| 56 | canvas->drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors, |
| 57 | r.xmode.get(), r.indices, r.indexCount, r.paint); |
| 58 | } |
| 59 | |
| 60 | #undef CASE |
| 61 | |
| 62 | #endif//SkRecordDraw_DEFINED |