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

Side by Side Diff: cc/trees/layer_tree_host_common.cc

Issue 952893003: Update from https://crrev.com/317530 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix gn for nacl Created 5 years, 10 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/trees/layer_tree_host_client.h ('k') | cc/trees/layer_tree_host_common_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/trees/layer_tree_host_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // Ensure that this translation is truly 2d. 154 // Ensure that this translation is truly 2d.
155 DCHECK(trans.IsIdentityOrTranslation()); 155 DCHECK(trans.IsIdentityOrTranslation());
156 DCHECK_EQ(0.f, trans.matrix().get(2, 3)); 156 DCHECK_EQ(0.f, trans.matrix().get(2, 3));
157 translation += trans.To2dTranslation(); 157 translation += trans.To2dTranslation();
158 } 158 }
159 159
160 return translation; 160 return translation;
161 } 161 }
162 162
163 enum TranslateRectDirection { 163 enum TranslateRectDirection {
164 TranslateRectDirectionToAncestor, 164 TRANSLATE_RECT_DIRECTION_TO_ANCESTOR,
165 TranslateRectDirectionToDescendant 165 TRANSLATE_RECT_DIRECTION_TO_DESCENDANT
166 }; 166 };
167 167
168 template <typename LayerType> 168 template <typename LayerType>
169 static gfx::Rect TranslateRectToTargetSpace(const LayerType& ancestor_layer, 169 static gfx::Rect TranslateRectToTargetSpace(const LayerType& ancestor_layer,
170 const LayerType& descendant_layer, 170 const LayerType& descendant_layer,
171 const gfx::Rect& rect, 171 const gfx::Rect& rect,
172 TranslateRectDirection direction) { 172 TranslateRectDirection direction) {
173 gfx::Vector2dF translation = ComputeChangeOfBasisTranslation<LayerType>( 173 gfx::Vector2dF translation = ComputeChangeOfBasisTranslation<LayerType>(
174 ancestor_layer, descendant_layer); 174 ancestor_layer, descendant_layer);
175 if (direction == TranslateRectDirectionToDescendant) 175 if (direction == TRANSLATE_RECT_DIRECTION_TO_DESCENDANT)
176 translation.Scale(-1.f); 176 translation.Scale(-1.f);
177 return gfx::ToEnclosingRect( 177 return gfx::ToEnclosingRect(
178 gfx::RectF(rect.origin() + translation, rect.size())); 178 gfx::RectF(rect.origin() + translation, rect.size()));
179 } 179 }
180 180
181 // Attempts to update the clip rects for the given layer. If the layer has a 181 // Attempts to update the clip rects for the given layer. If the layer has a
182 // clip_parent, it may not inherit its immediate ancestor's clip. 182 // clip_parent, it may not inherit its immediate ancestor's clip.
183 template <typename LayerType> 183 template <typename LayerType>
184 static void UpdateClipRectsForClipChild( 184 static void UpdateClipRectsForClipChild(
185 const LayerType* layer, 185 const LayerType* layer,
(...skipping 18 matching lines...) Expand all
204 *subtree_should_be_clipped = clip_parent->is_clipped(); 204 *subtree_should_be_clipped = clip_parent->is_clipped();
205 205
206 // We may have to project the clip rect into our parent's target space. Note, 206 // We may have to project the clip rect into our parent's target space. Note,
207 // it must be our parent's target space, not ours. For one, we haven't 207 // it must be our parent's target space, not ours. For one, we haven't
208 // computed our transforms, so we couldn't put it in our space yet even if we 208 // computed our transforms, so we couldn't put it in our space yet even if we
209 // wanted to. But more importantly, this matches the expectations of 209 // wanted to. But more importantly, this matches the expectations of
210 // CalculateDrawPropertiesInternal. If we, say, create a render surface, these 210 // CalculateDrawPropertiesInternal. If we, say, create a render surface, these
211 // clip rects will want to be in its target space, not ours. 211 // clip rects will want to be in its target space, not ours.
212 if (clip_parent == layer->clip_parent()) { 212 if (clip_parent == layer->clip_parent()) {
213 *clip_rect_in_parent_target_space = TranslateRectToTargetSpace<LayerType>( 213 *clip_rect_in_parent_target_space = TranslateRectToTargetSpace<LayerType>(
214 *clip_parent, 214 *clip_parent, *layer->parent(), *clip_rect_in_parent_target_space,
215 *layer->parent(), 215 TRANSLATE_RECT_DIRECTION_TO_DESCENDANT);
216 *clip_rect_in_parent_target_space,
217 TranslateRectDirectionToDescendant);
218 } else { 216 } else {
219 // If we're being clipped by our scroll parent, we must translate through 217 // If we're being clipped by our scroll parent, we must translate through
220 // our common ancestor. This happens to be our parent, so it is sufficent to 218 // our common ancestor. This happens to be our parent, so it is sufficent to
221 // translate from our clip parent's space to the space of its ancestor (our 219 // translate from our clip parent's space to the space of its ancestor (our
222 // parent). 220 // parent).
223 *clip_rect_in_parent_target_space = 221 *clip_rect_in_parent_target_space = TranslateRectToTargetSpace<LayerType>(
224 TranslateRectToTargetSpace<LayerType>(*layer->parent(), 222 *layer->parent(), *clip_parent, *clip_rect_in_parent_target_space,
225 *clip_parent, 223 TRANSLATE_RECT_DIRECTION_TO_ANCESTOR);
226 *clip_rect_in_parent_target_space,
227 TranslateRectDirectionToAncestor);
228 } 224 }
229 } 225 }
230 226
231 // We collect an accumulated drawable content rect per render surface. 227 // We collect an accumulated drawable content rect per render surface.
232 // Typically, a layer will contribute to only one surface, the surface 228 // Typically, a layer will contribute to only one surface, the surface
233 // associated with its render target. Clip children, however, may affect 229 // associated with its render target. Clip children, however, may affect
234 // several surfaces since there may be several surfaces between the clip child 230 // several surfaces since there may be several surfaces between the clip child
235 // and its parent. 231 // and its parent.
236 // 232 //
237 // NB: we accumulate the layer's *clipped* drawable content rect. 233 // NB: we accumulate the layer's *clipped* drawable content rect.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 target_rect = 275 target_rect =
280 gfx::ToEnclosedRect(layer->render_surface()->DrawableContentRect()); 276 gfx::ToEnclosedRect(layer->render_surface()->DrawableContentRect());
281 } 277 }
282 278
283 if (render_target->is_clipped()) { 279 if (render_target->is_clipped()) {
284 gfx::Rect clip_rect = render_target->clip_rect(); 280 gfx::Rect clip_rect = render_target->clip_rect();
285 // If the layer has a clip parent, the clip rect may be in the wrong space, 281 // If the layer has a clip parent, the clip rect may be in the wrong space,
286 // so we'll need to transform it before it is applied. 282 // so we'll need to transform it before it is applied.
287 if (layer->clip_parent()) { 283 if (layer->clip_parent()) {
288 clip_rect = TranslateRectToTargetSpace<LayerType>( 284 clip_rect = TranslateRectToTargetSpace<LayerType>(
289 *layer->clip_parent(), 285 *layer->clip_parent(), *layer, clip_rect,
290 *layer, 286 TRANSLATE_RECT_DIRECTION_TO_DESCENDANT);
291 clip_rect,
292 TranslateRectDirectionToDescendant);
293 } 287 }
294 target_rect.Intersect(clip_rect); 288 target_rect.Intersect(clip_rect);
295 } 289 }
296 290
297 // We must have at least one entry in the vector for the root. 291 // We must have at least one entry in the vector for the root.
298 DCHECK_LT(0ul, accumulated_surface_state->size()); 292 DCHECK_LT(0ul, accumulated_surface_state->size());
299 293
300 typedef typename std::vector<AccumulatedSurfaceState<LayerType>> 294 typedef typename std::vector<AccumulatedSurfaceState<LayerType>>
301 AccumulatedSurfaceStateVector; 295 AccumulatedSurfaceStateVector;
302 typedef typename AccumulatedSurfaceStateVector::reverse_iterator 296 typedef typename AccumulatedSurfaceStateVector::reverse_iterator
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 void Merge(const PreCalculateMetaInformationRecursiveData& data) { 1190 void Merge(const PreCalculateMetaInformationRecursiveData& data) {
1197 layer_or_descendant_has_copy_request |= 1191 layer_or_descendant_has_copy_request |=
1198 data.layer_or_descendant_has_copy_request; 1192 data.layer_or_descendant_has_copy_request;
1199 layer_or_descendant_has_input_handler |= 1193 layer_or_descendant_has_input_handler |=
1200 data.layer_or_descendant_has_input_handler; 1194 data.layer_or_descendant_has_input_handler;
1201 num_unclipped_descendants += 1195 num_unclipped_descendants +=
1202 data.num_unclipped_descendants; 1196 data.num_unclipped_descendants;
1203 } 1197 }
1204 }; 1198 };
1205 1199
1200 static bool ValidateRenderSurface(LayerImpl* layer) {
1201 // This test verifies that there are no cases where a LayerImpl needs
1202 // a render surface, but doesn't have one.
1203 if (layer->render_surface())
1204 return true;
1205
1206 return layer->filters().IsEmpty() && layer->background_filters().IsEmpty() &&
1207 !layer->mask_layer() && !layer->replica_layer() &&
1208 !IsRootLayer(layer) && !layer->is_root_for_isolated_group() &&
1209 !layer->HasCopyRequest();
1210 }
1211
1212 static bool ValidateRenderSurface(Layer* layer) {
1213 return true;
1214 }
1215
1206 // Recursively walks the layer tree to compute any information that is needed 1216 // Recursively walks the layer tree to compute any information that is needed
1207 // before doing the main recursion. 1217 // before doing the main recursion.
1208 template <typename LayerType> 1218 template <typename LayerType>
1209 static void PreCalculateMetaInformation( 1219 static void PreCalculateMetaInformation(
1210 LayerType* layer, 1220 LayerType* layer,
1211 PreCalculateMetaInformationRecursiveData* recursive_data) { 1221 PreCalculateMetaInformationRecursiveData* recursive_data) {
1222 DCHECK(ValidateRenderSurface(layer));
1223
1212 layer->draw_properties().sorted_for_recursion = false; 1224 layer->draw_properties().sorted_for_recursion = false;
1213 layer->draw_properties().has_child_with_a_scroll_parent = false; 1225 layer->draw_properties().has_child_with_a_scroll_parent = false;
1214 1226
1215 if (!HasInvertibleOrAnimatedTransform(layer)) { 1227 if (!HasInvertibleOrAnimatedTransform(layer)) {
1216 // Layers with singular transforms should not be drawn, the whole subtree 1228 // Layers with singular transforms should not be drawn, the whole subtree
1217 // can be skipped. 1229 // can be skipped.
1218 return; 1230 return;
1219 } 1231 }
1220 1232
1221 if (layer->clip_parent()) 1233 if (layer->clip_parent())
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 inputs->current_render_surface_layer_list_id); 2570 inputs->current_render_surface_layer_list_id);
2559 2571
2560 // The dummy layer list should not have been used. 2572 // The dummy layer list should not have been used.
2561 DCHECK_EQ(0u, dummy_layer_list.size()); 2573 DCHECK_EQ(0u, dummy_layer_list.size());
2562 // A root layer render_surface should always exist after 2574 // A root layer render_surface should always exist after
2563 // CalculateDrawProperties. 2575 // CalculateDrawProperties.
2564 DCHECK(inputs->root_layer->render_surface()); 2576 DCHECK(inputs->root_layer->render_surface());
2565 } 2577 }
2566 2578
2567 } // namespace cc 2579 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_client.h ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698