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

Side by Side Diff: cc/layers/picture_layer.cc

Issue 952893003: Update from https://crrev.com/317530 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix gn for nacl Created 5 years, 10 months 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/layers/picture_layer.h ('k') | cc/layers/picture_layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layers/picture_layer.h" 5 #include "cc/layers/picture_layer.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "cc/layers/content_layer_client.h" 8 #include "cc/layers/content_layer_client.h"
9 #include "cc/layers/picture_layer_impl.h" 9 #include "cc/layers/picture_layer_impl.h"
10 #include "cc/resources/display_list_recording_source.h" 10 #include "cc/resources/display_list_recording_source.h"
11 #include "cc/resources/picture_pile.h" 11 #include "cc/resources/picture_pile.h"
12 #include "cc/trees/layer_tree_impl.h" 12 #include "cc/trees/layer_tree_impl.h"
13 #include "third_party/skia/include/core/SkPictureRecorder.h" 13 #include "third_party/skia/include/core/SkPictureRecorder.h"
14 #include "ui/gfx/geometry/rect_conversions.h" 14 #include "ui/gfx/geometry/rect_conversions.h"
15 15
16 namespace cc { 16 namespace cc {
17 17
18 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { 18 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
19 return make_scoped_refptr(new PictureLayer(client)); 19 return make_scoped_refptr(new PictureLayer(client));
20 } 20 }
21 21
22 PictureLayer::PictureLayer(ContentLayerClient* client) 22 PictureLayer::PictureLayer(ContentLayerClient* client)
23 : client_(client), 23 : client_(client),
24 instrumentation_object_tracker_(id()), 24 instrumentation_object_tracker_(id()),
25 update_source_frame_number_(-1), 25 update_source_frame_number_(-1),
26 can_use_lcd_text_for_update_(true),
27 is_mask_(false), 26 is_mask_(false),
28 nearest_neighbor_(false) { 27 nearest_neighbor_(false) {
29 } 28 }
30 29
31 PictureLayer::PictureLayer(ContentLayerClient* client, 30 PictureLayer::PictureLayer(ContentLayerClient* client,
32 scoped_ptr<RecordingSource> source) 31 scoped_ptr<RecordingSource> source)
33 : PictureLayer(client) { 32 : PictureLayer(client) {
34 recording_source_ = source.Pass(); 33 recording_source_ = source.Pass();
35 } 34 }
36 35
(...skipping 25 matching lines...) Expand all
62 if (update_source_frame_number_ != source_frame_number && 61 if (update_source_frame_number_ != source_frame_number &&
63 recording_source_bounds != impl_bounds) { 62 recording_source_bounds != impl_bounds) {
64 // Update may not get called for the layer (if it's not in the viewport 63 // Update may not get called for the layer (if it's not in the viewport
65 // for example, even though it has resized making the recording source no 64 // for example, even though it has resized making the recording source no
66 // longer valid. In this case just destroy the recording source. 65 // longer valid. In this case just destroy the recording source.
67 recording_source_->SetEmptyBounds(); 66 recording_source_->SetEmptyBounds();
68 } 67 }
69 68
70 layer_impl->SetNearestNeighbor(nearest_neighbor_); 69 layer_impl->SetNearestNeighbor(nearest_neighbor_);
71 70
71 // Preserve lcd text settings from the current raster source.
72 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText();
72 scoped_refptr<RasterSource> raster_source = 73 scoped_refptr<RasterSource> raster_source =
73 recording_source_->CreateRasterSource(); 74 recording_source_->CreateRasterSource(can_use_lcd_text);
74 layer_impl->UpdateRasterSource(raster_source, &recording_invalidation_, 75 layer_impl->UpdateRasterSource(raster_source, &recording_invalidation_,
75 nullptr); 76 nullptr);
76 DCHECK(recording_invalidation_.IsEmpty()); 77 DCHECK(recording_invalidation_.IsEmpty());
77 } 78 }
78 79
79 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { 80 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) {
80 Layer::SetLayerTreeHost(host); 81 Layer::SetLayerTreeHost(host);
81 if (host) { 82 if (host) {
82 if (!recording_source_) { 83 if (!recording_source_) {
83 if (host->settings().use_display_lists) { 84 if (host->settings().use_display_lists) {
(...skipping 16 matching lines...) Expand all
100 gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); 101 gfx::IntersectRects(layer_rect, gfx::Rect(bounds())));
101 } 102 }
102 Layer::SetNeedsDisplayRect(layer_rect); 103 Layer::SetNeedsDisplayRect(layer_rect);
103 } 104 }
104 105
105 bool PictureLayer::Update(ResourceUpdateQueue* queue, 106 bool PictureLayer::Update(ResourceUpdateQueue* queue,
106 const OcclusionTracker<Layer>* occlusion) { 107 const OcclusionTracker<Layer>* occlusion) {
107 update_source_frame_number_ = layer_tree_host()->source_frame_number(); 108 update_source_frame_number_ = layer_tree_host()->source_frame_number();
108 bool updated = Layer::Update(queue, occlusion); 109 bool updated = Layer::Update(queue, occlusion);
109 110
110 bool can_use_lcd_text_changed = UpdateCanUseLCDText();
111
112 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( 111 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect(
113 visible_content_rect(), 1.f / contents_scale_x()); 112 visible_content_rect(), 1.f / contents_scale_x());
114 gfx::Size layer_size = paint_properties().bounds; 113 gfx::Size layer_size = paint_properties().bounds;
115 114
116 if (last_updated_visible_content_rect_ == visible_content_rect() && 115 if (last_updated_visible_content_rect_ == visible_content_rect() &&
117 recording_source_->GetSize() == layer_size && !can_use_lcd_text_changed && 116 recording_source_->GetSize() == layer_size &&
118 pending_invalidation_.IsEmpty()) { 117 pending_invalidation_.IsEmpty()) {
119 // Only early out if the visible content rect of this layer hasn't changed. 118 // Only early out if the visible content rect of this layer hasn't changed.
120 return updated; 119 return updated;
121 } 120 }
122 121
123 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor()); 122 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor());
124 recording_source_->SetRequiresClear(!contents_opaque() && 123 recording_source_->SetRequiresClear(!contents_opaque() &&
125 !client_->FillsBoundsCompletely()); 124 !client_->FillsBoundsCompletely());
126 125
127 TRACE_EVENT1("cc", "PictureLayer::Update", 126 TRACE_EVENT1("cc", "PictureLayer::Update",
(...skipping 12 matching lines...) Expand all
140 // the full page content must always be provided in the picture layer. 139 // the full page content must always be provided in the picture layer.
141 visible_layer_rect = gfx::Rect(layer_size); 140 visible_layer_rect = gfx::Rect(layer_size);
142 } 141 }
143 142
144 // UpdateAndExpandInvalidation will give us an invalidation that covers 143 // UpdateAndExpandInvalidation will give us an invalidation that covers
145 // anything not explicitly recorded in this frame. We give this region 144 // anything not explicitly recorded in this frame. We give this region
146 // to the impl side so that it drops tiles that may not have a recording 145 // to the impl side so that it drops tiles that may not have a recording
147 // for them. 146 // for them.
148 DCHECK(client_); 147 DCHECK(client_);
149 updated |= recording_source_->UpdateAndExpandInvalidation( 148 updated |= recording_source_->UpdateAndExpandInvalidation(
150 client_, &recording_invalidation_, can_use_lcd_text_for_update_, 149 client_, &recording_invalidation_, layer_size, visible_layer_rect,
151 layer_size, visible_layer_rect, update_source_frame_number_, 150 update_source_frame_number_, RecordingSource::RECORD_NORMALLY);
152 RecordingSource::RECORD_NORMALLY);
153 last_updated_visible_content_rect_ = visible_content_rect(); 151 last_updated_visible_content_rect_ = visible_content_rect();
154 152
155 if (updated) { 153 if (updated) {
156 SetNeedsPushProperties(); 154 SetNeedsPushProperties();
157 } else { 155 } else {
158 // If this invalidation did not affect the recording source, then it can be 156 // If this invalidation did not affect the recording source, then it can be
159 // cleared as an optimization. 157 // cleared as an optimization.
160 recording_invalidation_.Clear(); 158 recording_invalidation_.Clear();
161 } 159 }
162 160
163 return updated; 161 return updated;
164 } 162 }
165 163
166 void PictureLayer::SetIsMask(bool is_mask) { 164 void PictureLayer::SetIsMask(bool is_mask) {
167 is_mask_ = is_mask; 165 is_mask_ = is_mask;
168 } 166 }
169 167
170 bool PictureLayer::SupportsLCDText() const {
171 return true;
172 }
173
174 bool PictureLayer::UpdateCanUseLCDText() {
175 if (!can_use_lcd_text_for_update_)
176 return false; // Don't allow the LCD text state to change once disabled.
177 if (can_use_lcd_text_for_update_ == can_use_lcd_text())
178 return false;
179
180 can_use_lcd_text_for_update_ = can_use_lcd_text();
181 return true;
182 }
183
184 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { 168 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const {
185 // We could either flatten the RecordingSource into a single SkPicture, 169 // We could either flatten the RecordingSource into a single SkPicture,
186 // or paint a fresh one depending on what we intend to do with the 170 // or paint a fresh one depending on what we intend to do with the
187 // picture. For now we just paint a fresh one to get consistent results. 171 // picture. For now we just paint a fresh one to get consistent results.
188 if (!DrawsContent()) 172 if (!DrawsContent())
189 return skia::RefPtr<SkPicture>(); 173 return skia::RefPtr<SkPicture>();
190 174
191 int width = bounds().width(); 175 int width = bounds().width();
192 int height = bounds().height(); 176 int height = bounds().height();
193 177
(...skipping 24 matching lines...) Expand all
218 202
219 bool PictureLayer::HasDrawableContent() const { 203 bool PictureLayer::HasDrawableContent() const {
220 return client_ && Layer::HasDrawableContent(); 204 return client_ && Layer::HasDrawableContent();
221 } 205 }
222 206
223 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { 207 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
224 benchmark->RunOnLayer(this); 208 benchmark->RunOnLayer(this);
225 } 209 }
226 210
227 } // namespace cc 211 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer.h ('k') | cc/layers/picture_layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698