| OLD | NEW |
| 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/layers/render_surface_impl.h" | 5 #include "cc/layers/render_surface_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "cc/trees/layer_tree_impl.h" | 25 #include "cc/trees/layer_tree_impl.h" |
| 26 #include "cc/trees/occlusion.h" | 26 #include "cc/trees/occlusion.h" |
| 27 #include "cc/trees/transform_node.h" | 27 #include "cc/trees/transform_node.h" |
| 28 #include "third_party/skia/include/core/SkImageFilter.h" | 28 #include "third_party/skia/include/core/SkImageFilter.h" |
| 29 #include "ui/gfx/geometry/rect_conversions.h" | 29 #include "ui/gfx/geometry/rect_conversions.h" |
| 30 #include "ui/gfx/transform.h" | 30 #include "ui/gfx/transform.h" |
| 31 | 31 |
| 32 namespace cc { | 32 namespace cc { |
| 33 | 33 |
| 34 RenderSurfaceImpl::RenderSurfaceImpl(LayerImpl* owning_layer) | 34 RenderSurfaceImpl::RenderSurfaceImpl(LayerImpl* owning_layer) |
| 35 : owning_layer_(owning_layer), | 35 : layer_tree_impl_(owning_layer->layer_tree_impl()), |
| 36 layer_tree_impl_(owning_layer->layer_tree_impl()), | |
| 37 stable_effect_id_(owning_layer->id()), | 36 stable_effect_id_(owning_layer->id()), |
| 38 effect_tree_index_(EffectTree::kInvalidNodeId), | 37 effect_tree_index_(EffectTree::kInvalidNodeId), |
| 39 surface_property_changed_(false), | 38 surface_property_changed_(false), |
| 40 ancestor_property_changed_(false), | 39 ancestor_property_changed_(false), |
| 41 contributes_to_drawn_surface_(false), | 40 contributes_to_drawn_surface_(false), |
| 42 nearest_occlusion_immune_ancestor_(nullptr), | 41 nearest_occlusion_immune_ancestor_(nullptr), |
| 43 target_render_surface_layer_index_history_(0), | 42 target_render_surface_layer_index_history_(0), |
| 44 current_layer_index_history_(0) { | 43 current_layer_index_history_(0) { |
| 45 damage_tracker_ = DamageTracker::Create(); | 44 damage_tracker_ = DamageTracker::Create(); |
| 46 } | 45 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 75 | 74 |
| 76 RenderSurfaceImpl::DrawProperties::~DrawProperties() {} | 75 RenderSurfaceImpl::DrawProperties::~DrawProperties() {} |
| 77 | 76 |
| 78 gfx::RectF RenderSurfaceImpl::DrawableContentRect() const { | 77 gfx::RectF RenderSurfaceImpl::DrawableContentRect() const { |
| 79 if (content_rect().IsEmpty()) | 78 if (content_rect().IsEmpty()) |
| 80 return gfx::RectF(); | 79 return gfx::RectF(); |
| 81 | 80 |
| 82 gfx::Rect surface_content_rect = content_rect(); | 81 gfx::Rect surface_content_rect = content_rect(); |
| 83 const FilterOperations& filters = Filters(); | 82 const FilterOperations& filters = Filters(); |
| 84 if (!filters.IsEmpty()) { | 83 if (!filters.IsEmpty()) { |
| 85 const gfx::Transform& owning_layer_draw_transform = | 84 surface_content_rect = |
| 86 owning_layer_->DrawTransform(); | 85 filters.MapRect(surface_content_rect, FiltersTransform().matrix()); |
| 87 DCHECK(owning_layer_draw_transform.IsScale2d()); | |
| 88 surface_content_rect = filters.MapRect( | |
| 89 surface_content_rect, owning_layer_draw_transform.matrix()); | |
| 90 } | 86 } |
| 91 gfx::RectF drawable_content_rect = MathUtil::MapClippedRect( | 87 gfx::RectF drawable_content_rect = MathUtil::MapClippedRect( |
| 92 draw_transform(), gfx::RectF(surface_content_rect)); | 88 draw_transform(), gfx::RectF(surface_content_rect)); |
| 93 if (!filters.IsEmpty() && is_clipped()) { | 89 if (!filters.IsEmpty() && is_clipped()) { |
| 94 // Filter could move pixels around, but still need to be clipped. | 90 // Filter could move pixels around, but still need to be clipped. |
| 95 drawable_content_rect.Intersect(gfx::RectF(clip_rect())); | 91 drawable_content_rect.Intersect(gfx::RectF(clip_rect())); |
| 96 } | 92 } |
| 97 | 93 |
| 98 // If the rect has a NaN coordinate, we return empty rect to avoid crashes in | 94 // If the rect has a NaN coordinate, we return empty rect to avoid crashes in |
| 99 // functions (for example, gfx::ToEnclosedRect) that are called on this rect. | 95 // functions (for example, gfx::ToEnclosedRect) that are called on this rect. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 129 |
| 134 const FilterOperations& RenderSurfaceImpl::Filters() const { | 130 const FilterOperations& RenderSurfaceImpl::Filters() const { |
| 135 return OwningEffectNode()->filters; | 131 return OwningEffectNode()->filters; |
| 136 } | 132 } |
| 137 | 133 |
| 138 gfx::PointF RenderSurfaceImpl::FiltersOrigin() const { | 134 gfx::PointF RenderSurfaceImpl::FiltersOrigin() const { |
| 139 return OwningEffectNode()->filters_origin; | 135 return OwningEffectNode()->filters_origin; |
| 140 } | 136 } |
| 141 | 137 |
| 142 gfx::Transform RenderSurfaceImpl::FiltersTransform() const { | 138 gfx::Transform RenderSurfaceImpl::FiltersTransform() const { |
| 143 return owning_layer_->DrawTransform(); | 139 gfx::Transform filters_transform; |
| 140 filters_transform.Scale(OwningEffectNode()->surface_contents_scale.x(), |
| 141 OwningEffectNode()->surface_contents_scale.y()); |
| 142 return filters_transform; |
| 144 } | 143 } |
| 145 | 144 |
| 146 const FilterOperations& RenderSurfaceImpl::BackgroundFilters() const { | 145 const FilterOperations& RenderSurfaceImpl::BackgroundFilters() const { |
| 147 return OwningEffectNode()->background_filters; | 146 return OwningEffectNode()->background_filters; |
| 148 } | 147 } |
| 149 | 148 |
| 150 bool RenderSurfaceImpl::HasCopyRequest() const { | 149 bool RenderSurfaceImpl::HasCopyRequest() const { |
| 151 return OwningEffectNode()->has_copy_request; | 150 return OwningEffectNode()->has_copy_request; |
| 152 } | 151 } |
| 153 | 152 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 bool RenderSurfaceImpl::SurfacePropertyChanged() const { | 311 bool RenderSurfaceImpl::SurfacePropertyChanged() const { |
| 313 // Surface property changes are tracked as follows: | 312 // Surface property changes are tracked as follows: |
| 314 // | 313 // |
| 315 // - surface_property_changed_ is flagged when the clip_rect or content_rect | 314 // - surface_property_changed_ is flagged when the clip_rect or content_rect |
| 316 // change. As of now, these are the only two properties that can be affected | 315 // change. As of now, these are the only two properties that can be affected |
| 317 // by descendant layers. | 316 // by descendant layers. |
| 318 // | 317 // |
| 319 // - all other property changes come from the surface's property tree nodes | 318 // - all other property changes come from the surface's property tree nodes |
| 320 // (or some ancestor node that propagates its change to one of these nodes). | 319 // (or some ancestor node that propagates its change to one of these nodes). |
| 321 // | 320 // |
| 322 DCHECK(owning_layer_); | |
| 323 return surface_property_changed_ || AncestorPropertyChanged(); | 321 return surface_property_changed_ || AncestorPropertyChanged(); |
| 324 } | 322 } |
| 325 | 323 |
| 326 bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const { | 324 bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const { |
| 327 return surface_property_changed_ && !AncestorPropertyChanged(); | 325 return surface_property_changed_ && !AncestorPropertyChanged(); |
| 328 } | 326 } |
| 329 | 327 |
| 330 bool RenderSurfaceImpl::AncestorPropertyChanged() const { | 328 bool RenderSurfaceImpl::AncestorPropertyChanged() const { |
| 331 const PropertyTrees* property_trees = layer_tree_impl_->property_trees(); | 329 const PropertyTrees* property_trees = layer_tree_impl_->property_trees(); |
| 332 return ancestor_property_changed_ || property_trees->full_tree_damaged || | 330 return ancestor_property_changed_ || property_trees->full_tree_damaged || |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 DebugBorderDrawQuad* debug_border_quad = | 383 DebugBorderDrawQuad* debug_border_quad = |
| 386 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>(); | 384 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>(); |
| 387 debug_border_quad->SetNew(shared_quad_state, content_rect(), | 385 debug_border_quad->SetNew(shared_quad_state, content_rect(), |
| 388 visible_layer_rect, GetDebugBorderColor(), | 386 visible_layer_rect, GetDebugBorderColor(), |
| 389 GetDebugBorderWidth()); | 387 GetDebugBorderWidth()); |
| 390 } | 388 } |
| 391 | 389 |
| 392 ResourceId mask_resource_id = 0; | 390 ResourceId mask_resource_id = 0; |
| 393 gfx::Size mask_texture_size; | 391 gfx::Size mask_texture_size; |
| 394 gfx::Vector2dF mask_uv_scale; | 392 gfx::Vector2dF mask_uv_scale; |
| 395 gfx::Transform owning_layer_draw_transform = owning_layer_->DrawTransform(); | 393 gfx::Vector2dF surface_contents_scale = |
| 394 OwningEffectNode()->surface_contents_scale; |
| 396 LayerImpl* mask_layer = MaskLayer(); | 395 LayerImpl* mask_layer = MaskLayer(); |
| 397 if (mask_layer && mask_layer->DrawsContent() && | 396 if (mask_layer && mask_layer->DrawsContent() && |
| 398 !mask_layer->bounds().IsEmpty()) { | 397 !mask_layer->bounds().IsEmpty()) { |
| 399 mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size); | 398 mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size); |
| 400 gfx::Vector2dF owning_layer_draw_scale = | |
| 401 MathUtil::ComputeTransform2dScaleComponents(owning_layer_draw_transform, | |
| 402 1.f); | |
| 403 gfx::SizeF unclipped_mask_target_size = gfx::ScaleSize( | 399 gfx::SizeF unclipped_mask_target_size = gfx::ScaleSize( |
| 404 gfx::SizeF(OwningEffectNode()->unscaled_mask_target_size), | 400 gfx::SizeF(OwningEffectNode()->unscaled_mask_target_size), |
| 405 owning_layer_draw_scale.x(), owning_layer_draw_scale.y()); | 401 surface_contents_scale.x(), surface_contents_scale.y()); |
| 406 mask_uv_scale = gfx::Vector2dF(1.0f / unclipped_mask_target_size.width(), | 402 mask_uv_scale = gfx::Vector2dF(1.0f / unclipped_mask_target_size.width(), |
| 407 1.0f / unclipped_mask_target_size.height()); | 403 1.0f / unclipped_mask_target_size.height()); |
| 408 } | 404 } |
| 409 | 405 |
| 410 DCHECK(owning_layer_draw_transform.IsScale2d()); | |
| 411 gfx::Vector2dF owning_layer_to_target_scale = | |
| 412 owning_layer_draw_transform.Scale2d(); | |
| 413 | |
| 414 RenderPassDrawQuad* quad = | 406 RenderPassDrawQuad* quad = |
| 415 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); | 407 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 416 quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect, | 408 quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect, |
| 417 GetRenderPassId(), mask_resource_id, mask_uv_scale, | 409 GetRenderPassId(), mask_resource_id, mask_uv_scale, |
| 418 mask_texture_size, owning_layer_to_target_scale, | 410 mask_texture_size, surface_contents_scale, FiltersOrigin()); |
| 419 FiltersOrigin()); | |
| 420 } | 411 } |
| 421 | 412 |
| 422 } // namespace cc | 413 } // namespace cc |
| OLD | NEW |