blob: 3441a0dfeb265f14d4568d50af188b6fa1446553 [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
robertphillips82365912014-11-12 09:32:34 -08008#include "SkLayerInfo.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +00009#include "SkPictureRecorder.h"
mtklein887f3972014-06-17 12:08:15 -070010#include "SkRecord.h"
11#include "SkRecordDraw.h"
12#include "SkRecorder.h"
robertphillips81f71b62014-11-11 04:54:49 -080013#include "SkRecordOpts.h"
mtklein887f3972014-06-17 12:08:15 -070014#include "SkTypes.h"
robertphillips643b8bd2014-06-08 05:55:05 -070015
Mike Kleinf22b6b52014-06-23 13:29:10 -040016SkPictureRecorder::SkPictureRecorder() {}
mtklein887f3972014-06-17 12:08:15 -070017
Mike Kleinf22b6b52014-06-23 13:29:10 -040018SkPictureRecorder::~SkPictureRecorder() {}
robertphillips@google.com770963f2014-04-18 18:04:41 +000019
robertphillipsa8d7f0b2014-08-29 08:03:56 -070020SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height,
robertphillips@google.com770963f2014-04-18 18:04:41 +000021 SkBBHFactory* bbhFactory /* = NULL */,
22 uint32_t recordFlags /* = 0 */) {
robertphillips81f71b62014-11-11 04:54:49 -080023 fFlags = recordFlags;
robertphillipsa8d7f0b2014-08-29 08:03:56 -070024 fCullWidth = width;
25 fCullHeight = height;
mtklein887f3972014-06-17 12:08:15 -070026
bsalomon49f085d2014-09-05 13:34:00 -070027 if (bbhFactory) {
mtklein5ad6ee12014-08-11 08:08:43 -070028 fBBH.reset((*bbhFactory)(width, height));
bsalomon49f085d2014-09-05 13:34:00 -070029 SkASSERT(fBBH.get());
mtklein5ad6ee12014-08-11 08:08:43 -070030 }
31
Mike Kleinf22b6b52014-06-23 13:29:10 -040032 fRecord.reset(SkNEW(SkRecord));
33 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height)));
mtklein887f3972014-06-17 12:08:15 -070034 return this->getRecordingCanvas();
robertphillips643b8bd2014-06-08 05:55:05 -070035}
36
37SkCanvas* SkPictureRecorder::getRecordingCanvas() {
mtklein8e126562014-10-01 09:29:35 -070038 return fRecorder.get();
robertphillips643b8bd2014-06-08 05:55:05 -070039}
40
41SkPicture* SkPictureRecorder::endRecording() {
robertphillips81f71b62014-11-11 04:54:49 -080042 // TODO: delay as much of this work until just before first playback?
43 SkRecordOptimize(fRecord);
44
robertphillips82365912014-11-12 09:32:34 -080045 SkAutoTUnref<SkLayerInfo> saveLayerData;
robertphillips81f71b62014-11-11 04:54:49 -080046
47 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) {
robertphillips82365912014-11-12 09:32:34 -080048 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
robertphillips81f71b62014-11-11 04:54:49 -080049
robertphillips82365912014-11-12 09:32:34 -080050 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
robertphillips81f71b62014-11-11 04:54:49 -080051 }
robertphillips81f71b62014-11-11 04:54:49 -080052
53 if (fBBH.get()) {
54 SkRect cullRect = SkRect::MakeWH(fCullWidth, fCullHeight);
55
robertphillips81f71b62014-11-11 04:54:49 -080056 if (saveLayerData) {
57 SkRecordComputeLayers(cullRect, *fRecord, fBBH.get(), saveLayerData);
58 } else {
robertphillips81f71b62014-11-11 04:54:49 -080059 SkRecordFillBounds(cullRect, *fRecord, fBBH.get());
robertphillips81f71b62014-11-11 04:54:49 -080060 }
robertphillips81f71b62014-11-11 04:54:49 -080061 }
62
63 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, fRecord.detach(), fBBH.get()));
64
robertphillips81f71b62014-11-11 04:54:49 -080065 if (saveLayerData) {
66 pict->EXPERIMENTAL_addAccelData(saveLayerData);
67 }
robertphillips81f71b62014-11-11 04:54:49 -080068
69 return pict;
robertphillips643b8bd2014-06-08 05:55:05 -070070}
71
commit-bot@chromium.org2246e322014-05-29 15:57:11 +000072void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
mtklein887f3972014-06-17 12:08:15 -070073 if (NULL == canvas) {
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000074 return;
75 }
mtklein8e126562014-10-01 09:29:35 -070076 SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/);
commit-bot@chromium.org6d3eaea2014-05-27 23:41:45 +000077}