SkRecorder.h revision 3729469d6a12266037b697c2192768545e097ab0
1/* 2 * Copyright 2014 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef SkRecorder_DEFINED 9#define SkRecorder_DEFINED 10 11#include "SkCanvas.h" 12#include "SkRecord.h" 13#include "SkRecords.h" 14#include "SkTDArray.h" 15 16class SkBBHFactory; 17 18class SkCanvasDrawableList : SkNoncopyable { 19public: 20 ~SkCanvasDrawableList(); 21 22 int count() const { return fArray.count(); } 23 SkCanvasDrawable* const* begin() const { return fArray.begin(); } 24 25 void append(SkCanvasDrawable* drawable); 26 27 // Return a new or ref'd array of pictures that were snapped from our drawables. 28 SkPicture::SnapshotArray* newDrawableSnapshot(); 29 30private: 31 SkTDArray<SkCanvasDrawable*> fArray; 32}; 33 34// SkRecorder provides an SkCanvas interface for recording into an SkRecord. 35 36class SkRecorder : public SkCanvas { 37public: 38 // Does not take ownership of the SkRecord. 39 SkRecorder(SkRecord*, int width, int height); // legacy version 40 SkRecorder(SkRecord*, const SkRect& bounds); 41 42 SkCanvasDrawableList* getDrawableList() const { return fDrawableList.get(); } 43 SkCanvasDrawableList* detachDrawableList() { return fDrawableList.detach(); } 44 45 // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail. 46 void forgetRecord(); 47 48 void drawPaint(const SkPaint& paint) SK_OVERRIDE; 49 void drawPoints(PointMode mode, 50 size_t count, 51 const SkPoint pts[], 52 const SkPaint& paint) SK_OVERRIDE; 53 void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE; 54 void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE; 55 void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE; 56 void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE; 57 void drawBitmap(const SkBitmap& bitmap, 58 SkScalar left, 59 SkScalar top, 60 const SkPaint* paint = NULL) SK_OVERRIDE; 61 void drawBitmapRectToRect(const SkBitmap& bitmap, 62 const SkRect* src, 63 const SkRect& dst, 64 const SkPaint* paint = NULL, 65 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) SK_OVERRIDE; 66 void drawBitmapMatrix(const SkBitmap& bitmap, 67 const SkMatrix& m, 68 const SkPaint* paint = NULL) SK_OVERRIDE; 69 void drawBitmapNine(const SkBitmap& bitmap, 70 const SkIRect& center, 71 const SkRect& dst, 72 const SkPaint* paint = NULL) SK_OVERRIDE; 73 virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top, 74 const SkPaint* paint = NULL) SK_OVERRIDE; 75 virtual void drawImageRect(const SkImage* image, const SkRect* src, 76 const SkRect& dst, 77 const SkPaint* paint = NULL) SK_OVERRIDE; 78 void drawSprite(const SkBitmap& bitmap, 79 int left, 80 int top, 81 const SkPaint* paint = NULL) SK_OVERRIDE; 82 void drawVertices(VertexMode vmode, 83 int vertexCount, 84 const SkPoint vertices[], 85 const SkPoint texs[], 86 const SkColor colors[], 87 SkXfermode* xmode, 88 const uint16_t indices[], 89 int indexCount, 90 const SkPaint& paint) SK_OVERRIDE; 91 92 void willSave() SK_OVERRIDE; 93 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) SK_OVERRIDE; 94 void willRestore() SK_OVERRIDE {} 95 void didRestore() SK_OVERRIDE; 96 97 void didConcat(const SkMatrix&) SK_OVERRIDE; 98 void didSetMatrix(const SkMatrix&) SK_OVERRIDE; 99 100 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; 101 void onDrawDrawable(SkCanvasDrawable*) SK_OVERRIDE; 102 void onDrawText(const void* text, 103 size_t byteLength, 104 SkScalar x, 105 SkScalar y, 106 const SkPaint& paint) SK_OVERRIDE; 107 void onDrawPosText(const void* text, 108 size_t byteLength, 109 const SkPoint pos[], 110 const SkPaint& paint) SK_OVERRIDE; 111 void onDrawPosTextH(const void* text, 112 size_t byteLength, 113 const SkScalar xpos[], 114 SkScalar constY, 115 const SkPaint& paint) SK_OVERRIDE; 116 void onDrawTextOnPath(const void* text, 117 size_t byteLength, 118 const SkPath& path, 119 const SkMatrix* matrix, 120 const SkPaint& paint) SK_OVERRIDE; 121 void onDrawTextBlob(const SkTextBlob* blob, 122 SkScalar x, 123 SkScalar y, 124 const SkPaint& paint) SK_OVERRIDE; 125 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 126 const SkPoint texCoords[4], SkXfermode* xmode, 127 const SkPaint& paint) SK_OVERRIDE; 128 129 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE; 130 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE; 131 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE; 132 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) SK_OVERRIDE; 133 134 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) SK_OVERRIDE; 135 136 void onPushCull(const SkRect& cullRect) SK_OVERRIDE; 137 void onPopCull() SK_OVERRIDE; 138 139 void beginCommentGroup(const char*) SK_OVERRIDE; 140 void addComment(const char*, const char*) SK_OVERRIDE; 141 void endCommentGroup() SK_OVERRIDE; 142 void drawData(const void*, size_t) SK_OVERRIDE; 143 144 bool isDrawingToLayer() const SK_OVERRIDE; 145 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE { return NULL; } 146 147private: 148 template <typename T> 149 T* copy(const T*); 150 151 template <typename T> 152 T* copy(const T[], size_t count); 153 154 SkIRect devBounds() const { 155 SkIRect devBounds; 156 this->getClipDeviceBounds(&devBounds); 157 return devBounds; 158 } 159 160 SkRecord* fRecord; 161 162 int fSaveLayerCount; 163 SkTDArray<SkBool8> fSaveIsSaveLayer; 164 SkAutoTDelete<SkCanvasDrawableList> fDrawableList; 165}; 166 167#endif//SkRecorder_DEFINED 168