blob: f1423e3992e35bae425ef4d9c0fe38f3dafb0bce [file] [log] [blame]
robertphillips@google.com770963f2014-04-18 18:04:41 +00001/*
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
robertphillips643b8bd2014-06-08 05:55:05 -07008#include "SkBBoxHierarchyRecord.h"
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +00009#include "SkPicturePlayback.h"
robertphillips643b8bd2014-06-08 05:55:05 -070010#include "SkPictureRecord.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000011#include "SkPictureRecorder.h"
mtklein887f3972014-06-17 12:08:15 -070012#include "SkRecord.h"
13#include "SkRecordDraw.h"
14#include "SkRecorder.h"
15#include "SkTypes.h"
robertphillips643b8bd2014-06-08 05:55:05 -070016
17SkPictureRecorder::~SkPictureRecorder() {
mtklein887f3972014-06-17 12:08:15 -070018 this->reset();
19}
20
21void SkPictureRecorder::reset() {
22 SkSafeSetNull(fPictureRecord);
23 SkSafeSetNull(fRecorder);
24 SkDELETE(fRecord);
25 fRecord = NULL;
robertphillips643b8bd2014-06-08 05:55:05 -070026}
robertphillips@google.com770963f2014-04-18 18:04:41 +000027
28SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
29 SkBBHFactory* bbhFactory /* = NULL */,
30 uint32_t recordFlags /* = 0 */) {
mtklein887f3972014-06-17 12:08:15 -070031 this->reset(); // terminate any prior recording(s)
robertphillips0bdbea72014-06-11 11:37:55 -070032 fWidth = width;
33 fHeight = height;
robertphillips643b8bd2014-06-08 05:55:05 -070034
35 const SkISize size = SkISize::Make(width, height);
36
37 if (NULL != bbhFactory) {
38 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height));
39 SkASSERT(NULL != tree);
mtklein887f3972014-06-17 12:08:15 -070040 fPictureRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get()));
robertphillips643b8bd2014-06-08 05:55:05 -070041 } else {
mtklein887f3972014-06-17 12:08:15 -070042 fPictureRecord = SkNEW_ARGS(SkPictureRecord, (size, recordFlags));
robertphillips643b8bd2014-06-08 05:55:05 -070043 }
44
mtklein887f3972014-06-17 12:08:15 -070045 fPictureRecord->beginRecording();
46 return this->getRecordingCanvas();
47}
robertphillips643b8bd2014-06-08 05:55:05 -070048
mtklein887f3972014-06-17 12:08:15 -070049SkCanvas* 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();
robertphillips643b8bd2014-06-08 05:55:05 -070059}
60
61SkCanvas* SkPictureRecorder::getRecordingCanvas() {
mtklein887f3972014-06-17 12:08:15 -070062 if (NULL != fRecorder) {
63 return fRecorder;
64 }
65 return fPictureRecord;
robertphillips643b8bd2014-06-08 05:55:05 -070066}
67
68SkPicture* SkPictureRecorder::endRecording() {
mtklein887f3972014-06-17 12:08:15 -070069 SkPicture* picture = NULL;
70
71 if (NULL != fRecorder) {
72 // TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord));
73 // fRecord = NULL;
robertphillips643b8bd2014-06-08 05:55:05 -070074 }
75
mtklein887f3972014-06-17 12:08:15 -070076 if (NULL != fPictureRecord) {
77 fPictureRecord->endRecording();
78 const bool deepCopyOps = false;
79 picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord, deepCopyOps));
80 }
robertphillips643b8bd2014-06-08 05:55:05 -070081
mtklein887f3972014-06-17 12:08:15 -070082 this->reset();
83 return picture;
robertphillips643b8bd2014-06-08 05:55:05 -070084}
85
86void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) {
mtklein887f3972014-06-17 12:08:15 -070087 if (NULL != fPictureRecord) {
88 fPictureRecord->internalOnly_EnableOpts(enableOpts);
robertphillips643b8bd2014-06-08 05:55:05 -070089 }
robertphillips@google.com770963f2014-04-18 18:04:41 +000090}
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000091
commit-bot@chromium.org2246e322014-05-29 15:57:11 +000092void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
mtklein887f3972014-06-17 12:08:15 -070093 if (NULL == canvas) {
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000094 return;
95 }
96
mtklein887f3972014-06-17 12:08:15 -070097 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.org6d3eaea2014-05-27 23:41:45 +0000106}