[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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. |
| 4 | |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 7 | #include "cc/animation/layer_animation_controller.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 8 | #include "cc/base/math_util.h" |
| 9 | #include "cc/base/thread.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 10 | #include "cc/layers/content_layer.h" |
| 11 | #include "cc/layers/content_layer_client.h" |
| 12 | #include "cc/layers/heads_up_display_layer_impl.h" |
| 13 | #include "cc/layers/layer.h" |
| 14 | #include "cc/layers/layer_impl.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 15 | #include "cc/layers/render_surface.h" |
| 16 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 17 | #include "cc/test/animation_test_common.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 18 | #include "cc/test/fake_impl_proxy.h" |
| 19 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 20 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 21 | #include "cc/trees/layer_tree_impl.h" |
| 22 | #include "cc/trees/proxy.h" |
| 23 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 24 | #include "testing/gmock/include/gmock/gmock.h" |
| 25 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 93698c1 | 2012-12-07 00:43:56 | [diff] [blame] | 26 | #include "ui/gfx/quad_f.h" |
| 27 | #include "ui/gfx/size_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 28 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 29 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 30 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 31 | namespace { |
| 32 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 33 | template <typename LayerType> |
| 34 | void SetLayerPropertiesForTestingInternal( |
| 35 | LayerType* layer, |
| 36 | const gfx::Transform& transform, |
| 37 | const gfx::Transform& sublayer_transform, |
| 38 | gfx::PointF anchor, |
| 39 | gfx::PointF position, |
| 40 | gfx::Size bounds, |
| 41 | bool preserves3d) { |
| 42 | layer->SetTransform(transform); |
| 43 | layer->SetSublayerTransform(sublayer_transform); |
| 44 | layer->SetAnchorPoint(anchor); |
| 45 | layer->SetPosition(position); |
| 46 | layer->SetBounds(bounds); |
| 47 | layer->SetPreserves3d(preserves3d); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 50 | void SetLayerPropertiesForTesting(Layer* layer, |
| 51 | const gfx::Transform& transform, |
| 52 | const gfx::Transform& sublayer_transform, |
| 53 | gfx::PointF anchor, |
| 54 | gfx::PointF position, |
| 55 | gfx::Size bounds, |
| 56 | bool preserves3d) { |
| 57 | SetLayerPropertiesForTestingInternal<Layer>(layer, |
| 58 | transform, |
| 59 | sublayer_transform, |
| 60 | anchor, |
| 61 | position, |
| 62 | bounds, |
| 63 | preserves3d); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 64 | } |
| 65 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 66 | void SetLayerPropertiesForTesting(LayerImpl* layer, |
| 67 | const gfx::Transform& transform, |
| 68 | const gfx::Transform& sublayer_transform, |
| 69 | gfx::PointF anchor, |
| 70 | gfx::PointF position, |
| 71 | gfx::Size bounds, |
| 72 | bool preserves3d) { |
| 73 | SetLayerPropertiesForTestingInternal<LayerImpl>(layer, |
| 74 | transform, |
| 75 | sublayer_transform, |
| 76 | anchor, |
| 77 | position, |
| 78 | bounds, |
| 79 | preserves3d); |
| 80 | layer->SetContentBounds(bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 81 | } |
| 82 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 83 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 84 | float device_scale_factor, |
| 85 | float page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 86 | Layer* page_scale_application_layer, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 87 | bool can_use_lcd_text) { |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 88 | EXPECT_TRUE(page_scale_application_layer || (page_scale_factor == 1.f)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 89 | gfx::Transform identity_matrix; |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 90 | LayerList dummy_render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 91 | int dummy_max_texture_size = 512; |
| 92 | gfx::Size device_viewport_size = |
| 93 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 94 | root_layer->bounds().height() * device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 95 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 96 | // We are probably not testing what is intended if the root_layer bounds are |
| 97 | // empty. |
| 98 | DCHECK(!root_layer->bounds().IsEmpty()); |
| 99 | LayerTreeHostCommon::CalculateDrawProperties( |
| 100 | root_layer, |
| 101 | device_viewport_size, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 102 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 103 | device_scale_factor, |
| 104 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 105 | page_scale_application_layer, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 106 | dummy_max_texture_size, |
| 107 | can_use_lcd_text, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 108 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 109 | &dummy_render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 110 | } |
| 111 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 112 | void ExecuteCalculateDrawProperties(LayerImpl* root_layer, |
| 113 | float device_scale_factor, |
| 114 | float page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 115 | LayerImpl* page_scale_application_layer, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 116 | bool can_use_lcd_text) { |
| 117 | gfx::Transform identity_matrix; |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 118 | LayerImplList dummy_render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 119 | int dummy_max_texture_size = 512; |
| 120 | gfx::Size device_viewport_size = |
| 121 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 122 | root_layer->bounds().height() * device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 123 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 124 | // We are probably not testing what is intended if the root_layer bounds are |
| 125 | // empty. |
| 126 | DCHECK(!root_layer->bounds().IsEmpty()); |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 127 | LayerTreeHostCommon::CalculateDrawProperties( |
| 128 | root_layer, |
| 129 | device_viewport_size, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 130 | gfx::Transform(), |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 131 | device_scale_factor, |
| 132 | page_scale_factor, |
| 133 | page_scale_application_layer, |
| 134 | dummy_max_texture_size, |
| 135 | can_use_lcd_text, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 136 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 137 | &dummy_render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 138 | } |
| 139 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 140 | template <class LayerType> |
| 141 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 142 | LayerType* page_scale_application_layer = NULL; |
| 143 | ExecuteCalculateDrawProperties( |
| 144 | root_layer, 1.f, 1.f, page_scale_application_layer, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 145 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 146 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 147 | template <class LayerType> |
| 148 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 149 | float device_scale_factor) { |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 150 | LayerType* page_scale_application_layer = NULL; |
| 151 | ExecuteCalculateDrawProperties(root_layer, |
| 152 | device_scale_factor, |
| 153 | 1.f, |
| 154 | page_scale_application_layer, |
| 155 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 156 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 157 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 158 | template <class LayerType> |
| 159 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 160 | float device_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 161 | float page_scale_factor, |
| 162 | LayerType* page_scale_application_layer) { |
| 163 | ExecuteCalculateDrawProperties(root_layer, |
| 164 | device_scale_factor, |
| 165 | page_scale_factor, |
| 166 | page_scale_application_layer, |
| 167 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 168 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 169 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 170 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 171 | public: |
| 172 | LayerWithForcedDrawsContent() : Layer() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 173 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 174 | virtual bool DrawsContent() const OVERRIDE; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 175 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 176 | private: |
| 177 | virtual ~LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 178 | }; |
| 179 | |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 180 | class LayerCanClipSelf : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 181 | public: |
| 182 | LayerCanClipSelf() : Layer() {} |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 183 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 184 | virtual bool DrawsContent() const OVERRIDE; |
| 185 | virtual bool CanClipSelf() const OVERRIDE; |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 186 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 187 | private: |
| 188 | virtual ~LayerCanClipSelf() {} |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 189 | }; |
| 190 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 191 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 192 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 193 | bool LayerCanClipSelf::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 194 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 195 | bool LayerCanClipSelf::CanClipSelf() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 196 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 197 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 198 | public: |
| 199 | MockContentLayerClient() {} |
| 200 | virtual ~MockContentLayerClient() {} |
| 201 | virtual void PaintContents(SkCanvas* canvas, |
| 202 | gfx::Rect clip, |
| 203 | gfx::RectF* opaque) OVERRIDE {} |
| 204 | virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 205 | }; |
| 206 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 207 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 208 | ContentLayerClient* delegate) { |
| 209 | scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 210 | to_return->SetIsDrawable(true); |
| 211 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 212 | } |
| 213 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 214 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 215 | do { \ |
| 216 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 217 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 218 | } while (false) |
| 219 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 220 | TEST(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
| 221 | // Sanity check: For layers positioned at zero, with zero size, |
| 222 | // and with identity transforms, then the draw transform, |
| 223 | // screen space transform, and the hierarchy passed on to children |
| 224 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 225 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 226 | scoped_refptr<Layer> parent = Layer::Create(); |
| 227 | scoped_refptr<Layer> child = Layer::Create(); |
| 228 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 229 | parent->AddChild(child); |
| 230 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 231 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 232 | gfx::Transform identity_matrix; |
| 233 | SetLayerPropertiesForTesting(parent.get(), |
| 234 | identity_matrix, |
| 235 | identity_matrix, |
| 236 | gfx::PointF(), |
| 237 | gfx::PointF(), |
| 238 | gfx::Size(100, 100), |
| 239 | false); |
| 240 | SetLayerPropertiesForTesting(child.get(), |
| 241 | identity_matrix, |
| 242 | identity_matrix, |
| 243 | gfx::PointF(), |
| 244 | gfx::PointF(), |
| 245 | gfx::Size(), |
| 246 | false); |
| 247 | SetLayerPropertiesForTesting(grand_child.get(), |
| 248 | identity_matrix, |
| 249 | identity_matrix, |
| 250 | gfx::PointF(), |
| 251 | gfx::PointF(), |
| 252 | gfx::Size(), |
| 253 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 254 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 255 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 256 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 257 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 258 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 259 | child->screen_space_transform()); |
| 260 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 261 | grand_child->draw_transform()); |
| 262 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 263 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 264 | } |
| 265 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 266 | TEST(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
| 267 | gfx::Transform identity_matrix; |
| 268 | scoped_refptr<Layer> layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 269 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 270 | scoped_refptr<Layer> root = Layer::Create(); |
| 271 | SetLayerPropertiesForTesting(root.get(), |
| 272 | identity_matrix, |
| 273 | identity_matrix, |
| 274 | gfx::PointF(), |
| 275 | gfx::PointF(), |
| 276 | gfx::Size(1, 2), |
| 277 | false); |
| 278 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 279 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 280 | // Case 1: setting the sublayer transform should not affect this layer's draw |
| 281 | // transform or screen-space transform. |
| 282 | gfx::Transform arbitrary_translation; |
| 283 | arbitrary_translation.Translate(10.0, 20.0); |
| 284 | SetLayerPropertiesForTesting(layer.get(), |
| 285 | identity_matrix, |
| 286 | arbitrary_translation, |
| 287 | gfx::PointF(), |
| 288 | gfx::PointF(), |
| 289 | gfx::Size(100, 100), |
| 290 | false); |
| 291 | ExecuteCalculateDrawProperties(root.get()); |
| 292 | gfx::Transform expected_draw_transform = identity_matrix; |
| 293 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 294 | layer->draw_transform()); |
| 295 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 296 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 297 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 298 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 299 | // transform or the screenspace transform. |
| 300 | gfx::Transform translation_to_center; |
| 301 | translation_to_center.Translate(5.0, 6.0); |
| 302 | SetLayerPropertiesForTesting(layer.get(), |
| 303 | identity_matrix, |
| 304 | identity_matrix, |
| 305 | gfx::PointF(), |
| 306 | gfx::PointF(), |
| 307 | gfx::Size(10, 12), |
| 308 | false); |
| 309 | ExecuteCalculateDrawProperties(root.get()); |
| 310 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 311 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 312 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 313 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 314 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 315 | // no effect on the transforms. |
| 316 | SetLayerPropertiesForTesting(layer.get(), |
| 317 | identity_matrix, |
| 318 | identity_matrix, |
| 319 | gfx::PointF(0.25f, 0.25f), |
| 320 | gfx::PointF(), |
| 321 | gfx::Size(10, 12), |
| 322 | false); |
| 323 | ExecuteCalculateDrawProperties(root.get()); |
| 324 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 325 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 326 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 327 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 328 | // Case 4: A change in actual position affects both the draw transform and |
| 329 | // screen space transform. |
| 330 | gfx::Transform position_transform; |
| 331 | position_transform.Translate(0.0, 1.2); |
| 332 | SetLayerPropertiesForTesting(layer.get(), |
| 333 | identity_matrix, |
| 334 | identity_matrix, |
| 335 | gfx::PointF(0.25f, 0.25f), |
| 336 | gfx::PointF(0.f, 1.2f), |
| 337 | gfx::Size(10, 12), |
| 338 | false); |
| 339 | ExecuteCalculateDrawProperties(root.get()); |
| 340 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 341 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 342 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 343 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 344 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 345 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 346 | // scale transform, because scale and translation are not commutative. |
| 347 | gfx::Transform layer_transform; |
| 348 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 349 | SetLayerPropertiesForTesting(layer.get(), |
| 350 | layer_transform, |
| 351 | identity_matrix, |
| 352 | gfx::PointF(), |
| 353 | gfx::PointF(), |
| 354 | gfx::Size(10, 12), |
| 355 | false); |
| 356 | ExecuteCalculateDrawProperties(root.get()); |
| 357 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 358 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 359 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 360 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 361 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 362 | gfx::Transform translation_to_anchor; |
| 363 | translation_to_anchor.Translate(5.0, 0.0); |
| 364 | gfx::Transform expected_result = |
| 365 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 366 | SetLayerPropertiesForTesting(layer.get(), |
| 367 | layer_transform, |
| 368 | identity_matrix, |
| 369 | gfx::PointF(0.5f, 0.f), |
| 370 | gfx::PointF(), |
| 371 | gfx::Size(10, 12), |
| 372 | false); |
| 373 | ExecuteCalculateDrawProperties(root.get()); |
| 374 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 375 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 376 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 377 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 378 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 379 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 380 | // it is still worth testing to detect accidental regressions. |
| 381 | expected_result = position_transform * translation_to_anchor * |
| 382 | layer_transform * Inverse(translation_to_anchor); |
| 383 | SetLayerPropertiesForTesting(layer.get(), |
| 384 | layer_transform, |
| 385 | identity_matrix, |
| 386 | gfx::PointF(0.5f, 0.f), |
| 387 | gfx::PointF(0.f, 1.2f), |
| 388 | gfx::Size(10, 12), |
| 389 | false); |
| 390 | ExecuteCalculateDrawProperties(root.get()); |
| 391 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 392 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 393 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 396 | TEST(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
| 397 | const gfx::Vector2d kScrollOffset(50, 100); |
| 398 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
| 399 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 400 | -kScrollOffset.y()); |
| 401 | const float kPageScale = 0.888f; |
| 402 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 403 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 404 | FakeImplProxy proxy; |
| 405 | FakeLayerTreeHostImpl host_impl(&proxy); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 406 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 407 | gfx::Transform identity_matrix; |
| 408 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 409 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 410 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 411 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 412 | kPageScale * kDeviceScale); |
| 413 | SetLayerPropertiesForTesting(sublayer, |
| 414 | identity_matrix, |
| 415 | identity_matrix, |
| 416 | gfx::Point(), |
| 417 | gfx::PointF(), |
| 418 | gfx::Size(500, 500), |
| 419 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 420 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 421 | scoped_ptr<LayerImpl> scroll_layerScopedPtr( |
| 422 | LayerImpl::Create(host_impl.active_tree(), 2)); |
| 423 | LayerImpl* scroll_layer = scroll_layerScopedPtr.get(); |
| 424 | SetLayerPropertiesForTesting(scroll_layer, |
| 425 | identity_matrix, |
| 426 | identity_matrix, |
| 427 | gfx::PointF(), |
| 428 | kScrollLayerPosition, |
| 429 | gfx::Size(10, 20), |
| 430 | false); |
| 431 | scroll_layer->SetScrollable(true); |
| 432 | scroll_layer->SetScrollOffset(kScrollOffset); |
| 433 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 434 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 435 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 436 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 437 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
| 438 | SetLayerPropertiesForTesting(root.get(), |
| 439 | identity_matrix, |
| 440 | identity_matrix, |
| 441 | gfx::PointF(), |
| 442 | gfx::PointF(), |
| 443 | gfx::Size(3, 4), |
| 444 | false); |
| 445 | root->AddChild(scroll_layerScopedPtr.Pass()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 446 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 447 | ExecuteCalculateDrawProperties( |
| 448 | root.get(), kDeviceScale, kPageScale, scroll_layer); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 449 | gfx::Transform expected_transform = identity_matrix; |
| 450 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 451 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 452 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 453 | MathUtil::Round(sub_layer_screen_position.y())); |
| 454 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 455 | sublayer->draw_transform()); |
| 456 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 457 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 458 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 459 | gfx::Transform arbitrary_translate; |
| 460 | const float kTranslateX = 10.6f; |
| 461 | const float kTranslateY = 20.6f; |
| 462 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
| 463 | SetLayerPropertiesForTesting(scroll_layer, |
| 464 | arbitrary_translate, |
| 465 | identity_matrix, |
| 466 | gfx::PointF(), |
| 467 | kScrollLayerPosition, |
| 468 | gfx::Size(10, 20), |
| 469 | false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 470 | ExecuteCalculateDrawProperties( |
| 471 | root.get(), kDeviceScale, kPageScale, scroll_layer); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 472 | expected_transform.MakeIdentity(); |
| 473 | expected_transform.Translate( |
| 474 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 475 | sub_layer_screen_position.x()), |
| 476 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 477 | sub_layer_screen_position.y())); |
| 478 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 479 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 480 | } |
| 481 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 482 | TEST(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
| 483 | gfx::Transform identity_matrix; |
| 484 | scoped_refptr<Layer> root = Layer::Create(); |
| 485 | scoped_refptr<Layer> parent = Layer::Create(); |
| 486 | scoped_refptr<Layer> child = Layer::Create(); |
| 487 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 488 | root->AddChild(parent); |
| 489 | parent->AddChild(child); |
| 490 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 491 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 492 | // One-time setup of root layer |
| 493 | SetLayerPropertiesForTesting(root.get(), |
| 494 | identity_matrix, |
| 495 | identity_matrix, |
| 496 | gfx::PointF(), |
| 497 | gfx::PointF(), |
| 498 | gfx::Size(1, 2), |
| 499 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 500 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 501 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 502 | SetLayerPropertiesForTesting(parent.get(), |
| 503 | identity_matrix, |
| 504 | identity_matrix, |
| 505 | gfx::PointF(0.25f, 0.25f), |
| 506 | gfx::PointF(), |
| 507 | gfx::Size(10, 12), |
| 508 | false); |
| 509 | SetLayerPropertiesForTesting(child.get(), |
| 510 | identity_matrix, |
| 511 | identity_matrix, |
| 512 | gfx::PointF(), |
| 513 | gfx::PointF(), |
| 514 | gfx::Size(16, 18), |
| 515 | false); |
| 516 | SetLayerPropertiesForTesting(grand_child.get(), |
| 517 | identity_matrix, |
| 518 | identity_matrix, |
| 519 | gfx::PointF(), |
| 520 | gfx::PointF(), |
| 521 | gfx::Size(76, 78), |
| 522 | false); |
| 523 | ExecuteCalculateDrawProperties(root.get()); |
| 524 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 525 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 526 | child->screen_space_transform()); |
| 527 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 528 | grand_child->draw_transform()); |
| 529 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 530 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 531 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 532 | // Case 2: parent's position affects child and grand_child. |
| 533 | gfx::Transform parent_position_transform; |
| 534 | parent_position_transform.Translate(0.0, 1.2); |
| 535 | SetLayerPropertiesForTesting(parent.get(), |
| 536 | identity_matrix, |
| 537 | identity_matrix, |
| 538 | gfx::PointF(0.25f, 0.25f), |
| 539 | gfx::PointF(0.f, 1.2f), |
| 540 | gfx::Size(10, 12), |
| 541 | false); |
| 542 | SetLayerPropertiesForTesting(child.get(), |
| 543 | identity_matrix, |
| 544 | identity_matrix, |
| 545 | gfx::PointF(), |
| 546 | gfx::PointF(), |
| 547 | gfx::Size(16, 18), |
| 548 | false); |
| 549 | SetLayerPropertiesForTesting(grand_child.get(), |
| 550 | identity_matrix, |
| 551 | identity_matrix, |
| 552 | gfx::PointF(), |
| 553 | gfx::PointF(), |
| 554 | gfx::Size(76, 78), |
| 555 | false); |
| 556 | ExecuteCalculateDrawProperties(root.get()); |
| 557 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 558 | child->draw_transform()); |
| 559 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 560 | child->screen_space_transform()); |
| 561 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 562 | grand_child->draw_transform()); |
| 563 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 564 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 565 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 566 | // Case 3: parent's local transform affects child and grandchild |
| 567 | gfx::Transform parent_layer_transform; |
| 568 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 569 | gfx::Transform parent_translation_to_anchor; |
| 570 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 571 | gfx::Transform parent_composite_transform = |
| 572 | parent_translation_to_anchor * parent_layer_transform * |
| 573 | Inverse(parent_translation_to_anchor); |
| 574 | SetLayerPropertiesForTesting(parent.get(), |
| 575 | parent_layer_transform, |
| 576 | identity_matrix, |
| 577 | gfx::PointF(0.25f, 0.25f), |
| 578 | gfx::PointF(), |
| 579 | gfx::Size(10, 12), |
| 580 | false); |
| 581 | SetLayerPropertiesForTesting(child.get(), |
| 582 | identity_matrix, |
| 583 | identity_matrix, |
| 584 | gfx::PointF(), |
| 585 | gfx::PointF(), |
| 586 | gfx::Size(16, 18), |
| 587 | false); |
| 588 | SetLayerPropertiesForTesting(grand_child.get(), |
| 589 | identity_matrix, |
| 590 | identity_matrix, |
| 591 | gfx::PointF(), |
| 592 | gfx::PointF(), |
| 593 | gfx::Size(76, 78), |
| 594 | false); |
| 595 | ExecuteCalculateDrawProperties(root.get()); |
| 596 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 597 | child->draw_transform()); |
| 598 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 599 | child->screen_space_transform()); |
| 600 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 601 | grand_child->draw_transform()); |
| 602 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 603 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 604 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 605 | // Case 4: parent's sublayer matrix affects child and grandchild scaling is |
| 606 | // used here again so that the correct sequence of transforms is properly |
| 607 | // tested. Note that preserves3d is false, but the sublayer matrix should |
| 608 | // retain its 3D properties when given to child. But then, the child also |
| 609 | // does not preserve3D. When it gives its hierarchy to the grand_child, it |
| 610 | // should be flattened to 2D. |
| 611 | gfx::Transform parent_sublayer_matrix; |
| 612 | parent_sublayer_matrix.Scale3d(10.0, 10.0, 3.3); |
| 613 | // Sublayer matrix is applied to the anchor point of the parent layer. |
| 614 | parent_composite_transform = |
| 615 | parent_translation_to_anchor * parent_layer_transform * |
| 616 | Inverse(parent_translation_to_anchor) * parent_translation_to_anchor * |
| 617 | parent_sublayer_matrix * Inverse(parent_translation_to_anchor); |
| 618 | gfx::Transform flattened_composite_transform = parent_composite_transform; |
| 619 | flattened_composite_transform.FlattenTo2d(); |
| 620 | SetLayerPropertiesForTesting(parent.get(), |
| 621 | parent_layer_transform, |
| 622 | parent_sublayer_matrix, |
| 623 | gfx::PointF(0.25f, 0.25f), |
| 624 | gfx::PointF(), |
| 625 | gfx::Size(10, 12), |
| 626 | false); |
| 627 | SetLayerPropertiesForTesting(child.get(), |
| 628 | identity_matrix, |
| 629 | identity_matrix, |
| 630 | gfx::PointF(), |
| 631 | gfx::PointF(), |
| 632 | gfx::Size(16, 18), |
| 633 | false); |
| 634 | SetLayerPropertiesForTesting(grand_child.get(), |
| 635 | identity_matrix, |
| 636 | identity_matrix, |
| 637 | gfx::PointF(), |
| 638 | gfx::PointF(), |
| 639 | gfx::Size(76, 78), |
| 640 | false); |
| 641 | ExecuteCalculateDrawProperties(root.get()); |
| 642 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 643 | child->draw_transform()); |
| 644 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 645 | child->screen_space_transform()); |
| 646 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_composite_transform, |
| 647 | grand_child->draw_transform()); |
| 648 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_composite_transform, |
| 649 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 650 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 651 | // Case 5: same as Case 4, except that child does preserve 3D, so the |
| 652 | // grand_child should receive the non-flattened composite transform. |
| 653 | SetLayerPropertiesForTesting(parent.get(), |
| 654 | parent_layer_transform, |
| 655 | parent_sublayer_matrix, |
| 656 | gfx::PointF(0.25f, 0.25f), |
| 657 | gfx::PointF(), |
| 658 | gfx::Size(10, 12), |
| 659 | false); |
| 660 | SetLayerPropertiesForTesting(child.get(), |
| 661 | identity_matrix, |
| 662 | identity_matrix, |
| 663 | gfx::PointF(), |
| 664 | gfx::PointF(), |
| 665 | gfx::Size(16, 18), |
| 666 | true); |
| 667 | SetLayerPropertiesForTesting(grand_child.get(), |
| 668 | identity_matrix, |
| 669 | identity_matrix, |
| 670 | gfx::PointF(), |
| 671 | gfx::PointF(), |
| 672 | gfx::Size(76, 78), |
| 673 | false); |
| 674 | ExecuteCalculateDrawProperties(root.get()); |
| 675 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 676 | child->draw_transform()); |
| 677 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 678 | child->screen_space_transform()); |
| 679 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 680 | grand_child->draw_transform()); |
| 681 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 682 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 683 | } |
| 684 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 685 | TEST(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
| 686 | scoped_refptr<Layer> root = Layer::Create(); |
| 687 | scoped_refptr<Layer> parent = Layer::Create(); |
| 688 | scoped_refptr<Layer> child = Layer::Create(); |
| 689 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 690 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 691 | root->AddChild(parent); |
| 692 | parent->AddChild(child); |
| 693 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 694 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 695 | // One-time setup of root layer |
| 696 | gfx::Transform identity_matrix; |
| 697 | SetLayerPropertiesForTesting(root.get(), |
| 698 | identity_matrix, |
| 699 | identity_matrix, |
| 700 | gfx::PointF(), |
| 701 | gfx::PointF(), |
| 702 | gfx::Size(1, 2), |
| 703 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 704 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 705 | // Child is set up so that a new render surface should be created. |
| 706 | child->SetOpacity(0.5f); |
| 707 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 708 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 709 | gfx::Transform parent_layer_transform; |
| 710 | parent_layer_transform.Scale3d(1.0, 0.9, 1.0); |
| 711 | gfx::Transform parent_translation_to_anchor; |
| 712 | parent_translation_to_anchor.Translate(25.0, 30.0); |
| 713 | gfx::Transform parent_sublayer_matrix; |
| 714 | parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 715 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 716 | gfx::Transform parent_composite_transform = |
| 717 | parent_translation_to_anchor * parent_layer_transform * |
| 718 | Inverse(parent_translation_to_anchor) * parent_translation_to_anchor * |
| 719 | parent_sublayer_matrix * Inverse(parent_translation_to_anchor); |
| 720 | gfx::Vector2dF parent_composite_scale = |
| 721 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 722 | 1.f); |
| 723 | gfx::Transform surface_sublayer_transform; |
| 724 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 725 | parent_composite_scale.y()); |
| 726 | gfx::Transform surface_sublayer_composite_transform = |
| 727 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 728 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 729 | // Child's render surface should not exist yet. |
| 730 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 731 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 732 | SetLayerPropertiesForTesting(parent.get(), |
| 733 | parent_layer_transform, |
| 734 | parent_sublayer_matrix, |
| 735 | gfx::PointF(0.25f, 0.25f), |
| 736 | gfx::PointF(), |
| 737 | gfx::Size(100, 120), |
| 738 | false); |
| 739 | SetLayerPropertiesForTesting(child.get(), |
| 740 | identity_matrix, |
| 741 | identity_matrix, |
| 742 | gfx::PointF(), |
| 743 | gfx::PointF(), |
| 744 | gfx::Size(16, 18), |
| 745 | false); |
| 746 | SetLayerPropertiesForTesting(grand_child.get(), |
| 747 | identity_matrix, |
| 748 | identity_matrix, |
| 749 | gfx::PointF(), |
| 750 | gfx::PointF(), |
| 751 | gfx::Size(8, 10), |
| 752 | false); |
| 753 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 754 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 755 | // Render surface should have been created now. |
| 756 | ASSERT_TRUE(child->render_surface()); |
| 757 | ASSERT_EQ(child, child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 758 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 759 | // The child layer's draw transform should refer to its new render surface. |
| 760 | // The screen-space transform, however, should still refer to the root. |
| 761 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 762 | child->draw_transform()); |
| 763 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 764 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 765 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 766 | // Because the grand_child is the only drawable content, the child's render |
| 767 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 768 | // surface's subtree is drawn must be removed from the composite transform. |
| 769 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 770 | surface_sublayer_composite_transform, |
| 771 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 772 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 773 | // The screen space is the same as the target since the child surface draws |
| 774 | // into the root. |
| 775 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 776 | surface_sublayer_composite_transform, |
| 777 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 778 | } |
| 779 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 780 | TEST(LayerTreeHostCommonTest, SublayerTransformWithAnchorPoint) { |
| 781 | // crbug.com/157961 - we were always applying the sublayer transform about |
| 782 | // the center of the layer, rather than the anchor point. |
[email protected] | 9a3e6b7 | 2013-02-12 18:31:21 | [diff] [blame] | 783 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 784 | scoped_refptr<Layer> root = Layer::Create(); |
| 785 | scoped_refptr<Layer> parent = Layer::Create(); |
| 786 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 787 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 788 | root->AddChild(parent); |
| 789 | parent->AddChild(child); |
[email protected] | 9a3e6b7 | 2013-02-12 18:31:21 | [diff] [blame] | 790 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 791 | gfx::Transform identity_matrix; |
| 792 | gfx::Transform parent_sublayer_matrix; |
| 793 | parent_sublayer_matrix.ApplyPerspectiveDepth(2.0); |
| 794 | gfx::PointF parent_anchor_point(0.2f, 0.8f); |
[email protected] | 9a3e6b7 | 2013-02-12 18:31:21 | [diff] [blame] | 795 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 796 | SetLayerPropertiesForTesting(root.get(), |
| 797 | identity_matrix, |
| 798 | identity_matrix, |
| 799 | gfx::PointF(), |
| 800 | gfx::PointF(), |
| 801 | gfx::Size(1, 2), |
| 802 | false); |
| 803 | SetLayerPropertiesForTesting(parent.get(), |
| 804 | identity_matrix, |
| 805 | parent_sublayer_matrix, |
| 806 | parent_anchor_point, |
| 807 | gfx::PointF(), |
| 808 | gfx::Size(100, 100), |
| 809 | false); |
| 810 | SetLayerPropertiesForTesting(child.get(), |
| 811 | identity_matrix, |
| 812 | identity_matrix, |
| 813 | gfx::PointF(), |
| 814 | gfx::PointF(), |
| 815 | gfx::Size(10, 10), |
| 816 | false); |
| 817 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 9a3e6b7 | 2013-02-12 18:31:21 | [diff] [blame] | 818 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 819 | gfx::Transform expected_child_draw_transform; |
| 820 | expected_child_draw_transform.Translate(20.0, 80.0); |
| 821 | expected_child_draw_transform.ApplyPerspectiveDepth(2.0); |
| 822 | expected_child_draw_transform.Translate(-20.0, -80.0); |
| 823 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 824 | child->draw_transform()); |
[email protected] | 9a3e6b7 | 2013-02-12 18:31:21 | [diff] [blame] | 825 | } |
| 826 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 827 | TEST(LayerTreeHostCommonTest, SeparateRenderTargetRequirementWithClipping) { |
| 828 | scoped_refptr<Layer> root = Layer::Create(); |
| 829 | scoped_refptr<Layer> parent = Layer::Create(); |
| 830 | scoped_refptr<Layer> child = Layer::Create(); |
| 831 | scoped_refptr<Layer> grand_child = make_scoped_refptr(new LayerCanClipSelf()); |
| 832 | root->AddChild(parent); |
| 833 | parent->AddChild(child); |
| 834 | child->AddChild(grand_child); |
| 835 | parent->SetMasksToBounds(true); |
| 836 | child->SetMasksToBounds(true); |
[email protected] | 9a3e6b7 | 2013-02-12 18:31:21 | [diff] [blame] | 837 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 838 | gfx::Transform identity_matrix; |
| 839 | gfx::Transform parent_layer_transform; |
| 840 | gfx::Transform parent_sublayer_matrix; |
| 841 | gfx::Transform child_layer_matrix; |
| 842 | |
| 843 | // No render surface should exist yet. |
| 844 | EXPECT_FALSE(root->render_surface()); |
| 845 | EXPECT_FALSE(parent->render_surface()); |
| 846 | EXPECT_FALSE(child->render_surface()); |
| 847 | EXPECT_FALSE(grand_child->render_surface()); |
| 848 | |
| 849 | // One-time setup of root layer |
| 850 | parent_layer_transform.Scale3d(1.0, 0.9, 1.0); |
| 851 | parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3); |
| 852 | child_layer_matrix.Rotate(20.0); |
| 853 | |
| 854 | SetLayerPropertiesForTesting(root.get(), |
| 855 | identity_matrix, |
| 856 | identity_matrix, |
| 857 | gfx::PointF(), |
| 858 | gfx::PointF(), |
| 859 | gfx::Size(1, 2), |
| 860 | false); |
| 861 | SetLayerPropertiesForTesting(parent.get(), |
| 862 | parent_layer_transform, |
| 863 | parent_sublayer_matrix, |
| 864 | gfx::PointF(0.25f, 0.25f), |
| 865 | gfx::PointF(), |
| 866 | gfx::Size(100, 120), |
| 867 | false); |
| 868 | SetLayerPropertiesForTesting(child.get(), |
| 869 | child_layer_matrix, |
| 870 | identity_matrix, |
| 871 | gfx::PointF(), |
| 872 | gfx::PointF(), |
| 873 | gfx::Size(16, 18), |
| 874 | false); |
| 875 | SetLayerPropertiesForTesting(grand_child.get(), |
| 876 | identity_matrix, |
| 877 | identity_matrix, |
| 878 | gfx::PointF(), |
| 879 | gfx::PointF(), |
| 880 | gfx::Size(8, 10), |
| 881 | false); |
| 882 | |
| 883 | ExecuteCalculateDrawProperties(root.get()); |
| 884 | |
| 885 | // Render surfaces should have been created according to clipping rules now |
| 886 | // (grandchild can clip self). |
| 887 | EXPECT_TRUE(root->render_surface()); |
| 888 | EXPECT_FALSE(parent->render_surface()); |
| 889 | EXPECT_FALSE(child->render_surface()); |
| 890 | EXPECT_FALSE(grand_child->render_surface()); |
| 891 | } |
| 892 | |
| 893 | TEST(LayerTreeHostCommonTest, SeparateRenderTargetRequirementWithoutClipping) { |
| 894 | scoped_refptr<Layer> root = Layer::Create(); |
| 895 | scoped_refptr<Layer> parent = Layer::Create(); |
| 896 | scoped_refptr<Layer> child = Layer::Create(); |
| 897 | // This layer cannot clip itself, a feature we are testing here. |
| 898 | scoped_refptr<Layer> grand_child = |
| 899 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 900 | root->AddChild(parent); |
| 901 | parent->AddChild(child); |
| 902 | child->AddChild(grand_child); |
| 903 | parent->SetMasksToBounds(true); |
| 904 | child->SetMasksToBounds(true); |
| 905 | |
| 906 | gfx::Transform identity_matrix; |
| 907 | gfx::Transform parent_layer_transform; |
| 908 | gfx::Transform parent_sublayer_matrix; |
| 909 | gfx::Transform child_layer_matrix; |
| 910 | |
| 911 | // No render surface should exist yet. |
| 912 | EXPECT_FALSE(root->render_surface()); |
| 913 | EXPECT_FALSE(parent->render_surface()); |
| 914 | EXPECT_FALSE(child->render_surface()); |
| 915 | EXPECT_FALSE(grand_child->render_surface()); |
| 916 | |
| 917 | // One-time setup of root layer |
| 918 | parent_layer_transform.Scale3d(1.0, 0.9, 1.0); |
| 919 | parent_sublayer_matrix.Scale3d(0.9, 1.0, 3.3); |
| 920 | child_layer_matrix.Rotate(20.0); |
| 921 | |
| 922 | SetLayerPropertiesForTesting(root.get(), |
| 923 | identity_matrix, |
| 924 | identity_matrix, |
| 925 | gfx::PointF(), |
| 926 | gfx::PointF(), |
| 927 | gfx::Size(1, 2), |
| 928 | false); |
| 929 | SetLayerPropertiesForTesting(parent.get(), |
| 930 | parent_layer_transform, |
| 931 | parent_sublayer_matrix, |
| 932 | gfx::PointF(0.25f, 0.25f), |
| 933 | gfx::PointF(), |
| 934 | gfx::Size(100, 120), |
| 935 | false); |
| 936 | SetLayerPropertiesForTesting(child.get(), |
| 937 | child_layer_matrix, |
| 938 | identity_matrix, |
| 939 | gfx::PointF(), |
| 940 | gfx::PointF(), |
| 941 | gfx::Size(16, 18), |
| 942 | false); |
| 943 | SetLayerPropertiesForTesting(grand_child.get(), |
| 944 | identity_matrix, |
| 945 | identity_matrix, |
| 946 | gfx::PointF(), |
| 947 | gfx::PointF(), |
| 948 | gfx::Size(8, 10), |
| 949 | false); |
| 950 | |
| 951 | ExecuteCalculateDrawProperties(root.get()); |
| 952 | |
| 953 | // Render surfaces should have been created according to clipping rules now |
| 954 | // (grandchild can't clip self). |
| 955 | EXPECT_TRUE(root->render_surface()); |
| 956 | EXPECT_FALSE(parent->render_surface()); |
| 957 | EXPECT_TRUE(child->render_surface()); |
| 958 | EXPECT_FALSE(grand_child->render_surface()); |
| 959 | } |
| 960 | |
| 961 | TEST(LayerTreeHostCommonTest, TransformsForReplica) { |
| 962 | scoped_refptr<Layer> root = Layer::Create(); |
| 963 | scoped_refptr<Layer> parent = Layer::Create(); |
| 964 | scoped_refptr<Layer> child = Layer::Create(); |
| 965 | scoped_refptr<Layer> child_replica = Layer::Create(); |
| 966 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 967 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 968 | root->AddChild(parent); |
| 969 | parent->AddChild(child); |
| 970 | child->AddChild(grand_child); |
| 971 | child->SetReplicaLayer(child_replica.get()); |
| 972 | |
| 973 | // One-time setup of root layer |
| 974 | gfx::Transform identity_matrix; |
| 975 | SetLayerPropertiesForTesting(root.get(), |
| 976 | identity_matrix, |
| 977 | identity_matrix, |
| 978 | gfx::PointF(), |
| 979 | gfx::PointF(), |
| 980 | gfx::Size(1, 2), |
| 981 | false); |
| 982 | |
| 983 | // Child is set up so that a new render surface should be created. |
| 984 | child->SetOpacity(0.5f); |
| 985 | |
| 986 | gfx::Transform parent_layer_transform; |
| 987 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 988 | gfx::Transform parent_translation_to_anchor; |
| 989 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 990 | gfx::Transform parent_sublayer_matrix; |
| 991 | parent_sublayer_matrix.Scale3d(10.0, 10.0, 3.3); |
| 992 | gfx::Transform parent_composite_transform = |
| 993 | parent_translation_to_anchor * parent_layer_transform * |
| 994 | Inverse(parent_translation_to_anchor) * parent_translation_to_anchor * |
| 995 | parent_sublayer_matrix * Inverse(parent_translation_to_anchor); |
| 996 | gfx::Transform replica_layer_transform; |
| 997 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 998 | gfx::Vector2dF parent_composite_scale = |
| 999 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 1000 | 1.f); |
| 1001 | gfx::Transform surface_sublayer_transform; |
| 1002 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 1003 | parent_composite_scale.y()); |
| 1004 | gfx::Transform replica_composite_transform = |
| 1005 | parent_composite_transform * replica_layer_transform * |
| 1006 | Inverse(surface_sublayer_transform); |
| 1007 | |
| 1008 | // Child's render surface should not exist yet. |
| 1009 | ASSERT_FALSE(child->render_surface()); |
| 1010 | |
| 1011 | SetLayerPropertiesForTesting(parent.get(), |
| 1012 | parent_layer_transform, |
| 1013 | parent_sublayer_matrix, |
| 1014 | gfx::PointF(0.25f, 0.25f), |
| 1015 | gfx::PointF(), |
| 1016 | gfx::Size(10, 12), |
| 1017 | false); |
| 1018 | SetLayerPropertiesForTesting(child.get(), |
| 1019 | identity_matrix, |
| 1020 | identity_matrix, |
| 1021 | gfx::PointF(), |
| 1022 | gfx::PointF(), |
| 1023 | gfx::Size(16, 18), |
| 1024 | false); |
| 1025 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1026 | identity_matrix, |
| 1027 | identity_matrix, |
| 1028 | gfx::PointF(), |
| 1029 | gfx::PointF(-0.5f, -0.5f), |
| 1030 | gfx::Size(1, 1), |
| 1031 | false); |
| 1032 | SetLayerPropertiesForTesting(child_replica.get(), |
| 1033 | replica_layer_transform, |
| 1034 | identity_matrix, |
| 1035 | gfx::PointF(), |
| 1036 | gfx::PointF(), |
| 1037 | gfx::Size(), |
| 1038 | false); |
| 1039 | ExecuteCalculateDrawProperties(root.get()); |
| 1040 | |
| 1041 | // Render surface should have been created now. |
| 1042 | ASSERT_TRUE(child->render_surface()); |
| 1043 | ASSERT_EQ(child, child->render_target()); |
| 1044 | |
| 1045 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1046 | replica_composite_transform, |
| 1047 | child->render_target()->render_surface()->replica_draw_transform()); |
| 1048 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
| 1049 | child->render_target()->render_surface() |
| 1050 | ->replica_screen_space_transform()); |
| 1051 | } |
| 1052 | |
| 1053 | TEST(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
| 1054 | // This test creates a more complex tree and verifies it all at once. This |
| 1055 | // covers the following cases: |
| 1056 | // - layers that are described w.r.t. a render surface: should have draw |
| 1057 | // transforms described w.r.t. that surface |
| 1058 | // - A render surface described w.r.t. an ancestor render surface: should |
| 1059 | // have a draw transform described w.r.t. that ancestor surface |
| 1060 | // - Replicas of a render surface are described w.r.t. the replica's |
| 1061 | // transform around its anchor, along with the surface itself. |
| 1062 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 1063 | // a render surface that is described w.r.t. an ancestor render surface. |
| 1064 | // - verifying that each layer has a reference to the correct render surface |
| 1065 | // and render target values. |
| 1066 | |
| 1067 | scoped_refptr<Layer> root = Layer::Create(); |
| 1068 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1069 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1070 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 1071 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 1072 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 1073 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 1074 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); |
| 1075 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); |
| 1076 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 1077 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 1078 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1079 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 1080 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1081 | root->AddChild(parent); |
| 1082 | parent->AddChild(render_surface1); |
| 1083 | parent->AddChild(child_of_root); |
| 1084 | render_surface1->AddChild(child_of_rs1); |
| 1085 | render_surface1->AddChild(render_surface2); |
| 1086 | render_surface2->AddChild(child_of_rs2); |
| 1087 | child_of_root->AddChild(grand_child_of_root); |
| 1088 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 1089 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 1090 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 1091 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 1092 | |
| 1093 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 1094 | // to have a new render surface. |
| 1095 | render_surface1->SetOpacity(0.5f); |
| 1096 | render_surface2->SetOpacity(0.33f); |
| 1097 | |
| 1098 | // One-time setup of root layer |
| 1099 | gfx::Transform identity_matrix; |
| 1100 | SetLayerPropertiesForTesting(root.get(), |
| 1101 | identity_matrix, |
| 1102 | identity_matrix, |
| 1103 | gfx::PointF(), |
| 1104 | gfx::PointF(), |
| 1105 | gfx::Size(1, 2), |
| 1106 | false); |
| 1107 | |
| 1108 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 1109 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
| 1110 | // centered about the anchor point. matrix "B" is the sublayer transform used |
| 1111 | // in all layers, centered about the center position of the layer. matrix "R" |
| 1112 | // is the composite replica transform used in all replica layers. |
| 1113 | // |
| 1114 | // x component tests that layer_transform and sublayer_transform are done in |
| 1115 | // the right order (translation and scale are noncommutative). y component |
| 1116 | // has a translation by 1 for every ancestor, which indicates the "depth" of |
| 1117 | // the layer in the hierarchy. |
| 1118 | gfx::Transform translation_to_anchor; |
| 1119 | translation_to_anchor.Translate(2.5, 0.0); |
| 1120 | gfx::Transform layer_transform; |
| 1121 | layer_transform.Translate(1.0, 1.0); |
| 1122 | gfx::Transform sublayer_transform; |
| 1123 | sublayer_transform.Scale3d(10.0, 1.0, 1.0); |
| 1124 | gfx::Transform replica_layer_transform; |
| 1125 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 1126 | |
| 1127 | gfx::Transform A = |
| 1128 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 1129 | gfx::Transform B = translation_to_anchor * sublayer_transform * |
| 1130 | Inverse(translation_to_anchor); |
| 1131 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 1132 | Inverse(translation_to_anchor); |
| 1133 | |
| 1134 | gfx::Vector2dF surface1_parent_transform_scale = |
| 1135 | MathUtil::ComputeTransform2dScaleComponents(A * B, 1.f); |
| 1136 | gfx::Transform surface1_sublayer_transform; |
| 1137 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 1138 | surface1_parent_transform_scale.y()); |
| 1139 | |
| 1140 | // SS1 = transform given to the subtree of render_surface1 |
| 1141 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 1142 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 1143 | // the owning layer |
| 1144 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 1145 | |
| 1146 | gfx::Vector2dF surface2_parent_transform_scale = |
| 1147 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A * B, 1.f); |
| 1148 | gfx::Transform surface2_sublayer_transform; |
| 1149 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 1150 | surface2_parent_transform_scale.y()); |
| 1151 | |
| 1152 | // SS2 = transform given to the subtree of render_surface2 |
| 1153 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 1154 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 1155 | // the owning layer |
| 1156 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 1157 | |
| 1158 | SetLayerPropertiesForTesting(parent.get(), |
| 1159 | layer_transform, |
| 1160 | sublayer_transform, |
| 1161 | gfx::PointF(0.25f, 0.f), |
| 1162 | gfx::PointF(), |
| 1163 | gfx::Size(10, 10), |
| 1164 | false); |
| 1165 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1166 | layer_transform, |
| 1167 | sublayer_transform, |
| 1168 | gfx::PointF(0.25f, 0.f), |
| 1169 | gfx::PointF(), |
| 1170 | gfx::Size(10, 10), |
| 1171 | false); |
| 1172 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 1173 | layer_transform, |
| 1174 | sublayer_transform, |
| 1175 | gfx::PointF(0.25f, 0.f), |
| 1176 | gfx::PointF(), |
| 1177 | gfx::Size(10, 10), |
| 1178 | false); |
| 1179 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 1180 | layer_transform, |
| 1181 | sublayer_transform, |
| 1182 | gfx::PointF(0.25f, 0.f), |
| 1183 | gfx::PointF(), |
| 1184 | gfx::Size(10, 10), |
| 1185 | false); |
| 1186 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 1187 | layer_transform, |
| 1188 | sublayer_transform, |
| 1189 | gfx::PointF(0.25f, 0.f), |
| 1190 | gfx::PointF(), |
| 1191 | gfx::Size(10, 10), |
| 1192 | false); |
| 1193 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 1194 | layer_transform, |
| 1195 | sublayer_transform, |
| 1196 | gfx::PointF(0.25f, 0.f), |
| 1197 | gfx::PointF(), |
| 1198 | gfx::Size(10, 10), |
| 1199 | false); |
| 1200 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 1201 | layer_transform, |
| 1202 | sublayer_transform, |
| 1203 | gfx::PointF(0.25f, 0.f), |
| 1204 | gfx::PointF(), |
| 1205 | gfx::Size(10, 10), |
| 1206 | false); |
| 1207 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 1208 | layer_transform, |
| 1209 | sublayer_transform, |
| 1210 | gfx::PointF(0.25f, 0.f), |
| 1211 | gfx::PointF(), |
| 1212 | gfx::Size(10, 10), |
| 1213 | false); |
| 1214 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 1215 | layer_transform, |
| 1216 | sublayer_transform, |
| 1217 | gfx::PointF(0.25f, 0.f), |
| 1218 | gfx::PointF(), |
| 1219 | gfx::Size(10, 10), |
| 1220 | false); |
| 1221 | SetLayerPropertiesForTesting(replica_of_rs1.get(), |
| 1222 | replica_layer_transform, |
| 1223 | sublayer_transform, |
| 1224 | gfx::PointF(0.25f, 0.f), |
| 1225 | gfx::PointF(), |
| 1226 | gfx::Size(), |
| 1227 | false); |
| 1228 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 1229 | replica_layer_transform, |
| 1230 | sublayer_transform, |
| 1231 | gfx::PointF(0.25f, 0.f), |
| 1232 | gfx::PointF(), |
| 1233 | gfx::Size(), |
| 1234 | false); |
| 1235 | |
| 1236 | ExecuteCalculateDrawProperties(root.get()); |
| 1237 | |
| 1238 | // Only layers that are associated with render surfaces should have an actual |
| 1239 | // RenderSurface() value. |
| 1240 | ASSERT_TRUE(root->render_surface()); |
| 1241 | ASSERT_FALSE(child_of_root->render_surface()); |
| 1242 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 1243 | |
| 1244 | ASSERT_TRUE(render_surface1->render_surface()); |
| 1245 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 1246 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 1247 | |
| 1248 | ASSERT_TRUE(render_surface2->render_surface()); |
| 1249 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 1250 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 1251 | |
| 1252 | // Verify all render target accessors |
| 1253 | EXPECT_EQ(root, parent->render_target()); |
| 1254 | EXPECT_EQ(root, child_of_root->render_target()); |
| 1255 | EXPECT_EQ(root, grand_child_of_root->render_target()); |
| 1256 | |
| 1257 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 1258 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 1259 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 1260 | |
| 1261 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 1262 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 1263 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 1264 | |
| 1265 | // Verify layer draw transforms note that draw transforms are described with |
| 1266 | // respect to the nearest ancestor render surface but screen space transforms |
| 1267 | // are described with respect to the root. |
| 1268 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
| 1269 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, child_of_root->draw_transform()); |
| 1270 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, |
| 1271 | grand_child_of_root->draw_transform()); |
| 1272 | |
| 1273 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
| 1274 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A, child_of_rs1->draw_transform()); |
| 1275 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A * B * A, |
| 1276 | grand_child_of_rs1->draw_transform()); |
| 1277 | |
| 1278 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
| 1279 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A, child_of_rs2->draw_transform()); |
| 1280 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A * B * A, |
| 1281 | grand_child_of_rs2->draw_transform()); |
| 1282 | |
| 1283 | // Verify layer screen-space transforms |
| 1284 | // |
| 1285 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
| 1286 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, |
| 1287 | child_of_root->screen_space_transform()); |
| 1288 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1289 | A * B * A * B * A, grand_child_of_root->screen_space_transform()); |
| 1290 | |
| 1291 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, |
| 1292 | render_surface1->screen_space_transform()); |
| 1293 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, |
| 1294 | child_of_rs1->screen_space_transform()); |
| 1295 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A, |
| 1296 | grand_child_of_rs1->screen_space_transform()); |
| 1297 | |
| 1298 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, |
| 1299 | render_surface2->screen_space_transform()); |
| 1300 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A, |
| 1301 | child_of_rs2->screen_space_transform()); |
| 1302 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A * B * A, |
| 1303 | grand_child_of_rs2->screen_space_transform()); |
| 1304 | |
| 1305 | // Verify render surface transforms. |
| 1306 | // |
| 1307 | // Draw transform of render surface 1 is described with respect to root. |
| 1308 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1309 | A * B * A * S1, render_surface1->render_surface()->draw_transform()); |
| 1310 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1311 | A * B * R * S1, |
| 1312 | render_surface1->render_surface()->replica_draw_transform()); |
| 1313 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1314 | A * B * A * S1, |
| 1315 | render_surface1->render_surface()->screen_space_transform()); |
| 1316 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1317 | A * B * R * S1, |
| 1318 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 1319 | // Draw transform of render surface 2 is described with respect to render |
| 1320 | // surface 1. |
| 1321 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1322 | SS1 * B * A * S2, render_surface2->render_surface()->draw_transform()); |
| 1323 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1324 | SS1 * B * R * S2, |
| 1325 | render_surface2->render_surface()->replica_draw_transform()); |
| 1326 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1327 | A * B * A * B * A * S2, |
| 1328 | render_surface2->render_surface()->screen_space_transform()); |
| 1329 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1330 | A * B * A * B * R * S2, |
| 1331 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 1332 | |
| 1333 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1334 | // is expected that we correctly set up transforms so that the y-component of |
| 1335 | // the screen-space transform encodes the "depth" of the layer in the tree. |
| 1336 | EXPECT_FLOAT_EQ(1.0, |
| 1337 | parent->screen_space_transform().matrix().getDouble(1, 3)); |
| 1338 | EXPECT_FLOAT_EQ( |
| 1339 | 2.0, child_of_root->screen_space_transform().matrix().getDouble(1, 3)); |
| 1340 | EXPECT_FLOAT_EQ( |
| 1341 | 3.0, |
| 1342 | grand_child_of_root->screen_space_transform().matrix().getDouble(1, 3)); |
| 1343 | |
| 1344 | EXPECT_FLOAT_EQ( |
| 1345 | 2.0, render_surface1->screen_space_transform().matrix().getDouble(1, 3)); |
| 1346 | EXPECT_FLOAT_EQ( |
| 1347 | 3.0, child_of_rs1->screen_space_transform().matrix().getDouble(1, 3)); |
| 1348 | EXPECT_FLOAT_EQ( |
| 1349 | 4.0, |
| 1350 | grand_child_of_rs1->screen_space_transform().matrix().getDouble(1, 3)); |
| 1351 | |
| 1352 | EXPECT_FLOAT_EQ( |
| 1353 | 3.0, render_surface2->screen_space_transform().matrix().getDouble(1, 3)); |
| 1354 | EXPECT_FLOAT_EQ( |
| 1355 | 4.0, child_of_rs2->screen_space_transform().matrix().getDouble(1, 3)); |
| 1356 | EXPECT_FLOAT_EQ( |
| 1357 | 5.0, |
| 1358 | grand_child_of_rs2->screen_space_transform().matrix().getDouble(1, 3)); |
| 1359 | } |
| 1360 | |
| 1361 | TEST(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
| 1362 | // For layers that flatten their subtree, there should be an orthographic |
| 1363 | // projection (for x and y values) in the middle of the transform sequence. |
| 1364 | // Note that the way the code is currently implemented, it is not expected to |
| 1365 | // use a canonical orthographic projection. |
| 1366 | |
| 1367 | scoped_refptr<Layer> root = Layer::Create(); |
| 1368 | scoped_refptr<Layer> child = Layer::Create(); |
| 1369 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1370 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1371 | |
| 1372 | gfx::Transform rotation_about_y_axis; |
| 1373 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1374 | |
| 1375 | const gfx::Transform identity_matrix; |
| 1376 | SetLayerPropertiesForTesting(root.get(), |
| 1377 | identity_matrix, |
| 1378 | identity_matrix, |
| 1379 | gfx::PointF(), |
| 1380 | gfx::PointF(), |
| 1381 | gfx::Size(100, 100), |
| 1382 | false); |
| 1383 | SetLayerPropertiesForTesting(child.get(), |
| 1384 | rotation_about_y_axis, |
| 1385 | identity_matrix, |
| 1386 | gfx::PointF(), |
| 1387 | gfx::PointF(), |
| 1388 | gfx::Size(10, 10), |
| 1389 | false); |
| 1390 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1391 | rotation_about_y_axis, |
| 1392 | identity_matrix, |
| 1393 | gfx::PointF(), |
| 1394 | gfx::PointF(), |
| 1395 | gfx::Size(10, 10), |
| 1396 | false); |
| 1397 | |
| 1398 | root->AddChild(child); |
| 1399 | child->AddChild(grand_child); |
| 1400 | child->SetForceRenderSurface(true); |
| 1401 | |
| 1402 | // No layers in this test should preserve 3d. |
| 1403 | ASSERT_FALSE(root->preserves_3d()); |
| 1404 | ASSERT_FALSE(child->preserves_3d()); |
| 1405 | ASSERT_FALSE(grand_child->preserves_3d()); |
| 1406 | |
| 1407 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1408 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1409 | gfx::Transform expected_grand_child_draw_transform = |
| 1410 | rotation_about_y_axis; // draws onto child's render surface |
| 1411 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1412 | flattened_rotation_about_y.FlattenTo2d(); |
| 1413 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1414 | flattened_rotation_about_y * rotation_about_y_axis; |
| 1415 | |
| 1416 | ExecuteCalculateDrawProperties(root.get()); |
| 1417 | |
| 1418 | // The child's draw transform should have been taken by its surface. |
| 1419 | ASSERT_TRUE(child->render_surface()); |
| 1420 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1421 | child->render_surface()->draw_transform()); |
| 1422 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1423 | expected_child_screen_space_transform, |
| 1424 | child->render_surface()->screen_space_transform()); |
| 1425 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1426 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1427 | child->screen_space_transform()); |
| 1428 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1429 | grand_child->draw_transform()); |
| 1430 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1431 | grand_child->screen_space_transform()); |
| 1432 | } |
| 1433 | |
| 1434 | TEST(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
| 1435 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1436 | // skipping a necessary translation. Without that translation, the coordinate |
| 1437 | // space of the layer's draw transform is incorrect. |
| 1438 | // |
| 1439 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1440 | // but if that layer becomes a render surface, then its draw transform is |
| 1441 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1442 | // incorrectly as a result. |
| 1443 | |
| 1444 | scoped_refptr<Layer> root = Layer::Create(); |
| 1445 | scoped_refptr<Layer> child = Layer::Create(); |
| 1446 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1447 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1448 | |
| 1449 | // The child height is zero, but has non-zero width that should be accounted |
| 1450 | // for while computing draw transforms. |
| 1451 | const gfx::Transform identity_matrix; |
| 1452 | SetLayerPropertiesForTesting(root.get(), |
| 1453 | identity_matrix, |
| 1454 | identity_matrix, |
| 1455 | gfx::PointF(), |
| 1456 | gfx::PointF(), |
| 1457 | gfx::Size(100, 100), |
| 1458 | false); |
| 1459 | SetLayerPropertiesForTesting(child.get(), |
| 1460 | identity_matrix, |
| 1461 | identity_matrix, |
| 1462 | gfx::PointF(), |
| 1463 | gfx::PointF(), |
| 1464 | gfx::Size(10, 0), |
| 1465 | false); |
| 1466 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1467 | identity_matrix, |
| 1468 | identity_matrix, |
| 1469 | gfx::PointF(), |
| 1470 | gfx::PointF(), |
| 1471 | gfx::Size(10, 10), |
| 1472 | false); |
| 1473 | |
| 1474 | root->AddChild(child); |
| 1475 | child->AddChild(grand_child); |
| 1476 | child->SetForceRenderSurface(true); |
| 1477 | |
| 1478 | ExecuteCalculateDrawProperties(root.get()); |
| 1479 | |
| 1480 | ASSERT_TRUE(child->render_surface()); |
| 1481 | // This is the real test, the rest are sanity checks. |
| 1482 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1483 | child->render_surface()->draw_transform()); |
| 1484 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1485 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1486 | grand_child->draw_transform()); |
| 1487 | } |
| 1488 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 1489 | TEST(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
| 1490 | // Transformations applied at the root of the tree should be forwarded |
| 1491 | // to child layers instead of applied to the root RenderSurface. |
| 1492 | const gfx::Transform identity_matrix; |
| 1493 | scoped_refptr<Layer> root = Layer::Create(); |
| 1494 | scoped_refptr<Layer> child = Layer::Create(); |
| 1495 | |
| 1496 | root->AddChild(child); |
| 1497 | |
| 1498 | SetLayerPropertiesForTesting(root.get(), |
| 1499 | identity_matrix, |
| 1500 | identity_matrix, |
| 1501 | gfx::PointF(), |
| 1502 | gfx::PointF(), |
| 1503 | gfx::Size(20, 20), |
| 1504 | false); |
| 1505 | SetLayerPropertiesForTesting(child.get(), |
| 1506 | identity_matrix, |
| 1507 | identity_matrix, |
| 1508 | gfx::PointF(), |
| 1509 | gfx::PointF(), |
| 1510 | gfx::Size(20, 20), |
| 1511 | false); |
| 1512 | |
| 1513 | LayerList render_surface_layer_list; |
| 1514 | int dummy_max_texture_size = 512; |
| 1515 | |
| 1516 | gfx::Transform translate; |
| 1517 | translate.Translate(50, 50); |
| 1518 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 1519 | root->bounds(), |
| 1520 | translate, |
| 1521 | 1.f, |
| 1522 | 1.f, |
| 1523 | NULL, |
| 1524 | dummy_max_texture_size, |
| 1525 | false, |
| 1526 | true, // can_adjust_raster_scale |
| 1527 | &render_surface_layer_list); |
| 1528 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1529 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1530 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1531 | |
| 1532 | gfx::Transform scale; |
| 1533 | scale.Scale(2, 2); |
| 1534 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 1535 | root->bounds(), |
| 1536 | scale, |
| 1537 | 1.f, |
| 1538 | 1.f, |
| 1539 | NULL, |
| 1540 | dummy_max_texture_size, |
| 1541 | false, |
| 1542 | true, // can_adjust_raster_scale |
| 1543 | &render_surface_layer_list); |
| 1544 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1545 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1546 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1547 | |
| 1548 | gfx::Transform rotate; |
| 1549 | rotate.Rotate(2); |
| 1550 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 1551 | root->bounds(), |
| 1552 | rotate, |
| 1553 | 1.f, |
| 1554 | 1.f, |
| 1555 | NULL, |
| 1556 | dummy_max_texture_size, |
| 1557 | false, |
| 1558 | true, // can_adjust_raster_scale |
| 1559 | &render_surface_layer_list); |
| 1560 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1561 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1562 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1563 | |
| 1564 | gfx::Transform composite; |
| 1565 | composite.ConcatTransform(translate); |
| 1566 | composite.ConcatTransform(scale); |
| 1567 | composite.ConcatTransform(rotate); |
| 1568 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 1569 | root->bounds(), |
| 1570 | composite, |
| 1571 | 1.f, |
| 1572 | 1.f, |
| 1573 | NULL, |
| 1574 | dummy_max_texture_size, |
| 1575 | false, |
| 1576 | true, // can_adjust_raster_scale |
| 1577 | &render_surface_layer_list); |
| 1578 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1579 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1580 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1581 | |
| 1582 | // Verify that it composes correctly with transforms directly on root layer. |
| 1583 | root->SetTransform(composite); |
| 1584 | root->SetSublayerTransform(composite); |
| 1585 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 1586 | root->bounds(), |
| 1587 | composite, |
| 1588 | 1.f, |
| 1589 | 1.f, |
| 1590 | NULL, |
| 1591 | dummy_max_texture_size, |
| 1592 | false, |
| 1593 | true, // can_adjust_raster_scale |
| 1594 | &render_surface_layer_list); |
| 1595 | gfx::Transform compositeSquared = composite; |
| 1596 | compositeSquared.ConcatTransform(composite); |
| 1597 | gfx::Transform compositeCubed = compositeSquared; |
| 1598 | compositeCubed.ConcatTransform(composite); |
| 1599 | EXPECT_EQ(compositeSquared, root->draw_properties().target_space_transform); |
| 1600 | EXPECT_EQ(compositeCubed, child->draw_properties().target_space_transform); |
| 1601 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1602 | } |
| 1603 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1604 | TEST(LayerTreeHostCommonTest, |
| 1605 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
| 1606 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1607 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1608 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1609 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1610 | |
| 1611 | const gfx::Transform identity_matrix; |
| 1612 | SetLayerPropertiesForTesting(parent.get(), |
| 1613 | identity_matrix, |
| 1614 | identity_matrix, |
| 1615 | gfx::PointF(), |
| 1616 | gfx::PointF(), |
| 1617 | gfx::Size(10, 10), |
| 1618 | false); |
| 1619 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1620 | identity_matrix, |
| 1621 | identity_matrix, |
| 1622 | gfx::PointF(), |
| 1623 | gfx::PointF(), |
| 1624 | gfx::Size(10, 10), |
| 1625 | false); |
| 1626 | SetLayerPropertiesForTesting(child.get(), |
| 1627 | identity_matrix, |
| 1628 | identity_matrix, |
| 1629 | gfx::PointF(), |
| 1630 | gfx::PointF(30.f, 30.f), |
| 1631 | gfx::Size(10, 10), |
| 1632 | false); |
| 1633 | |
| 1634 | parent->AddChild(render_surface1); |
| 1635 | parent->SetMasksToBounds(true); |
| 1636 | render_surface1->AddChild(child); |
| 1637 | render_surface1->SetForceRenderSurface(true); |
| 1638 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 1639 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1640 | int dummy_max_texture_size = 512; |
| 1641 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 1642 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 1643 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1644 | 1.f, |
| 1645 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 1646 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1647 | dummy_max_texture_size, |
| 1648 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1649 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1650 | &render_surface_layer_list); |
| 1651 | |
| 1652 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1653 | // the intermediate render surface should not be listed here, even if it was |
| 1654 | // forced to be created. Render surfaces without children or visible content |
| 1655 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1656 | // of size 0). |
| 1657 | ASSERT_TRUE(parent->render_surface()); |
| 1658 | ASSERT_FALSE(render_surface1->render_surface()); |
| 1659 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1660 | } |
| 1661 | |
| 1662 | TEST(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
| 1663 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1664 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1665 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1666 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1667 | |
| 1668 | const gfx::Transform identity_matrix; |
| 1669 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1670 | identity_matrix, |
| 1671 | identity_matrix, |
| 1672 | gfx::PointF(), |
| 1673 | gfx::PointF(), |
| 1674 | gfx::Size(10, 10), |
| 1675 | false); |
| 1676 | SetLayerPropertiesForTesting(child.get(), |
| 1677 | identity_matrix, |
| 1678 | identity_matrix, |
| 1679 | gfx::PointF(), |
| 1680 | gfx::PointF(), |
| 1681 | gfx::Size(10, 10), |
| 1682 | false); |
| 1683 | |
| 1684 | parent->AddChild(render_surface1); |
| 1685 | render_surface1->AddChild(child); |
| 1686 | render_surface1->SetForceRenderSurface(true); |
| 1687 | render_surface1->SetOpacity(0.f); |
| 1688 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 1689 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1690 | int dummy_max_texture_size = 512; |
| 1691 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 1692 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 1693 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1694 | 1.f, |
| 1695 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 1696 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1697 | dummy_max_texture_size, |
| 1698 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1699 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1700 | &render_surface_layer_list); |
| 1701 | |
| 1702 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1703 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1704 | // have been extended by the children. |
| 1705 | ASSERT_TRUE(parent->render_surface()); |
| 1706 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1707 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1708 | EXPECT_EQ(parent->id(), render_surface_layer_list[0]->id()); |
| 1709 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1710 | } |
| 1711 | |
| 1712 | TEST(LayerTreeHostCommonTest, ForceRenderSurface) { |
| 1713 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1714 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1715 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1716 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1717 | render_surface1->SetForceRenderSurface(true); |
| 1718 | |
| 1719 | const gfx::Transform identity_matrix; |
| 1720 | SetLayerPropertiesForTesting(parent.get(), |
| 1721 | identity_matrix, |
| 1722 | identity_matrix, |
| 1723 | gfx::PointF(), |
| 1724 | gfx::PointF(), |
| 1725 | gfx::Size(10, 10), |
| 1726 | false); |
| 1727 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1728 | identity_matrix, |
| 1729 | identity_matrix, |
| 1730 | gfx::PointF(), |
| 1731 | gfx::PointF(), |
| 1732 | gfx::Size(10, 10), |
| 1733 | false); |
| 1734 | SetLayerPropertiesForTesting(child.get(), |
| 1735 | identity_matrix, |
| 1736 | identity_matrix, |
| 1737 | gfx::PointF(), |
| 1738 | gfx::PointF(), |
| 1739 | gfx::Size(10, 10), |
| 1740 | false); |
| 1741 | |
| 1742 | parent->AddChild(render_surface1); |
| 1743 | render_surface1->AddChild(child); |
| 1744 | |
| 1745 | // Sanity check before the actual test |
| 1746 | EXPECT_FALSE(parent->render_surface()); |
| 1747 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1748 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 1749 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1750 | int dummy_max_texture_size = 512; |
| 1751 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 1752 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 1753 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1754 | 1.f, |
| 1755 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 1756 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1757 | dummy_max_texture_size, |
| 1758 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1759 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1760 | &render_surface_layer_list); |
| 1761 | |
| 1762 | // The root layer always creates a render surface |
| 1763 | EXPECT_TRUE(parent->render_surface()); |
| 1764 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1765 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1766 | |
| 1767 | render_surface_layer_list.clear(); |
| 1768 | render_surface1->SetForceRenderSurface(false); |
| 1769 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 1770 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 1771 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1772 | 1.f, |
| 1773 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 1774 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1775 | dummy_max_texture_size, |
| 1776 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1777 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1778 | &render_surface_layer_list); |
| 1779 | EXPECT_TRUE(parent->render_surface()); |
| 1780 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1781 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1782 | } |
| 1783 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1784 | TEST(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
| 1785 | // The entire subtree of layers that are outside the clip rect should be |
| 1786 | // culled away, and should not affect the render_surface_layer_list. |
| 1787 | // |
| 1788 | // The test tree is set up as follows: |
| 1789 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1790 | // that have something to draw. |
| 1791 | // - parent is a large container layer. |
| 1792 | // - child has masksToBounds=true to cause clipping. |
| 1793 | // - grand_child is positioned outside of the child's bounds |
| 1794 | // - great_grand_child is also kept outside child's bounds. |
| 1795 | // |
| 1796 | // In this configuration, grand_child and great_grand_child are completely |
| 1797 | // outside the clip rect, and they should never get scheduled on the list of |
| 1798 | // render surfaces. |
| 1799 | // |
| 1800 | |
| 1801 | const gfx::Transform identity_matrix; |
| 1802 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1803 | scoped_refptr<Layer> child = Layer::Create(); |
| 1804 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1805 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1806 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1807 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1808 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1809 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1810 | parent->AddChild(child); |
| 1811 | child->AddChild(grand_child); |
| 1812 | grand_child->AddChild(great_grand_child); |
| 1813 | |
| 1814 | // leaf_node1 ensures that parent and child are kept on the |
| 1815 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1816 | // should be clipped. |
| 1817 | child->AddChild(leaf_node1); |
| 1818 | great_grand_child->AddChild(leaf_node2); |
| 1819 | |
| 1820 | SetLayerPropertiesForTesting(parent.get(), |
| 1821 | identity_matrix, |
| 1822 | identity_matrix, |
| 1823 | gfx::PointF(), |
| 1824 | gfx::PointF(), |
| 1825 | gfx::Size(500, 500), |
| 1826 | false); |
| 1827 | SetLayerPropertiesForTesting(child.get(), |
| 1828 | identity_matrix, |
| 1829 | identity_matrix, |
| 1830 | gfx::PointF(), |
| 1831 | gfx::PointF(), |
| 1832 | gfx::Size(20, 20), |
| 1833 | false); |
| 1834 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1835 | identity_matrix, |
| 1836 | identity_matrix, |
| 1837 | gfx::PointF(), |
| 1838 | gfx::PointF(45.f, 45.f), |
| 1839 | gfx::Size(10, 10), |
| 1840 | false); |
| 1841 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1842 | identity_matrix, |
| 1843 | identity_matrix, |
| 1844 | gfx::PointF(), |
| 1845 | gfx::PointF(), |
| 1846 | gfx::Size(10, 10), |
| 1847 | false); |
| 1848 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1849 | identity_matrix, |
| 1850 | identity_matrix, |
| 1851 | gfx::PointF(), |
| 1852 | gfx::PointF(), |
| 1853 | gfx::Size(500, 500), |
| 1854 | false); |
| 1855 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1856 | identity_matrix, |
| 1857 | identity_matrix, |
| 1858 | gfx::PointF(), |
| 1859 | gfx::PointF(), |
| 1860 | gfx::Size(20, 20), |
| 1861 | false); |
| 1862 | |
| 1863 | child->SetMasksToBounds(true); |
| 1864 | child->SetOpacity(0.4f); |
| 1865 | child->SetForceRenderSurface(true); |
| 1866 | grand_child->SetOpacity(0.5f); |
| 1867 | great_grand_child->SetOpacity(0.4f); |
| 1868 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 1869 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1870 | int dummy_max_texture_size = 512; |
| 1871 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 1872 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 1873 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1874 | 1.f, |
| 1875 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 1876 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1877 | dummy_max_texture_size, |
| 1878 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1879 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1880 | &render_surface_layer_list); |
| 1881 | |
| 1882 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
| 1883 | EXPECT_EQ(parent->id(), render_surface_layer_list[0]->id()); |
| 1884 | EXPECT_EQ(child->id(), render_surface_layer_list[1]->id()); |
| 1885 | } |
| 1886 | |
| 1887 | TEST(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
| 1888 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1889 | // of the surface. When the render surface is animating its transforms, then |
| 1890 | // the content rect's position in the clip rect is not defined on the main |
| 1891 | // thread, and its content rect should not be clipped. |
| 1892 | |
| 1893 | // The test tree is set up as follows: |
| 1894 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1895 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1896 | // the parent. |
| 1897 | // - grand_child is a render surface, and the only visible content in child. |
| 1898 | // It is positioned outside of the clip rect from parent. |
| 1899 | |
| 1900 | // In this configuration, grand_child should be outside the clipped |
| 1901 | // content rect of the child, making grand_child not appear in the |
| 1902 | // render_surface_layer_list. However, when we place an animation on the |
| 1903 | // child, this clipping should be avoided and we should keep the grand_child |
| 1904 | // in the render_surface_layer_list. |
| 1905 | |
| 1906 | const gfx::Transform identity_matrix; |
| 1907 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1908 | scoped_refptr<Layer> child = Layer::Create(); |
| 1909 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1910 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1911 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1912 | parent->AddChild(child); |
| 1913 | child->AddChild(grand_child); |
| 1914 | grand_child->AddChild(leaf_node); |
| 1915 | |
| 1916 | SetLayerPropertiesForTesting(parent.get(), |
| 1917 | identity_matrix, |
| 1918 | identity_matrix, |
| 1919 | gfx::PointF(), |
| 1920 | gfx::PointF(), |
| 1921 | gfx::Size(100, 100), |
| 1922 | false); |
| 1923 | SetLayerPropertiesForTesting(child.get(), |
| 1924 | identity_matrix, |
| 1925 | identity_matrix, |
| 1926 | gfx::PointF(), |
| 1927 | gfx::PointF(), |
| 1928 | gfx::Size(20, 20), |
| 1929 | false); |
| 1930 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1931 | identity_matrix, |
| 1932 | identity_matrix, |
| 1933 | gfx::PointF(), |
| 1934 | gfx::PointF(200.f, 200.f), |
| 1935 | gfx::Size(10, 10), |
| 1936 | false); |
| 1937 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1938 | identity_matrix, |
| 1939 | identity_matrix, |
| 1940 | gfx::PointF(), |
| 1941 | gfx::PointF(), |
| 1942 | gfx::Size(10, 10), |
| 1943 | false); |
| 1944 | |
| 1945 | parent->SetMasksToBounds(true); |
| 1946 | child->SetOpacity(0.4f); |
| 1947 | child->SetForceRenderSurface(true); |
| 1948 | grand_child->SetOpacity(0.4f); |
| 1949 | grand_child->SetForceRenderSurface(true); |
| 1950 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 1951 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1952 | int dummy_max_texture_size = 512; |
| 1953 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 1954 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 1955 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1956 | 1.f, |
| 1957 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 1958 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1959 | dummy_max_texture_size, |
| 1960 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1961 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1962 | &render_surface_layer_list); |
| 1963 | |
| 1964 | // Without an animation, we should cull child and grand_child from the |
| 1965 | // render_surface_layer_list. |
| 1966 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1967 | EXPECT_EQ(parent->id(), render_surface_layer_list[0]->id()); |
| 1968 | |
| 1969 | // Now put an animating transform on child. |
| 1970 | AddAnimatedTransformToController( |
| 1971 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1972 | |
| 1973 | parent->ClearRenderSurface(); |
| 1974 | child->ClearRenderSurface(); |
| 1975 | grand_child->ClearRenderSurface(); |
| 1976 | render_surface_layer_list.clear(); |
| 1977 | |
| 1978 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 1979 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 1980 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1981 | 1.f, |
| 1982 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 1983 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1984 | dummy_max_texture_size, |
| 1985 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 1986 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1987 | &render_surface_layer_list); |
| 1988 | |
| 1989 | // With an animating transform, we should keep child and grand_child in the |
| 1990 | // render_surface_layer_list. |
| 1991 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1992 | EXPECT_EQ(parent->id(), render_surface_layer_list[0]->id()); |
| 1993 | EXPECT_EQ(child->id(), render_surface_layer_list[1]->id()); |
| 1994 | EXPECT_EQ(grand_child->id(), render_surface_layer_list[2]->id()); |
| 1995 | } |
| 1996 | |
| 1997 | TEST(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
| 1998 | // Layer's IsClipped() property is set to true when: |
| 1999 | // - the layer clips its subtree, e.g. masks to bounds, |
| 2000 | // - the layer is clipped by an ancestor that contributes to the same |
| 2001 | // render target, |
| 2002 | // - a surface is clipped by an ancestor that contributes to the same |
| 2003 | // render target. |
| 2004 | // |
| 2005 | // In particular, for a layer that owns a render surface: |
| 2006 | // - the render surface inherits any clip from ancestors, and does NOT |
| 2007 | // pass that clipped status to the layer itself. |
| 2008 | // - but if the layer itself masks to bounds, it is considered clipped |
| 2009 | // and propagates the clip to the subtree. |
| 2010 | |
| 2011 | const gfx::Transform identity_matrix; |
| 2012 | scoped_refptr<Layer> root = Layer::Create(); |
| 2013 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2014 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 2015 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 2016 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 2017 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 2018 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2019 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 2020 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2021 | root->AddChild(parent); |
| 2022 | parent->AddChild(child1); |
| 2023 | parent->AddChild(child2); |
| 2024 | child1->AddChild(grand_child); |
| 2025 | child2->AddChild(leaf_node2); |
| 2026 | grand_child->AddChild(leaf_node1); |
| 2027 | |
| 2028 | child2->SetForceRenderSurface(true); |
| 2029 | |
| 2030 | SetLayerPropertiesForTesting(root.get(), |
| 2031 | identity_matrix, |
| 2032 | identity_matrix, |
| 2033 | gfx::PointF(), |
| 2034 | gfx::PointF(), |
| 2035 | gfx::Size(100, 100), |
| 2036 | false); |
| 2037 | SetLayerPropertiesForTesting(parent.get(), |
| 2038 | identity_matrix, |
| 2039 | identity_matrix, |
| 2040 | gfx::PointF(), |
| 2041 | gfx::PointF(), |
| 2042 | gfx::Size(100, 100), |
| 2043 | false); |
| 2044 | SetLayerPropertiesForTesting(child1.get(), |
| 2045 | identity_matrix, |
| 2046 | identity_matrix, |
| 2047 | gfx::PointF(), |
| 2048 | gfx::PointF(), |
| 2049 | gfx::Size(100, 100), |
| 2050 | false); |
| 2051 | SetLayerPropertiesForTesting(child2.get(), |
| 2052 | identity_matrix, |
| 2053 | identity_matrix, |
| 2054 | gfx::PointF(), |
| 2055 | gfx::PointF(), |
| 2056 | gfx::Size(100, 100), |
| 2057 | false); |
| 2058 | SetLayerPropertiesForTesting(grand_child.get(), |
| 2059 | identity_matrix, |
| 2060 | identity_matrix, |
| 2061 | gfx::PointF(), |
| 2062 | gfx::PointF(), |
| 2063 | gfx::Size(100, 100), |
| 2064 | false); |
| 2065 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2066 | identity_matrix, |
| 2067 | identity_matrix, |
| 2068 | gfx::PointF(), |
| 2069 | gfx::PointF(), |
| 2070 | gfx::Size(100, 100), |
| 2071 | false); |
| 2072 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2073 | identity_matrix, |
| 2074 | identity_matrix, |
| 2075 | gfx::PointF(), |
| 2076 | gfx::PointF(), |
| 2077 | gfx::Size(100, 100), |
| 2078 | false); |
| 2079 | |
| 2080 | // Case 1: nothing is clipped except the root render surface. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 2081 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2082 | int dummy_max_texture_size = 512; |
| 2083 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 2084 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 2085 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2086 | 1.f, |
| 2087 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 2088 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2089 | dummy_max_texture_size, |
| 2090 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 2091 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2092 | &render_surface_layer_list); |
| 2093 | |
| 2094 | ASSERT_TRUE(root->render_surface()); |
| 2095 | ASSERT_TRUE(child2->render_surface()); |
| 2096 | |
| 2097 | EXPECT_FALSE(root->is_clipped()); |
| 2098 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2099 | EXPECT_FALSE(parent->is_clipped()); |
| 2100 | EXPECT_FALSE(child1->is_clipped()); |
| 2101 | EXPECT_FALSE(child2->is_clipped()); |
| 2102 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 2103 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2104 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2105 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2106 | |
| 2107 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 2108 | // surface are clipped. But layers that contribute to child2's surface are |
| 2109 | // not clipped explicitly because child2's surface already accounts for |
| 2110 | // that clip. |
| 2111 | render_surface_layer_list.clear(); |
| 2112 | parent->SetMasksToBounds(true); |
| 2113 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 2114 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 2115 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2116 | 1.f, |
| 2117 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 2118 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2119 | dummy_max_texture_size, |
| 2120 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 2121 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2122 | &render_surface_layer_list); |
| 2123 | |
| 2124 | ASSERT_TRUE(root->render_surface()); |
| 2125 | ASSERT_TRUE(child2->render_surface()); |
| 2126 | |
| 2127 | EXPECT_FALSE(root->is_clipped()); |
| 2128 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2129 | EXPECT_TRUE(parent->is_clipped()); |
| 2130 | EXPECT_TRUE(child1->is_clipped()); |
| 2131 | EXPECT_FALSE(child2->is_clipped()); |
| 2132 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 2133 | EXPECT_TRUE(grand_child->is_clipped()); |
| 2134 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 2135 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 2136 | |
| 2137 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 2138 | // child2's render surface is not clipped. |
| 2139 | render_surface_layer_list.clear(); |
| 2140 | parent->SetMasksToBounds(false); |
| 2141 | child2->SetMasksToBounds(true); |
| 2142 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 2143 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 2144 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2145 | 1.f, |
| 2146 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 2147 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2148 | dummy_max_texture_size, |
| 2149 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 2150 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2151 | &render_surface_layer_list); |
| 2152 | |
| 2153 | ASSERT_TRUE(root->render_surface()); |
| 2154 | ASSERT_TRUE(child2->render_surface()); |
| 2155 | |
| 2156 | EXPECT_FALSE(root->is_clipped()); |
| 2157 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2158 | EXPECT_FALSE(parent->is_clipped()); |
| 2159 | EXPECT_FALSE(child1->is_clipped()); |
| 2160 | EXPECT_TRUE(child2->is_clipped()); |
| 2161 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 2162 | EXPECT_FALSE(grand_child->is_clipped()); |
| 2163 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 2164 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 2165 | } |
| 2166 | |
| 2167 | TEST(LayerTreeHostCommonTest, drawable_content_rectForLayers) { |
| 2168 | // Verify that layers get the appropriate DrawableContentRect when their |
| 2169 | // parent masksToBounds is true. |
| 2170 | // |
| 2171 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 2172 | // be the layer rect expressed in target space. |
| 2173 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 2174 | // will be the intersection of layer bounds and the mask region. |
| 2175 | // grand_child3 - partially clipped and masksToBounds; the |
| 2176 | // DrawableContentRect will still be the intersection of layer bounds and |
| 2177 | // the mask region. |
| 2178 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 2179 | // be empty. |
| 2180 | // |
| 2181 | |
| 2182 | const gfx::Transform identity_matrix; |
| 2183 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2184 | scoped_refptr<Layer> child = Layer::Create(); |
| 2185 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 2186 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 2187 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 2188 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 2189 | |
| 2190 | parent->AddChild(child); |
| 2191 | child->AddChild(grand_child1); |
| 2192 | child->AddChild(grand_child2); |
| 2193 | child->AddChild(grand_child3); |
| 2194 | child->AddChild(grand_child4); |
| 2195 | |
| 2196 | SetLayerPropertiesForTesting(parent.get(), |
| 2197 | identity_matrix, |
| 2198 | identity_matrix, |
| 2199 | gfx::PointF(), |
| 2200 | gfx::PointF(), |
| 2201 | gfx::Size(500, 500), |
| 2202 | false); |
| 2203 | SetLayerPropertiesForTesting(child.get(), |
| 2204 | identity_matrix, |
| 2205 | identity_matrix, |
| 2206 | gfx::PointF(), |
| 2207 | gfx::PointF(), |
| 2208 | gfx::Size(20, 20), |
| 2209 | false); |
| 2210 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2211 | identity_matrix, |
| 2212 | identity_matrix, |
| 2213 | gfx::PointF(), |
| 2214 | gfx::PointF(5.f, 5.f), |
| 2215 | gfx::Size(10, 10), |
| 2216 | false); |
| 2217 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2218 | identity_matrix, |
| 2219 | identity_matrix, |
| 2220 | gfx::PointF(), |
| 2221 | gfx::PointF(15.f, 15.f), |
| 2222 | gfx::Size(10, 10), |
| 2223 | false); |
| 2224 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2225 | identity_matrix, |
| 2226 | identity_matrix, |
| 2227 | gfx::PointF(), |
| 2228 | gfx::PointF(15.f, 15.f), |
| 2229 | gfx::Size(10, 10), |
| 2230 | false); |
| 2231 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2232 | identity_matrix, |
| 2233 | identity_matrix, |
| 2234 | gfx::PointF(), |
| 2235 | gfx::PointF(45.f, 45.f), |
| 2236 | gfx::Size(10, 10), |
| 2237 | false); |
| 2238 | |
| 2239 | child->SetMasksToBounds(true); |
| 2240 | grand_child3->SetMasksToBounds(true); |
| 2241 | |
| 2242 | // Force everyone to be a render surface. |
| 2243 | child->SetOpacity(0.4f); |
| 2244 | grand_child1->SetOpacity(0.5f); |
| 2245 | grand_child2->SetOpacity(0.5f); |
| 2246 | grand_child3->SetOpacity(0.5f); |
| 2247 | grand_child4->SetOpacity(0.5f); |
| 2248 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 2249 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2250 | int dummy_max_texture_size = 512; |
| 2251 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 2252 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 2253 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2254 | 1.f, |
| 2255 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 2256 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2257 | dummy_max_texture_size, |
| 2258 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 2259 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2260 | &render_surface_layer_list); |
| 2261 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2262 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2263 | grand_child1->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2264 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2265 | grand_child3->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2266 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2267 | grand_child3->drawable_content_rect()); |
| 2268 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2269 | } |
| 2270 | |
| 2271 | TEST(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
| 2272 | // Verify that render surfaces (and their layers) get the appropriate |
| 2273 | // clip rects when their parent masksToBounds is true. |
| 2274 | // |
| 2275 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2276 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2277 | // They may still have a clip rect of their own layer bounds, however, if |
| 2278 | // masksToBounds was true. |
| 2279 | const gfx::Transform identity_matrix; |
| 2280 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2281 | scoped_refptr<Layer> child = Layer::Create(); |
| 2282 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 2283 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 2284 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 2285 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 2286 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 2287 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2288 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 2289 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2290 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 2291 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2292 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 2293 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2294 | |
| 2295 | parent->AddChild(child); |
| 2296 | child->AddChild(grand_child1); |
| 2297 | child->AddChild(grand_child2); |
| 2298 | child->AddChild(grand_child3); |
| 2299 | child->AddChild(grand_child4); |
| 2300 | |
| 2301 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2302 | // this test. |
| 2303 | grand_child1->AddChild(leaf_node1); |
| 2304 | grand_child2->AddChild(leaf_node2); |
| 2305 | grand_child3->AddChild(leaf_node3); |
| 2306 | grand_child4->AddChild(leaf_node4); |
| 2307 | |
| 2308 | SetLayerPropertiesForTesting(parent.get(), |
| 2309 | identity_matrix, |
| 2310 | identity_matrix, |
| 2311 | gfx::PointF(), |
| 2312 | gfx::PointF(), |
| 2313 | gfx::Size(500, 500), |
| 2314 | false); |
| 2315 | SetLayerPropertiesForTesting(child.get(), |
| 2316 | identity_matrix, |
| 2317 | identity_matrix, |
| 2318 | gfx::PointF(), |
| 2319 | gfx::PointF(), |
| 2320 | gfx::Size(20, 20), |
| 2321 | false); |
| 2322 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2323 | identity_matrix, |
| 2324 | identity_matrix, |
| 2325 | gfx::PointF(), |
| 2326 | gfx::PointF(5.f, 5.f), |
| 2327 | gfx::Size(10, 10), |
| 2328 | false); |
| 2329 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2330 | identity_matrix, |
| 2331 | identity_matrix, |
| 2332 | gfx::PointF(), |
| 2333 | gfx::PointF(15.f, 15.f), |
| 2334 | gfx::Size(10, 10), |
| 2335 | false); |
| 2336 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2337 | identity_matrix, |
| 2338 | identity_matrix, |
| 2339 | gfx::PointF(), |
| 2340 | gfx::PointF(15.f, 15.f), |
| 2341 | gfx::Size(10, 10), |
| 2342 | false); |
| 2343 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2344 | identity_matrix, |
| 2345 | identity_matrix, |
| 2346 | gfx::PointF(), |
| 2347 | gfx::PointF(45.f, 45.f), |
| 2348 | gfx::Size(10, 10), |
| 2349 | false); |
| 2350 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2351 | identity_matrix, |
| 2352 | identity_matrix, |
| 2353 | gfx::PointF(), |
| 2354 | gfx::PointF(), |
| 2355 | gfx::Size(10, 10), |
| 2356 | false); |
| 2357 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2358 | identity_matrix, |
| 2359 | identity_matrix, |
| 2360 | gfx::PointF(), |
| 2361 | gfx::PointF(), |
| 2362 | gfx::Size(10, 10), |
| 2363 | false); |
| 2364 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2365 | identity_matrix, |
| 2366 | identity_matrix, |
| 2367 | gfx::PointF(), |
| 2368 | gfx::PointF(), |
| 2369 | gfx::Size(10, 10), |
| 2370 | false); |
| 2371 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2372 | identity_matrix, |
| 2373 | identity_matrix, |
| 2374 | gfx::PointF(), |
| 2375 | gfx::PointF(), |
| 2376 | gfx::Size(10, 10), |
| 2377 | false); |
| 2378 | |
| 2379 | child->SetMasksToBounds(true); |
| 2380 | grand_child3->SetMasksToBounds(true); |
| 2381 | grand_child4->SetMasksToBounds(true); |
| 2382 | |
| 2383 | // Force everyone to be a render surface. |
| 2384 | child->SetOpacity(0.4f); |
| 2385 | child->SetForceRenderSurface(true); |
| 2386 | grand_child1->SetOpacity(0.5f); |
| 2387 | grand_child1->SetForceRenderSurface(true); |
| 2388 | grand_child2->SetOpacity(0.5f); |
| 2389 | grand_child2->SetForceRenderSurface(true); |
| 2390 | grand_child3->SetOpacity(0.5f); |
| 2391 | grand_child3->SetForceRenderSurface(true); |
| 2392 | grand_child4->SetOpacity(0.5f); |
| 2393 | grand_child4->SetForceRenderSurface(true); |
| 2394 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 2395 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2396 | int dummy_max_texture_size = 512; |
| 2397 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 2398 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 2399 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2400 | 1.f, |
| 2401 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 2402 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2403 | dummy_max_texture_size, |
| 2404 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 2405 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2406 | &render_surface_layer_list); |
| 2407 | |
| 2408 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2409 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2410 | ASSERT_TRUE(grand_child3->render_surface()); |
| 2411 | // Because grand_child4 is entirely clipped, it is expected to not have a |
| 2412 | // render surface. |
| 2413 | EXPECT_FALSE(grand_child4->render_surface()); |
| 2414 | |
| 2415 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2416 | // masksToBounds. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2417 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2418 | grand_child1->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2419 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2420 | grand_child2->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2421 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2422 | grand_child3->render_surface()->clip_rect()); |
| 2423 | } |
| 2424 | |
| 2425 | TEST(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
| 2426 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2427 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2428 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2429 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2430 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2431 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2432 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2433 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2434 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2435 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2436 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2437 | parent->AddChild(render_surface1); |
| 2438 | parent->AddChild(child_of_root); |
| 2439 | render_surface1->AddChild(child_of_rs1); |
| 2440 | render_surface1->AddChild(render_surface2); |
| 2441 | render_surface2->AddChild(child_of_rs2); |
| 2442 | child_of_root->AddChild(grand_child_of_root); |
| 2443 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2444 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2445 | |
| 2446 | // Make our render surfaces. |
| 2447 | render_surface1->SetForceRenderSurface(true); |
| 2448 | render_surface2->SetForceRenderSurface(true); |
| 2449 | |
| 2450 | gfx::Transform layer_transform; |
| 2451 | layer_transform.Translate(1.0, 1.0); |
| 2452 | gfx::Transform sublayer_transform; |
| 2453 | sublayer_transform.Scale3d(10.0, 1.0, 1.0); |
| 2454 | |
| 2455 | SetLayerPropertiesForTesting(parent.get(), |
| 2456 | layer_transform, |
| 2457 | sublayer_transform, |
| 2458 | gfx::PointF(0.25f, 0.f), |
| 2459 | gfx::PointF(2.5f, 0.f), |
| 2460 | gfx::Size(10, 10), |
| 2461 | false); |
| 2462 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2463 | layer_transform, |
| 2464 | sublayer_transform, |
| 2465 | gfx::PointF(0.25f, 0.f), |
| 2466 | gfx::PointF(2.5f, 0.f), |
| 2467 | gfx::Size(10, 10), |
| 2468 | false); |
| 2469 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2470 | layer_transform, |
| 2471 | sublayer_transform, |
| 2472 | gfx::PointF(0.25f, 0.f), |
| 2473 | gfx::PointF(2.5f, 0.f), |
| 2474 | gfx::Size(10, 10), |
| 2475 | false); |
| 2476 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2477 | layer_transform, |
| 2478 | sublayer_transform, |
| 2479 | gfx::PointF(0.25f, 0.f), |
| 2480 | gfx::PointF(2.5f, 0.f), |
| 2481 | gfx::Size(10, 10), |
| 2482 | false); |
| 2483 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2484 | layer_transform, |
| 2485 | sublayer_transform, |
| 2486 | gfx::PointF(0.25f, 0.f), |
| 2487 | gfx::PointF(2.5f, 0.f), |
| 2488 | gfx::Size(10, 10), |
| 2489 | false); |
| 2490 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2491 | layer_transform, |
| 2492 | sublayer_transform, |
| 2493 | gfx::PointF(0.25f, 0.f), |
| 2494 | gfx::PointF(2.5f, 0.f), |
| 2495 | gfx::Size(10, 10), |
| 2496 | false); |
| 2497 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2498 | layer_transform, |
| 2499 | sublayer_transform, |
| 2500 | gfx::PointF(0.25f, 0.f), |
| 2501 | gfx::PointF(2.5f, 0.f), |
| 2502 | gfx::Size(10, 10), |
| 2503 | false); |
| 2504 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2505 | layer_transform, |
| 2506 | sublayer_transform, |
| 2507 | gfx::PointF(0.25f, 0.f), |
| 2508 | gfx::PointF(2.5f, 0.f), |
| 2509 | gfx::Size(10, 10), |
| 2510 | false); |
| 2511 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2512 | layer_transform, |
| 2513 | sublayer_transform, |
| 2514 | gfx::PointF(0.25f, 0.f), |
| 2515 | gfx::PointF(2.5f, 0.f), |
| 2516 | gfx::Size(10, 10), |
| 2517 | false); |
| 2518 | |
| 2519 | // Put an animated opacity on the render surface. |
| 2520 | AddOpacityTransitionToController( |
| 2521 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2522 | |
| 2523 | // Also put an animated opacity on a layer without descendants. |
| 2524 | AddOpacityTransitionToController( |
| 2525 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2526 | |
| 2527 | // Put a transform animation on the render surface. |
| 2528 | AddAnimatedTransformToController( |
| 2529 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2530 | |
| 2531 | // Also put transform animations on grand_child_of_root, and |
| 2532 | // grand_child_of_rs2 |
| 2533 | AddAnimatedTransformToController( |
| 2534 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2535 | AddAnimatedTransformToController( |
| 2536 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2537 | |
| 2538 | ExecuteCalculateDrawProperties(parent.get()); |
| 2539 | |
| 2540 | // Only layers that are associated with render surfaces should have an actual |
| 2541 | // RenderSurface() value. |
| 2542 | ASSERT_TRUE(parent->render_surface()); |
| 2543 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2544 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2545 | |
| 2546 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2547 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2548 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2549 | |
| 2550 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2551 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2552 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2553 | |
| 2554 | // Verify all render target accessors |
| 2555 | EXPECT_EQ(parent, parent->render_target()); |
| 2556 | EXPECT_EQ(parent, child_of_root->render_target()); |
| 2557 | EXPECT_EQ(parent, grand_child_of_root->render_target()); |
| 2558 | |
| 2559 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 2560 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 2561 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 2562 | |
| 2563 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 2564 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 2565 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 2566 | |
| 2567 | // Verify draw_opacity_is_animating values |
| 2568 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2569 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2570 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2571 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2572 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2573 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2574 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2575 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2576 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2577 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2578 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2579 | |
| 2580 | // Verify draw_transform_is_animating values |
| 2581 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2582 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2583 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2584 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2585 | EXPECT_FALSE(render_surface1->render_surface() |
| 2586 | ->target_surface_transforms_are_animating()); |
| 2587 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2588 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2589 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2590 | EXPECT_TRUE(render_surface2->render_surface() |
| 2591 | ->target_surface_transforms_are_animating()); |
| 2592 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2593 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2594 | |
| 2595 | // Verify screen_space_transform_is_animating values |
| 2596 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2597 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2598 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2599 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2600 | EXPECT_FALSE(render_surface1->render_surface() |
| 2601 | ->screen_space_transforms_are_animating()); |
| 2602 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2603 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2604 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2605 | EXPECT_TRUE(render_surface2->render_surface() |
| 2606 | ->screen_space_transforms_are_animating()); |
| 2607 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2608 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2609 | |
| 2610 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2611 | // It is expected that we correctly set up transforms so that the y-component |
| 2612 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
| 2613 | EXPECT_FLOAT_EQ(1.0, |
| 2614 | parent->screen_space_transform().matrix().getDouble(1, 3)); |
| 2615 | EXPECT_FLOAT_EQ( |
| 2616 | 2.0, child_of_root->screen_space_transform().matrix().getDouble(1, 3)); |
| 2617 | EXPECT_FLOAT_EQ( |
| 2618 | 3.0, |
| 2619 | grand_child_of_root->screen_space_transform().matrix().getDouble(1, 3)); |
| 2620 | |
| 2621 | EXPECT_FLOAT_EQ( |
| 2622 | 2.0, render_surface1->screen_space_transform().matrix().getDouble(1, 3)); |
| 2623 | EXPECT_FLOAT_EQ( |
| 2624 | 3.0, child_of_rs1->screen_space_transform().matrix().getDouble(1, 3)); |
| 2625 | EXPECT_FLOAT_EQ( |
| 2626 | 4.0, |
| 2627 | grand_child_of_rs1->screen_space_transform().matrix().getDouble(1, 3)); |
| 2628 | |
| 2629 | EXPECT_FLOAT_EQ( |
| 2630 | 3.0, render_surface2->screen_space_transform().matrix().getDouble(1, 3)); |
| 2631 | EXPECT_FLOAT_EQ( |
| 2632 | 4.0, child_of_rs2->screen_space_transform().matrix().getDouble(1, 3)); |
| 2633 | EXPECT_FLOAT_EQ( |
| 2634 | 5.0, |
| 2635 | grand_child_of_rs2->screen_space_transform().matrix().getDouble(1, 3)); |
| 2636 | } |
| 2637 | |
| 2638 | TEST(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
| 2639 | // Test the calculateVisibleRect() function works correctly for identity |
| 2640 | // transforms. |
| 2641 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2642 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2643 | gfx::Transform layer_to_surface_transform; |
| 2644 | |
| 2645 | // Case 1: Layer is contained within the surface. |
| 2646 | gfx::Rect layer_content_rect = |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2647 | gfx::Rect(10, 10, 30, 30); |
| 2648 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2649 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2650 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2651 | EXPECT_RECT_EQ(expected, actual); |
| 2652 | |
| 2653 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2654 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2655 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2656 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2657 | EXPECT_TRUE(actual.IsEmpty()); |
| 2658 | |
| 2659 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2660 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2661 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2662 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2663 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2664 | EXPECT_RECT_EQ(expected, actual); |
| 2665 | } |
| 2666 | |
| 2667 | TEST(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
| 2668 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2669 | // transforms. |
| 2670 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2671 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2672 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2673 | gfx::Transform layer_to_surface_transform; |
| 2674 | |
| 2675 | // Case 1: Layer is contained within the surface. |
| 2676 | layer_to_surface_transform.MakeIdentity(); |
| 2677 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2678 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2679 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2680 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2681 | EXPECT_RECT_EQ(expected, actual); |
| 2682 | |
| 2683 | // Case 2: Layer is outside the surface rect. |
| 2684 | layer_to_surface_transform.MakeIdentity(); |
| 2685 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2686 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2687 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2688 | EXPECT_TRUE(actual.IsEmpty()); |
| 2689 | |
| 2690 | // Case 3: Layer is partially overlapping the surface rect. |
| 2691 | layer_to_surface_transform.MakeIdentity(); |
| 2692 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2693 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2694 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2695 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2696 | EXPECT_RECT_EQ(expected, actual); |
| 2697 | } |
| 2698 | |
| 2699 | TEST(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
| 2700 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2701 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2702 | // should return the g in the layer's space. |
| 2703 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2704 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2705 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2706 | gfx::Transform layer_to_surface_transform; |
| 2707 | |
| 2708 | // Case 1: Layer is contained within the surface. |
| 2709 | layer_to_surface_transform.MakeIdentity(); |
| 2710 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2711 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2712 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2713 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2714 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2715 | EXPECT_RECT_EQ(expected, actual); |
| 2716 | |
| 2717 | // Case 2: Layer is outside the surface rect. |
| 2718 | layer_to_surface_transform.MakeIdentity(); |
| 2719 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2720 | layer_to_surface_transform.Rotate(45.0); |
| 2721 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2722 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2723 | EXPECT_TRUE(actual.IsEmpty()); |
| 2724 | |
| 2725 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2726 | // the layer is oriented diagonally, with the left half outside of the render |
| 2727 | // surface. In this case, the g should still be the entire layer |
| 2728 | // (remember the g is computed in layer space); both the top-left |
| 2729 | // and bottom-right corners of the layer are still visible. |
| 2730 | layer_to_surface_transform.MakeIdentity(); |
| 2731 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2732 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2733 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2734 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2735 | EXPECT_RECT_EQ(expected, actual); |
| 2736 | |
| 2737 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2738 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2739 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2740 | // surface overlaps the right side of the layer. The g should be |
| 2741 | // the layer's right half. |
| 2742 | layer_to_surface_transform.MakeIdentity(); |
| 2743 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2744 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2745 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2746 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2747 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2748 | EXPECT_RECT_EQ(expected, actual); |
| 2749 | } |
| 2750 | |
| 2751 | TEST(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
| 2752 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2753 | // transforms. |
| 2754 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2755 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2756 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2757 | gfx::Transform layer_to_surface_transform; |
| 2758 | |
| 2759 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2760 | // degrees, should be fully contained in the render surface. |
| 2761 | layer_to_surface_transform.MakeIdentity(); |
| 2762 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2763 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2764 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2765 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2766 | EXPECT_RECT_EQ(expected, actual); |
| 2767 | |
| 2768 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2769 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2770 | // visible on the surface. |
| 2771 | // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
| 2772 | double half_width_of_rotated_layer = (100.0 / sqrt(2.0)) * 0.5; |
| 2773 | layer_to_surface_transform.MakeIdentity(); |
| 2774 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
| 2775 | layer_to_surface_transform.RotateAboutYAxis( |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2776 | 45.0); // Rotates about the left edge of the layer. |
| 2777 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2778 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2779 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2780 | EXPECT_RECT_EQ(expected, actual); |
| 2781 | } |
| 2782 | |
| 2783 | TEST(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
| 2784 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2785 | // a perspective projection onto the target surface. |
| 2786 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2787 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2788 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2789 | gfx::Transform layer_to_surface_transform; |
| 2790 | |
| 2791 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2792 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2793 | // its translated more than the perspective amount. |
| 2794 | layer_to_surface_transform.MakeIdentity(); |
| 2795 | |
| 2796 | // The following sequence of transforms applies the perspective about the |
| 2797 | // center of the surface. |
| 2798 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2799 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2800 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2801 | |
| 2802 | // This translate places the layer in front of the surface's projection plane. |
| 2803 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2804 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2805 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2806 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2807 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2808 | EXPECT_RECT_EQ(expected, actual); |
| 2809 | |
| 2810 | // Case 2: same projection as before, except that the layer is also translated |
| 2811 | // to the side, so that only the right half of the layer should be visible. |
| 2812 | // |
| 2813 | // Explanation of expected result: The perspective ratio is (z distance |
| 2814 | // between layer and camera origin) / (z distance between projection plane and |
| 2815 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2816 | // move a layer by translating -50 units in projected surface units (so that |
| 2817 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2818 | // -50 == -200 in the layer's units. |
| 2819 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
| 2820 | expected = gfx::Rect( |
| 2821 | gfx::Point(50, -50), |
| 2822 | gfx::Size(100, 200)); // The right half of the layer's bounding rect. |
| 2823 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2824 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2825 | EXPECT_RECT_EQ(expected, actual); |
| 2826 | } |
| 2827 | |
| 2828 | TEST(LayerTreeHostCommonTest, |
| 2829 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
| 2830 | // There is currently no explicit concept of an orthographic projection plane |
| 2831 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2832 | // are technically behind the surface in an orthographic world should not be |
| 2833 | // clipped when they are flattened to the surface. |
| 2834 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2835 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2836 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2837 | gfx::Transform layer_to_surface_transform; |
| 2838 | |
| 2839 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2840 | // at the center of the layer. |
| 2841 | layer_to_surface_transform.MakeIdentity(); |
| 2842 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2843 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2844 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2845 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2846 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2847 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2848 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2849 | EXPECT_RECT_EQ(expected, actual); |
| 2850 | } |
| 2851 | |
| 2852 | TEST(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
| 2853 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2854 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2855 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2856 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2857 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2858 | // converting to cartesian coordinates. |
| 2859 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2860 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2861 | gfx::Rect layer_content_rect = |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2862 | gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2863 | gfx::Transform layer_to_surface_transform; |
| 2864 | |
| 2865 | // The layer is positioned so that the right half of the layer should be in |
| 2866 | // front of the camera, while the other half is behind the surface's |
| 2867 | // projection plane. The following sequence of transforms applies the |
| 2868 | // perspective and rotation about the center of the layer. |
| 2869 | layer_to_surface_transform.MakeIdentity(); |
| 2870 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2871 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2872 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2873 | |
| 2874 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2875 | // transform, otherwise this code is not testing the intended scenario. |
| 2876 | bool clipped; |
| 2877 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2878 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2879 | &clipped); |
| 2880 | ASSERT_TRUE(clipped); |
| 2881 | |
| 2882 | int expected_x_position = 0; |
| 2883 | int expected_width = 10; |
| 2884 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2885 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2886 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2887 | EXPECT_EQ(expected_width, actual.width()); |
| 2888 | } |
| 2889 | |
| 2890 | TEST(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
| 2891 | // To determine visible rect in layer space, there needs to be an |
| 2892 | // un-projection from surface space to layer space. When the original |
| 2893 | // transform was a perspective projection that was clipped, it returns a rect |
| 2894 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2895 | // clipping again. |
| 2896 | |
| 2897 | // This sequence of transforms causes one corner of the layer to protrude |
| 2898 | // across the w = 0 plane, and should be clipped. |
| 2899 | gfx::Rect target_surface_rect = |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2900 | gfx::Rect(-50, -50, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2901 | gfx::Rect layer_content_rect = |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2902 | gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2903 | gfx::Transform layer_to_surface_transform; |
| 2904 | layer_to_surface_transform.MakeIdentity(); |
| 2905 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2906 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2907 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2908 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2909 | |
| 2910 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2911 | // code is not testing the intended scenario. |
| 2912 | bool clipped; |
| 2913 | gfx::RectF clipped_rect = |
| 2914 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2915 | MathUtil::ProjectQuad( |
| 2916 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2917 | ASSERT_TRUE(clipped); |
| 2918 | |
| 2919 | // Only the corner of the layer is not visible on the surface because of being |
| 2920 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2921 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2922 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2923 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2924 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2925 | EXPECT_RECT_EQ(expected, actual); |
| 2926 | } |
| 2927 | |
| 2928 | TEST(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
| 2929 | scoped_refptr<Layer> root = Layer::Create(); |
| 2930 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2931 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2932 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2933 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2934 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2935 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2936 | root->AddChild(child1); |
| 2937 | root->AddChild(child2); |
| 2938 | root->AddChild(child3); |
| 2939 | |
| 2940 | gfx::Transform identity_matrix; |
| 2941 | SetLayerPropertiesForTesting(root.get(), |
| 2942 | identity_matrix, |
| 2943 | identity_matrix, |
| 2944 | gfx::PointF(), |
| 2945 | gfx::PointF(), |
| 2946 | gfx::Size(100, 100), |
| 2947 | false); |
| 2948 | SetLayerPropertiesForTesting(child1.get(), |
| 2949 | identity_matrix, |
| 2950 | identity_matrix, |
| 2951 | gfx::PointF(), |
| 2952 | gfx::PointF(), |
| 2953 | gfx::Size(50, 50), |
| 2954 | false); |
| 2955 | SetLayerPropertiesForTesting(child2.get(), |
| 2956 | identity_matrix, |
| 2957 | identity_matrix, |
| 2958 | gfx::PointF(), |
| 2959 | gfx::PointF(75.f, 75.f), |
| 2960 | gfx::Size(50, 50), |
| 2961 | false); |
| 2962 | SetLayerPropertiesForTesting(child3.get(), |
| 2963 | identity_matrix, |
| 2964 | identity_matrix, |
| 2965 | gfx::PointF(), |
| 2966 | gfx::PointF(125.f, 125.f), |
| 2967 | gfx::Size(50, 50), |
| 2968 | false); |
| 2969 | |
| 2970 | ExecuteCalculateDrawProperties(root.get()); |
| 2971 | |
| 2972 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2973 | root->render_surface()->DrawableContentRect()); |
| 2974 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2975 | |
| 2976 | // Layers that do not draw content should have empty visible_content_rects. |
| 2977 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2978 | |
| 2979 | // layer visible_content_rects are clipped by their target surface. |
| 2980 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2981 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 2982 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2983 | |
| 2984 | // layer drawable_content_rects are not clipped. |
| 2985 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2986 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2987 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2988 | } |
| 2989 | |
| 2990 | TEST(LayerTreeHostCommonTest, |
| 2991 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
| 2992 | scoped_refptr<Layer> root = Layer::Create(); |
| 2993 | scoped_refptr<Layer> child = Layer::Create(); |
| 2994 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2995 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2996 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2997 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2998 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2999 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3000 | root->AddChild(child); |
| 3001 | child->AddChild(grand_child1); |
| 3002 | child->AddChild(grand_child2); |
| 3003 | child->AddChild(grand_child3); |
| 3004 | |
| 3005 | gfx::Transform identity_matrix; |
| 3006 | SetLayerPropertiesForTesting(root.get(), |
| 3007 | identity_matrix, |
| 3008 | identity_matrix, |
| 3009 | gfx::PointF(), |
| 3010 | gfx::PointF(), |
| 3011 | gfx::Size(100, 100), |
| 3012 | false); |
| 3013 | SetLayerPropertiesForTesting(child.get(), |
| 3014 | identity_matrix, |
| 3015 | identity_matrix, |
| 3016 | gfx::PointF(), |
| 3017 | gfx::PointF(), |
| 3018 | gfx::Size(100, 100), |
| 3019 | false); |
| 3020 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 3021 | identity_matrix, |
| 3022 | identity_matrix, |
| 3023 | gfx::PointF(), |
| 3024 | gfx::PointF(5.f, 5.f), |
| 3025 | gfx::Size(50, 50), |
| 3026 | false); |
| 3027 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 3028 | identity_matrix, |
| 3029 | identity_matrix, |
| 3030 | gfx::PointF(), |
| 3031 | gfx::PointF(75.f, 75.f), |
| 3032 | gfx::Size(50, 50), |
| 3033 | false); |
| 3034 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 3035 | identity_matrix, |
| 3036 | identity_matrix, |
| 3037 | gfx::PointF(), |
| 3038 | gfx::PointF(125.f, 125.f), |
| 3039 | gfx::Size(50, 50), |
| 3040 | false); |
| 3041 | |
| 3042 | child->SetMasksToBounds(true); |
| 3043 | ExecuteCalculateDrawProperties(root.get()); |
| 3044 | |
| 3045 | ASSERT_FALSE(child->render_surface()); |
| 3046 | |
| 3047 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3048 | root->render_surface()->DrawableContentRect()); |
| 3049 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3050 | |
| 3051 | // Layers that do not draw content should have empty visible content rects. |
| 3052 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3053 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
| 3054 | |
| 3055 | // All grandchild visible content rects should be clipped by child. |
| 3056 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 3057 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
| 3058 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 3059 | |
| 3060 | // All grandchild DrawableContentRects should also be clipped by child. |
| 3061 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), |
| 3062 | grand_child1->drawable_content_rect()); |
| 3063 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25), |
| 3064 | grand_child2->drawable_content_rect()); |
| 3065 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 3066 | } |
| 3067 | |
| 3068 | TEST(LayerTreeHostCommonTest, |
| 3069 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
| 3070 | scoped_refptr<Layer> root = Layer::Create(); |
| 3071 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3072 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3073 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3074 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3075 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3076 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3077 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3078 | root->AddChild(render_surface1); |
| 3079 | render_surface1->AddChild(child1); |
| 3080 | render_surface1->AddChild(child2); |
| 3081 | render_surface1->AddChild(child3); |
| 3082 | |
| 3083 | gfx::Transform identity_matrix; |
| 3084 | SetLayerPropertiesForTesting(root.get(), |
| 3085 | identity_matrix, |
| 3086 | identity_matrix, |
| 3087 | gfx::PointF(), |
| 3088 | gfx::PointF(), |
| 3089 | gfx::Size(100, 100), |
| 3090 | false); |
| 3091 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3092 | identity_matrix, |
| 3093 | identity_matrix, |
| 3094 | gfx::PointF(), |
| 3095 | gfx::PointF(), |
| 3096 | gfx::Size(3, 4), |
| 3097 | false); |
| 3098 | SetLayerPropertiesForTesting(child1.get(), |
| 3099 | identity_matrix, |
| 3100 | identity_matrix, |
| 3101 | gfx::PointF(), |
| 3102 | gfx::PointF(5.f, 5.f), |
| 3103 | gfx::Size(50, 50), |
| 3104 | false); |
| 3105 | SetLayerPropertiesForTesting(child2.get(), |
| 3106 | identity_matrix, |
| 3107 | identity_matrix, |
| 3108 | gfx::PointF(), |
| 3109 | gfx::PointF(75.f, 75.f), |
| 3110 | gfx::Size(50, 50), |
| 3111 | false); |
| 3112 | SetLayerPropertiesForTesting(child3.get(), |
| 3113 | identity_matrix, |
| 3114 | identity_matrix, |
| 3115 | gfx::PointF(), |
| 3116 | gfx::PointF(125.f, 125.f), |
| 3117 | gfx::Size(50, 50), |
| 3118 | false); |
| 3119 | |
| 3120 | render_surface1->SetForceRenderSurface(true); |
| 3121 | ExecuteCalculateDrawProperties(root.get()); |
| 3122 | |
| 3123 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3124 | |
| 3125 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3126 | root->render_surface()->DrawableContentRect()); |
| 3127 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3128 | |
| 3129 | // Layers that do not draw content should have empty visible content rects. |
| 3130 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3131 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3132 | render_surface1->visible_content_rect()); |
| 3133 | |
| 3134 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 3135 | // regions of the subtree. |
| 3136 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3137 | render_surface1->render_surface()->DrawableContentRect()); |
| 3138 | |
| 3139 | // All layers that draw content into the unclipped surface are also unclipped. |
| 3140 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3141 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3142 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 3143 | |
| 3144 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3145 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3146 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3147 | } |
| 3148 | |
| 3149 | TEST(LayerTreeHostCommonTest, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3150 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
| 3151 | scoped_refptr<Layer> root = Layer::Create(); |
| 3152 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3153 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3154 | root->AddChild(child); |
| 3155 | |
| 3156 | gfx::Transform identity_matrix; |
| 3157 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3158 | |
| 3159 | SetLayerPropertiesForTesting(root.get(), |
| 3160 | identity_matrix, |
| 3161 | identity_matrix, |
| 3162 | gfx::PointF(), |
| 3163 | gfx::PointF(), |
| 3164 | gfx::Size(100, 100), |
| 3165 | false); |
| 3166 | SetLayerPropertiesForTesting(child.get(), |
| 3167 | uninvertible_matrix, |
| 3168 | identity_matrix, |
| 3169 | gfx::PointF(), |
| 3170 | gfx::PointF(5.f, 5.f), |
| 3171 | gfx::Size(50, 50), |
| 3172 | false); |
| 3173 | |
| 3174 | ExecuteCalculateDrawProperties(root.get()); |
| 3175 | |
| 3176 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 3177 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
| 3178 | } |
| 3179 | |
| 3180 | TEST(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3181 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
| 3182 | scoped_refptr<Layer> root = Layer::Create(); |
| 3183 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3184 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3185 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3186 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3187 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3188 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3189 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3190 | root->AddChild(render_surface1); |
| 3191 | render_surface1->AddChild(child1); |
| 3192 | render_surface1->AddChild(child2); |
| 3193 | render_surface1->AddChild(child3); |
| 3194 | |
| 3195 | gfx::Transform identity_matrix; |
| 3196 | SetLayerPropertiesForTesting(root.get(), |
| 3197 | identity_matrix, |
| 3198 | identity_matrix, |
| 3199 | gfx::PointF(), |
| 3200 | gfx::PointF(), |
| 3201 | gfx::Size(100, 100), |
| 3202 | false); |
| 3203 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3204 | identity_matrix, |
| 3205 | identity_matrix, |
| 3206 | gfx::PointF(), |
| 3207 | gfx::PointF(), |
| 3208 | gfx::Size(3, 4), |
| 3209 | false); |
| 3210 | SetLayerPropertiesForTesting(child1.get(), |
| 3211 | identity_matrix, |
| 3212 | identity_matrix, |
| 3213 | gfx::PointF(), |
| 3214 | gfx::PointF(5.f, 5.f), |
| 3215 | gfx::Size(50, 50), |
| 3216 | false); |
| 3217 | SetLayerPropertiesForTesting(child2.get(), |
| 3218 | identity_matrix, |
| 3219 | identity_matrix, |
| 3220 | gfx::PointF(), |
| 3221 | gfx::PointF(75.f, 75.f), |
| 3222 | gfx::Size(50, 50), |
| 3223 | false); |
| 3224 | SetLayerPropertiesForTesting(child3.get(), |
| 3225 | identity_matrix, |
| 3226 | identity_matrix, |
| 3227 | gfx::PointF(), |
| 3228 | gfx::PointF(125.f, 125.f), |
| 3229 | gfx::Size(50, 50), |
| 3230 | false); |
| 3231 | |
| 3232 | root->SetMasksToBounds(true); |
| 3233 | render_surface1->SetForceRenderSurface(true); |
| 3234 | ExecuteCalculateDrawProperties(root.get()); |
| 3235 | |
| 3236 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3237 | |
| 3238 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3239 | root->render_surface()->DrawableContentRect()); |
| 3240 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3241 | |
| 3242 | // Layers that do not draw content should have empty visible content rects. |
| 3243 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3244 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3245 | render_surface1->visible_content_rect()); |
| 3246 | |
| 3247 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3248 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3249 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3250 | render_surface1->render_surface()->DrawableContentRect()); |
| 3251 | |
| 3252 | // All layers that draw content into the surface have their visible content |
| 3253 | // rect clipped by the surface clip rect. |
| 3254 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3255 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 3256 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3257 | |
| 3258 | // But the DrawableContentRects are unclipped. |
| 3259 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3260 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3261 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3262 | } |
| 3263 | |
| 3264 | TEST(LayerTreeHostCommonTest, |
| 3265 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
| 3266 | // Check that clipping does not propagate down surfaces. |
| 3267 | scoped_refptr<Layer> root = Layer::Create(); |
| 3268 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3269 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3270 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3271 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3272 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3273 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3274 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3275 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3276 | root->AddChild(render_surface1); |
| 3277 | render_surface1->AddChild(render_surface2); |
| 3278 | render_surface2->AddChild(child1); |
| 3279 | render_surface2->AddChild(child2); |
| 3280 | render_surface2->AddChild(child3); |
| 3281 | |
| 3282 | gfx::Transform identity_matrix; |
| 3283 | SetLayerPropertiesForTesting(root.get(), |
| 3284 | identity_matrix, |
| 3285 | identity_matrix, |
| 3286 | gfx::PointF(), |
| 3287 | gfx::PointF(), |
| 3288 | gfx::Size(100, 100), |
| 3289 | false); |
| 3290 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3291 | identity_matrix, |
| 3292 | identity_matrix, |
| 3293 | gfx::PointF(), |
| 3294 | gfx::PointF(), |
| 3295 | gfx::Size(3, 4), |
| 3296 | false); |
| 3297 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3298 | identity_matrix, |
| 3299 | identity_matrix, |
| 3300 | gfx::PointF(), |
| 3301 | gfx::PointF(), |
| 3302 | gfx::Size(7, 13), |
| 3303 | false); |
| 3304 | SetLayerPropertiesForTesting(child1.get(), |
| 3305 | identity_matrix, |
| 3306 | identity_matrix, |
| 3307 | gfx::PointF(), |
| 3308 | gfx::PointF(5.f, 5.f), |
| 3309 | gfx::Size(50, 50), |
| 3310 | false); |
| 3311 | SetLayerPropertiesForTesting(child2.get(), |
| 3312 | identity_matrix, |
| 3313 | identity_matrix, |
| 3314 | gfx::PointF(), |
| 3315 | gfx::PointF(75.f, 75.f), |
| 3316 | gfx::Size(50, 50), |
| 3317 | false); |
| 3318 | SetLayerPropertiesForTesting(child3.get(), |
| 3319 | identity_matrix, |
| 3320 | identity_matrix, |
| 3321 | gfx::PointF(), |
| 3322 | gfx::PointF(125.f, 125.f), |
| 3323 | gfx::Size(50, 50), |
| 3324 | false); |
| 3325 | |
| 3326 | root->SetMasksToBounds(true); |
| 3327 | render_surface1->SetForceRenderSurface(true); |
| 3328 | render_surface2->SetForceRenderSurface(true); |
| 3329 | ExecuteCalculateDrawProperties(root.get()); |
| 3330 | |
| 3331 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3332 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3333 | |
| 3334 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3335 | root->render_surface()->DrawableContentRect()); |
| 3336 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3337 | |
| 3338 | // Layers that do not draw content should have empty visible content rects. |
| 3339 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3340 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3341 | render_surface1->visible_content_rect()); |
| 3342 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3343 | render_surface2->visible_content_rect()); |
| 3344 | |
| 3345 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3346 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3347 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3348 | render_surface1->render_surface()->DrawableContentRect()); |
| 3349 | |
| 3350 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3351 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3352 | // render_surface2 grows to enclose all drawable content of its subtree. |
| 3353 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3354 | render_surface2->render_surface()->DrawableContentRect()); |
| 3355 | |
| 3356 | // All layers that draw content into render_surface2 think they are unclipped. |
| 3357 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3358 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3359 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 3360 | |
| 3361 | // DrawableContentRects are also unclipped. |
| 3362 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3363 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3364 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3365 | } |
| 3366 | |
| 3367 | TEST(LayerTreeHostCommonTest, |
| 3368 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
| 3369 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3370 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3371 | |
| 3372 | scoped_refptr<Layer> root = Layer::Create(); |
| 3373 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3374 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3375 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3376 | root->AddChild(render_surface1); |
| 3377 | render_surface1->AddChild(child1); |
| 3378 | |
| 3379 | gfx::Transform identity_matrix; |
| 3380 | gfx::Transform child_rotation; |
| 3381 | child_rotation.Rotate(45.0); |
| 3382 | SetLayerPropertiesForTesting(root.get(), |
| 3383 | identity_matrix, |
| 3384 | identity_matrix, |
| 3385 | gfx::PointF(), |
| 3386 | gfx::PointF(), |
| 3387 | gfx::Size(100, 100), |
| 3388 | false); |
| 3389 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3390 | identity_matrix, |
| 3391 | identity_matrix, |
| 3392 | gfx::PointF(), |
| 3393 | gfx::PointF(), |
| 3394 | gfx::Size(3, 4), |
| 3395 | false); |
| 3396 | SetLayerPropertiesForTesting(child1.get(), |
| 3397 | child_rotation, |
| 3398 | identity_matrix, |
| 3399 | gfx::PointF(0.5f, 0.5f), |
| 3400 | gfx::PointF(25.f, 25.f), |
| 3401 | gfx::Size(50, 50), |
| 3402 | false); |
| 3403 | |
| 3404 | render_surface1->SetForceRenderSurface(true); |
| 3405 | ExecuteCalculateDrawProperties(root.get()); |
| 3406 | |
| 3407 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3408 | |
| 3409 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3410 | root->render_surface()->DrawableContentRect()); |
| 3411 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3412 | |
| 3413 | // Layers that do not draw content should have empty visible content rects. |
| 3414 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3415 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3416 | render_surface1->visible_content_rect()); |
| 3417 | |
| 3418 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3419 | // regions of the subtree. |
| 3420 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3421 | gfx::Rect expected_surface_drawable_content = |
| 3422 | gfx::Rect(50.0 - diagonal_radius, |
| 3423 | 50.0 - diagonal_radius, |
| 3424 | diagonal_radius * 2.0, |
| 3425 | diagonal_radius * 2.0); |
| 3426 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3427 | render_surface1->render_surface()->DrawableContentRect()); |
| 3428 | |
| 3429 | // All layers that draw content into the unclipped surface are also unclipped. |
| 3430 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3431 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3432 | child1->drawable_content_rect()); |
| 3433 | } |
| 3434 | |
| 3435 | TEST(LayerTreeHostCommonTest, |
| 3436 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
| 3437 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3438 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3439 | |
| 3440 | scoped_refptr<Layer> root = Layer::Create(); |
| 3441 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3442 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3443 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3444 | root->AddChild(render_surface1); |
| 3445 | render_surface1->AddChild(child1); |
| 3446 | |
| 3447 | gfx::Transform identity_matrix; |
| 3448 | gfx::Transform child_rotation; |
| 3449 | child_rotation.Rotate(45.0); |
| 3450 | SetLayerPropertiesForTesting(root.get(), |
| 3451 | identity_matrix, |
| 3452 | identity_matrix, |
| 3453 | gfx::PointF(), |
| 3454 | gfx::PointF(), |
| 3455 | gfx::Size(50, 50), |
| 3456 | false); |
| 3457 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3458 | identity_matrix, |
| 3459 | identity_matrix, |
| 3460 | gfx::PointF(), |
| 3461 | gfx::PointF(), |
| 3462 | gfx::Size(3, 4), |
| 3463 | false); |
| 3464 | SetLayerPropertiesForTesting(child1.get(), |
| 3465 | child_rotation, |
| 3466 | identity_matrix, |
| 3467 | gfx::PointF(0.5f, 0.5f), |
| 3468 | gfx::PointF(25.f, 25.f), |
| 3469 | gfx::Size(50, 50), |
| 3470 | false); |
| 3471 | |
| 3472 | root->SetMasksToBounds(true); |
| 3473 | render_surface1->SetForceRenderSurface(true); |
| 3474 | ExecuteCalculateDrawProperties(root.get()); |
| 3475 | |
| 3476 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3477 | |
| 3478 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3479 | // rotated layer. |
| 3480 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3481 | gfx::Rect unclipped_surface_content = gfx::Rect(50.0 - diagonal_radius, |
| 3482 | 50.0 - diagonal_radius, |
| 3483 | diagonal_radius * 2.0, |
| 3484 | diagonal_radius * 2.0); |
| 3485 | gfx::Rect expected_surface_drawable_content = |
| 3486 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
| 3487 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3488 | render_surface1->render_surface()->DrawableContentRect()); |
| 3489 | |
| 3490 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3491 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3492 | // up covering the full left half of child1. |
| 3493 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
| 3494 | |
| 3495 | // The child's DrawableContentRect is unclipped. |
| 3496 | EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
| 3497 | } |
| 3498 | |
| 3499 | TEST(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
| 3500 | MockContentLayerClient client; |
| 3501 | |
| 3502 | scoped_refptr<Layer> root = Layer::Create(); |
| 3503 | scoped_refptr<ContentLayer> render_surface1 = |
| 3504 | CreateDrawableContentLayer(&client); |
| 3505 | scoped_refptr<ContentLayer> render_surface2 = |
| 3506 | CreateDrawableContentLayer(&client); |
| 3507 | scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client); |
| 3508 | scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client); |
| 3509 | scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client); |
| 3510 | root->AddChild(render_surface1); |
| 3511 | render_surface1->AddChild(render_surface2); |
| 3512 | render_surface2->AddChild(child1); |
| 3513 | render_surface2->AddChild(child2); |
| 3514 | render_surface2->AddChild(child3); |
| 3515 | |
| 3516 | gfx::Transform identity_matrix; |
| 3517 | SetLayerPropertiesForTesting(root.get(), |
| 3518 | identity_matrix, |
| 3519 | identity_matrix, |
| 3520 | gfx::PointF(), |
| 3521 | gfx::PointF(), |
| 3522 | gfx::Size(100, 100), |
| 3523 | false); |
| 3524 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3525 | identity_matrix, |
| 3526 | identity_matrix, |
| 3527 | gfx::PointF(), |
| 3528 | gfx::PointF(5.f, 5.f), |
| 3529 | gfx::Size(3, 4), |
| 3530 | false); |
| 3531 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3532 | identity_matrix, |
| 3533 | identity_matrix, |
| 3534 | gfx::PointF(), |
| 3535 | gfx::PointF(5.f, 5.f), |
| 3536 | gfx::Size(7, 13), |
| 3537 | false); |
| 3538 | SetLayerPropertiesForTesting(child1.get(), |
| 3539 | identity_matrix, |
| 3540 | identity_matrix, |
| 3541 | gfx::PointF(), |
| 3542 | gfx::PointF(5.f, 5.f), |
| 3543 | gfx::Size(50, 50), |
| 3544 | false); |
| 3545 | SetLayerPropertiesForTesting(child2.get(), |
| 3546 | identity_matrix, |
| 3547 | identity_matrix, |
| 3548 | gfx::PointF(), |
| 3549 | gfx::PointF(75.f, 75.f), |
| 3550 | gfx::Size(50, 50), |
| 3551 | false); |
| 3552 | SetLayerPropertiesForTesting(child3.get(), |
| 3553 | identity_matrix, |
| 3554 | identity_matrix, |
| 3555 | gfx::PointF(), |
| 3556 | gfx::PointF(125.f, 125.f), |
| 3557 | gfx::Size(50, 50), |
| 3558 | false); |
| 3559 | |
| 3560 | float device_scale_factor = 2.f; |
| 3561 | |
| 3562 | root->SetMasksToBounds(true); |
| 3563 | render_surface1->SetForceRenderSurface(true); |
| 3564 | render_surface2->SetForceRenderSurface(true); |
| 3565 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3566 | |
| 3567 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3568 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3569 | |
| 3570 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3571 | // device_scale_factor. |
| 3572 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3573 | root->render_surface()->DrawableContentRect()); |
| 3574 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3575 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3576 | render_surface1->render_surface()->DrawableContentRect()); |
| 3577 | |
| 3578 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3579 | // is only implicitly clipped by render_surface1. |
| 3580 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3581 | render_surface2->render_surface()->DrawableContentRect()); |
| 3582 | |
| 3583 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3584 | EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), |
| 3585 | child2->drawable_content_rect()); |
| 3586 | EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), |
| 3587 | child3->drawable_content_rect()); |
| 3588 | |
| 3589 | // The root layer does not actually draw content of its own. |
| 3590 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3591 | |
| 3592 | // All layer visible content rects are expressed in content space of each |
| 3593 | // layer, so they are also scaled by the device_scale_factor. |
| 3594 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8), |
| 3595 | render_surface1->visible_content_rect()); |
| 3596 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26), |
| 3597 | render_surface2->visible_content_rect()); |
| 3598 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect()); |
| 3599 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect()); |
| 3600 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect()); |
| 3601 | } |
| 3602 | |
| 3603 | TEST(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
| 3604 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3605 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3606 | // "flattened" to each parent layer according to current W3C spec. |
| 3607 | |
| 3608 | const gfx::Transform identity_matrix; |
| 3609 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3610 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3611 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3612 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3613 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3614 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3615 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3616 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3617 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3618 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3619 | front_facing_child_of_front_facing_surface = |
| 3620 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3621 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3622 | back_facing_child_of_front_facing_surface = |
| 3623 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3624 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3625 | front_facing_child_of_back_facing_surface = |
| 3626 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3627 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3628 | back_facing_child_of_back_facing_surface = |
| 3629 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3630 | |
| 3631 | parent->AddChild(front_facing_child); |
| 3632 | parent->AddChild(back_facing_child); |
| 3633 | parent->AddChild(front_facing_surface); |
| 3634 | parent->AddChild(back_facing_surface); |
| 3635 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3636 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3637 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3638 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3639 | |
| 3640 | // Nothing is double-sided |
| 3641 | front_facing_child->SetDoubleSided(false); |
| 3642 | back_facing_child->SetDoubleSided(false); |
| 3643 | front_facing_surface->SetDoubleSided(false); |
| 3644 | back_facing_surface->SetDoubleSided(false); |
| 3645 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3646 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3647 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3648 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3649 | |
| 3650 | gfx::Transform backface_matrix; |
| 3651 | backface_matrix.Translate(50.0, 50.0); |
| 3652 | backface_matrix.RotateAboutYAxis(180.0); |
| 3653 | backface_matrix.Translate(-50.0, -50.0); |
| 3654 | |
| 3655 | // Having a descendant and opacity will force these to have render surfaces. |
| 3656 | front_facing_surface->SetOpacity(0.5f); |
| 3657 | back_facing_surface->SetOpacity(0.5f); |
| 3658 | |
| 3659 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3660 | // these layers should blindly use their own local transforms to determine |
| 3661 | // back-face culling. |
| 3662 | SetLayerPropertiesForTesting(parent.get(), |
| 3663 | identity_matrix, |
| 3664 | identity_matrix, |
| 3665 | gfx::PointF(), |
| 3666 | gfx::PointF(), |
| 3667 | gfx::Size(100, 100), |
| 3668 | false); |
| 3669 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3670 | identity_matrix, |
| 3671 | identity_matrix, |
| 3672 | gfx::PointF(), |
| 3673 | gfx::PointF(), |
| 3674 | gfx::Size(100, 100), |
| 3675 | false); |
| 3676 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3677 | backface_matrix, |
| 3678 | identity_matrix, |
| 3679 | gfx::PointF(), |
| 3680 | gfx::PointF(), |
| 3681 | gfx::Size(100, 100), |
| 3682 | false); |
| 3683 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3684 | identity_matrix, |
| 3685 | identity_matrix, |
| 3686 | gfx::PointF(), |
| 3687 | gfx::PointF(), |
| 3688 | gfx::Size(100, 100), |
| 3689 | false); |
| 3690 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3691 | backface_matrix, |
| 3692 | identity_matrix, |
| 3693 | gfx::PointF(), |
| 3694 | gfx::PointF(), |
| 3695 | gfx::Size(100, 100), |
| 3696 | false); |
| 3697 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3698 | identity_matrix, |
| 3699 | identity_matrix, |
| 3700 | gfx::PointF(), |
| 3701 | gfx::PointF(), |
| 3702 | gfx::Size(100, 100), |
| 3703 | false); |
| 3704 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3705 | backface_matrix, |
| 3706 | identity_matrix, |
| 3707 | gfx::PointF(), |
| 3708 | gfx::PointF(), |
| 3709 | gfx::Size(100, 100), |
| 3710 | false); |
| 3711 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3712 | identity_matrix, |
| 3713 | identity_matrix, |
| 3714 | gfx::PointF(), |
| 3715 | gfx::PointF(), |
| 3716 | gfx::Size(100, 100), |
| 3717 | false); |
| 3718 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3719 | backface_matrix, |
| 3720 | identity_matrix, |
| 3721 | gfx::PointF(), |
| 3722 | gfx::PointF(), |
| 3723 | gfx::Size(100, 100), |
| 3724 | false); |
| 3725 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 3726 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3727 | int dummy_max_texture_size = 512; |
| 3728 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 3729 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 3730 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3731 | 1.f, |
| 3732 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 3733 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3734 | dummy_max_texture_size, |
| 3735 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 3736 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3737 | &render_surface_layer_list); |
| 3738 | |
| 3739 | // Verify which render surfaces were created. |
| 3740 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3741 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3742 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3743 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3744 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3745 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3746 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3747 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3748 | |
| 3749 | // Verify the render_surface_layer_list. |
| 3750 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
| 3751 | EXPECT_EQ(parent->id(), render_surface_layer_list[0]->id()); |
| 3752 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list[1]->id()); |
| 3753 | // Even though the back facing surface LAYER gets culled, the other |
| 3754 | // descendants should still be added, so the SURFACE should not be culled. |
| 3755 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list[2]->id()); |
| 3756 | |
| 3757 | // Verify root surface's layer list. |
| 3758 | ASSERT_EQ( |
| 3759 | 3u, render_surface_layer_list[0]->render_surface()->layer_list().size()); |
| 3760 | EXPECT_EQ( |
| 3761 | front_facing_child->id(), |
| 3762 | render_surface_layer_list[0]->render_surface()->layer_list()[0]->id()); |
| 3763 | EXPECT_EQ( |
| 3764 | front_facing_surface->id(), |
| 3765 | render_surface_layer_list[0]->render_surface()->layer_list()[1]->id()); |
| 3766 | EXPECT_EQ( |
| 3767 | back_facing_surface->id(), |
| 3768 | render_surface_layer_list[0]->render_surface()->layer_list()[2]->id()); |
| 3769 | |
| 3770 | // Verify front_facing_surface's layer list. |
| 3771 | ASSERT_EQ( |
| 3772 | 2u, render_surface_layer_list[1]->render_surface()->layer_list().size()); |
| 3773 | EXPECT_EQ( |
| 3774 | front_facing_surface->id(), |
| 3775 | render_surface_layer_list[1]->render_surface()->layer_list()[0]->id()); |
| 3776 | EXPECT_EQ( |
| 3777 | front_facing_child_of_front_facing_surface->id(), |
| 3778 | render_surface_layer_list[1]->render_surface()->layer_list()[1]->id()); |
| 3779 | |
| 3780 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3781 | // from the surface list. |
| 3782 | ASSERT_EQ( |
| 3783 | 1u, render_surface_layer_list[2]->render_surface()->layer_list().size()); |
| 3784 | EXPECT_EQ( |
| 3785 | front_facing_child_of_back_facing_surface->id(), |
| 3786 | render_surface_layer_list[2]->render_surface()->layer_list()[0]->id()); |
| 3787 | } |
| 3788 | |
| 3789 | TEST(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
| 3790 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3791 | // is used. |
| 3792 | |
| 3793 | const gfx::Transform identity_matrix; |
| 3794 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3795 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3796 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3797 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3798 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3799 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3800 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3801 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3802 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3803 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3804 | front_facing_child_of_front_facing_surface = |
| 3805 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3806 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3807 | back_facing_child_of_front_facing_surface = |
| 3808 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3809 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3810 | front_facing_child_of_back_facing_surface = |
| 3811 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3812 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3813 | back_facing_child_of_back_facing_surface = |
| 3814 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3815 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3816 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3817 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3818 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3819 | |
| 3820 | parent->AddChild(front_facing_child); |
| 3821 | parent->AddChild(back_facing_child); |
| 3822 | parent->AddChild(front_facing_surface); |
| 3823 | parent->AddChild(back_facing_surface); |
| 3824 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3825 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3826 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3827 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3828 | |
| 3829 | // Nothing is double-sided |
| 3830 | front_facing_child->SetDoubleSided(false); |
| 3831 | back_facing_child->SetDoubleSided(false); |
| 3832 | front_facing_surface->SetDoubleSided(false); |
| 3833 | back_facing_surface->SetDoubleSided(false); |
| 3834 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3835 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3836 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3837 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3838 | |
| 3839 | gfx::Transform backface_matrix; |
| 3840 | backface_matrix.Translate(50.0, 50.0); |
| 3841 | backface_matrix.RotateAboutYAxis(180.0); |
| 3842 | backface_matrix.Translate(-50.0, -50.0); |
| 3843 | |
| 3844 | // Opacity will not force creation of render surfaces in this case because of |
| 3845 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3846 | // would be created with preserve-3d is when there is a replica layer. |
| 3847 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3848 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3849 | |
| 3850 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3851 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3852 | // rendering context should use the transform with respect to that context. |
| 3853 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3854 | // and (b) the layer's transform style is preserve-3d. |
| 3855 | SetLayerPropertiesForTesting(parent.get(), |
| 3856 | identity_matrix, |
| 3857 | identity_matrix, |
| 3858 | gfx::PointF(), |
| 3859 | gfx::PointF(), |
| 3860 | gfx::Size(100, 100), |
| 3861 | false); // parent transform style is flat. |
| 3862 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3863 | identity_matrix, |
| 3864 | identity_matrix, |
| 3865 | gfx::PointF(), |
| 3866 | gfx::PointF(), |
| 3867 | gfx::Size(100, 100), |
| 3868 | false); |
| 3869 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3870 | backface_matrix, |
| 3871 | identity_matrix, |
| 3872 | gfx::PointF(), |
| 3873 | gfx::PointF(), |
| 3874 | gfx::Size(100, 100), |
| 3875 | false); |
| 3876 | SetLayerPropertiesForTesting( |
| 3877 | front_facing_surface.get(), |
| 3878 | identity_matrix, |
| 3879 | identity_matrix, |
| 3880 | gfx::PointF(), |
| 3881 | gfx::PointF(), |
| 3882 | gfx::Size(100, 100), |
| 3883 | true); // surface transform style is preserve-3d. |
| 3884 | SetLayerPropertiesForTesting( |
| 3885 | back_facing_surface.get(), |
| 3886 | backface_matrix, |
| 3887 | identity_matrix, |
| 3888 | gfx::PointF(), |
| 3889 | gfx::PointF(), |
| 3890 | gfx::Size(100, 100), |
| 3891 | true); // surface transform style is preserve-3d. |
| 3892 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3893 | identity_matrix, |
| 3894 | identity_matrix, |
| 3895 | gfx::PointF(), |
| 3896 | gfx::PointF(), |
| 3897 | gfx::Size(100, 100), |
| 3898 | false); |
| 3899 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3900 | backface_matrix, |
| 3901 | identity_matrix, |
| 3902 | gfx::PointF(), |
| 3903 | gfx::PointF(), |
| 3904 | gfx::Size(100, 100), |
| 3905 | false); |
| 3906 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3907 | identity_matrix, |
| 3908 | identity_matrix, |
| 3909 | gfx::PointF(), |
| 3910 | gfx::PointF(), |
| 3911 | gfx::Size(100, 100), |
| 3912 | false); |
| 3913 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3914 | backface_matrix, |
| 3915 | identity_matrix, |
| 3916 | gfx::PointF(), |
| 3917 | gfx::PointF(), |
| 3918 | gfx::Size(100, 100), |
| 3919 | false); |
| 3920 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 3921 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3922 | int dummy_max_texture_size = 512; |
| 3923 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 3924 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 3925 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3926 | 1.f, |
| 3927 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 3928 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3929 | dummy_max_texture_size, |
| 3930 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 3931 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3932 | &render_surface_layer_list); |
| 3933 | |
| 3934 | // Verify which render surfaces were created. |
| 3935 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3936 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3937 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3938 | EXPECT_FALSE(back_facing_surface->render_surface()); |
| 3939 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3940 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3941 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3942 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3943 | |
| 3944 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3945 | // culled. |
| 3946 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
| 3947 | EXPECT_EQ(parent->id(), render_surface_layer_list[0]->id()); |
| 3948 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list[1]->id()); |
| 3949 | |
| 3950 | // Verify root surface's layer list. |
| 3951 | ASSERT_EQ( |
| 3952 | 2u, render_surface_layer_list[0]->render_surface()->layer_list().size()); |
| 3953 | EXPECT_EQ( |
| 3954 | front_facing_child->id(), |
| 3955 | render_surface_layer_list[0]->render_surface()->layer_list()[0]->id()); |
| 3956 | EXPECT_EQ( |
| 3957 | front_facing_surface->id(), |
| 3958 | render_surface_layer_list[0]->render_surface()->layer_list()[1]->id()); |
| 3959 | |
| 3960 | // Verify front_facing_surface's layer list. |
| 3961 | ASSERT_EQ( |
| 3962 | 2u, render_surface_layer_list[1]->render_surface()->layer_list().size()); |
| 3963 | EXPECT_EQ( |
| 3964 | front_facing_surface->id(), |
| 3965 | render_surface_layer_list[1]->render_surface()->layer_list()[0]->id()); |
| 3966 | EXPECT_EQ( |
| 3967 | front_facing_child_of_front_facing_surface->id(), |
| 3968 | render_surface_layer_list[1]->render_surface()->layer_list()[1]->id()); |
| 3969 | } |
| 3970 | |
| 3971 | TEST(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
| 3972 | // Verify that layers are appropriately culled when their back face is showing |
| 3973 | // and they are not double sided, while animations are going on. |
| 3974 | // |
| 3975 | // Layers that are animating do not get culled on the main thread, as their |
| 3976 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3977 | // back face is really showing. |
| 3978 | const gfx::Transform identity_matrix; |
| 3979 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3980 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3981 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3982 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3983 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3984 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3985 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3986 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3987 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3988 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3989 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3990 | |
| 3991 | parent->AddChild(child); |
| 3992 | parent->AddChild(animating_surface); |
| 3993 | animating_surface->AddChild(child_of_animating_surface); |
| 3994 | parent->AddChild(animating_child); |
| 3995 | parent->AddChild(child2); |
| 3996 | |
| 3997 | // Nothing is double-sided |
| 3998 | child->SetDoubleSided(false); |
| 3999 | child2->SetDoubleSided(false); |
| 4000 | animating_surface->SetDoubleSided(false); |
| 4001 | child_of_animating_surface->SetDoubleSided(false); |
| 4002 | animating_child->SetDoubleSided(false); |
| 4003 | |
| 4004 | gfx::Transform backface_matrix; |
| 4005 | backface_matrix.Translate(50.0, 50.0); |
| 4006 | backface_matrix.RotateAboutYAxis(180.0); |
| 4007 | backface_matrix.Translate(-50.0, -50.0); |
| 4008 | |
| 4009 | // Make our render surface. |
| 4010 | animating_surface->SetForceRenderSurface(true); |
| 4011 | |
| 4012 | // Animate the transform on the render surface. |
| 4013 | AddAnimatedTransformToController( |
| 4014 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 4015 | // This is just an animating layer, not a surface. |
| 4016 | AddAnimatedTransformToController( |
| 4017 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 4018 | |
| 4019 | SetLayerPropertiesForTesting(parent.get(), |
| 4020 | identity_matrix, |
| 4021 | identity_matrix, |
| 4022 | gfx::PointF(), |
| 4023 | gfx::PointF(), |
| 4024 | gfx::Size(100, 100), |
| 4025 | false); |
| 4026 | SetLayerPropertiesForTesting(child.get(), |
| 4027 | backface_matrix, |
| 4028 | identity_matrix, |
| 4029 | gfx::PointF(), |
| 4030 | gfx::PointF(), |
| 4031 | gfx::Size(100, 100), |
| 4032 | false); |
| 4033 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 4034 | backface_matrix, |
| 4035 | identity_matrix, |
| 4036 | gfx::PointF(), |
| 4037 | gfx::PointF(), |
| 4038 | gfx::Size(100, 100), |
| 4039 | false); |
| 4040 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 4041 | backface_matrix, |
| 4042 | identity_matrix, |
| 4043 | gfx::PointF(), |
| 4044 | gfx::PointF(), |
| 4045 | gfx::Size(100, 100), |
| 4046 | false); |
| 4047 | SetLayerPropertiesForTesting(animating_child.get(), |
| 4048 | backface_matrix, |
| 4049 | identity_matrix, |
| 4050 | gfx::PointF(), |
| 4051 | gfx::PointF(), |
| 4052 | gfx::Size(100, 100), |
| 4053 | false); |
| 4054 | SetLayerPropertiesForTesting(child2.get(), |
| 4055 | identity_matrix, |
| 4056 | identity_matrix, |
| 4057 | gfx::PointF(), |
| 4058 | gfx::PointF(), |
| 4059 | gfx::Size(100, 100), |
| 4060 | false); |
| 4061 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4062 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4063 | int dummy_max_texture_size = 512; |
| 4064 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 4065 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4066 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4067 | 1.f, |
| 4068 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4069 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4070 | dummy_max_texture_size, |
| 4071 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4072 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4073 | &render_surface_layer_list); |
| 4074 | |
| 4075 | EXPECT_FALSE(child->render_surface()); |
| 4076 | EXPECT_TRUE(animating_surface->render_surface()); |
| 4077 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 4078 | EXPECT_FALSE(animating_child->render_surface()); |
| 4079 | EXPECT_FALSE(child2->render_surface()); |
| 4080 | |
| 4081 | // Verify that the animating_child and child_of_animating_surface were not |
| 4082 | // culled, but that child was. |
| 4083 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
| 4084 | EXPECT_EQ(parent->id(), render_surface_layer_list[0]->id()); |
| 4085 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list[1]->id()); |
| 4086 | |
| 4087 | // The non-animating child be culled from the layer list for the parent render |
| 4088 | // surface. |
| 4089 | ASSERT_EQ( |
| 4090 | 3u, render_surface_layer_list[0]->render_surface()->layer_list().size()); |
| 4091 | EXPECT_EQ( |
| 4092 | animating_surface->id(), |
| 4093 | render_surface_layer_list[0]->render_surface()->layer_list()[0]->id()); |
| 4094 | EXPECT_EQ( |
| 4095 | animating_child->id(), |
| 4096 | render_surface_layer_list[0]->render_surface()->layer_list()[1]->id()); |
| 4097 | EXPECT_EQ( |
| 4098 | child2->id(), |
| 4099 | render_surface_layer_list[0]->render_surface()->layer_list()[2]->id()); |
| 4100 | |
| 4101 | ASSERT_EQ( |
| 4102 | 2u, render_surface_layer_list[1]->render_surface()->layer_list().size()); |
| 4103 | EXPECT_EQ( |
| 4104 | animating_surface->id(), |
| 4105 | render_surface_layer_list[1]->render_surface()->layer_list()[0]->id()); |
| 4106 | EXPECT_EQ( |
| 4107 | child_of_animating_surface->id(), |
| 4108 | render_surface_layer_list[1]->render_surface()->layer_list()[1]->id()); |
| 4109 | |
| 4110 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 4111 | |
| 4112 | // The animating layers should have a visible content rect that represents the |
| 4113 | // area of the front face that is within the viewport. |
| 4114 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4115 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4116 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4117 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4118 | // And layers in the subtree of the animating layer should have valid visible |
| 4119 | // content rects also. |
| 4120 | EXPECT_EQ( |
| 4121 | child_of_animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4122 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | TEST(LayerTreeHostCommonTest, |
| 4126 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4127 | // Verify the behavior of back-face culling for a render surface that is |
| 4128 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4129 | |
| 4130 | const gfx::Transform identity_matrix; |
| 4131 | scoped_refptr<Layer> parent = Layer::Create(); |
| 4132 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 4133 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4134 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 4135 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4136 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 4137 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4138 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 4139 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4140 | |
| 4141 | parent->AddChild(front_facing_surface); |
| 4142 | parent->AddChild(back_facing_surface); |
| 4143 | front_facing_surface->AddChild(child1); |
| 4144 | back_facing_surface->AddChild(child2); |
| 4145 | |
| 4146 | // RenderSurfaces are not double-sided |
| 4147 | front_facing_surface->SetDoubleSided(false); |
| 4148 | back_facing_surface->SetDoubleSided(false); |
| 4149 | |
| 4150 | gfx::Transform backface_matrix; |
| 4151 | backface_matrix.Translate(50.0, 50.0); |
| 4152 | backface_matrix.RotateAboutYAxis(180.0); |
| 4153 | backface_matrix.Translate(-50.0, -50.0); |
| 4154 | |
| 4155 | SetLayerPropertiesForTesting(parent.get(), |
| 4156 | identity_matrix, |
| 4157 | identity_matrix, |
| 4158 | gfx::PointF(), |
| 4159 | gfx::PointF(), |
| 4160 | gfx::Size(100, 100), |
| 4161 | true); // parent transform style is preserve3d. |
| 4162 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4163 | identity_matrix, |
| 4164 | identity_matrix, |
| 4165 | gfx::PointF(), |
| 4166 | gfx::PointF(), |
| 4167 | gfx::Size(100, 100), |
| 4168 | false); // surface transform style is flat. |
| 4169 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4170 | backface_matrix, |
| 4171 | identity_matrix, |
| 4172 | gfx::PointF(), |
| 4173 | gfx::PointF(), |
| 4174 | gfx::Size(100, 100), |
| 4175 | false); // surface transform style is flat. |
| 4176 | SetLayerPropertiesForTesting(child1.get(), |
| 4177 | identity_matrix, |
| 4178 | identity_matrix, |
| 4179 | gfx::PointF(), |
| 4180 | gfx::PointF(), |
| 4181 | gfx::Size(100, 100), |
| 4182 | false); |
| 4183 | SetLayerPropertiesForTesting(child2.get(), |
| 4184 | identity_matrix, |
| 4185 | identity_matrix, |
| 4186 | gfx::PointF(), |
| 4187 | gfx::PointF(), |
| 4188 | gfx::Size(100, 100), |
| 4189 | false); |
| 4190 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4191 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4192 | int dummy_max_texture_size = 512; |
| 4193 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 4194 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4195 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4196 | 1.f, |
| 4197 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4198 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4199 | dummy_max_texture_size, |
| 4200 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4201 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4202 | &render_surface_layer_list); |
| 4203 | |
| 4204 | // Verify which render surfaces were created. |
| 4205 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 4206 | EXPECT_FALSE( |
| 4207 | back_facing_surface->render_surface()); // because it should be culled |
| 4208 | EXPECT_FALSE(child1->render_surface()); |
| 4209 | EXPECT_FALSE(child2->render_surface()); |
| 4210 | |
| 4211 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4212 | // culled. |
| 4213 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
| 4214 | EXPECT_EQ(parent->id(), render_surface_layer_list[0]->id()); |
| 4215 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list[1]->id()); |
| 4216 | |
| 4217 | // Verify root surface's layer list. |
| 4218 | ASSERT_EQ( |
| 4219 | 1u, render_surface_layer_list[0]->render_surface()->layer_list().size()); |
| 4220 | EXPECT_EQ( |
| 4221 | front_facing_surface->id(), |
| 4222 | render_surface_layer_list[0]->render_surface()->layer_list()[0]->id()); |
| 4223 | |
| 4224 | // Verify front_facing_surface's layer list. |
| 4225 | ASSERT_EQ( |
| 4226 | 2u, render_surface_layer_list[1]->render_surface()->layer_list().size()); |
| 4227 | EXPECT_EQ( |
| 4228 | front_facing_surface->id(), |
| 4229 | render_surface_layer_list[1]->render_surface()->layer_list()[0]->id()); |
| 4230 | EXPECT_EQ( |
| 4231 | child1->id(), |
| 4232 | render_surface_layer_list[1]->render_surface()->layer_list()[1]->id()); |
| 4233 | } |
| 4234 | |
| 4235 | TEST(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) { |
| 4236 | // Hit testing on an empty render_surface_layer_list should return a null |
| 4237 | // pointer. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4238 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4239 | |
| 4240 | gfx::Point test_point(0, 0); |
| 4241 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4242 | test_point, render_surface_layer_list); |
| 4243 | EXPECT_FALSE(result_layer); |
| 4244 | |
| 4245 | test_point = gfx::Point(10, 20); |
| 4246 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4247 | test_point, render_surface_layer_list); |
| 4248 | EXPECT_FALSE(result_layer); |
| 4249 | } |
| 4250 | |
| 4251 | TEST(LayerTreeHostCommonTest, HitTestingForSingleLayer) { |
| 4252 | FakeImplProxy proxy; |
| 4253 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4254 | scoped_ptr<LayerImpl> root = |
| 4255 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4256 | |
| 4257 | gfx::Transform identity_matrix; |
| 4258 | gfx::PointF anchor; |
| 4259 | gfx::PointF position; |
| 4260 | gfx::Size bounds(100, 100); |
| 4261 | SetLayerPropertiesForTesting(root.get(), |
| 4262 | identity_matrix, |
| 4263 | identity_matrix, |
| 4264 | anchor, |
| 4265 | position, |
| 4266 | bounds, |
| 4267 | false); |
| 4268 | root->SetDrawsContent(true); |
| 4269 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4270 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4271 | int dummy_max_texture_size = 512; |
| 4272 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4273 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4274 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4275 | 1.f, |
| 4276 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4277 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4278 | dummy_max_texture_size, |
| 4279 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4280 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4281 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4282 | |
| 4283 | // Sanity check the scenario we just created. |
| 4284 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4285 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4286 | |
| 4287 | // Hit testing for a point outside the layer should return a null pointer. |
| 4288 | gfx::Point test_point(101, 101); |
| 4289 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4290 | test_point, render_surface_layer_list); |
| 4291 | EXPECT_FALSE(result_layer); |
| 4292 | |
| 4293 | test_point = gfx::Point(-1, -1); |
| 4294 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4295 | test_point, render_surface_layer_list); |
| 4296 | EXPECT_FALSE(result_layer); |
| 4297 | |
| 4298 | // Hit testing for a point inside should return the root layer. |
| 4299 | test_point = gfx::Point(1, 1); |
| 4300 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4301 | test_point, render_surface_layer_list); |
| 4302 | ASSERT_TRUE(result_layer); |
| 4303 | EXPECT_EQ(12345, result_layer->id()); |
| 4304 | |
| 4305 | test_point = gfx::Point(99, 99); |
| 4306 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4307 | test_point, render_surface_layer_list); |
| 4308 | ASSERT_TRUE(result_layer); |
| 4309 | EXPECT_EQ(12345, result_layer->id()); |
| 4310 | } |
| 4311 | |
| 4312 | TEST(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) { |
| 4313 | FakeImplProxy proxy; |
| 4314 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4315 | scoped_ptr<LayerImpl> root = |
| 4316 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4317 | scoped_ptr<HeadsUpDisplayLayerImpl> hud = |
| 4318 | HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111); |
| 4319 | |
| 4320 | gfx::Transform identity_matrix; |
| 4321 | gfx::PointF anchor; |
| 4322 | gfx::PointF position; |
| 4323 | gfx::Size bounds(100, 100); |
| 4324 | SetLayerPropertiesForTesting(root.get(), |
| 4325 | identity_matrix, |
| 4326 | identity_matrix, |
| 4327 | anchor, |
| 4328 | position, |
| 4329 | bounds, |
| 4330 | false); |
| 4331 | root->SetDrawsContent(true); |
| 4332 | |
| 4333 | // Create hud and add it as a child of root. |
| 4334 | gfx::Size hud_bounds(200, 200); |
| 4335 | SetLayerPropertiesForTesting(hud.get(), |
| 4336 | identity_matrix, |
| 4337 | identity_matrix, |
| 4338 | anchor, |
| 4339 | position, |
| 4340 | hud_bounds, |
| 4341 | false); |
| 4342 | hud->SetDrawsContent(true); |
| 4343 | |
| 4344 | host_impl.active_tree()->set_hud_layer(hud.get()); |
| 4345 | root->AddChild(hud.PassAs<LayerImpl>()); |
| 4346 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4347 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4348 | int dummy_max_texture_size = 512; |
| 4349 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4350 | hud_bounds, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4351 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4352 | 1.f, |
| 4353 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4354 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4355 | dummy_max_texture_size, |
| 4356 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4357 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4358 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4359 | |
| 4360 | // Sanity check the scenario we just created. |
| 4361 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4362 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 4363 | |
| 4364 | // Hit testing for a point inside HUD, but outside root should return null |
| 4365 | gfx::Point test_point(101, 101); |
| 4366 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4367 | test_point, render_surface_layer_list); |
| 4368 | EXPECT_FALSE(result_layer); |
| 4369 | |
| 4370 | test_point = gfx::Point(-1, -1); |
| 4371 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4372 | test_point, render_surface_layer_list); |
| 4373 | EXPECT_FALSE(result_layer); |
| 4374 | |
| 4375 | // Hit testing for a point inside should return the root layer, never the HUD |
| 4376 | // layer. |
| 4377 | test_point = gfx::Point(1, 1); |
| 4378 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4379 | test_point, render_surface_layer_list); |
| 4380 | ASSERT_TRUE(result_layer); |
| 4381 | EXPECT_EQ(12345, result_layer->id()); |
| 4382 | |
| 4383 | test_point = gfx::Point(99, 99); |
| 4384 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4385 | test_point, render_surface_layer_list); |
| 4386 | ASSERT_TRUE(result_layer); |
| 4387 | EXPECT_EQ(12345, result_layer->id()); |
| 4388 | } |
| 4389 | |
| 4390 | TEST(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) { |
| 4391 | FakeImplProxy proxy; |
| 4392 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4393 | scoped_ptr<LayerImpl> root = |
| 4394 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4395 | |
| 4396 | gfx::Transform uninvertible_transform; |
| 4397 | uninvertible_transform.matrix().setDouble(0, 0, 0.0); |
| 4398 | uninvertible_transform.matrix().setDouble(1, 1, 0.0); |
| 4399 | uninvertible_transform.matrix().setDouble(2, 2, 0.0); |
| 4400 | uninvertible_transform.matrix().setDouble(3, 3, 0.0); |
| 4401 | ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
| 4402 | |
| 4403 | gfx::Transform identity_matrix; |
| 4404 | gfx::PointF anchor; |
| 4405 | gfx::PointF position; |
| 4406 | gfx::Size bounds(100, 100); |
| 4407 | SetLayerPropertiesForTesting(root.get(), |
| 4408 | uninvertible_transform, |
| 4409 | identity_matrix, |
| 4410 | anchor, |
| 4411 | position, |
| 4412 | bounds, |
| 4413 | false); |
| 4414 | root->SetDrawsContent(true); |
| 4415 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4416 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4417 | int dummy_max_texture_size = 512; |
| 4418 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4419 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4420 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4421 | 1.f, |
| 4422 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4423 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4424 | dummy_max_texture_size, |
| 4425 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4426 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4427 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4428 | |
| 4429 | // Sanity check the scenario we just created. |
| 4430 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4431 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4432 | ASSERT_FALSE(root->screen_space_transform().IsInvertible()); |
| 4433 | |
| 4434 | // Hit testing any point should not hit the layer. If the invertible matrix is |
| 4435 | // accidentally ignored and treated like an identity, then the hit testing |
| 4436 | // will incorrectly hit the layer when it shouldn't. |
| 4437 | gfx::Point test_point(1, 1); |
| 4438 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4439 | test_point, render_surface_layer_list); |
| 4440 | EXPECT_FALSE(result_layer); |
| 4441 | |
| 4442 | test_point = gfx::Point(10, 10); |
| 4443 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4444 | test_point, render_surface_layer_list); |
| 4445 | EXPECT_FALSE(result_layer); |
| 4446 | |
| 4447 | test_point = gfx::Point(10, 30); |
| 4448 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4449 | test_point, render_surface_layer_list); |
| 4450 | EXPECT_FALSE(result_layer); |
| 4451 | |
| 4452 | test_point = gfx::Point(50, 50); |
| 4453 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4454 | test_point, render_surface_layer_list); |
| 4455 | EXPECT_FALSE(result_layer); |
| 4456 | |
| 4457 | test_point = gfx::Point(67, 48); |
| 4458 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4459 | test_point, render_surface_layer_list); |
| 4460 | EXPECT_FALSE(result_layer); |
| 4461 | |
| 4462 | test_point = gfx::Point(99, 99); |
| 4463 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4464 | test_point, render_surface_layer_list); |
| 4465 | EXPECT_FALSE(result_layer); |
| 4466 | |
| 4467 | test_point = gfx::Point(-1, -1); |
| 4468 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4469 | test_point, render_surface_layer_list); |
| 4470 | EXPECT_FALSE(result_layer); |
| 4471 | } |
| 4472 | |
| 4473 | TEST(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) { |
| 4474 | FakeImplProxy proxy; |
| 4475 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4476 | scoped_ptr<LayerImpl> root = |
| 4477 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4478 | |
| 4479 | gfx::Transform identity_matrix; |
| 4480 | gfx::PointF anchor; |
| 4481 | // this layer is positioned, and hit testing should correctly know where the |
| 4482 | // layer is located. |
| 4483 | gfx::PointF position(50.f, 50.f); |
| 4484 | gfx::Size bounds(100, 100); |
| 4485 | SetLayerPropertiesForTesting(root.get(), |
| 4486 | identity_matrix, |
| 4487 | identity_matrix, |
| 4488 | anchor, |
| 4489 | position, |
| 4490 | bounds, |
| 4491 | false); |
| 4492 | root->SetDrawsContent(true); |
| 4493 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4494 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4495 | int dummy_max_texture_size = 512; |
| 4496 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4497 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4498 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4499 | 1.f, |
| 4500 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4501 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4502 | dummy_max_texture_size, |
| 4503 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4504 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4505 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4506 | |
| 4507 | // Sanity check the scenario we just created. |
| 4508 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4509 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4510 | |
| 4511 | // Hit testing for a point outside the layer should return a null pointer. |
| 4512 | gfx::Point test_point(49, 49); |
| 4513 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4514 | test_point, render_surface_layer_list); |
| 4515 | EXPECT_FALSE(result_layer); |
| 4516 | |
| 4517 | // Even though the layer exists at (101, 101), it should not be visible there |
| 4518 | // since the root render surface would clamp it. |
| 4519 | test_point = gfx::Point(101, 101); |
| 4520 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4521 | test_point, render_surface_layer_list); |
| 4522 | EXPECT_FALSE(result_layer); |
| 4523 | |
| 4524 | // Hit testing for a point inside should return the root layer. |
| 4525 | test_point = gfx::Point(51, 51); |
| 4526 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4527 | test_point, render_surface_layer_list); |
| 4528 | ASSERT_TRUE(result_layer); |
| 4529 | EXPECT_EQ(12345, result_layer->id()); |
| 4530 | |
| 4531 | test_point = gfx::Point(99, 99); |
| 4532 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4533 | test_point, render_surface_layer_list); |
| 4534 | ASSERT_TRUE(result_layer); |
| 4535 | EXPECT_EQ(12345, result_layer->id()); |
| 4536 | } |
| 4537 | |
| 4538 | TEST(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) { |
| 4539 | FakeImplProxy proxy; |
| 4540 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4541 | scoped_ptr<LayerImpl> root = |
| 4542 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4543 | |
| 4544 | gfx::Transform identity_matrix; |
| 4545 | gfx::Transform rotation45_degrees_about_center; |
| 4546 | rotation45_degrees_about_center.Translate(50.0, 50.0); |
| 4547 | rotation45_degrees_about_center.RotateAboutZAxis(45.0); |
| 4548 | rotation45_degrees_about_center.Translate(-50.0, -50.0); |
| 4549 | gfx::PointF anchor; |
| 4550 | gfx::PointF position; |
| 4551 | gfx::Size bounds(100, 100); |
| 4552 | SetLayerPropertiesForTesting(root.get(), |
| 4553 | rotation45_degrees_about_center, |
| 4554 | identity_matrix, |
| 4555 | anchor, |
| 4556 | position, |
| 4557 | bounds, |
| 4558 | false); |
| 4559 | root->SetDrawsContent(true); |
| 4560 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4561 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4562 | int dummy_max_texture_size = 512; |
| 4563 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4564 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4565 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4566 | 1.f, |
| 4567 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4568 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4569 | dummy_max_texture_size, |
| 4570 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4571 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4572 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4573 | |
| 4574 | // Sanity check the scenario we just created. |
| 4575 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4576 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4577 | |
| 4578 | // Hit testing for points outside the layer. |
| 4579 | // These corners would have been inside the un-transformed layer, but they |
| 4580 | // should not hit the correctly transformed layer. |
| 4581 | gfx::Point test_point(99, 99); |
| 4582 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4583 | test_point, render_surface_layer_list); |
| 4584 | EXPECT_FALSE(result_layer); |
| 4585 | |
| 4586 | test_point = gfx::Point(1, 1); |
| 4587 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4588 | test_point, render_surface_layer_list); |
| 4589 | EXPECT_FALSE(result_layer); |
| 4590 | |
| 4591 | // Hit testing for a point inside should return the root layer. |
| 4592 | test_point = gfx::Point(1, 50); |
| 4593 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4594 | test_point, render_surface_layer_list); |
| 4595 | ASSERT_TRUE(result_layer); |
| 4596 | EXPECT_EQ(12345, result_layer->id()); |
| 4597 | |
| 4598 | // Hit testing the corners that would overlap the unclipped layer, but are |
| 4599 | // outside the clipped region. |
| 4600 | test_point = gfx::Point(50, -1); |
| 4601 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4602 | test_point, render_surface_layer_list); |
| 4603 | ASSERT_FALSE(result_layer); |
| 4604 | |
| 4605 | test_point = gfx::Point(-1, 50); |
| 4606 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4607 | test_point, render_surface_layer_list); |
| 4608 | ASSERT_FALSE(result_layer); |
| 4609 | } |
| 4610 | |
| 4611 | TEST(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) { |
| 4612 | FakeImplProxy proxy; |
| 4613 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4614 | scoped_ptr<LayerImpl> root = |
| 4615 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4616 | |
| 4617 | gfx::Transform identity_matrix; |
| 4618 | |
| 4619 | // perspective_projection_about_center * translation_by_z is designed so that |
| 4620 | // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). |
| 4621 | gfx::Transform perspective_projection_about_center; |
| 4622 | perspective_projection_about_center.Translate(50.0, 50.0); |
| 4623 | perspective_projection_about_center.ApplyPerspectiveDepth(1.0); |
| 4624 | perspective_projection_about_center.Translate(-50.0, -50.0); |
| 4625 | gfx::Transform translation_by_z; |
| 4626 | translation_by_z.Translate3d(0.0, 0.0, -1.0); |
| 4627 | |
| 4628 | gfx::PointF anchor; |
| 4629 | gfx::PointF position; |
| 4630 | gfx::Size bounds(100, 100); |
| 4631 | SetLayerPropertiesForTesting( |
| 4632 | root.get(), |
| 4633 | perspective_projection_about_center * translation_by_z, |
| 4634 | identity_matrix, |
| 4635 | anchor, |
| 4636 | position, |
| 4637 | bounds, |
| 4638 | false); |
| 4639 | root->SetDrawsContent(true); |
| 4640 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4641 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4642 | int dummy_max_texture_size = 512; |
| 4643 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4644 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4645 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4646 | 1.f, |
| 4647 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4648 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4649 | dummy_max_texture_size, |
| 4650 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4651 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4652 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4653 | |
| 4654 | // Sanity check the scenario we just created. |
| 4655 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4656 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4657 | |
| 4658 | // Hit testing for points outside the layer. |
| 4659 | // These corners would have been inside the un-transformed layer, but they |
| 4660 | // should not hit the correctly transformed layer. |
| 4661 | gfx::Point test_point(24, 24); |
| 4662 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4663 | test_point, render_surface_layer_list); |
| 4664 | EXPECT_FALSE(result_layer); |
| 4665 | |
| 4666 | test_point = gfx::Point(76, 76); |
| 4667 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4668 | test_point, render_surface_layer_list); |
| 4669 | EXPECT_FALSE(result_layer); |
| 4670 | |
| 4671 | // Hit testing for a point inside should return the root layer. |
| 4672 | test_point = gfx::Point(26, 26); |
| 4673 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4674 | test_point, render_surface_layer_list); |
| 4675 | ASSERT_TRUE(result_layer); |
| 4676 | EXPECT_EQ(12345, result_layer->id()); |
| 4677 | |
| 4678 | test_point = gfx::Point(74, 74); |
| 4679 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4680 | test_point, render_surface_layer_list); |
| 4681 | ASSERT_TRUE(result_layer); |
| 4682 | EXPECT_EQ(12345, result_layer->id()); |
| 4683 | } |
| 4684 | |
| 4685 | TEST(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) { |
| 4686 | // A layer's visible content rect is actually in the layer's content space. |
| 4687 | // The screen space transform converts from the layer's origin space to screen |
| 4688 | // space. This test makes sure that hit testing works correctly accounts for |
| 4689 | // the contents scale. A contents scale that is not 1 effectively forces a |
| 4690 | // non-identity transform between layer's content space and layer's origin |
| 4691 | // space. The hit testing code must take this into account. |
| 4692 | // |
| 4693 | // To test this, the layer is positioned at (25, 25), and is size (50, 50). If |
| 4694 | // contents scale is ignored, then hit testing will mis-interpret the visible |
| 4695 | // content rect as being larger than the actual bounds of the layer. |
| 4696 | // |
| 4697 | FakeImplProxy proxy; |
| 4698 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4699 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4700 | |
| 4701 | gfx::Transform identity_matrix; |
| 4702 | gfx::PointF anchor; |
| 4703 | |
| 4704 | SetLayerPropertiesForTesting(root.get(), |
| 4705 | identity_matrix, |
| 4706 | identity_matrix, |
| 4707 | anchor, |
| 4708 | gfx::PointF(), |
| 4709 | gfx::Size(100, 100), |
| 4710 | false); |
| 4711 | { |
| 4712 | gfx::PointF position(25.f, 25.f); |
| 4713 | gfx::Size bounds(50, 50); |
| 4714 | scoped_ptr<LayerImpl> test_layer = |
| 4715 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4716 | SetLayerPropertiesForTesting(test_layer.get(), |
| 4717 | identity_matrix, |
| 4718 | identity_matrix, |
| 4719 | anchor, |
| 4720 | position, |
| 4721 | bounds, |
| 4722 | false); |
| 4723 | |
| 4724 | // override content bounds and contents scale |
| 4725 | test_layer->SetContentBounds(gfx::Size(100, 100)); |
| 4726 | test_layer->SetContentsScale(2, 2); |
| 4727 | |
| 4728 | test_layer->SetDrawsContent(true); |
| 4729 | root->AddChild(test_layer.Pass()); |
| 4730 | } |
| 4731 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4732 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4733 | int dummy_max_texture_size = 512; |
| 4734 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4735 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4736 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4737 | 1.f, |
| 4738 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4739 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4740 | dummy_max_texture_size, |
| 4741 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4742 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4743 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4744 | |
| 4745 | // Sanity check the scenario we just created. |
| 4746 | // The visible content rect for test_layer is actually 100x100, even though |
| 4747 | // its layout size is 50x50, positioned at 25x25. |
| 4748 | LayerImpl* test_layer = root->children()[0]; |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4749 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4750 | test_layer->visible_content_rect()); |
| 4751 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4752 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4753 | |
| 4754 | // Hit testing for a point outside the layer should return a null pointer (the |
| 4755 | // root layer does not draw content, so it will not be hit tested either). |
| 4756 | gfx::Point test_point(101, 101); |
| 4757 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4758 | test_point, render_surface_layer_list); |
| 4759 | EXPECT_FALSE(result_layer); |
| 4760 | |
| 4761 | test_point = gfx::Point(24, 24); |
| 4762 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4763 | test_point, render_surface_layer_list); |
| 4764 | EXPECT_FALSE(result_layer); |
| 4765 | |
| 4766 | test_point = gfx::Point(76, 76); |
| 4767 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4768 | test_point, render_surface_layer_list); |
| 4769 | EXPECT_FALSE(result_layer); |
| 4770 | |
| 4771 | // Hit testing for a point inside should return the test layer. |
| 4772 | test_point = gfx::Point(26, 26); |
| 4773 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4774 | test_point, render_surface_layer_list); |
| 4775 | ASSERT_TRUE(result_layer); |
| 4776 | EXPECT_EQ(12345, result_layer->id()); |
| 4777 | |
| 4778 | test_point = gfx::Point(74, 74); |
| 4779 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4780 | test_point, render_surface_layer_list); |
| 4781 | ASSERT_TRUE(result_layer); |
| 4782 | EXPECT_EQ(12345, result_layer->id()); |
| 4783 | } |
| 4784 | |
| 4785 | TEST(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) { |
| 4786 | // Test that hit-testing will only work for the visible portion of a layer, |
| 4787 | // and not the entire layer bounds. Here we just test the simple axis-aligned |
| 4788 | // case. |
| 4789 | gfx::Transform identity_matrix; |
| 4790 | gfx::PointF anchor; |
| 4791 | |
| 4792 | FakeImplProxy proxy; |
| 4793 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4794 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4795 | SetLayerPropertiesForTesting(root.get(), |
| 4796 | identity_matrix, |
| 4797 | identity_matrix, |
| 4798 | anchor, |
| 4799 | gfx::PointF(), |
| 4800 | gfx::Size(100, 100), |
| 4801 | false); |
| 4802 | { |
| 4803 | scoped_ptr<LayerImpl> clipping_layer = |
| 4804 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 4805 | // this layer is positioned, and hit testing should correctly know where the |
| 4806 | // layer is located. |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4807 | gfx::PointF position(25.f, 25.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4808 | gfx::Size bounds(50, 50); |
| 4809 | SetLayerPropertiesForTesting(clipping_layer.get(), |
| 4810 | identity_matrix, |
| 4811 | identity_matrix, |
| 4812 | anchor, |
| 4813 | position, |
| 4814 | bounds, |
| 4815 | false); |
| 4816 | clipping_layer->SetMasksToBounds(true); |
| 4817 | |
| 4818 | scoped_ptr<LayerImpl> child = |
| 4819 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4820 | position = gfx::PointF(-50.f, -50.f); |
| 4821 | bounds = gfx::Size(300, 300); |
| 4822 | SetLayerPropertiesForTesting(child.get(), |
| 4823 | identity_matrix, |
| 4824 | identity_matrix, |
| 4825 | anchor, |
| 4826 | position, |
| 4827 | bounds, |
| 4828 | false); |
| 4829 | child->SetDrawsContent(true); |
| 4830 | clipping_layer->AddChild(child.Pass()); |
| 4831 | root->AddChild(clipping_layer.Pass()); |
| 4832 | } |
| 4833 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4834 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4835 | int dummy_max_texture_size = 512; |
| 4836 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4837 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4838 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4839 | 1.f, |
| 4840 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4841 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4842 | dummy_max_texture_size, |
| 4843 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4844 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4845 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4846 | |
| 4847 | // Sanity check the scenario we just created. |
| 4848 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4849 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4850 | ASSERT_EQ(456, root->render_surface()->layer_list()[0]->id()); |
| 4851 | |
| 4852 | // Hit testing for a point outside the layer should return a null pointer. |
| 4853 | // Despite the child layer being very large, it should be clipped to the root |
| 4854 | // layer's bounds. |
| 4855 | gfx::Point test_point(24, 24); |
| 4856 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4857 | test_point, render_surface_layer_list); |
| 4858 | EXPECT_FALSE(result_layer); |
| 4859 | |
| 4860 | // Even though the layer exists at (101, 101), it should not be visible there |
| 4861 | // since the clipping_layer would clamp it. |
| 4862 | test_point = gfx::Point(76, 76); |
| 4863 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4864 | test_point, render_surface_layer_list); |
| 4865 | EXPECT_FALSE(result_layer); |
| 4866 | |
| 4867 | // Hit testing for a point inside should return the child layer. |
| 4868 | test_point = gfx::Point(26, 26); |
| 4869 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4870 | test_point, render_surface_layer_list); |
| 4871 | ASSERT_TRUE(result_layer); |
| 4872 | EXPECT_EQ(456, result_layer->id()); |
| 4873 | |
| 4874 | test_point = gfx::Point(74, 74); |
| 4875 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4876 | test_point, render_surface_layer_list); |
| 4877 | ASSERT_TRUE(result_layer); |
| 4878 | EXPECT_EQ(456, result_layer->id()); |
| 4879 | } |
| 4880 | |
| 4881 | TEST(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) { |
| 4882 | // This test checks whether hit testing correctly avoids hit testing with |
| 4883 | // multiple ancestors that clip in non axis-aligned ways. To pass this test, |
| 4884 | // the hit testing algorithm needs to recognize that multiple parent layers |
| 4885 | // may clip the layer, and should not actually hit those clipped areas. |
| 4886 | // |
| 4887 | // The child and grand_child layers are both initialized to clip the |
| 4888 | // rotated_leaf. The child layer is rotated about the top-left corner, so that |
| 4889 | // the root + child clips combined create a triangle. The rotated_leaf will |
| 4890 | // only be visible where it overlaps this triangle. |
| 4891 | // |
| 4892 | FakeImplProxy proxy; |
| 4893 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 4894 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123); |
| 4895 | |
| 4896 | gfx::Transform identity_matrix; |
| 4897 | gfx::PointF anchor; |
| 4898 | gfx::PointF position; |
| 4899 | gfx::Size bounds(100, 100); |
| 4900 | SetLayerPropertiesForTesting(root.get(), |
| 4901 | identity_matrix, |
| 4902 | identity_matrix, |
| 4903 | anchor, |
| 4904 | position, |
| 4905 | bounds, |
| 4906 | false); |
| 4907 | root->SetMasksToBounds(true); |
| 4908 | { |
| 4909 | scoped_ptr<LayerImpl> child = |
| 4910 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4911 | scoped_ptr<LayerImpl> grand_child = |
| 4912 | LayerImpl::Create(host_impl.active_tree(), 789); |
| 4913 | scoped_ptr<LayerImpl> rotated_leaf = |
| 4914 | LayerImpl::Create(host_impl.active_tree(), 2468); |
| 4915 | |
| 4916 | position = gfx::PointF(10.f, 10.f); |
| 4917 | bounds = gfx::Size(80, 80); |
| 4918 | SetLayerPropertiesForTesting(child.get(), |
| 4919 | identity_matrix, |
| 4920 | identity_matrix, |
| 4921 | anchor, |
| 4922 | position, |
| 4923 | bounds, |
| 4924 | false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4925 | child->SetMasksToBounds(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4926 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4927 | gfx::Transform rotation45_degrees_about_corner; |
| 4928 | rotation45_degrees_about_corner.RotateAboutZAxis(45.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4929 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4930 | // remember, positioned with respect to its parent which is already at 10, |
| 4931 | // 10 |
| 4932 | position = gfx::PointF(); |
| 4933 | bounds = |
| 4934 | gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100. |
| 4935 | SetLayerPropertiesForTesting(grand_child.get(), |
| 4936 | rotation45_degrees_about_corner, |
| 4937 | identity_matrix, |
| 4938 | anchor, |
| 4939 | position, |
| 4940 | bounds, |
| 4941 | false); |
| 4942 | grand_child->SetMasksToBounds(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4943 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4944 | // Rotates about the center of the layer |
| 4945 | gfx::Transform rotated_leaf_transform; |
| 4946 | rotated_leaf_transform.Translate( |
| 4947 | -10.0, -10.0); // cancel out the grand_parent's position |
| 4948 | rotated_leaf_transform.RotateAboutZAxis( |
| 4949 | -45.0); // cancel out the corner 45-degree rotation of the parent. |
| 4950 | rotated_leaf_transform.Translate(50.0, 50.0); |
| 4951 | rotated_leaf_transform.RotateAboutZAxis(45.0); |
| 4952 | rotated_leaf_transform.Translate(-50.0, -50.0); |
| 4953 | position = gfx::PointF(); |
| 4954 | bounds = gfx::Size(100, 100); |
| 4955 | SetLayerPropertiesForTesting(rotated_leaf.get(), |
| 4956 | rotated_leaf_transform, |
| 4957 | identity_matrix, |
| 4958 | anchor, |
| 4959 | position, |
| 4960 | bounds, |
| 4961 | false); |
| 4962 | rotated_leaf->SetDrawsContent(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4963 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4964 | grand_child->AddChild(rotated_leaf.Pass()); |
| 4965 | child->AddChild(grand_child.Pass()); |
| 4966 | root->AddChild(child.Pass()); |
| 4967 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4968 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4969 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4970 | int dummy_max_texture_size = 512; |
| 4971 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 4972 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 4973 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4974 | 1.f, |
| 4975 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4976 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4977 | dummy_max_texture_size, |
| 4978 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4979 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 4980 | &render_surface_layer_list); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4981 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4982 | // Sanity check the scenario we just created. |
| 4983 | // The grand_child is expected to create a render surface because it |
| 4984 | // masksToBounds and is not axis aligned. |
| 4985 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
| 4986 | ASSERT_EQ( |
| 4987 | 1u, render_surface_layer_list[0]->render_surface()->layer_list().size()); |
| 4988 | ASSERT_EQ(789, |
| 4989 | render_surface_layer_list[0]->render_surface()->layer_list()[0] |
| 4990 | ->id()); // grand_child's surface. |
| 4991 | ASSERT_EQ( |
| 4992 | 1u, render_surface_layer_list[1]->render_surface()->layer_list().size()); |
| 4993 | ASSERT_EQ( |
| 4994 | 2468, |
| 4995 | render_surface_layer_list[1]->render_surface()->layer_list()[0]->id()); |
| 4996 | |
| 4997 | // (11, 89) is close to the the bottom left corner within the clip, but it is |
| 4998 | // not inside the layer. |
| 4999 | gfx::Point test_point(11, 89); |
| 5000 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5001 | test_point, render_surface_layer_list); |
| 5002 | EXPECT_FALSE(result_layer); |
| 5003 | |
| 5004 | // Closer inwards from the bottom left will overlap the layer. |
| 5005 | test_point = gfx::Point(25, 75); |
| 5006 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5007 | test_point, render_surface_layer_list); |
| 5008 | ASSERT_TRUE(result_layer); |
| 5009 | EXPECT_EQ(2468, result_layer->id()); |
| 5010 | |
| 5011 | // (4, 50) is inside the unclipped layer, but that corner of the layer should |
| 5012 | // be clipped away by the grandparent and should not get hit. If hit testing |
| 5013 | // blindly uses visible content rect without considering how parent may clip |
| 5014 | // the layer, then hit testing would accidentally think that the point |
| 5015 | // successfully hits the layer. |
| 5016 | test_point = gfx::Point(4, 50); |
| 5017 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5018 | test_point, render_surface_layer_list); |
| 5019 | EXPECT_FALSE(result_layer); |
| 5020 | |
| 5021 | // (11, 50) is inside the layer and within the clipped area. |
| 5022 | test_point = gfx::Point(11, 50); |
| 5023 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5024 | test_point, render_surface_layer_list); |
| 5025 | ASSERT_TRUE(result_layer); |
| 5026 | EXPECT_EQ(2468, result_layer->id()); |
| 5027 | |
| 5028 | // Around the middle, just to the right and up, would have hit the layer |
| 5029 | // except that that area should be clipped away by the parent. |
| 5030 | test_point = gfx::Point(51, 51); |
| 5031 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5032 | test_point, render_surface_layer_list); |
| 5033 | EXPECT_FALSE(result_layer); |
| 5034 | |
| 5035 | // Around the middle, just to the left and down, should successfully hit the |
| 5036 | // layer. |
| 5037 | test_point = gfx::Point(49, 51); |
| 5038 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5039 | test_point, render_surface_layer_list); |
| 5040 | ASSERT_TRUE(result_layer); |
| 5041 | EXPECT_EQ(2468, result_layer->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 5042 | } |
| 5043 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5044 | TEST(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) { |
| 5045 | // This test checks that hit testing code does not accidentally clip to layer |
| 5046 | // bounds for a layer that actually does not clip. |
| 5047 | gfx::Transform identity_matrix; |
| 5048 | gfx::PointF anchor; |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 5049 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5050 | FakeImplProxy proxy; |
| 5051 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5052 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 5053 | SetLayerPropertiesForTesting(root.get(), |
| 5054 | identity_matrix, |
| 5055 | identity_matrix, |
| 5056 | anchor, |
| 5057 | gfx::PointF(), |
| 5058 | gfx::Size(100, 100), |
| 5059 | false); |
| 5060 | { |
| 5061 | scoped_ptr<LayerImpl> intermediate_layer = |
| 5062 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 5063 | // this layer is positioned, and hit testing should correctly know where the |
| 5064 | // layer is located. |
| 5065 | gfx::PointF position(10.f, 10.f); |
| 5066 | gfx::Size bounds(50, 50); |
| 5067 | SetLayerPropertiesForTesting(intermediate_layer.get(), |
| 5068 | identity_matrix, |
| 5069 | identity_matrix, |
| 5070 | anchor, |
| 5071 | position, |
| 5072 | bounds, |
| 5073 | false); |
| 5074 | // Sanity check the intermediate layer should not clip. |
| 5075 | ASSERT_FALSE(intermediate_layer->masks_to_bounds()); |
| 5076 | ASSERT_FALSE(intermediate_layer->mask_layer()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 5077 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5078 | // The child of the intermediate_layer is translated so that it does not |
| 5079 | // overlap intermediate_layer at all. If child is incorrectly clipped, we |
| 5080 | // would not be able to hit it successfully. |
| 5081 | scoped_ptr<LayerImpl> child = |
| 5082 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 5083 | position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space |
| 5084 | bounds = gfx::Size(20, 20); |
| 5085 | SetLayerPropertiesForTesting(child.get(), |
| 5086 | identity_matrix, |
| 5087 | identity_matrix, |
| 5088 | anchor, |
| 5089 | position, |
| 5090 | bounds, |
| 5091 | false); |
| 5092 | child->SetDrawsContent(true); |
| 5093 | intermediate_layer->AddChild(child.Pass()); |
| 5094 | root->AddChild(intermediate_layer.Pass()); |
| 5095 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 5096 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5097 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5098 | int dummy_max_texture_size = 512; |
| 5099 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 5100 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 5101 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5102 | 1.f, |
| 5103 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5104 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5105 | dummy_max_texture_size, |
| 5106 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5107 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 5108 | &render_surface_layer_list); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 5109 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5110 | // Sanity check the scenario we just created. |
| 5111 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5112 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5113 | ASSERT_EQ(456, root->render_surface()->layer_list()[0]->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 5114 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5115 | // Hit testing for a point outside the layer should return a null pointer. |
| 5116 | gfx::Point test_point(69, 69); |
| 5117 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5118 | test_point, render_surface_layer_list); |
| 5119 | EXPECT_FALSE(result_layer); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 5120 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5121 | test_point = gfx::Point(91, 91); |
| 5122 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5123 | test_point, render_surface_layer_list); |
| 5124 | EXPECT_FALSE(result_layer); |
| 5125 | |
| 5126 | // Hit testing for a point inside should return the child layer. |
| 5127 | test_point = gfx::Point(71, 71); |
| 5128 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5129 | test_point, render_surface_layer_list); |
| 5130 | ASSERT_TRUE(result_layer); |
| 5131 | EXPECT_EQ(456, result_layer->id()); |
| 5132 | |
| 5133 | test_point = gfx::Point(89, 89); |
| 5134 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5135 | test_point, render_surface_layer_list); |
| 5136 | ASSERT_TRUE(result_layer); |
| 5137 | EXPECT_EQ(456, result_layer->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 5138 | } |
| 5139 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5140 | TEST(LayerTreeHostCommonTest, HitTestingForMultipleLayers) { |
| 5141 | FakeImplProxy proxy; |
| 5142 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5143 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5144 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5145 | gfx::Transform identity_matrix; |
| 5146 | gfx::PointF anchor; |
| 5147 | gfx::PointF position; |
| 5148 | gfx::Size bounds(100, 100); |
| 5149 | SetLayerPropertiesForTesting(root.get(), |
| 5150 | identity_matrix, |
| 5151 | identity_matrix, |
| 5152 | anchor, |
| 5153 | position, |
| 5154 | bounds, |
| 5155 | false); |
| 5156 | root->SetDrawsContent(true); |
| 5157 | { |
| 5158 | // child 1 and child2 are initialized to overlap between x=50 and x=60. |
| 5159 | // grand_child is set to overlap both child1 and child2 between y=50 and |
| 5160 | // y=60. The expected stacking order is: (front) child2, (second) |
| 5161 | // grand_child, (third) child1, and (back) the root layer behind all other |
| 5162 | // layers. |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 5163 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5164 | scoped_ptr<LayerImpl> child1 = |
| 5165 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 5166 | scoped_ptr<LayerImpl> child2 = |
| 5167 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 5168 | scoped_ptr<LayerImpl> grand_child1 = |
| 5169 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5170 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5171 | position = gfx::PointF(10.f, 10.f); |
| 5172 | bounds = gfx::Size(50, 50); |
| 5173 | SetLayerPropertiesForTesting(child1.get(), |
| 5174 | identity_matrix, |
| 5175 | identity_matrix, |
| 5176 | anchor, |
| 5177 | position, |
| 5178 | bounds, |
| 5179 | false); |
| 5180 | child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5181 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5182 | position = gfx::PointF(50.f, 10.f); |
| 5183 | bounds = gfx::Size(50, 50); |
| 5184 | SetLayerPropertiesForTesting(child2.get(), |
| 5185 | identity_matrix, |
| 5186 | identity_matrix, |
| 5187 | anchor, |
| 5188 | position, |
| 5189 | bounds, |
| 5190 | false); |
| 5191 | child2->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5192 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5193 | // Remember that grand_child is positioned with respect to its parent (i.e. |
| 5194 | // child1). In screen space, the intended position is (10, 50), with size |
| 5195 | // 100 x 50. |
| 5196 | position = gfx::PointF(0.f, 40.f); |
| 5197 | bounds = gfx::Size(100, 50); |
| 5198 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 5199 | identity_matrix, |
| 5200 | identity_matrix, |
| 5201 | anchor, |
| 5202 | position, |
| 5203 | bounds, |
| 5204 | false); |
| 5205 | grand_child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5206 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5207 | child1->AddChild(grand_child1.Pass()); |
| 5208 | root->AddChild(child1.Pass()); |
| 5209 | root->AddChild(child2.Pass()); |
| 5210 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5211 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5212 | LayerImpl* child1 = root->children()[0]; |
| 5213 | LayerImpl* child2 = root->children()[1]; |
| 5214 | LayerImpl* grand_child1 = child1->children()[0]; |
| 5215 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5216 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5217 | int dummy_max_texture_size = 512; |
| 5218 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 5219 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 5220 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5221 | 1.f, |
| 5222 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5223 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5224 | dummy_max_texture_size, |
| 5225 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5226 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 5227 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5228 | |
| 5229 | // Sanity check the scenario we just created. |
| 5230 | ASSERT_TRUE(child1); |
| 5231 | ASSERT_TRUE(child2); |
| 5232 | ASSERT_TRUE(grand_child1); |
| 5233 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5234 | ASSERT_EQ(4u, root->render_surface()->layer_list().size()); |
| 5235 | ASSERT_EQ(1, root->render_surface()->layer_list()[0]->id()); // root layer |
| 5236 | ASSERT_EQ(2, root->render_surface()->layer_list()[1]->id()); // child1 |
| 5237 | ASSERT_EQ(4, root->render_surface()->layer_list()[2]->id()); // grand_child1 |
| 5238 | ASSERT_EQ(3, root->render_surface()->layer_list()[3]->id()); // child2 |
| 5239 | |
| 5240 | // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
| 5241 | // the root layer. |
| 5242 | gfx::Point test_point = gfx::Point(1, 1); |
| 5243 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5244 | test_point, render_surface_layer_list); |
| 5245 | ASSERT_TRUE(result_layer); |
| 5246 | EXPECT_EQ(1, result_layer->id()); |
| 5247 | |
| 5248 | // At (15, 15), child1 and root are the only layers. child1 is expected to be |
| 5249 | // on top. |
| 5250 | test_point = gfx::Point(15, 15); |
| 5251 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5252 | test_point, render_surface_layer_list); |
| 5253 | ASSERT_TRUE(result_layer); |
| 5254 | EXPECT_EQ(2, result_layer->id()); |
| 5255 | |
| 5256 | // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. |
| 5257 | test_point = gfx::Point(51, 20); |
| 5258 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5259 | test_point, render_surface_layer_list); |
| 5260 | ASSERT_TRUE(result_layer); |
| 5261 | EXPECT_EQ(3, result_layer->id()); |
| 5262 | |
| 5263 | // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on |
| 5264 | // top. |
| 5265 | test_point = gfx::Point(80, 51); |
| 5266 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5267 | test_point, render_surface_layer_list); |
| 5268 | ASSERT_TRUE(result_layer); |
| 5269 | EXPECT_EQ(3, result_layer->id()); |
| 5270 | |
| 5271 | // At (51, 51), all layers overlap each other. child2 is expected to be on top |
| 5272 | // of all other layers. |
| 5273 | test_point = gfx::Point(51, 51); |
| 5274 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5275 | test_point, render_surface_layer_list); |
| 5276 | ASSERT_TRUE(result_layer); |
| 5277 | EXPECT_EQ(3, result_layer->id()); |
| 5278 | |
| 5279 | // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to |
| 5280 | // be on top. |
| 5281 | test_point = gfx::Point(20, 51); |
| 5282 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5283 | test_point, render_surface_layer_list); |
| 5284 | ASSERT_TRUE(result_layer); |
| 5285 | EXPECT_EQ(4, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5286 | } |
| 5287 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5288 | TEST(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) { |
| 5289 | // |
| 5290 | // The geometry is set up similarly to the previous case, but |
| 5291 | // all layers are forced to be render surfaces now. |
| 5292 | // |
| 5293 | FakeImplProxy proxy; |
| 5294 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5295 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5296 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5297 | gfx::Transform identity_matrix; |
| 5298 | gfx::PointF anchor; |
| 5299 | gfx::PointF position; |
| 5300 | gfx::Size bounds(100, 100); |
| 5301 | SetLayerPropertiesForTesting(root.get(), |
| 5302 | identity_matrix, |
| 5303 | identity_matrix, |
| 5304 | anchor, |
| 5305 | position, |
| 5306 | bounds, |
| 5307 | false); |
| 5308 | root->SetDrawsContent(true); |
| 5309 | { |
| 5310 | // child 1 and child2 are initialized to overlap between x=50 and x=60. |
| 5311 | // grand_child is set to overlap both child1 and child2 between y=50 and |
| 5312 | // y=60. The expected stacking order is: (front) child2, (second) |
| 5313 | // grand_child, (third) child1, and (back) the root layer behind all other |
| 5314 | // layers. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5315 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5316 | scoped_ptr<LayerImpl> child1 = |
| 5317 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 5318 | scoped_ptr<LayerImpl> child2 = |
| 5319 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 5320 | scoped_ptr<LayerImpl> grand_child1 = |
| 5321 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5322 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5323 | position = gfx::PointF(10.f, 10.f); |
| 5324 | bounds = gfx::Size(50, 50); |
| 5325 | SetLayerPropertiesForTesting(child1.get(), |
| 5326 | identity_matrix, |
| 5327 | identity_matrix, |
| 5328 | anchor, |
| 5329 | position, |
| 5330 | bounds, |
| 5331 | false); |
| 5332 | child1->SetDrawsContent(true); |
| 5333 | child1->SetForceRenderSurface(true); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 5334 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5335 | position = gfx::PointF(50.f, 10.f); |
| 5336 | bounds = gfx::Size(50, 50); |
| 5337 | SetLayerPropertiesForTesting(child2.get(), |
| 5338 | identity_matrix, |
| 5339 | identity_matrix, |
| 5340 | anchor, |
| 5341 | position, |
| 5342 | bounds, |
| 5343 | false); |
| 5344 | child2->SetDrawsContent(true); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 5345 | child2->SetForceRenderSurface(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5346 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5347 | // Remember that grand_child is positioned with respect to its parent (i.e. |
| 5348 | // child1). In screen space, the intended position is (10, 50), with size |
| 5349 | // 100 x 50. |
| 5350 | position = gfx::PointF(0.f, 40.f); |
| 5351 | bounds = gfx::Size(100, 50); |
| 5352 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 5353 | identity_matrix, |
| 5354 | identity_matrix, |
| 5355 | anchor, |
| 5356 | position, |
| 5357 | bounds, |
| 5358 | false); |
| 5359 | grand_child1->SetDrawsContent(true); |
| 5360 | grand_child1->SetForceRenderSurface(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5361 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5362 | child1->AddChild(grand_child1.Pass()); |
| 5363 | root->AddChild(child1.Pass()); |
| 5364 | root->AddChild(child2.Pass()); |
| 5365 | } |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5366 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5367 | LayerImpl* child1 = root->children()[0]; |
| 5368 | LayerImpl* child2 = root->children()[1]; |
| 5369 | LayerImpl* grand_child1 = child1->children()[0]; |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5370 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5371 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5372 | int dummy_max_texture_size = 512; |
| 5373 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 5374 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 5375 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5376 | 1.f, |
| 5377 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5378 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5379 | dummy_max_texture_size, |
| 5380 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5381 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 5382 | &render_surface_layer_list); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5383 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5384 | // Sanity check the scenario we just created. |
| 5385 | ASSERT_TRUE(child1); |
| 5386 | ASSERT_TRUE(child2); |
| 5387 | ASSERT_TRUE(grand_child1); |
| 5388 | ASSERT_TRUE(child1->render_surface()); |
| 5389 | ASSERT_TRUE(child2->render_surface()); |
| 5390 | ASSERT_TRUE(grand_child1->render_surface()); |
| 5391 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
| 5392 | // The root surface has the root layer, and child1's and child2's render |
| 5393 | // surfaces. |
| 5394 | ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
| 5395 | // The child1 surface has the child1 layer and grand_child1's render surface. |
| 5396 | ASSERT_EQ(2u, child1->render_surface()->layer_list().size()); |
| 5397 | ASSERT_EQ(1u, child2->render_surface()->layer_list().size()); |
| 5398 | ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size()); |
| 5399 | ASSERT_EQ(1, render_surface_layer_list[0]->id()); // root layer |
| 5400 | ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1 |
| 5401 | ASSERT_EQ(4, render_surface_layer_list[2]->id()); // grand_child1 |
| 5402 | ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2 |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5403 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5404 | // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
| 5405 | // the root layer. |
| 5406 | gfx::Point test_point = gfx::Point(1, 1); |
| 5407 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5408 | test_point, render_surface_layer_list); |
| 5409 | ASSERT_TRUE(result_layer); |
| 5410 | EXPECT_EQ(1, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5411 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5412 | // At (15, 15), child1 and root are the only layers. child1 is expected to be |
| 5413 | // on top. |
| 5414 | test_point = gfx::Point(15, 15); |
| 5415 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5416 | test_point, render_surface_layer_list); |
| 5417 | ASSERT_TRUE(result_layer); |
| 5418 | EXPECT_EQ(2, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5419 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5420 | // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. |
| 5421 | test_point = gfx::Point(51, 20); |
| 5422 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5423 | test_point, render_surface_layer_list); |
| 5424 | ASSERT_TRUE(result_layer); |
| 5425 | EXPECT_EQ(3, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5426 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5427 | // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on |
| 5428 | // top. |
| 5429 | test_point = gfx::Point(80, 51); |
| 5430 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5431 | test_point, render_surface_layer_list); |
| 5432 | ASSERT_TRUE(result_layer); |
| 5433 | EXPECT_EQ(3, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5434 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5435 | // At (51, 51), all layers overlap each other. child2 is expected to be on top |
| 5436 | // of all other layers. |
| 5437 | test_point = gfx::Point(51, 51); |
| 5438 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5439 | test_point, render_surface_layer_list); |
| 5440 | ASSERT_TRUE(result_layer); |
| 5441 | EXPECT_EQ(3, result_layer->id()); |
| 5442 | |
| 5443 | // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to |
| 5444 | // be on top. |
| 5445 | test_point = gfx::Point(20, 51); |
| 5446 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5447 | test_point, render_surface_layer_list); |
| 5448 | ASSERT_TRUE(result_layer); |
| 5449 | EXPECT_EQ(4, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5450 | } |
| 5451 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5452 | TEST(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForEmptyLayerList) { |
| 5453 | // Hit checking on an empty render_surface_layer_list should return a null |
| 5454 | // pointer. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5455 | LayerImplList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5456 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5457 | gfx::Point test_point(0, 0); |
| 5458 | LayerImpl* result_layer = |
| 5459 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5460 | test_point, render_surface_layer_list); |
| 5461 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5462 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5463 | test_point = gfx::Point(10, 20); |
| 5464 | result_layer = |
| 5465 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5466 | test_point, render_surface_layer_list); |
| 5467 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5468 | } |
| 5469 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5470 | TEST(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) { |
| 5471 | FakeImplProxy proxy; |
| 5472 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5473 | scoped_ptr<LayerImpl> root = |
| 5474 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5475 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5476 | gfx::Transform identity_matrix; |
| 5477 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5478 | gfx::PointF anchor; |
| 5479 | gfx::PointF position; |
| 5480 | gfx::Size bounds(100, 100); |
| 5481 | SetLayerPropertiesForTesting(root.get(), |
| 5482 | identity_matrix, |
| 5483 | identity_matrix, |
| 5484 | anchor, |
| 5485 | position, |
| 5486 | bounds, |
| 5487 | false); |
| 5488 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5489 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5490 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5491 | int dummy_max_texture_size = 512; |
| 5492 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 5493 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 5494 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5495 | 1.f, |
| 5496 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5497 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5498 | dummy_max_texture_size, |
| 5499 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5500 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 5501 | &render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5502 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5503 | // Sanity check the scenario we just created. |
| 5504 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5505 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5506 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5507 | // Hit checking for any point should return a null pointer for a layer without |
| 5508 | // any touch event handler regions. |
| 5509 | gfx::Point test_point(11, 11); |
| 5510 | LayerImpl* result_layer = |
| 5511 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5512 | test_point, render_surface_layer_list); |
| 5513 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5514 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5515 | root->SetTouchEventHandlerRegion(touch_handler_region); |
| 5516 | // Hit checking for a point outside the layer should return a null pointer. |
| 5517 | test_point = gfx::Point(101, 101); |
| 5518 | result_layer = |
| 5519 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5520 | test_point, render_surface_layer_list); |
| 5521 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5522 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5523 | test_point = gfx::Point(-1, -1); |
| 5524 | result_layer = |
| 5525 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5526 | test_point, render_surface_layer_list); |
| 5527 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5528 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5529 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5530 | // region should return a null pointer. |
| 5531 | test_point = gfx::Point(1, 1); |
| 5532 | result_layer = |
| 5533 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5534 | test_point, render_surface_layer_list); |
| 5535 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5536 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5537 | test_point = gfx::Point(99, 99); |
| 5538 | result_layer = |
| 5539 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5540 | test_point, render_surface_layer_list); |
| 5541 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5542 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5543 | // Hit checking for a point inside the touch event handler region should |
| 5544 | // return the root layer. |
| 5545 | test_point = gfx::Point(11, 11); |
| 5546 | result_layer = |
| 5547 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5548 | test_point, render_surface_layer_list); |
| 5549 | ASSERT_TRUE(result_layer); |
| 5550 | EXPECT_EQ(12345, result_layer->id()); |
| 5551 | |
| 5552 | test_point = gfx::Point(59, 59); |
| 5553 | result_layer = |
| 5554 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5555 | test_point, render_surface_layer_list); |
| 5556 | ASSERT_TRUE(result_layer); |
| 5557 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5558 | } |
| 5559 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5560 | TEST(LayerTreeHostCommonTest, |
| 5561 | HitCheckingTouchHandlerRegionsForUninvertibleTransform) { |
| 5562 | FakeImplProxy proxy; |
| 5563 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5564 | scoped_ptr<LayerImpl> root = |
| 5565 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5566 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5567 | gfx::Transform uninvertible_transform; |
| 5568 | uninvertible_transform.matrix().setDouble(0, 0, 0.0); |
| 5569 | uninvertible_transform.matrix().setDouble(1, 1, 0.0); |
| 5570 | uninvertible_transform.matrix().setDouble(2, 2, 0.0); |
| 5571 | uninvertible_transform.matrix().setDouble(3, 3, 0.0); |
| 5572 | ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5573 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5574 | gfx::Transform identity_matrix; |
| 5575 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5576 | gfx::PointF anchor; |
| 5577 | gfx::PointF position; |
| 5578 | gfx::Size bounds(100, 100); |
| 5579 | SetLayerPropertiesForTesting(root.get(), |
| 5580 | uninvertible_transform, |
| 5581 | identity_matrix, |
| 5582 | anchor, |
| 5583 | position, |
| 5584 | bounds, |
| 5585 | false); |
| 5586 | root->SetDrawsContent(true); |
| 5587 | root->SetTouchEventHandlerRegion(touch_handler_region); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5588 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5589 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5590 | int dummy_max_texture_size = 512; |
| 5591 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 5592 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 5593 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5594 | 1.f, |
| 5595 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5596 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5597 | dummy_max_texture_size, |
| 5598 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5599 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 5600 | &render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5601 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5602 | // Sanity check the scenario we just created. |
| 5603 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5604 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5605 | ASSERT_FALSE(root->screen_space_transform().IsInvertible()); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5606 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5607 | // Hit checking any point should not hit the touch handler region on the |
| 5608 | // layer. If the invertible matrix is accidentally ignored and treated like an |
| 5609 | // identity, then the hit testing will incorrectly hit the layer when it |
| 5610 | // shouldn't. |
| 5611 | gfx::Point test_point(1, 1); |
| 5612 | LayerImpl* result_layer = |
| 5613 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5614 | test_point, render_surface_layer_list); |
| 5615 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5616 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5617 | test_point = gfx::Point(10, 10); |
| 5618 | result_layer = |
| 5619 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5620 | test_point, render_surface_layer_list); |
| 5621 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5622 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5623 | test_point = gfx::Point(10, 30); |
| 5624 | result_layer = |
| 5625 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5626 | test_point, render_surface_layer_list); |
| 5627 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5628 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5629 | test_point = gfx::Point(50, 50); |
| 5630 | result_layer = |
| 5631 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5632 | test_point, render_surface_layer_list); |
| 5633 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5634 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5635 | test_point = gfx::Point(67, 48); |
| 5636 | result_layer = |
| 5637 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5638 | test_point, render_surface_layer_list); |
| 5639 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5640 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5641 | test_point = gfx::Point(99, 99); |
| 5642 | result_layer = |
| 5643 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5644 | test_point, render_surface_layer_list); |
| 5645 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5646 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5647 | test_point = gfx::Point(-1, -1); |
| 5648 | result_layer = |
| 5649 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5650 | test_point, render_surface_layer_list); |
| 5651 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5652 | } |
| 5653 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5654 | TEST(LayerTreeHostCommonTest, |
| 5655 | HitCheckingTouchHandlerRegionsForSinglePositionedLayer) { |
| 5656 | FakeImplProxy proxy; |
| 5657 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5658 | scoped_ptr<LayerImpl> root = |
| 5659 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5660 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5661 | gfx::Transform identity_matrix; |
| 5662 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5663 | gfx::PointF anchor; |
| 5664 | // this layer is positioned, and hit testing should correctly know where the |
| 5665 | // layer is located. |
| 5666 | gfx::PointF position(50.f, 50.f); |
| 5667 | gfx::Size bounds(100, 100); |
| 5668 | SetLayerPropertiesForTesting(root.get(), |
| 5669 | identity_matrix, |
| 5670 | identity_matrix, |
| 5671 | anchor, |
| 5672 | position, |
| 5673 | bounds, |
| 5674 | false); |
| 5675 | root->SetDrawsContent(true); |
| 5676 | root->SetTouchEventHandlerRegion(touch_handler_region); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5677 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5678 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5679 | int dummy_max_texture_size = 512; |
| 5680 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 5681 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 5682 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5683 | 1.f, |
| 5684 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5685 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5686 | dummy_max_texture_size, |
| 5687 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5688 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 5689 | &render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5690 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5691 | // Sanity check the scenario we just created. |
| 5692 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5693 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5694 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5695 | // Hit checking for a point outside the layer should return a null pointer. |
| 5696 | gfx::Point test_point(49, 49); |
| 5697 | LayerImpl* result_layer = |
| 5698 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5699 | test_point, render_surface_layer_list); |
| 5700 | EXPECT_FALSE(result_layer); |
| 5701 | |
| 5702 | // Even though the layer has a touch handler region containing (101, 101), it |
| 5703 | // should not be visible there since the root render surface would clamp it. |
| 5704 | test_point = gfx::Point(101, 101); |
| 5705 | result_layer = |
| 5706 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5707 | test_point, render_surface_layer_list); |
| 5708 | EXPECT_FALSE(result_layer); |
| 5709 | |
| 5710 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5711 | // region should return a null pointer. |
| 5712 | test_point = gfx::Point(51, 51); |
| 5713 | result_layer = |
| 5714 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5715 | test_point, render_surface_layer_list); |
| 5716 | EXPECT_FALSE(result_layer); |
| 5717 | |
| 5718 | // Hit checking for a point inside the touch event handler region should |
| 5719 | // return the root layer. |
| 5720 | test_point = gfx::Point(61, 61); |
| 5721 | result_layer = |
| 5722 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5723 | test_point, render_surface_layer_list); |
| 5724 | ASSERT_TRUE(result_layer); |
| 5725 | EXPECT_EQ(12345, result_layer->id()); |
| 5726 | |
| 5727 | test_point = gfx::Point(99, 99); |
| 5728 | result_layer = |
| 5729 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5730 | test_point, render_surface_layer_list); |
| 5731 | ASSERT_TRUE(result_layer); |
| 5732 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5733 | } |
| 5734 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5735 | TEST(LayerTreeHostCommonTest, |
| 5736 | HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) { |
| 5737 | // A layer's visible content rect is actually in the layer's content space. |
| 5738 | // The screen space transform converts from the layer's origin space to screen |
| 5739 | // space. This test makes sure that hit testing works correctly accounts for |
| 5740 | // the contents scale. A contents scale that is not 1 effectively forces a |
| 5741 | // non-identity transform between layer's content space and layer's origin |
| 5742 | // space. The hit testing code must take this into account. |
| 5743 | // |
| 5744 | // To test this, the layer is positioned at (25, 25), and is size (50, 50). If |
| 5745 | // contents scale is ignored, then hit checking will mis-interpret the visible |
| 5746 | // content rect as being larger than the actual bounds of the layer. |
| 5747 | // |
| 5748 | FakeImplProxy proxy; |
| 5749 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5750 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5751 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5752 | gfx::Transform identity_matrix; |
| 5753 | gfx::PointF anchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5754 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5755 | SetLayerPropertiesForTesting(root.get(), |
| 5756 | identity_matrix, |
| 5757 | identity_matrix, |
| 5758 | anchor, |
| 5759 | gfx::PointF(), |
| 5760 | gfx::Size(100, 100), |
| 5761 | false); |
| 5762 | { |
| 5763 | Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); |
| 5764 | gfx::PointF position(25.f, 25.f); |
| 5765 | gfx::Size bounds(50, 50); |
| 5766 | scoped_ptr<LayerImpl> test_layer = |
| 5767 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 5768 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5769 | identity_matrix, |
| 5770 | identity_matrix, |
| 5771 | anchor, |
| 5772 | position, |
| 5773 | bounds, |
| 5774 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5775 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5776 | // override content bounds and contents scale |
| 5777 | test_layer->SetContentBounds(gfx::Size(100, 100)); |
| 5778 | test_layer->SetContentsScale(2, 2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5779 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5780 | test_layer->SetDrawsContent(true); |
| 5781 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5782 | root->AddChild(test_layer.Pass()); |
| 5783 | } |
| 5784 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5785 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5786 | int dummy_max_texture_size = 512; |
| 5787 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 5788 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 5789 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5790 | 1.f, |
| 5791 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5792 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5793 | dummy_max_texture_size, |
| 5794 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5795 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 5796 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5797 | |
| 5798 | // Sanity check the scenario we just created. |
| 5799 | // The visible content rect for test_layer is actually 100x100, even though |
| 5800 | // its layout size is 50x50, positioned at 25x25. |
| 5801 | LayerImpl* test_layer = root->children()[0]; |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 5802 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5803 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5804 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5805 | |
| 5806 | // Hit checking for a point outside the layer should return a null pointer |
| 5807 | // (the root layer does not draw content, so it will not be tested either). |
| 5808 | gfx::Point test_point(76, 76); |
| 5809 | LayerImpl* result_layer = |
| 5810 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5811 | test_point, render_surface_layer_list); |
| 5812 | EXPECT_FALSE(result_layer); |
| 5813 | |
| 5814 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5815 | // region should return a null pointer. |
| 5816 | test_point = gfx::Point(26, 26); |
| 5817 | result_layer = |
| 5818 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5819 | test_point, render_surface_layer_list); |
| 5820 | EXPECT_FALSE(result_layer); |
| 5821 | |
| 5822 | test_point = gfx::Point(34, 34); |
| 5823 | result_layer = |
| 5824 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5825 | test_point, render_surface_layer_list); |
| 5826 | EXPECT_FALSE(result_layer); |
| 5827 | |
| 5828 | test_point = gfx::Point(65, 65); |
| 5829 | result_layer = |
| 5830 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5831 | test_point, render_surface_layer_list); |
| 5832 | EXPECT_FALSE(result_layer); |
| 5833 | |
| 5834 | test_point = gfx::Point(74, 74); |
| 5835 | result_layer = |
| 5836 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5837 | test_point, render_surface_layer_list); |
| 5838 | EXPECT_FALSE(result_layer); |
| 5839 | |
| 5840 | // Hit checking for a point inside the touch event handler region should |
| 5841 | // return the root layer. |
| 5842 | test_point = gfx::Point(35, 35); |
| 5843 | result_layer = |
| 5844 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5845 | test_point, render_surface_layer_list); |
| 5846 | ASSERT_TRUE(result_layer); |
| 5847 | EXPECT_EQ(12345, result_layer->id()); |
| 5848 | |
| 5849 | test_point = gfx::Point(64, 64); |
| 5850 | result_layer = |
| 5851 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5852 | test_point, render_surface_layer_list); |
| 5853 | ASSERT_TRUE(result_layer); |
| 5854 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5855 | } |
| 5856 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5857 | TEST(LayerTreeHostCommonTest, |
| 5858 | HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) { |
| 5859 | // The layer's device_scale_factor and page_scale_factor should scale the |
| 5860 | // content rect and we should be able to hit the touch handler region by |
| 5861 | // scaling the points accordingly. |
| 5862 | FakeImplProxy proxy; |
| 5863 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5864 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5865 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5866 | gfx::Transform identity_matrix; |
| 5867 | gfx::PointF anchor; |
| 5868 | // Set the bounds of the root layer big enough to fit the child when scaled. |
| 5869 | SetLayerPropertiesForTesting(root.get(), |
| 5870 | identity_matrix, |
| 5871 | identity_matrix, |
| 5872 | anchor, |
| 5873 | gfx::PointF(), |
| 5874 | gfx::Size(100, 100), |
| 5875 | false); |
| 5876 | { |
| 5877 | Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); |
| 5878 | gfx::PointF position(25.f, 25.f); |
| 5879 | gfx::Size bounds(50, 50); |
| 5880 | scoped_ptr<LayerImpl> test_layer = |
| 5881 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 5882 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5883 | identity_matrix, |
| 5884 | identity_matrix, |
| 5885 | anchor, |
| 5886 | position, |
| 5887 | bounds, |
| 5888 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5889 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5890 | test_layer->SetDrawsContent(true); |
| 5891 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5892 | root->AddChild(test_layer.Pass()); |
| 5893 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5894 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5895 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5896 | int dummy_max_texture_size = 512; |
| 5897 | float device_scale_factor = 3.f; |
| 5898 | float page_scale_factor = 5.f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5899 | gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize( |
| 5900 | gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor)); |
| 5901 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 5902 | scaled_bounds_for_root, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 5903 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5904 | device_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5905 | page_scale_factor, |
| 5906 | root.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5907 | dummy_max_texture_size, |
| 5908 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5909 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 5910 | &render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5911 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5912 | // Sanity check the scenario we just created. |
| 5913 | // The visible content rect for test_layer is actually 100x100, even though |
| 5914 | // its layout size is 50x50, positioned at 25x25. |
| 5915 | LayerImpl* test_layer = root->children()[0]; |
| 5916 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5917 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5918 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5919 | // Check whether the child layer fits into the root after scaled. |
| 5920 | EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()), |
| 5921 | test_layer->visible_content_rect()); |
| 5922 | |
| 5923 | // Hit checking for a point outside the layer should return a null pointer |
| 5924 | // (the root layer does not draw content, so it will not be tested either). |
| 5925 | gfx::PointF test_point(76.f, 76.f); |
| 5926 | test_point = |
| 5927 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5928 | LayerImpl* result_layer = |
| 5929 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5930 | test_point, render_surface_layer_list); |
| 5931 | EXPECT_FALSE(result_layer); |
| 5932 | |
| 5933 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5934 | // region should return a null pointer. |
| 5935 | test_point = gfx::Point(26, 26); |
| 5936 | test_point = |
| 5937 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5938 | result_layer = |
| 5939 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5940 | test_point, render_surface_layer_list); |
| 5941 | EXPECT_FALSE(result_layer); |
| 5942 | |
| 5943 | test_point = gfx::Point(34, 34); |
| 5944 | test_point = |
| 5945 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5946 | result_layer = |
| 5947 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5948 | test_point, render_surface_layer_list); |
| 5949 | EXPECT_FALSE(result_layer); |
| 5950 | |
| 5951 | test_point = gfx::Point(65, 65); |
| 5952 | test_point = |
| 5953 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5954 | result_layer = |
| 5955 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5956 | test_point, render_surface_layer_list); |
| 5957 | EXPECT_FALSE(result_layer); |
| 5958 | |
| 5959 | test_point = gfx::Point(74, 74); |
| 5960 | test_point = |
| 5961 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5962 | result_layer = |
| 5963 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5964 | test_point, render_surface_layer_list); |
| 5965 | EXPECT_FALSE(result_layer); |
| 5966 | |
| 5967 | // Hit checking for a point inside the touch event handler region should |
| 5968 | // return the root layer. |
| 5969 | test_point = gfx::Point(35, 35); |
| 5970 | test_point = |
| 5971 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5972 | result_layer = |
| 5973 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5974 | test_point, render_surface_layer_list); |
| 5975 | ASSERT_TRUE(result_layer); |
| 5976 | EXPECT_EQ(12345, result_layer->id()); |
| 5977 | |
| 5978 | test_point = gfx::Point(64, 64); |
| 5979 | test_point = |
| 5980 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5981 | result_layer = |
| 5982 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5983 | test_point, render_surface_layer_list); |
| 5984 | ASSERT_TRUE(result_layer); |
| 5985 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5986 | } |
| 5987 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5988 | TEST(LayerTreeHostCommonTest, |
| 5989 | HitCheckingTouchHandlerRegionsForSimpleClippedLayer) { |
| 5990 | // Test that hit-checking will only work for the visible portion of a layer, |
| 5991 | // and not the entire layer bounds. Here we just test the simple axis-aligned |
| 5992 | // case. |
| 5993 | gfx::Transform identity_matrix; |
| 5994 | gfx::PointF anchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5995 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5996 | FakeImplProxy proxy; |
| 5997 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 5998 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 5999 | SetLayerPropertiesForTesting(root.get(), |
| 6000 | identity_matrix, |
| 6001 | identity_matrix, |
| 6002 | anchor, |
| 6003 | gfx::PointF(), |
| 6004 | gfx::Size(100, 100), |
| 6005 | false); |
| 6006 | { |
| 6007 | scoped_ptr<LayerImpl> clipping_layer = |
| 6008 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 6009 | // this layer is positioned, and hit testing should correctly know where the |
| 6010 | // layer is located. |
| 6011 | gfx::PointF position(25.f, 25.f); |
| 6012 | gfx::Size bounds(50, 50); |
| 6013 | SetLayerPropertiesForTesting(clipping_layer.get(), |
| 6014 | identity_matrix, |
| 6015 | identity_matrix, |
| 6016 | anchor, |
| 6017 | position, |
| 6018 | bounds, |
| 6019 | false); |
| 6020 | clipping_layer->SetMasksToBounds(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6021 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6022 | scoped_ptr<LayerImpl> child = |
| 6023 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 6024 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 6025 | position = gfx::PointF(-50.f, -50.f); |
| 6026 | bounds = gfx::Size(300, 300); |
| 6027 | SetLayerPropertiesForTesting(child.get(), |
| 6028 | identity_matrix, |
| 6029 | identity_matrix, |
| 6030 | anchor, |
| 6031 | position, |
| 6032 | bounds, |
| 6033 | false); |
| 6034 | child->SetDrawsContent(true); |
| 6035 | child->SetTouchEventHandlerRegion(touch_handler_region); |
| 6036 | clipping_layer->AddChild(child.Pass()); |
| 6037 | root->AddChild(clipping_layer.Pass()); |
| 6038 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6039 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 6040 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6041 | int dummy_max_texture_size = 512; |
| 6042 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 6043 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6044 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6045 | 1.f, |
| 6046 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6047 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6048 | dummy_max_texture_size, |
| 6049 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6050 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 6051 | &render_surface_layer_list); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6052 | |
| 6053 | // Sanity check the scenario we just created. |
| 6054 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6055 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 6056 | ASSERT_EQ(456, root->render_surface()->layer_list()[0]->id()); |
| 6057 | |
| 6058 | // Hit checking for a point outside the layer should return a null pointer. |
| 6059 | // Despite the child layer being very large, it should be clipped to the root |
| 6060 | // layer's bounds. |
| 6061 | gfx::Point test_point(24, 24); |
| 6062 | LayerImpl* result_layer = |
| 6063 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6064 | test_point, render_surface_layer_list); |
| 6065 | EXPECT_FALSE(result_layer); |
| 6066 | |
| 6067 | // Hit checking for a point inside the layer, but outside the touch handler |
| 6068 | // region should return a null pointer. |
| 6069 | test_point = gfx::Point(35, 35); |
| 6070 | result_layer = |
| 6071 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6072 | test_point, render_surface_layer_list); |
| 6073 | EXPECT_FALSE(result_layer); |
| 6074 | |
| 6075 | test_point = gfx::Point(74, 74); |
| 6076 | result_layer = |
| 6077 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6078 | test_point, render_surface_layer_list); |
| 6079 | EXPECT_FALSE(result_layer); |
| 6080 | |
| 6081 | // Hit checking for a point inside the touch event handler region should |
| 6082 | // return the root layer. |
| 6083 | test_point = gfx::Point(25, 25); |
| 6084 | result_layer = |
| 6085 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6086 | test_point, render_surface_layer_list); |
| 6087 | ASSERT_TRUE(result_layer); |
| 6088 | EXPECT_EQ(456, result_layer->id()); |
| 6089 | |
| 6090 | test_point = gfx::Point(34, 34); |
| 6091 | result_layer = |
| 6092 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6093 | test_point, render_surface_layer_list); |
| 6094 | ASSERT_TRUE(result_layer); |
| 6095 | EXPECT_EQ(456, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6096 | } |
| 6097 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6098 | class NoScaleContentLayer : public ContentLayer { |
| 6099 | public: |
| 6100 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 6101 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 6102 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6103 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6104 | virtual void CalculateContentsScale(float ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 6105 | float device_scale_factor, |
| 6106 | float page_scale_factor, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6107 | bool animating_transform_to_screen, |
| 6108 | float* contents_scale_x, |
| 6109 | float* contents_scale_y, |
| 6110 | gfx::Size* content_bounds) OVERRIDE { |
| 6111 | // Skip over the ContentLayer to the base Layer class. |
| 6112 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 6113 | device_scale_factor, |
| 6114 | page_scale_factor, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6115 | animating_transform_to_screen, |
| 6116 | contents_scale_x, |
| 6117 | contents_scale_y, |
| 6118 | content_bounds); |
| 6119 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6120 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6121 | protected: |
| 6122 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 6123 | : ContentLayer(client) {} |
| 6124 | virtual ~NoScaleContentLayer() {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6125 | }; |
| 6126 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6127 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 6128 | ContentLayerClient* delegate) { |
| 6129 | scoped_refptr<NoScaleContentLayer> to_return = |
| 6130 | NoScaleContentLayer::Create(delegate); |
| 6131 | to_return->SetIsDrawable(true); |
| 6132 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6133 | } |
| 6134 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6135 | TEST(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
| 6136 | // Verify draw and screen space transforms of layers not in a surface. |
| 6137 | MockContentLayerClient delegate; |
| 6138 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6139 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6140 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6141 | SetLayerPropertiesForTesting(parent.get(), |
| 6142 | identity_matrix, |
| 6143 | identity_matrix, |
| 6144 | gfx::PointF(), |
| 6145 | gfx::PointF(), |
| 6146 | gfx::Size(100, 100), |
| 6147 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6148 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6149 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 6150 | SetLayerPropertiesForTesting(child.get(), |
| 6151 | identity_matrix, |
| 6152 | identity_matrix, |
| 6153 | gfx::PointF(), |
| 6154 | gfx::PointF(2.f, 2.f), |
| 6155 | gfx::Size(10, 10), |
| 6156 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6157 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6158 | scoped_refptr<ContentLayer> child_empty = |
| 6159 | CreateDrawableContentLayer(&delegate); |
| 6160 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6161 | identity_matrix, |
| 6162 | identity_matrix, |
| 6163 | gfx::PointF(), |
| 6164 | gfx::PointF(2.f, 2.f), |
| 6165 | gfx::Size(), |
| 6166 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6167 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6168 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6169 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6170 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6171 | identity_matrix, |
| 6172 | identity_matrix, |
| 6173 | gfx::PointF(), |
| 6174 | gfx::PointF(2.f, 2.f), |
| 6175 | gfx::Size(10, 10), |
| 6176 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6177 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6178 | parent->AddChild(child); |
| 6179 | parent->AddChild(child_empty); |
| 6180 | parent->AddChild(child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6181 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 6182 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6183 | int dummy_max_texture_size = 512; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6184 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6185 | float device_scale_factor = 2.5f; |
| 6186 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6187 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6188 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 6189 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6190 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6191 | device_scale_factor, |
| 6192 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6193 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6194 | dummy_max_texture_size, |
| 6195 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6196 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6197 | &render_surface_layer_list); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6198 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6199 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6200 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 6201 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6202 | child_empty); |
| 6203 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6204 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6205 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6206 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6207 | // Verify parent transforms |
| 6208 | gfx::Transform expected_parent_transform; |
| 6209 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6210 | parent->screen_space_transform()); |
| 6211 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6212 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6213 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6214 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6215 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6216 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6217 | gfx::RectF parent_draw_rect = |
| 6218 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 6219 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 6220 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6221 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6222 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6223 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 6224 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 6225 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6226 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6227 | // Verify child and child_empty transforms. They should match. |
| 6228 | gfx::Transform expected_child_transform; |
| 6229 | expected_child_transform.Translate( |
| 6230 | device_scale_factor * child->position().x(), |
| 6231 | device_scale_factor * child->position().y()); |
| 6232 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6233 | child->draw_transform()); |
| 6234 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6235 | child->screen_space_transform()); |
| 6236 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6237 | child_empty->draw_transform()); |
| 6238 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6239 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6240 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6241 | // Verify results of transformed child and child_empty rects. They should |
| 6242 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6243 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6244 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6245 | gfx::RectF child_draw_rect = |
| 6246 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 6247 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 6248 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6249 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6250 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 6251 | child_empty->draw_transform(), child_content_bounds); |
| 6252 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 6253 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6254 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6255 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 6256 | expected_child_draw_rect.Scale(device_scale_factor); |
| 6257 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 6258 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 6259 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 6260 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6261 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6262 | // Verify child_no_scale transforms |
| 6263 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 6264 | // All transforms operate on content rects. The child's content rect |
| 6265 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 6266 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 6267 | device_scale_factor); |
| 6268 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6269 | child_no_scale->draw_transform()); |
| 6270 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6271 | child_no_scale->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6272 | } |
| 6273 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6274 | TEST(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
| 6275 | // Verify draw and screen space transforms of layers in a surface. |
| 6276 | MockContentLayerClient delegate; |
| 6277 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6278 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6279 | gfx::Transform perspective_matrix; |
| 6280 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6281 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6282 | gfx::Transform scale_small_matrix; |
| 6283 | scale_small_matrix.Scale(1.0 / 10.0, 1.0 / 12.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6284 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6285 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6286 | SetLayerPropertiesForTesting(parent.get(), |
| 6287 | identity_matrix, |
| 6288 | identity_matrix, |
| 6289 | gfx::PointF(), |
| 6290 | gfx::PointF(), |
| 6291 | gfx::Size(100, 100), |
| 6292 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6293 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6294 | scoped_refptr<ContentLayer> perspective_surface = |
| 6295 | CreateDrawableContentLayer(&delegate); |
| 6296 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 6297 | perspective_matrix * scale_small_matrix, |
| 6298 | identity_matrix, |
| 6299 | gfx::PointF(), |
| 6300 | gfx::PointF(2.f, 2.f), |
| 6301 | gfx::Size(10, 10), |
| 6302 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6303 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6304 | scoped_refptr<ContentLayer> scale_surface = |
| 6305 | CreateDrawableContentLayer(&delegate); |
| 6306 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 6307 | scale_small_matrix, |
| 6308 | identity_matrix, |
| 6309 | gfx::PointF(), |
| 6310 | gfx::PointF(2.f, 2.f), |
| 6311 | gfx::Size(10, 10), |
| 6312 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6313 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6314 | perspective_surface->SetForceRenderSurface(true); |
| 6315 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6316 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6317 | parent->AddChild(perspective_surface); |
| 6318 | parent->AddChild(scale_surface); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6319 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 6320 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6321 | int dummy_max_texture_size = 512; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6322 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6323 | float device_scale_factor = 2.5f; |
| 6324 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6325 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6326 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 6327 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6328 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6329 | device_scale_factor, |
| 6330 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6331 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6332 | dummy_max_texture_size, |
| 6333 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6334 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6335 | &render_surface_layer_list); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6336 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6337 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6338 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6339 | perspective_surface); |
| 6340 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6341 | scale_surface); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6342 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6343 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6344 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6345 | gfx::Transform expected_parent_draw_transform; |
| 6346 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 6347 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6348 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6349 | // The scaled surface is rendered at its appropriate scale, and drawn 1:1 |
| 6350 | // into its target. |
| 6351 | gfx::Transform expected_scale_surface_draw_transform; |
| 6352 | expected_scale_surface_draw_transform.Translate( |
| 6353 | device_scale_factor * page_scale_factor * scale_surface->position().x(), |
| 6354 | device_scale_factor * page_scale_factor * scale_surface->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6355 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6356 | expected_scale_surface_draw_transform, |
| 6357 | scale_surface->render_surface()->draw_transform()); |
[email protected] | a52c6ff | 2013-05-04 05:33:15 | [diff] [blame] | 6358 | gfx::Transform expected_scale_surface_layer_draw_transform = |
| 6359 | scale_small_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6360 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform, |
| 6361 | scale_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6362 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6363 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 6364 | // with the screen, and then scaled during drawing. |
| 6365 | gfx::Transform expected_perspective_surface_draw_transform; |
| 6366 | expected_perspective_surface_draw_transform.Translate( |
| 6367 | device_scale_factor * page_scale_factor * |
| 6368 | perspective_surface->position().x(), |
| 6369 | device_scale_factor * page_scale_factor * |
| 6370 | perspective_surface->position().y()); |
| 6371 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 6372 | perspective_matrix); |
| 6373 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 6374 | scale_small_matrix); |
| 6375 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
| 6376 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6377 | expected_perspective_surface_draw_transform, |
| 6378 | perspective_surface->render_surface()->draw_transform()); |
| 6379 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6380 | expected_perspective_surface_layer_draw_transform, |
| 6381 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6382 | } |
| 6383 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6384 | TEST(LayerTreeHostCommonTest, |
| 6385 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 6386 | // Verify draw and screen space transforms of layers not in a surface. |
| 6387 | MockContentLayerClient delegate; |
| 6388 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6389 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6390 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6391 | SetLayerPropertiesForTesting(parent.get(), |
| 6392 | identity_matrix, |
| 6393 | identity_matrix, |
| 6394 | gfx::PointF(), |
| 6395 | gfx::PointF(), |
| 6396 | gfx::Size(133, 133), |
| 6397 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6398 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6399 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 6400 | SetLayerPropertiesForTesting(child.get(), |
| 6401 | identity_matrix, |
| 6402 | identity_matrix, |
| 6403 | gfx::PointF(), |
| 6404 | gfx::PointF(), |
| 6405 | gfx::Size(13, 13), |
| 6406 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6407 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6408 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6409 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6410 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6411 | identity_matrix, |
| 6412 | identity_matrix, |
| 6413 | gfx::PointF(), |
| 6414 | gfx::PointF(), |
| 6415 | gfx::Size(13, 13), |
| 6416 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6417 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6418 | parent->AddChild(child); |
| 6419 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6420 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 6421 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6422 | int dummy_max_texture_size = 512; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6423 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6424 | float device_scale_factor = 1.7f; |
| 6425 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6426 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6427 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 6428 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6429 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6430 | device_scale_factor, |
| 6431 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6432 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6433 | dummy_max_texture_size, |
| 6434 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6435 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6436 | &render_surface_layer_list); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6437 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6438 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6439 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 6440 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6441 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6442 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6443 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6444 | // Verify parent transforms |
| 6445 | gfx::Transform expected_parent_transform; |
| 6446 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6447 | parent->screen_space_transform()); |
| 6448 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6449 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6450 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6451 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6452 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6453 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6454 | gfx::RectF parent_draw_rect = |
| 6455 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 6456 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 6457 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6458 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6459 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6460 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 6461 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 6462 | expected_parent_draw_rect.set_height( |
| 6463 | ceil(expected_parent_draw_rect.height())); |
| 6464 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 6465 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6466 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6467 | // Verify child transforms |
| 6468 | gfx::Transform expected_child_transform; |
| 6469 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6470 | child->draw_transform()); |
| 6471 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6472 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6473 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6474 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6475 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6476 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6477 | gfx::RectF child_draw_rect = |
| 6478 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 6479 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 6480 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6481 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6482 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6483 | expected_child_draw_rect.Scale(device_scale_factor); |
| 6484 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 6485 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 6486 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 6487 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6488 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6489 | // Verify child_no_scale transforms |
| 6490 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 6491 | // All transforms operate on content rects. The child's content rect |
| 6492 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 6493 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 6494 | device_scale_factor); |
| 6495 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6496 | child_no_scale->draw_transform()); |
| 6497 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6498 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6499 | } |
| 6500 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6501 | TEST(LayerTreeHostCommonTest, ContentsScale) { |
| 6502 | MockContentLayerClient delegate; |
| 6503 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6504 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6505 | gfx::Transform parent_scale_matrix; |
| 6506 | double initial_parent_scale = 1.75; |
| 6507 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6508 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6509 | gfx::Transform child_scale_matrix; |
| 6510 | double initial_child_scale = 1.25; |
| 6511 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6512 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6513 | scoped_refptr<Layer> root = Layer::Create(); |
| 6514 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6515 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6516 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6517 | SetLayerPropertiesForTesting(parent.get(), |
| 6518 | parent_scale_matrix, |
| 6519 | identity_matrix, |
| 6520 | gfx::PointF(), |
| 6521 | gfx::PointF(), |
| 6522 | gfx::Size(100, 100), |
| 6523 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6524 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6525 | scoped_refptr<ContentLayer> child_scale = |
| 6526 | CreateDrawableContentLayer(&delegate); |
| 6527 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6528 | child_scale_matrix, |
| 6529 | identity_matrix, |
| 6530 | gfx::PointF(), |
| 6531 | gfx::PointF(2.f, 2.f), |
| 6532 | gfx::Size(10, 10), |
| 6533 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6534 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6535 | scoped_refptr<ContentLayer> child_empty = |
| 6536 | CreateDrawableContentLayer(&delegate); |
| 6537 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6538 | child_scale_matrix, |
| 6539 | identity_matrix, |
| 6540 | gfx::PointF(), |
| 6541 | gfx::PointF(2.f, 2.f), |
| 6542 | gfx::Size(), |
| 6543 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6544 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6545 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6546 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6547 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6548 | child_scale_matrix, |
| 6549 | identity_matrix, |
| 6550 | gfx::PointF(), |
| 6551 | gfx::PointF(12.f, 12.f), |
| 6552 | gfx::Size(10, 10), |
| 6553 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6554 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6555 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6556 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6557 | parent->AddChild(child_scale); |
| 6558 | parent->AddChild(child_empty); |
| 6559 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6560 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 6561 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6562 | int dummy_max_texture_size = 512; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6563 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6564 | float device_scale_factor = 2.5f; |
| 6565 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6566 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6567 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 6568 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6569 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6570 | device_scale_factor, |
| 6571 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6572 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6573 | dummy_max_texture_size, |
| 6574 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6575 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6576 | &render_surface_layer_list); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6577 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6578 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6579 | initial_parent_scale, parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6580 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6581 | initial_parent_scale * initial_child_scale, |
| 6582 | child_scale); |
| 6583 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6584 | initial_parent_scale * initial_child_scale, |
| 6585 | child_empty); |
| 6586 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6587 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6588 | // The parent is scaled up and shouldn't need to scale during draw. The child |
| 6589 | // that can scale its contents should also not need to scale during draw. This |
| 6590 | // shouldn't change if the child has empty bounds. The other children should. |
| 6591 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(0, 0)); |
| 6592 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(1, 1)); |
| 6593 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().getDouble(0, 0)); |
| 6594 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().getDouble(1, 1)); |
| 6595 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().getDouble(0, 0)); |
| 6596 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().getDouble(1, 1)); |
| 6597 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 6598 | initial_parent_scale * initial_child_scale, |
| 6599 | child_no_scale->draw_transform().matrix().getDouble(0, 0)); |
| 6600 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 6601 | initial_parent_scale * initial_child_scale, |
| 6602 | child_no_scale->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6603 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6604 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 6605 | // updated using the initial transform as the raster scale. |
| 6606 | device_scale_factor = 2.25f; |
| 6607 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6608 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6609 | render_surface_layer_list.clear(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6610 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 6611 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6612 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6613 | device_scale_factor, |
| 6614 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6615 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6616 | dummy_max_texture_size, |
| 6617 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6618 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6619 | &render_surface_layer_list); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6620 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6621 | initial_parent_scale, |
| 6622 | parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6623 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6624 | initial_parent_scale * initial_child_scale, |
| 6625 | child_scale); |
| 6626 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6627 | initial_parent_scale * initial_child_scale, |
| 6628 | child_empty); |
| 6629 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6630 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6631 | // If the transform changes, we expect the raster scale to be reset to 1.0. |
| 6632 | double second_child_scale = 1.75; |
| 6633 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 6634 | second_child_scale / initial_child_scale); |
| 6635 | child_scale->SetTransform(child_scale_matrix); |
| 6636 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6637 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6638 | render_surface_layer_list.clear(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6639 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 6640 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6641 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6642 | device_scale_factor, |
| 6643 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6644 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6645 | dummy_max_texture_size, |
| 6646 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6647 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6648 | &render_surface_layer_list); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6649 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6650 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6651 | initial_parent_scale, |
| 6652 | parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6653 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6654 | child_scale); |
| 6655 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6656 | child_empty); |
| 6657 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6658 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6659 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 6660 | // updated, but still using 1.0 as the raster scale. |
| 6661 | device_scale_factor = 2.75f; |
| 6662 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6663 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6664 | render_surface_layer_list.clear(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6665 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 6666 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6667 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6668 | device_scale_factor, |
| 6669 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6670 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6671 | dummy_max_texture_size, |
| 6672 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6673 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6674 | &render_surface_layer_list); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6675 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6676 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6677 | initial_parent_scale, |
| 6678 | parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6679 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6680 | child_scale); |
| 6681 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6682 | child_empty); |
| 6683 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6684 | } |
| 6685 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6686 | TEST(LayerTreeHostCommonTest, |
| 6687 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6688 | MockContentLayerClient delegate; |
| 6689 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6690 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6691 | gfx::Transform parent_scale_matrix; |
| 6692 | double initial_parent_scale = 1.75; |
| 6693 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6694 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6695 | gfx::Transform child_scale_matrix; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6696 | double initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6697 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6698 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6699 | scoped_refptr<Layer> root = Layer::Create(); |
| 6700 | root->SetBounds(gfx::Size(100, 100)); |
| 6701 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6702 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6703 | SetLayerPropertiesForTesting(parent.get(), |
| 6704 | parent_scale_matrix, |
| 6705 | identity_matrix, |
| 6706 | gfx::PointF(), |
| 6707 | gfx::PointF(), |
| 6708 | gfx::Size(100, 100), |
| 6709 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6711 | scoped_refptr<ContentLayer> child_scale = |
| 6712 | CreateDrawableContentLayer(&delegate); |
| 6713 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6714 | child_scale_matrix, |
| 6715 | identity_matrix, |
| 6716 | gfx::PointF(), |
| 6717 | gfx::PointF(2.f, 2.f), |
| 6718 | gfx::Size(10, 10), |
| 6719 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6720 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6721 | scoped_refptr<ContentLayer> child_empty = |
| 6722 | CreateDrawableContentLayer(&delegate); |
| 6723 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6724 | child_scale_matrix, |
| 6725 | identity_matrix, |
| 6726 | gfx::PointF(), |
| 6727 | gfx::PointF(2.f, 2.f), |
| 6728 | gfx::Size(), |
| 6729 | true); |
| 6730 | |
| 6731 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6732 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6733 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6734 | child_scale_matrix, |
| 6735 | identity_matrix, |
| 6736 | gfx::PointF(), |
| 6737 | gfx::PointF(12.f, 12.f), |
| 6738 | gfx::Size(10, 10), |
| 6739 | true); |
| 6740 | |
| 6741 | root->AddChild(parent); |
| 6742 | |
| 6743 | parent->AddChild(child_scale); |
| 6744 | parent->AddChild(child_empty); |
| 6745 | parent->AddChild(child_no_scale); |
| 6746 | |
| 6747 | LayerList render_surface_layer_list; |
| 6748 | int dummy_max_texture_size = 512; |
| 6749 | |
| 6750 | float device_scale_factor = 2.5f; |
| 6751 | float page_scale_factor = 1.f; |
| 6752 | |
| 6753 | LayerTreeHostCommon::CalculateDrawProperties( |
| 6754 | root.get(), |
| 6755 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6756 | gfx::Transform(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6757 | device_scale_factor, |
| 6758 | page_scale_factor, |
| 6759 | parent.get(), |
| 6760 | dummy_max_texture_size, |
| 6761 | false, |
| 6762 | false, // can_adjust_raster_scale |
| 6763 | &render_surface_layer_list); |
| 6764 | |
| 6765 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6766 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6767 | child_scale); |
| 6768 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6769 | child_empty); |
| 6770 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6771 | |
| 6772 | // Since the transform scale does not affect contents scale, it should affect |
| 6773 | // the draw transform instead. |
| 6774 | EXPECT_FLOAT_EQ(initial_parent_scale, |
| 6775 | parent->draw_transform().matrix().getDouble(0, 0)); |
| 6776 | EXPECT_FLOAT_EQ(initial_parent_scale, |
| 6777 | parent->draw_transform().matrix().getDouble(1, 1)); |
| 6778 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 6779 | child_scale->draw_transform().matrix().getDouble(0, 0)); |
| 6780 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 6781 | child_scale->draw_transform().matrix().getDouble(1, 1)); |
| 6782 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 6783 | child_empty->draw_transform().matrix().getDouble(0, 0)); |
| 6784 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 6785 | child_empty->draw_transform().matrix().getDouble(1, 1)); |
| 6786 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 6787 | initial_parent_scale * initial_child_scale, |
| 6788 | child_no_scale->draw_transform().matrix().getDouble(0, 0)); |
| 6789 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 6790 | initial_parent_scale * initial_child_scale, |
| 6791 | child_no_scale->draw_transform().matrix().getDouble(1, 1)); |
| 6792 | } |
| 6793 | |
| 6794 | TEST(LayerTreeHostCommonTest, SmallContentsScale) { |
| 6795 | MockContentLayerClient delegate; |
| 6796 | gfx::Transform identity_matrix; |
| 6797 | |
| 6798 | gfx::Transform parent_scale_matrix; |
| 6799 | double initial_parent_scale = 1.75; |
| 6800 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 6801 | |
| 6802 | gfx::Transform child_scale_matrix; |
| 6803 | double initial_child_scale = 0.25; |
| 6804 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 6805 | |
| 6806 | scoped_refptr<Layer> root = Layer::Create(); |
| 6807 | root->SetBounds(gfx::Size(100, 100)); |
| 6808 | |
| 6809 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6810 | SetLayerPropertiesForTesting(parent.get(), |
| 6811 | parent_scale_matrix, |
| 6812 | identity_matrix, |
| 6813 | gfx::PointF(), |
| 6814 | gfx::PointF(), |
| 6815 | gfx::Size(100, 100), |
| 6816 | true); |
| 6817 | |
| 6818 | scoped_refptr<ContentLayer> child_scale = |
| 6819 | CreateDrawableContentLayer(&delegate); |
| 6820 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6821 | child_scale_matrix, |
| 6822 | identity_matrix, |
| 6823 | gfx::PointF(), |
| 6824 | gfx::PointF(2.f, 2.f), |
| 6825 | gfx::Size(10, 10), |
| 6826 | true); |
| 6827 | |
| 6828 | root->AddChild(parent); |
| 6829 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6830 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6831 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 6832 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6833 | int dummy_max_texture_size = 512; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6834 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6835 | float device_scale_factor = 2.5f; |
| 6836 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6837 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6838 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 6839 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6840 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6841 | device_scale_factor, |
| 6842 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6843 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6844 | dummy_max_texture_size, |
| 6845 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6846 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6847 | &render_surface_layer_list); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6848 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6849 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6850 | initial_parent_scale, |
| 6851 | parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6852 | // The child's scale is < 1, so we should not save and use that scale factor. |
| 6853 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1, |
| 6854 | child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6855 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6856 | // When chilld's total scale becomes >= 1, we should save and use that scale |
| 6857 | // factor. |
| 6858 | child_scale_matrix.MakeIdentity(); |
| 6859 | double final_child_scale = 0.75; |
| 6860 | child_scale_matrix.Scale(final_child_scale, final_child_scale); |
| 6861 | child_scale->SetTransform(child_scale_matrix); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6862 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6863 | render_surface_layer_list.clear(); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6864 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 6865 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6866 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6867 | device_scale_factor, |
| 6868 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6869 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6870 | dummy_max_texture_size, |
| 6871 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6872 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6873 | &render_surface_layer_list); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6874 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6875 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6876 | initial_parent_scale, |
| 6877 | parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6878 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6879 | initial_parent_scale * final_child_scale, |
| 6880 | child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6881 | } |
| 6882 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6883 | TEST(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
| 6884 | MockContentLayerClient delegate; |
| 6885 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6886 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6887 | gfx::Transform parent_scale_matrix; |
| 6888 | double initial_parent_scale = 2.0; |
| 6889 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6890 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6891 | gfx::Transform child_scale_matrix; |
| 6892 | double initial_child_scale = 3.0; |
| 6893 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6894 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6895 | scoped_refptr<Layer> root = Layer::Create(); |
| 6896 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6897 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6898 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6899 | SetLayerPropertiesForTesting(parent.get(), |
| 6900 | parent_scale_matrix, |
| 6901 | identity_matrix, |
| 6902 | gfx::PointF(), |
| 6903 | gfx::PointF(), |
| 6904 | gfx::Size(100, 100), |
| 6905 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6906 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6907 | scoped_refptr<ContentLayer> surface_scale = |
| 6908 | CreateDrawableContentLayer(&delegate); |
| 6909 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 6910 | child_scale_matrix, |
| 6911 | identity_matrix, |
| 6912 | gfx::PointF(), |
| 6913 | gfx::PointF(2.f, 2.f), |
| 6914 | gfx::Size(10, 10), |
| 6915 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6916 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6917 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 6918 | CreateDrawableContentLayer(&delegate); |
| 6919 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 6920 | child_scale_matrix, |
| 6921 | identity_matrix, |
| 6922 | gfx::PointF(), |
| 6923 | gfx::PointF(), |
| 6924 | gfx::Size(10, 10), |
| 6925 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6926 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6927 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 6928 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6929 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 6930 | child_scale_matrix, |
| 6931 | identity_matrix, |
| 6932 | gfx::PointF(), |
| 6933 | gfx::PointF(), |
| 6934 | gfx::Size(10, 10), |
| 6935 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6936 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6937 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 6938 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6939 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 6940 | child_scale_matrix, |
| 6941 | identity_matrix, |
| 6942 | gfx::PointF(), |
| 6943 | gfx::PointF(12.f, 12.f), |
| 6944 | gfx::Size(10, 10), |
| 6945 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6946 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6947 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 6948 | CreateDrawableContentLayer(&delegate); |
| 6949 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 6950 | child_scale_matrix, |
| 6951 | identity_matrix, |
| 6952 | gfx::PointF(), |
| 6953 | gfx::PointF(), |
| 6954 | gfx::Size(10, 10), |
| 6955 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6956 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6957 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 6958 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6959 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 6960 | child_scale_matrix, |
| 6961 | identity_matrix, |
| 6962 | gfx::PointF(), |
| 6963 | gfx::PointF(), |
| 6964 | gfx::Size(10, 10), |
| 6965 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6966 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6967 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6968 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6969 | parent->AddChild(surface_scale); |
| 6970 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6971 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6972 | surface_scale->SetForceRenderSurface(true); |
| 6973 | surface_scale->AddChild(surface_scale_child_scale); |
| 6974 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6975 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6976 | surface_no_scale->SetForceRenderSurface(true); |
| 6977 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 6978 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6979 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 6980 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6981 | int dummy_max_texture_size = 512; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6982 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6983 | double device_scale_factor = 5; |
| 6984 | double page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6985 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6986 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 6987 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 6988 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6989 | device_scale_factor, |
| 6990 | page_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6991 | parent.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6992 | dummy_max_texture_size, |
| 6993 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6994 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6995 | &render_surface_layer_list); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6996 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6997 | initial_parent_scale, |
| 6998 | parent); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6999 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 7000 | initial_parent_scale * initial_child_scale, |
| 7001 | surface_scale); |
| 7002 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 7003 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7004 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 7005 | initial_child_scale * initial_child_scale, |
| 7006 | surface_scale_child_scale); |
| 7007 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 7008 | EXPECT_CONTENTS_SCALE_EQ( |
| 7009 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 7010 | initial_child_scale * initial_child_scale, |
| 7011 | surface_no_scale_child_scale); |
| 7012 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7013 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7014 | // The parent is scaled up and shouldn't need to scale during draw. |
| 7015 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(0, 0)); |
| 7016 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7017 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7018 | // RenderSurfaces should always be 1:1 with their target. |
| 7019 | EXPECT_FLOAT_EQ( |
| 7020 | 1.0, |
| 7021 | surface_scale->render_surface()->draw_transform().matrix().getDouble(0, |
| 7022 | 0)); |
| 7023 | EXPECT_FLOAT_EQ( |
| 7024 | 1.0, |
| 7025 | surface_scale->render_surface()->draw_transform().matrix().getDouble(1, |
| 7026 | 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7027 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7028 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 7029 | // scale during draw. |
| 7030 | EXPECT_FLOAT_EQ(1.0, |
| 7031 | surface_scale->draw_transform().matrix().getDouble(0, 0)); |
| 7032 | EXPECT_FLOAT_EQ(1.0, |
| 7033 | surface_scale->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7034 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7035 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 7036 | // to scale during draw. |
| 7037 | EXPECT_FLOAT_EQ( |
| 7038 | 1.0, |
| 7039 | surface_scale_child_scale->draw_transform().matrix().getDouble(0, 0)); |
| 7040 | EXPECT_FLOAT_EQ( |
| 7041 | 1.0, |
| 7042 | surface_scale_child_scale->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7043 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7044 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 7045 | // to be scaled during draw. |
| 7046 | EXPECT_FLOAT_EQ( |
| 7047 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 7048 | initial_child_scale * initial_child_scale, |
| 7049 | surface_scale_child_no_scale->draw_transform().matrix().getDouble(0, 0)); |
| 7050 | EXPECT_FLOAT_EQ( |
| 7051 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 7052 | initial_child_scale * initial_child_scale, |
| 7053 | surface_scale_child_no_scale->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7054 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7055 | // RenderSurfaces should always be 1:1 with their target. |
| 7056 | EXPECT_FLOAT_EQ( |
| 7057 | 1.0, |
| 7058 | surface_no_scale->render_surface()->draw_transform().matrix().getDouble( |
| 7059 | 0, 0)); |
| 7060 | EXPECT_FLOAT_EQ( |
| 7061 | 1.0, |
| 7062 | surface_no_scale->render_surface()->draw_transform().matrix().getDouble( |
| 7063 | 1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7064 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7065 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 7066 | // scaled during draw. |
| 7067 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 7068 | initial_parent_scale * initial_child_scale, |
| 7069 | surface_no_scale->draw_transform().matrix().getDouble(0, 0)); |
| 7070 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 7071 | initial_parent_scale * initial_child_scale, |
| 7072 | surface_no_scale->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7073 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7074 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 7075 | // to scale during draw. |
| 7076 | EXPECT_FLOAT_EQ( |
| 7077 | 1.0, |
| 7078 | surface_no_scale_child_scale->draw_transform().matrix().getDouble(0, 0)); |
| 7079 | EXPECT_FLOAT_EQ( |
| 7080 | 1.0, |
| 7081 | surface_no_scale_child_scale->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7082 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7083 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 7084 | // to be scaled during draw. |
| 7085 | EXPECT_FLOAT_EQ( |
| 7086 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 7087 | initial_child_scale * initial_child_scale, |
| 7088 | surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(0, |
| 7089 | 0)); |
| 7090 | EXPECT_FLOAT_EQ( |
| 7091 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 7092 | initial_child_scale * initial_child_scale, |
| 7093 | surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(1, |
| 7094 | 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7095 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7096 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7097 | TEST(LayerTreeHostCommonTest, |
| 7098 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
| 7099 | MockContentLayerClient delegate; |
| 7100 | gfx::Transform identity_matrix; |
| 7101 | |
| 7102 | gfx::Transform parent_scale_matrix; |
| 7103 | double initial_parent_scale = 2.0; |
| 7104 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 7105 | |
| 7106 | gfx::Transform child_scale_matrix; |
| 7107 | double initial_child_scale = 3.0; |
| 7108 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 7109 | |
| 7110 | scoped_refptr<Layer> root = Layer::Create(); |
| 7111 | root->SetBounds(gfx::Size(100, 100)); |
| 7112 | |
| 7113 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7114 | SetLayerPropertiesForTesting(parent.get(), |
| 7115 | parent_scale_matrix, |
| 7116 | identity_matrix, |
| 7117 | gfx::PointF(), |
| 7118 | gfx::PointF(), |
| 7119 | gfx::Size(100, 100), |
| 7120 | true); |
| 7121 | |
| 7122 | scoped_refptr<ContentLayer> surface_scale = |
| 7123 | CreateDrawableContentLayer(&delegate); |
| 7124 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 7125 | child_scale_matrix, |
| 7126 | identity_matrix, |
| 7127 | gfx::PointF(), |
| 7128 | gfx::PointF(2.f, 2.f), |
| 7129 | gfx::Size(10, 10), |
| 7130 | true); |
| 7131 | |
| 7132 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 7133 | CreateDrawableContentLayer(&delegate); |
| 7134 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 7135 | child_scale_matrix, |
| 7136 | identity_matrix, |
| 7137 | gfx::PointF(), |
| 7138 | gfx::PointF(), |
| 7139 | gfx::Size(10, 10), |
| 7140 | true); |
| 7141 | |
| 7142 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 7143 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7144 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 7145 | child_scale_matrix, |
| 7146 | identity_matrix, |
| 7147 | gfx::PointF(), |
| 7148 | gfx::PointF(), |
| 7149 | gfx::Size(10, 10), |
| 7150 | true); |
| 7151 | |
| 7152 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 7153 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7154 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 7155 | child_scale_matrix, |
| 7156 | identity_matrix, |
| 7157 | gfx::PointF(), |
| 7158 | gfx::PointF(12.f, 12.f), |
| 7159 | gfx::Size(10, 10), |
| 7160 | true); |
| 7161 | |
| 7162 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 7163 | CreateDrawableContentLayer(&delegate); |
| 7164 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 7165 | child_scale_matrix, |
| 7166 | identity_matrix, |
| 7167 | gfx::PointF(), |
| 7168 | gfx::PointF(), |
| 7169 | gfx::Size(10, 10), |
| 7170 | true); |
| 7171 | |
| 7172 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 7173 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7174 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 7175 | child_scale_matrix, |
| 7176 | identity_matrix, |
| 7177 | gfx::PointF(), |
| 7178 | gfx::PointF(), |
| 7179 | gfx::Size(10, 10), |
| 7180 | true); |
| 7181 | |
| 7182 | root->AddChild(parent); |
| 7183 | |
| 7184 | parent->AddChild(surface_scale); |
| 7185 | parent->AddChild(surface_no_scale); |
| 7186 | |
| 7187 | surface_scale->SetForceRenderSurface(true); |
| 7188 | surface_scale->AddChild(surface_scale_child_scale); |
| 7189 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 7190 | |
| 7191 | surface_no_scale->SetForceRenderSurface(true); |
| 7192 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 7193 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 7194 | |
| 7195 | LayerList render_surface_layer_list; |
| 7196 | int dummy_max_texture_size = 512; |
| 7197 | |
| 7198 | double device_scale_factor = 5; |
| 7199 | double page_scale_factor = 7; |
| 7200 | |
| 7201 | LayerTreeHostCommon::CalculateDrawProperties( |
| 7202 | root.get(), |
| 7203 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 7204 | gfx::Transform(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7205 | device_scale_factor, |
| 7206 | page_scale_factor, |
| 7207 | parent.get(), |
| 7208 | dummy_max_texture_size, |
| 7209 | false, |
| 7210 | false, // can_adjust_raster_scale |
| 7211 | &render_surface_layer_list); |
| 7212 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7213 | parent); |
| 7214 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7215 | surface_scale); |
| 7216 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 7217 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7218 | surface_scale_child_scale); |
| 7219 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 7220 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7221 | surface_no_scale_child_scale); |
| 7222 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 7223 | |
| 7224 | // The parent is scaled up during draw, since its contents are not scaled by |
| 7225 | // the transform hierarchy. |
| 7226 | EXPECT_FLOAT_EQ(initial_parent_scale, |
| 7227 | parent->draw_transform().matrix().getDouble(0, 0)); |
| 7228 | EXPECT_FLOAT_EQ(initial_parent_scale, |
| 7229 | parent->draw_transform().matrix().getDouble(1, 1)); |
| 7230 | |
| 7231 | // The child surface is scaled up during draw since its subtree is not scaled |
| 7232 | // by the transform hierarchy. |
| 7233 | EXPECT_FLOAT_EQ( |
| 7234 | initial_parent_scale * initial_child_scale, |
| 7235 | surface_scale->render_surface()->draw_transform().matrix().getDouble(0, |
| 7236 | 0)); |
| 7237 | EXPECT_FLOAT_EQ( |
| 7238 | initial_parent_scale * initial_child_scale, |
| 7239 | surface_scale->render_surface()->draw_transform().matrix().getDouble(1, |
| 7240 | 1)); |
| 7241 | |
| 7242 | // The surface_scale's RenderSurface is scaled during draw, so the layer does |
| 7243 | // not need to be scaled when drawing into its surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7244 | EXPECT_FLOAT_EQ(1.0, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7245 | surface_scale->draw_transform().matrix().getDouble(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7246 | EXPECT_FLOAT_EQ(1.0, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7247 | surface_scale->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7248 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7249 | // The surface_scale_child_scale is scaled when drawing into its surface, |
| 7250 | // since its content bounds are not scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7251 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7252 | initial_child_scale, |
| 7253 | surface_scale_child_scale->draw_transform().matrix().getDouble(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7254 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7255 | initial_child_scale, |
| 7256 | surface_scale_child_scale->draw_transform().matrix().getDouble(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7257 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7258 | // The surface_scale_child_no_scale has a fixed contents scale of 1, so it |
| 7259 | // needs to be scaled by the device and page scale factors, along with the |
| 7260 | // transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7261 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7262 | device_scale_factor * page_scale_factor * initial_child_scale, |
| 7263 | surface_scale_child_no_scale->draw_transform().matrix().getDouble(0, 0)); |
| 7264 | EXPECT_FLOAT_EQ( |
| 7265 | device_scale_factor * page_scale_factor * initial_child_scale, |
| 7266 | surface_scale_child_no_scale->draw_transform().matrix().getDouble(1, 1)); |
| 7267 | |
| 7268 | // The child surface is scaled up during draw since its subtree is not scaled |
| 7269 | // by the transform hierarchy. |
| 7270 | EXPECT_FLOAT_EQ( |
| 7271 | initial_parent_scale * initial_child_scale, |
| 7272 | surface_no_scale->render_surface()->draw_transform().matrix().getDouble( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7273 | 0, 0)); |
| 7274 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7275 | initial_parent_scale * initial_child_scale, |
| 7276 | surface_no_scale->render_surface()->draw_transform().matrix().getDouble( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7277 | 1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7278 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7279 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 7280 | // be scaled by the device and page scale factors. Its surface is already |
| 7281 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 7282 | // drawing. |
| 7283 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 7284 | surface_no_scale->draw_transform().matrix().getDouble(0, 0)); |
| 7285 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 7286 | surface_no_scale->draw_transform().matrix().getDouble(1, 1)); |
| 7287 | |
| 7288 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 7289 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 7290 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7291 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7292 | initial_child_scale, |
| 7293 | surface_no_scale_child_scale->draw_transform().matrix().getDouble(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7294 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7295 | initial_child_scale, |
| 7296 | surface_no_scale_child_scale->draw_transform().matrix().getDouble(1, 1)); |
| 7297 | |
| 7298 | // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it |
| 7299 | // needs to be scaled by the device and page scale factors. It also needs to |
| 7300 | // be scaled by any transform heirarchy below its target surface. |
| 7301 | EXPECT_FLOAT_EQ( |
| 7302 | device_scale_factor * page_scale_factor * initial_child_scale, |
| 7303 | surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(0, |
| 7304 | 0)); |
| 7305 | EXPECT_FLOAT_EQ( |
| 7306 | device_scale_factor * page_scale_factor * initial_child_scale, |
| 7307 | surface_no_scale_child_no_scale->draw_transform().matrix().getDouble(1, |
| 7308 | 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7309 | } |
| 7310 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7311 | TEST(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) { |
| 7312 | MockContentLayerClient delegate; |
| 7313 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7314 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7315 | gfx::Transform parent_scale_matrix; |
| 7316 | double initial_parent_scale = 1.75; |
| 7317 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7318 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7319 | gfx::Transform child_scale_matrix; |
| 7320 | double initial_child_scale = 1.25; |
| 7321 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7322 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7323 | scoped_refptr<Layer> root = Layer::Create(); |
| 7324 | root->SetBounds(gfx::Size(100, 100)); |
| 7325 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7326 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7327 | SetLayerPropertiesForTesting(parent.get(), |
| 7328 | parent_scale_matrix, |
| 7329 | identity_matrix, |
| 7330 | gfx::PointF(), |
| 7331 | gfx::PointF(), |
| 7332 | gfx::Size(100, 100), |
| 7333 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7334 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7335 | scoped_refptr<ContentLayer> child_scale = |
| 7336 | CreateDrawableContentLayer(&delegate); |
| 7337 | SetLayerPropertiesForTesting(child_scale.get(), |
| 7338 | child_scale_matrix, |
| 7339 | identity_matrix, |
| 7340 | gfx::PointF(), |
| 7341 | gfx::PointF(2.f, 2.f), |
| 7342 | gfx::Size(10, 10), |
| 7343 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7344 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7345 | root->AddChild(parent); |
| 7346 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7347 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7348 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7349 | // Now put an animating transform on child. |
| 7350 | int animation_id = AddAnimatedTransformToController( |
| 7351 | child_scale->layer_animation_controller(), 10.0, 30, 0); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7352 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 7353 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7354 | int dummy_max_texture_size = 512; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7355 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7356 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 7357 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 7358 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7359 | 1.f, |
| 7360 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 7361 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7362 | dummy_max_texture_size, |
| 7363 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7364 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7365 | &render_surface_layer_list); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7366 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7367 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 7368 | // The layers with animating transforms should not compute a contents scale |
| 7369 | // other than 1 until they finish animating. |
| 7370 | EXPECT_CONTENTS_SCALE_EQ(1, child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7371 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7372 | // Remove the animation, now it can save a raster scale. |
| 7373 | child_scale->layer_animation_controller()->RemoveAnimation(animation_id); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7374 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7375 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 7376 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 7377 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7378 | 1.f, |
| 7379 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 7380 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7381 | dummy_max_texture_size, |
| 7382 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7383 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7384 | &render_surface_layer_list); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7385 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7386 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 7387 | // The layers with animating transforms should not compute a contents scale |
| 7388 | // other than 1 until they finish animating. |
| 7389 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale, |
| 7390 | child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7391 | } |
| 7392 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7393 | TEST(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
| 7394 | MockContentLayerClient delegate; |
| 7395 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7396 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7397 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7398 | SetLayerPropertiesForTesting(parent.get(), |
| 7399 | identity_matrix, |
| 7400 | identity_matrix, |
| 7401 | gfx::PointF(), |
| 7402 | gfx::PointF(), |
| 7403 | gfx::Size(30, 30), |
| 7404 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7405 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7406 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 7407 | SetLayerPropertiesForTesting(child.get(), |
| 7408 | identity_matrix, |
| 7409 | identity_matrix, |
| 7410 | gfx::PointF(), |
| 7411 | gfx::PointF(2.f, 2.f), |
| 7412 | gfx::Size(10, 10), |
| 7413 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7414 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7415 | gfx::Transform replica_transform; |
| 7416 | replica_transform.Scale(1.0, -1.0); |
| 7417 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 7418 | SetLayerPropertiesForTesting(replica.get(), |
| 7419 | replica_transform, |
| 7420 | identity_matrix, |
| 7421 | gfx::PointF(), |
| 7422 | gfx::PointF(2.f, 2.f), |
| 7423 | gfx::Size(10, 10), |
| 7424 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7425 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7426 | // This layer should end up in the same surface as child, with the same draw |
| 7427 | // and screen space transforms. |
| 7428 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 7429 | CreateDrawableContentLayer(&delegate); |
| 7430 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 7431 | identity_matrix, |
| 7432 | identity_matrix, |
| 7433 | gfx::PointF(), |
| 7434 | gfx::PointF(), |
| 7435 | gfx::Size(10, 10), |
| 7436 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7437 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7438 | parent->AddChild(child); |
| 7439 | child->AddChild(duplicate_child_non_owner); |
| 7440 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7441 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 7442 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7443 | int dummy_max_texture_size = 512; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7444 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7445 | float device_scale_factor = 1.5f; |
| 7446 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 7447 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 7448 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7449 | device_scale_factor, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 7450 | 1.f, |
| 7451 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7452 | dummy_max_texture_size, |
| 7453 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7454 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7455 | &render_surface_layer_list); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7456 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7457 | // We should have two render surfaces. The root's render surface and child's |
| 7458 | // render surface (it needs one because it has a replica layer). |
| 7459 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7460 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7461 | gfx::Transform expected_parent_transform; |
| 7462 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 7463 | parent->screen_space_transform()); |
| 7464 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 7465 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7466 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7467 | gfx::Transform expected_draw_transform; |
| 7468 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 7469 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7470 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7471 | gfx::Transform expected_screen_space_transform; |
| 7472 | expected_screen_space_transform.Translate( |
| 7473 | device_scale_factor * child->position().x(), |
| 7474 | device_scale_factor * child->position().y()); |
| 7475 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 7476 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7477 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7478 | gfx::Transform expected_duplicate_child_draw_transform = |
| 7479 | child->draw_transform(); |
| 7480 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 7481 | duplicate_child_non_owner->draw_transform()); |
| 7482 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7483 | child->screen_space_transform(), |
| 7484 | duplicate_child_non_owner->screen_space_transform()); |
| 7485 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 7486 | duplicate_child_non_owner->drawable_content_rect()); |
| 7487 | EXPECT_EQ(child->content_bounds(), |
| 7488 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7489 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7490 | gfx::Transform expected_render_surface_draw_transform; |
| 7491 | expected_render_surface_draw_transform.Translate( |
| 7492 | device_scale_factor * child->position().x(), |
| 7493 | device_scale_factor * child->position().y()); |
| 7494 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 7495 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7496 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7497 | gfx::Transform expected_surface_draw_transform; |
| 7498 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 7499 | device_scale_factor * 2.f); |
| 7500 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 7501 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7502 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7503 | gfx::Transform expected_surface_screen_space_transform; |
| 7504 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 7505 | device_scale_factor * 2.f); |
| 7506 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7507 | expected_surface_screen_space_transform, |
| 7508 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7509 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7510 | gfx::Transform expected_replica_draw_transform; |
| 7511 | expected_replica_draw_transform.matrix().setDouble(1, 1, -1.0); |
| 7512 | expected_replica_draw_transform.matrix().setDouble(0, 3, 6.0); |
| 7513 | expected_replica_draw_transform.matrix().setDouble(1, 3, 6.0); |
| 7514 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7515 | expected_replica_draw_transform, |
| 7516 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7517 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7518 | gfx::Transform expected_replica_screen_space_transform; |
| 7519 | expected_replica_screen_space_transform.matrix().setDouble(1, 1, -1.0); |
| 7520 | expected_replica_screen_space_transform.matrix().setDouble(0, 3, 6.0); |
| 7521 | expected_replica_screen_space_transform.matrix().setDouble(1, 3, 6.0); |
| 7522 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7523 | expected_replica_screen_space_transform, |
| 7524 | child->render_surface()->replica_screen_space_transform()); |
| 7525 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7526 | expected_replica_screen_space_transform, |
| 7527 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7528 | } |
| 7529 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7530 | TEST(LayerTreeHostCommonTest, |
| 7531 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 7532 | MockContentLayerClient delegate; |
| 7533 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7534 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7535 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7536 | SetLayerPropertiesForTesting(parent.get(), |
| 7537 | identity_matrix, |
| 7538 | identity_matrix, |
| 7539 | gfx::PointF(), |
| 7540 | gfx::PointF(), |
| 7541 | gfx::Size(33, 31), |
| 7542 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7543 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7544 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 7545 | SetLayerPropertiesForTesting(child.get(), |
| 7546 | identity_matrix, |
| 7547 | identity_matrix, |
| 7548 | gfx::PointF(), |
| 7549 | gfx::PointF(), |
| 7550 | gfx::Size(13, 11), |
| 7551 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7552 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7553 | gfx::Transform replica_transform; |
| 7554 | replica_transform.Scale(1.0, -1.0); |
| 7555 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 7556 | SetLayerPropertiesForTesting(replica.get(), |
| 7557 | replica_transform, |
| 7558 | identity_matrix, |
| 7559 | gfx::PointF(), |
| 7560 | gfx::PointF(), |
| 7561 | gfx::Size(13, 11), |
| 7562 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7563 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7564 | // This layer should end up in the same surface as child, with the same draw |
| 7565 | // and screen space transforms. |
| 7566 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 7567 | CreateDrawableContentLayer(&delegate); |
| 7568 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 7569 | identity_matrix, |
| 7570 | identity_matrix, |
| 7571 | gfx::PointF(), |
| 7572 | gfx::PointF(), |
| 7573 | gfx::Size(13, 11), |
| 7574 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7575 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7576 | parent->AddChild(child); |
| 7577 | child->AddChild(duplicate_child_non_owner); |
| 7578 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7579 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 7580 | LayerList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7581 | int dummy_max_texture_size = 512; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7582 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7583 | float device_scale_factor = 1.7f; |
| 7584 | LayerTreeHostCommon::CalculateDrawProperties(parent.get(), |
| 7585 | parent->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 7586 | gfx::Transform(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7587 | device_scale_factor, |
| 7588 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 7589 | NULL, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7590 | dummy_max_texture_size, |
| 7591 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7592 | true, // can_adjust_raster_scale |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7593 | &render_surface_layer_list); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7594 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7595 | // We should have two render surfaces. The root's render surface and child's |
| 7596 | // render surface (it needs one because it has a replica layer). |
| 7597 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7599 | gfx::Transform identity_transform; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7600 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7601 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7602 | parent->screen_space_transform()); |
| 7603 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform()); |
| 7604 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform()); |
| 7605 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7606 | child->screen_space_transform()); |
| 7607 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7608 | duplicate_child_non_owner->draw_transform()); |
| 7609 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7610 | identity_transform, duplicate_child_non_owner->screen_space_transform()); |
| 7611 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 7612 | duplicate_child_non_owner->drawable_content_rect()); |
| 7613 | EXPECT_EQ(child->content_bounds(), |
| 7614 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7615 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7616 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7617 | child->render_surface()->draw_transform()); |
| 7618 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7619 | child->render_surface()->draw_transform()); |
| 7620 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7621 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7622 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7623 | gfx::Transform expected_replica_draw_transform; |
| 7624 | expected_replica_draw_transform.matrix().setDouble(1, 1, -1.0); |
| 7625 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7626 | expected_replica_draw_transform, |
| 7627 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7628 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7629 | gfx::Transform expected_replica_screen_space_transform; |
| 7630 | expected_replica_screen_space_transform.matrix().setDouble(1, 1, -1.0); |
| 7631 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7632 | expected_replica_screen_space_transform, |
| 7633 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7634 | } |
| 7635 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7636 | TEST(LayerTreeHostCommonTest, SubtreeSearch) { |
| 7637 | scoped_refptr<Layer> root = Layer::Create(); |
| 7638 | scoped_refptr<Layer> child = Layer::Create(); |
| 7639 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 7640 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 7641 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7642 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7643 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 7644 | child->AddChild(grand_child.get()); |
| 7645 | child->SetMaskLayer(mask_layer.get()); |
| 7646 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7647 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7648 | int nonexistent_id = -1; |
| 7649 | EXPECT_EQ(root, |
| 7650 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
| 7651 | EXPECT_EQ(child, |
| 7652 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 7653 | EXPECT_EQ( |
| 7654 | grand_child, |
| 7655 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 7656 | EXPECT_EQ( |
| 7657 | mask_layer, |
| 7658 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 7659 | EXPECT_EQ( |
| 7660 | replica_layer, |
| 7661 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 7662 | EXPECT_EQ( |
| 7663 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7664 | } |
| 7665 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7666 | TEST(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
| 7667 | scoped_refptr<Layer> root = Layer::Create(); |
| 7668 | scoped_refptr<Layer> child = Layer::Create(); |
| 7669 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 7670 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7671 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7672 | const gfx::Transform identity_matrix; |
| 7673 | SetLayerPropertiesForTesting(root.get(), |
| 7674 | identity_matrix, |
| 7675 | identity_matrix, |
| 7676 | gfx::PointF(), |
| 7677 | gfx::PointF(), |
| 7678 | gfx::Size(100, 100), |
| 7679 | false); |
| 7680 | SetLayerPropertiesForTesting(child.get(), |
| 7681 | identity_matrix, |
| 7682 | identity_matrix, |
| 7683 | gfx::PointF(), |
| 7684 | gfx::PointF(), |
| 7685 | gfx::Size(10, 10), |
| 7686 | false); |
| 7687 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7688 | identity_matrix, |
| 7689 | identity_matrix, |
| 7690 | gfx::PointF(), |
| 7691 | gfx::PointF(), |
| 7692 | gfx::Size(10, 10), |
| 7693 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7694 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7695 | root->AddChild(child); |
| 7696 | child->AddChild(grand_child); |
| 7697 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7698 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7699 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7700 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7701 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7702 | } |
| 7703 | |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7704 | TEST(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
| 7705 | FakeImplProxy proxy; |
| 7706 | FakeLayerTreeHostImpl host_impl(&proxy); |
| 7707 | host_impl.CreatePendingTree(); |
| 7708 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 7709 | |
| 7710 | const gfx::Transform identity_matrix; |
| 7711 | SetLayerPropertiesForTesting(root.get(), |
| 7712 | identity_matrix, |
| 7713 | identity_matrix, |
| 7714 | gfx::PointF(), |
| 7715 | gfx::PointF(), |
| 7716 | gfx::Size(100, 100), |
| 7717 | false); |
| 7718 | root->SetDrawsContent(true); |
| 7719 | |
| 7720 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 7721 | SetLayerPropertiesForTesting(child.get(), |
| 7722 | identity_matrix, |
| 7723 | identity_matrix, |
| 7724 | gfx::PointF(), |
| 7725 | gfx::PointF(), |
| 7726 | gfx::Size(50, 50), |
| 7727 | false); |
| 7728 | child->SetDrawsContent(true); |
| 7729 | child->SetOpacity(0.0f); |
| 7730 | |
| 7731 | // Add opacity animation. |
| 7732 | AddOpacityTransitionToController( |
| 7733 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 7734 | |
| 7735 | root->AddChild(child.Pass()); |
| 7736 | |
| 7737 | std::vector<LayerImpl*> render_surface_layer_list; |
| 7738 | int dummy_max_texture_size = 512; |
| 7739 | LayerTreeHostCommon::CalculateDrawProperties(root.get(), |
| 7740 | root->bounds(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame^] | 7741 | gfx::Transform(), |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7742 | 1.f, |
| 7743 | 1.f, |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 7744 | NULL, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7745 | dummy_max_texture_size, |
| 7746 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7747 | true, // can_adjust_raster_scale |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 7748 | &render_surface_layer_list); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7749 | |
| 7750 | // We should have one render surface and two layers. The child |
| 7751 | // layer should be included even though it is transparent. |
| 7752 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 7753 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 7754 | } |
| 7755 | |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7756 | typedef std::tr1::tuple<bool, bool> LCDTextTestParam; |
| 7757 | class LCDTextTest : public testing::TestWithParam<LCDTextTestParam> { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7758 | protected: |
| 7759 | virtual void SetUp() { |
| 7760 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7761 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7762 | root_ = Layer::Create(); |
| 7763 | child_ = Layer::Create(); |
| 7764 | grand_child_ = Layer::Create(); |
| 7765 | child_->AddChild(grand_child_.get()); |
| 7766 | root_->AddChild(child_.get()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7767 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7768 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7769 | SetLayerPropertiesForTesting(root_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7770 | identity_matrix, |
| 7771 | identity_matrix, |
| 7772 | gfx::PointF(), |
| 7773 | gfx::PointF(), |
| 7774 | gfx::Size(1, 1), |
| 7775 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7776 | SetLayerPropertiesForTesting(child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7777 | identity_matrix, |
| 7778 | identity_matrix, |
| 7779 | gfx::PointF(), |
| 7780 | gfx::PointF(), |
| 7781 | gfx::Size(1, 1), |
| 7782 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7783 | SetLayerPropertiesForTesting(grand_child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7784 | identity_matrix, |
| 7785 | identity_matrix, |
| 7786 | gfx::PointF(), |
| 7787 | gfx::PointF(), |
| 7788 | gfx::Size(1, 1), |
| 7789 | false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7790 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7791 | child_->SetForceRenderSurface(std::tr1::get<1>(GetParam())); |
| 7792 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7793 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7794 | bool can_use_lcd_text_; |
| 7795 | scoped_refptr<Layer> root_; |
| 7796 | scoped_refptr<Layer> child_; |
| 7797 | scoped_refptr<Layer> grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7798 | }; |
| 7799 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7800 | TEST_P(LCDTextTest, CanUseLCDText) { |
| 7801 | // Case 1: Identity transform. |
| 7802 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7803 | ExecuteCalculateDrawProperties( |
| 7804 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7805 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7806 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7807 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7808 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7809 | // Case 2: Integral translation. |
| 7810 | gfx::Transform integral_translation; |
| 7811 | integral_translation.Translate(1.0, 2.0); |
| 7812 | child_->SetTransform(integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7813 | ExecuteCalculateDrawProperties( |
| 7814 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7815 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7816 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7817 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7818 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7819 | // Case 3: Non-integral translation. |
| 7820 | gfx::Transform non_integral_translation; |
| 7821 | non_integral_translation.Translate(1.5, 2.5); |
| 7822 | child_->SetTransform(non_integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7823 | ExecuteCalculateDrawProperties( |
| 7824 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7825 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7826 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7827 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7828 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7829 | // Case 4: Rotation. |
| 7830 | gfx::Transform rotation; |
| 7831 | rotation.Rotate(10.0); |
| 7832 | child_->SetTransform(rotation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7833 | ExecuteCalculateDrawProperties( |
| 7834 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7835 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7836 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7837 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7838 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7839 | // Case 5: Scale. |
| 7840 | gfx::Transform scale; |
| 7841 | scale.Scale(2.0, 2.0); |
| 7842 | child_->SetTransform(scale); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7843 | ExecuteCalculateDrawProperties( |
| 7844 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7845 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7846 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7847 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7848 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7849 | // Case 6: Skew. |
| 7850 | gfx::Transform skew; |
| 7851 | skew.SkewX(10.0); |
| 7852 | child_->SetTransform(skew); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7853 | ExecuteCalculateDrawProperties( |
| 7854 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7855 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7856 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7857 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7858 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7859 | // Case 7: Translucent. |
| 7860 | child_->SetTransform(identity_matrix); |
| 7861 | child_->SetOpacity(0.5f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7862 | ExecuteCalculateDrawProperties( |
| 7863 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7864 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7865 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7866 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7867 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7868 | // Case 8: Sanity check: restore transform and opacity. |
| 7869 | child_->SetTransform(identity_matrix); |
| 7870 | child_->SetOpacity(1.f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7871 | ExecuteCalculateDrawProperties( |
| 7872 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7873 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7874 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7875 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7876 | } |
| 7877 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7878 | TEST_P(LCDTextTest, verifycan_use_lcd_textWithAnimation) { |
| 7879 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7880 | ExecuteCalculateDrawProperties( |
| 7881 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7882 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7883 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7884 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7885 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7886 | // Add opacity animation. |
| 7887 | child_->SetOpacity(0.9f); |
| 7888 | AddOpacityTransitionToController( |
| 7889 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7890 | |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7891 | ExecuteCalculateDrawProperties( |
| 7892 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7893 | // Text AA should not be adjusted while animation is active. |
| 7894 | // Make sure LCD text AA setting remains unchanged. |
| 7895 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7896 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7897 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7898 | } |
| 7899 | |
| 7900 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 7901 | LCDTextTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7902 | testing::Combine(testing::Bool(), testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7903 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 7904 | } // namespace |
| 7905 | } // namespace cc |