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

Side by Side Diff: cc/layer_tree_impl.cc

Issue 12093015: Move page scale ownership to LayerTreeImpl. (Closed) Base URL: http://git.chromium.org/chromium/src.git@coordchange3
Patch Set: Rebase to 179503 Created 7 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/layer_tree_impl.h ('k') | cc/pinch_zoom_viewport.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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/layer_tree_impl.h" 5 #include "cc/layer_tree_impl.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "cc/heads_up_display_layer_impl.h"
8 #include "cc/layer_tree_host_common.h" 9 #include "cc/layer_tree_host_common.h"
9 #include "cc/layer_tree_host_impl.h" 10 #include "cc/layer_tree_host_impl.h"
10 #include "ui/gfx/vector2d_conversions.h" 11 #include "ui/gfx/vector2d_conversions.h"
11 12
12 namespace cc { 13 namespace cc {
13 14
14 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) 15 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
15 : layer_tree_host_impl_(layer_tree_host_impl) 16 : layer_tree_host_impl_(layer_tree_host_impl)
16 , source_frame_number_(-1) 17 , source_frame_number_(-1)
17 , hud_layer_(0) 18 , hud_layer_(0)
18 , root_scroll_layer_(0) 19 , root_scroll_layer_(0)
19 , currently_scrolling_layer_(0) 20 , currently_scrolling_layer_(0)
20 , background_color_(0) 21 , background_color_(0)
21 , has_transparent_background_(false) 22 , has_transparent_background_(false)
23 , page_scale_factor_(1)
24 , page_scale_delta_(1)
25 , sent_page_scale_delta_(1)
26 , min_page_scale_factor_(0)
27 , max_page_scale_factor_(0)
22 , scrolling_layer_id_from_previous_tree_(0) 28 , scrolling_layer_id_from_previous_tree_(0)
23 , contents_textures_purged_(false) 29 , contents_textures_purged_(false)
24 , needs_update_draw_properties_(true) { 30 , needs_update_draw_properties_(true) {
25 } 31 }
26 32
27 LayerTreeImpl::~LayerTreeImpl() { 33 LayerTreeImpl::~LayerTreeImpl() {
28 // Need to explicitly clear the tree prior to destroying this so that 34 // Need to explicitly clear the tree prior to destroying this so that
29 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. 35 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
30 root_layer_.reset(); 36 root_layer_.reset();
31 } 37 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 scrolling_layer_id_from_previous_tree_ = 78 scrolling_layer_id_from_previous_tree_ =
73 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; 79 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
74 root_scroll_layer_ = NULL; 80 root_scroll_layer_ = NULL;
75 currently_scrolling_layer_ = NULL; 81 currently_scrolling_layer_ = NULL;
76 82
77 render_surface_layer_list_.clear(); 83 render_surface_layer_list_.clear();
78 set_needs_update_draw_properties(); 84 set_needs_update_draw_properties();
79 return root_layer_.Pass(); 85 return root_layer_.Pass();
80 } 86 }
81 87
88 void LayerTreeImpl::pushPropertiesTo(LayerTreeImpl* target_tree) {
89 target_tree->SetPageScaleFactorAndLimits(
90 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor());
91 target_tree->SetPageScaleDelta(
92 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
93 target_tree->set_sent_page_scale_delta(1);
94
95 // This should match the property synchronization in
96 // LayerTreeHost::finishCommitOnImplThread().
97 target_tree->set_source_frame_number(source_frame_number());
98 target_tree->set_background_color(background_color());
99 target_tree->set_has_transparent_background(has_transparent_background());
100
101 if (ContentsTexturesPurged())
102 target_tree->SetContentsTexturesPurged();
103 else
104 target_tree->ResetContentsTexturesPurged();
105
106 if (hud_layer())
107 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
108 LayerTreeHostCommon::findLayerInSubtree(
109 target_tree->RootLayer(), hud_layer()->id())));
110 else
111 target_tree->set_hud_layer(NULL);
112 }
113
82 LayerImpl* LayerTreeImpl::RootScrollLayer() { 114 LayerImpl* LayerTreeImpl::RootScrollLayer() {
83 DCHECK(IsActiveTree()); 115 DCHECK(IsActiveTree());
84 return root_scroll_layer_; 116 return root_scroll_layer_;
85 } 117 }
86 118
87 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { 119 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() {
88 DCHECK(IsActiveTree()); 120 DCHECK(IsActiveTree());
89 return currently_scrolling_layer_; 121 return currently_scrolling_layer_;
90 } 122 }
91 123
92 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { 124 void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
93 currently_scrolling_layer_ = NULL; 125 currently_scrolling_layer_ = NULL;
94 scrolling_layer_id_from_previous_tree_ = 0; 126 scrolling_layer_id_from_previous_tree_ = 0;
95 } 127 }
96 128
129 void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
130 float min_page_scale_factor, float max_page_scale_factor)
131 {
132 if (!page_scale_factor)
133 return;
134
135 min_page_scale_factor_ = min_page_scale_factor;
136 max_page_scale_factor_ = max_page_scale_factor;
137 page_scale_factor_ = page_scale_factor;
138 }
139
140 void LayerTreeImpl::SetPageScaleDelta(float delta)
141 {
142 // Clamp to the current min/max limits.
143 float total = page_scale_factor_ * delta;
144 if (min_page_scale_factor_ && total < min_page_scale_factor_)
145 delta = min_page_scale_factor_ / page_scale_factor_;
146 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
147 delta = max_page_scale_factor_ / page_scale_factor_;
148
149 if (delta == page_scale_delta_)
150 return;
151
152 page_scale_delta_ = delta;
153
154 if (IsActiveTree()) {
155 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pendingTree();
156 if (pending_tree) {
157 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
158 pending_tree->SetPageScaleDelta(page_scale_delta_ / sent_page_scale_delta_ );
159 }
160 }
161
162 UpdateMaxScrollOffset();
163 set_needs_update_draw_properties();
164 }
165
97 gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { 166 gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
98 gfx::SizeF view_bounds; 167 gfx::SizeF view_bounds;
99 // The clip layer should be used for scrolling bounds if available since it 168 // The clip layer should be used for scrolling bounds if available since it
100 // adjusts for non-overlay scrollbars. Otherwise, fall back to our knowledge 169 // adjusts for non-overlay scrollbars. Otherwise, fall back to our knowledge
101 // of the physical viewport size. 170 // of the physical viewport size.
102 LayerImpl* clip_layer = NULL; 171 LayerImpl* clip_layer = NULL;
103 if (root_scroll_layer_) 172 if (root_scroll_layer_)
104 clip_layer = root_scroll_layer_->parent(); 173 clip_layer = root_scroll_layer_->parent();
105 if (clip_layer && clip_layer->masksToBounds()) { 174 if (clip_layer && clip_layer->masksToBounds()) {
106 view_bounds = clip_layer->bounds(); 175 view_bounds = clip_layer->bounds();
107 } else { 176 } else {
108 view_bounds = gfx::ScaleSize(device_viewport_size(), 177 view_bounds = gfx::ScaleSize(device_viewport_size(),
109 1 / device_scale_factor()); 178 1 / device_scale_factor());
110 } 179 }
111 view_bounds.Scale(1 / pinch_zoom_viewport().total_page_scale_factor()); 180 view_bounds.Scale(1 / total_page_scale_factor());
112 181
113 return view_bounds; 182 return view_bounds;
114 } 183 }
115 184
116 void LayerTreeImpl::UpdateMaxScrollOffset() { 185 void LayerTreeImpl::UpdateMaxScrollOffset() {
117 if (!root_scroll_layer_ || !root_scroll_layer_->children().size()) 186 if (!root_scroll_layer_ || !root_scroll_layer_->children().size())
118 return; 187 return;
119 188
120 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - 189 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() -
121 gfx::RectF(ScrollableViewportSize()).bottom_right(); 190 gfx::RectF(ScrollableViewportSize()).bottom_right();
122 191
123 // The viewport may be larger than the contents in some cases, such as 192 // The viewport may be larger than the contents in some cases, such as
124 // having a vertical scrollbar but no horizontal overflow. 193 // having a vertical scrollbar but no horizontal overflow.
125 max_scroll.ClampToMin(gfx::Vector2dF()); 194 max_scroll.ClampToMin(gfx::Vector2dF());
126 195
127 root_scroll_layer_->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); 196 root_scroll_layer_->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
128 } 197 }
129 198
199 gfx::Transform LayerTreeImpl::ImplTransform() const {
200 gfx::Transform transform;
201 transform.Scale(page_scale_delta_, page_scale_delta_);
202 if (settings().pageScalePinchZoomEnabled)
203 transform.Scale(page_scale_factor_, page_scale_factor_);
204 return transform;
205 }
206
130 struct UpdateTilePrioritiesForLayer { 207 struct UpdateTilePrioritiesForLayer {
131 void operator()(LayerImpl *layer) { 208 void operator()(LayerImpl *layer) {
132 layer->updateTilePriorities(); 209 layer->updateTilePriorities();
133 } 210 }
134 }; 211 };
135 212
136 void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) { 213 void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) {
137 if (!needs_update_draw_properties_) { 214 if (!needs_update_draw_properties_) {
138 if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && RootLayer()) 215 if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && RootLayer())
139 LayerTreeHostCommon::callFunctionForSubtree<UpdateTilePrioritiesForLayer>( 216 LayerTreeHostCommon::callFunctionForSubtree<UpdateTilePrioritiesForLayer>(
140 RootLayer()); 217 RootLayer());
141 return; 218 return;
142 } 219 }
143 220
144 needs_update_draw_properties_ = false; 221 needs_update_draw_properties_ = false;
145 render_surface_layer_list_.clear(); 222 render_surface_layer_list_.clear();
146 223
147 // For maxTextureSize. 224 // For maxTextureSize.
148 if (!layer_tree_host_impl_->renderer()) 225 if (!layer_tree_host_impl_->renderer())
149 return; 226 return;
150 227
151 if (!RootLayer()) 228 if (!RootLayer())
152 return; 229 return;
153 230
154 if (root_scroll_layer_) { 231 if (root_scroll_layer_) {
155 root_scroll_layer_->setImplTransform( 232 root_scroll_layer_->setImplTransform(ImplTransform());
156 layer_tree_host_impl_->implTransform());
157 // Setting the impl transform re-sets this. 233 // Setting the impl transform re-sets this.
158 needs_update_draw_properties_ = false; 234 needs_update_draw_properties_ = false;
159 } 235 }
160 236
161 { 237 {
162 TRACE_EVENT1("cc", "LayerTreeImpl::UpdateDrawProperties", "IsActive", IsActi veTree()); 238 TRACE_EVENT1("cc", "LayerTreeImpl::UpdateDrawProperties", "IsActive", IsActi veTree());
163 bool update_tile_priorities = 239 bool update_tile_priorities =
164 reason == UPDATE_PENDING_TREE || 240 reason == UPDATE_PENDING_TREE ||
165 reason == UPDATE_ACTIVE_TREE_FOR_DRAW; 241 reason == UPDATE_ACTIVE_TREE_FOR_DRAW;
166 LayerTreeHostCommon::calculateDrawProperties( 242 LayerTreeHostCommon::calculateDrawProperties(
167 RootLayer(), 243 RootLayer(),
168 device_viewport_size(), 244 device_viewport_size(),
169 device_scale_factor(), 245 device_scale_factor(),
170 pinch_zoom_viewport().total_page_scale_factor(), 246 total_page_scale_factor(),
171 MaxTextureSize(), 247 MaxTextureSize(),
172 settings().canUseLCDText, 248 settings().canUseLCDText,
173 render_surface_layer_list_, 249 render_surface_layer_list_,
174 update_tile_priorities); 250 update_tile_priorities);
175 } 251 }
176 252
177 DCHECK(!needs_update_draw_properties_) << 253 DCHECK(!needs_update_draw_properties_) <<
178 "calcDrawProperties should not set_needs_update_draw_properties()"; 254 "calcDrawProperties should not set_needs_update_draw_properties()";
179 } 255 }
180 256
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 436 }
361 437
362 DebugRectHistory* LayerTreeImpl::debug_rect_history() const { 438 DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
363 return layer_tree_host_impl_->debugRectHistory(); 439 return layer_tree_host_impl_->debugRectHistory();
364 } 440 }
365 441
366 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { 442 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
367 return layer_tree_host_impl_->animationRegistrar(); 443 return layer_tree_host_impl_->animationRegistrar();
368 } 444 }
369 445
370 const PinchZoomViewport& LayerTreeImpl::pinch_zoom_viewport() const {
371 return layer_tree_host_impl_->pinchZoomViewport();
372 }
373
374 } // namespace cc 446 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_impl.h ('k') | cc/pinch_zoom_viewport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698