[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 5 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 9 | #include "base/logging.h" |
[email protected] | 8e61d4b | 2013-06-10 22:11:48 | [diff] [blame] | 10 | #include "base/strings/stringprintf.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 11 | #include "cc/base/math_util.h" |
[email protected] | 6e84de2 | 2013-03-18 06:54:27 | [diff] [blame] | 12 | #include "cc/debug/debug_colors.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 13 | #include "cc/layers/delegated_renderer_layer_impl.h" |
| 14 | #include "cc/layers/layer_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 15 | #include "cc/layers/render_pass_sink.h" |
[email protected] | 89e8267a | 2013-03-18 07:50:56 | [diff] [blame] | 16 | #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] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 20 | #include "cc/trees/damage_tracker.h" |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 21 | #include "cc/trees/occlusion.h" |
[email protected] | 55761e6 | 2012-11-21 18:55:58 | [diff] [blame] | 22 | #include "third_party/skia/include/core/SkImageFilter.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 23 | #include "ui/gfx/geometry/rect_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 24 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 25 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 26 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 27 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 28 | RenderSurfaceImpl::RenderSurfaceImpl(LayerImpl* owning_layer) |
| 29 | : owning_layer_(owning_layer), |
| 30 | surface_property_changed_(false), |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 31 | is_clipped_(false), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 32 | contributes_to_drawn_surface_(false), |
[email protected] | c55f3fc | 2013-12-10 05:48:48 | [diff] [blame] | 33 | draw_opacity_(1), |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 34 | nearest_occlusion_immune_ancestor_(nullptr), |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 35 | target_render_surface_layer_index_history_(0), |
| 36 | current_layer_index_history_(0) { |
| 37 | damage_tracker_ = DamageTracker::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 38 | } |
| 39 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 40 | RenderSurfaceImpl::~RenderSurfaceImpl() {} |
| 41 | |
| 42 | gfx::RectF RenderSurfaceImpl::DrawableContentRect() const { |
| 43 | gfx::RectF drawable_content_rect = |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 44 | MathUtil::MapClippedRect(draw_transform_, content_rect_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 45 | if (owning_layer_->has_replica()) { |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 46 | drawable_content_rect.Union( |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 47 | MathUtil::MapClippedRect(replica_draw_transform_, content_rect_)); |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | return drawable_content_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 51 | } |
| 52 | |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 53 | SkColor RenderSurfaceImpl::GetDebugBorderColor() const { |
| 54 | return DebugColors::SurfaceBorderColor(); |
| 55 | } |
| 56 | |
| 57 | SkColor RenderSurfaceImpl::GetReplicaDebugBorderColor() const { |
| 58 | return DebugColors::SurfaceReplicaBorderColor(); |
| 59 | } |
| 60 | |
| 61 | float RenderSurfaceImpl::GetDebugBorderWidth() const { |
| 62 | return DebugColors::SurfaceBorderWidth(owning_layer_->layer_tree_impl()); |
| 63 | } |
| 64 | |
| 65 | float RenderSurfaceImpl::GetReplicaDebugBorderWidth() const { |
| 66 | return DebugColors::SurfaceReplicaBorderWidth( |
| 67 | owning_layer_->layer_tree_impl()); |
| 68 | } |
| 69 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 70 | int RenderSurfaceImpl::OwningLayerId() const { |
| 71 | return owning_layer_ ? owning_layer_->id() : 0; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | } |
| 73 | |
jaydasika | 7ba8f92 | 2015-08-21 05:39:42 | [diff] [blame^] | 74 | bool RenderSurfaceImpl::HasReplica() const { |
| 75 | return owning_layer_->has_replica(); |
| 76 | } |
| 77 | |
| 78 | gfx::Transform RenderSurfaceImpl::ReplicaDrawTransform() const { |
| 79 | return replica_draw_transform_; |
| 80 | } |
| 81 | |
jaydasika | 504a050 | 2015-07-23 19:25:44 | [diff] [blame] | 82 | int RenderSurfaceImpl::TransformTreeIndex() const { |
| 83 | return owning_layer_->transform_tree_index(); |
| 84 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 85 | |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 86 | int RenderSurfaceImpl::ClipTreeIndex() const { |
| 87 | return owning_layer_->clip_tree_index(); |
| 88 | } |
| 89 | |
jaydasika | 0f4b1a9 | 2015-08-18 23:19:02 | [diff] [blame] | 90 | int RenderSurfaceImpl::EffectTreeIndex() const { |
| 91 | return owning_layer_->effect_tree_index(); |
| 92 | } |
| 93 | |
| 94 | int 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] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 100 | void RenderSurfaceImpl::SetClipRect(const gfx::Rect& clip_rect) { |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 101 | if (clip_rect_ == clip_rect) |
| 102 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 104 | surface_property_changed_ = true; |
| 105 | clip_rect_ = clip_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 106 | } |
| 107 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 108 | void RenderSurfaceImpl::SetContentRect(const gfx::Rect& content_rect) { |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 109 | if (content_rect_ == content_rect) |
| 110 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 111 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 112 | surface_property_changed_ = true; |
| 113 | content_rect_ = content_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 114 | } |
| 115 | |
jaydasika | 7ba8f92 | 2015-08-21 05:39:42 | [diff] [blame^] | 116 | void 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 | |
| 125 | void RenderSurfaceImpl::SetAccumulatedContentRect( |
| 126 | const gfx::Rect& content_rect) { |
| 127 | accumulated_content_rect_ = content_rect; |
| 128 | } |
| 129 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 130 | bool 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] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 141 | return surface_property_changed_ || owning_layer_->LayerPropertyChanged(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 142 | } |
| 143 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 144 | bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 145 | return surface_property_changed_ && !owning_layer_->LayerPropertyChanged(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 148 | void 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] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 158 | void RenderSurfaceImpl::ClearLayerLists() { |
| 159 | layer_list_.clear(); |
| 160 | contributing_delegated_render_pass_layer_list_.clear(); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 161 | } |
| 162 | |
[email protected] | 0cd7d6f7 | 2014-08-22 14:50:51 | [diff] [blame] | 163 | RenderPassId RenderSurfaceImpl::GetRenderPassId() { |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 164 | int layer_id = owning_layer_->id(); |
| 165 | int sub_id = 0; |
| 166 | DCHECK_GT(layer_id, 0); |
[email protected] | 0cd7d6f7 | 2014-08-22 14:50:51 | [diff] [blame] | 167 | return RenderPassId(layer_id, sub_id); |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 170 | void 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] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 178 | |
[email protected] | b27511f | 2013-11-28 05:39:04 | [diff] [blame] | 179 | scoped_ptr<RenderPass> pass = RenderPass::Create(layer_list_.size()); |
[email protected] | 0cd7d6f7 | 2014-08-22 14:50:51 | [diff] [blame] | 180 | pass->SetNew(GetRenderPassId(), |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 181 | content_rect_, |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 182 | gfx::IntersectRects(content_rect_, |
| 183 | damage_tracker_->current_damage_rect()), |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 184 | screen_space_transform_); |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 185 | pass_sink->AppendRenderPass(pass.Pass()); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 186 | } |
| 187 | |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 188 | void 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) { |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 196 | gfx::Rect visible_layer_rect = |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 197 | occlusion_in_content_space.GetUnoccludedContentRect(content_rect_); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 198 | if (visible_layer_rect.IsEmpty()) |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 199 | return; |
| 200 | |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 201 | SharedQuadState* shared_quad_state = |
| 202 | render_pass->CreateAndAppendSharedQuadState(); |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 203 | shared_quad_state->SetAll(draw_transform, content_rect_.size(), content_rect_, |
| 204 | clip_rect_, is_clipped_, draw_opacity_, |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 205 | owning_layer_->blend_mode(), |
| 206 | owning_layer_->sorting_context_id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 207 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 208 | if (owning_layer_->ShowDebugBorders()) { |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 209 | DebugBorderDrawQuad* debug_border_quad = |
| 210 | render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>(); |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 211 | debug_border_quad->SetNew(shared_quad_state, content_rect_, |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 212 | visible_layer_rect, debug_border_color, |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 213 | debug_border_width); |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 214 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 215 | |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 216 | ResourceId mask_resource_id = 0; |
enne | f6f3fbba4 | 2014-10-16 18:16:49 | [diff] [blame] | 217 | gfx::Size mask_texture_size; |
| 218 | gfx::Vector2dF mask_uv_scale; |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 219 | if (mask_layer && mask_layer->DrawsContent() && |
| 220 | !mask_layer->bounds().IsEmpty()) { |
enne | f6f3fbba4 | 2014-10-16 18:16:49 | [diff] [blame] | 221 | mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size); |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 222 | gfx::Vector2dF owning_layer_draw_scale = |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 223 | MathUtil::ComputeTransform2dScaleComponents( |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 224 | owning_layer_->draw_transform(), 1.f); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 225 | gfx::SizeF unclipped_mask_target_size = |
| 226 | gfx::ScaleSize(owning_layer_->bounds(), owning_layer_draw_scale.x(), |
| 227 | owning_layer_draw_scale.y()); |
enne | f6f3fbba4 | 2014-10-16 18:16:49 | [diff] [blame] | 228 | 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] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 231 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 232 | |
[email protected] | 7ac3d49 | 2014-08-08 21:25:32 | [diff] [blame] | 233 | 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] | 7ac3d49 | 2014-08-08 21:25:32 | [diff] [blame] | 236 | |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 237 | RenderPassDrawQuad* quad = |
| 238 | render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 239 | 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] | 7ac3d49 | 2014-08-08 21:25:32 | [diff] [blame] | 242 | owning_layer_to_target_scale, |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 243 | owning_layer_->background_filters()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 246 | } // namespace cc |