blob: b9530ad2598379f22e4716be0f77cd6272dcbf48 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2011 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
[email protected]cc3cfaa2013-03-18 09:05:525#include "cc/layers/render_surface_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]ac7c7f52012-11-08 06:26:507#include <algorithm>
8
[email protected]4456eee22012-10-19 18:16:389#include "base/logging.h"
[email protected]8e61d4b2013-06-10 22:11:4810#include "base/strings/stringprintf.h"
[email protected]681ccff2013-03-18 06:13:5211#include "cc/base/math_util.h"
[email protected]6e84de22013-03-18 06:54:2712#include "cc/debug/debug_colors.h"
[email protected]cc3cfaa2013-03-18 09:05:5213#include "cc/layers/delegated_renderer_layer_impl.h"
14#include "cc/layers/layer_impl.h"
[email protected]cc3cfaa2013-03-18 09:05:5215#include "cc/layers/render_pass_sink.h"
[email protected]89e8267a2013-03-18 07:50:5616#include "cc/quads/debug_border_draw_quad.h"
17#include "cc/quads/render_pass.h"
18#include "cc/quads/render_pass_draw_quad.h"
19#include "cc/quads/shared_quad_state.h"
[email protected]556fd292013-03-18 08:03:0420#include "cc/trees/damage_tracker.h"
danakja1b92e42015-02-11 21:07:4721#include "cc/trees/occlusion.h"
[email protected]55761e62012-11-21 18:55:5822#include "third_party/skia/include/core/SkImageFilter.h"
heejin.r.chungd28506ba2014-10-23 16:36:2023#include "ui/gfx/geometry/rect_conversions.h"
[email protected]c8686a02012-11-27 08:29:0024#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1425
[email protected]9c88e562012-09-14 22:21:3026namespace cc {
[email protected]94f206c12012-08-25 00:09:1427
[email protected]d2d915aa2013-03-08 20:18:1228RenderSurfaceImpl::RenderSurfaceImpl(LayerImpl* owning_layer)
29 : owning_layer_(owning_layer),
30 surface_property_changed_(false),
[email protected]d2d915aa2013-03-08 20:18:1231 is_clipped_(false),
[email protected]30fe19ff2013-07-04 00:54:4532 contributes_to_drawn_surface_(false),
[email protected]c55f3fc2013-12-10 05:48:4833 draw_opacity_(1),
kulkarni.a4015690f12014-10-10 13:50:0634 nearest_occlusion_immune_ancestor_(nullptr),
[email protected]d2d915aa2013-03-08 20:18:1235 target_render_surface_layer_index_history_(0),
36 current_layer_index_history_(0) {
37 damage_tracker_ = DamageTracker::Create();
[email protected]94f206c12012-08-25 00:09:1438}
39
[email protected]d2d915aa2013-03-08 20:18:1240RenderSurfaceImpl::~RenderSurfaceImpl() {}
41
42gfx::RectF RenderSurfaceImpl::DrawableContentRect() const {
43 gfx::RectF drawable_content_rect =
[email protected]fa816c62013-03-18 04:24:2144 MathUtil::MapClippedRect(draw_transform_, content_rect_);
[email protected]7aba6662013-03-12 10:17:3445 if (owning_layer_->has_replica()) {
[email protected]d2d915aa2013-03-08 20:18:1246 drawable_content_rect.Union(
[email protected]fa816c62013-03-18 04:24:2147 MathUtil::MapClippedRect(replica_draw_transform_, content_rect_));
[email protected]d2d915aa2013-03-08 20:18:1248 }
49
50 return drawable_content_rect;
[email protected]94f206c12012-08-25 00:09:1451}
52
danakja1b92e42015-02-11 21:07:4753SkColor RenderSurfaceImpl::GetDebugBorderColor() const {
54 return DebugColors::SurfaceBorderColor();
55}
56
57SkColor RenderSurfaceImpl::GetReplicaDebugBorderColor() const {
58 return DebugColors::SurfaceReplicaBorderColor();
59}
60
61float RenderSurfaceImpl::GetDebugBorderWidth() const {
62 return DebugColors::SurfaceBorderWidth(owning_layer_->layer_tree_impl());
63}
64
65float RenderSurfaceImpl::GetReplicaDebugBorderWidth() const {
66 return DebugColors::SurfaceReplicaBorderWidth(
67 owning_layer_->layer_tree_impl());
68}
69
[email protected]d2d915aa2013-03-08 20:18:1270int RenderSurfaceImpl::OwningLayerId() const {
71 return owning_layer_ ? owning_layer_->id() : 0;
[email protected]94f206c12012-08-25 00:09:1472}
73
jaydasika7ba8f922015-08-21 05:39:4274bool RenderSurfaceImpl::HasReplica() const {
75 return owning_layer_->has_replica();
76}
77
78gfx::Transform RenderSurfaceImpl::ReplicaDrawTransform() const {
79 return replica_draw_transform_;
80}
81
jaydasika504a0502015-07-23 19:25:4482int RenderSurfaceImpl::TransformTreeIndex() const {
83 return owning_layer_->transform_tree_index();
84}
[email protected]94f206c12012-08-25 00:09:1485
jaydasikaebf9e4ea2015-08-14 21:29:1286int RenderSurfaceImpl::ClipTreeIndex() const {
87 return owning_layer_->clip_tree_index();
88}
89
jaydasika0f4b1a92015-08-18 23:19:0290int RenderSurfaceImpl::EffectTreeIndex() const {
91 return owning_layer_->effect_tree_index();
92}
93
94int RenderSurfaceImpl::TargetEffectTreeIndex() const {
95 if (!owning_layer_->parent() || !owning_layer_->parent()->render_target())
96 return -1;
97 return owning_layer_->parent()->render_target()->effect_tree_index();
98}
99
[email protected]0023fc72014-01-10 20:05:06100void RenderSurfaceImpl::SetClipRect(const gfx::Rect& clip_rect) {
[email protected]d2d915aa2013-03-08 20:18:12101 if (clip_rect_ == clip_rect)
102 return;
[email protected]94f206c12012-08-25 00:09:14103
[email protected]d2d915aa2013-03-08 20:18:12104 surface_property_changed_ = true;
105 clip_rect_ = clip_rect;
[email protected]94f206c12012-08-25 00:09:14106}
107
[email protected]0023fc72014-01-10 20:05:06108void RenderSurfaceImpl::SetContentRect(const gfx::Rect& content_rect) {
[email protected]d2d915aa2013-03-08 20:18:12109 if (content_rect_ == content_rect)
110 return;
[email protected]94f206c12012-08-25 00:09:14111
[email protected]d2d915aa2013-03-08 20:18:12112 surface_property_changed_ = true;
113 content_rect_ = content_rect;
[email protected]94f206c12012-08-25 00:09:14114}
115
jaydasika7ba8f922015-08-21 05:39:42116void RenderSurfaceImpl::SetContentRectFromPropertyTrees(
117 const gfx::Rect& content_rect) {
118 if (content_rect_from_property_trees_ == content_rect)
119 return;
120
121 surface_property_changed_ = true;
122 content_rect_from_property_trees_ = content_rect;
123}
124
125void RenderSurfaceImpl::SetAccumulatedContentRect(
126 const gfx::Rect& content_rect) {
127 accumulated_content_rect_ = content_rect;
128}
129
[email protected]d2d915aa2013-03-08 20:18:12130bool RenderSurfaceImpl::SurfacePropertyChanged() const {
131 // Surface property changes are tracked as follows:
132 //
133 // - surface_property_changed_ is flagged when the clip_rect or content_rect
134 // change. As of now, these are the only two properties that can be affected
135 // by descendant layers.
136 //
137 // - all other property changes come from the owning layer (or some ancestor
138 // layer that propagates its change to the owning layer).
139 //
140 DCHECK(owning_layer_);
[email protected]7aba6662013-03-12 10:17:34141 return surface_property_changed_ || owning_layer_->LayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14142}
143
[email protected]d2d915aa2013-03-08 20:18:12144bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const {
[email protected]7aba6662013-03-12 10:17:34145 return surface_property_changed_ && !owning_layer_->LayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14146}
147
[email protected]d2d915aa2013-03-08 20:18:12148void RenderSurfaceImpl::AddContributingDelegatedRenderPassLayer(
149 LayerImpl* layer) {
150 DCHECK(std::find(layer_list_.begin(), layer_list_.end(), layer) !=
151 layer_list_.end());
152 DelegatedRendererLayerImpl* delegated_renderer_layer =
153 static_cast<DelegatedRendererLayerImpl*>(layer);
154 contributing_delegated_render_pass_layer_list_.push_back(
155 delegated_renderer_layer);
[email protected]7d929c02012-09-20 17:26:57156}
157
[email protected]d2d915aa2013-03-08 20:18:12158void RenderSurfaceImpl::ClearLayerLists() {
159 layer_list_.clear();
160 contributing_delegated_render_pass_layer_list_.clear();
[email protected]7d929c02012-09-20 17:26:57161}
162
[email protected]0cd7d6f72014-08-22 14:50:51163RenderPassId RenderSurfaceImpl::GetRenderPassId() {
[email protected]d2d915aa2013-03-08 20:18:12164 int layer_id = owning_layer_->id();
165 int sub_id = 0;
166 DCHECK_GT(layer_id, 0);
[email protected]0cd7d6f72014-08-22 14:50:51167 return RenderPassId(layer_id, sub_id);
[email protected]0f077a52012-09-08 01:45:24168}
169
[email protected]d2d915aa2013-03-08 20:18:12170void RenderSurfaceImpl::AppendRenderPasses(RenderPassSink* pass_sink) {
171 for (size_t i = 0;
172 i < contributing_delegated_render_pass_layer_list_.size();
173 ++i) {
174 DelegatedRendererLayerImpl* delegated_renderer_layer =
175 contributing_delegated_render_pass_layer_list_[i];
176 delegated_renderer_layer->AppendContributingRenderPasses(pass_sink);
177 }
[email protected]7d929c02012-09-20 17:26:57178
[email protected]b27511f2013-11-28 05:39:04179 scoped_ptr<RenderPass> pass = RenderPass::Create(layer_list_.size());
[email protected]0cd7d6f72014-08-22 14:50:51180 pass->SetNew(GetRenderPassId(),
[email protected]d2d915aa2013-03-08 20:18:12181 content_rect_,
[email protected]b4ead7b2014-04-07 18:12:18182 gfx::IntersectRects(content_rect_,
183 damage_tracker_->current_damage_rect()),
[email protected]d2d915aa2013-03-08 20:18:12184 screen_space_transform_);
[email protected]c1bb5af2013-03-13 19:06:27185 pass_sink->AppendRenderPass(pass.Pass());
[email protected]467b3612012-08-28 07:41:16186}
187
danakja1b92e42015-02-11 21:07:47188void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass,
189 const gfx::Transform& draw_transform,
190 const Occlusion& occlusion_in_content_space,
191 SkColor debug_border_color,
192 float debug_border_width,
193 LayerImpl* mask_layer,
194 AppendQuadsData* append_quads_data,
195 RenderPassId render_pass_id) {
danakj64767d902015-06-19 00:10:43196 gfx::Rect visible_layer_rect =
danakja1b92e42015-02-11 21:07:47197 occlusion_in_content_space.GetUnoccludedContentRect(content_rect_);
danakj64767d902015-06-19 00:10:43198 if (visible_layer_rect.IsEmpty())
[email protected]ba0f8d92014-03-21 18:41:10199 return;
200
[email protected]c6707fd2014-06-23 05:50:36201 SharedQuadState* shared_quad_state =
202 render_pass->CreateAndAppendSharedQuadState();
danakja1b92e42015-02-11 21:07:47203 shared_quad_state->SetAll(draw_transform, content_rect_.size(), content_rect_,
204 clip_rect_, is_clipped_, draw_opacity_,
[email protected]a9d4d4f2014-06-19 06:49:28205 owning_layer_->blend_mode(),
206 owning_layer_->sorting_context_id());
[email protected]94f206c12012-08-25 00:09:14207
[email protected]7aba6662013-03-12 10:17:34208 if (owning_layer_->ShowDebugBorders()) {
[email protected]f7030c32014-07-03 18:54:34209 DebugBorderDrawQuad* debug_border_quad =
210 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
danakja1b92e42015-02-11 21:07:47211 debug_border_quad->SetNew(shared_quad_state, content_rect_,
danakj64767d902015-06-19 00:10:43212 visible_layer_rect, debug_border_color,
danakja1b92e42015-02-11 21:07:47213 debug_border_width);
[email protected]d2d915aa2013-03-08 20:18:12214 }
[email protected]94f206c12012-08-25 00:09:14215
jbaumanbbd425e2015-05-19 00:33:35216 ResourceId mask_resource_id = 0;
ennef6f3fbba42014-10-16 18:16:49217 gfx::Size mask_texture_size;
218 gfx::Vector2dF mask_uv_scale;
danakja1b92e42015-02-11 21:07:47219 if (mask_layer && mask_layer->DrawsContent() &&
220 !mask_layer->bounds().IsEmpty()) {
ennef6f3fbba42014-10-16 18:16:49221 mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
[email protected]d2d915aa2013-03-08 20:18:12222 gfx::Vector2dF owning_layer_draw_scale =
[email protected]fa816c62013-03-18 04:24:21223 MathUtil::ComputeTransform2dScaleComponents(
[email protected]7aba6662013-03-12 10:17:34224 owning_layer_->draw_transform(), 1.f);
Dana Jansensc46d3742015-06-18 01:33:14225 gfx::SizeF unclipped_mask_target_size =
226 gfx::ScaleSize(owning_layer_->bounds(), owning_layer_draw_scale.x(),
227 owning_layer_draw_scale.y());
ennef6f3fbba42014-10-16 18:16:49228 mask_uv_scale = gfx::Vector2dF(
229 content_rect_.width() / unclipped_mask_target_size.width(),
230 content_rect_.height() / unclipped_mask_target_size.height());
[email protected]d2d915aa2013-03-08 20:18:12231 }
[email protected]94f206c12012-08-25 00:09:14232
[email protected]7ac3d492014-08-08 21:25:32233 DCHECK(owning_layer_->draw_properties().target_space_transform.IsScale2d());
234 gfx::Vector2dF owning_layer_to_target_scale =
235 owning_layer_->draw_properties().target_space_transform.Scale2d();
[email protected]7ac3d492014-08-08 21:25:32236
[email protected]f7030c32014-07-03 18:54:34237 RenderPassDrawQuad* quad =
238 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
danakj64767d902015-06-19 00:10:43239 quad->SetNew(shared_quad_state, content_rect_, visible_layer_rect,
240 render_pass_id, mask_resource_id, mask_uv_scale,
241 mask_texture_size, owning_layer_->filters(),
[email protected]7ac3d492014-08-08 21:25:32242 owning_layer_to_target_scale,
[email protected]7aba6662013-03-12 10:17:34243 owning_layer_->background_filters());
[email protected]94f206c12012-08-25 00:09:14244}
245
[email protected]bc5e77c2012-11-05 20:00:49246} // namespace cc