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 SkPictureRecorder_DEFINED 9#define SkPictureRecorder_DEFINED 10 11#include "SkBBHFactory.h" 12#include "SkPicture.h" 13#include "SkRefCnt.h" 14 15#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 16namespace android { 17 class Picture; 18}; 19#endif 20 21class SkCanvas; 22class SkPictureRecord; 23class SkRecord; 24class SkRecorder; 25 26class SK_API SkPictureRecorder : SkNoncopyable { 27public: 28 SkPictureRecorder() : fPictureRecord(NULL), fRecorder(NULL), fRecord(NULL) { } 29 ~SkPictureRecorder(); 30 31 /** Returns the canvas that records the drawing commands. 32 @param width the base width for the picture, as if the recording 33 canvas' bitmap had this width. 34 @param height the base width for the picture, as if the recording 35 canvas' bitmap had this height. 36 @param bbhFactory factory to create desired acceleration structure 37 @param recordFlags optional flags that control recording. 38 @return the canvas. 39 */ 40 SkCanvas* beginRecording(int width, int height, 41 SkBBHFactory* bbhFactory = NULL, 42 uint32_t recordFlags = 0); 43 44 /** Same as beginRecording(), using a new faster backend. */ 45 SkCanvas* EXPERIMENTAL_beginRecording(int width, int height, 46 SkBBHFactory* bbhFactory = NULL); 47 48 /** Returns the recording canvas if one is active, or NULL if recording is 49 not active. This does not alter the refcnt on the canvas (if present). 50 */ 51 SkCanvas* getRecordingCanvas(); 52 53 /** Signal that the caller is done recording. This invalidates the canvas 54 returned by beginRecording/getRecordingCanvas, and returns the 55 created SkPicture. Note that the returned picture has its creation 56 ref which the caller must take ownership of. 57 */ 58 SkPicture* endRecording(); 59 60 /** Enable/disable all the picture recording optimizations (i.e., 61 those in SkPictureRecord). It is mainly intended for testing the 62 existing optimizations (i.e., to actually have the pattern 63 appear in an .skp we have to disable the optimization). Call right 64 after 'beginRecording'. 65 */ 66 void internalOnly_EnableOpts(bool enableOpts); 67 68private: 69 void reset(); 70 71 /** Replay the current (partially recorded) operation stream into 72 canvas. This call doesn't close the current recording. 73 */ 74#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 75 friend class android::Picture; 76#endif 77 friend class SkPictureRecorderReplayTester; // for unit testing 78 void partialReplay(SkCanvas* canvas) const; 79 80 int fWidth; 81 int fHeight; 82 83 // Both ref counted. One of these two will be non-null: 84 SkPictureRecord* fPictureRecord; // beginRecording() 85 SkRecorder* fRecorder; // EXPERIMENTAL_beginRecording() 86 87 // Not refcounted. Used by EXPERIMENTAL_beginRecording(). 88 SkRecord* fRecord; 89 90 typedef SkNoncopyable INHERITED; 91}; 92 93#endif 94