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/layers/render_surface_impl.h" | 5 #include "cc/layers/render_surface_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 } | 143 } |
144 | 144 |
145 void RenderSurfaceImpl::SetContentRect(const gfx::Rect& content_rect) { | 145 void RenderSurfaceImpl::SetContentRect(const gfx::Rect& content_rect) { |
146 if (content_rect == draw_properties_.content_rect) | 146 if (content_rect == draw_properties_.content_rect) |
147 return; | 147 return; |
148 | 148 |
149 surface_property_changed_ = true; | 149 surface_property_changed_ = true; |
150 draw_properties_.content_rect = content_rect; | 150 draw_properties_.content_rect = content_rect; |
151 } | 151 } |
152 | 152 |
153 void RenderSurfaceImpl::SetContentRectForTesting(const gfx::Rect& rect) { | |
154 SetContentRect(rect); | |
155 } | |
156 | |
157 void RenderSurfaceImpl::CalculateContentRectFromAccumulatedContentRect( | |
158 int max_texture_size) { | |
159 // Root render surface use viewport, and does not calculate content rect. | |
160 DCHECK_NE(render_target(), this); | |
161 | |
162 // Surface's content rect is the clipped accumulated content rect. By default | |
163 // use accumulated content rect, and then try to clip it. | |
164 gfx::Rect surface_content_rect = accumulated_content_rect(); | |
165 // Early out if no need to clip. | |
166 if (!owning_layer_->replica_layer() && !owning_layer_->HasCopyRequest() && | |
167 is_clipped()) { | |
168 if (!accumulated_content_rect().IsEmpty()) { | |
169 // Calculate projection from the target surface rect to local | |
170 // space. Non-invertible draw transforms means no able to bring clipped | |
171 // rect in target space back to local space, early out without clip. | |
172 gfx::Transform target_to_surface(gfx::Transform::kSkipInitialization); | |
173 if (draw_transform().GetInverse(&target_to_surface)) { | |
174 // Clip rect is in target space. Bring accumulated content rect to | |
175 // target space in preparation for clipping. | |
176 gfx::Rect accumulated_rect_in_target_space = | |
177 MathUtil::MapEnclosingClippedRect(draw_transform(), | |
178 accumulated_content_rect()); | |
179 // If accumulated content rect is contained within clip rect, early out | |
180 // without clipping. | |
181 if (!clip_rect().Contains(accumulated_rect_in_target_space)) { | |
182 gfx::Rect clipped_accumulated_rect_in_target_space = clip_rect(); | |
183 clipped_accumulated_rect_in_target_space.Intersect( | |
184 accumulated_rect_in_target_space); | |
185 | |
186 if (!clipped_accumulated_rect_in_target_space.IsEmpty()) { | |
187 gfx::Rect clipped_accumulated_rect_in_local_space = | |
188 MathUtil::ProjectEnclosingClippedRect( | |
189 target_to_surface, | |
190 clipped_accumulated_rect_in_target_space); | |
191 // Bringing clipped accumulated rect back to local space may result | |
192 // in inflationg due to axis-alignment. | |
ajuma
2016/04/19 19:20:37
typo: inflation
| |
193 surface_content_rect.Intersect( | |
194 clipped_accumulated_rect_in_local_space); | |
195 } else { | |
196 // All accumulated content rect is clipped out. | |
197 surface_content_rect = gfx::Rect(); | |
198 } | |
199 } | |
200 } | |
201 } | |
202 } | |
ajuma
2016/04/19 19:20:37
Suggestion for making this easier to read: put thi
| |
203 // The RenderSurfaceImpl backing texture cannot exceed the maximum | |
204 // supported texture size. | |
205 surface_content_rect.set_width( | |
206 std::min(surface_content_rect.width(), max_texture_size)); | |
207 surface_content_rect.set_height( | |
208 std::min(surface_content_rect.height(), max_texture_size)); | |
209 | |
210 SetContentRect(surface_content_rect); | |
211 } | |
212 | |
213 void RenderSurfaceImpl::SetContentRectToViewport() { | |
214 // Only root render surface use viewport as content rect. | |
215 DCHECK_EQ(render_target(), this); | |
216 gfx::Rect viewport = gfx::ToEnclosingRect(owning_layer_->layer_tree_impl() | |
217 ->property_trees() | |
218 ->clip_tree.ViewportClip()); | |
219 SetContentRect(viewport); | |
220 } | |
221 | |
153 void RenderSurfaceImpl::ClearAccumulatedContentRect() { | 222 void RenderSurfaceImpl::ClearAccumulatedContentRect() { |
154 accumulated_content_rect_ = gfx::Rect(); | 223 accumulated_content_rect_ = gfx::Rect(); |
155 } | 224 } |
156 | 225 |
157 void RenderSurfaceImpl::AccumulateContentRectFromContributingLayer( | 226 void RenderSurfaceImpl::AccumulateContentRectFromContributingLayer( |
158 LayerImpl* layer) { | 227 LayerImpl* layer) { |
159 DCHECK(layer->DrawsContent()); | 228 DCHECK(layer->DrawsContent()); |
160 DCHECK_EQ(this, layer->render_target()); | 229 DCHECK_EQ(this, layer->render_target()); |
161 | 230 |
162 // Root render surface doesn't accumulate content rect, it always uses | 231 // Root render surface doesn't accumulate content rect, it always uses |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 RenderPassDrawQuad* quad = | 344 RenderPassDrawQuad* quad = |
276 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); | 345 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
277 quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect, | 346 quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect, |
278 render_pass_id, mask_resource_id, mask_uv_scale, | 347 render_pass_id, mask_resource_id, mask_uv_scale, |
279 mask_texture_size, owning_layer_->filters(), | 348 mask_texture_size, owning_layer_->filters(), |
280 owning_layer_to_target_scale, | 349 owning_layer_to_target_scale, |
281 owning_layer_->background_filters()); | 350 owning_layer_->background_filters()); |
282 } | 351 } |
283 | 352 |
284 } // namespace cc | 353 } // namespace cc |
OLD | NEW |