OLD | NEW |
(Empty) | |
| 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 |
| 5 #ifndef UI_COMPOSITOR_PAINT_RECORDER_H_ |
| 6 #define UI_COMPOSITOR_PAINT_RECORDER_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "skia/ext/refptr.h" |
| 10 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 11 #include "ui/compositor/compositor_export.h" |
| 12 |
| 13 namespace cc { |
| 14 class DisplayItemList; |
| 15 class DrawingDisplayItem; |
| 16 } |
| 17 |
| 18 namespace gfx { |
| 19 class Canvas; |
| 20 class Rect; |
| 21 } |
| 22 |
| 23 class SkCanvas; |
| 24 |
| 25 namespace ui { |
| 26 |
| 27 // A class to hide the complexity behind setting up a recording into an |
| 28 // SkPicture. This is meant to be short-lived within the scope of recording |
| 29 // taking place, the SkPicture should be removed from the PaintRecorder once |
| 30 // recording is complete and can be cached. |
| 31 class COMPOSITOR_EXPORT PaintRecorder { |
| 32 public: |
| 33 // The |recording_bounds| are in the space of the ui::Layer that the |
| 34 // recording is being done in. |
| 35 PaintRecorder(const gfx::Rect& recording_bounds, float device_scale_factor); |
| 36 ~PaintRecorder(); |
| 37 |
| 38 // Gets the SkCanvas for the recording. Any operations done on this canvas |
| 39 // will be saved in the resulting SkPicture. |
| 40 SkCanvas* skcanvas() { return skcanvas_.get(); } |
| 41 |
| 42 // Gets a gfx::Canvas wrapping the SkCanvas for convenience methods. |
| 43 gfx::Canvas* canvas() { return canvas_.get(); } |
| 44 |
| 45 // Ends recording and returns the DisplayItem from the object. Any use of the |
| 46 // canvas after calling this would be lost or undefined. |
| 47 scoped_ptr<cc::DrawingDisplayItem> TakeDisplayItem(); |
| 48 |
| 49 // A helper method for TakeDisplayItem(), when caching the SkPicture is not |
| 50 // required, that inserts it directly into a DisplayItemList. |
| 51 void AppendDisplayItem(cc::DisplayItemList* list); |
| 52 |
| 53 private: |
| 54 float device_scale_factor_; |
| 55 SkPictureRecorder recorder_; |
| 56 skia::RefPtr<SkCanvas> skcanvas_; |
| 57 scoped_ptr<gfx::Canvas> canvas_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(PaintRecorder); |
| 60 }; |
| 61 |
| 62 } // namespace ui |
| 63 |
| 64 #endif // UI_COMPOSITOR_PAINT_RECORDER_H_ |
OLD | NEW |