robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
robertphillips | 81f71b6 | 2014-11-11 04:54:49 -0800 | [diff] [blame^] | 8 | #if SK_SUPPORT_GPU |
| 9 | #include "GrPictureUtils.h" |
| 10 | #endif |
| 11 | |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 12 | #include "SkPictureRecorder.h" |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 13 | #include "SkRecord.h" |
| 14 | #include "SkRecordDraw.h" |
| 15 | #include "SkRecorder.h" |
robertphillips | 81f71b6 | 2014-11-11 04:54:49 -0800 | [diff] [blame^] | 16 | #include "SkRecordOpts.h" |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 17 | #include "SkTypes.h" |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 18 | |
Mike Klein | f22b6b5 | 2014-06-23 13:29:10 -0400 | [diff] [blame] | 19 | SkPictureRecorder::SkPictureRecorder() {} |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 20 | |
Mike Klein | f22b6b5 | 2014-06-23 13:29:10 -0400 | [diff] [blame] | 21 | SkPictureRecorder::~SkPictureRecorder() {} |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 22 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 23 | SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height, |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 24 | SkBBHFactory* bbhFactory /* = NULL */, |
| 25 | uint32_t recordFlags /* = 0 */) { |
robertphillips | 81f71b6 | 2014-11-11 04:54:49 -0800 | [diff] [blame^] | 26 | fFlags = recordFlags; |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 27 | fCullWidth = width; |
| 28 | fCullHeight = height; |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 29 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 30 | if (bbhFactory) { |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 31 | fBBH.reset((*bbhFactory)(width, height)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 32 | SkASSERT(fBBH.get()); |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Mike Klein | f22b6b5 | 2014-06-23 13:29:10 -0400 | [diff] [blame] | 35 | fRecord.reset(SkNEW(SkRecord)); |
| 36 | fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height))); |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 37 | return this->getRecordingCanvas(); |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
mtklein | 8e12656 | 2014-10-01 09:29:35 -0700 | [diff] [blame] | 41 | return fRecorder.get(); |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | SkPicture* SkPictureRecorder::endRecording() { |
robertphillips | 81f71b6 | 2014-11-11 04:54:49 -0800 | [diff] [blame^] | 45 | // 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; |
robertphillips | 643b8bd | 2014-06-08 05:55:05 -0700 | [diff] [blame] | 81 | } |
| 82 | |
commit-bot@chromium.org | 2246e32 | 2014-05-29 15:57:11 +0000 | [diff] [blame] | 83 | void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
mtklein | 887f397 | 2014-06-17 12:08:15 -0700 | [diff] [blame] | 84 | if (NULL == canvas) { |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 85 | return; |
| 86 | } |
mtklein | 8e12656 | 2014-10-01 09:29:35 -0700 | [diff] [blame] | 87 | SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/); |
commit-bot@chromium.org | 6d3eaea | 2014-05-27 23:41:45 +0000 | [diff] [blame] | 88 | } |