OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 CC_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ | |
6 #define CC_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/threading/thread_checker.h" | |
15 #include "base/trace_event/memory_allocator_dump.h" | |
16 #include "base/trace_event/memory_dump_provider.h" | |
17 #include "cc/base/cc_export.h" | |
18 #include "cc/debug/rendering_stats_instrumentation.h" | |
19 #include "cc/playback/display_list_recording_source.h" | |
20 #include "skia/ext/analysis_canvas.h" | |
21 #include "third_party/skia/include/core/SkPicture.h" | |
22 | |
23 namespace cc { | |
24 class DisplayItemList; | |
25 class DrawImage; | |
26 class ImageDecodeController; | |
27 | |
28 class CC_EXPORT DisplayListRasterSource | |
29 : public base::trace_event::MemoryDumpProvider, | |
30 public base::RefCountedThreadSafe<DisplayListRasterSource> { | |
31 public: | |
32 static scoped_refptr<DisplayListRasterSource> | |
33 CreateFromDisplayListRecordingSource(const DisplayListRecordingSource* other, | |
34 bool can_use_lcd_text); | |
35 | |
36 // Raster a subrect of this RasterSource into the given canvas. It is | |
37 // assumed that contents_scale has already been applied to this canvas. | |
38 // Writes the total number of pixels rasterized and the time spent | |
39 // rasterizing to the stats if the respective pointer is not nullptr. | |
40 // It is assumed that the canvas passed here will only be rasterized by | |
41 // this raster source via this call. | |
42 // | |
43 // Virtual for testing. | |
44 // | |
45 // Note that this should only be called after the image decode controller has | |
46 // been set, which happens during commit. | |
47 virtual void PlaybackToCanvas(SkCanvas* canvas, | |
48 const gfx::Rect& canvas_bitmap_rect, | |
49 const gfx::Rect& canvas_playback_rect, | |
50 float contents_scale, | |
51 bool include_images) const; | |
52 | |
53 // Similar to above, except that the canvas passed here can (or was already) | |
54 // rasterized into by another raster source. That is, it is not safe to clear | |
55 // the canvas or discard its underlying memory. | |
56 void PlaybackToSharedCanvas(SkCanvas* canvas, | |
57 const gfx::Rect& canvas_rect, | |
58 float contents_scale, | |
59 bool include_images) const; | |
60 | |
61 // Returns whether the given rect at given scale is of solid color in | |
62 // this raster source, as well as the solid color value. | |
63 bool PerformSolidColorAnalysis(const gfx::Rect& content_rect, | |
64 float contents_scale, | |
65 SkColor* color) const; | |
66 | |
67 // Returns true iff the whole raster source is of solid color. | |
68 bool IsSolidColor() const; | |
69 | |
70 // Returns the color of the raster source if it is solid color. The results | |
71 // are unspecified if IsSolidColor returns false. | |
72 SkColor GetSolidColor() const; | |
73 | |
74 // Returns the size of this raster source. | |
75 gfx::Size GetSize() const; | |
76 | |
77 // Populate the given list with all images that may overlap the given | |
78 // rect in layer space. The returned draw images' matrices are modified as if | |
79 // they were being using during raster at scale |raster_scale|. | |
80 void GetDiscardableImagesInRect(const gfx::Rect& layer_rect, | |
81 float raster_scale, | |
82 std::vector<DrawImage>* images) const; | |
83 | |
84 // Return true iff this raster source can raster the given rect in layer | |
85 // space. | |
86 bool CoversRect(const gfx::Rect& layer_rect) const; | |
87 | |
88 // Returns true if this raster source has anything to rasterize. | |
89 virtual bool HasRecordings() const; | |
90 | |
91 // Valid rectangle in which everything is recorded and can be rastered from. | |
92 virtual gfx::Rect RecordedViewport() const; | |
93 | |
94 // Informs the raster source that it should attempt to use distance field text | |
95 // during rasterization. | |
96 virtual void SetShouldAttemptToUseDistanceFieldText(); | |
97 | |
98 // Return true iff this raster source would benefit from using distance | |
99 // field text. | |
100 virtual bool ShouldAttemptToUseDistanceFieldText() const; | |
101 | |
102 // Tracing functionality. | |
103 virtual void DidBeginTracing(); | |
104 virtual void AsValueInto(base::trace_event::TracedValue* array) const; | |
105 virtual sk_sp<SkPicture> GetFlattenedPicture(); | |
106 virtual size_t GetPictureMemoryUsage() const; | |
107 | |
108 // Return true if LCD anti-aliasing may be used when rastering text. | |
109 virtual bool CanUseLCDText() const; | |
110 | |
111 scoped_refptr<DisplayListRasterSource> CreateCloneWithoutLCDText() const; | |
112 | |
113 // Image decode controller should be set once. Its lifetime has to exceed that | |
114 // of the raster source, since the raster source will access it during raster. | |
115 void SetImageDecodeController(ImageDecodeController* image_decode_controller); | |
116 | |
117 // base::trace_event::MemoryDumpProvider implementation | |
118 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
119 base::trace_event::ProcessMemoryDump* pmd) override; | |
120 | |
121 protected: | |
122 friend class base::RefCountedThreadSafe<DisplayListRasterSource>; | |
123 | |
124 DisplayListRasterSource(const DisplayListRecordingSource* other, | |
125 bool can_use_lcd_text); | |
126 DisplayListRasterSource(const DisplayListRasterSource* other, | |
127 bool can_use_lcd_text); | |
128 ~DisplayListRasterSource() override; | |
129 | |
130 // These members are const as this raster source may be in use on another | |
131 // thread and so should not be touched after construction. | |
132 const scoped_refptr<DisplayItemList> display_list_; | |
133 const size_t painter_reported_memory_usage_; | |
134 const SkColor background_color_; | |
135 const bool requires_clear_; | |
136 const bool can_use_lcd_text_; | |
137 const bool is_solid_color_; | |
138 const SkColor solid_color_; | |
139 const gfx::Rect recorded_viewport_; | |
140 const gfx::Size size_; | |
141 const bool clear_canvas_with_debug_color_; | |
142 const int slow_down_raster_scale_factor_for_debug_; | |
143 // TODO(enne/vmiura): this has a read/write race between raster and compositor | |
144 // threads with multi-threaded Ganesh. Make this const or remove it. | |
145 bool should_attempt_to_use_distance_field_text_; | |
146 | |
147 // In practice, this is only set once before raster begins, so it's ok with | |
148 // respect to threading. | |
149 ImageDecodeController* image_decode_controller_; | |
150 | |
151 private: | |
152 // Called when analyzing a tile. We can use AnalysisCanvas as | |
153 // SkPicture::AbortCallback, which allows us to early out from analysis. | |
154 void RasterForAnalysis(skia::AnalysisCanvas* canvas, | |
155 const gfx::Rect& canvas_rect, | |
156 float contents_scale) const; | |
157 | |
158 void RasterCommon(SkCanvas* canvas, | |
159 SkPicture::AbortCallback* callback, | |
160 const gfx::Rect& canvas_bitmap_rect, | |
161 const gfx::Rect& canvas_playback_rect, | |
162 float contents_scale) const; | |
163 | |
164 void PrepareForPlaybackToCanvas(SkCanvas* canvas, | |
165 const gfx::Rect& canvas_bitmap_rect, | |
166 const gfx::Rect& canvas_playback_rect, | |
167 float contents_scale) const; | |
168 | |
169 // Used to ensure that memory dump logic always happens on the same thread. | |
170 base::ThreadChecker memory_dump_thread_checker_; | |
171 | |
172 DISALLOW_COPY_AND_ASSIGN(DisplayListRasterSource); | |
173 }; | |
174 | |
175 } // namespace cc | |
176 | |
177 #endif // CC_PLAYBACK_DISPLAY_LIST_RASTER_SOURCE_H_ | |
OLD | NEW |