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 | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 31 | #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 | |
robertphillips | 81f71b6 | 2014-11-11 04:54:49 -0800 | [diff] [blame^] | 40 | 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.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 46 | /** Returns the canvas that records the drawing commands. |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 47 | @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.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 49 | @param bbhFactory factory to create desired acceleration structure |
| 50 | @param recordFlags optional flags that control recording. |
| 51 | @return the canvas. |
| 52 | */ |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 53 | SkCanvas* beginRecording(SkScalar width, SkScalar height, |
robertphillips | 9f1c241 | 2014-06-09 06:25:34 -0700 | [diff] [blame] | 54 | SkBBHFactory* bbhFactory = NULL, |
| 55 | uint32_t recordFlags = 0); |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 56 | |
| 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 | */ |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 60 | SkCanvas* getRecordingCanvas(); |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 61 | |
| 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 | */ |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 67 | SkPicture* endRecording(); |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 68 | |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 69 | private: |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 70 | void reset(); |
| 71 | |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 72 | /** Replay the current (partially recorded) operation stream into |
| 73 | canvas. This call doesn't close the current recording. |
| 74 | */ |
djsollen | dbb7b30 | 2014-06-17 13:42:59 -0700 | [diff] [blame] | 75 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
djsollen | dbb7b30 | 2014-06-17 13:42:59 -0700 | [diff] [blame] | 76 | friend class android::Picture; |
| 77 | #endif |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 78 | friend class SkPictureRecorderReplayTester; // for unit testing |
commit-bot@chromium.org | 2246e32 | 2014-05-29 15:57:11 +0000 | [diff] [blame] | 79 | void partialReplay(SkCanvas* canvas) const; |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 80 | |
robertphillips | 81f71b6 | 2014-11-11 04:54:49 -0800 | [diff] [blame^] | 81 | uint32_t fFlags; |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 82 | SkScalar fCullWidth; |
| 83 | SkScalar fCullHeight; |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 84 | SkAutoTUnref<SkBBoxHierarchy> fBBH; |
mtklein | 8e12656 | 2014-10-01 09:29:35 -0700 | [diff] [blame] | 85 | SkAutoTUnref<SkRecorder> fRecorder; |
| 86 | SkAutoTDelete<SkRecord> fRecord; |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 87 | |
| 88 | typedef SkNoncopyable INHERITED; |
| 89 | }; |
| 90 | |
| 91 | #endif |