canvas_painter.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_CANVAS_PAINTER_H_
  5. #define UI_COMPOSITOR_CANVAS_PAINTER_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "third_party/skia/include/core/SkBitmap.h"
  9. #include "third_party/skia/include/core/SkColor.h"
  10. #include "ui/compositor/compositor_export.h"
  11. #include "ui/compositor/paint_context.h"
  12. #include "ui/gfx/geometry/rect.h"
  13. namespace cc {
  14. class DisplayItemList;
  15. }
  16. namespace ui {
  17. // This class provides a simple helper for rasterizing from a PaintContext
  18. // interface directly into a bitmap. After constructing an instance of a
  19. // CanvasPainter, the context() can be used to do painting using the normal
  20. // composited paint paths. When the painter is destroyed, any painting done
  21. // with the context() will be rastered into the provided output bitmap.
  22. //
  23. // TODO(enne): rename this class to be PaintContextRasterizer or some such.
  24. class COMPOSITOR_EXPORT CanvasPainter {
  25. public:
  26. CanvasPainter(SkBitmap* output,
  27. const gfx::Size& output_size,
  28. float device_scale_factor,
  29. SkColor clear_color,
  30. bool is_pixel_canvas);
  31. CanvasPainter(const CanvasPainter&) = delete;
  32. CanvasPainter& operator=(const CanvasPainter&) = delete;
  33. ~CanvasPainter();
  34. const PaintContext& context() const { return context_; }
  35. private:
  36. friend class CanvasPainterTest;
  37. const raw_ptr<SkBitmap> output_;
  38. const gfx::Size pixel_output_size_;
  39. const float raster_scale_;
  40. const SkColor clear_color_;
  41. scoped_refptr<cc::DisplayItemList> list_;
  42. PaintContext context_;
  43. };
  44. } // namespace ui
  45. #endif // UI_COMPOSITOR_CANVAS_PAINTER_H_