12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CC_LAYERS_DRAW_PROPERTIES_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CC_LAYERS_DRAW_PROPERTIES_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/rect.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/transform.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc { 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Container for properties that layers need to compute before they can be 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// drawn. 168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)template <typename LayerType> 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct CC_EXPORT DrawProperties { 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DrawProperties() 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : opacity(0.f), 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) opacity_is_animating(false), 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) screen_space_opacity_is_animating(false), 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) target_space_transform_is_animating(false), 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) screen_space_transform_is_animating(false), 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) can_use_lcd_text(false), 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) is_clipped(false), 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) render_target(NULL), 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) contents_scale_x(1.f), 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) contents_scale_y(1.f), 29424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) num_unclipped_descendants(0), 308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) layer_or_descendant_has_copy_request(false), 31f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) layer_or_descendant_has_input_handler(false), 328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) has_child_with_a_scroll_parent(false), 338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) sorted_for_recursion(false), 348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) index_of_first_descendants_addition(0), 358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) num_descendants_added(0), 368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) index_of_first_render_surface_layer_list_addition(0), 370de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) num_render_surfaces_added(0), 38f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) last_drawn_render_surface_layer_list_id(0), 39f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) ideal_contents_scale(0.f), 40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) maximum_animation_contents_scale(0.f), 41f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) page_scale_factor(0.f), 42f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) device_scale_factor(0.f) {} 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Transforms objects from content space to target surface space, where 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this layer would be drawn. 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Transform target_space_transform; 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Transforms objects from content space to screen space (viewport space). 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Transform screen_space_transform; 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // DrawProperties::opacity may be different than LayerType::opacity, 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // particularly in the case when a RenderSurface re-parents the layer's 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // opacity, or when opacity is compounded by the hierarchy. 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float opacity; 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // xxx_is_animating flags are used to indicate whether the DrawProperties 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // are actually meaningful on the main thread. When the properties are 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // animating, the main thread may not have the same values that are used 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to draw. 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool opacity_is_animating; 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool screen_space_opacity_is_animating; 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool target_space_transform_is_animating; 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool screen_space_transform_is_animating; 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // True if the layer can use LCD text. 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool can_use_lcd_text; 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // True if the layer needs to be clipped by clip_rect. 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_clipped; 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The layer whose coordinate space this layer draws into. This can be 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // either the same layer (draw_properties_.render_target == this) or an 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ancestor of this layer. 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LayerType* render_target; 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The surface that this layer and its subtree would contribute to. 778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) scoped_ptr<typename LayerType::RenderSurfaceType> render_surface; 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This rect is in the layer's content space. 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect visible_content_rect; 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // In target surface space, the rect that encloses the clipped, drawable 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // content of the layer. 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect drawable_content_rect; 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // In target surface space, the original rect that clipped this layer. This 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // value is used to avoid unnecessarily changing GL scissor state. 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect clip_rect; 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The scale used to move between layer space and content space, and bounds 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // of the space. One is always a function of the other, but which one 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // depends on the layer type. For picture layers, this is an ideal scale, 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and not always the one used. 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float contents_scale_x; 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float contents_scale_y; 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Size content_bounds; 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 98424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Number of descendants with a clip parent that is our ancestor. NB - this 99424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // does not include our clip children because they are clipped by us. 100424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) int num_unclipped_descendants; 101424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 1027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // If true, the layer or some layer in its sub-tree has a CopyOutputRequest 1037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // present on it. 1047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch bool layer_or_descendant_has_copy_request; 1058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 106f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // If true, the layer or one of its descendants has a wheel or touch handler. 107f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) bool layer_or_descendant_has_input_handler; 108f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // This is true if the layer has any direct child that has a scroll parent. 1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // This layer will not be the scroll parent in this case. This information 1118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our 1128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // children have scroll parents, we will not need to recur out of order. 1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) bool has_child_with_a_scroll_parent; 1148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // This is true if the order (wrt to its siblings in the tree) in which the 1168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // layer will be visited while computing draw properties has been determined. 1178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) bool sorted_for_recursion; 1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // If this layer is visited out of order, its contribution to the descendant 1208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // and render surface layer lists will be put aside in a temporary list. 1218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // These values will allow for an efficient reordering of these additions. 1228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) size_t index_of_first_descendants_addition; 1238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) size_t num_descendants_added; 1248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) size_t index_of_first_render_surface_layer_list_addition; 1258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) size_t num_render_surfaces_added; 1260de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) 1270de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) // Each time we generate a new render surface layer list, an ID is used to 1280de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) // identify it. |last_drawn_render_surface_layer_list_id| is set to the ID 1290de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) // that marked the render surface layer list generation which last updated 1300de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) // these draw properties and determined that this layer will draw itself. 1310de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) // If these draw properties are not a part of the render surface layer list, 1320de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) // or the layer doesn't contribute anything, then this ID will be either out 1330de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) // of date or 0. 1340de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) int last_drawn_render_surface_layer_list_id; 135f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 136f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // The scale at which content for the layer should be rastered in order to be 137f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // perfectly crisp. 138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) float ideal_contents_scale; 139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 140f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // The maximum scale during the layers current animation at which content 141f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // should be rastered at to be crisp. 142f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) float maximum_animation_contents_scale; 143f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 144f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // The page scale factor that is applied to the layer. Since some layers may 145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // have page scale applied and others not, this may differ between layers. 146f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) float page_scale_factor; 147f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 148f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // The device scale factor that is applied to the layer. 149f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) float device_scale_factor; 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace cc 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CC_LAYERS_DRAW_PROPERTIES_H_ 155