Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_PAINT_PAINT_RECORDER_H_ | 5 #ifndef CC_PAINT_PAINT_RECORDER_H_ |
| 6 #define CC_PAINT_PAINT_RECORDER_H_ | 6 #define CC_PAINT_PAINT_RECORDER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/optional.h" | |
| 12 #include "cc/paint/paint_canvas.h" | |
| 13 #include "cc/paint/paint_record.h" | |
| 8 #include "third_party/skia/include/core/SkPictureRecorder.h" | 14 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 9 | 15 |
| 10 namespace cc { | 16 namespace cc { |
| 11 using PaintRecorder = SkPictureRecorder; | 17 |
| 12 } | 18 class CC_PAINT_EXPORT PaintRecorder { |
| 19 public: | |
| 20 PaintRecorder(); | |
| 21 ~PaintRecorder(); | |
| 22 | |
| 23 ALWAYS_INLINE PaintCanvas* beginRecording(const SkRect& bounds) { | |
| 24 uint32_t record_flags = 0; | |
| 25 canvas_.emplace(recorder_.beginRecording(bounds, nullptr, record_flags)); | |
| 26 return getRecordingCanvas(); | |
| 27 } | |
| 28 | |
| 29 ALWAYS_INLINE PaintCanvas* beginRecording( | |
| 30 SkScalar width, | |
| 31 SkScalar height, | |
| 32 SkBBHFactory* rtree_factory = nullptr) { | |
| 33 uint32_t record_flags = 0; | |
| 34 canvas_.emplace( | |
| 35 recorder_.beginRecording(width, height, rtree_factory, record_flags)); | |
| 36 return getRecordingCanvas(); | |
| 37 } | |
| 38 | |
| 39 // Only valid between between and finish recording. | |
| 40 ALWAYS_INLINE PaintCanvas* getRecordingCanvas() { | |
| 41 return canvas_.has_value() ? &canvas_.value() : nullptr; | |
| 42 } | |
| 43 | |
| 44 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPicture( | |
| 45 uint32_t end_flags = 0) { | |
| 46 sk_sp<SkPicture> picture = recorder_.finishRecordingAsPicture(end_flags); | |
| 47 // Some users (e.g. printing) use the existence of the recording canvas | |
| 48 // to know if recording is finished, so reset it here. | |
| 49 canvas_.reset(); | |
|
enne (OOO)
2017/03/03 19:26:10
Apparently getRecordingCanvas is (reasonably) only
danakj
2017/03/03 19:27:22
Oh wild, glad Optional makes that easy.
| |
| 50 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); | |
| 51 } | |
| 52 | |
| 53 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPictureWithCull( | |
| 54 const SkRect& cull_rect, | |
| 55 uint32_t end_flags = 0) { | |
| 56 sk_sp<SkPicture> picture = | |
| 57 recorder_.finishRecordingAsPictureWithCull(cull_rect, end_flags); | |
| 58 canvas_.reset(); | |
| 59 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 SkPictureRecorder recorder_; | |
| 64 base::Optional<PaintCanvas> canvas_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); | |
| 67 }; | |
| 68 | |
| 69 } // namespace cc | |
| 13 | 70 |
| 14 #endif // CC_PAINT_PAINT_RECORDER_H_ | 71 #endif // CC_PAINT_PAINT_RECORDER_H_ |
| OLD | NEW |