blob: 2985b2dfff4facbc1a77eba13ab3b19b484e2ba8 [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
robertphillips81f71b62014-11-11 04:54:49 -08008#if SK_SUPPORT_GPU
9#include "GrPictureUtils.h"
10#endif
11
robertphillips@google.com770963f2014-04-18 18:04:41 +000012#include "SkPictureRecorder.h"
mtklein887f3972014-06-17 12:08:15 -070013#include "SkRecord.h"
14#include "SkRecordDraw.h"
15#include "SkRecorder.h"
robertphillips81f71b62014-11-11 04:54:49 -080016#include "SkRecordOpts.h"
mtklein887f3972014-06-17 12:08:15 -070017#include "SkTypes.h"
robertphillips643b8bd2014-06-08 05:55:05 -070018
Mike Kleinf22b6b52014-06-23 13:29:10 -040019SkPictureRecorder::SkPictureRecorder() {}
mtklein887f3972014-06-17 12:08:15 -070020
Mike Kleinf22b6b52014-06-23 13:29:10 -040021SkPictureRecorder::~SkPictureRecorder() {}
robertphillips@google.com770963f2014-04-18 18:04:41 +000022
robertphillipsa8d7f0b2014-08-29 08:03:56 -070023SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height,
robertphillips@google.com770963f2014-04-18 18:04:41 +000024 SkBBHFactory* bbhFactory /* = NULL */,
25 uint32_t recordFlags /* = 0 */) {
robertphillips81f71b62014-11-11 04:54:49 -080026 fFlags = recordFlags;
robertphillipsa8d7f0b2014-08-29 08:03:56 -070027 fCullWidth = width;
28 fCullHeight = height;
mtklein887f3972014-06-17 12:08:15 -070029
bsalomon49f085d2014-09-05 13:34:00 -070030 if (bbhFactory) {
mtklein5ad6ee12014-08-11 08:08:43 -070031 fBBH.reset((*bbhFactory)(width, height));
bsalomon49f085d2014-09-05 13:34:00 -070032 SkASSERT(fBBH.get());
mtklein5ad6ee12014-08-11 08:08:43 -070033 }
34
Mike Kleinf22b6b52014-06-23 13:29:10 -040035 fRecord.reset(SkNEW(SkRecord));
36 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height)));
mtklein887f3972014-06-17 12:08:15 -070037 return this->getRecordingCanvas();
robertphillips643b8bd2014-06-08 05:55:05 -070038}
39
40SkCanvas* SkPictureRecorder::getRecordingCanvas() {
mtklein8e126562014-10-01 09:29:35 -070041 return fRecorder.get();
robertphillips643b8bd2014-06-08 05:55:05 -070042}
43
44SkPicture* SkPictureRecorder::endRecording() {
robertphillips81f71b62014-11-11 04:54:49 -080045 // TODO: delay as much of this work until just before first playback?
46 SkRecordOptimize(fRecord);
47
48#if SK_SUPPORT_GPU
49 SkAutoTUnref<GrAccelData> saveLayerData;
50
51 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) {
52 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
53
54 saveLayerData.reset(SkNEW_ARGS(GrAccelData, (key)));
55 }
56#endif
57
58 if (fBBH.get()) {
59 SkRect cullRect = SkRect::MakeWH(fCullWidth, fCullHeight);
60
61#if SK_SUPPORT_GPU
62 if (saveLayerData) {
63 SkRecordComputeLayers(cullRect, *fRecord, fBBH.get(), saveLayerData);
64 } else {
65#endif
66 SkRecordFillBounds(cullRect, *fRecord, fBBH.get());
67#if SK_SUPPORT_GPU
68 }
69#endif
70 }
71
72 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, fRecord.detach(), fBBH.get()));
73
74#if SK_SUPPORT_GPU
75 if (saveLayerData) {
76 pict->EXPERIMENTAL_addAccelData(saveLayerData);
77 }
78#endif
79
80 return pict;
robertphillips643b8bd2014-06-08 05:55:05 -070081}
82
commit-bot@chromium.org2246e322014-05-29 15:57:11 +000083void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
mtklein887f3972014-06-17 12:08:15 -070084 if (NULL == canvas) {
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000085 return;
86 }
mtklein8e126562014-10-01 09:29:35 -070087 SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/);
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000088}