blob: bd22d5560647447d5c65953bc562d70adb2ebcc5 [file] [log] [blame]
robertphillips@google.com770963f2014-04-18 18:04:41 +00001/*
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
djsollendbb7b302014-06-17 13:42:59 -070015#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
16namespace android {
17 class Picture;
18};
19#endif
20
robertphillips@google.com770963f2014-04-18 18:04:41 +000021class SkCanvas;
robertphillips643b8bd2014-06-08 05:55:05 -070022class SkPictureRecord;
mtklein887f3972014-06-17 12:08:15 -070023class SkRecord;
24class SkRecorder;
robertphillips@google.com770963f2014-04-18 18:04:41 +000025
26class SK_API SkPictureRecorder : SkNoncopyable {
27public:
Mike Kleinf22b6b52014-06-23 13:29:10 -040028 SkPictureRecorder();
robertphillips643b8bd2014-06-08 05:55:05 -070029 ~SkPictureRecorder();
30
robertphillips@google.com770963f2014-04-18 18:04:41 +000031 /** 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 */
robertphillips@google.com770963f2014-04-18 18:04:41 +000040 SkCanvas* beginRecording(int width, int height,
robertphillips9f1c2412014-06-09 06:25:34 -070041 SkBBHFactory* bbhFactory = NULL,
42 uint32_t recordFlags = 0);
robertphillips@google.com770963f2014-04-18 18:04:41 +000043
mtklein887f3972014-06-17 12:08:15 -070044 /** Same as beginRecording(), using a new faster backend. */
45 SkCanvas* EXPERIMENTAL_beginRecording(int width, int height,
46 SkBBHFactory* bbhFactory = NULL);
47
robertphillips@google.com770963f2014-04-18 18:04:41 +000048 /** 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 */
robertphillips643b8bd2014-06-08 05:55:05 -070051 SkCanvas* getRecordingCanvas();
robertphillips@google.com770963f2014-04-18 18:04:41 +000052
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 */
robertphillips643b8bd2014-06-08 05:55:05 -070058 SkPicture* endRecording();
robertphillips@google.com770963f2014-04-18 18:04:41 +000059
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 */
robertphillips643b8bd2014-06-08 05:55:05 -070066 void internalOnly_EnableOpts(bool enableOpts);
robertphillips@google.com770963f2014-04-18 18:04:41 +000067
68private:
mtklein887f3972014-06-17 12:08:15 -070069 void reset();
70
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000071 /** Replay the current (partially recorded) operation stream into
72 canvas. This call doesn't close the current recording.
73 */
djsollendbb7b302014-06-17 13:42:59 -070074#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
djsollendbb7b302014-06-17 13:42:59 -070075 friend class android::Picture;
76#endif
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000077 friend class SkPictureRecorderReplayTester; // for unit testing
commit-bot@chromium.org2246e322014-05-29 15:57:11 +000078 void partialReplay(SkCanvas* canvas) const;
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000079
Mike Kleinf22b6b52014-06-23 13:29:10 -040080 int fWidth;
81 int fHeight;
mtklein887f3972014-06-17 12:08:15 -070082
Mike Kleinf22b6b52014-06-23 13:29:10 -040083 // One of these two canvases will be non-NULL.
84 SkAutoTUnref<SkPictureRecord> fPictureRecord; // beginRecording()
85 SkAutoTUnref<SkRecorder> fRecorder; // EXPERIMENTAL_beginRecording()
mtklein887f3972014-06-17 12:08:15 -070086
Mike Kleinf22b6b52014-06-23 13:29:10 -040087 // Used by EXPERIMENTAL_beginRecording().
88 SkAutoTDelete<SkRecord> fRecord;
robertphillips@google.com770963f2014-04-18 18:04:41 +000089
90 typedef SkNoncopyable INHERITED;
91};
92
93#endif