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 ALWAYS_INLINE PaintCanvas* getRecordingCanvas() { | |
40 return canvas_.has_value() ? &canvas_.value() : nullptr; | |
41 } | |
42 | |
43 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPicture( | |
44 uint32_t endFlags = 0) { | |
danakj
2017/03/03 18:33:19
end_flags
| |
45 sk_sp<SkPicture> picture = recorder_.finishRecordingAsPicture(endFlags); | |
46 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); | |
47 } | |
48 | |
49 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPictureWithCull( | |
50 const SkRect& cullRect, | |
danakj
2017/03/03 18:33:19
cull_rect
| |
51 uint32_t endFlags = 0) { | |
danakj
2017/03/03 18:33:19
end_flags
| |
52 sk_sp<SkPicture> picture = | |
53 recorder_.finishRecordingAsPictureWithCull(cullRect, endFlags); | |
54 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); | |
55 } | |
56 | |
57 private: | |
58 SkPictureRecorder recorder_; | |
59 base::Optional<PaintCanvas> canvas_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); | |
62 }; | |
63 | |
64 } // namespace cc | |
13 | 65 |
14 #endif // CC_PAINT_PAINT_RECORDER_H_ | 66 #endif // CC_PAINT_PAINT_RECORDER_H_ |
OLD | NEW |