| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBBoxHierarchyRecord.h" | 8 #include "SkBBoxHierarchyRecord.h" |
| 9 #include "SkPictureRecord.h" | 9 #include "SkPictureRecord.h" |
| 10 #include "SkPictureRecorder.h" | 10 #include "SkPictureRecorder.h" |
| 11 #include "SkRecord.h" | 11 #include "SkRecord.h" |
| 12 #include "SkRecordDraw.h" | 12 #include "SkRecordDraw.h" |
| 13 #include "SkRecorder.h" | 13 #include "SkRecorder.h" |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 | 15 |
| 16 SkPictureRecorder::SkPictureRecorder() {} | 16 SkPictureRecorder::SkPictureRecorder() {} |
| 17 | 17 |
| 18 SkPictureRecorder::~SkPictureRecorder() {} | 18 SkPictureRecorder::~SkPictureRecorder() {} |
| 19 | 19 |
| 20 SkCanvas* SkPictureRecorder::beginRecording(int width, int height, | 20 SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height, |
| 21 SkBBHFactory* bbhFactory /* = NULL *
/, | 21 SkBBHFactory* bbhFactory /* = NULL *
/, |
| 22 uint32_t recordFlags /* = 0 */) { | 22 uint32_t recordFlags /* = 0 */) { |
| 23 #ifdef SK_PICTURE_USE_SK_RECORD | 23 #ifdef SK_PICTURE_USE_SK_RECORD |
| 24 return EXPERIMENTAL_beginRecording(width, height, bbhFactory); | 24 return EXPERIMENTAL_beginRecording(width, height, bbhFactory); |
| 25 #else | 25 #else |
| 26 return DEPRECATED_beginRecording(width, height, bbhFactory, recordFlags); | 26 return DEPRECATED_beginRecording(width, height, bbhFactory, recordFlags); |
| 27 #endif | 27 #endif |
| 28 } | 28 } |
| 29 | 29 |
| 30 SkCanvas* SkPictureRecorder::DEPRECATED_beginRecording(int width, int height, | 30 SkCanvas* SkPictureRecorder::DEPRECATED_beginRecording(SkScalar width, SkScalar
height, |
| 31 SkBBHFactory* bbhFactory
/* = NULL */, | 31 SkBBHFactory* bbhFactory
/* = NULL */, |
| 32 uint32_t recordFlags /* =
0 */) { | 32 uint32_t recordFlags /* =
0 */) { |
| 33 fWidth = width; | 33 fCullWidth = width; |
| 34 fHeight = height; | 34 fCullHeight = height; |
| 35 | 35 |
| 36 const SkISize size = SkISize::Make(width, height); | 36 const SkISize size = SkISize::Make(width, height); |
| 37 | 37 |
| 38 if (NULL != bbhFactory) { | 38 if (NULL != bbhFactory) { |
| 39 // We don't need to hold a ref on the BBH ourselves, but might as well f
or | 39 // We don't need to hold a ref on the BBH ourselves, but might as well f
or |
| 40 // consistency with EXPERIMENTAL_beginRecording(), which does need to. | 40 // consistency with EXPERIMENTAL_beginRecording(), which does need to. |
| 41 fBBH.reset((*bbhFactory)(width, height)); | 41 fBBH.reset((*bbhFactory)(width, height)); |
| 42 SkASSERT(NULL != fBBH.get()); | 42 SkASSERT(NULL != fBBH.get()); |
| 43 fPictureRecord.reset(SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlag
s, fBBH.get()))); | 43 fPictureRecord.reset(SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlag
s, fBBH.get()))); |
| 44 } else { | 44 } else { |
| 45 fPictureRecord.reset(SkNEW_ARGS(SkPictureRecord, (size, recordFlags))); | 45 fPictureRecord.reset(SkNEW_ARGS(SkPictureRecord, (size, recordFlags))); |
| 46 } | 46 } |
| 47 | 47 |
| 48 fPictureRecord->beginRecording(); | 48 fPictureRecord->beginRecording(); |
| 49 return this->getRecordingCanvas(); | 49 return this->getRecordingCanvas(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height, | 52 SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(SkScalar width, SkScala
r height, |
| 53 SkBBHFactory* bbhFactor
y /* = NULL */) { | 53 SkBBHFactory* bbhFactor
y /* = NULL */) { |
| 54 fWidth = width; | 54 fCullWidth = width; |
| 55 fHeight = height; | 55 fCullHeight = height; |
| 56 | 56 |
| 57 if (NULL != bbhFactory) { | 57 if (NULL != bbhFactory) { |
| 58 fBBH.reset((*bbhFactory)(width, height)); | 58 fBBH.reset((*bbhFactory)(width, height)); |
| 59 SkASSERT(NULL != fBBH.get()); | 59 SkASSERT(NULL != fBBH.get()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 fRecord.reset(SkNEW(SkRecord)); | 62 fRecord.reset(SkNEW(SkRecord)); |
| 63 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height))); | 63 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height))); |
| 64 return this->getRecordingCanvas(); | 64 return this->getRecordingCanvas(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 67 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
| 68 if (NULL != fRecorder.get()) { | 68 if (NULL != fRecorder.get()) { |
| 69 return fRecorder.get(); | 69 return fRecorder.get(); |
| 70 } | 70 } |
| 71 return fPictureRecord.get(); | 71 return fPictureRecord.get(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 SkPicture* SkPictureRecorder::endRecording() { | 74 SkPicture* SkPictureRecorder::endRecording() { |
| 75 SkPicture* picture = NULL; | 75 SkPicture* picture = NULL; |
| 76 | 76 |
| 77 if (NULL != fRecord.get()) { | 77 if (NULL != fRecord.get()) { |
| 78 picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord.detach(), fBBH
.get())); | 78 picture = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, |
| 79 fRecord.detach(), fBBH.get())); |
| 79 } | 80 } |
| 80 | 81 |
| 81 if (NULL != fPictureRecord.get()) { | 82 if (NULL != fPictureRecord.get()) { |
| 82 fPictureRecord->endRecording(); | 83 fPictureRecord->endRecording(); |
| 83 const bool deepCopyOps = false; | 84 const bool deepCopyOps = false; |
| 84 picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord.get(),
deepCopyOps)); | 85 picture = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, |
| 86 *fPictureRecord.get(), deepCopyOps)); |
| 85 } | 87 } |
| 86 | 88 |
| 87 return picture; | 89 return picture; |
| 88 } | 90 } |
| 89 | 91 |
| 90 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) { | 92 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) { |
| 91 if (NULL != fPictureRecord.get()) { | 93 if (NULL != fPictureRecord.get()) { |
| 92 fPictureRecord->internalOnly_EnableOpts(enableOpts); | 94 fPictureRecord->internalOnly_EnableOpts(enableOpts); |
| 93 } | 95 } |
| 94 } | 96 } |
| 95 | 97 |
| 96 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 98 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
| 97 if (NULL == canvas) { | 99 if (NULL == canvas) { |
| 98 return; | 100 return; |
| 99 } | 101 } |
| 100 | 102 |
| 101 if (NULL != fRecord.get()) { | 103 if (NULL != fRecord.get()) { |
| 102 SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/); | 104 SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/); |
| 103 } | 105 } |
| 104 | 106 |
| 105 if (NULL != fPictureRecord.get()) { | 107 if (NULL != fPictureRecord.get()) { |
| 106 const bool deepCopyOps = true; | 108 const bool deepCopyOps = true; |
| 107 SkPicture picture(fWidth, fHeight, *fPictureRecord.get(), deepCopyOps); | 109 SkPicture picture(fCullWidth, fCullHeight, |
| 110 *fPictureRecord.get(), deepCopyOps); |
| 108 picture.draw(canvas); | 111 picture.draw(canvas); |
| 109 } | 112 } |
| 110 } | 113 } |
| OLD | NEW |