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" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 canvas_.emplace( | 35 canvas_.emplace( |
36 recorder_.beginRecording(width, height, rtree_factory, record_flags)); | 36 recorder_.beginRecording(width, height, rtree_factory, record_flags)); |
37 return getRecordingCanvas(); | 37 return getRecordingCanvas(); |
38 } | 38 } |
39 | 39 |
40 // Only valid between between and finish recording. | 40 // Only valid between between and finish recording. |
41 ALWAYS_INLINE PaintCanvas* getRecordingCanvas() { | 41 ALWAYS_INLINE PaintCanvas* getRecordingCanvas() { |
42 return canvas_.has_value() ? &canvas_.value() : nullptr; | 42 return canvas_.has_value() ? &canvas_.value() : nullptr; |
43 } | 43 } |
44 | 44 |
45 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPicture( | 45 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPicture() { |
46 uint32_t end_flags = 0) { | 46 sk_sp<SkPicture> picture = recorder_.finishRecordingAsPicture(); |
47 sk_sp<SkPicture> picture = recorder_.finishRecordingAsPicture(end_flags); | |
48 // Some users (e.g. printing) use the existence of the recording canvas | 47 // Some users (e.g. printing) use the existence of the recording canvas |
49 // to know if recording is finished, so reset it here. | 48 // to know if recording is finished, so reset it here. |
50 canvas_.reset(); | 49 canvas_.reset(); |
51 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); | 50 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); |
52 } | 51 } |
53 | 52 |
54 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPictureWithCull( | 53 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPictureWithCull( |
55 const SkRect& cull_rect, | 54 const SkRect& cull_rect, |
56 uint32_t end_flags = 0) { | 55 uint32_t end_flags = 0) { |
57 sk_sp<SkPicture> picture = | 56 sk_sp<SkPicture> picture = |
58 recorder_.finishRecordingAsPictureWithCull(cull_rect, end_flags); | 57 recorder_.finishRecordingAsPictureWithCull(cull_rect, end_flags); |
59 canvas_.reset(); | 58 canvas_.reset(); |
60 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); | 59 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); |
61 } | 60 } |
62 | 61 |
63 private: | 62 private: |
64 SkPictureRecorder recorder_; | 63 SkPictureRecorder recorder_; |
65 base::Optional<SkiaPaintCanvas> canvas_; | 64 base::Optional<SkiaPaintCanvas> canvas_; |
66 | 65 |
67 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); | 66 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); |
68 }; | 67 }; |
69 | 68 |
70 } // namespace cc | 69 } // namespace cc |
71 | 70 |
72 #endif // CC_PAINT_PAINT_RECORDER_H_ | 71 #endif // CC_PAINT_PAINT_RECORDER_H_ |
OLD | NEW |