| 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 #include "cc/resources/display_list_recording_source.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "cc/base/region.h" | |
| 10 #include "cc/layers/content_layer_client.h" | |
| 11 #include "cc/resources/display_item_list.h" | |
| 12 #include "cc/resources/display_list_raster_source.h" | |
| 13 #include "skia/ext/analysis_canvas.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // Layout pixel buffer around the visible layer rect to record. Any base | |
| 18 // picture that intersects the visible layer rect expanded by this distance | |
| 19 // will be recorded. | |
| 20 const int kPixelDistanceToRecord = 8000; | |
| 21 // We don't perform solid color analysis on images that have more than 10 skia | |
| 22 // operations. | |
| 23 const int kOpCountThatIsOkToAnalyze = 10; | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 namespace cc { | |
| 28 | |
| 29 DisplayListRecordingSource::DisplayListRecordingSource( | |
| 30 const gfx::Size& grid_cell_size, | |
| 31 bool use_cached_picture) | |
| 32 : use_cached_picture_(use_cached_picture), | |
| 33 slow_down_raster_scale_factor_for_debug_(0), | |
| 34 gather_pixel_refs_(false), | |
| 35 requires_clear_(false), | |
| 36 is_solid_color_(false), | |
| 37 solid_color_(SK_ColorTRANSPARENT), | |
| 38 background_color_(SK_ColorTRANSPARENT), | |
| 39 pixel_record_distance_(kPixelDistanceToRecord), | |
| 40 grid_cell_size_(grid_cell_size), | |
| 41 is_suitable_for_gpu_rasterization_(true) { | |
| 42 } | |
| 43 | |
| 44 DisplayListRecordingSource::~DisplayListRecordingSource() { | |
| 45 } | |
| 46 | |
| 47 bool DisplayListRecordingSource::UpdateAndExpandInvalidation( | |
| 48 ContentLayerClient* painter, | |
| 49 Region* invalidation, | |
| 50 const gfx::Size& layer_size, | |
| 51 const gfx::Rect& visible_layer_rect, | |
| 52 int frame_number, | |
| 53 RecordingMode recording_mode) { | |
| 54 bool updated = false; | |
| 55 | |
| 56 if (size_ != layer_size) { | |
| 57 size_ = layer_size; | |
| 58 updated = true; | |
| 59 } | |
| 60 | |
| 61 gfx::Rect old_recorded_viewport = recorded_viewport_; | |
| 62 recorded_viewport_ = visible_layer_rect; | |
| 63 recorded_viewport_.Inset(-pixel_record_distance_, -pixel_record_distance_); | |
| 64 recorded_viewport_.Intersect(gfx::Rect(GetSize())); | |
| 65 | |
| 66 if (recorded_viewport_ != old_recorded_viewport) { | |
| 67 // Invalidate newly-exposed and no-longer-exposed areas. | |
| 68 Region newly_exposed_region(recorded_viewport_); | |
| 69 newly_exposed_region.Subtract(old_recorded_viewport); | |
| 70 invalidation->Union(newly_exposed_region); | |
| 71 | |
| 72 Region no_longer_exposed_region(old_recorded_viewport); | |
| 73 no_longer_exposed_region.Subtract(recorded_viewport_); | |
| 74 invalidation->Union(no_longer_exposed_region); | |
| 75 | |
| 76 updated = true; | |
| 77 } | |
| 78 | |
| 79 if (!updated && !invalidation->Intersects(recorded_viewport_)) | |
| 80 return false; | |
| 81 | |
| 82 ContentLayerClient::PaintingControlSetting painting_control = | |
| 83 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; | |
| 84 | |
| 85 switch (recording_mode) { | |
| 86 case RECORD_NORMALLY: | |
| 87 // Already setup for normal recording. | |
| 88 break; | |
| 89 case RECORD_WITH_PAINTING_DISABLED: | |
| 90 painting_control = ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED; | |
| 91 break; | |
| 92 case RECORD_WITH_CACHING_DISABLED: | |
| 93 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; | |
| 94 break; | |
| 95 case RECORD_WITH_CONSTRUCTION_DISABLED: | |
| 96 painting_control = ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED; | |
| 97 break; | |
| 98 default: | |
| 99 // case RecordingSource::RECORD_WITH_SK_NULL_CANVAS should not be reached | |
| 100 NOTREACHED(); | |
| 101 } | |
| 102 | |
| 103 int repeat_count = 1; | |
| 104 if (slow_down_raster_scale_factor_for_debug_ > 1) { | |
| 105 repeat_count = slow_down_raster_scale_factor_for_debug_; | |
| 106 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; | |
| 107 } | |
| 108 for (int i = 0; i < repeat_count; ++i) { | |
| 109 display_list_ = | |
| 110 DisplayItemList::Create(recorded_viewport_, use_cached_picture_); | |
| 111 painter->PaintContentsToDisplayList(display_list_.get(), recorded_viewport_, | |
| 112 painting_control); | |
| 113 } | |
| 114 display_list_->ProcessAppendedItems(); | |
| 115 if (use_cached_picture_) | |
| 116 display_list_->CreateAndCacheSkPicture(); | |
| 117 | |
| 118 is_suitable_for_gpu_rasterization_ = | |
| 119 display_list_->IsSuitableForGpuRasterization(); | |
| 120 DetermineIfSolidColor(); | |
| 121 display_list_->EmitTraceSnapshot(); | |
| 122 if (gather_pixel_refs_) | |
| 123 display_list_->GatherPixelRefs(grid_cell_size_); | |
| 124 | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 gfx::Size DisplayListRecordingSource::GetSize() const { | |
| 129 return size_; | |
| 130 } | |
| 131 | |
| 132 void DisplayListRecordingSource::SetEmptyBounds() { | |
| 133 size_ = gfx::Size(); | |
| 134 Clear(); | |
| 135 } | |
| 136 | |
| 137 void DisplayListRecordingSource::SetSlowdownRasterScaleFactor(int factor) { | |
| 138 slow_down_raster_scale_factor_for_debug_ = factor; | |
| 139 } | |
| 140 | |
| 141 void DisplayListRecordingSource::SetGatherPixelRefs(bool gather_pixel_refs) { | |
| 142 gather_pixel_refs_ = gather_pixel_refs; | |
| 143 } | |
| 144 | |
| 145 void DisplayListRecordingSource::SetBackgroundColor(SkColor background_color) { | |
| 146 background_color_ = background_color; | |
| 147 } | |
| 148 | |
| 149 void DisplayListRecordingSource::SetRequiresClear(bool requires_clear) { | |
| 150 requires_clear_ = requires_clear; | |
| 151 } | |
| 152 | |
| 153 void DisplayListRecordingSource::SetUnsuitableForGpuRasterizationForTesting() { | |
| 154 is_suitable_for_gpu_rasterization_ = false; | |
| 155 } | |
| 156 | |
| 157 bool DisplayListRecordingSource::IsSuitableForGpuRasterization() const { | |
| 158 return is_suitable_for_gpu_rasterization_; | |
| 159 } | |
| 160 | |
| 161 scoped_refptr<RasterSource> DisplayListRecordingSource::CreateRasterSource( | |
| 162 bool can_use_lcd_text) const { | |
| 163 return scoped_refptr<RasterSource>( | |
| 164 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
| 165 this, can_use_lcd_text)); | |
| 166 } | |
| 167 | |
| 168 gfx::Size DisplayListRecordingSource::GetTileGridSizeForTesting() const { | |
| 169 return gfx::Size(); | |
| 170 } | |
| 171 | |
| 172 void DisplayListRecordingSource::DetermineIfSolidColor() { | |
| 173 DCHECK(display_list_.get()); | |
| 174 is_solid_color_ = false; | |
| 175 solid_color_ = SK_ColorTRANSPARENT; | |
| 176 | |
| 177 if (display_list_->ApproximateOpCount() > kOpCountThatIsOkToAnalyze) | |
| 178 return; | |
| 179 | |
| 180 gfx::Size layer_size = GetSize(); | |
| 181 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); | |
| 182 display_list_->Raster(&canvas, nullptr, 1.f); | |
| 183 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | |
| 184 } | |
| 185 | |
| 186 void DisplayListRecordingSource::Clear() { | |
| 187 recorded_viewport_ = gfx::Rect(); | |
| 188 display_list_ = NULL; | |
| 189 is_solid_color_ = false; | |
| 190 } | |
| 191 | |
| 192 } // namespace cc | |
| OLD | NEW |