SkPictureRecorder.h revision 643b8bd6617e333f7a970a57ad9166f3d6675d1a
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
15class SkCanvas;
16class SkPictureRecord;
17
18class SK_API SkPictureRecorder : SkNoncopyable {
19public:
20    SkPictureRecorder() : fCanvas(NULL) { }
21    ~SkPictureRecorder();
22
23    /** Returns the canvas that records the drawing commands.
24        @param width the base width for the picture, as if the recording
25                     canvas' bitmap had this width.
26        @param height the base width for the picture, as if the recording
27                     canvas' bitmap had this height.
28        @param bbhFactory factory to create desired acceleration structure
29        @param recordFlags optional flags that control recording.
30        @return the canvas.
31    */
32    // TODO: allow default parameters once the other beginRecoding entry point is gone
33    SkCanvas* beginRecording(int width, int height,
34                             SkBBHFactory* bbhFactory /* = NULL */,
35                             uint32_t recordFlags /* = 0 */);
36
37    /** Returns the recording canvas if one is active, or NULL if recording is
38        not active. This does not alter the refcnt on the canvas (if present).
39    */
40    SkCanvas* getRecordingCanvas();
41
42    /** Signal that the caller is done recording. This invalidates the canvas
43        returned by beginRecording/getRecordingCanvas, and returns the
44        created SkPicture. Note that the returned picture has its creation
45        ref which the caller must take ownership of.
46    */
47    SkPicture* endRecording();
48
49    /** Enable/disable all the picture recording optimizations (i.e.,
50        those in SkPictureRecord). It is mainly intended for testing the
51        existing optimizations (i.e., to actually have the pattern
52        appear in an .skp we have to disable the optimization). Call right
53        after 'beginRecording'.
54    */
55    void internalOnly_EnableOpts(bool enableOpts);
56
57private:
58#ifdef SK_BUILD_FOR_ANDROID
59    /** Replay the current (partially recorded) operation stream into
60        canvas. This call doesn't close the current recording.
61    */
62    friend class AndroidPicture;
63    friend class SkPictureRecorderReplayTester; // for unit testing
64    void partialReplay(SkCanvas* canvas) const;
65#endif
66
67    SkAutoTUnref<SkPicture> fPicture;
68    SkPictureRecord*        fCanvas;   // ref counted
69
70    typedef SkNoncopyable INHERITED;
71};
72
73#endif
74