Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: cc/resources/display_list_recording_source.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/display_list_recording_source.h ('k') | cc/resources/drawing_display_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 : slow_down_raster_scale_factor_for_debug_(0),
31 can_use_lcd_text_(true),
32 is_solid_color_(false),
33 solid_color_(SK_ColorTRANSPARENT),
34 pixel_record_distance_(kPixelDistanceToRecord),
35 is_suitable_for_gpu_rasterization_(true) {
36 }
37
38 DisplayListRecordingSource::~DisplayListRecordingSource() {
39 }
40
41 bool DisplayListRecordingSource::UpdateAndExpandInvalidation(
42 ContentLayerClient* painter,
43 Region* invalidation,
44 bool can_use_lcd_text,
45 const gfx::Size& layer_size,
46 const gfx::Rect& visible_layer_rect,
47 int frame_number,
48 Picture::RecordingMode recording_mode) {
49 bool updated = false;
50
51 if (size_ != layer_size) {
52 size_ = layer_size;
53 updated = true;
54 }
55
56 if (can_use_lcd_text_ != can_use_lcd_text) {
57 can_use_lcd_text_ = can_use_lcd_text;
58 invalidation->Union(gfx::Rect(GetSize()));
59 updated = true;
60 }
61
62 gfx::Rect old_recorded_viewport = recorded_viewport_;
63 recorded_viewport_ = visible_layer_rect;
64 recorded_viewport_.Inset(-pixel_record_distance_, -pixel_record_distance_);
65 recorded_viewport_.Intersect(gfx::Rect(GetSize()));
66
67 if (recorded_viewport_ != old_recorded_viewport) {
68 // Invalidate newly-exposed and no-longer-exposed areas.
69 Region newly_exposed_region(recorded_viewport_);
70 newly_exposed_region.Subtract(old_recorded_viewport);
71 invalidation->Union(newly_exposed_region);
72
73 Region no_longer_exposed_region(old_recorded_viewport);
74 no_longer_exposed_region.Subtract(recorded_viewport_);
75 invalidation->Union(no_longer_exposed_region);
76
77 updated = true;
78 }
79
80 if (!updated && !invalidation->Intersects(recorded_viewport_))
81 return false;
82
83 // TODO(ajuma): Does repeating this way really makes sense with display lists?
84 // With Blink caching recordings, repeated calls will not cause re-recording.
85 int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_);
86 for (int i = 0; i < repeat_count; ++i) {
87 display_list_ = painter->PaintContentsToDisplayList(
88 recorded_viewport_, ContentLayerClient::GRAPHICS_CONTEXT_ENABLED);
89 }
90 is_suitable_for_gpu_rasterization_ =
91 display_list_->IsSuitableForGpuRasterization();
92
93 DetermineIfSolidColor();
94 display_list_->EmitTraceSnapshot();
95 return true;
96 }
97
98 gfx::Size DisplayListRecordingSource::GetSize() const {
99 return size_;
100 }
101
102 void DisplayListRecordingSource::SetEmptyBounds() {
103 size_ = gfx::Size();
104 Clear();
105 }
106
107 void DisplayListRecordingSource::SetMinContentsScale(float min_contents_scale) {
108 }
109
110 void DisplayListRecordingSource::SetTileGridSize(
111 const gfx::Size& tile_grid_size) {
112 }
113
114 void DisplayListRecordingSource::SetSlowdownRasterScaleFactor(int factor) {
115 slow_down_raster_scale_factor_for_debug_ = factor;
116 }
117
118 void DisplayListRecordingSource::SetUnsuitableForGpuRasterizationForTesting() {
119 is_suitable_for_gpu_rasterization_ = false;
120 }
121
122 bool DisplayListRecordingSource::IsSuitableForGpuRasterization() const {
123 return is_suitable_for_gpu_rasterization_;
124 }
125
126 scoped_refptr<RasterSource> DisplayListRecordingSource::CreateRasterSource()
127 const {
128 return scoped_refptr<RasterSource>(
129 DisplayListRasterSource::CreateFromDisplayListRecordingSource(this));
130 }
131
132 SkTileGridFactory::TileGridInfo
133 DisplayListRecordingSource::GetTileGridInfoForTesting() const {
134 return SkTileGridFactory::TileGridInfo();
135 }
136
137 void DisplayListRecordingSource::DetermineIfSolidColor() {
138 DCHECK(display_list_.get());
139 is_solid_color_ = false;
140 solid_color_ = SK_ColorTRANSPARENT;
141
142 if (display_list_->ApproximateOpCount() > kOpCountThatIsOkToAnalyze)
143 return;
144
145 skia::AnalysisCanvas canvas(recorded_viewport_.width(),
146 recorded_viewport_.height());
147 canvas.translate(-recorded_viewport_.x(), -recorded_viewport_.y());
148 display_list_->Raster(&canvas, nullptr, 1.f);
149 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_);
150 }
151
152 void DisplayListRecordingSource::Clear() {
153 recorded_viewport_ = gfx::Rect();
154 display_list_ = NULL;
155 is_solid_color_ = false;
156 }
157
158 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/display_list_recording_source.h ('k') | cc/resources/drawing_display_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698