Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / cc / layers / render_surface_impl.cc
blob2ca1241f719d211529171304681efe1144aaf6d1
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.
5 #include "cc/layers/render_surface_impl.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h"
11 #include "cc/base/math_util.h"
12 #include "cc/debug/debug_colors.h"
13 #include "cc/layers/delegated_renderer_layer_impl.h"
14 #include "cc/layers/layer_impl.h"
15 #include "cc/layers/render_pass_sink.h"
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"
20 #include "cc/trees/damage_tracker.h"
21 #include "cc/trees/occlusion.h"
22 #include "third_party/skia/include/core/SkImageFilter.h"
23 #include "ui/gfx/geometry/rect_conversions.h"
24 #include "ui/gfx/transform.h"
26 namespace cc {
28 RenderSurfaceImpl::RenderSurfaceImpl(LayerImpl* owning_layer)
29 : owning_layer_(owning_layer),
30 surface_property_changed_(false),
31 draw_opacity_is_animating_(false),
32 target_surface_transforms_are_animating_(false),
33 screen_space_transforms_are_animating_(false),
34 is_clipped_(false),
35 contributes_to_drawn_surface_(false),
36 draw_opacity_(1),
37 nearest_occlusion_immune_ancestor_(nullptr),
38 target_render_surface_layer_index_history_(0),
39 current_layer_index_history_(0) {
40 damage_tracker_ = DamageTracker::Create();
43 RenderSurfaceImpl::~RenderSurfaceImpl() {}
45 gfx::RectF RenderSurfaceImpl::DrawableContentRect() const {
46 gfx::RectF drawable_content_rect =
47 MathUtil::MapClippedRect(draw_transform_, content_rect_);
48 if (owning_layer_->has_replica()) {
49 drawable_content_rect.Union(
50 MathUtil::MapClippedRect(replica_draw_transform_, content_rect_));
53 return drawable_content_rect;
56 SkColor RenderSurfaceImpl::GetDebugBorderColor() const {
57 return DebugColors::SurfaceBorderColor();
60 SkColor RenderSurfaceImpl::GetReplicaDebugBorderColor() const {
61 return DebugColors::SurfaceReplicaBorderColor();
64 float RenderSurfaceImpl::GetDebugBorderWidth() const {
65 return DebugColors::SurfaceBorderWidth(owning_layer_->layer_tree_impl());
68 float RenderSurfaceImpl::GetReplicaDebugBorderWidth() const {
69 return DebugColors::SurfaceReplicaBorderWidth(
70 owning_layer_->layer_tree_impl());
73 int RenderSurfaceImpl::OwningLayerId() const {
74 return owning_layer_ ? owning_layer_->id() : 0;
78 void RenderSurfaceImpl::SetClipRect(const gfx::Rect& clip_rect) {
79 if (clip_rect_ == clip_rect)
80 return;
82 surface_property_changed_ = true;
83 clip_rect_ = clip_rect;
86 void RenderSurfaceImpl::SetContentRect(const gfx::Rect& content_rect) {
87 if (content_rect_ == content_rect)
88 return;
90 surface_property_changed_ = true;
91 content_rect_ = content_rect;
94 bool RenderSurfaceImpl::SurfacePropertyChanged() const {
95 // Surface property changes are tracked as follows:
97 // - surface_property_changed_ is flagged when the clip_rect or content_rect
98 // change. As of now, these are the only two properties that can be affected
99 // by descendant layers.
101 // - all other property changes come from the owning layer (or some ancestor
102 // layer that propagates its change to the owning layer).
104 DCHECK(owning_layer_);
105 return surface_property_changed_ || owning_layer_->LayerPropertyChanged();
108 bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const {
109 return surface_property_changed_ && !owning_layer_->LayerPropertyChanged();
112 void RenderSurfaceImpl::AddContributingDelegatedRenderPassLayer(
113 LayerImpl* layer) {
114 DCHECK(std::find(layer_list_.begin(), layer_list_.end(), layer) !=
115 layer_list_.end());
116 DelegatedRendererLayerImpl* delegated_renderer_layer =
117 static_cast<DelegatedRendererLayerImpl*>(layer);
118 contributing_delegated_render_pass_layer_list_.push_back(
119 delegated_renderer_layer);
122 void RenderSurfaceImpl::ClearLayerLists() {
123 layer_list_.clear();
124 contributing_delegated_render_pass_layer_list_.clear();
127 RenderPassId RenderSurfaceImpl::GetRenderPassId() {
128 int layer_id = owning_layer_->id();
129 int sub_id = 0;
130 DCHECK_GT(layer_id, 0);
131 return RenderPassId(layer_id, sub_id);
134 void RenderSurfaceImpl::AppendRenderPasses(RenderPassSink* pass_sink) {
135 for (size_t i = 0;
136 i < contributing_delegated_render_pass_layer_list_.size();
137 ++i) {
138 DelegatedRendererLayerImpl* delegated_renderer_layer =
139 contributing_delegated_render_pass_layer_list_[i];
140 delegated_renderer_layer->AppendContributingRenderPasses(pass_sink);
143 scoped_ptr<RenderPass> pass = RenderPass::Create(layer_list_.size());
144 pass->SetNew(GetRenderPassId(),
145 content_rect_,
146 gfx::IntersectRects(content_rect_,
147 damage_tracker_->current_damage_rect()),
148 screen_space_transform_);
149 pass_sink->AppendRenderPass(pass.Pass());
152 void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass,
153 const gfx::Transform& draw_transform,
154 const Occlusion& occlusion_in_content_space,
155 SkColor debug_border_color,
156 float debug_border_width,
157 LayerImpl* mask_layer,
158 AppendQuadsData* append_quads_data,
159 RenderPassId render_pass_id) {
160 gfx::Rect visible_content_rect =
161 occlusion_in_content_space.GetUnoccludedContentRect(content_rect_);
162 if (visible_content_rect.IsEmpty())
163 return;
165 SharedQuadState* shared_quad_state =
166 render_pass->CreateAndAppendSharedQuadState();
167 shared_quad_state->SetAll(draw_transform, content_rect_.size(), content_rect_,
168 clip_rect_, is_clipped_, draw_opacity_,
169 owning_layer_->blend_mode(),
170 owning_layer_->sorting_context_id());
172 if (owning_layer_->ShowDebugBorders()) {
173 DebugBorderDrawQuad* debug_border_quad =
174 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
175 debug_border_quad->SetNew(shared_quad_state, content_rect_,
176 visible_content_rect, debug_border_color,
177 debug_border_width);
180 ResourceProvider::ResourceId mask_resource_id = 0;
181 gfx::Size mask_texture_size;
182 gfx::Vector2dF mask_uv_scale;
183 if (mask_layer && mask_layer->DrawsContent() &&
184 !mask_layer->bounds().IsEmpty()) {
185 mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size);
186 gfx::Vector2dF owning_layer_draw_scale =
187 MathUtil::ComputeTransform2dScaleComponents(
188 owning_layer_->draw_transform(), 1.f);
189 gfx::SizeF unclipped_mask_target_size = gfx::ScaleSize(
190 owning_layer_->content_bounds(),
191 owning_layer_draw_scale.x(),
192 owning_layer_draw_scale.y());
193 mask_uv_scale = gfx::Vector2dF(
194 content_rect_.width() / unclipped_mask_target_size.width(),
195 content_rect_.height() / unclipped_mask_target_size.height());
198 DCHECK(owning_layer_->draw_properties().target_space_transform.IsScale2d());
199 gfx::Vector2dF owning_layer_to_target_scale =
200 owning_layer_->draw_properties().target_space_transform.Scale2d();
201 owning_layer_to_target_scale.Scale(owning_layer_->contents_scale_x(),
202 owning_layer_->contents_scale_y());
204 RenderPassDrawQuad* quad =
205 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
206 quad->SetNew(shared_quad_state,
207 content_rect_,
208 visible_content_rect,
209 render_pass_id,
210 mask_resource_id,
211 mask_uv_scale,
212 mask_texture_size,
213 owning_layer_->filters(),
214 owning_layer_to_target_scale,
215 owning_layer_->background_filters());
218 } // namespace cc