SkRecorder.h revision 9db912c2ac2ab53bc24f2d50a3e5a80162051dcc
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 "SkBigPicture.h" 12#include "SkCanvas.h" 13#include "SkMiniRecorder.h" 14#include "SkRecord.h" 15#include "SkRecords.h" 16#include "SkTDArray.h" 17 18class SkBBHFactory; 19 20class SkDrawableList : SkNoncopyable { 21public: 22 ~SkDrawableList(); 23 24 int count() const { return fArray.count(); } 25 SkDrawable* const* begin() const { return fArray.begin(); } 26 27 void append(SkDrawable* drawable); 28 29 // Return a new or ref'd array of pictures that were snapped from our drawables. 30 SkBigPicture::SnapshotArray* newDrawableSnapshot(); 31 32private: 33 SkTDArray<SkDrawable*> fArray; 34}; 35 36// SkRecorder provides an SkCanvas interface for recording into an SkRecord. 37 38class SkRecorder : public SkCanvas { 39public: 40 // Does not take ownership of the SkRecord. 41 SkRecorder(SkRecord*, int width, int height, SkMiniRecorder* = nullptr); // legacy version 42 SkRecorder(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr); 43 44 void reset(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr); 45 46 size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; } 47 48 SkDrawableList* getDrawableList() const { return fDrawableList.get(); } 49 SkDrawableList* detachDrawableList() { return fDrawableList.detach(); } 50 51 // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail. 52 void forgetRecord(); 53 54 void willSave() override; 55 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) override; 56 void willRestore() override {} 57 void didRestore() override; 58 59 void didConcat(const SkMatrix&) override; 60 void didSetMatrix(const SkMatrix&) override; 61 62 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; 63 void onDrawDrawable(SkDrawable*) override; 64 void onDrawText(const void* text, 65 size_t byteLength, 66 SkScalar x, 67 SkScalar y, 68 const SkPaint& paint) override; 69 void onDrawPosText(const void* text, 70 size_t byteLength, 71 const SkPoint pos[], 72 const SkPaint& paint) override; 73 void onDrawPosTextH(const void* text, 74 size_t byteLength, 75 const SkScalar xpos[], 76 SkScalar constY, 77 const SkPaint& paint) override; 78 void onDrawTextOnPath(const void* text, 79 size_t byteLength, 80 const SkPath& path, 81 const SkMatrix* matrix, 82 const SkPaint& paint) override; 83 void onDrawTextBlob(const SkTextBlob* blob, 84 SkScalar x, 85 SkScalar y, 86 const SkPaint& paint) override; 87 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 88 const SkPoint texCoords[4], SkXfermode* xmode, 89 const SkPaint& paint) override; 90 91 void onDrawPaint(const SkPaint&) override; 92 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override; 93 void onDrawRect(const SkRect&, const SkPaint&) override; 94 void onDrawOval(const SkRect&, const SkPaint&) override; 95 void onDrawRRect(const SkRRect&, const SkPaint&) override; 96 void onDrawPath(const SkPath&, const SkPaint&) override; 97 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override; 98 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, 99 DrawBitmapRectFlags flags) override; 100 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override; 101 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, 102 const SkPaint*) override; 103 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, 104 const SkPaint*) override; 105 void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) override; 106 void onDrawVertices(VertexMode vmode, int vertexCount, 107 const SkPoint vertices[], const SkPoint texs[], 108 const SkColor colors[], SkXfermode* xmode, 109 const uint16_t indices[], int indexCount, 110 const SkPaint&) override; 111 112 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override; 113 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override; 114 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) override; 115 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override; 116 117 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; 118 119 void beginCommentGroup(const char*) override; 120 void addComment(const char*, const char*) override; 121 void endCommentGroup() override; 122 123 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override { return NULL; } 124 125 void flushMiniRecorder(); 126 127private: 128 template <typename T> 129 T* copy(const T*); 130 131 template <typename T> 132 T* copy(const T[], size_t count); 133 134 SkIRect devBounds() const { 135 SkIRect devBounds; 136 this->getClipDeviceBounds(&devBounds); 137 return devBounds; 138 } 139 140 size_t fApproxBytesUsedBySubPictures; 141 SkRecord* fRecord; 142 SkAutoTDelete<SkDrawableList> fDrawableList; 143 144 SkMiniRecorder* fMiniRecorder; 145}; 146 147#endif//SkRecorder_DEFINED 148