| 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/render_surface_impl.h" | 5 #include "cc/render_surface_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 target_render_surface_layer_index_history_(0), | 37 target_render_surface_layer_index_history_(0), |
| 38 current_layer_index_history_(0) { | 38 current_layer_index_history_(0) { |
| 39 damage_tracker_ = DamageTracker::Create(); | 39 damage_tracker_ = DamageTracker::Create(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 RenderSurfaceImpl::~RenderSurfaceImpl() {} | 42 RenderSurfaceImpl::~RenderSurfaceImpl() {} |
| 43 | 43 |
| 44 gfx::RectF RenderSurfaceImpl::DrawableContentRect() const { | 44 gfx::RectF RenderSurfaceImpl::DrawableContentRect() const { |
| 45 gfx::RectF drawable_content_rect = | 45 gfx::RectF drawable_content_rect = |
| 46 MathUtil::mapClippedRect(draw_transform_, content_rect_); | 46 MathUtil::mapClippedRect(draw_transform_, content_rect_); |
| 47 if (owning_layer_->hasReplica()) { | 47 if (owning_layer_->has_replica()) { |
| 48 drawable_content_rect.Union( | 48 drawable_content_rect.Union( |
| 49 MathUtil::mapClippedRect(replica_draw_transform_, content_rect_)); | 49 MathUtil::mapClippedRect(replica_draw_transform_, content_rect_)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 return drawable_content_rect; | 52 return drawable_content_rect; |
| 53 } | 53 } |
| 54 | 54 |
| 55 std::string RenderSurfaceImpl::Name() const { | 55 std::string RenderSurfaceImpl::Name() const { |
| 56 return base::StringPrintf("RenderSurfaceImpl(id=%i,owner=%s)", | 56 return base::StringPrintf("RenderSurfaceImpl(id=%i,owner=%s)", |
| 57 owning_layer_->id(), | 57 owning_layer_->id(), |
| 58 owning_layer_->debugName().data()); | 58 owning_layer_->debug_name().data()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 static std::string IndentString(int indent) { | 61 static std::string IndentString(int indent) { |
| 62 std::string str; | 62 std::string str; |
| 63 for (int i = 0; i != indent; ++i) | 63 for (int i = 0; i != indent; ++i) |
| 64 str.append(" "); | 64 str.append(" "); |
| 65 return str; | 65 return str; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void RenderSurfaceImpl::DumpSurface(std::string* str, int indent) const { | 68 void RenderSurfaceImpl::DumpSurface(std::string* str, int indent) const { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // Surface property changes are tracked as follows: | 141 // Surface property changes are tracked as follows: |
| 142 // | 142 // |
| 143 // - surface_property_changed_ is flagged when the clip_rect or content_rect | 143 // - surface_property_changed_ is flagged when the clip_rect or content_rect |
| 144 // change. As of now, these are the only two properties that can be affected | 144 // change. As of now, these are the only two properties that can be affected |
| 145 // by descendant layers. | 145 // by descendant layers. |
| 146 // | 146 // |
| 147 // - all other property changes come from the owning layer (or some ancestor | 147 // - all other property changes come from the owning layer (or some ancestor |
| 148 // layer that propagates its change to the owning layer). | 148 // layer that propagates its change to the owning layer). |
| 149 // | 149 // |
| 150 DCHECK(owning_layer_); | 150 DCHECK(owning_layer_); |
| 151 return surface_property_changed_ || owning_layer_->layerPropertyChanged(); | 151 return surface_property_changed_ || owning_layer_->LayerPropertyChanged(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const { | 154 bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const { |
| 155 return surface_property_changed_ && !owning_layer_->layerPropertyChanged(); | 155 return surface_property_changed_ && !owning_layer_->LayerPropertyChanged(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void RenderSurfaceImpl::AddContributingDelegatedRenderPassLayer( | 158 void RenderSurfaceImpl::AddContributingDelegatedRenderPassLayer( |
| 159 LayerImpl* layer) { | 159 LayerImpl* layer) { |
| 160 DCHECK(std::find(layer_list_.begin(), layer_list_.end(), layer) != | 160 DCHECK(std::find(layer_list_.begin(), layer_list_.end(), layer) != |
| 161 layer_list_.end()); | 161 layer_list_.end()); |
| 162 DelegatedRendererLayerImpl* delegated_renderer_layer = | 162 DelegatedRendererLayerImpl* delegated_renderer_layer = |
| 163 static_cast<DelegatedRendererLayerImpl*>(layer); | 163 static_cast<DelegatedRendererLayerImpl*>(layer); |
| 164 contributing_delegated_render_pass_layer_list_.push_back( | 164 contributing_delegated_render_pass_layer_list_.push_back( |
| 165 delegated_renderer_layer); | 165 delegated_renderer_layer); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 191 content_rect_, | 191 content_rect_, |
| 192 damage_tracker_->current_damage_rect(), | 192 damage_tracker_->current_damage_rect(), |
| 193 screen_space_transform_); | 193 screen_space_transform_); |
| 194 pass_sink->appendRenderPass(pass.Pass()); | 194 pass_sink->appendRenderPass(pass.Pass()); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void RenderSurfaceImpl::AppendQuads(QuadSink* quad_sink, | 197 void RenderSurfaceImpl::AppendQuads(QuadSink* quad_sink, |
| 198 AppendQuadsData* append_quads_data, | 198 AppendQuadsData* append_quads_data, |
| 199 bool for_replica, | 199 bool for_replica, |
| 200 RenderPass::Id render_pass_id) { | 200 RenderPass::Id render_pass_id) { |
| 201 DCHECK(!for_replica || owning_layer_->hasReplica()); | 201 DCHECK(!for_replica || owning_layer_->has_replica()); |
| 202 | 202 |
| 203 const gfx::Transform& draw_transform = | 203 const gfx::Transform& draw_transform = |
| 204 for_replica ? replica_draw_transform_ : draw_transform_; | 204 for_replica ? replica_draw_transform_ : draw_transform_; |
| 205 SharedQuadState* shared_quad_state = | 205 SharedQuadState* shared_quad_state = |
| 206 quad_sink->useSharedQuadState(SharedQuadState::Create()); | 206 quad_sink->useSharedQuadState(SharedQuadState::Create()); |
| 207 shared_quad_state->SetAll(draw_transform, | 207 shared_quad_state->SetAll(draw_transform, |
| 208 content_rect_.size(), | 208 content_rect_.size(), |
| 209 content_rect_, | 209 content_rect_, |
| 210 clip_rect_, | 210 clip_rect_, |
| 211 is_clipped_, | 211 is_clipped_, |
| 212 draw_opacity_); | 212 draw_opacity_); |
| 213 | 213 |
| 214 if (owning_layer_->showDebugBorders()) { | 214 if (owning_layer_->ShowDebugBorders()) { |
| 215 SkColor color = for_replica ? | 215 SkColor color = for_replica ? |
| 216 DebugColors::SurfaceReplicaBorderColor() : | 216 DebugColors::SurfaceReplicaBorderColor() : |
| 217 DebugColors::SurfaceBorderColor(); | 217 DebugColors::SurfaceBorderColor(); |
| 218 float width = for_replica ? | 218 float width = for_replica ? |
| 219 DebugColors::SurfaceReplicaBorderWidth( | 219 DebugColors::SurfaceReplicaBorderWidth( |
| 220 owning_layer_->layerTreeImpl()) : | 220 owning_layer_->layer_tree_impl()) : |
| 221 DebugColors::SurfaceBorderWidth( | 221 DebugColors::SurfaceBorderWidth( |
| 222 owning_layer_->layerTreeImpl()); | 222 owning_layer_->layer_tree_impl()); |
| 223 scoped_ptr<DebugBorderDrawQuad> debug_border_quad = | 223 scoped_ptr<DebugBorderDrawQuad> debug_border_quad = |
| 224 DebugBorderDrawQuad::Create(); | 224 DebugBorderDrawQuad::Create(); |
| 225 debug_border_quad->SetNew(shared_quad_state, content_rect_, color, width); | 225 debug_border_quad->SetNew(shared_quad_state, content_rect_, color, width); |
| 226 quad_sink->append(debug_border_quad.PassAs<DrawQuad>(), *append_quads_data); | 226 quad_sink->append(debug_border_quad.PassAs<DrawQuad>(), append_quads_data); |
| 227 } | 227 } |
| 228 | 228 |
| 229 // FIXME: By using the same RenderSurfaceImpl for both the content and its | 229 // FIXME: By using the same RenderSurfaceImpl for both the content and its |
| 230 // reflection, it's currently not possible to apply a separate mask to the | 230 // reflection, it's currently not possible to apply a separate mask to the |
| 231 // reflection layer or correctly handle opacity in reflections (opacity must | 231 // reflection layer or correctly handle opacity in reflections (opacity must |
| 232 // be applied after drawing both the layer and its reflection). The solution | 232 // be applied after drawing both the layer and its reflection). The solution |
| 233 // is to introduce yet another RenderSurfaceImpl to draw the layer and its | 233 // is to introduce yet another RenderSurfaceImpl to draw the layer and its |
| 234 // reflection in. For now we only apply a separate reflection mask if the | 234 // reflection in. For now we only apply a separate reflection mask if the |
| 235 // contents don't have a mask of their own. | 235 // contents don't have a mask of their own. |
| 236 LayerImpl* mask_layer = owning_layer_->maskLayer(); | 236 LayerImpl* mask_layer = owning_layer_->mask_layer(); |
| 237 if (mask_layer && | 237 if (mask_layer && |
| 238 (!mask_layer->drawsContent() || mask_layer->bounds().IsEmpty())) | 238 (!mask_layer->DrawsContent() || mask_layer->bounds().IsEmpty())) |
| 239 mask_layer = NULL; | 239 mask_layer = NULL; |
| 240 | 240 |
| 241 if (!mask_layer && for_replica) { | 241 if (!mask_layer && for_replica) { |
| 242 mask_layer = owning_layer_->replicaLayer()->maskLayer(); | 242 mask_layer = owning_layer_->replica_layer()->mask_layer(); |
| 243 if (mask_layer && | 243 if (mask_layer && |
| 244 (!mask_layer->drawsContent() || mask_layer->bounds().IsEmpty())) | 244 (!mask_layer->DrawsContent() || mask_layer->bounds().IsEmpty())) |
| 245 mask_layer = NULL; | 245 mask_layer = NULL; |
| 246 } | 246 } |
| 247 | 247 |
| 248 gfx::RectF mask_uv_rect(0.f, 0.f, 1.f, 1.f); | 248 gfx::RectF mask_uv_rect(0.f, 0.f, 1.f, 1.f); |
| 249 if (mask_layer) { | 249 if (mask_layer) { |
| 250 gfx::Vector2dF owning_layer_draw_scale = | 250 gfx::Vector2dF owning_layer_draw_scale = |
| 251 MathUtil::computeTransform2dScaleComponents( | 251 MathUtil::computeTransform2dScaleComponents( |
| 252 owning_layer_->drawTransform(), 1.f); | 252 owning_layer_->draw_transform(), 1.f); |
| 253 gfx::SizeF unclipped_surface_size = gfx::ScaleSize( | 253 gfx::SizeF unclipped_surface_size = gfx::ScaleSize( |
| 254 owning_layer_->contentBounds(), | 254 owning_layer_->content_bounds(), |
| 255 owning_layer_draw_scale.x(), | 255 owning_layer_draw_scale.x(), |
| 256 owning_layer_draw_scale.y()); | 256 owning_layer_draw_scale.y()); |
| 257 // This assumes that the owning layer clips its subtree when a mask is | 257 // This assumes that the owning layer clips its subtree when a mask is |
| 258 // present. | 258 // present. |
| 259 DCHECK(gfx::RectF(unclipped_surface_size).Contains(content_rect_)); | 259 DCHECK(gfx::RectF(unclipped_surface_size).Contains(content_rect_)); |
| 260 | 260 |
| 261 float uv_scale_x = content_rect_.width() / unclipped_surface_size.width(); | 261 float uv_scale_x = content_rect_.width() / unclipped_surface_size.width(); |
| 262 float uv_scale_y = content_rect_.height() / unclipped_surface_size.height(); | 262 float uv_scale_y = content_rect_.height() / unclipped_surface_size.height(); |
| 263 | 263 |
| 264 mask_uv_rect = gfx::RectF( | 264 mask_uv_rect = gfx::RectF( |
| 265 uv_scale_x * content_rect_.x() / content_rect_.width(), | 265 uv_scale_x * content_rect_.x() / content_rect_.width(), |
| 266 uv_scale_y * content_rect_.y() / content_rect_.height(), | 266 uv_scale_y * content_rect_.y() / content_rect_.height(), |
| 267 uv_scale_x, | 267 uv_scale_x, |
| 268 uv_scale_y); | 268 uv_scale_y); |
| 269 } | 269 } |
| 270 | 270 |
| 271 ResourceProvider::ResourceId mask_resource_id = | 271 ResourceProvider::ResourceId mask_resource_id = |
| 272 mask_layer ? mask_layer->contentsResourceId() : 0; | 272 mask_layer ? mask_layer->ContentsResourceId() : 0; |
| 273 gfx::Rect contents_changed_since_last_frame = | 273 gfx::Rect contents_changed_since_last_frame = |
| 274 ContentsChanged() ? content_rect_ : gfx::Rect(); | 274 ContentsChanged() ? content_rect_ : gfx::Rect(); |
| 275 | 275 |
| 276 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create(); | 276 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create(); |
| 277 quad->SetNew(shared_quad_state, | 277 quad->SetNew(shared_quad_state, |
| 278 content_rect_, | 278 content_rect_, |
| 279 render_pass_id, | 279 render_pass_id, |
| 280 for_replica, | 280 for_replica, |
| 281 mask_resource_id, | 281 mask_resource_id, |
| 282 contents_changed_since_last_frame, | 282 contents_changed_since_last_frame, |
| 283 mask_uv_rect, | 283 mask_uv_rect, |
| 284 owning_layer_->filters(), | 284 owning_layer_->filters(), |
| 285 owning_layer_->filter(), | 285 owning_layer_->filter(), |
| 286 owning_layer_->backgroundFilters()); | 286 owning_layer_->background_filters()); |
| 287 quad_sink->append(quad.PassAs<DrawQuad>(), *append_quads_data); | 287 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 288 } | 288 } |
| 289 | 289 |
| 290 } // namespace cc | 290 } // namespace cc |
| OLD | NEW |