blob: c621218516e3d70e41a3a6a722353828d1c7a53c [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
jaydasika504a0502015-07-23 19:25:4474int RenderSurfaceImpl::TransformTreeIndex() const {
75 return owning_layer_->transform_tree_index();
76}
[email protected]94f206c12012-08-25 00:09:1477
jaydasikaebf9e4ea2015-08-14 21:29:1278int RenderSurfaceImpl::ClipTreeIndex() const {
79 return owning_layer_->clip_tree_index();
80}
81
[email protected]0023fc72014-01-10 20:05:0682void RenderSurfaceImpl::SetClipRect(const gfx::Rect& clip_rect) {
[email protected]d2d915aa2013-03-08 20:18:1283 if (clip_rect_ == clip_rect)
84 return;
[email protected]94f206c12012-08-25 00:09:1485
[email protected]d2d915aa2013-03-08 20:18:1286 surface_property_changed_ = true;
87 clip_rect_ = clip_rect;
[email protected]94f206c12012-08-25 00:09:1488}
89
[email protected]0023fc72014-01-10 20:05:0690void RenderSurfaceImpl::SetContentRect(const gfx::Rect& content_rect) {
[email protected]d2d915aa2013-03-08 20:18:1291 if (content_rect_ == content_rect)
92 return;
[email protected]94f206c12012-08-25 00:09:1493
[email protected]d2d915aa2013-03-08 20:18:1294 surface_property_changed_ = true;
95 content_rect_ = content_rect;
[email protected]94f206c12012-08-25 00:09:1496}
97
[email protected]d2d915aa2013-03-08 20:18:1298bool RenderSurfaceImpl::SurfacePropertyChanged() const {
99 // Surface property changes are tracked as follows:
100 //
101 // - surface_property_changed_ is flagged when the clip_rect or content_rect
102 // change. As of now, these are the only two properties that can be affected
103 // by descendant layers.
104 //
105 // - all other property changes come from the owning layer (or some ancestor
106 // layer that propagates its change to the owning layer).
107 //
108 DCHECK(owning_layer_);
[email protected]7aba6662013-03-12 10:17:34109 return surface_property_changed_ || owning_layer_->LayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14110}
111
[email protected]d2d915aa2013-03-08 20:18:12112bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const {
[email protected]7aba6662013-03-12 10:17:34113 return surface_property_changed_ && !owning_layer_->LayerPropertyChanged();
[email protected]94f206c12012-08-25 00:09:14114}
115
[email protected]d2d915aa2013-03-08 20:18:12116void RenderSurfaceImpl::AddContributingDelegatedRenderPassLayer(
117 LayerImpl* layer) {
118 DCHECK(std::find(layer_list_.begin(), layer_list_.end(), layer) !=
119 layer_list_.end());
120 DelegatedRendererLayerImpl* delegated_renderer_layer =
121 static_cast<DelegatedRendererLayerImpl*>(layer);
122 contributing_delegated_render_pass_layer_list_.push_back(
123 delegated_renderer_layer);
[email protected]7d929c02012-09-20 17:26:57124}
125
[email protected]d2d915aa2013-03-08 20:18:12126void RenderSurfaceImpl::ClearLayerLists() {
127 layer_list_.clear();
128 contributing_delegated_render_pass_layer_list_.clear();
[email protected]7d929c02012-09-20 17:26:57129}
130
[email protected]0cd7d6f72014-08-22 14:50:51131RenderPassId RenderSurfaceImpl::GetRenderPassId() {
[email protected]d2d915aa2013-03-08 20:18:12132 int layer_id = owning_layer_->id();
133 int sub_id = 0;
134 DCHECK_GT(layer_id, 0);
[email protected]0cd7d6f72014-08-22 14:50:51135 return RenderPassId(layer_id, sub_id);
[email protected]0f077a52012-09-08 01:45:24136}
137
[email protected]d2d915aa2013-03-08 20:18:12138void RenderSurfaceImpl::AppendRenderPasses(RenderPassSink* pass_sink) {
139 for (size_t i = 0;
140 i < contributing_delegated_render_pass_layer_list_.size();
141 ++i) {
142 DelegatedRendererLayerImpl* delegated_renderer_layer =
143 contributing_delegated_render_pass_layer_list_[i];
144 delegated_renderer_layer->AppendContributingRenderPasses(pass_sink);
145 }
[email protected]7d929c02012-09-20 17:26:57146
[email protected]b27511f2013-11-28 05:39:04147 scoped_ptr<RenderPass> pass = RenderPass::Create(layer_list_.size());
[email protected]0cd7d6f72014-08-22 14:50:51148 pass->SetNew(GetRenderPassId(),
[email protected]d2d915aa2013-03-08 20:18:12149 content_rect_,
[email protected]b4ead7b2014-04-07 18:12:18150 gfx::IntersectRects(content_rect_,
151 damage_tracker_->current_damage_rect()),
[email protected]d2d915aa2013-03-08 20:18:12152 screen_space_transform_);
[email protected]c1bb5af2013-03-13 19:06:27153 pass_sink->AppendRenderPass(pass.Pass());
[email protected]467b3612012-08-28 07:41:16154}
155
danakja1b92e42015-02-11 21:07:47156void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass,
157 const gfx::Transform& draw_transform,
158 const Occlusion& occlusion_in_content_space,
159 SkColor debug_border_color,
160 float debug_border_width,
161 LayerImpl* mask_layer,
162 AppendQuadsData* append_quads_data,
163 RenderPassId render_pass_id) {
danakj64767d902015-06-19 00:10:43164 gfx::Rect visible_layer_rect =
danakja1b92e42015-02-11 21:07:47165 occlusion_in_content_space.GetUnoccludedContentRect(content_rect_);
danakj64767d902015-06-19 00:10:43166 if (visible_layer_rect.IsEmpty())
[email protected]ba0f8d92014-03-21 18:41:10167 return;
168
[email protected]c6707fd2014-06-23 05:50:36169 SharedQuadState* shared_quad_state =
170 render_pass->CreateAndAppendSharedQuadState();
danakja1b92e42015-02-11 21:07:47171 shared_quad_state->SetAll(draw_transform, content_rect_.size(), content_rect_,
172 clip_rect_, is_clipped_, draw_opacity_,
[email protected]a9d4d4f2014-06-19 06:49:28173 owning_layer_->blend_mode(),
174 owning_layer_->sorting_context_id());
[email protected]94f206c12012-08-25 00:09:14175
[email protected]7aba6662013-03-12 10:17:34176 if (owning_layer_->ShowDebugBorders()) {
[email protected]f7030c32014-07-03 18:54:34177 DebugBorderDrawQuad* debug_border_quad =
178 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
danakja1b92e42015-02-11 21:07:47179 debug_border_quad->SetNew(shared_quad_state, content_rect_,
danakj64767d902015-06-19 00:10:43180 visible_layer_rect, debug_border_color,
danakja1b92e42015-02-11 21:07:47181 debug_border_width);
[email protected]d2d915aa2013-03-08 20:18:12182 }
[email protected]94f206c12012-08-25 00:09:14183
jbaumanbbd425e2015-05-19 00:33:35184 ResourceId mask_resource_id = 0;
ennef6f3fbba42014-10-16 18:16:49185 gfx::Size mask_texture_size;
186 gfx::Vector2dF mask_uv_scale;
danakja1b92e42015-02-11 21:07:47187 if (mask_layer && mask_layer->DrawsContent() &&
188 !mask_layer->bounds().IsEmpty()) {
ennef6f3fbba42014-10-16 18:16:49189 mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
[email protected]d2d915aa2013-03-08 20:18:12190 gfx::Vector2dF owning_layer_draw_scale =
[email protected]fa816c62013-03-18 04:24:21191 MathUtil::ComputeTransform2dScaleComponents(
[email protected]7aba6662013-03-12 10:17:34192 owning_layer_->draw_transform(), 1.f);
Dana Jansensc46d3742015-06-18 01:33:14193 gfx::SizeF unclipped_mask_target_size =
194 gfx::ScaleSize(owning_layer_->bounds(), owning_layer_draw_scale.x(),
195 owning_layer_draw_scale.y());
ennef6f3fbba42014-10-16 18:16:49196 mask_uv_scale = gfx::Vector2dF(
197 content_rect_.width() / unclipped_mask_target_size.width(),
198 content_rect_.height() / unclipped_mask_target_size.height());
[email protected]d2d915aa2013-03-08 20:18:12199 }
[email protected]94f206c12012-08-25 00:09:14200
[email protected]7ac3d492014-08-08 21:25:32201 DCHECK(owning_layer_->draw_properties().target_space_transform.IsScale2d());
202 gfx::Vector2dF owning_layer_to_target_scale =
203 owning_layer_->draw_properties().target_space_transform.Scale2d();
[email protected]7ac3d492014-08-08 21:25:32204
[email protected]f7030c32014-07-03 18:54:34205 RenderPassDrawQuad* quad =
206 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
danakj64767d902015-06-19 00:10:43207 quad->SetNew(shared_quad_state, content_rect_, visible_layer_rect,
208 render_pass_id, mask_resource_id, mask_uv_scale,
209 mask_texture_size, owning_layer_->filters(),
[email protected]7ac3d492014-08-08 21:25:32210 owning_layer_to_target_scale,
[email protected]7aba6662013-03-12 10:17:34211 owning_layer_->background_filters());
[email protected]94f206c12012-08-25 00:09:14212}
213
[email protected]bc5e77c2012-11-05 20:00:49214} // namespace cc