| 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 make everything go through the non-rect version. |
| 31 uint32_t record_flags = 0; | 27 // See comments in RecordPaintCanvas ctor for why. |
| 32 canvas_.emplace( | 28 PaintCanvas* beginRecording(SkScalar width, SkScalar height) { |
| 33 recorder_.beginRecording(width, height, nullptr, record_flags)); | 29 return beginRecording(SkRect::MakeWH(width, height)); |
| 34 return getRecordingCanvas(); | |
| 35 } | 30 } |
| 36 | 31 |
| 37 // Only valid between between and finish recording. | 32 // Only valid between between and finish recording. |
| 38 ALWAYS_INLINE PaintCanvas* getRecordingCanvas() { | 33 ALWAYS_INLINE RecordPaintCanvas* getRecordingCanvas() { |
| 39 return canvas_.has_value() ? &canvas_.value() : nullptr; | 34 return canvas_.has_value() ? &canvas_.value() : nullptr; |
| 40 } | 35 } |
| 41 | 36 |
| 42 ALWAYS_INLINE sk_sp<PaintRecord> finishRecordingAsPicture() { | 37 sk_sp<PaintRecord> finishRecordingAsPicture(); |
| 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 | 38 |
| 50 private: | 39 private: |
| 51 SkPictureRecorder recorder_; | 40 sk_sp<PaintOpBuffer> buffer_; |
| 52 base::Optional<SkiaPaintCanvas> canvas_; | 41 base::Optional<RecordPaintCanvas> canvas_; |
| 53 | 42 |
| 54 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); | 43 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); |
| 55 }; | 44 }; |
| 56 | 45 |
| 57 } // namespace cc | 46 } // namespace cc |
| 58 | 47 |
| 59 #endif // CC_PAINT_PAINT_RECORDER_H_ | 48 #endif // CC_PAINT_PAINT_RECORDER_H_ |
| OLD | NEW |