Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: cc/layers/render_surface_impl.cc

Issue 1902893002: cc: Move calculation of content rect to RenderSurfaceImpl class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@targetid
Patch Set: fix error Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/render_surface_impl.h ('k') | cc/layers/render_surface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 gfx::Rect RenderSurfaceImpl::CalculateClippedAccumulatedContentRect() {
158 if (owning_layer_->replica_layer() || owning_layer_->HasCopyRequest() ||
159 !is_clipped())
160 return accumulated_content_rect();
161
162 if (accumulated_content_rect().IsEmpty())
163 return gfx::Rect();
164
165 // Calculate projection from the target surface rect to local
166 // space. Non-invertible draw transforms means no able to bring clipped rect
167 // in target space back to local space, early out without clip.
168 gfx::Transform target_to_surface(gfx::Transform::kSkipInitialization);
169 if (!draw_transform().GetInverse(&target_to_surface))
170 return accumulated_content_rect();
171
172 // Clip rect is in target space. Bring accumulated content rect to
173 // target space in preparation for clipping.
174 gfx::Rect accumulated_rect_in_target_space =
175 MathUtil::MapEnclosingClippedRect(draw_transform(),
176 accumulated_content_rect());
177 // If accumulated content rect is contained within clip rect, early out
178 // without clipping.
179 if (clip_rect().Contains(accumulated_rect_in_target_space))
180 return accumulated_content_rect();
181
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 return gfx::Rect();
188
189 gfx::Rect clipped_accumulated_rect_in_local_space =
190 MathUtil::ProjectEnclosingClippedRect(
191 target_to_surface, clipped_accumulated_rect_in_target_space);
192 // Bringing clipped accumulated rect back to local space may result
193 // in inflation due to axis-alignment.
194 clipped_accumulated_rect_in_local_space.Intersect(accumulated_content_rect());
195 return clipped_accumulated_rect_in_local_space;
196 }
197
198 void RenderSurfaceImpl::CalculateContentRectFromAccumulatedContentRect(
199 int max_texture_size) {
200 // Root render surface use viewport, and does not calculate content rect.
201 DCHECK_NE(render_target(), this);
202
203 // Surface's content rect is the clipped accumulated content rect. By default
204 // use accumulated content rect, and then try to clip it.
205 gfx::Rect surface_content_rect = CalculateClippedAccumulatedContentRect();
206
207 // The RenderSurfaceImpl backing texture cannot exceed the maximum
208 // supported texture size.
209 surface_content_rect.set_width(
210 std::min(surface_content_rect.width(), max_texture_size));
211 surface_content_rect.set_height(
212 std::min(surface_content_rect.height(), max_texture_size));
213
214 SetContentRect(surface_content_rect);
215 }
216
217 void RenderSurfaceImpl::SetContentRectToViewport() {
218 // Only root render surface use viewport as content rect.
219 DCHECK_EQ(render_target(), this);
220 gfx::Rect viewport = gfx::ToEnclosingRect(owning_layer_->layer_tree_impl()
221 ->property_trees()
222 ->clip_tree.ViewportClip());
223 SetContentRect(viewport);
224 }
225
153 void RenderSurfaceImpl::ClearAccumulatedContentRect() { 226 void RenderSurfaceImpl::ClearAccumulatedContentRect() {
154 accumulated_content_rect_ = gfx::Rect(); 227 accumulated_content_rect_ = gfx::Rect();
155 } 228 }
156 229
157 void RenderSurfaceImpl::AccumulateContentRectFromContributingLayer( 230 void RenderSurfaceImpl::AccumulateContentRectFromContributingLayer(
158 LayerImpl* layer) { 231 LayerImpl* layer) {
159 DCHECK(layer->DrawsContent()); 232 DCHECK(layer->DrawsContent());
160 DCHECK_EQ(this, layer->render_target()); 233 DCHECK_EQ(this, layer->render_target());
161 234
162 // Root render surface doesn't accumulate content rect, it always uses 235 // Root render surface doesn't accumulate content rect, it always uses
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 RenderPassDrawQuad* quad = 348 RenderPassDrawQuad* quad =
276 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); 349 render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
277 quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect, 350 quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect,
278 render_pass_id, mask_resource_id, mask_uv_scale, 351 render_pass_id, mask_resource_id, mask_uv_scale,
279 mask_texture_size, owning_layer_->filters(), 352 mask_texture_size, owning_layer_->filters(),
280 owning_layer_to_target_scale, 353 owning_layer_to_target_scale,
281 owning_layer_->background_filters()); 354 owning_layer_->background_filters());
282 } 355 }
283 356
284 } // namespace cc 357 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/render_surface_impl.h ('k') | cc/layers/render_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698