OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/display_list_recording_source.h" | 5 #include "cc/resources/display_list_recording_source.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "cc/base/histograms.h" | |
10 #include "cc/base/region.h" | 9 #include "cc/base/region.h" |
11 #include "cc/layers/content_layer_client.h" | 10 #include "cc/layers/content_layer_client.h" |
12 #include "cc/resources/display_item_list.h" | 11 #include "cc/resources/display_item_list.h" |
13 #include "cc/resources/display_list_raster_source.h" | 12 #include "cc/resources/display_list_raster_source.h" |
14 #include "skia/ext/analysis_canvas.h" | 13 #include "skia/ext/analysis_canvas.h" |
15 | 14 |
16 namespace { | 15 namespace { |
17 | 16 |
18 // Layout pixel buffer around the visible layer rect to record. Any base | 17 // Layout pixel buffer around the visible layer rect to record. Any base |
19 // picture that intersects the visible layer rect expanded by this distance | 18 // picture that intersects the visible layer rect expanded by this distance |
20 // will be recorded. | 19 // will be recorded. |
21 const int kPixelDistanceToRecord = 8000; | 20 const int kPixelDistanceToRecord = 8000; |
22 // We don't perform solid color analysis on images that have more than 10 skia | 21 // We don't perform solid color analysis on images that have more than 10 skia |
23 // operations. | 22 // operations. |
24 const int kOpCountThatIsOkToAnalyze = 10; | 23 const int kOpCountThatIsOkToAnalyze = 10; |
25 | 24 |
26 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( | |
27 ScopedDisplayListRecordingSourceUpdateTimer, | |
28 "Compositing.DisplayListRecordingSource.UpdateUs", | |
29 "Compositing.DisplayListRecordingSource.UpdateInvalidatedAreaPerMs"); | |
30 | |
31 } // namespace | 25 } // namespace |
32 | 26 |
33 namespace cc { | 27 namespace cc { |
34 | 28 |
35 DisplayListRecordingSource::DisplayListRecordingSource( | 29 DisplayListRecordingSource::DisplayListRecordingSource( |
36 const gfx::Size& grid_cell_size, | 30 const gfx::Size& grid_cell_size, |
37 bool use_cached_picture) | 31 bool use_cached_picture) |
38 : use_cached_picture_(use_cached_picture), | 32 : use_cached_picture_(use_cached_picture), |
39 slow_down_raster_scale_factor_for_debug_(0), | 33 slow_down_raster_scale_factor_for_debug_(0), |
40 gather_pixel_refs_(false), | 34 gather_pixel_refs_(false), |
41 requires_clear_(false), | 35 requires_clear_(false), |
42 is_solid_color_(false), | 36 is_solid_color_(false), |
43 solid_color_(SK_ColorTRANSPARENT), | 37 solid_color_(SK_ColorTRANSPARENT), |
44 background_color_(SK_ColorTRANSPARENT), | 38 background_color_(SK_ColorTRANSPARENT), |
45 pixel_record_distance_(kPixelDistanceToRecord), | 39 pixel_record_distance_(kPixelDistanceToRecord), |
46 grid_cell_size_(grid_cell_size), | 40 grid_cell_size_(grid_cell_size), |
47 is_suitable_for_gpu_rasterization_(true) { | 41 is_suitable_for_gpu_rasterization_(true) { |
48 } | 42 } |
49 | 43 |
50 DisplayListRecordingSource::~DisplayListRecordingSource() { | 44 DisplayListRecordingSource::~DisplayListRecordingSource() { |
51 } | 45 } |
52 | 46 |
53 bool DisplayListRecordingSource::UpdateAndExpandInvalidation( | 47 bool DisplayListRecordingSource::UpdateAndExpandInvalidation( |
54 ContentLayerClient* painter, | 48 ContentLayerClient* painter, |
55 Region* invalidation, | 49 Region* invalidation, |
56 const gfx::Size& layer_size, | 50 const gfx::Size& layer_size, |
57 const gfx::Rect& visible_layer_rect, | 51 const gfx::Rect& visible_layer_rect, |
58 int frame_number, | 52 int frame_number, |
59 RecordingMode recording_mode) { | 53 RecordingMode recording_mode) { |
60 ScopedDisplayListRecordingSourceUpdateTimer timer; | |
61 bool updated = false; | 54 bool updated = false; |
62 | 55 |
63 if (size_ != layer_size) { | 56 if (size_ != layer_size) { |
64 size_ = layer_size; | 57 size_ = layer_size; |
65 updated = true; | 58 updated = true; |
66 } | 59 } |
67 | 60 |
68 gfx::Rect old_recorded_viewport = recorded_viewport_; | 61 gfx::Rect old_recorded_viewport = recorded_viewport_; |
69 recorded_viewport_ = visible_layer_rect; | 62 recorded_viewport_ = visible_layer_rect; |
70 recorded_viewport_.Inset(-pixel_record_distance_, -pixel_record_distance_); | 63 recorded_viewport_.Inset(-pixel_record_distance_, -pixel_record_distance_); |
71 recorded_viewport_.Intersect(gfx::Rect(GetSize())); | 64 recorded_viewport_.Intersect(gfx::Rect(GetSize())); |
72 | 65 |
73 if (recorded_viewport_ != old_recorded_viewport) { | 66 if (recorded_viewport_ != old_recorded_viewport) { |
74 // Invalidate newly-exposed and no-longer-exposed areas. | 67 // Invalidate newly-exposed and no-longer-exposed areas. |
75 Region newly_exposed_region(recorded_viewport_); | 68 Region newly_exposed_region(recorded_viewport_); |
76 newly_exposed_region.Subtract(old_recorded_viewport); | 69 newly_exposed_region.Subtract(old_recorded_viewport); |
77 invalidation->Union(newly_exposed_region); | 70 invalidation->Union(newly_exposed_region); |
78 | 71 |
79 Region no_longer_exposed_region(old_recorded_viewport); | 72 Region no_longer_exposed_region(old_recorded_viewport); |
80 no_longer_exposed_region.Subtract(recorded_viewport_); | 73 no_longer_exposed_region.Subtract(recorded_viewport_); |
81 invalidation->Union(no_longer_exposed_region); | 74 invalidation->Union(no_longer_exposed_region); |
82 | 75 |
83 updated = true; | 76 updated = true; |
84 } | 77 } |
85 | 78 |
86 // Count the area that is being invalidated. | |
87 Region recorded_invalidation(*invalidation); | |
88 recorded_invalidation.Intersect(recorded_viewport_); | |
89 for (Region::Iterator it(recorded_invalidation); it.has_rect(); it.next()) | |
90 timer.AddArea(it.rect().size().GetArea()); | |
91 | |
92 if (!updated && !invalidation->Intersects(recorded_viewport_)) | 79 if (!updated && !invalidation->Intersects(recorded_viewport_)) |
93 return false; | 80 return false; |
94 | 81 |
95 ContentLayerClient::PaintingControlSetting painting_control = | 82 ContentLayerClient::PaintingControlSetting painting_control = |
96 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; | 83 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; |
97 | 84 |
98 switch (recording_mode) { | 85 switch (recording_mode) { |
99 case RECORD_NORMALLY: | 86 case RECORD_NORMALLY: |
100 // Already setup for normal recording. | 87 // Already setup for normal recording. |
101 break; | 88 break; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | 183 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); |
197 } | 184 } |
198 | 185 |
199 void DisplayListRecordingSource::Clear() { | 186 void DisplayListRecordingSource::Clear() { |
200 recorded_viewport_ = gfx::Rect(); | 187 recorded_viewport_ = gfx::Rect(); |
201 display_list_ = NULL; | 188 display_list_ = NULL; |
202 is_solid_color_ = false; | 189 is_solid_color_ = false; |
203 } | 190 } |
204 | 191 |
205 } // namespace cc | 192 } // namespace cc |
OLD | NEW |