| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 8 #include "cdl_picture_recorder.h" |
| 9 |
| 10 #if CDL_ENABLED |
| 11 |
| 12 #include "base/trace_event/trace_event.h" |
| 13 #include "third_party/skia/include/core/SkBBHFactory.h" |
| 14 #include "skia/ext/cdl_picture_buffer.h" |
| 15 |
| 16 #include "skia/ext/cdl_picture.h" |
| 17 #include "skia/ext/cdl_picture_recording_canvas.h" |
| 18 |
| 19 base::Lock CdlPictureRecorder::lock; |
| 20 std::shared_ptr<CdlPictureRecordingCanvas> CdlPictureRecorder::free_recorder; |
| 21 |
| 22 CdlPictureRecorder::CdlPictureRecorder() { |
| 23 fActivelyRecording = false; |
| 24 start_offset_ = 0; |
| 25 fFlags = 0; |
| 26 } |
| 27 CdlPictureRecorder::~CdlPictureRecorder() { |
| 28 if (fRecorder.get()) { |
| 29 base::AutoLock hold(lock); |
| 30 fRecorder.swap(free_recorder); |
| 31 } |
| 32 } |
| 33 |
| 34 CdlCanvas* CdlPictureRecorder::beginRecording(const SkRect& bounds, |
| 35 SkBBHFactory* bbhFactory, |
| 36 uint32_t recordFlags) { |
| 37 fCullRect = bounds; |
| 38 fFlags = recordFlags; |
| 39 |
| 40 // TODO(cdl): Painting is relying on a funky behavior of SkPictureRecorder; |
| 41 // calling beginRecording multiple times results in appending to the |
| 42 // existing SkRecord, but resetting the SkRecorder which seems wrong. |
| 43 if (fActivelyRecording) |
| 44 return fRecorder.get(); |
| 45 |
| 46 /* |
| 47 if (bbhFactory) { |
| 48 fBBH.reset((*bbhFactory)(cullRect)); |
| 49 SkASSERT(fBBH.get()); |
| 50 } |
| 51 */ |
| 52 |
| 53 // TRACE_EVENT_ASYNC_BEGIN0("cc", "CdlPictureRecorder::beginRecording", this); |
| 54 |
| 55 // Create new recorder only if it's above a threshold in size. |
| 56 if (!fRecord.get() || fRecord->getRecordOffset() >= 4096 - 256) |
| 57 fRecord.reset(new CdlPictureBuffer(bounds)); |
| 58 else |
| 59 fRecord->resetForNextPicture(bounds); |
| 60 |
| 61 start_offset_ = fRecord->getRecordOffset(); |
| 62 |
| 63 if (!fRecorder.get()) { |
| 64 base::AutoLock hold(lock); |
| 65 fRecorder.swap(free_recorder); |
| 66 } |
| 67 |
| 68 if (fRecorder.get()) { |
| 69 fRecorder->reset(fRecord.get(), bounds); |
| 70 } else { |
| 71 fRecorder.reset(new CdlPictureRecordingCanvas(fRecord.get(), bounds)); |
| 72 } |
| 73 |
| 74 fActivelyRecording = true; |
| 75 return this->getRecordingCanvas(); |
| 76 } |
| 77 |
| 78 CdlCanvas* CdlPictureRecorder::getRecordingCanvas() { |
| 79 return fActivelyRecording ? fRecorder.get() : nullptr; |
| 80 } |
| 81 |
| 82 sk_sp<CdlPicture> CdlPictureRecorder::finishRecordingAsPicture( |
| 83 uint32_t endFlags) { |
| 84 // TRACE_EVENT_ASYNC_END0("cc", "CdlPictureRecorder::beginRecording", this); |
| 85 // CHECK(fActivelyRecording); |
| 86 fActivelyRecording = false; |
| 87 |
| 88 fRecorder->restoreToCount( |
| 89 1); // If we were missing any restores, add them now. |
| 90 |
| 91 sk_sp<CdlPicture> pic = sk_make_sp<CdlPicture>( |
| 92 fRecord, fCullRect, start_offset_, fRecord->getRecordOffset()); |
| 93 return pic; |
| 94 } |
| 95 |
| 96 #endif // CDL_ENABLED |
| OLD | NEW |