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" | 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" |
| 11 #include "base/optional.h" | 11 #include "base/optional.h" |
| 12 #include "cc/paint/paint_canvas.h" | |
| 13 #include "cc/paint/paint_record.h" | 12 #include "cc/paint/paint_record.h" |
| 14 #include "cc/paint/skia_paint_canvas.h" | 13 #include "cc/paint/record_paint_canvas.h" |
| 15 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 16 | 14 |
| 17 namespace cc { | 15 namespace cc { |
| 18 | 16 |
| 17 class PaintOpBuffer; | |
| 18 | |
| 19 class CC_PAINT_EXPORT PaintRecorder { | 19 class CC_PAINT_EXPORT PaintRecorder { |
| 20 public: | 20 public: |
| 21 PaintRecorder(); | 21 PaintRecorder(); |
| 22 ~PaintRecorder(); | 22 ~PaintRecorder(); |
| 23 | 23 |
| 24 ALWAYS_INLINE PaintCanvas* beginRecording(const SkRect& bounds) { | 24 PaintCanvas* beginRecording(const SkRect& bounds); |
| 25 uint32_t record_flags = 0; | |
| 26 canvas_.emplace(recorder_.beginRecording(bounds, nullptr, record_flags)); | |
| 27 return getRecordingCanvas(); | |
| 28 } | |
| 29 | 25 |
| 30 ALWAYS_INLINE PaintCanvas* beginRecording(SkScalar width, SkScalar height) { | 26 // TODO(enne): should combine rect and non-rect beginRecording functions. |
| 31 uint32_t record_flags = 0; | 27 PaintCanvas* beginRecording(SkScalar width, SkScalar height) { |
| 32 canvas_.emplace( | 28 return beginRecording(SkRect::MakeWH(width, height)); |
| 33 recorder_.beginRecording(width, height, nullptr, record_flags)); | |
| 34 return getRecordingCanvas(); | |
| 35 } | 29 } |
| 36 | 30 |
| 37 // Only valid between between and finish recording. | 31 // Only valid between between and finish recording. |
| 38 ALWAYS_INLINE PaintCanvas* getRecordingCanvas() { | 32 ALWAYS_INLINE RecordPaintCanvas* getRecordingCanvas() { |
| 39 return canvas_.has_value() ? &canvas_.value() : nullptr; | 33 return canvas_.has_value() ? &canvas_.value() : nullptr; |
| 40 } | 34 } |
| 41 | 35 |
| 42 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPicture() { | 36 sk_sp<PaintRecord> finishRecordingAsPicture(); |
|
vmpstr
2017/03/28 18:27:15
nit: probably WARN_UNUSED_RESULT, but maybe that's
enne (OOO)
2017/03/28 19:28:05
Mmm, Canvas2DLayerBridge calls this and drops the
| |
| 43 sk_sp<SkPicture> picture = recorder_.finishRecordingAsPicture(); | |
| 44 // Some users (e.g. printing) use the existence of the recording canvas | |
| 45 // to know if recording is finished, so reset it here. | |
| 46 canvas_.reset(); | |
| 47 return sk_ref_sp(static_cast<PaintRecord*>(picture.get())); | |
| 48 } | |
| 49 | 37 |
| 50 private: | 38 private: |
| 51 SkPictureRecorder recorder_; | 39 sk_sp<PaintOpBuffer> buffer_; |
| 52 base::Optional<SkiaPaintCanvas> canvas_; | 40 base::Optional<RecordPaintCanvas> canvas_; |
| 53 | 41 |
| 54 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); | 42 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); |
| 55 }; | 43 }; |
| 56 | 44 |
| 57 } // namespace cc | 45 } // namespace cc |
| 58 | 46 |
| 59 #endif // CC_PAINT_PAINT_RECORDER_H_ | 47 #endif // CC_PAINT_PAINT_RECORDER_H_ |
| OLD | NEW |