robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 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 | |
djsollen | dbb7b30 | 2014-06-17 13:42:59 -0700 | [diff] [blame] | 15 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 16 | namespace android { |
| 17 | class Picture; |
| 18 | }; |
| 19 | #endif |
| 20 | |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 21 | class SkCanvas; |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 22 | class SkPictureRecord; |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 23 | class SkRecord; |
| 24 | class SkRecorder; |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 25 | |
| 26 | class SK_API SkPictureRecorder : SkNoncopyable { |
| 27 | public: |
Mike Klein | f22b6b5 | 2014-06-23 13:29:10 -0400 | [diff] [blame^] | 28 | SkPictureRecorder(); |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 29 | ~SkPictureRecorder(); |
| 30 | |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 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 | */ |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 40 | SkCanvas* beginRecording(int width, int height, |
robertphillips | 9f1c241 | 2014-06-09 06:25:34 -0700 | [diff] [blame] | 41 | SkBBHFactory* bbhFactory = NULL, |
| 42 | uint32_t recordFlags = 0); |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 43 | |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 44 | /** Same as beginRecording(), using a new faster backend. */ |
| 45 | SkCanvas* EXPERIMENTAL_beginRecording(int width, int height, |
| 46 | SkBBHFactory* bbhFactory = NULL); |
| 47 | |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 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 | */ |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 51 | SkCanvas* getRecordingCanvas(); |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 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 | */ |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 58 | SkPicture* endRecording(); |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 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 | */ |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 66 | void internalOnly_EnableOpts(bool enableOpts); |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 67 | |
| 68 | private: |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 69 | void reset(); |
| 70 | |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 71 | /** Replay the current (partially recorded) operation stream into |
| 72 | canvas. This call doesn't close the current recording. |
| 73 | */ |
djsollen | dbb7b30 | 2014-06-17 13:42:59 -0700 | [diff] [blame] | 74 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
djsollen | dbb7b30 | 2014-06-17 13:42:59 -0700 | [diff] [blame] | 75 | friend class android::Picture; |
| 76 | #endif |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 77 | friend class SkPictureRecorderReplayTester; // for unit testing |
commit-bot@chromium.org | 2246e32 | 2014-05-29 15:57:11 +0000 | [diff] [blame] | 78 | void partialReplay(SkCanvas* canvas) const; |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 79 | |
Mike Klein | f22b6b5 | 2014-06-23 13:29:10 -0400 | [diff] [blame^] | 80 | int fWidth; |
| 81 | int fHeight; |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 82 | |
Mike Klein | f22b6b5 | 2014-06-23 13:29:10 -0400 | [diff] [blame^] | 83 | // One of these two canvases will be non-NULL. |
| 84 | SkAutoTUnref<SkPictureRecord> fPictureRecord; // beginRecording() |
| 85 | SkAutoTUnref<SkRecorder> fRecorder; // EXPERIMENTAL_beginRecording() |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 86 | |
Mike Klein | f22b6b5 | 2014-06-23 13:29:10 -0400 | [diff] [blame^] | 87 | // Used by EXPERIMENTAL_beginRecording(). |
| 88 | SkAutoTDelete<SkRecord> fRecord; |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 89 | |
| 90 | typedef SkNoncopyable INHERITED; |
| 91 | }; |
| 92 | |
| 93 | #endif |