2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkBBoxHierarchyRecord.h"
9 #include "SkPictureRecord.h"
10 #include "SkPictureRecorder.h"
12 #include "SkRecordDraw.h"
13 #include "SkRecorder.h"
16 SkPictureRecorder::SkPictureRecorder() {}
18 SkPictureRecorder::~SkPictureRecorder() {}
20 SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height,
21 SkBBHFactory* bbhFactory /* = NULL */,
22 uint32_t recordFlags /* = 0 */) {
23 #ifdef SK_PICTURE_USE_SK_RECORD
24 return EXPERIMENTAL_beginRecording(width, height, bbhFactory);
26 return DEPRECATED_beginRecording(width, height, bbhFactory, recordFlags);
30 SkCanvas* SkPictureRecorder::DEPRECATED_beginRecording(SkScalar width, SkScalar height,
31 SkBBHFactory* bbhFactory /* = NULL */,
32 uint32_t recordFlags /* = 0 */) {
36 const SkISize size = SkISize::Make(width, height);
39 // We don't need to hold a ref on the BBH ourselves, but might as well for
40 // consistency with EXPERIMENTAL_beginRecording(), which does need to.
41 fBBH.reset((*bbhFactory)(width, height));
43 fPictureRecord.reset(SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, fBBH.get())));
45 fPictureRecord.reset(SkNEW_ARGS(SkPictureRecord, (size, recordFlags)));
48 fPictureRecord->beginRecording();
49 return this->getRecordingCanvas();
52 SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(SkScalar width, SkScalar height,
53 SkBBHFactory* bbhFactory /* = NULL */) {
58 fBBH.reset((*bbhFactory)(width, height));
62 fRecord.reset(SkNEW(SkRecord));
63 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height)));
64 return this->getRecordingCanvas();
67 SkCanvas* SkPictureRecorder::getRecordingCanvas() {
68 if (fRecorder.get()) {
69 return fRecorder.get();
71 return fPictureRecord.get();
74 SkPicture* SkPictureRecorder::endRecording() {
75 SkPicture* picture = NULL;
78 picture = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight,
79 fRecord.detach(), fBBH.get()));
82 if (fPictureRecord.get()) {
83 fPictureRecord->endRecording();
84 const bool deepCopyOps = false;
85 picture = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight,
86 *fPictureRecord.get(), deepCopyOps));
92 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) {
93 if (fPictureRecord.get()) {
94 fPictureRecord->internalOnly_EnableOpts(enableOpts);
98 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
104 SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/);
107 if (fPictureRecord.get()) {
108 const bool deepCopyOps = true;
109 SkPicture picture(fCullWidth, fCullHeight,
110 *fPictureRecord.get(), deepCopyOps);
111 picture.playback(canvas);