blob: de216b4e5be6f08f02ce2db76625f3e18266aaf1 [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
robertphillipsa8d7f0b2014-08-29 08:03:56 -070031#ifdef SK_LEGACY_PICTURE_SIZE_API
32 SkCanvas* beginRecording(int width, int height,
33 SkBBHFactory* bbhFactory = NULL,
34 uint32_t recordFlags = 0) {
35 return this->beginRecording(SkIntToScalar(width), SkIntToScalar(height),
36 bbhFactory, recordFlags);
37 }
38#endif
39
robertphillips81f71b62014-11-11 04:54:49 -080040 enum RecordFlags {
41 // This flag indicates that, if some BHH is being computed, saveLayer
42 // information should also be extracted at the same time.
43 kComputeSaveLayerInfo_RecordFlag = 0x01
44 };
45
robertphillips@google.com770963f2014-04-18 18:04:41 +000046 /** Returns the canvas that records the drawing commands.
robertphillipsa8d7f0b2014-08-29 08:03:56 -070047 @param width the width of the cull rect used when recording this picture.
48 @param height the height of the cull rect used when recording this picture.
robertphillips@google.com770963f2014-04-18 18:04:41 +000049 @param bbhFactory factory to create desired acceleration structure
50 @param recordFlags optional flags that control recording.
51 @return the canvas.
52 */
robertphillipsa8d7f0b2014-08-29 08:03:56 -070053 SkCanvas* beginRecording(SkScalar width, SkScalar height,
robertphillips9f1c2412014-06-09 06:25:34 -070054 SkBBHFactory* bbhFactory = NULL,
55 uint32_t recordFlags = 0);
robertphillips@google.com770963f2014-04-18 18:04:41 +000056
57 /** Returns the recording canvas if one is active, or NULL if recording is
58 not active. This does not alter the refcnt on the canvas (if present).
59 */
robertphillips643b8bd2014-06-08 05:55:05 -070060 SkCanvas* getRecordingCanvas();
robertphillips@google.com770963f2014-04-18 18:04:41 +000061
62 /** Signal that the caller is done recording. This invalidates the canvas
63 returned by beginRecording/getRecordingCanvas, and returns the
64 created SkPicture. Note that the returned picture has its creation
65 ref which the caller must take ownership of.
66 */
robertphillips643b8bd2014-06-08 05:55:05 -070067 SkPicture* endRecording();
robertphillips@google.com770963f2014-04-18 18:04:41 +000068
robertphillips@google.com770963f2014-04-18 18:04:41 +000069private:
mtklein887f3972014-06-17 12:08:15 -070070 void reset();
71
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000072 /** Replay the current (partially recorded) operation stream into
73 canvas. This call doesn't close the current recording.
74 */
djsollendbb7b302014-06-17 13:42:59 -070075#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
djsollendbb7b302014-06-17 13:42:59 -070076 friend class android::Picture;
77#endif
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000078 friend class SkPictureRecorderReplayTester; // for unit testing
commit-bot@chromium.org2246e322014-05-29 15:57:11 +000079 void partialReplay(SkCanvas* canvas) const;
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000080
robertphillips81f71b62014-11-11 04:54:49 -080081 uint32_t fFlags;
robertphillipsa8d7f0b2014-08-29 08:03:56 -070082 SkScalar fCullWidth;
83 SkScalar fCullHeight;
mtklein5ad6ee12014-08-11 08:08:43 -070084 SkAutoTUnref<SkBBoxHierarchy> fBBH;
mtklein8e126562014-10-01 09:29:35 -070085 SkAutoTUnref<SkRecorder> fRecorder;
86 SkAutoTDelete<SkRecord> fRecord;
robertphillips@google.com770963f2014-04-18 18:04:41 +000087
88 typedef SkNoncopyable INHERITED;
89};
90
91#endif