OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/layers/layer_impl.h" | |
6 | |
7 #include "base/json/json_reader.h" | |
8 #include "base/strings/stringprintf.h" | |
9 #include "base/trace_event/trace_event.h" | |
10 #include "base/trace_event/trace_event_argument.h" | |
11 #include "cc/animation/animation_registrar.h" | |
12 #include "cc/animation/scrollbar_animation_controller.h" | |
13 #include "cc/base/math_util.h" | |
14 #include "cc/base/simple_enclosed_region.h" | |
15 #include "cc/debug/debug_colors.h" | |
16 #include "cc/debug/layer_tree_debug_state.h" | |
17 #include "cc/debug/micro_benchmark_impl.h" | |
18 #include "cc/debug/traced_value.h" | |
19 #include "cc/input/layer_scroll_offset_delegate.h" | |
20 #include "cc/layers/layer_utils.h" | |
21 #include "cc/layers/painted_scrollbar_layer_impl.h" | |
22 #include "cc/output/copy_output_request.h" | |
23 #include "cc/quads/debug_border_draw_quad.h" | |
24 #include "cc/quads/render_pass.h" | |
25 #include "cc/trees/layer_tree_host_common.h" | |
26 #include "cc/trees/layer_tree_impl.h" | |
27 #include "cc/trees/layer_tree_settings.h" | |
28 #include "cc/trees/proxy.h" | |
29 #include "ui/gfx/geometry/box_f.h" | |
30 #include "ui/gfx/geometry/point_conversions.h" | |
31 #include "ui/gfx/geometry/quad_f.h" | |
32 #include "ui/gfx/geometry/rect_conversions.h" | |
33 #include "ui/gfx/geometry/size_conversions.h" | |
34 #include "ui/gfx/geometry/vector2d_conversions.h" | |
35 | |
36 namespace cc { | |
37 LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id) | |
38 : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) { | |
39 } | |
40 | |
41 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, | |
42 int id, | |
43 scoped_refptr<SyncedScrollOffset> scroll_offset) | |
44 : parent_(nullptr), | |
45 scroll_parent_(nullptr), | |
46 clip_parent_(nullptr), | |
47 mask_layer_id_(-1), | |
48 replica_layer_id_(-1), | |
49 layer_id_(id), | |
50 layer_tree_impl_(tree_impl), | |
51 scroll_offset_(scroll_offset), | |
52 scroll_offset_delegate_(nullptr), | |
53 scroll_clip_layer_(nullptr), | |
54 should_scroll_on_main_thread_(false), | |
55 have_wheel_event_handlers_(false), | |
56 have_scroll_event_handlers_(false), | |
57 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE), | |
58 user_scrollable_horizontal_(true), | |
59 user_scrollable_vertical_(true), | |
60 stacking_order_changed_(false), | |
61 double_sided_(true), | |
62 should_flatten_transform_(true), | |
63 layer_property_changed_(false), | |
64 masks_to_bounds_(false), | |
65 contents_opaque_(false), | |
66 is_root_for_isolated_group_(false), | |
67 use_parent_backface_visibility_(false), | |
68 draw_checkerboard_for_missing_tiles_(false), | |
69 draws_content_(false), | |
70 hide_layer_and_subtree_(false), | |
71 transform_is_invertible_(true), | |
72 is_container_for_fixed_position_layers_(false), | |
73 background_color_(0), | |
74 opacity_(1.0), | |
75 blend_mode_(SkXfermode::kSrcOver_Mode), | |
76 num_descendants_that_draw_content_(0), | |
77 draw_depth_(0.f), | |
78 needs_push_properties_(false), | |
79 num_dependents_need_push_properties_(0), | |
80 sorting_context_id_(0), | |
81 current_draw_mode_(DRAW_MODE_NONE), | |
82 frame_timing_requests_dirty_(false) { | |
83 DCHECK_GT(layer_id_, 0); | |
84 DCHECK(layer_tree_impl_); | |
85 layer_tree_impl_->RegisterLayer(this); | |
86 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar(); | |
87 layer_animation_controller_ = | |
88 registrar->GetAnimationControllerForId(layer_id_); | |
89 layer_animation_controller_->AddValueObserver(this); | |
90 if (IsActive()) { | |
91 layer_animation_controller_->set_value_provider(this); | |
92 layer_animation_controller_->set_layer_animation_delegate(this); | |
93 } | |
94 SetNeedsPushProperties(); | |
95 } | |
96 | |
97 LayerImpl::~LayerImpl() { | |
98 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); | |
99 | |
100 layer_animation_controller_->RemoveValueObserver(this); | |
101 layer_animation_controller_->remove_value_provider(this); | |
102 layer_animation_controller_->remove_layer_animation_delegate(this); | |
103 | |
104 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree()) | |
105 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); | |
106 layer_tree_impl_->UnregisterLayer(this); | |
107 | |
108 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | |
109 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); | |
110 } | |
111 | |
112 void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) { | |
113 child->SetParent(this); | |
114 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl()); | |
115 children_.push_back(child.Pass()); | |
116 layer_tree_impl()->set_needs_update_draw_properties(); | |
117 } | |
118 | |
119 scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) { | |
120 for (OwnedLayerImplList::iterator it = children_.begin(); | |
121 it != children_.end(); | |
122 ++it) { | |
123 if (*it == child) { | |
124 scoped_ptr<LayerImpl> ret = children_.take(it); | |
125 children_.erase(it); | |
126 layer_tree_impl()->set_needs_update_draw_properties(); | |
127 return ret.Pass(); | |
128 } | |
129 } | |
130 return nullptr; | |
131 } | |
132 | |
133 void LayerImpl::SetParent(LayerImpl* parent) { | |
134 if (parent_should_know_need_push_properties()) { | |
135 if (parent_) | |
136 parent_->RemoveDependentNeedsPushProperties(); | |
137 if (parent) | |
138 parent->AddDependentNeedsPushProperties(); | |
139 } | |
140 parent_ = parent; | |
141 } | |
142 | |
143 void LayerImpl::ClearChildList() { | |
144 if (children_.empty()) | |
145 return; | |
146 | |
147 children_.clear(); | |
148 layer_tree_impl()->set_needs_update_draw_properties(); | |
149 } | |
150 | |
151 bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const { | |
152 if (!ancestor) | |
153 return false; | |
154 | |
155 for (const LayerImpl* layer = this; layer; layer = layer->parent()) { | |
156 if (layer == ancestor) | |
157 return true; | |
158 } | |
159 | |
160 return false; | |
161 } | |
162 | |
163 void LayerImpl::SetScrollParent(LayerImpl* parent) { | |
164 if (scroll_parent_ == parent) | |
165 return; | |
166 | |
167 // Having both a scroll parent and a scroll offset delegate is unsupported. | |
168 DCHECK(!scroll_offset_delegate_); | |
169 | |
170 if (parent) | |
171 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent); | |
172 | |
173 scroll_parent_ = parent; | |
174 SetNeedsPushProperties(); | |
175 } | |
176 | |
177 void LayerImpl::SetDebugInfo( | |
178 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) { | |
179 debug_info_ = other; | |
180 SetNeedsPushProperties(); | |
181 } | |
182 | |
183 void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) { | |
184 if (scroll_children_.get() == children) | |
185 return; | |
186 scroll_children_.reset(children); | |
187 SetNeedsPushProperties(); | |
188 } | |
189 | |
190 void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) { | |
191 if (num_descendants_that_draw_content_ == num_descendants) | |
192 return; | |
193 num_descendants_that_draw_content_ = num_descendants; | |
194 SetNeedsPushProperties(); | |
195 } | |
196 | |
197 void LayerImpl::SetClipParent(LayerImpl* ancestor) { | |
198 if (clip_parent_ == ancestor) | |
199 return; | |
200 | |
201 clip_parent_ = ancestor; | |
202 SetNeedsPushProperties(); | |
203 } | |
204 | |
205 void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) { | |
206 if (clip_children_.get() == children) | |
207 return; | |
208 clip_children_.reset(children); | |
209 SetNeedsPushProperties(); | |
210 } | |
211 | |
212 void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) { | |
213 if (requests->empty()) | |
214 return; | |
215 DCHECK(render_surface()); | |
216 bool was_empty = copy_requests_.empty(); | |
217 copy_requests_.insert_and_take(copy_requests_.end(), requests); | |
218 requests->clear(); | |
219 | |
220 if (was_empty && layer_tree_impl()->IsActiveTree()) | |
221 layer_tree_impl()->AddLayerWithCopyOutputRequest(this); | |
222 NoteLayerPropertyChangedForSubtree(); | |
223 } | |
224 | |
225 void LayerImpl::TakeCopyRequestsAndTransformToTarget( | |
226 ScopedPtrVector<CopyOutputRequest>* requests) { | |
227 DCHECK(!copy_requests_.empty()); | |
228 DCHECK(layer_tree_impl()->IsActiveTree()); | |
229 DCHECK_EQ(render_target(), this); | |
230 | |
231 size_t first_inserted_request = requests->size(); | |
232 requests->insert_and_take(requests->end(), ©_requests_); | |
233 copy_requests_.clear(); | |
234 | |
235 for (size_t i = first_inserted_request; i < requests->size(); ++i) { | |
236 CopyOutputRequest* request = requests->at(i); | |
237 if (!request->has_area()) | |
238 continue; | |
239 | |
240 gfx::Rect request_in_layer_space = request->area(); | |
241 gfx::Rect request_in_content_space = | |
242 LayerRectToContentRect(request_in_layer_space); | |
243 request->set_area(MathUtil::MapEnclosingClippedRect( | |
244 draw_properties_.target_space_transform, request_in_content_space)); | |
245 } | |
246 | |
247 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); | |
248 layer_tree_impl()->set_needs_update_draw_properties(); | |
249 } | |
250 | |
251 void LayerImpl::ClearRenderSurfaceLayerList() { | |
252 if (render_surface_) | |
253 render_surface_->ClearLayerLists(); | |
254 } | |
255 | |
256 void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const { | |
257 state->SetAll( | |
258 draw_properties_.target_space_transform, draw_properties_.content_bounds, | |
259 draw_properties_.visible_content_rect, draw_properties_.clip_rect, | |
260 draw_properties_.is_clipped, draw_properties_.opacity, | |
261 draw_properties_.blend_mode, sorting_context_id_); | |
262 } | |
263 | |
264 void LayerImpl::PopulateScaledSharedQuadState(SharedQuadState* state, | |
265 float scale) const { | |
266 gfx::Transform scaled_draw_transform = | |
267 draw_properties_.target_space_transform; | |
268 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); | |
269 gfx::Size scaled_content_bounds = | |
270 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale)); | |
271 gfx::Rect scaled_visible_content_rect = | |
272 gfx::ScaleToEnclosingRect(visible_content_rect(), scale); | |
273 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); | |
274 | |
275 state->SetAll(scaled_draw_transform, scaled_content_bounds, | |
276 scaled_visible_content_rect, draw_properties().clip_rect, | |
277 draw_properties().is_clipped, draw_properties().opacity, | |
278 draw_properties().blend_mode, sorting_context_id_); | |
279 } | |
280 | |
281 bool LayerImpl::WillDraw(DrawMode draw_mode, | |
282 ResourceProvider* resource_provider) { | |
283 // WillDraw/DidDraw must be matched. | |
284 DCHECK_NE(DRAW_MODE_NONE, draw_mode); | |
285 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); | |
286 current_draw_mode_ = draw_mode; | |
287 return true; | |
288 } | |
289 | |
290 void LayerImpl::DidDraw(ResourceProvider* resource_provider) { | |
291 DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_); | |
292 current_draw_mode_ = DRAW_MODE_NONE; | |
293 } | |
294 | |
295 bool LayerImpl::ShowDebugBorders() const { | |
296 return layer_tree_impl()->debug_state().show_debug_borders; | |
297 } | |
298 | |
299 void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const { | |
300 if (draws_content_) { | |
301 *color = DebugColors::ContentLayerBorderColor(); | |
302 *width = DebugColors::ContentLayerBorderWidth(layer_tree_impl()); | |
303 return; | |
304 } | |
305 | |
306 if (masks_to_bounds_) { | |
307 *color = DebugColors::MaskingLayerBorderColor(); | |
308 *width = DebugColors::MaskingLayerBorderWidth(layer_tree_impl()); | |
309 return; | |
310 } | |
311 | |
312 *color = DebugColors::ContainerLayerBorderColor(); | |
313 *width = DebugColors::ContainerLayerBorderWidth(layer_tree_impl()); | |
314 } | |
315 | |
316 void LayerImpl::AppendDebugBorderQuad( | |
317 RenderPass* render_pass, | |
318 const gfx::Size& content_bounds, | |
319 const SharedQuadState* shared_quad_state, | |
320 AppendQuadsData* append_quads_data) const { | |
321 SkColor color; | |
322 float width; | |
323 GetDebugBorderProperties(&color, &width); | |
324 AppendDebugBorderQuad(render_pass, | |
325 content_bounds, | |
326 shared_quad_state, | |
327 append_quads_data, | |
328 color, | |
329 width); | |
330 } | |
331 | |
332 void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass, | |
333 const gfx::Size& content_bounds, | |
334 const SharedQuadState* shared_quad_state, | |
335 AppendQuadsData* append_quads_data, | |
336 SkColor color, | |
337 float width) const { | |
338 if (!ShowDebugBorders()) | |
339 return; | |
340 | |
341 gfx::Rect quad_rect(content_bounds); | |
342 gfx::Rect visible_quad_rect(quad_rect); | |
343 DebugBorderDrawQuad* debug_border_quad = | |
344 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>(); | |
345 debug_border_quad->SetNew( | |
346 shared_quad_state, quad_rect, visible_quad_rect, color, width); | |
347 if (contents_opaque()) { | |
348 // When opaque, draw a second inner border that is thicker than the outer | |
349 // border, but more transparent. | |
350 static const float kFillOpacity = 0.3f; | |
351 SkColor fill_color = SkColorSetA( | |
352 color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity)); | |
353 float fill_width = width * 3; | |
354 gfx::Rect fill_rect = quad_rect; | |
355 fill_rect.Inset(fill_width / 2.f, fill_width / 2.f); | |
356 gfx::Rect visible_fill_rect = | |
357 gfx::IntersectRects(visible_quad_rect, fill_rect); | |
358 DebugBorderDrawQuad* fill_quad = | |
359 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>(); | |
360 fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect, | |
361 fill_color, fill_width); | |
362 } | |
363 } | |
364 | |
365 bool LayerImpl::HasDelegatedContent() const { | |
366 return false; | |
367 } | |
368 | |
369 bool LayerImpl::HasContributingDelegatedRenderPasses() const { | |
370 return false; | |
371 } | |
372 | |
373 RenderPassId LayerImpl::FirstContributingRenderPassId() const { | |
374 return RenderPassId(0, 0); | |
375 } | |
376 | |
377 RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const { | |
378 return RenderPassId(0, 0); | |
379 } | |
380 | |
381 void LayerImpl::GetContentsResourceId(ResourceProvider::ResourceId* resource_id, | |
382 gfx::Size* resource_size) const { | |
383 NOTREACHED(); | |
384 *resource_id = 0; | |
385 } | |
386 | |
387 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { | |
388 RefreshFromScrollDelegate(); | |
389 | |
390 gfx::ScrollOffset adjusted_scroll(scroll); | |
391 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) { | |
392 if (!user_scrollable_horizontal_) | |
393 adjusted_scroll.set_x(0); | |
394 if (!user_scrollable_vertical_) | |
395 adjusted_scroll.set_y(0); | |
396 } | |
397 DCHECK(scrollable()); | |
398 gfx::ScrollOffset old_offset = CurrentScrollOffset(); | |
399 gfx::ScrollOffset new_offset = | |
400 ClampScrollOffsetToLimits(old_offset + adjusted_scroll); | |
401 SetCurrentScrollOffset(new_offset); | |
402 | |
403 gfx::ScrollOffset unscrolled = | |
404 old_offset + gfx::ScrollOffset(scroll) - new_offset; | |
405 return gfx::Vector2dF(unscrolled.x(), unscrolled.y()); | |
406 } | |
407 | |
408 void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) { | |
409 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id); | |
410 } | |
411 | |
412 bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const { | |
413 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_ | |
414 : user_scrollable_vertical_; | |
415 } | |
416 | |
417 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { | |
418 DCHECK(layer_tree_impl()->IsActiveTree()); | |
419 scroll_offset_->AbortCommit(); | |
420 } | |
421 | |
422 InputHandler::ScrollStatus LayerImpl::TryScroll( | |
423 const gfx::PointF& screen_space_point, | |
424 InputHandler::ScrollInputType type, | |
425 ScrollBlocksOn effective_block_mode) const { | |
426 if (should_scroll_on_main_thread()) { | |
427 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread"); | |
428 return InputHandler::SCROLL_ON_MAIN_THREAD; | |
429 } | |
430 | |
431 if (!screen_space_transform().IsInvertible()) { | |
432 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform"); | |
433 return InputHandler::SCROLL_IGNORED; | |
434 } | |
435 | |
436 if (!non_fast_scrollable_region().IsEmpty()) { | |
437 bool clipped = false; | |
438 gfx::Transform inverse_screen_space_transform( | |
439 gfx::Transform::kSkipInitialization); | |
440 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) { | |
441 // TODO(shawnsingh): We shouldn't be applying a projection if screen space | |
442 // transform is uninvertible here. Perhaps we should be returning | |
443 // SCROLL_ON_MAIN_THREAD in this case? | |
444 } | |
445 | |
446 gfx::PointF hit_test_point_in_content_space = | |
447 MathUtil::ProjectPoint(inverse_screen_space_transform, | |
448 screen_space_point, | |
449 &clipped); | |
450 gfx::PointF hit_test_point_in_layer_space = | |
451 gfx::ScalePoint(hit_test_point_in_content_space, | |
452 1.f / contents_scale_x(), | |
453 1.f / contents_scale_y()); | |
454 if (!clipped && | |
455 non_fast_scrollable_region().Contains( | |
456 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) { | |
457 TRACE_EVENT0("cc", | |
458 "LayerImpl::tryScroll: Failed NonFastScrollableRegion"); | |
459 return InputHandler::SCROLL_ON_MAIN_THREAD; | |
460 } | |
461 } | |
462 | |
463 if (have_scroll_event_handlers() && | |
464 effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) { | |
465 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers"); | |
466 return InputHandler::SCROLL_ON_MAIN_THREAD; | |
467 } | |
468 | |
469 if (type == InputHandler::WHEEL && have_wheel_event_handlers() && | |
470 effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) { | |
471 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); | |
472 return InputHandler::SCROLL_ON_MAIN_THREAD; | |
473 } | |
474 | |
475 if (!scrollable()) { | |
476 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); | |
477 return InputHandler::SCROLL_IGNORED; | |
478 } | |
479 | |
480 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset(); | |
481 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) { | |
482 TRACE_EVENT0("cc", | |
483 "LayerImpl::tryScroll: Ignored. Technically scrollable," | |
484 " but has no affordance in either direction."); | |
485 return InputHandler::SCROLL_IGNORED; | |
486 } | |
487 | |
488 return InputHandler::SCROLL_STARTED; | |
489 } | |
490 | |
491 gfx::Rect LayerImpl::LayerRectToContentRect( | |
492 const gfx::RectF& layer_rect) const { | |
493 gfx::RectF content_rect = | |
494 gfx::ScaleRect(layer_rect, contents_scale_x(), contents_scale_y()); | |
495 // Intersect with content rect to avoid the extra pixel because for some | |
496 // values x and y, ceil((x / y) * y) may be x + 1. | |
497 content_rect.Intersect(gfx::Rect(content_bounds())); | |
498 return gfx::ToEnclosingRect(content_rect); | |
499 } | |
500 | |
501 skia::RefPtr<SkPicture> LayerImpl::GetPicture() { | |
502 return skia::RefPtr<SkPicture>(); | |
503 } | |
504 | |
505 scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) { | |
506 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_); | |
507 } | |
508 | |
509 void LayerImpl::PushPropertiesTo(LayerImpl* layer) { | |
510 layer->SetTransformOrigin(transform_origin_); | |
511 layer->SetBackgroundColor(background_color_); | |
512 layer->SetBounds(bounds_); | |
513 layer->SetContentBounds(content_bounds()); | |
514 layer->SetContentsScale(contents_scale_x(), contents_scale_y()); | |
515 layer->SetDoubleSided(double_sided_); | |
516 layer->SetDrawCheckerboardForMissingTiles( | |
517 draw_checkerboard_for_missing_tiles_); | |
518 layer->SetDrawsContent(DrawsContent()); | |
519 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_); | |
520 layer->SetHasRenderSurface(!!render_surface() || layer->HasCopyRequest()); | |
521 layer->SetFilters(filters()); | |
522 layer->SetBackgroundFilters(background_filters()); | |
523 layer->SetMasksToBounds(masks_to_bounds_); | |
524 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_); | |
525 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_); | |
526 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_); | |
527 layer->SetScrollBlocksOn(scroll_blocks_on_); | |
528 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); | |
529 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); | |
530 layer->SetContentsOpaque(contents_opaque_); | |
531 layer->SetOpacity(opacity_); | |
532 layer->SetBlendMode(blend_mode_); | |
533 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_); | |
534 layer->SetPosition(position_); | |
535 layer->SetIsContainerForFixedPositionLayers( | |
536 is_container_for_fixed_position_layers_); | |
537 layer->SetPositionConstraint(position_constraint_); | |
538 layer->SetShouldFlattenTransform(should_flatten_transform_); | |
539 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | |
540 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | |
541 | |
542 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() | |
543 : Layer::INVALID_ID); | |
544 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | |
545 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | |
546 | |
547 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_); | |
548 | |
549 layer->PushScrollOffset(nullptr); | |
550 | |
551 layer->Set3dSortingContextId(sorting_context_id_); | |
552 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | |
553 | |
554 LayerImpl* scroll_parent = nullptr; | |
555 if (scroll_parent_) { | |
556 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | |
557 DCHECK(scroll_parent); | |
558 } | |
559 | |
560 layer->SetScrollParent(scroll_parent); | |
561 if (scroll_children_) { | |
562 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | |
563 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin(); | |
564 it != scroll_children_->end(); | |
565 ++it) { | |
566 DCHECK_EQ((*it)->scroll_parent(), this); | |
567 LayerImpl* scroll_child = | |
568 layer->layer_tree_impl()->LayerById((*it)->id()); | |
569 DCHECK(scroll_child); | |
570 scroll_children->insert(scroll_child); | |
571 } | |
572 layer->SetScrollChildren(scroll_children); | |
573 } else { | |
574 layer->SetScrollChildren(nullptr); | |
575 } | |
576 | |
577 LayerImpl* clip_parent = nullptr; | |
578 if (clip_parent_) { | |
579 clip_parent = layer->layer_tree_impl()->LayerById( | |
580 clip_parent_->id()); | |
581 DCHECK(clip_parent); | |
582 } | |
583 | |
584 layer->SetClipParent(clip_parent); | |
585 if (clip_children_) { | |
586 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>; | |
587 for (std::set<LayerImpl*>::iterator it = clip_children_->begin(); | |
588 it != clip_children_->end(); ++it) | |
589 clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id())); | |
590 layer->SetClipChildren(clip_children); | |
591 } else { | |
592 layer->SetClipChildren(nullptr); | |
593 } | |
594 | |
595 layer->PassCopyRequests(©_requests_); | |
596 | |
597 // If the main thread commits multiple times before the impl thread actually | |
598 // draws, then damage tracking will become incorrect if we simply clobber the | |
599 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. | |
600 // union) any update changes that have occurred on the main thread. | |
601 update_rect_.Union(layer->update_rect()); | |
602 layer->SetUpdateRect(update_rect_); | |
603 | |
604 layer->SetStackingOrderChanged(stacking_order_changed_); | |
605 layer->SetDebugInfo(debug_info_); | |
606 | |
607 if (frame_timing_requests_dirty_) { | |
608 layer->PassFrameTimingRequests(&frame_timing_requests_); | |
609 frame_timing_requests_dirty_ = false; | |
610 } | |
611 | |
612 // Reset any state that should be cleared for the next update. | |
613 stacking_order_changed_ = false; | |
614 update_rect_ = gfx::Rect(); | |
615 needs_push_properties_ = false; | |
616 num_dependents_need_push_properties_ = 0; | |
617 } | |
618 | |
619 gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const { | |
620 if (!scroll_clip_layer_) | |
621 return gfx::Vector2dF(); | |
622 | |
623 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta(); | |
624 | |
625 // In virtual-viewport mode, we don't need to compensate for pinch zoom or | |
626 // scale since the fixed container is the outer viewport, which sits below | |
627 // the page scale. | |
628 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) | |
629 return delta_from_scroll; | |
630 | |
631 float scale_delta = layer_tree_impl()->page_scale_delta(); | |
632 float scale = layer_tree_impl()->current_page_scale_factor() / | |
633 layer_tree_impl()->page_scale_delta(); | |
634 | |
635 delta_from_scroll.Scale(1.f / scale); | |
636 | |
637 // The delta-from-pinch component requires some explanation: A viewport of | |
638 // size (w,h) will appear to be size (w/s,h/s) under scale s in the content | |
639 // space. If s -> s' on the impl thread, where s' = s * ds, then the apparent | |
640 // viewport size change in the content space due to ds is: | |
641 // | |
642 // (w/s',h/s') - (w/s,h/s) = (w,h)(1/s' - 1/s) = (w,h)(1 - ds)/(s ds) | |
643 // | |
644 gfx::Vector2dF delta_from_pinch = | |
645 gfx::Rect(scroll_clip_layer_->bounds()).bottom_right() - gfx::PointF(); | |
646 delta_from_pinch.Scale((1.f - scale_delta) / (scale * scale_delta)); | |
647 | |
648 return delta_from_scroll + delta_from_pinch; | |
649 } | |
650 | |
651 base::DictionaryValue* LayerImpl::LayerTreeAsJson() const { | |
652 base::DictionaryValue* result = new base::DictionaryValue; | |
653 result->SetString("LayerType", LayerTypeAsString()); | |
654 | |
655 base::ListValue* list = new base::ListValue; | |
656 list->AppendInteger(bounds().width()); | |
657 list->AppendInteger(bounds().height()); | |
658 result->Set("Bounds", list); | |
659 | |
660 list = new base::ListValue; | |
661 list->AppendDouble(position_.x()); | |
662 list->AppendDouble(position_.y()); | |
663 result->Set("Position", list); | |
664 | |
665 const gfx::Transform& gfx_transform = draw_properties_.target_space_transform; | |
666 double transform[16]; | |
667 gfx_transform.matrix().asColMajord(transform); | |
668 list = new base::ListValue; | |
669 for (int i = 0; i < 16; ++i) | |
670 list->AppendDouble(transform[i]); | |
671 result->Set("DrawTransform", list); | |
672 | |
673 result->SetBoolean("DrawsContent", draws_content_); | |
674 result->SetBoolean("Is3dSorted", Is3dSorted()); | |
675 result->SetDouble("OPACITY", opacity()); | |
676 result->SetBoolean("ContentsOpaque", contents_opaque_); | |
677 | |
678 if (scrollable()) | |
679 result->SetBoolean("Scrollable", true); | |
680 | |
681 if (have_wheel_event_handlers_) | |
682 result->SetBoolean("WheelHandler", have_wheel_event_handlers_); | |
683 if (have_scroll_event_handlers_) | |
684 result->SetBoolean("ScrollHandler", have_scroll_event_handlers_); | |
685 if (!touch_event_handler_region_.IsEmpty()) { | |
686 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue(); | |
687 result->Set("TouchRegion", region.release()); | |
688 } | |
689 | |
690 if (scroll_blocks_on_) { | |
691 list = new base::ListValue; | |
692 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH) | |
693 list->AppendString("StartTouch"); | |
694 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT) | |
695 list->AppendString("WheelEvent"); | |
696 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT) | |
697 list->AppendString("ScrollEvent"); | |
698 result->Set("ScrollBlocksOn", list); | |
699 } | |
700 | |
701 list = new base::ListValue; | |
702 for (size_t i = 0; i < children_.size(); ++i) | |
703 list->Append(children_[i]->LayerTreeAsJson()); | |
704 result->Set("Children", list); | |
705 | |
706 return result; | |
707 } | |
708 | |
709 void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) { | |
710 if (stacking_order_changed) { | |
711 stacking_order_changed_ = true; | |
712 NoteLayerPropertyChangedForSubtree(); | |
713 } | |
714 } | |
715 | |
716 void LayerImpl::NoteLayerPropertyChanged() { | |
717 layer_property_changed_ = true; | |
718 layer_tree_impl()->set_needs_update_draw_properties(); | |
719 SetNeedsPushProperties(); | |
720 } | |
721 | |
722 void LayerImpl::NoteLayerPropertyChangedForSubtree() { | |
723 layer_property_changed_ = true; | |
724 layer_tree_impl()->set_needs_update_draw_properties(); | |
725 for (size_t i = 0; i < children_.size(); ++i) | |
726 children_[i]->NoteLayerPropertyChangedForDescendantsInternal(); | |
727 SetNeedsPushProperties(); | |
728 } | |
729 | |
730 void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() { | |
731 layer_property_changed_ = true; | |
732 for (size_t i = 0; i < children_.size(); ++i) | |
733 children_[i]->NoteLayerPropertyChangedForDescendantsInternal(); | |
734 } | |
735 | |
736 void LayerImpl::NoteLayerPropertyChangedForDescendants() { | |
737 layer_tree_impl()->set_needs_update_draw_properties(); | |
738 for (size_t i = 0; i < children_.size(); ++i) | |
739 children_[i]->NoteLayerPropertyChangedForDescendantsInternal(); | |
740 SetNeedsPushProperties(); | |
741 } | |
742 | |
743 const char* LayerImpl::LayerTypeAsString() const { | |
744 return "cc::LayerImpl"; | |
745 } | |
746 | |
747 void LayerImpl::ResetAllChangeTrackingForSubtree() { | |
748 layer_property_changed_ = false; | |
749 | |
750 update_rect_ = gfx::Rect(); | |
751 damage_rect_ = gfx::RectF(); | |
752 | |
753 if (render_surface_) | |
754 render_surface_->ResetPropertyChangedFlag(); | |
755 | |
756 if (mask_layer_) | |
757 mask_layer_->ResetAllChangeTrackingForSubtree(); | |
758 | |
759 if (replica_layer_) { | |
760 // This also resets the replica mask, if it exists. | |
761 replica_layer_->ResetAllChangeTrackingForSubtree(); | |
762 } | |
763 | |
764 for (size_t i = 0; i < children_.size(); ++i) | |
765 children_[i]->ResetAllChangeTrackingForSubtree(); | |
766 | |
767 needs_push_properties_ = false; | |
768 num_dependents_need_push_properties_ = 0; | |
769 } | |
770 | |
771 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const { | |
772 return CurrentScrollOffset(); | |
773 } | |
774 | |
775 void LayerImpl::OnFilterAnimated(const FilterOperations& filters) { | |
776 SetFilters(filters); | |
777 } | |
778 | |
779 void LayerImpl::OnOpacityAnimated(float opacity) { | |
780 SetOpacity(opacity); | |
781 } | |
782 | |
783 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { | |
784 SetTransform(transform); | |
785 } | |
786 | |
787 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { | |
788 // Only layers in the active tree should need to do anything here, since | |
789 // layers in the pending tree will find out about these changes as a | |
790 // result of the shared SyncedProperty. | |
791 if (!IsActive()) | |
792 return; | |
793 | |
794 SetCurrentScrollOffset(scroll_offset); | |
795 | |
796 layer_tree_impl_->DidAnimateScrollOffset(); | |
797 } | |
798 | |
799 void LayerImpl::OnAnimationWaitingForDeletion() {} | |
800 | |
801 bool LayerImpl::IsActive() const { | |
802 return layer_tree_impl_->IsActiveTree(); | |
803 } | |
804 | |
805 gfx::Size LayerImpl::bounds() const { | |
806 gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_); | |
807 return gfx::Size(bounds_.width() + delta.x(), | |
808 bounds_.height() + delta.y()); | |
809 } | |
810 | |
811 gfx::SizeF LayerImpl::BoundsForScrolling() const { | |
812 return gfx::SizeF(bounds_.width() + bounds_delta_.x(), | |
813 bounds_.height() + bounds_delta_.y()); | |
814 } | |
815 | |
816 void LayerImpl::SetBounds(const gfx::Size& bounds) { | |
817 if (bounds_ == bounds) | |
818 return; | |
819 | |
820 bounds_ = bounds; | |
821 | |
822 ScrollbarParametersDidChange(true); | |
823 if (masks_to_bounds()) | |
824 NoteLayerPropertyChangedForSubtree(); | |
825 else | |
826 NoteLayerPropertyChanged(); | |
827 } | |
828 | |
829 void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) { | |
830 if (bounds_delta_ == bounds_delta) | |
831 return; | |
832 | |
833 bounds_delta_ = bounds_delta; | |
834 | |
835 ScrollbarParametersDidChange(true); | |
836 if (masks_to_bounds()) | |
837 NoteLayerPropertyChangedForSubtree(); | |
838 else | |
839 NoteLayerPropertyChanged(); | |
840 } | |
841 | |
842 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { | |
843 int new_layer_id = mask_layer ? mask_layer->id() : -1; | |
844 | |
845 if (mask_layer) { | |
846 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl()); | |
847 DCHECK_NE(new_layer_id, mask_layer_id_); | |
848 } else if (new_layer_id == mask_layer_id_) { | |
849 return; | |
850 } | |
851 | |
852 mask_layer_ = mask_layer.Pass(); | |
853 mask_layer_id_ = new_layer_id; | |
854 if (mask_layer_) | |
855 mask_layer_->SetParent(this); | |
856 NoteLayerPropertyChangedForSubtree(); | |
857 } | |
858 | |
859 scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() { | |
860 mask_layer_id_ = -1; | |
861 return mask_layer_.Pass(); | |
862 } | |
863 | |
864 void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) { | |
865 int new_layer_id = replica_layer ? replica_layer->id() : -1; | |
866 | |
867 if (replica_layer) { | |
868 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl()); | |
869 DCHECK_NE(new_layer_id, replica_layer_id_); | |
870 } else if (new_layer_id == replica_layer_id_) { | |
871 return; | |
872 } | |
873 | |
874 replica_layer_ = replica_layer.Pass(); | |
875 replica_layer_id_ = new_layer_id; | |
876 if (replica_layer_) | |
877 replica_layer_->SetParent(this); | |
878 NoteLayerPropertyChangedForSubtree(); | |
879 } | |
880 | |
881 scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() { | |
882 replica_layer_id_ = -1; | |
883 return replica_layer_.Pass(); | |
884 } | |
885 | |
886 ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { | |
887 return nullptr; | |
888 } | |
889 | |
890 void LayerImpl::SetDrawsContent(bool draws_content) { | |
891 if (draws_content_ == draws_content) | |
892 return; | |
893 | |
894 draws_content_ = draws_content; | |
895 NoteLayerPropertyChanged(); | |
896 } | |
897 | |
898 void LayerImpl::SetHideLayerAndSubtree(bool hide) { | |
899 if (hide_layer_and_subtree_ == hide) | |
900 return; | |
901 | |
902 hide_layer_and_subtree_ = hide; | |
903 NoteLayerPropertyChangedForSubtree(); | |
904 } | |
905 | |
906 void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) { | |
907 if (transform_origin_ == transform_origin) | |
908 return; | |
909 transform_origin_ = transform_origin; | |
910 NoteLayerPropertyChangedForSubtree(); | |
911 } | |
912 | |
913 void LayerImpl::SetBackgroundColor(SkColor background_color) { | |
914 if (background_color_ == background_color) | |
915 return; | |
916 | |
917 background_color_ = background_color; | |
918 NoteLayerPropertyChanged(); | |
919 } | |
920 | |
921 SkColor LayerImpl::SafeOpaqueBackgroundColor() const { | |
922 SkColor color = background_color(); | |
923 if (SkColorGetA(color) == 255 && !contents_opaque()) { | |
924 color = SK_ColorTRANSPARENT; | |
925 } else if (SkColorGetA(color) != 255 && contents_opaque()) { | |
926 for (const LayerImpl* layer = parent(); layer; | |
927 layer = layer->parent()) { | |
928 color = layer->background_color(); | |
929 if (SkColorGetA(color) == 255) | |
930 break; | |
931 } | |
932 if (SkColorGetA(color) != 255) | |
933 color = layer_tree_impl()->background_color(); | |
934 if (SkColorGetA(color) != 255) | |
935 color = SkColorSetA(color, 255); | |
936 } | |
937 return color; | |
938 } | |
939 | |
940 void LayerImpl::SetFilters(const FilterOperations& filters) { | |
941 if (filters_ == filters) | |
942 return; | |
943 | |
944 filters_ = filters; | |
945 NoteLayerPropertyChangedForSubtree(); | |
946 } | |
947 | |
948 bool LayerImpl::FilterIsAnimating() const { | |
949 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER); | |
950 } | |
951 | |
952 bool LayerImpl::FilterIsAnimatingOnImplOnly() const { | |
953 Animation* filter_animation = | |
954 layer_animation_controller_->GetAnimation(Animation::FILTER); | |
955 return filter_animation && filter_animation->is_impl_only(); | |
956 } | |
957 | |
958 void LayerImpl::SetBackgroundFilters( | |
959 const FilterOperations& filters) { | |
960 if (background_filters_ == filters) | |
961 return; | |
962 | |
963 background_filters_ = filters; | |
964 NoteLayerPropertyChanged(); | |
965 } | |
966 | |
967 void LayerImpl::SetMasksToBounds(bool masks_to_bounds) { | |
968 if (masks_to_bounds_ == masks_to_bounds) | |
969 return; | |
970 | |
971 masks_to_bounds_ = masks_to_bounds; | |
972 NoteLayerPropertyChangedForSubtree(); | |
973 } | |
974 | |
975 void LayerImpl::SetContentsOpaque(bool opaque) { | |
976 if (contents_opaque_ == opaque) | |
977 return; | |
978 | |
979 contents_opaque_ = opaque; | |
980 NoteLayerPropertyChangedForSubtree(); | |
981 } | |
982 | |
983 void LayerImpl::SetOpacity(float opacity) { | |
984 if (opacity_ == opacity) | |
985 return; | |
986 | |
987 opacity_ = opacity; | |
988 NoteLayerPropertyChangedForSubtree(); | |
989 } | |
990 | |
991 bool LayerImpl::OpacityIsAnimating() const { | |
992 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY); | |
993 } | |
994 | |
995 bool LayerImpl::OpacityIsAnimatingOnImplOnly() const { | |
996 Animation* opacity_animation = | |
997 layer_animation_controller_->GetAnimation(Animation::OPACITY); | |
998 return opacity_animation && opacity_animation->is_impl_only(); | |
999 } | |
1000 | |
1001 void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) { | |
1002 if (blend_mode_ == blend_mode) | |
1003 return; | |
1004 | |
1005 blend_mode_ = blend_mode; | |
1006 NoteLayerPropertyChangedForSubtree(); | |
1007 } | |
1008 | |
1009 void LayerImpl::SetIsRootForIsolatedGroup(bool root) { | |
1010 if (is_root_for_isolated_group_ == root) | |
1011 return; | |
1012 | |
1013 is_root_for_isolated_group_ = root; | |
1014 SetNeedsPushProperties(); | |
1015 } | |
1016 | |
1017 void LayerImpl::SetPosition(const gfx::PointF& position) { | |
1018 if (position_ == position) | |
1019 return; | |
1020 | |
1021 position_ = position; | |
1022 NoteLayerPropertyChangedForSubtree(); | |
1023 } | |
1024 | |
1025 void LayerImpl::SetShouldFlattenTransform(bool flatten) { | |
1026 if (should_flatten_transform_ == flatten) | |
1027 return; | |
1028 | |
1029 should_flatten_transform_ = flatten; | |
1030 NoteLayerPropertyChangedForSubtree(); | |
1031 } | |
1032 | |
1033 void LayerImpl::Set3dSortingContextId(int id) { | |
1034 if (id == sorting_context_id_) | |
1035 return; | |
1036 sorting_context_id_ = id; | |
1037 NoteLayerPropertyChangedForSubtree(); | |
1038 } | |
1039 | |
1040 void LayerImpl::PassFrameTimingRequests( | |
1041 std::vector<FrameTimingRequest>* requests) { | |
1042 frame_timing_requests_.swap(*requests); | |
1043 frame_timing_requests_dirty_ = true; | |
1044 SetNeedsPushProperties(); | |
1045 } | |
1046 | |
1047 void LayerImpl::SetTransform(const gfx::Transform& transform) { | |
1048 if (transform_ == transform) | |
1049 return; | |
1050 | |
1051 transform_ = transform; | |
1052 transform_is_invertible_ = transform_.IsInvertible(); | |
1053 NoteLayerPropertyChangedForSubtree(); | |
1054 } | |
1055 | |
1056 void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform, | |
1057 bool transform_is_invertible) { | |
1058 if (transform_ == transform) { | |
1059 DCHECK(transform_is_invertible_ == transform_is_invertible) | |
1060 << "Can't change invertibility if transform is unchanged"; | |
1061 return; | |
1062 } | |
1063 transform_ = transform; | |
1064 transform_is_invertible_ = transform_is_invertible; | |
1065 NoteLayerPropertyChangedForSubtree(); | |
1066 } | |
1067 | |
1068 bool LayerImpl::TransformIsAnimating() const { | |
1069 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM); | |
1070 } | |
1071 | |
1072 bool LayerImpl::TransformIsAnimatingOnImplOnly() const { | |
1073 Animation* transform_animation = | |
1074 layer_animation_controller_->GetAnimation(Animation::TRANSFORM); | |
1075 return transform_animation && transform_animation->is_impl_only(); | |
1076 } | |
1077 | |
1078 void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) { | |
1079 update_rect_ = update_rect; | |
1080 SetNeedsPushProperties(); | |
1081 } | |
1082 | |
1083 void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) { | |
1084 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect); | |
1085 } | |
1086 | |
1087 void LayerImpl::SetContentBounds(const gfx::Size& content_bounds) { | |
1088 if (this->content_bounds() == content_bounds) | |
1089 return; | |
1090 | |
1091 draw_properties_.content_bounds = content_bounds; | |
1092 NoteLayerPropertyChanged(); | |
1093 } | |
1094 | |
1095 void LayerImpl::SetContentsScale(float contents_scale_x, | |
1096 float contents_scale_y) { | |
1097 if (this->contents_scale_x() == contents_scale_x && | |
1098 this->contents_scale_y() == contents_scale_y) | |
1099 return; | |
1100 | |
1101 draw_properties_.contents_scale_x = contents_scale_x; | |
1102 draw_properties_.contents_scale_y = contents_scale_y; | |
1103 NoteLayerPropertyChanged(); | |
1104 } | |
1105 | |
1106 void LayerImpl::SetScrollOffsetDelegate( | |
1107 ScrollOffsetDelegate* scroll_offset_delegate) { | |
1108 // Having both a scroll parent and a scroll offset delegate is unsupported. | |
1109 DCHECK(!scroll_parent_); | |
1110 RefreshFromScrollDelegate(); | |
1111 scroll_offset_delegate_ = scroll_offset_delegate; | |
1112 if (scroll_offset_delegate_) | |
1113 scroll_offset_delegate_->SetCurrentScrollOffset(CurrentScrollOffset()); | |
1114 } | |
1115 | |
1116 bool LayerImpl::IsExternalFlingActive() const { | |
1117 return scroll_offset_delegate_ && | |
1118 scroll_offset_delegate_->IsExternalFlingActive(); | |
1119 } | |
1120 | |
1121 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { | |
1122 DCHECK(IsActive()); | |
1123 if (scroll_offset_->SetCurrent(scroll_offset)) | |
1124 DidUpdateScrollOffset(); | |
1125 } | |
1126 | |
1127 void LayerImpl::PushScrollOffsetFromMainThread( | |
1128 const gfx::ScrollOffset& scroll_offset) { | |
1129 PushScrollOffset(&scroll_offset); | |
1130 } | |
1131 | |
1132 void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue( | |
1133 const gfx::ScrollOffset& scroll_offset) { | |
1134 scroll_offset_->set_clobber_active_value(); | |
1135 PushScrollOffset(&scroll_offset); | |
1136 } | |
1137 | |
1138 gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() { | |
1139 RefreshFromScrollDelegate(); | |
1140 | |
1141 // TODO(miletus): Remove all this temporary flooring machinery when | |
1142 // Blink fully supports fractional scrolls. | |
1143 gfx::ScrollOffset current_offset = CurrentScrollOffset(); | |
1144 gfx::Vector2dF current_delta = ScrollDelta(); | |
1145 gfx::Vector2dF floored_delta(floor(current_delta.x()), | |
1146 floor(current_delta.y())); | |
1147 gfx::Vector2dF diff_delta = floored_delta - current_delta; | |
1148 gfx::ScrollOffset tmp_offset = ScrollOffsetWithDelta(current_offset, | |
1149 diff_delta); | |
1150 scroll_offset_->SetCurrent(tmp_offset); | |
1151 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread(); | |
1152 scroll_offset_->SetCurrent(current_offset); | |
1153 return delta; | |
1154 } | |
1155 | |
1156 void LayerImpl::RefreshFromScrollDelegate() { | |
1157 if (scroll_offset_delegate_) { | |
1158 SetCurrentScrollOffset( | |
1159 gfx::ScrollOffset(scroll_offset_delegate_->GetCurrentScrollOffset())); | |
1160 } | |
1161 } | |
1162 | |
1163 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { | |
1164 return scroll_offset_->Current(IsActive()); | |
1165 } | |
1166 | |
1167 gfx::Vector2dF LayerImpl::ScrollDelta() const { | |
1168 if (IsActive()) | |
1169 return gfx::Vector2dF(scroll_offset_->Delta().x(), | |
1170 scroll_offset_->Delta().y()); | |
1171 else | |
1172 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(), | |
1173 scroll_offset_->PendingDelta().get().y()); | |
1174 } | |
1175 | |
1176 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) { | |
1177 DCHECK(IsActive()); | |
1178 SetCurrentScrollOffset(scroll_offset_->ActiveBase() + | |
1179 gfx::ScrollOffset(delta)); | |
1180 } | |
1181 | |
1182 gfx::ScrollOffset LayerImpl::BaseScrollOffset() const { | |
1183 if (IsActive()) | |
1184 return scroll_offset_->ActiveBase(); | |
1185 else | |
1186 return scroll_offset_->PendingBase(); | |
1187 } | |
1188 | |
1189 void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) { | |
1190 DCHECK(scroll_offset || IsActive()); | |
1191 bool changed = false; | |
1192 if (scroll_offset) { | |
1193 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id())); | |
1194 changed |= scroll_offset_->PushFromMainThread(*scroll_offset); | |
1195 } | |
1196 if (IsActive()) { | |
1197 changed |= scroll_offset_->PushPendingToActive(); | |
1198 } | |
1199 | |
1200 if (changed) | |
1201 DidUpdateScrollOffset(); | |
1202 } | |
1203 | |
1204 void LayerImpl::DidUpdateScrollOffset() { | |
1205 if (scroll_offset_delegate_) { | |
1206 scroll_offset_delegate_->SetCurrentScrollOffset(CurrentScrollOffset()); | |
1207 scroll_offset_delegate_->Update(); | |
1208 RefreshFromScrollDelegate(); | |
1209 } | |
1210 | |
1211 NoteLayerPropertyChangedForSubtree(); | |
1212 ScrollbarParametersDidChange(false); | |
1213 } | |
1214 | |
1215 void LayerImpl::SetDoubleSided(bool double_sided) { | |
1216 if (double_sided_ == double_sided) | |
1217 return; | |
1218 | |
1219 double_sided_ = double_sided; | |
1220 NoteLayerPropertyChangedForSubtree(); | |
1221 } | |
1222 | |
1223 SimpleEnclosedRegion LayerImpl::VisibleContentOpaqueRegion() const { | |
1224 if (contents_opaque()) | |
1225 return SimpleEnclosedRegion(visible_content_rect()); | |
1226 return SimpleEnclosedRegion(); | |
1227 } | |
1228 | |
1229 void LayerImpl::DidBeginTracing() {} | |
1230 | |
1231 void LayerImpl::ReleaseResources() {} | |
1232 | |
1233 void LayerImpl::RecreateResources() { | |
1234 } | |
1235 | |
1236 gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { | |
1237 if (!scroll_clip_layer_ || bounds().IsEmpty()) | |
1238 return gfx::ScrollOffset(); | |
1239 | |
1240 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer(); | |
1241 DCHECK(this != page_scale_layer); | |
1242 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() || | |
1243 IsContainerForFixedPositionLayers()); | |
1244 | |
1245 float scale_factor = 1.f; | |
1246 for (LayerImpl const* current_layer = this; | |
1247 current_layer != scroll_clip_layer_->parent(); | |
1248 current_layer = current_layer->parent()) { | |
1249 if (current_layer == page_scale_layer) | |
1250 scale_factor = layer_tree_impl()->current_page_scale_factor(); | |
1251 } | |
1252 | |
1253 gfx::SizeF scaled_scroll_bounds = | |
1254 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor)); | |
1255 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds); | |
1256 | |
1257 gfx::ScrollOffset max_offset( | |
1258 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), | |
1259 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); | |
1260 // We need the final scroll offset to be in CSS coords. | |
1261 max_offset.Scale(1 / scale_factor); | |
1262 max_offset.SetToMax(gfx::ScrollOffset()); | |
1263 return max_offset; | |
1264 } | |
1265 | |
1266 gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits( | |
1267 gfx::ScrollOffset offset) const { | |
1268 offset.SetToMin(MaxScrollOffset()); | |
1269 offset.SetToMax(gfx::ScrollOffset()); | |
1270 return offset; | |
1271 } | |
1272 | |
1273 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { | |
1274 gfx::ScrollOffset old_offset = CurrentScrollOffset(); | |
1275 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset); | |
1276 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset); | |
1277 if (!delta.IsZero()) | |
1278 ScrollBy(delta); | |
1279 return delta; | |
1280 } | |
1281 | |
1282 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, | |
1283 LayerImpl* scrollbar_clip_layer, | |
1284 bool on_resize) const { | |
1285 DCHECK(scrollbar_layer); | |
1286 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer(); | |
1287 | |
1288 DCHECK(this != page_scale_layer); | |
1289 DCHECK(scrollbar_clip_layer); | |
1290 gfx::RectF clip_rect(gfx::PointF(), | |
1291 scrollbar_clip_layer->BoundsForScrolling()); | |
1292 | |
1293 // See comment in MaxScrollOffset() regarding the use of the content layer | |
1294 // bounds here. | |
1295 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling()); | |
1296 | |
1297 if (scroll_rect.size().IsEmpty()) | |
1298 return; | |
1299 | |
1300 gfx::ScrollOffset current_offset; | |
1301 for (LayerImpl const* current_layer = this; | |
1302 current_layer != scrollbar_clip_layer->parent(); | |
1303 current_layer = current_layer->parent()) { | |
1304 current_offset += current_layer->CurrentScrollOffset(); | |
1305 if (current_layer == page_scale_layer) { | |
1306 float scale_factor = layer_tree_impl()->current_page_scale_factor(); | |
1307 current_offset.Scale(scale_factor); | |
1308 scroll_rect.Scale(scale_factor); | |
1309 } | |
1310 } | |
1311 | |
1312 bool scrollbar_needs_animation = false; | |
1313 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust( | |
1314 scrollbar_clip_layer->bounds_delta().y()); | |
1315 if (scrollbar_layer->orientation() == HORIZONTAL) { | |
1316 float visible_ratio = clip_rect.width() / scroll_rect.width(); | |
1317 scrollbar_needs_animation |= | |
1318 scrollbar_layer->SetCurrentPos(current_offset.x()); | |
1319 scrollbar_needs_animation |= | |
1320 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width()); | |
1321 scrollbar_needs_animation |= | |
1322 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); | |
1323 } else { | |
1324 float visible_ratio = clip_rect.height() / scroll_rect.height(); | |
1325 scrollbar_needs_animation |= | |
1326 scrollbar_layer->SetCurrentPos(current_offset.y()); | |
1327 scrollbar_needs_animation |= | |
1328 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height()); | |
1329 scrollbar_needs_animation |= | |
1330 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); | |
1331 } | |
1332 if (scrollbar_needs_animation) { | |
1333 layer_tree_impl()->set_needs_update_draw_properties(); | |
1334 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars | |
1335 // should activate for every scroll on the main frame, not just the | |
1336 // scrolls that move the pinch virtual viewport (i.e. trigger from | |
1337 // either inner or outer viewport). | |
1338 if (scrollbar_animation_controller_) { | |
1339 // Non-overlay scrollbars shouldn't trigger animations. | |
1340 if (scrollbar_layer->is_overlay_scrollbar()) | |
1341 scrollbar_animation_controller_->DidScrollUpdate(on_resize); | |
1342 } | |
1343 } | |
1344 } | |
1345 | |
1346 void LayerImpl::DidBecomeActive() { | |
1347 if (layer_tree_impl_->settings().scrollbar_animator == | |
1348 LayerTreeSettings::NO_ANIMATOR) { | |
1349 return; | |
1350 } | |
1351 | |
1352 bool need_scrollbar_animation_controller = scrollable() && scrollbars_; | |
1353 if (!need_scrollbar_animation_controller) { | |
1354 scrollbar_animation_controller_ = nullptr; | |
1355 return; | |
1356 } | |
1357 | |
1358 if (scrollbar_animation_controller_) | |
1359 return; | |
1360 | |
1361 scrollbar_animation_controller_ = | |
1362 layer_tree_impl_->CreateScrollbarAnimationController(this); | |
1363 } | |
1364 | |
1365 void LayerImpl::ClearScrollbars() { | |
1366 if (!scrollbars_) | |
1367 return; | |
1368 | |
1369 scrollbars_.reset(nullptr); | |
1370 } | |
1371 | |
1372 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) { | |
1373 DCHECK(layer); | |
1374 DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end()); | |
1375 if (!scrollbars_) | |
1376 scrollbars_.reset(new ScrollbarSet()); | |
1377 | |
1378 scrollbars_->insert(layer); | |
1379 } | |
1380 | |
1381 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) { | |
1382 DCHECK(scrollbars_); | |
1383 DCHECK(layer); | |
1384 DCHECK(scrollbars_->find(layer) != scrollbars_->end()); | |
1385 | |
1386 scrollbars_->erase(layer); | |
1387 if (scrollbars_->empty()) | |
1388 scrollbars_ = nullptr; | |
1389 } | |
1390 | |
1391 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const { | |
1392 if (!scrollbars_) | |
1393 return false; | |
1394 | |
1395 for (ScrollbarSet::iterator it = scrollbars_->begin(); | |
1396 it != scrollbars_->end(); | |
1397 ++it) | |
1398 if ((*it)->orientation() == orientation) | |
1399 return true; | |
1400 | |
1401 return false; | |
1402 } | |
1403 | |
1404 void LayerImpl::ScrollbarParametersDidChange(bool on_resize) { | |
1405 if (!scrollbars_) | |
1406 return; | |
1407 | |
1408 for (ScrollbarSet::iterator it = scrollbars_->begin(); | |
1409 it != scrollbars_->end(); | |
1410 ++it) { | |
1411 bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_; | |
1412 bool scroll_layer_resized = is_scroll_layer && on_resize; | |
1413 (*it)->ScrollbarParametersDidChange(scroll_layer_resized); | |
1414 } | |
1415 } | |
1416 | |
1417 void LayerImpl::SetNeedsPushProperties() { | |
1418 if (needs_push_properties_) | |
1419 return; | |
1420 if (!parent_should_know_need_push_properties() && parent_) | |
1421 parent_->AddDependentNeedsPushProperties(); | |
1422 needs_push_properties_ = true; | |
1423 } | |
1424 | |
1425 void LayerImpl::AddDependentNeedsPushProperties() { | |
1426 DCHECK_GE(num_dependents_need_push_properties_, 0); | |
1427 | |
1428 if (!parent_should_know_need_push_properties() && parent_) | |
1429 parent_->AddDependentNeedsPushProperties(); | |
1430 | |
1431 num_dependents_need_push_properties_++; | |
1432 } | |
1433 | |
1434 void LayerImpl::RemoveDependentNeedsPushProperties() { | |
1435 num_dependents_need_push_properties_--; | |
1436 DCHECK_GE(num_dependents_need_push_properties_, 0); | |
1437 | |
1438 if (!parent_should_know_need_push_properties() && parent_) | |
1439 parent_->RemoveDependentNeedsPushProperties(); | |
1440 } | |
1441 | |
1442 void LayerImpl::GetAllTilesAndPrioritiesForTracing( | |
1443 std::map<const Tile*, TilePriority>* tile_map) const { | |
1444 } | |
1445 | |
1446 void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { | |
1447 TracedValue::MakeDictIntoImplicitSnapshotWithCategory( | |
1448 TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
1449 state, | |
1450 "cc::LayerImpl", | |
1451 LayerTypeAsString(), | |
1452 this); | |
1453 state->SetInteger("layer_id", id()); | |
1454 MathUtil::AddToTracedValue("bounds", bounds_, state); | |
1455 | |
1456 state->SetDouble("opacity", opacity()); | |
1457 | |
1458 MathUtil::AddToTracedValue("position", position_, state); | |
1459 | |
1460 state->SetInteger("draws_content", DrawsContent()); | |
1461 state->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes()); | |
1462 | |
1463 MathUtil::AddToTracedValue( | |
1464 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive()) | |
1465 : gfx::ScrollOffset(), | |
1466 state); | |
1467 | |
1468 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state); | |
1469 | |
1470 bool clipped; | |
1471 gfx::QuadF layer_quad = MathUtil::MapQuad( | |
1472 screen_space_transform(), | |
1473 gfx::QuadF(gfx::Rect(content_bounds())), | |
1474 &clipped); | |
1475 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); | |
1476 if (!touch_event_handler_region_.IsEmpty()) { | |
1477 state->BeginArray("touch_event_handler_region"); | |
1478 touch_event_handler_region_.AsValueInto(state); | |
1479 state->EndArray(); | |
1480 } | |
1481 if (have_wheel_event_handlers_) { | |
1482 gfx::Rect wheel_rect(content_bounds()); | |
1483 Region wheel_region(wheel_rect); | |
1484 state->BeginArray("wheel_event_handler_region"); | |
1485 wheel_region.AsValueInto(state); | |
1486 state->EndArray(); | |
1487 } | |
1488 if (have_scroll_event_handlers_) { | |
1489 gfx::Rect scroll_rect(content_bounds()); | |
1490 Region scroll_region(scroll_rect); | |
1491 state->BeginArray("scroll_event_handler_region"); | |
1492 scroll_region.AsValueInto(state); | |
1493 state->EndArray(); | |
1494 } | |
1495 if (!non_fast_scrollable_region_.IsEmpty()) { | |
1496 state->BeginArray("non_fast_scrollable_region"); | |
1497 non_fast_scrollable_region_.AsValueInto(state); | |
1498 state->EndArray(); | |
1499 } | |
1500 if (scroll_blocks_on_) { | |
1501 state->SetInteger("scroll_blocks_on", scroll_blocks_on_); | |
1502 } | |
1503 | |
1504 state->BeginArray("children"); | |
1505 for (size_t i = 0; i < children_.size(); ++i) { | |
1506 state->BeginDictionary(); | |
1507 children_[i]->AsValueInto(state); | |
1508 state->EndDictionary(); | |
1509 } | |
1510 state->EndArray(); | |
1511 if (mask_layer_) { | |
1512 state->BeginDictionary("mask_layer"); | |
1513 mask_layer_->AsValueInto(state); | |
1514 state->EndDictionary(); | |
1515 } | |
1516 if (replica_layer_) { | |
1517 state->BeginDictionary("replica_layer"); | |
1518 replica_layer_->AsValueInto(state); | |
1519 state->EndDictionary(); | |
1520 } | |
1521 | |
1522 if (scroll_parent_) | |
1523 state->SetInteger("scroll_parent", scroll_parent_->id()); | |
1524 | |
1525 if (clip_parent_) | |
1526 state->SetInteger("clip_parent", clip_parent_->id()); | |
1527 | |
1528 state->SetBoolean("can_use_lcd_text", can_use_lcd_text()); | |
1529 state->SetBoolean("contents_opaque", contents_opaque()); | |
1530 | |
1531 state->SetBoolean( | |
1532 "has_animation_bounds", | |
1533 layer_animation_controller()->HasAnimationThatInflatesBounds()); | |
1534 | |
1535 gfx::BoxF box; | |
1536 if (LayerUtils::GetAnimationBounds(*this, &box)) | |
1537 MathUtil::AddToTracedValue("animation_bounds", box, state); | |
1538 | |
1539 if (debug_info_.get()) { | |
1540 std::string str; | |
1541 debug_info_->AppendAsTraceFormat(&str); | |
1542 base::JSONReader json_reader; | |
1543 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str)); | |
1544 | |
1545 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) { | |
1546 base::DictionaryValue* dictionary_value = nullptr; | |
1547 bool converted_to_dictionary = | |
1548 debug_info_value->GetAsDictionary(&dictionary_value); | |
1549 DCHECK(converted_to_dictionary); | |
1550 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd(); | |
1551 it.Advance()) { | |
1552 state->SetValue(it.key().data(), it.value().DeepCopy()); | |
1553 } | |
1554 } else { | |
1555 NOTREACHED(); | |
1556 } | |
1557 } | |
1558 | |
1559 if (!frame_timing_requests_.empty()) { | |
1560 state->BeginArray("frame_timing_requests"); | |
1561 for (const auto& request : frame_timing_requests_) { | |
1562 state->BeginDictionary(); | |
1563 state->SetInteger("request_id", request.id()); | |
1564 MathUtil::AddToTracedValue("request_rect", request.rect(), state); | |
1565 state->EndDictionary(); | |
1566 } | |
1567 state->EndArray(); | |
1568 } | |
1569 } | |
1570 | |
1571 bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const { | |
1572 return draw_properties_.last_drawn_render_surface_layer_list_id == | |
1573 layer_tree_impl_->current_render_surface_list_id(); | |
1574 } | |
1575 | |
1576 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } | |
1577 | |
1578 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | |
1579 benchmark->RunOnLayer(this); | |
1580 } | |
1581 | |
1582 int LayerImpl::NumDescendantsThatDrawContent() const { | |
1583 return num_descendants_that_draw_content_; | |
1584 } | |
1585 | |
1586 void LayerImpl::NotifyAnimationFinished( | |
1587 base::TimeTicks monotonic_time, | |
1588 Animation::TargetProperty target_property, | |
1589 int group) { | |
1590 if (target_property == Animation::SCROLL_OFFSET) | |
1591 layer_tree_impl_->InputScrollAnimationFinished(); | |
1592 } | |
1593 | |
1594 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { | |
1595 if (!!render_surface() == should_have_render_surface) | |
1596 return; | |
1597 | |
1598 SetNeedsPushProperties(); | |
1599 layer_tree_impl()->set_needs_update_draw_properties(); | |
1600 if (should_have_render_surface) { | |
1601 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); | |
1602 return; | |
1603 } | |
1604 render_surface_.reset(); | |
1605 } | |
1606 | |
1607 Region LayerImpl::GetInvalidationRegion() { | |
1608 return Region(update_rect_); | |
1609 } | |
1610 | |
1611 gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const { | |
1612 return MathUtil::MapEnclosingClippedRect( | |
1613 draw_properties_.target_space_transform, | |
1614 gfx::Rect(draw_properties_.content_bounds)); | |
1615 } | |
1616 | |
1617 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { | |
1618 gfx::Transform scaled_draw_transform = | |
1619 draw_properties_.target_space_transform; | |
1620 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); | |
1621 gfx::Size scaled_content_bounds = | |
1622 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), scale)); | |
1623 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, | |
1624 gfx::Rect(scaled_content_bounds)); | |
1625 } | |
1626 | |
1627 } // namespace cc | |
OLD | NEW |