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 | |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 8 | #include "SkBBoxHierarchyRecord.h" |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 9 | #include "SkPicturePlayback.h" |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 10 | #include "SkPictureRecord.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 11 | #include "SkPictureRecorder.h" |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 12 | #include "SkRecord.h" |
| 13 | #include "SkRecordDraw.h" |
| 14 | #include "SkRecorder.h" |
| 15 | #include "SkTypes.h" |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 16 | |
| 17 | SkPictureRecorder::~SkPictureRecorder() { |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 18 | this->reset(); |
| 19 | } |
| 20 | |
| 21 | void SkPictureRecorder::reset() { |
| 22 | SkSafeSetNull(fPictureRecord); |
| 23 | SkSafeSetNull(fRecorder); |
| 24 | SkDELETE(fRecord); |
| 25 | fRecord = NULL; |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 26 | } |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 27 | |
| 28 | SkCanvas* SkPictureRecorder::beginRecording(int width, int height, |
| 29 | SkBBHFactory* bbhFactory /* = NULL */, |
| 30 | uint32_t recordFlags /* = 0 */) { |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 31 | this->reset(); // terminate any prior recording(s) |
robertphillips | 0bdbea7 | 2014-06-11 11:37:55 -0700 | [diff] [blame] | 32 | fWidth = width; |
| 33 | fHeight = height; |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 34 | |
| 35 | const SkISize size = SkISize::Make(width, height); |
| 36 | |
| 37 | if (NULL != bbhFactory) { |
| 38 | SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height)); |
| 39 | SkASSERT(NULL != tree); |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 40 | fPictureRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get())); |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 41 | } else { |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 42 | fPictureRecord = SkNEW_ARGS(SkPictureRecord, (size, recordFlags)); |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 43 | } |
| 44 | |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 45 | fPictureRecord->beginRecording(); |
| 46 | return this->getRecordingCanvas(); |
| 47 | } |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 48 | |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 49 | SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height, |
| 50 | SkBBHFactory* bbhFactory /* = NULL */) { |
| 51 | this->reset(); |
| 52 | fWidth = width; |
| 53 | fHeight = height; |
| 54 | |
| 55 | // TODO: plumb bbhFactory through |
| 56 | fRecord = SkNEW(SkRecord); |
| 57 | fRecorder = SkNEW_ARGS(SkRecorder, (fRecord, width, height)); |
| 58 | return this->getRecordingCanvas(); |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 62 | if (NULL != fRecorder) { |
| 63 | return fRecorder; |
| 64 | } |
| 65 | return fPictureRecord; |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | SkPicture* SkPictureRecorder::endRecording() { |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 69 | SkPicture* picture = NULL; |
| 70 | |
| 71 | if (NULL != fRecorder) { |
| 72 | // TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord)); |
| 73 | // fRecord = NULL; |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 74 | } |
| 75 | |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 76 | if (NULL != fPictureRecord) { |
| 77 | fPictureRecord->endRecording(); |
| 78 | const bool deepCopyOps = false; |
| 79 | picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord, deepCopyOps)); |
| 80 | } |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 81 | |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 82 | this->reset(); |
| 83 | return picture; |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) { |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 87 | if (NULL != fPictureRecord) { |
| 88 | fPictureRecord->internalOnly_EnableOpts(enableOpts); |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 89 | } |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 90 | } |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 91 | |
commit-bot@chromium.org | 2246e32 | 2014-05-29 15:57:11 +0000 | [diff] [blame] | 92 | void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 93 | if (NULL == canvas) { |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 94 | return; |
| 95 | } |
| 96 | |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame^] | 97 | if (NULL != fRecorder) { |
| 98 | SkRecordDraw(*fRecord, canvas); |
| 99 | } |
| 100 | |
| 101 | if (NULL != fPictureRecord) { |
| 102 | const bool deepCopyOps = true; |
| 103 | SkPicture picture(fWidth, fHeight, *fPictureRecord, deepCopyOps); |
| 104 | picture.draw(canvas); |
| 105 | } |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 106 | } |