paint_recorder.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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
  3. // found in the LICENSE file.
  4. #ifndef CC_PAINT_PAINT_RECORDER_H_
  5. #define CC_PAINT_PAINT_RECORDER_H_
  6. #include <memory>
  7. #include "base/compiler_specific.h"
  8. #include "cc/paint/display_item_list.h"
  9. #include "cc/paint/paint_record.h"
  10. #include "cc/paint/record_paint_canvas.h"
  11. namespace cc {
  12. class DisplayItemList;
  13. class CC_PAINT_EXPORT PaintRecorder {
  14. public:
  15. PaintRecorder();
  16. PaintRecorder(const PaintRecorder&) = delete;
  17. virtual ~PaintRecorder();
  18. PaintRecorder& operator=(const PaintRecorder&) = delete;
  19. PaintCanvas* beginRecording(const SkRect& bounds);
  20. // TODO(enne): should make everything go through the non-rect version.
  21. // See comments in RecordPaintCanvas ctor for why.
  22. PaintCanvas* beginRecording(SkScalar width, SkScalar height) {
  23. return beginRecording(SkRect::MakeWH(width, height));
  24. }
  25. // Only valid while recording.
  26. ALWAYS_INLINE RecordPaintCanvas* getRecordingCanvas() {
  27. return canvas_.get();
  28. }
  29. sk_sp<PaintRecord> finishRecordingAsPicture();
  30. bool ListHasDrawOps() const;
  31. // Ops with nested paint ops are considered as a single op.
  32. size_t num_paint_ops() const;
  33. size_t TotalOpCount() const { return display_item_list_->TotalOpCount(); }
  34. size_t OpBytesUsed() const { return display_item_list_->OpBytesUsed(); }
  35. protected:
  36. virtual std::unique_ptr<RecordPaintCanvas> CreateCanvas(DisplayItemList* list,
  37. const SkRect& bounds);
  38. private:
  39. scoped_refptr<DisplayItemList> display_item_list_;
  40. std::unique_ptr<RecordPaintCanvas> canvas_;
  41. };
  42. } // namespace cc
  43. #endif // CC_PAINT_PAINT_RECORDER_H_