paint_recorder.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2015 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 UI_COMPOSITOR_PAINT_RECORDER_H_
  5. #define UI_COMPOSITOR_PAINT_RECORDER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "cc/paint/display_item_list.h"
  8. #include "cc/paint/record_paint_canvas.h"
  9. #include "ui/compositor/compositor_export.h"
  10. #include "ui/gfx/canvas.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. namespace gfx {
  13. class Canvas;
  14. }
  15. namespace ui {
  16. class PaintCache;
  17. class PaintContext;
  18. // A class to hide the complexity behind setting up a recording into a
  19. // DisplayItem. This is meant to be short-lived within the scope of recording
  20. // taking place, the DisplayItem should be removed from the PaintRecorder once
  21. // recording is complete and can be cached.
  22. class COMPOSITOR_EXPORT PaintRecorder {
  23. public:
  24. // The |cache| is owned by the caller and must be kept alive while
  25. // PaintRecorder is in use. Canvas is bounded by |recording_size|.
  26. PaintRecorder(const PaintContext& context,
  27. const gfx::Size& recording_size,
  28. float recording_scale_x,
  29. float recording_scale_y,
  30. PaintCache* cache);
  31. PaintRecorder(const PaintContext& context, const gfx::Size& recording_size);
  32. PaintRecorder(const PaintRecorder&) = delete;
  33. PaintRecorder& operator=(const PaintRecorder&) = delete;
  34. ~PaintRecorder();
  35. // Gets a gfx::Canvas for painting into.
  36. gfx::Canvas* canvas() { return &canvas_; }
  37. private:
  38. const PaintContext& context_;
  39. scoped_refptr<cc::DisplayItemList> local_list_;
  40. cc::RecordPaintCanvas record_canvas_;
  41. gfx::Canvas canvas_;
  42. raw_ptr<PaintCache> cache_;
  43. gfx::Size recording_size_;
  44. };
  45. } // namespace ui
  46. #endif // UI_COMPOSITOR_PAINT_RECORDER_H_