[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] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7 | #include <set> |
| 8 | |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 9 | #include "cc/animation/layer_animation_controller.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 10 | #include "cc/base/math_util.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 11 | #include "cc/layers/content_layer.h" |
| 12 | #include "cc/layers/content_layer_client.h" |
| 13 | #include "cc/layers/heads_up_display_layer_impl.h" |
| 14 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 15 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 16 | #include "cc/layers/layer_impl.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 17 | #include "cc/layers/render_surface.h" |
| 18 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 19 | #include "cc/output/copy_output_request.h" |
| 20 | #include "cc/output/copy_output_result.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 21 | #include "cc/test/animation_test_common.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 22 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 23 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 24 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 25 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 26 | #include "cc/trees/layer_tree_impl.h" |
| 27 | #include "cc/trees/proxy.h" |
| 28 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 29 | #include "testing/gmock/include/gmock/gmock.h" |
| 30 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 93698c1 | 2012-12-07 00:43:56 | [diff] [blame] | 31 | #include "ui/gfx/quad_f.h" |
| 32 | #include "ui/gfx/size_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 33 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 34 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 35 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 36 | namespace { |
| 37 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 38 | class LayerTreeHostCommonTestBase { |
| 39 | protected: |
| 40 | template <typename LayerType> |
| 41 | void SetLayerPropertiesForTestingInternal( |
| 42 | LayerType* layer, |
| 43 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 44 | const gfx::PointF& anchor, |
| 45 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 46 | const gfx::Size& bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 47 | bool flatten_transform, |
| 48 | bool is_3d_sorted) { |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 49 | layer->SetTransform(transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 50 | layer->SetAnchorPoint(anchor); |
| 51 | layer->SetPosition(position); |
| 52 | layer->SetBounds(bounds); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 53 | layer->SetShouldFlattenTransform(flatten_transform); |
| 54 | layer->SetIs3dSorted(is_3d_sorted); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 55 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 56 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 57 | void SetLayerPropertiesForTesting(Layer* layer, |
| 58 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 59 | const gfx::PointF& anchor, |
| 60 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 61 | const gfx::Size& bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 62 | bool flatten_transform, |
| 63 | bool is_3d_sorted) { |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 64 | SetLayerPropertiesForTestingInternal<Layer>(layer, |
| 65 | transform, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 66 | anchor, |
| 67 | position, |
| 68 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 69 | flatten_transform, |
| 70 | is_3d_sorted); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 71 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 73 | void SetLayerPropertiesForTesting(LayerImpl* layer, |
| 74 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 75 | const gfx::PointF& anchor, |
| 76 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 77 | const gfx::Size& bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 78 | bool flatten_transform, |
| 79 | bool is_3d_sorted) { |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 80 | SetLayerPropertiesForTestingInternal<LayerImpl>(layer, |
| 81 | transform, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 82 | anchor, |
| 83 | position, |
| 84 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 85 | flatten_transform, |
| 86 | is_3d_sorted); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 87 | layer->SetContentBounds(bounds); |
| 88 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 89 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 90 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 91 | float device_scale_factor, |
| 92 | float page_scale_factor, |
| 93 | Layer* page_scale_application_layer, |
| 94 | bool can_use_lcd_text) { |
| 95 | EXPECT_TRUE(page_scale_application_layer || (page_scale_factor == 1.f)); |
| 96 | gfx::Transform identity_matrix; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 97 | gfx::Size device_viewport_size = |
| 98 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 99 | root_layer->bounds().height() * device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 100 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 101 | render_surface_layer_list_.reset(new RenderSurfaceLayerList); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 102 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 103 | // We are probably not testing what is intended if the root_layer bounds are |
| 104 | // empty. |
| 105 | DCHECK(!root_layer->bounds().IsEmpty()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 106 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 107 | root_layer, device_viewport_size, render_surface_layer_list_.get()); |
| 108 | inputs.device_scale_factor = device_scale_factor; |
| 109 | inputs.page_scale_factor = page_scale_factor; |
| 110 | inputs.page_scale_application_layer = page_scale_application_layer; |
| 111 | inputs.can_use_lcd_text = can_use_lcd_text; |
| 112 | inputs.can_adjust_raster_scales = true; |
| 113 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 114 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 115 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 116 | void ExecuteCalculateDrawProperties(LayerImpl* root_layer, |
| 117 | float device_scale_factor, |
| 118 | float page_scale_factor, |
| 119 | LayerImpl* page_scale_application_layer, |
| 120 | bool can_use_lcd_text) { |
| 121 | gfx::Transform identity_matrix; |
| 122 | LayerImplList dummy_render_surface_layer_list; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 123 | gfx::Size device_viewport_size = |
| 124 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 125 | root_layer->bounds().height() * device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 126 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 127 | // We are probably not testing what is intended if the root_layer bounds are |
| 128 | // empty. |
| 129 | DCHECK(!root_layer->bounds().IsEmpty()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 130 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 131 | root_layer, device_viewport_size, &dummy_render_surface_layer_list); |
| 132 | inputs.device_scale_factor = device_scale_factor; |
| 133 | inputs.page_scale_factor = page_scale_factor; |
| 134 | inputs.page_scale_application_layer = page_scale_application_layer; |
| 135 | inputs.can_use_lcd_text = can_use_lcd_text; |
| 136 | inputs.can_adjust_raster_scales = true; |
| 137 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 138 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 139 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 140 | template <class LayerType> |
| 141 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 142 | LayerType* page_scale_application_layer = NULL; |
| 143 | ExecuteCalculateDrawProperties( |
| 144 | root_layer, 1.f, 1.f, page_scale_application_layer, false); |
| 145 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 146 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 147 | template <class LayerType> |
| 148 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 149 | float device_scale_factor) { |
| 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); |
| 156 | } |
| 157 | |
| 158 | template <class LayerType> |
| 159 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 160 | float device_scale_factor, |
| 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); |
| 168 | } |
| 169 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 170 | RenderSurfaceLayerList* render_surface_layer_list() const { |
| 171 | return render_surface_layer_list_.get(); |
| 172 | } |
| 173 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 174 | private: |
| 175 | scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_; |
| 176 | }; |
| 177 | |
| 178 | class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, |
| 179 | public testing::Test { |
| 180 | }; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 181 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 182 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 183 | public: |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 184 | LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 185 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 186 | virtual bool DrawsContent() const OVERRIDE; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 187 | virtual void CalculateContentsScale(float ideal_contents_scale, |
| 188 | float device_scale_factor, |
| 189 | float page_scale_factor, |
| 190 | bool animating_transform_to_screen, |
| 191 | float* contents_scale_x, |
| 192 | float* contents_scale_y, |
| 193 | gfx::Size* content_bounds) OVERRIDE; |
| 194 | |
| 195 | float last_device_scale_factor() const { return last_device_scale_factor_; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 196 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 197 | private: |
| 198 | virtual ~LayerWithForcedDrawsContent() {} |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 199 | |
| 200 | // Parameters from last CalculateContentsScale. |
| 201 | float last_device_scale_factor_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 202 | }; |
| 203 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 204 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 205 | |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 206 | void LayerWithForcedDrawsContent::CalculateContentsScale( |
| 207 | float ideal_contents_scale, |
| 208 | float device_scale_factor, |
| 209 | float page_scale_factor, |
| 210 | bool animating_transform_to_screen, |
| 211 | float* contents_scale_x, |
| 212 | float* contents_scale_y, |
| 213 | gfx::Size* content_bounds) { |
| 214 | last_device_scale_factor_ = device_scale_factor; |
| 215 | Layer::CalculateContentsScale(ideal_contents_scale, |
| 216 | device_scale_factor, |
| 217 | page_scale_factor, |
| 218 | animating_transform_to_screen, |
| 219 | contents_scale_x, |
| 220 | contents_scale_y, |
| 221 | content_bounds); |
| 222 | } |
| 223 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 224 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 225 | public: |
| 226 | MockContentLayerClient() {} |
| 227 | virtual ~MockContentLayerClient() {} |
| 228 | virtual void PaintContents(SkCanvas* canvas, |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 229 | const gfx::Rect& clip, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 230 | gfx::RectF* opaque) OVERRIDE {} |
| 231 | virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} |
[email protected] | 1d96e03 | 2014-03-25 05:59:08 | [diff] [blame] | 232 | virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 233 | }; |
| 234 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 235 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 236 | ContentLayerClient* delegate) { |
| 237 | scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 238 | to_return->SetIsDrawable(true); |
| 239 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 240 | } |
| 241 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 242 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 243 | do { \ |
| 244 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 245 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 246 | } while (false) |
| 247 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 248 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 249 | // Sanity check: For layers positioned at zero, with zero size, |
| 250 | // and with identity transforms, then the draw transform, |
| 251 | // screen space transform, and the hierarchy passed on to children |
| 252 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 253 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 254 | scoped_refptr<Layer> parent = Layer::Create(); |
| 255 | scoped_refptr<Layer> child = Layer::Create(); |
| 256 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 257 | parent->AddChild(child); |
| 258 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 259 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 260 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 261 | host->SetRootLayer(parent); |
| 262 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 263 | gfx::Transform identity_matrix; |
| 264 | SetLayerPropertiesForTesting(parent.get(), |
| 265 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 266 | gfx::PointF(), |
| 267 | gfx::PointF(), |
| 268 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 269 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 270 | false); |
| 271 | SetLayerPropertiesForTesting(child.get(), |
| 272 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 273 | gfx::PointF(), |
| 274 | gfx::PointF(), |
| 275 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 276 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 277 | false); |
| 278 | SetLayerPropertiesForTesting(grand_child.get(), |
| 279 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 280 | gfx::PointF(), |
| 281 | gfx::PointF(), |
| 282 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 283 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 284 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 285 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 286 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 287 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 288 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 289 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 290 | child->screen_space_transform()); |
| 291 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 292 | grand_child->draw_transform()); |
| 293 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 294 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 297 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 298 | gfx::Transform identity_matrix; |
| 299 | scoped_refptr<Layer> layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 300 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 301 | scoped_refptr<Layer> root = Layer::Create(); |
| 302 | SetLayerPropertiesForTesting(root.get(), |
| 303 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 304 | gfx::PointF(), |
| 305 | gfx::PointF(), |
| 306 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 307 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 308 | false); |
| 309 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 310 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 311 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 312 | host->SetRootLayer(root); |
| 313 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 314 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 315 | // transform or the screenspace transform. |
| 316 | gfx::Transform translation_to_center; |
| 317 | translation_to_center.Translate(5.0, 6.0); |
| 318 | SetLayerPropertiesForTesting(layer.get(), |
| 319 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 320 | gfx::PointF(), |
| 321 | gfx::PointF(), |
| 322 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 323 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 324 | false); |
| 325 | ExecuteCalculateDrawProperties(root.get()); |
| 326 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 327 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 328 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 329 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 330 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 331 | // no effect on the transforms. |
| 332 | SetLayerPropertiesForTesting(layer.get(), |
| 333 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 334 | gfx::PointF(0.25f, 0.25f), |
| 335 | gfx::PointF(), |
| 336 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 337 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 338 | false); |
| 339 | ExecuteCalculateDrawProperties(root.get()); |
| 340 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 341 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 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 4: A change in actual position affects both the draw transform and |
| 345 | // screen space transform. |
| 346 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 347 | position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 348 | SetLayerPropertiesForTesting(layer.get(), |
| 349 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 350 | gfx::PointF(0.25f, 0.25f), |
| 351 | gfx::PointF(0.f, 1.2f), |
| 352 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 353 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 354 | false); |
| 355 | ExecuteCalculateDrawProperties(root.get()); |
| 356 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 357 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 358 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 359 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 360 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 361 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 362 | // scale transform, because scale and translation are not commutative. |
| 363 | gfx::Transform layer_transform; |
| 364 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 365 | SetLayerPropertiesForTesting(layer.get(), |
| 366 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 367 | gfx::PointF(), |
| 368 | gfx::PointF(), |
| 369 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 370 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 371 | false); |
| 372 | ExecuteCalculateDrawProperties(root.get()); |
| 373 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 374 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 375 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 376 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 377 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 378 | gfx::Transform translation_to_anchor; |
| 379 | translation_to_anchor.Translate(5.0, 0.0); |
| 380 | gfx::Transform expected_result = |
| 381 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 382 | SetLayerPropertiesForTesting(layer.get(), |
| 383 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 384 | gfx::PointF(0.5f, 0.f), |
| 385 | gfx::PointF(), |
| 386 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 387 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 388 | false); |
| 389 | ExecuteCalculateDrawProperties(root.get()); |
| 390 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 391 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 392 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 393 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 394 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 395 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 396 | // it is still worth testing to detect accidental regressions. |
| 397 | expected_result = position_transform * translation_to_anchor * |
| 398 | layer_transform * Inverse(translation_to_anchor); |
| 399 | SetLayerPropertiesForTesting(layer.get(), |
| 400 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 401 | gfx::PointF(0.5f, 0.f), |
| 402 | gfx::PointF(0.f, 1.2f), |
| 403 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 404 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 405 | false); |
| 406 | ExecuteCalculateDrawProperties(root.get()); |
| 407 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 408 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 409 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 410 | } |
| 411 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 412 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 413 | const gfx::Vector2d kScrollOffset(50, 100); |
| 414 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 415 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 416 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 417 | -kScrollOffset.y()); |
| 418 | const float kPageScale = 0.888f; |
| 419 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 420 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 421 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 422 | TestSharedBitmapManager shared_bitmap_manager; |
| 423 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 424 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 425 | gfx::Transform identity_matrix; |
| 426 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 427 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 428 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 429 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 430 | kPageScale * kDeviceScale); |
| 431 | SetLayerPropertiesForTesting(sublayer, |
| 432 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 433 | gfx::Point(), |
| 434 | gfx::PointF(), |
| 435 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 436 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 437 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 438 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 439 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 440 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 441 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 442 | SetLayerPropertiesForTesting(scroll_layer, |
| 443 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 444 | gfx::PointF(), |
[email protected] | 4ec78f8 | 2013-07-11 18:45:47 | [diff] [blame] | 445 | gfx::PointF(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 446 | gfx::Size(10, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 447 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 448 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 449 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 450 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 451 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 452 | |
| 453 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 454 | clip_layer->SetBounds( |
| 455 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 456 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 457 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 458 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 459 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 460 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 461 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
| 462 | clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
| 463 | scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 464 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 465 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
| 466 | SetLayerPropertiesForTesting(root.get(), |
| 467 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 468 | gfx::PointF(), |
| 469 | gfx::PointF(), |
| 470 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 471 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 472 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 473 | root->AddChild(clip_layer_scoped_ptr.Pass()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 474 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 475 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 476 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 477 | gfx::Transform expected_transform = identity_matrix; |
| 478 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 479 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 480 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 481 | MathUtil::Round(sub_layer_screen_position.y())); |
| 482 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 483 | sublayer->draw_transform()); |
| 484 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 485 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 486 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 487 | gfx::Transform arbitrary_translate; |
| 488 | const float kTranslateX = 10.6f; |
| 489 | const float kTranslateY = 20.6f; |
| 490 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
| 491 | SetLayerPropertiesForTesting(scroll_layer, |
| 492 | arbitrary_translate, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 493 | gfx::PointF(), |
[email protected] | 4ec78f8 | 2013-07-11 18:45:47 | [diff] [blame] | 494 | gfx::PointF(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 495 | gfx::Size(10, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 496 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 497 | false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 498 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 499 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 500 | expected_transform.MakeIdentity(); |
| 501 | expected_transform.Translate( |
| 502 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 503 | sub_layer_screen_position.x()), |
| 504 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 505 | sub_layer_screen_position.y())); |
| 506 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 507 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 508 | } |
| 509 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 510 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 511 | gfx::Transform identity_matrix; |
| 512 | scoped_refptr<Layer> root = Layer::Create(); |
| 513 | scoped_refptr<Layer> parent = Layer::Create(); |
| 514 | scoped_refptr<Layer> child = Layer::Create(); |
| 515 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 516 | root->AddChild(parent); |
| 517 | parent->AddChild(child); |
| 518 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 519 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 520 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 521 | host->SetRootLayer(root); |
| 522 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 523 | // One-time setup of root layer |
| 524 | SetLayerPropertiesForTesting(root.get(), |
| 525 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 526 | gfx::PointF(), |
| 527 | gfx::PointF(), |
| 528 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 529 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 530 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 531 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 532 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 533 | SetLayerPropertiesForTesting(parent.get(), |
| 534 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 535 | gfx::PointF(0.25f, 0.25f), |
| 536 | gfx::PointF(), |
| 537 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 538 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 539 | false); |
| 540 | SetLayerPropertiesForTesting(child.get(), |
| 541 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 542 | gfx::PointF(), |
| 543 | gfx::PointF(), |
| 544 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 545 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 546 | false); |
| 547 | SetLayerPropertiesForTesting(grand_child.get(), |
| 548 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 549 | gfx::PointF(), |
| 550 | gfx::PointF(), |
| 551 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 552 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 553 | false); |
| 554 | ExecuteCalculateDrawProperties(root.get()); |
| 555 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 556 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 557 | child->screen_space_transform()); |
| 558 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 559 | grand_child->draw_transform()); |
| 560 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 561 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 562 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 563 | // Case 2: parent's position affects child and grand_child. |
| 564 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 565 | parent_position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 566 | SetLayerPropertiesForTesting(parent.get(), |
| 567 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 568 | gfx::PointF(0.25f, 0.25f), |
| 569 | gfx::PointF(0.f, 1.2f), |
| 570 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 571 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 572 | false); |
| 573 | SetLayerPropertiesForTesting(child.get(), |
| 574 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 575 | gfx::PointF(), |
| 576 | gfx::PointF(), |
| 577 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 578 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 579 | false); |
| 580 | SetLayerPropertiesForTesting(grand_child.get(), |
| 581 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 582 | gfx::PointF(), |
| 583 | gfx::PointF(), |
| 584 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 585 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 586 | false); |
| 587 | ExecuteCalculateDrawProperties(root.get()); |
| 588 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 589 | child->draw_transform()); |
| 590 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 591 | child->screen_space_transform()); |
| 592 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 593 | grand_child->draw_transform()); |
| 594 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 595 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 596 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 597 | // Case 3: parent's local transform affects child and grandchild |
| 598 | gfx::Transform parent_layer_transform; |
| 599 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 600 | gfx::Transform parent_translation_to_anchor; |
| 601 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 602 | gfx::Transform parent_composite_transform = |
| 603 | parent_translation_to_anchor * parent_layer_transform * |
| 604 | Inverse(parent_translation_to_anchor); |
| 605 | SetLayerPropertiesForTesting(parent.get(), |
| 606 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 607 | gfx::PointF(0.25f, 0.25f), |
| 608 | gfx::PointF(), |
| 609 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 610 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 611 | false); |
| 612 | SetLayerPropertiesForTesting(child.get(), |
| 613 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 614 | gfx::PointF(), |
| 615 | gfx::PointF(), |
| 616 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 617 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 618 | false); |
| 619 | SetLayerPropertiesForTesting(grand_child.get(), |
| 620 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 621 | gfx::PointF(), |
| 622 | gfx::PointF(), |
| 623 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 624 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 625 | false); |
| 626 | ExecuteCalculateDrawProperties(root.get()); |
| 627 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 628 | child->draw_transform()); |
| 629 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 630 | child->screen_space_transform()); |
| 631 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 632 | grand_child->draw_transform()); |
| 633 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 634 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 635 | } |
| 636 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 637 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 638 | scoped_refptr<Layer> root = Layer::Create(); |
| 639 | scoped_refptr<Layer> parent = Layer::Create(); |
| 640 | scoped_refptr<Layer> child = Layer::Create(); |
| 641 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 642 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 643 | root->AddChild(parent); |
| 644 | parent->AddChild(child); |
| 645 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 646 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 647 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 648 | host->SetRootLayer(root); |
| 649 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 650 | // One-time setup of root layer |
| 651 | gfx::Transform identity_matrix; |
| 652 | SetLayerPropertiesForTesting(root.get(), |
| 653 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 654 | gfx::PointF(), |
| 655 | gfx::PointF(), |
| 656 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 657 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 658 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 659 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 660 | // Child is set up so that a new render surface should be created. |
| 661 | child->SetOpacity(0.5f); |
| 662 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 663 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 664 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 665 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 666 | gfx::Transform parent_translation_to_anchor; |
| 667 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 668 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 669 | gfx::Transform parent_composite_transform = |
| 670 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 671 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 672 | gfx::Vector2dF parent_composite_scale = |
| 673 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 674 | 1.f); |
| 675 | gfx::Transform surface_sublayer_transform; |
| 676 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 677 | parent_composite_scale.y()); |
| 678 | gfx::Transform surface_sublayer_composite_transform = |
| 679 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 680 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 681 | // Child's render surface should not exist yet. |
| 682 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 683 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 684 | SetLayerPropertiesForTesting(parent.get(), |
| 685 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 686 | gfx::PointF(0.25f, 0.25f), |
| 687 | gfx::PointF(), |
| 688 | gfx::Size(100, 120), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 689 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 690 | false); |
| 691 | SetLayerPropertiesForTesting(child.get(), |
| 692 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 693 | gfx::PointF(), |
| 694 | gfx::PointF(), |
| 695 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 696 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 697 | false); |
| 698 | SetLayerPropertiesForTesting(grand_child.get(), |
| 699 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 700 | gfx::PointF(), |
| 701 | gfx::PointF(), |
| 702 | gfx::Size(8, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 703 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 704 | false); |
| 705 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 706 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 707 | // Render surface should have been created now. |
| 708 | ASSERT_TRUE(child->render_surface()); |
| 709 | ASSERT_EQ(child, child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 711 | // The child layer's draw transform should refer to its new render surface. |
| 712 | // The screen-space transform, however, should still refer to the root. |
| 713 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 714 | child->draw_transform()); |
| 715 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 716 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 717 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 718 | // Because the grand_child is the only drawable content, the child's render |
| 719 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 720 | // surface's subtree is drawn must be removed from the composite transform. |
| 721 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 722 | surface_sublayer_composite_transform, |
| 723 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 724 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 725 | // The screen space is the same as the target since the child surface draws |
| 726 | // into the root. |
| 727 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 728 | surface_sublayer_composite_transform, |
| 729 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 730 | } |
| 731 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 732 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 733 | scoped_refptr<Layer> root = Layer::Create(); |
| 734 | scoped_refptr<Layer> parent = Layer::Create(); |
| 735 | scoped_refptr<Layer> child = Layer::Create(); |
| 736 | scoped_refptr<Layer> child_replica = Layer::Create(); |
| 737 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 738 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 739 | root->AddChild(parent); |
| 740 | parent->AddChild(child); |
| 741 | child->AddChild(grand_child); |
| 742 | child->SetReplicaLayer(child_replica.get()); |
| 743 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 744 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 745 | host->SetRootLayer(root); |
| 746 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 747 | // One-time setup of root layer |
| 748 | gfx::Transform identity_matrix; |
| 749 | SetLayerPropertiesForTesting(root.get(), |
| 750 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 751 | gfx::PointF(), |
| 752 | gfx::PointF(), |
| 753 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 754 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 755 | false); |
| 756 | |
| 757 | // Child is set up so that a new render surface should be created. |
| 758 | child->SetOpacity(0.5f); |
| 759 | |
| 760 | gfx::Transform parent_layer_transform; |
| 761 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 762 | gfx::Transform parent_translation_to_anchor; |
| 763 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 764 | gfx::Transform parent_composite_transform = |
| 765 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 766 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 767 | gfx::Transform replica_layer_transform; |
| 768 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 769 | gfx::Vector2dF parent_composite_scale = |
| 770 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 771 | 1.f); |
| 772 | gfx::Transform surface_sublayer_transform; |
| 773 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 774 | parent_composite_scale.y()); |
| 775 | gfx::Transform replica_composite_transform = |
| 776 | parent_composite_transform * replica_layer_transform * |
| 777 | Inverse(surface_sublayer_transform); |
| 778 | |
| 779 | // Child's render surface should not exist yet. |
| 780 | ASSERT_FALSE(child->render_surface()); |
| 781 | |
| 782 | SetLayerPropertiesForTesting(parent.get(), |
| 783 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 784 | gfx::PointF(0.25f, 0.25f), |
| 785 | gfx::PointF(), |
| 786 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 787 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 788 | false); |
| 789 | SetLayerPropertiesForTesting(child.get(), |
| 790 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 791 | gfx::PointF(), |
| 792 | gfx::PointF(), |
| 793 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 794 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 795 | false); |
| 796 | SetLayerPropertiesForTesting(grand_child.get(), |
| 797 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 798 | gfx::PointF(), |
| 799 | gfx::PointF(-0.5f, -0.5f), |
| 800 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 801 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 802 | false); |
| 803 | SetLayerPropertiesForTesting(child_replica.get(), |
| 804 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 805 | gfx::PointF(), |
| 806 | gfx::PointF(), |
| 807 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 808 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 809 | false); |
| 810 | ExecuteCalculateDrawProperties(root.get()); |
| 811 | |
| 812 | // Render surface should have been created now. |
| 813 | ASSERT_TRUE(child->render_surface()); |
| 814 | ASSERT_EQ(child, child->render_target()); |
| 815 | |
| 816 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 817 | replica_composite_transform, |
| 818 | child->render_target()->render_surface()->replica_draw_transform()); |
| 819 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 820 | child->render_target() |
| 821 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 822 | ->replica_screen_space_transform()); |
| 823 | } |
| 824 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 825 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 826 | // This test creates a more complex tree and verifies it all at once. This |
| 827 | // covers the following cases: |
| 828 | // - layers that are described w.r.t. a render surface: should have draw |
| 829 | // transforms described w.r.t. that surface |
| 830 | // - A render surface described w.r.t. an ancestor render surface: should |
| 831 | // have a draw transform described w.r.t. that ancestor surface |
| 832 | // - Replicas of a render surface are described w.r.t. the replica's |
| 833 | // transform around its anchor, along with the surface itself. |
| 834 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 835 | // a render surface that is described w.r.t. an ancestor render surface. |
| 836 | // - verifying that each layer has a reference to the correct render surface |
| 837 | // and render target values. |
| 838 | |
| 839 | scoped_refptr<Layer> root = Layer::Create(); |
| 840 | scoped_refptr<Layer> parent = Layer::Create(); |
| 841 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 842 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 843 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 844 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 845 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 846 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); |
| 847 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); |
| 848 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 849 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 850 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 851 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 852 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 853 | root->AddChild(parent); |
| 854 | parent->AddChild(render_surface1); |
| 855 | parent->AddChild(child_of_root); |
| 856 | render_surface1->AddChild(child_of_rs1); |
| 857 | render_surface1->AddChild(render_surface2); |
| 858 | render_surface2->AddChild(child_of_rs2); |
| 859 | child_of_root->AddChild(grand_child_of_root); |
| 860 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 861 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 862 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 863 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 864 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 865 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 866 | host->SetRootLayer(root); |
| 867 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 868 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 869 | // to have a new render surface. |
| 870 | render_surface1->SetOpacity(0.5f); |
| 871 | render_surface2->SetOpacity(0.33f); |
| 872 | |
| 873 | // One-time setup of root layer |
| 874 | gfx::Transform identity_matrix; |
| 875 | SetLayerPropertiesForTesting(root.get(), |
| 876 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 877 | gfx::PointF(), |
| 878 | gfx::PointF(), |
| 879 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 880 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 881 | false); |
| 882 | |
| 883 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 884 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 885 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 886 | gfx::Transform translation_to_anchor; |
| 887 | translation_to_anchor.Translate(2.5, 0.0); |
| 888 | gfx::Transform layer_transform; |
| 889 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 890 | gfx::Transform replica_layer_transform; |
| 891 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 892 | |
| 893 | gfx::Transform A = |
| 894 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 895 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 896 | Inverse(translation_to_anchor); |
| 897 | |
| 898 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 899 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 900 | gfx::Transform surface1_sublayer_transform; |
| 901 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 902 | surface1_parent_transform_scale.y()); |
| 903 | |
| 904 | // SS1 = transform given to the subtree of render_surface1 |
| 905 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 906 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 907 | // the owning layer |
| 908 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 909 | |
| 910 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 911 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 912 | gfx::Transform surface2_sublayer_transform; |
| 913 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 914 | surface2_parent_transform_scale.y()); |
| 915 | |
| 916 | // SS2 = transform given to the subtree of render_surface2 |
| 917 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 918 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 919 | // the owning layer |
| 920 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 921 | |
| 922 | SetLayerPropertiesForTesting(parent.get(), |
| 923 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 924 | gfx::PointF(0.25f, 0.f), |
| 925 | gfx::PointF(), |
| 926 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 927 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 928 | false); |
| 929 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 930 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 931 | gfx::PointF(0.25f, 0.f), |
| 932 | gfx::PointF(), |
| 933 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 934 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 935 | false); |
| 936 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 937 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 938 | gfx::PointF(0.25f, 0.f), |
| 939 | gfx::PointF(), |
| 940 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 941 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 942 | false); |
| 943 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 944 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 945 | gfx::PointF(0.25f, 0.f), |
| 946 | gfx::PointF(), |
| 947 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 948 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 949 | false); |
| 950 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 951 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 952 | gfx::PointF(0.25f, 0.f), |
| 953 | gfx::PointF(), |
| 954 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 955 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 956 | false); |
| 957 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 958 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 959 | gfx::PointF(0.25f, 0.f), |
| 960 | gfx::PointF(), |
| 961 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 962 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 963 | false); |
| 964 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 965 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 966 | gfx::PointF(0.25f, 0.f), |
| 967 | gfx::PointF(), |
| 968 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 969 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 970 | false); |
| 971 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 972 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 973 | gfx::PointF(0.25f, 0.f), |
| 974 | gfx::PointF(), |
| 975 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 976 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 977 | false); |
| 978 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 979 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 980 | gfx::PointF(0.25f, 0.f), |
| 981 | gfx::PointF(), |
| 982 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 983 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 984 | false); |
| 985 | SetLayerPropertiesForTesting(replica_of_rs1.get(), |
| 986 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 987 | gfx::PointF(0.25f, 0.f), |
| 988 | gfx::PointF(), |
| 989 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 990 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 991 | false); |
| 992 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 993 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 994 | gfx::PointF(0.25f, 0.f), |
| 995 | gfx::PointF(), |
| 996 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 997 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 998 | false); |
| 999 | |
| 1000 | ExecuteCalculateDrawProperties(root.get()); |
| 1001 | |
| 1002 | // Only layers that are associated with render surfaces should have an actual |
| 1003 | // RenderSurface() value. |
| 1004 | ASSERT_TRUE(root->render_surface()); |
| 1005 | ASSERT_FALSE(child_of_root->render_surface()); |
| 1006 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 1007 | |
| 1008 | ASSERT_TRUE(render_surface1->render_surface()); |
| 1009 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 1010 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 1011 | |
| 1012 | ASSERT_TRUE(render_surface2->render_surface()); |
| 1013 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 1014 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 1015 | |
| 1016 | // Verify all render target accessors |
| 1017 | EXPECT_EQ(root, parent->render_target()); |
| 1018 | EXPECT_EQ(root, child_of_root->render_target()); |
| 1019 | EXPECT_EQ(root, grand_child_of_root->render_target()); |
| 1020 | |
| 1021 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 1022 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 1023 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 1024 | |
| 1025 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 1026 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 1027 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 1028 | |
| 1029 | // Verify layer draw transforms note that draw transforms are described with |
| 1030 | // respect to the nearest ancestor render surface but screen space transforms |
| 1031 | // are described with respect to the root. |
| 1032 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1033 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); |
| 1034 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1035 | grand_child_of_root->draw_transform()); |
| 1036 | |
| 1037 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1038 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); |
| 1039 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1040 | grand_child_of_rs1->draw_transform()); |
| 1041 | |
| 1042 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1043 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); |
| 1044 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1045 | grand_child_of_rs2->draw_transform()); |
| 1046 | |
| 1047 | // Verify layer screen-space transforms |
| 1048 | // |
| 1049 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1050 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1051 | child_of_root->screen_space_transform()); |
| 1052 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1053 | A * A * A, grand_child_of_root->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1054 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1055 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1056 | render_surface1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1057 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1058 | child_of_rs1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1059 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1060 | grand_child_of_rs1->screen_space_transform()); |
| 1061 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1062 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1063 | render_surface2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1064 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1065 | child_of_rs2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1066 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1067 | grand_child_of_rs2->screen_space_transform()); |
| 1068 | |
| 1069 | // Verify render surface transforms. |
| 1070 | // |
| 1071 | // Draw transform of render surface 1 is described with respect to root. |
| 1072 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1073 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1074 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1075 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1076 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1077 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1078 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1079 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1080 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 1081 | // Draw transform of render surface 2 is described with respect to render |
| 1082 | // surface 1. |
| 1083 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1084 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1085 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1086 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1087 | render_surface2->render_surface()->replica_draw_transform()); |
| 1088 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1089 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1090 | render_surface2->render_surface()->screen_space_transform()); |
| 1091 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1092 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1093 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 1094 | |
| 1095 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1096 | // is expected that we correctly set up transforms so that the y-component of |
| 1097 | // the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1098 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 1099 | EXPECT_FLOAT_EQ(2.0, |
| 1100 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1101 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1102 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1103 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1104 | EXPECT_FLOAT_EQ(2.0, |
| 1105 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 1106 | EXPECT_FLOAT_EQ(3.0, |
| 1107 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1108 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1109 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1110 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1111 | EXPECT_FLOAT_EQ(3.0, |
| 1112 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 1113 | EXPECT_FLOAT_EQ(4.0, |
| 1114 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1115 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1116 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1117 | } |
| 1118 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1119 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1120 | // For layers that flatten their subtree, there should be an orthographic |
| 1121 | // projection (for x and y values) in the middle of the transform sequence. |
| 1122 | // Note that the way the code is currently implemented, it is not expected to |
| 1123 | // use a canonical orthographic projection. |
| 1124 | |
| 1125 | scoped_refptr<Layer> root = Layer::Create(); |
| 1126 | scoped_refptr<Layer> child = Layer::Create(); |
| 1127 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1128 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1129 | |
| 1130 | gfx::Transform rotation_about_y_axis; |
| 1131 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1132 | |
| 1133 | const gfx::Transform identity_matrix; |
| 1134 | SetLayerPropertiesForTesting(root.get(), |
| 1135 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1136 | gfx::PointF(), |
| 1137 | gfx::PointF(), |
| 1138 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1139 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1140 | false); |
| 1141 | SetLayerPropertiesForTesting(child.get(), |
| 1142 | rotation_about_y_axis, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1143 | gfx::PointF(), |
| 1144 | gfx::PointF(), |
| 1145 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1146 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1147 | false); |
| 1148 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1149 | rotation_about_y_axis, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1150 | gfx::PointF(), |
| 1151 | gfx::PointF(), |
| 1152 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1153 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1154 | false); |
| 1155 | |
| 1156 | root->AddChild(child); |
| 1157 | child->AddChild(grand_child); |
| 1158 | child->SetForceRenderSurface(true); |
| 1159 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1160 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1161 | host->SetRootLayer(root); |
| 1162 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1163 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1164 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1165 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1166 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1167 | |
| 1168 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1169 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1170 | gfx::Transform expected_grand_child_draw_transform = |
| 1171 | rotation_about_y_axis; // draws onto child's render surface |
| 1172 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1173 | flattened_rotation_about_y.FlattenTo2d(); |
| 1174 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1175 | flattened_rotation_about_y * rotation_about_y_axis; |
| 1176 | |
| 1177 | ExecuteCalculateDrawProperties(root.get()); |
| 1178 | |
| 1179 | // The child's draw transform should have been taken by its surface. |
| 1180 | ASSERT_TRUE(child->render_surface()); |
| 1181 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1182 | child->render_surface()->draw_transform()); |
| 1183 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1184 | expected_child_screen_space_transform, |
| 1185 | child->render_surface()->screen_space_transform()); |
| 1186 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1187 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1188 | child->screen_space_transform()); |
| 1189 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1190 | grand_child->draw_transform()); |
| 1191 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1192 | grand_child->screen_space_transform()); |
| 1193 | } |
| 1194 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1195 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1196 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1197 | // skipping a necessary translation. Without that translation, the coordinate |
| 1198 | // space of the layer's draw transform is incorrect. |
| 1199 | // |
| 1200 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1201 | // but if that layer becomes a render surface, then its draw transform is |
| 1202 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1203 | // incorrectly as a result. |
| 1204 | |
| 1205 | scoped_refptr<Layer> root = Layer::Create(); |
| 1206 | scoped_refptr<Layer> child = Layer::Create(); |
| 1207 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1208 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1209 | |
| 1210 | // The child height is zero, but has non-zero width that should be accounted |
| 1211 | // for while computing draw transforms. |
| 1212 | const gfx::Transform identity_matrix; |
| 1213 | SetLayerPropertiesForTesting(root.get(), |
| 1214 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1215 | gfx::PointF(), |
| 1216 | gfx::PointF(), |
| 1217 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1218 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1219 | false); |
| 1220 | SetLayerPropertiesForTesting(child.get(), |
| 1221 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1222 | gfx::PointF(), |
| 1223 | gfx::PointF(), |
| 1224 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1225 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1226 | false); |
| 1227 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1228 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1229 | gfx::PointF(), |
| 1230 | gfx::PointF(), |
| 1231 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1232 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1233 | false); |
| 1234 | |
| 1235 | root->AddChild(child); |
| 1236 | child->AddChild(grand_child); |
| 1237 | child->SetForceRenderSurface(true); |
| 1238 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1239 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1240 | host->SetRootLayer(root); |
| 1241 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1242 | ExecuteCalculateDrawProperties(root.get()); |
| 1243 | |
| 1244 | ASSERT_TRUE(child->render_surface()); |
| 1245 | // This is the real test, the rest are sanity checks. |
| 1246 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1247 | child->render_surface()->draw_transform()); |
| 1248 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1249 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1250 | grand_child->draw_transform()); |
| 1251 | } |
| 1252 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1253 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1254 | // Transformations applied at the root of the tree should be forwarded |
| 1255 | // to child layers instead of applied to the root RenderSurface. |
| 1256 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 1257 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 1258 | new LayerWithForcedDrawsContent; |
| 1259 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1260 | new LayerWithForcedDrawsContent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1261 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1262 | root->AddChild(child); |
| 1263 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1264 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1265 | host->SetRootLayer(root); |
| 1266 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1267 | SetLayerPropertiesForTesting(root.get(), |
| 1268 | identity_matrix, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1269 | gfx::PointF(), |
| 1270 | gfx::PointF(), |
| 1271 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1272 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1273 | false); |
| 1274 | SetLayerPropertiesForTesting(child.get(), |
| 1275 | identity_matrix, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1276 | gfx::PointF(), |
| 1277 | gfx::PointF(), |
| 1278 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1279 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1280 | false); |
| 1281 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1282 | gfx::Transform translate; |
| 1283 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1284 | { |
| 1285 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1286 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1287 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1288 | inputs.can_adjust_raster_scales = true; |
| 1289 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1290 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1291 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1292 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 1293 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1294 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1295 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1296 | |
| 1297 | gfx::Transform scale; |
| 1298 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1299 | { |
| 1300 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1301 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1302 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
| 1303 | inputs.can_adjust_raster_scales = true; |
| 1304 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1305 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1306 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1307 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 1308 | EXPECT_EQ(2.f, root->last_device_scale_factor()); |
| 1309 | EXPECT_EQ(2.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1310 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1311 | |
| 1312 | gfx::Transform rotate; |
| 1313 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1314 | { |
| 1315 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1316 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1317 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
| 1318 | inputs.can_adjust_raster_scales = true; |
| 1319 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1320 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1321 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1322 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 1323 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1324 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1325 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1326 | |
| 1327 | gfx::Transform composite; |
| 1328 | composite.ConcatTransform(translate); |
| 1329 | composite.ConcatTransform(scale); |
| 1330 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1331 | { |
| 1332 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1333 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1334 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
| 1335 | inputs.can_adjust_raster_scales = true; |
| 1336 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1337 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1338 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1339 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1340 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1341 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1342 | // Verify it composes correctly with device scale. |
| 1343 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1344 | |
| 1345 | { |
| 1346 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1347 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1348 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1349 | inputs.device_scale_factor = device_scale_factor; |
| 1350 | inputs.can_adjust_raster_scales = true; |
| 1351 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1352 | gfx::Transform device_scaled_translate = translate; |
| 1353 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1354 | EXPECT_EQ(device_scaled_translate, |
| 1355 | root->draw_properties().target_space_transform); |
| 1356 | EXPECT_EQ(device_scaled_translate, |
| 1357 | child->draw_properties().target_space_transform); |
| 1358 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 1359 | EXPECT_EQ(device_scale_factor, root->last_device_scale_factor()); |
| 1360 | EXPECT_EQ(device_scale_factor, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1361 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1362 | |
| 1363 | // Verify it composes correctly with page scale. |
| 1364 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1365 | |
| 1366 | { |
| 1367 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1368 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1369 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1370 | inputs.page_scale_factor = page_scale_factor; |
| 1371 | inputs.page_scale_application_layer = root.get(); |
| 1372 | inputs.can_adjust_raster_scales = true; |
| 1373 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1374 | gfx::Transform page_scaled_translate = translate; |
| 1375 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
| 1376 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1377 | EXPECT_EQ(page_scaled_translate, |
| 1378 | child->draw_properties().target_space_transform); |
| 1379 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame^] | 1380 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1381 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1382 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1383 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1384 | // Verify that it composes correctly with transforms directly on root layer. |
| 1385 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1386 | |
| 1387 | { |
| 1388 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1389 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1390 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
| 1391 | inputs.can_adjust_raster_scales = true; |
| 1392 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1393 | gfx::Transform compositeSquared = composite; |
| 1394 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1395 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1396 | compositeSquared, root->draw_properties().target_space_transform); |
| 1397 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1398 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1399 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1400 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1401 | } |
| 1402 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1403 | TEST_F(LayerTreeHostCommonTest, |
| 1404 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1405 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1406 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1407 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1408 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1409 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1410 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1411 | host->SetRootLayer(parent); |
| 1412 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1413 | const gfx::Transform identity_matrix; |
| 1414 | SetLayerPropertiesForTesting(parent.get(), |
| 1415 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1416 | gfx::PointF(), |
| 1417 | gfx::PointF(), |
| 1418 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1419 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1420 | false); |
| 1421 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1422 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1423 | gfx::PointF(), |
| 1424 | gfx::PointF(), |
| 1425 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1426 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1427 | false); |
| 1428 | SetLayerPropertiesForTesting(child.get(), |
| 1429 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1430 | gfx::PointF(), |
| 1431 | gfx::PointF(30.f, 30.f), |
| 1432 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1433 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1434 | false); |
| 1435 | |
| 1436 | parent->AddChild(render_surface1); |
| 1437 | parent->SetMasksToBounds(true); |
| 1438 | render_surface1->AddChild(child); |
| 1439 | render_surface1->SetForceRenderSurface(true); |
| 1440 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1441 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1442 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1443 | parent.get(), |
| 1444 | parent->bounds(), |
| 1445 | gfx::Transform(), |
| 1446 | &render_surface_layer_list); |
| 1447 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1448 | |
| 1449 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1450 | // the intermediate render surface should not be listed here, even if it was |
| 1451 | // forced to be created. Render surfaces without children or visible content |
| 1452 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1453 | // of size 0). |
| 1454 | ASSERT_TRUE(parent->render_surface()); |
| 1455 | ASSERT_FALSE(render_surface1->render_surface()); |
| 1456 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1457 | } |
| 1458 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1459 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1460 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1461 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1462 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1463 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1464 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1465 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1466 | host->SetRootLayer(parent); |
| 1467 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1468 | const gfx::Transform identity_matrix; |
| 1469 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1470 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1471 | gfx::PointF(), |
| 1472 | gfx::PointF(), |
| 1473 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1474 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1475 | false); |
| 1476 | SetLayerPropertiesForTesting(child.get(), |
| 1477 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1478 | gfx::PointF(), |
| 1479 | gfx::PointF(), |
| 1480 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1481 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1482 | false); |
| 1483 | |
| 1484 | parent->AddChild(render_surface1); |
| 1485 | render_surface1->AddChild(child); |
| 1486 | render_surface1->SetForceRenderSurface(true); |
| 1487 | render_surface1->SetOpacity(0.f); |
| 1488 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1489 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1490 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1491 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1492 | inputs.can_adjust_raster_scales = true; |
| 1493 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1494 | |
| 1495 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1496 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1497 | // have been extended by the children. |
| 1498 | ASSERT_TRUE(parent->render_surface()); |
| 1499 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1500 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1501 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1502 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1503 | } |
| 1504 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1505 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1506 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1507 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1508 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1509 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1510 | render_surface1->SetForceRenderSurface(true); |
| 1511 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1512 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1513 | host->SetRootLayer(parent); |
| 1514 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1515 | const gfx::Transform identity_matrix; |
| 1516 | SetLayerPropertiesForTesting(parent.get(), |
| 1517 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1518 | gfx::PointF(), |
| 1519 | gfx::PointF(), |
| 1520 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1521 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1522 | false); |
| 1523 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1524 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1525 | gfx::PointF(), |
| 1526 | gfx::PointF(), |
| 1527 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1528 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1529 | false); |
| 1530 | SetLayerPropertiesForTesting(child.get(), |
| 1531 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1532 | gfx::PointF(), |
| 1533 | gfx::PointF(), |
| 1534 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1535 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1536 | false); |
| 1537 | |
| 1538 | parent->AddChild(render_surface1); |
| 1539 | render_surface1->AddChild(child); |
| 1540 | |
| 1541 | // Sanity check before the actual test |
| 1542 | EXPECT_FALSE(parent->render_surface()); |
| 1543 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1544 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1545 | { |
| 1546 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1547 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1548 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1549 | inputs.can_adjust_raster_scales = true; |
| 1550 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1551 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1552 | // The root layer always creates a render surface |
| 1553 | EXPECT_TRUE(parent->render_surface()); |
| 1554 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1555 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1556 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1557 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1558 | { |
| 1559 | RenderSurfaceLayerList render_surface_layer_list; |
| 1560 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1561 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1562 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1563 | inputs.can_adjust_raster_scales = true; |
| 1564 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1565 | EXPECT_TRUE(parent->render_surface()); |
| 1566 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1567 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1568 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1569 | } |
| 1570 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1571 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1572 | // The entire subtree of layers that are outside the clip rect should be |
| 1573 | // culled away, and should not affect the render_surface_layer_list. |
| 1574 | // |
| 1575 | // The test tree is set up as follows: |
| 1576 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1577 | // that have something to draw. |
| 1578 | // - parent is a large container layer. |
| 1579 | // - child has masksToBounds=true to cause clipping. |
| 1580 | // - grand_child is positioned outside of the child's bounds |
| 1581 | // - great_grand_child is also kept outside child's bounds. |
| 1582 | // |
| 1583 | // In this configuration, grand_child and great_grand_child are completely |
| 1584 | // outside the clip rect, and they should never get scheduled on the list of |
| 1585 | // render surfaces. |
| 1586 | // |
| 1587 | |
| 1588 | const gfx::Transform identity_matrix; |
| 1589 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1590 | scoped_refptr<Layer> child = Layer::Create(); |
| 1591 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1592 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1593 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1594 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1595 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1596 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1597 | parent->AddChild(child); |
| 1598 | child->AddChild(grand_child); |
| 1599 | grand_child->AddChild(great_grand_child); |
| 1600 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1601 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1602 | host->SetRootLayer(parent); |
| 1603 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1604 | // leaf_node1 ensures that parent and child are kept on the |
| 1605 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1606 | // should be clipped. |
| 1607 | child->AddChild(leaf_node1); |
| 1608 | great_grand_child->AddChild(leaf_node2); |
| 1609 | |
| 1610 | SetLayerPropertiesForTesting(parent.get(), |
| 1611 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1612 | gfx::PointF(), |
| 1613 | gfx::PointF(), |
| 1614 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1615 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1616 | false); |
| 1617 | SetLayerPropertiesForTesting(child.get(), |
| 1618 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1619 | gfx::PointF(), |
| 1620 | gfx::PointF(), |
| 1621 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1622 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1623 | false); |
| 1624 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1625 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1626 | gfx::PointF(), |
| 1627 | gfx::PointF(45.f, 45.f), |
| 1628 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1629 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1630 | false); |
| 1631 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1632 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1633 | gfx::PointF(), |
| 1634 | gfx::PointF(), |
| 1635 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1636 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1637 | false); |
| 1638 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1639 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1640 | gfx::PointF(), |
| 1641 | gfx::PointF(), |
| 1642 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1643 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1644 | false); |
| 1645 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1646 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1647 | gfx::PointF(), |
| 1648 | gfx::PointF(), |
| 1649 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1650 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1651 | false); |
| 1652 | |
| 1653 | child->SetMasksToBounds(true); |
| 1654 | child->SetOpacity(0.4f); |
| 1655 | child->SetForceRenderSurface(true); |
| 1656 | grand_child->SetOpacity(0.5f); |
| 1657 | great_grand_child->SetOpacity(0.4f); |
| 1658 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1659 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1660 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1661 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1662 | inputs.can_adjust_raster_scales = true; |
| 1663 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1664 | |
| 1665 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1666 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1667 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1668 | } |
| 1669 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1670 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1671 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1672 | // of the surface. When the render surface is animating its transforms, then |
| 1673 | // the content rect's position in the clip rect is not defined on the main |
| 1674 | // thread, and its content rect should not be clipped. |
| 1675 | |
| 1676 | // The test tree is set up as follows: |
| 1677 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1678 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1679 | // the parent. |
| 1680 | // - grand_child is a render surface, and the only visible content in child. |
| 1681 | // It is positioned outside of the clip rect from parent. |
| 1682 | |
| 1683 | // In this configuration, grand_child should be outside the clipped |
| 1684 | // content rect of the child, making grand_child not appear in the |
| 1685 | // render_surface_layer_list. However, when we place an animation on the |
| 1686 | // child, this clipping should be avoided and we should keep the grand_child |
| 1687 | // in the render_surface_layer_list. |
| 1688 | |
| 1689 | const gfx::Transform identity_matrix; |
| 1690 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1691 | scoped_refptr<Layer> child = Layer::Create(); |
| 1692 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1693 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1694 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1695 | parent->AddChild(child); |
| 1696 | child->AddChild(grand_child); |
| 1697 | grand_child->AddChild(leaf_node); |
| 1698 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1699 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1700 | host->SetRootLayer(parent); |
| 1701 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1702 | SetLayerPropertiesForTesting(parent.get(), |
| 1703 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1704 | gfx::PointF(), |
| 1705 | gfx::PointF(), |
| 1706 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1707 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1708 | false); |
| 1709 | SetLayerPropertiesForTesting(child.get(), |
| 1710 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1711 | gfx::PointF(), |
| 1712 | gfx::PointF(), |
| 1713 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1714 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1715 | false); |
| 1716 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1717 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1718 | gfx::PointF(), |
| 1719 | gfx::PointF(200.f, 200.f), |
| 1720 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1721 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1722 | false); |
| 1723 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1724 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1725 | gfx::PointF(), |
| 1726 | gfx::PointF(), |
| 1727 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1728 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1729 | false); |
| 1730 | |
| 1731 | parent->SetMasksToBounds(true); |
| 1732 | child->SetOpacity(0.4f); |
| 1733 | child->SetForceRenderSurface(true); |
| 1734 | grand_child->SetOpacity(0.4f); |
| 1735 | grand_child->SetForceRenderSurface(true); |
| 1736 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1737 | { |
| 1738 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1739 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1740 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1741 | inputs.can_adjust_raster_scales = true; |
| 1742 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1743 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1744 | // Without an animation, we should cull child and grand_child from the |
| 1745 | // render_surface_layer_list. |
| 1746 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1747 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1748 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1749 | |
| 1750 | // Now put an animating transform on child. |
| 1751 | AddAnimatedTransformToController( |
| 1752 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1753 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1754 | { |
| 1755 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1756 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1757 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1758 | inputs.can_adjust_raster_scales = true; |
| 1759 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1760 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1761 | // With an animating transform, we should keep child and grand_child in the |
| 1762 | // render_surface_layer_list. |
| 1763 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1764 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1765 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1766 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1767 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1768 | } |
| 1769 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1770 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1771 | // Layer's IsClipped() property is set to true when: |
| 1772 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1773 | // - the layer is clipped by an ancestor that contributes to the same |
| 1774 | // render target, |
| 1775 | // - a surface is clipped by an ancestor that contributes to the same |
| 1776 | // render target. |
| 1777 | // |
| 1778 | // In particular, for a layer that owns a render surface: |
| 1779 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1780 | // pass that clipped status to the layer itself. |
| 1781 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1782 | // and propagates the clip to the subtree. |
| 1783 | |
| 1784 | const gfx::Transform identity_matrix; |
| 1785 | scoped_refptr<Layer> root = Layer::Create(); |
| 1786 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1787 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 1788 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 1789 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1790 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1791 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1792 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1793 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1794 | root->AddChild(parent); |
| 1795 | parent->AddChild(child1); |
| 1796 | parent->AddChild(child2); |
| 1797 | child1->AddChild(grand_child); |
| 1798 | child2->AddChild(leaf_node2); |
| 1799 | grand_child->AddChild(leaf_node1); |
| 1800 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1801 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1802 | host->SetRootLayer(root); |
| 1803 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1804 | child2->SetForceRenderSurface(true); |
| 1805 | |
| 1806 | SetLayerPropertiesForTesting(root.get(), |
| 1807 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1808 | gfx::PointF(), |
| 1809 | gfx::PointF(), |
| 1810 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1811 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1812 | false); |
| 1813 | SetLayerPropertiesForTesting(parent.get(), |
| 1814 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1815 | gfx::PointF(), |
| 1816 | gfx::PointF(), |
| 1817 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1818 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1819 | false); |
| 1820 | SetLayerPropertiesForTesting(child1.get(), |
| 1821 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1822 | gfx::PointF(), |
| 1823 | gfx::PointF(), |
| 1824 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1825 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1826 | false); |
| 1827 | SetLayerPropertiesForTesting(child2.get(), |
| 1828 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1829 | gfx::PointF(), |
| 1830 | gfx::PointF(), |
| 1831 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1832 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1833 | false); |
| 1834 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1835 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1836 | gfx::PointF(), |
| 1837 | gfx::PointF(), |
| 1838 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1839 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1840 | false); |
| 1841 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1842 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1843 | gfx::PointF(), |
| 1844 | gfx::PointF(), |
| 1845 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1846 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1847 | false); |
| 1848 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1849 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1850 | gfx::PointF(), |
| 1851 | gfx::PointF(), |
| 1852 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1853 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1854 | false); |
| 1855 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1856 | // Case 1: nothing is clipped except the root render surface. |
| 1857 | { |
| 1858 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1859 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1860 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1861 | inputs.can_adjust_raster_scales = true; |
| 1862 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1863 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1864 | ASSERT_TRUE(root->render_surface()); |
| 1865 | ASSERT_TRUE(child2->render_surface()); |
| 1866 | |
| 1867 | EXPECT_FALSE(root->is_clipped()); |
| 1868 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1869 | EXPECT_FALSE(parent->is_clipped()); |
| 1870 | EXPECT_FALSE(child1->is_clipped()); |
| 1871 | EXPECT_FALSE(child2->is_clipped()); |
| 1872 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1873 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1874 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1875 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1876 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1877 | |
| 1878 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1879 | // surface are clipped. But layers that contribute to child2's surface are |
| 1880 | // not clipped explicitly because child2's surface already accounts for |
| 1881 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1882 | { |
| 1883 | RenderSurfaceLayerList render_surface_layer_list; |
| 1884 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1885 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1886 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1887 | inputs.can_adjust_raster_scales = true; |
| 1888 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1889 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1890 | ASSERT_TRUE(root->render_surface()); |
| 1891 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1892 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1893 | EXPECT_FALSE(root->is_clipped()); |
| 1894 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1895 | EXPECT_TRUE(parent->is_clipped()); |
| 1896 | EXPECT_TRUE(child1->is_clipped()); |
| 1897 | EXPECT_FALSE(child2->is_clipped()); |
| 1898 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1899 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1900 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1901 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1902 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1903 | |
| 1904 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1905 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1906 | { |
| 1907 | RenderSurfaceLayerList render_surface_layer_list; |
| 1908 | parent->SetMasksToBounds(false); |
| 1909 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1910 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1911 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1912 | inputs.can_adjust_raster_scales = true; |
| 1913 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1914 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1915 | ASSERT_TRUE(root->render_surface()); |
| 1916 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1917 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1918 | EXPECT_FALSE(root->is_clipped()); |
| 1919 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1920 | EXPECT_FALSE(parent->is_clipped()); |
| 1921 | EXPECT_FALSE(child1->is_clipped()); |
| 1922 | EXPECT_TRUE(child2->is_clipped()); |
| 1923 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1924 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1925 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1926 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1927 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1928 | } |
| 1929 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1930 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1931 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1932 | // parent masksToBounds is true. |
| 1933 | // |
| 1934 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1935 | // be the layer rect expressed in target space. |
| 1936 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1937 | // will be the intersection of layer bounds and the mask region. |
| 1938 | // grand_child3 - partially clipped and masksToBounds; the |
| 1939 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1940 | // the mask region. |
| 1941 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1942 | // be empty. |
| 1943 | // |
| 1944 | |
| 1945 | const gfx::Transform identity_matrix; |
| 1946 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1947 | scoped_refptr<Layer> child = Layer::Create(); |
| 1948 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1949 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1950 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1951 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1952 | |
| 1953 | parent->AddChild(child); |
| 1954 | child->AddChild(grand_child1); |
| 1955 | child->AddChild(grand_child2); |
| 1956 | child->AddChild(grand_child3); |
| 1957 | child->AddChild(grand_child4); |
| 1958 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1959 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1960 | host->SetRootLayer(parent); |
| 1961 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1962 | SetLayerPropertiesForTesting(parent.get(), |
| 1963 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1964 | gfx::PointF(), |
| 1965 | gfx::PointF(), |
| 1966 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1967 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1968 | false); |
| 1969 | SetLayerPropertiesForTesting(child.get(), |
| 1970 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1971 | gfx::PointF(), |
| 1972 | gfx::PointF(), |
| 1973 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1974 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1975 | false); |
| 1976 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1977 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1978 | gfx::PointF(), |
| 1979 | gfx::PointF(5.f, 5.f), |
| 1980 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1981 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1982 | false); |
| 1983 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1984 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1985 | gfx::PointF(), |
| 1986 | gfx::PointF(15.f, 15.f), |
| 1987 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1988 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1989 | false); |
| 1990 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 1991 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1992 | gfx::PointF(), |
| 1993 | gfx::PointF(15.f, 15.f), |
| 1994 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1995 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1996 | false); |
| 1997 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 1998 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1999 | gfx::PointF(), |
| 2000 | gfx::PointF(45.f, 45.f), |
| 2001 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2002 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2003 | false); |
| 2004 | |
| 2005 | child->SetMasksToBounds(true); |
| 2006 | grand_child3->SetMasksToBounds(true); |
| 2007 | |
| 2008 | // Force everyone to be a render surface. |
| 2009 | child->SetOpacity(0.4f); |
| 2010 | grand_child1->SetOpacity(0.5f); |
| 2011 | grand_child2->SetOpacity(0.5f); |
| 2012 | grand_child3->SetOpacity(0.5f); |
| 2013 | grand_child4->SetOpacity(0.5f); |
| 2014 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2015 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2016 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2017 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2018 | inputs.can_adjust_raster_scales = true; |
| 2019 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2020 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2021 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2022 | grand_child1->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2023 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2024 | grand_child3->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2025 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2026 | grand_child3->drawable_content_rect()); |
| 2027 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2028 | } |
| 2029 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2030 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2031 | // Verify that render surfaces (and their layers) get the appropriate |
| 2032 | // clip rects when their parent masksToBounds is true. |
| 2033 | // |
| 2034 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2035 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2036 | // They may still have a clip rect of their own layer bounds, however, if |
| 2037 | // masksToBounds was true. |
| 2038 | const gfx::Transform identity_matrix; |
| 2039 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2040 | scoped_refptr<Layer> child = Layer::Create(); |
| 2041 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 2042 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 2043 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 2044 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 2045 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 2046 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2047 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 2048 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2049 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 2050 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2051 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 2052 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2053 | |
| 2054 | parent->AddChild(child); |
| 2055 | child->AddChild(grand_child1); |
| 2056 | child->AddChild(grand_child2); |
| 2057 | child->AddChild(grand_child3); |
| 2058 | child->AddChild(grand_child4); |
| 2059 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2060 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2061 | host->SetRootLayer(parent); |
| 2062 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2063 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2064 | // this test. |
| 2065 | grand_child1->AddChild(leaf_node1); |
| 2066 | grand_child2->AddChild(leaf_node2); |
| 2067 | grand_child3->AddChild(leaf_node3); |
| 2068 | grand_child4->AddChild(leaf_node4); |
| 2069 | |
| 2070 | SetLayerPropertiesForTesting(parent.get(), |
| 2071 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2072 | gfx::PointF(), |
| 2073 | gfx::PointF(), |
| 2074 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2075 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2076 | false); |
| 2077 | SetLayerPropertiesForTesting(child.get(), |
| 2078 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2079 | gfx::PointF(), |
| 2080 | gfx::PointF(), |
| 2081 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2082 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2083 | false); |
| 2084 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2085 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2086 | gfx::PointF(), |
| 2087 | gfx::PointF(5.f, 5.f), |
| 2088 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2089 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2090 | false); |
| 2091 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2092 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2093 | gfx::PointF(), |
| 2094 | gfx::PointF(15.f, 15.f), |
| 2095 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2096 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2097 | false); |
| 2098 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2099 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2100 | gfx::PointF(), |
| 2101 | gfx::PointF(15.f, 15.f), |
| 2102 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2103 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2104 | false); |
| 2105 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2106 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2107 | gfx::PointF(), |
| 2108 | gfx::PointF(45.f, 45.f), |
| 2109 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2110 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2111 | false); |
| 2112 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2113 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2114 | gfx::PointF(), |
| 2115 | gfx::PointF(), |
| 2116 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2117 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2118 | false); |
| 2119 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2120 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2121 | gfx::PointF(), |
| 2122 | gfx::PointF(), |
| 2123 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2124 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2125 | false); |
| 2126 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2127 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2128 | gfx::PointF(), |
| 2129 | gfx::PointF(), |
| 2130 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2131 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2132 | false); |
| 2133 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2134 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2135 | gfx::PointF(), |
| 2136 | gfx::PointF(), |
| 2137 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2138 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2139 | false); |
| 2140 | |
| 2141 | child->SetMasksToBounds(true); |
| 2142 | grand_child3->SetMasksToBounds(true); |
| 2143 | grand_child4->SetMasksToBounds(true); |
| 2144 | |
| 2145 | // Force everyone to be a render surface. |
| 2146 | child->SetOpacity(0.4f); |
| 2147 | child->SetForceRenderSurface(true); |
| 2148 | grand_child1->SetOpacity(0.5f); |
| 2149 | grand_child1->SetForceRenderSurface(true); |
| 2150 | grand_child2->SetOpacity(0.5f); |
| 2151 | grand_child2->SetForceRenderSurface(true); |
| 2152 | grand_child3->SetOpacity(0.5f); |
| 2153 | grand_child3->SetForceRenderSurface(true); |
| 2154 | grand_child4->SetOpacity(0.5f); |
| 2155 | grand_child4->SetForceRenderSurface(true); |
| 2156 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2157 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2158 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2159 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2160 | inputs.can_adjust_raster_scales = true; |
| 2161 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2162 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2163 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2164 | ASSERT_TRUE(grand_child3->render_surface()); |
| 2165 | // Because grand_child4 is entirely clipped, it is expected to not have a |
| 2166 | // render surface. |
| 2167 | EXPECT_FALSE(grand_child4->render_surface()); |
| 2168 | |
| 2169 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2170 | // masksToBounds. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2171 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2172 | grand_child1->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2173 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2174 | grand_child2->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2175 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2176 | grand_child3->render_surface()->clip_rect()); |
| 2177 | } |
| 2178 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2179 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2180 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2181 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2182 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2183 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2184 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2185 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2186 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2187 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2188 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2189 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2190 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2191 | parent->AddChild(render_surface1); |
| 2192 | parent->AddChild(child_of_root); |
| 2193 | render_surface1->AddChild(child_of_rs1); |
| 2194 | render_surface1->AddChild(render_surface2); |
| 2195 | render_surface2->AddChild(child_of_rs2); |
| 2196 | child_of_root->AddChild(grand_child_of_root); |
| 2197 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2198 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2199 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2200 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2201 | host->SetRootLayer(parent); |
| 2202 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2203 | // Make our render surfaces. |
| 2204 | render_surface1->SetForceRenderSurface(true); |
| 2205 | render_surface2->SetForceRenderSurface(true); |
| 2206 | |
| 2207 | gfx::Transform layer_transform; |
| 2208 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2209 | |
| 2210 | SetLayerPropertiesForTesting(parent.get(), |
| 2211 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2212 | gfx::PointF(0.25f, 0.f), |
| 2213 | gfx::PointF(2.5f, 0.f), |
| 2214 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2215 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2216 | false); |
| 2217 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2218 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2219 | gfx::PointF(0.25f, 0.f), |
| 2220 | gfx::PointF(2.5f, 0.f), |
| 2221 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2222 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2223 | false); |
| 2224 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2225 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2226 | gfx::PointF(0.25f, 0.f), |
| 2227 | gfx::PointF(2.5f, 0.f), |
| 2228 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2229 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2230 | false); |
| 2231 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2232 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2233 | gfx::PointF(0.25f, 0.f), |
| 2234 | gfx::PointF(2.5f, 0.f), |
| 2235 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2236 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2237 | false); |
| 2238 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2239 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2240 | gfx::PointF(0.25f, 0.f), |
| 2241 | gfx::PointF(2.5f, 0.f), |
| 2242 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2243 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2244 | false); |
| 2245 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2246 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2247 | gfx::PointF(0.25f, 0.f), |
| 2248 | gfx::PointF(2.5f, 0.f), |
| 2249 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2250 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2251 | false); |
| 2252 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2253 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2254 | gfx::PointF(0.25f, 0.f), |
| 2255 | gfx::PointF(2.5f, 0.f), |
| 2256 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2257 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2258 | false); |
| 2259 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2260 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2261 | gfx::PointF(0.25f, 0.f), |
| 2262 | gfx::PointF(2.5f, 0.f), |
| 2263 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2264 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2265 | false); |
| 2266 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2267 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2268 | gfx::PointF(0.25f, 0.f), |
| 2269 | gfx::PointF(2.5f, 0.f), |
| 2270 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2271 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2272 | false); |
| 2273 | |
| 2274 | // Put an animated opacity on the render surface. |
| 2275 | AddOpacityTransitionToController( |
| 2276 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2277 | |
| 2278 | // Also put an animated opacity on a layer without descendants. |
| 2279 | AddOpacityTransitionToController( |
| 2280 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2281 | |
| 2282 | // Put a transform animation on the render surface. |
| 2283 | AddAnimatedTransformToController( |
| 2284 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2285 | |
| 2286 | // Also put transform animations on grand_child_of_root, and |
| 2287 | // grand_child_of_rs2 |
| 2288 | AddAnimatedTransformToController( |
| 2289 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2290 | AddAnimatedTransformToController( |
| 2291 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2292 | |
| 2293 | ExecuteCalculateDrawProperties(parent.get()); |
| 2294 | |
| 2295 | // Only layers that are associated with render surfaces should have an actual |
| 2296 | // RenderSurface() value. |
| 2297 | ASSERT_TRUE(parent->render_surface()); |
| 2298 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2299 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2300 | |
| 2301 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2302 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2303 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2304 | |
| 2305 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2306 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2307 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2308 | |
| 2309 | // Verify all render target accessors |
| 2310 | EXPECT_EQ(parent, parent->render_target()); |
| 2311 | EXPECT_EQ(parent, child_of_root->render_target()); |
| 2312 | EXPECT_EQ(parent, grand_child_of_root->render_target()); |
| 2313 | |
| 2314 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 2315 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 2316 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 2317 | |
| 2318 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 2319 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 2320 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 2321 | |
| 2322 | // Verify draw_opacity_is_animating values |
| 2323 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2324 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2325 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2326 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2327 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2328 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2329 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2330 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2331 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2332 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2333 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2334 | |
| 2335 | // Verify draw_transform_is_animating values |
| 2336 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2337 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2338 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2339 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2340 | EXPECT_FALSE(render_surface1->render_surface() |
| 2341 | ->target_surface_transforms_are_animating()); |
| 2342 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2343 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2344 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2345 | EXPECT_TRUE(render_surface2->render_surface() |
| 2346 | ->target_surface_transforms_are_animating()); |
| 2347 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2348 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2349 | |
| 2350 | // Verify screen_space_transform_is_animating values |
| 2351 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2352 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2353 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2354 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2355 | EXPECT_FALSE(render_surface1->render_surface() |
| 2356 | ->screen_space_transforms_are_animating()); |
| 2357 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2358 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2359 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2360 | EXPECT_TRUE(render_surface2->render_surface() |
| 2361 | ->screen_space_transforms_are_animating()); |
| 2362 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2363 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2364 | |
| 2365 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2366 | // It is expected that we correctly set up transforms so that the y-component |
| 2367 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2368 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2369 | EXPECT_FLOAT_EQ(2.0, |
| 2370 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2371 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2372 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2373 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2374 | EXPECT_FLOAT_EQ(2.0, |
| 2375 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2376 | EXPECT_FLOAT_EQ(3.0, |
| 2377 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2378 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2379 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2380 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2381 | EXPECT_FLOAT_EQ(3.0, |
| 2382 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2383 | EXPECT_FLOAT_EQ(4.0, |
| 2384 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2385 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2386 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2387 | } |
| 2388 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2389 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2390 | // Test the calculateVisibleRect() function works correctly for identity |
| 2391 | // transforms. |
| 2392 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2393 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2394 | gfx::Transform layer_to_surface_transform; |
| 2395 | |
| 2396 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2397 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2398 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2399 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2400 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2401 | EXPECT_RECT_EQ(expected, actual); |
| 2402 | |
| 2403 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2404 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2405 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2406 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2407 | EXPECT_TRUE(actual.IsEmpty()); |
| 2408 | |
| 2409 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2410 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2411 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2412 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2413 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2414 | EXPECT_RECT_EQ(expected, actual); |
| 2415 | } |
| 2416 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2417 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2418 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2419 | // transforms. |
| 2420 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2421 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2422 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2423 | gfx::Transform layer_to_surface_transform; |
| 2424 | |
| 2425 | // Case 1: Layer is contained within the surface. |
| 2426 | layer_to_surface_transform.MakeIdentity(); |
| 2427 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2428 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2429 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2430 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2431 | EXPECT_RECT_EQ(expected, actual); |
| 2432 | |
| 2433 | // Case 2: Layer is outside the surface rect. |
| 2434 | layer_to_surface_transform.MakeIdentity(); |
| 2435 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2436 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2437 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2438 | EXPECT_TRUE(actual.IsEmpty()); |
| 2439 | |
| 2440 | // Case 3: Layer is partially overlapping the surface rect. |
| 2441 | layer_to_surface_transform.MakeIdentity(); |
| 2442 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2443 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2444 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2445 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2446 | EXPECT_RECT_EQ(expected, actual); |
| 2447 | } |
| 2448 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2449 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2450 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2451 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2452 | // should return the g in the layer's space. |
| 2453 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2454 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2455 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2456 | gfx::Transform layer_to_surface_transform; |
| 2457 | |
| 2458 | // Case 1: Layer is contained within the surface. |
| 2459 | layer_to_surface_transform.MakeIdentity(); |
| 2460 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2461 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2462 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2463 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2464 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2465 | EXPECT_RECT_EQ(expected, actual); |
| 2466 | |
| 2467 | // Case 2: Layer is outside the surface rect. |
| 2468 | layer_to_surface_transform.MakeIdentity(); |
| 2469 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2470 | layer_to_surface_transform.Rotate(45.0); |
| 2471 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2472 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2473 | EXPECT_TRUE(actual.IsEmpty()); |
| 2474 | |
| 2475 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2476 | // the layer is oriented diagonally, with the left half outside of the render |
| 2477 | // surface. In this case, the g should still be the entire layer |
| 2478 | // (remember the g is computed in layer space); both the top-left |
| 2479 | // and bottom-right corners of the layer are still visible. |
| 2480 | layer_to_surface_transform.MakeIdentity(); |
| 2481 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2482 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2483 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2484 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2485 | EXPECT_RECT_EQ(expected, actual); |
| 2486 | |
| 2487 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2488 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2489 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2490 | // surface overlaps the right side of the layer. The g should be |
| 2491 | // the layer's right half. |
| 2492 | layer_to_surface_transform.MakeIdentity(); |
| 2493 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2494 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2495 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2496 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2497 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2498 | EXPECT_RECT_EQ(expected, actual); |
| 2499 | } |
| 2500 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2501 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2502 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2503 | // transforms. |
| 2504 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2505 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2506 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2507 | gfx::Transform layer_to_surface_transform; |
| 2508 | |
| 2509 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2510 | // degrees, should be fully contained in the render surface. |
| 2511 | layer_to_surface_transform.MakeIdentity(); |
| 2512 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2513 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2514 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2515 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2516 | EXPECT_RECT_EQ(expected, actual); |
| 2517 | |
| 2518 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2519 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2520 | // visible on the surface. |
| 2521 | // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2522 | SkMScalar half_width_of_rotated_layer = |
| 2523 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2524 | layer_to_surface_transform.MakeIdentity(); |
| 2525 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2526 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2527 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2528 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2529 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2530 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2531 | EXPECT_RECT_EQ(expected, actual); |
| 2532 | } |
| 2533 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2534 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2535 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2536 | // a perspective projection onto the target surface. |
| 2537 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2538 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2539 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2540 | gfx::Transform layer_to_surface_transform; |
| 2541 | |
| 2542 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2543 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2544 | // its translated more than the perspective amount. |
| 2545 | layer_to_surface_transform.MakeIdentity(); |
| 2546 | |
| 2547 | // The following sequence of transforms applies the perspective about the |
| 2548 | // center of the surface. |
| 2549 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2550 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2551 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2552 | |
| 2553 | // This translate places the layer in front of the surface's projection plane. |
| 2554 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2555 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2556 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2557 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2558 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2559 | EXPECT_RECT_EQ(expected, actual); |
| 2560 | |
| 2561 | // Case 2: same projection as before, except that the layer is also translated |
| 2562 | // to the side, so that only the right half of the layer should be visible. |
| 2563 | // |
| 2564 | // Explanation of expected result: The perspective ratio is (z distance |
| 2565 | // between layer and camera origin) / (z distance between projection plane and |
| 2566 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2567 | // move a layer by translating -50 units in projected surface units (so that |
| 2568 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2569 | // -50 == -200 in the layer's units. |
| 2570 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2571 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2572 | gfx::Size(100, 200)); // The right half of the layer's |
| 2573 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2574 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2575 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2576 | EXPECT_RECT_EQ(expected, actual); |
| 2577 | } |
| 2578 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2579 | TEST_F(LayerTreeHostCommonTest, |
| 2580 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2581 | // There is currently no explicit concept of an orthographic projection plane |
| 2582 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2583 | // are technically behind the surface in an orthographic world should not be |
| 2584 | // clipped when they are flattened to the surface. |
| 2585 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2586 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2587 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2588 | gfx::Transform layer_to_surface_transform; |
| 2589 | |
| 2590 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2591 | // at the center of the layer. |
| 2592 | layer_to_surface_transform.MakeIdentity(); |
| 2593 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2594 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2595 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2596 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2597 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2598 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2599 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2600 | EXPECT_RECT_EQ(expected, actual); |
| 2601 | } |
| 2602 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2603 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2604 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2605 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2606 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2607 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2608 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2609 | // converting to cartesian coordinates. |
| 2610 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2611 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2612 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2613 | gfx::Transform layer_to_surface_transform; |
| 2614 | |
| 2615 | // The layer is positioned so that the right half of the layer should be in |
| 2616 | // front of the camera, while the other half is behind the surface's |
| 2617 | // projection plane. The following sequence of transforms applies the |
| 2618 | // perspective and rotation about the center of the layer. |
| 2619 | layer_to_surface_transform.MakeIdentity(); |
| 2620 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2621 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2622 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2623 | |
| 2624 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2625 | // transform, otherwise this code is not testing the intended scenario. |
| 2626 | bool clipped; |
| 2627 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2628 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2629 | &clipped); |
| 2630 | ASSERT_TRUE(clipped); |
| 2631 | |
| 2632 | int expected_x_position = 0; |
| 2633 | int expected_width = 10; |
| 2634 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2635 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2636 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2637 | EXPECT_EQ(expected_width, actual.width()); |
| 2638 | } |
| 2639 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2640 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2641 | // To determine visible rect in layer space, there needs to be an |
| 2642 | // un-projection from surface space to layer space. When the original |
| 2643 | // transform was a perspective projection that was clipped, it returns a rect |
| 2644 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2645 | // clipping again. |
| 2646 | |
| 2647 | // This sequence of transforms causes one corner of the layer to protrude |
| 2648 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2649 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2650 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2651 | gfx::Transform layer_to_surface_transform; |
| 2652 | layer_to_surface_transform.MakeIdentity(); |
| 2653 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2654 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2655 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2656 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2657 | |
| 2658 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2659 | // code is not testing the intended scenario. |
| 2660 | bool clipped; |
| 2661 | gfx::RectF clipped_rect = |
| 2662 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2663 | MathUtil::ProjectQuad( |
| 2664 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2665 | ASSERT_TRUE(clipped); |
| 2666 | |
| 2667 | // Only the corner of the layer is not visible on the surface because of being |
| 2668 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2669 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2670 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2671 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2672 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2673 | EXPECT_RECT_EQ(expected, actual); |
| 2674 | } |
| 2675 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2676 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2677 | scoped_refptr<Layer> root = Layer::Create(); |
| 2678 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2679 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2680 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2681 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2682 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2683 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2684 | root->AddChild(child1); |
| 2685 | root->AddChild(child2); |
| 2686 | root->AddChild(child3); |
| 2687 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2688 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2689 | host->SetRootLayer(root); |
| 2690 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2691 | gfx::Transform identity_matrix; |
| 2692 | SetLayerPropertiesForTesting(root.get(), |
| 2693 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2694 | gfx::PointF(), |
| 2695 | gfx::PointF(), |
| 2696 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2697 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2698 | false); |
| 2699 | SetLayerPropertiesForTesting(child1.get(), |
| 2700 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2701 | gfx::PointF(), |
| 2702 | gfx::PointF(), |
| 2703 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2704 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2705 | false); |
| 2706 | SetLayerPropertiesForTesting(child2.get(), |
| 2707 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2708 | gfx::PointF(), |
| 2709 | gfx::PointF(75.f, 75.f), |
| 2710 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2711 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2712 | false); |
| 2713 | SetLayerPropertiesForTesting(child3.get(), |
| 2714 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2715 | gfx::PointF(), |
| 2716 | gfx::PointF(125.f, 125.f), |
| 2717 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2718 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2719 | false); |
| 2720 | |
| 2721 | ExecuteCalculateDrawProperties(root.get()); |
| 2722 | |
| 2723 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2724 | root->render_surface()->DrawableContentRect()); |
| 2725 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2726 | |
| 2727 | // Layers that do not draw content should have empty visible_content_rects. |
| 2728 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2729 | |
| 2730 | // layer visible_content_rects are clipped by their target surface. |
| 2731 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2732 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 2733 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2734 | |
| 2735 | // layer drawable_content_rects are not clipped. |
| 2736 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2737 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2738 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2739 | } |
| 2740 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2741 | TEST_F(LayerTreeHostCommonTest, |
| 2742 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2743 | scoped_refptr<Layer> root = Layer::Create(); |
| 2744 | scoped_refptr<Layer> child = Layer::Create(); |
| 2745 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2746 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2747 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2748 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2749 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2750 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2751 | root->AddChild(child); |
| 2752 | child->AddChild(grand_child1); |
| 2753 | child->AddChild(grand_child2); |
| 2754 | child->AddChild(grand_child3); |
| 2755 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2756 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2757 | host->SetRootLayer(root); |
| 2758 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2759 | gfx::Transform identity_matrix; |
| 2760 | SetLayerPropertiesForTesting(root.get(), |
| 2761 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2762 | gfx::PointF(), |
| 2763 | gfx::PointF(), |
| 2764 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2765 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2766 | false); |
| 2767 | SetLayerPropertiesForTesting(child.get(), |
| 2768 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2769 | gfx::PointF(), |
| 2770 | gfx::PointF(), |
| 2771 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2772 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2773 | false); |
| 2774 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2775 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2776 | gfx::PointF(), |
| 2777 | gfx::PointF(5.f, 5.f), |
| 2778 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2779 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2780 | false); |
| 2781 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2782 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2783 | gfx::PointF(), |
| 2784 | gfx::PointF(75.f, 75.f), |
| 2785 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2786 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2787 | false); |
| 2788 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2789 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2790 | gfx::PointF(), |
| 2791 | gfx::PointF(125.f, 125.f), |
| 2792 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2793 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2794 | false); |
| 2795 | |
| 2796 | child->SetMasksToBounds(true); |
| 2797 | ExecuteCalculateDrawProperties(root.get()); |
| 2798 | |
| 2799 | ASSERT_FALSE(child->render_surface()); |
| 2800 | |
| 2801 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2802 | root->render_surface()->DrawableContentRect()); |
| 2803 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2804 | |
| 2805 | // Layers that do not draw content should have empty visible content rects. |
| 2806 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2807 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
| 2808 | |
| 2809 | // All grandchild visible content rects should be clipped by child. |
| 2810 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2811 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
| 2812 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2813 | |
| 2814 | // All grandchild DrawableContentRects should also be clipped by child. |
| 2815 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), |
| 2816 | grand_child1->drawable_content_rect()); |
| 2817 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25), |
| 2818 | grand_child2->drawable_content_rect()); |
| 2819 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2820 | } |
| 2821 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2822 | TEST_F(LayerTreeHostCommonTest, |
| 2823 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2824 | scoped_refptr<Layer> root = Layer::Create(); |
| 2825 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2826 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2827 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2828 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2829 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2830 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2831 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2832 | root->AddChild(render_surface1); |
| 2833 | render_surface1->AddChild(child1); |
| 2834 | render_surface1->AddChild(child2); |
| 2835 | render_surface1->AddChild(child3); |
| 2836 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2837 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2838 | host->SetRootLayer(root); |
| 2839 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2840 | gfx::Transform identity_matrix; |
| 2841 | SetLayerPropertiesForTesting(root.get(), |
| 2842 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2843 | gfx::PointF(), |
| 2844 | gfx::PointF(), |
| 2845 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2846 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2847 | false); |
| 2848 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2849 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2850 | gfx::PointF(), |
| 2851 | gfx::PointF(), |
| 2852 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2853 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2854 | false); |
| 2855 | SetLayerPropertiesForTesting(child1.get(), |
| 2856 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2857 | gfx::PointF(), |
| 2858 | gfx::PointF(5.f, 5.f), |
| 2859 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2860 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2861 | false); |
| 2862 | SetLayerPropertiesForTesting(child2.get(), |
| 2863 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2864 | gfx::PointF(), |
| 2865 | gfx::PointF(75.f, 75.f), |
| 2866 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2867 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2868 | false); |
| 2869 | SetLayerPropertiesForTesting(child3.get(), |
| 2870 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2871 | gfx::PointF(), |
| 2872 | gfx::PointF(125.f, 125.f), |
| 2873 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2874 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2875 | false); |
| 2876 | |
| 2877 | render_surface1->SetForceRenderSurface(true); |
| 2878 | ExecuteCalculateDrawProperties(root.get()); |
| 2879 | |
| 2880 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2881 | |
| 2882 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2883 | root->render_surface()->DrawableContentRect()); |
| 2884 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2885 | |
| 2886 | // Layers that do not draw content should have empty visible content rects. |
| 2887 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2888 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 2889 | render_surface1->visible_content_rect()); |
| 2890 | |
| 2891 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2892 | // regions of the subtree. |
| 2893 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2894 | render_surface1->render_surface()->DrawableContentRect()); |
| 2895 | |
| 2896 | // All layers that draw content into the unclipped surface are also unclipped. |
| 2897 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2898 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2899 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 2900 | |
| 2901 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2902 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2903 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2904 | } |
| 2905 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2906 | TEST_F(LayerTreeHostCommonTest, |
| 2907 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2908 | scoped_refptr<Layer> root = Layer::Create(); |
| 2909 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2910 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2911 | root->AddChild(child); |
| 2912 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2913 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2914 | host->SetRootLayer(root); |
| 2915 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2916 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2917 | gfx::Transform identity_matrix; |
| 2918 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2919 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2920 | |
| 2921 | SetLayerPropertiesForTesting(root.get(), |
| 2922 | identity_matrix, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2923 | gfx::PointF(), |
| 2924 | gfx::PointF(), |
| 2925 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2926 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2927 | false); |
| 2928 | SetLayerPropertiesForTesting(child.get(), |
| 2929 | uninvertible_matrix, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2930 | gfx::PointF(), |
| 2931 | gfx::PointF(5.f, 5.f), |
| 2932 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2933 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2934 | false); |
| 2935 | |
| 2936 | ExecuteCalculateDrawProperties(root.get()); |
| 2937 | |
| 2938 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2939 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2940 | |
| 2941 | // Case 2: a matrix with flattened z, technically uninvertible but still |
| 2942 | // drawable and visible. In this case, we must assume that the entire layer |
| 2943 | // bounds are visible since there is no way to inverse-project the surface |
| 2944 | // bounds to intersect. |
| 2945 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2946 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2947 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2948 | |
| 2949 | SetLayerPropertiesForTesting(child.get(), |
| 2950 | uninvertible_matrix, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2951 | gfx::PointF(), |
| 2952 | gfx::PointF(5.f, 5.f), |
| 2953 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2954 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2955 | false); |
| 2956 | |
| 2957 | ExecuteCalculateDrawProperties(root.get()); |
| 2958 | |
| 2959 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child->visible_content_rect()); |
| 2960 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child->drawable_content_rect()); |
| 2961 | |
| 2962 | // Case 3: a matrix with flattened z, technically uninvertible but still |
| 2963 | // drawable, but not visible. In this case, we don't need to conservatively |
| 2964 | // assume that the whole layer is visible. |
| 2965 | uninvertible_matrix.MakeIdentity(); |
| 2966 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2967 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2968 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2969 | |
| 2970 | SetLayerPropertiesForTesting(child.get(), |
| 2971 | uninvertible_matrix, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2972 | gfx::PointF(), |
| 2973 | gfx::PointF(5.f, 5.f), |
| 2974 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2975 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2976 | false); |
| 2977 | |
| 2978 | ExecuteCalculateDrawProperties(root.get()); |
| 2979 | |
| 2980 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2981 | EXPECT_RECT_EQ(gfx::Rect(505, 5, 50, 50), child->drawable_content_rect()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2982 | } |
| 2983 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2984 | TEST_F(LayerTreeHostCommonTest, |
| 2985 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2986 | scoped_refptr<Layer> root = Layer::Create(); |
| 2987 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2988 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2989 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2990 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2991 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2992 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2993 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2994 | root->AddChild(render_surface1); |
| 2995 | render_surface1->AddChild(child1); |
| 2996 | render_surface1->AddChild(child2); |
| 2997 | render_surface1->AddChild(child3); |
| 2998 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2999 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3000 | host->SetRootLayer(root); |
| 3001 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3002 | gfx::Transform identity_matrix; |
| 3003 | SetLayerPropertiesForTesting(root.get(), |
| 3004 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3005 | gfx::PointF(), |
| 3006 | gfx::PointF(), |
| 3007 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3008 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3009 | false); |
| 3010 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3011 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3012 | gfx::PointF(), |
| 3013 | gfx::PointF(), |
| 3014 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3015 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3016 | false); |
| 3017 | SetLayerPropertiesForTesting(child1.get(), |
| 3018 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3019 | gfx::PointF(), |
| 3020 | gfx::PointF(5.f, 5.f), |
| 3021 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3022 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3023 | false); |
| 3024 | SetLayerPropertiesForTesting(child2.get(), |
| 3025 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3026 | gfx::PointF(), |
| 3027 | gfx::PointF(75.f, 75.f), |
| 3028 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3029 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3030 | false); |
| 3031 | SetLayerPropertiesForTesting(child3.get(), |
| 3032 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3033 | gfx::PointF(), |
| 3034 | gfx::PointF(125.f, 125.f), |
| 3035 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3036 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3037 | false); |
| 3038 | |
| 3039 | root->SetMasksToBounds(true); |
| 3040 | render_surface1->SetForceRenderSurface(true); |
| 3041 | ExecuteCalculateDrawProperties(root.get()); |
| 3042 | |
| 3043 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3044 | |
| 3045 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3046 | root->render_surface()->DrawableContentRect()); |
| 3047 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3048 | |
| 3049 | // Layers that do not draw content should have empty visible content rects. |
| 3050 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3051 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3052 | render_surface1->visible_content_rect()); |
| 3053 | |
| 3054 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3055 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3056 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3057 | render_surface1->render_surface()->DrawableContentRect()); |
| 3058 | |
| 3059 | // All layers that draw content into the surface have their visible content |
| 3060 | // rect clipped by the surface clip rect. |
| 3061 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3062 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 3063 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3064 | |
| 3065 | // But the DrawableContentRects are unclipped. |
| 3066 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3067 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3068 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3069 | } |
| 3070 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3071 | TEST_F(LayerTreeHostCommonTest, |
| 3072 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3073 | // Check that clipping does not propagate down surfaces. |
| 3074 | scoped_refptr<Layer> root = Layer::Create(); |
| 3075 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3076 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3077 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3078 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3079 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3080 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3081 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3082 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3083 | root->AddChild(render_surface1); |
| 3084 | render_surface1->AddChild(render_surface2); |
| 3085 | render_surface2->AddChild(child1); |
| 3086 | render_surface2->AddChild(child2); |
| 3087 | render_surface2->AddChild(child3); |
| 3088 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3089 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3090 | host->SetRootLayer(root); |
| 3091 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3092 | gfx::Transform identity_matrix; |
| 3093 | SetLayerPropertiesForTesting(root.get(), |
| 3094 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3095 | gfx::PointF(), |
| 3096 | gfx::PointF(), |
| 3097 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3098 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3099 | false); |
| 3100 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3101 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3102 | gfx::PointF(), |
| 3103 | gfx::PointF(), |
| 3104 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3105 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3106 | false); |
| 3107 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3108 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3109 | gfx::PointF(), |
| 3110 | gfx::PointF(), |
| 3111 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3112 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3113 | false); |
| 3114 | SetLayerPropertiesForTesting(child1.get(), |
| 3115 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3116 | gfx::PointF(), |
| 3117 | gfx::PointF(5.f, 5.f), |
| 3118 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3119 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3120 | false); |
| 3121 | SetLayerPropertiesForTesting(child2.get(), |
| 3122 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3123 | gfx::PointF(), |
| 3124 | gfx::PointF(75.f, 75.f), |
| 3125 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3126 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3127 | false); |
| 3128 | SetLayerPropertiesForTesting(child3.get(), |
| 3129 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3130 | gfx::PointF(), |
| 3131 | gfx::PointF(125.f, 125.f), |
| 3132 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3133 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3134 | false); |
| 3135 | |
| 3136 | root->SetMasksToBounds(true); |
| 3137 | render_surface1->SetForceRenderSurface(true); |
| 3138 | render_surface2->SetForceRenderSurface(true); |
| 3139 | ExecuteCalculateDrawProperties(root.get()); |
| 3140 | |
| 3141 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3142 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3143 | |
| 3144 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3145 | root->render_surface()->DrawableContentRect()); |
| 3146 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3147 | |
| 3148 | // Layers that do not draw content should have empty visible content rects. |
| 3149 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3150 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3151 | render_surface1->visible_content_rect()); |
| 3152 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3153 | render_surface2->visible_content_rect()); |
| 3154 | |
| 3155 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3156 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3157 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3158 | render_surface1->render_surface()->DrawableContentRect()); |
| 3159 | |
| 3160 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3161 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3162 | // render_surface2 grows to enclose all drawable content of its subtree. |
| 3163 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3164 | render_surface2->render_surface()->DrawableContentRect()); |
| 3165 | |
| 3166 | // All layers that draw content into render_surface2 think they are unclipped. |
| 3167 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3168 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3169 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 3170 | |
| 3171 | // DrawableContentRects are also unclipped. |
| 3172 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3173 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3174 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3175 | } |
| 3176 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3177 | TEST_F(LayerTreeHostCommonTest, |
| 3178 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3179 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3180 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3181 | |
| 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 | root->AddChild(render_surface1); |
| 3187 | render_surface1->AddChild(child1); |
| 3188 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3189 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3190 | host->SetRootLayer(root); |
| 3191 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3192 | gfx::Transform identity_matrix; |
| 3193 | gfx::Transform child_rotation; |
| 3194 | child_rotation.Rotate(45.0); |
| 3195 | SetLayerPropertiesForTesting(root.get(), |
| 3196 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3197 | gfx::PointF(), |
| 3198 | gfx::PointF(), |
| 3199 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3200 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3201 | false); |
| 3202 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3203 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3204 | gfx::PointF(), |
| 3205 | gfx::PointF(), |
| 3206 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3207 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3208 | false); |
| 3209 | SetLayerPropertiesForTesting(child1.get(), |
| 3210 | child_rotation, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3211 | gfx::PointF(0.5f, 0.5f), |
| 3212 | gfx::PointF(25.f, 25.f), |
| 3213 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3214 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3215 | false); |
| 3216 | |
| 3217 | render_surface1->SetForceRenderSurface(true); |
| 3218 | ExecuteCalculateDrawProperties(root.get()); |
| 3219 | |
| 3220 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3221 | |
| 3222 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3223 | root->render_surface()->DrawableContentRect()); |
| 3224 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3225 | |
| 3226 | // Layers that do not draw content should have empty visible content rects. |
| 3227 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3228 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3229 | render_surface1->visible_content_rect()); |
| 3230 | |
| 3231 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3232 | // regions of the subtree. |
| 3233 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3234 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3235 | gfx::Rect(50 - diagonal_radius, |
| 3236 | 50 - diagonal_radius, |
| 3237 | diagonal_radius * 2, |
| 3238 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3239 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3240 | render_surface1->render_surface()->DrawableContentRect()); |
| 3241 | |
| 3242 | // All layers that draw content into the unclipped surface are also unclipped. |
| 3243 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3244 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3245 | child1->drawable_content_rect()); |
| 3246 | } |
| 3247 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3248 | TEST_F(LayerTreeHostCommonTest, |
| 3249 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3250 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3251 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3252 | |
| 3253 | scoped_refptr<Layer> root = Layer::Create(); |
| 3254 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3255 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3256 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3257 | root->AddChild(render_surface1); |
| 3258 | render_surface1->AddChild(child1); |
| 3259 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3260 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3261 | host->SetRootLayer(root); |
| 3262 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3263 | gfx::Transform identity_matrix; |
| 3264 | gfx::Transform child_rotation; |
| 3265 | child_rotation.Rotate(45.0); |
| 3266 | SetLayerPropertiesForTesting(root.get(), |
| 3267 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3268 | gfx::PointF(), |
| 3269 | gfx::PointF(), |
| 3270 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3271 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3272 | false); |
| 3273 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3274 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3275 | gfx::PointF(), |
| 3276 | gfx::PointF(), |
| 3277 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3278 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3279 | false); |
| 3280 | SetLayerPropertiesForTesting(child1.get(), |
| 3281 | child_rotation, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3282 | gfx::PointF(0.5f, 0.5f), |
| 3283 | gfx::PointF(25.f, 25.f), |
| 3284 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3285 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3286 | false); |
| 3287 | |
| 3288 | root->SetMasksToBounds(true); |
| 3289 | render_surface1->SetForceRenderSurface(true); |
| 3290 | ExecuteCalculateDrawProperties(root.get()); |
| 3291 | |
| 3292 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3293 | |
| 3294 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3295 | // rotated layer. |
| 3296 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3297 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3298 | 50 - diagonal_radius, |
| 3299 | diagonal_radius * 2, |
| 3300 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3301 | gfx::Rect expected_surface_drawable_content = |
| 3302 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
| 3303 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3304 | render_surface1->render_surface()->DrawableContentRect()); |
| 3305 | |
| 3306 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3307 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3308 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3309 | // |
| 3310 | // Given the floating point math, this number is a little bit fuzzy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3311 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
| 3312 | |
| 3313 | // The child's DrawableContentRect is unclipped. |
| 3314 | EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
| 3315 | } |
| 3316 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3317 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3318 | MockContentLayerClient client; |
| 3319 | |
| 3320 | scoped_refptr<Layer> root = Layer::Create(); |
| 3321 | scoped_refptr<ContentLayer> render_surface1 = |
| 3322 | CreateDrawableContentLayer(&client); |
| 3323 | scoped_refptr<ContentLayer> render_surface2 = |
| 3324 | CreateDrawableContentLayer(&client); |
| 3325 | scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client); |
| 3326 | scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client); |
| 3327 | scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client); |
| 3328 | root->AddChild(render_surface1); |
| 3329 | render_surface1->AddChild(render_surface2); |
| 3330 | render_surface2->AddChild(child1); |
| 3331 | render_surface2->AddChild(child2); |
| 3332 | render_surface2->AddChild(child3); |
| 3333 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3334 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3335 | host->SetRootLayer(root); |
| 3336 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3337 | gfx::Transform identity_matrix; |
| 3338 | SetLayerPropertiesForTesting(root.get(), |
| 3339 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3340 | gfx::PointF(), |
| 3341 | gfx::PointF(), |
| 3342 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3343 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3344 | false); |
| 3345 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3346 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3347 | gfx::PointF(), |
| 3348 | gfx::PointF(5.f, 5.f), |
| 3349 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3350 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3351 | false); |
| 3352 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3353 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3354 | gfx::PointF(), |
| 3355 | gfx::PointF(5.f, 5.f), |
| 3356 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3357 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3358 | false); |
| 3359 | SetLayerPropertiesForTesting(child1.get(), |
| 3360 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3361 | gfx::PointF(), |
| 3362 | gfx::PointF(5.f, 5.f), |
| 3363 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3364 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3365 | false); |
| 3366 | SetLayerPropertiesForTesting(child2.get(), |
| 3367 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3368 | gfx::PointF(), |
| 3369 | gfx::PointF(75.f, 75.f), |
| 3370 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3371 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3372 | false); |
| 3373 | SetLayerPropertiesForTesting(child3.get(), |
| 3374 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3375 | gfx::PointF(), |
| 3376 | gfx::PointF(125.f, 125.f), |
| 3377 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3378 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3379 | false); |
| 3380 | |
| 3381 | float device_scale_factor = 2.f; |
| 3382 | |
| 3383 | root->SetMasksToBounds(true); |
| 3384 | render_surface1->SetForceRenderSurface(true); |
| 3385 | render_surface2->SetForceRenderSurface(true); |
| 3386 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3387 | |
| 3388 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3389 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3390 | |
| 3391 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3392 | // device_scale_factor. |
| 3393 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3394 | root->render_surface()->DrawableContentRect()); |
| 3395 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3396 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3397 | render_surface1->render_surface()->DrawableContentRect()); |
| 3398 | |
| 3399 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3400 | // is only implicitly clipped by render_surface1. |
| 3401 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3402 | render_surface2->render_surface()->DrawableContentRect()); |
| 3403 | |
| 3404 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3405 | EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), |
| 3406 | child2->drawable_content_rect()); |
| 3407 | EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), |
| 3408 | child3->drawable_content_rect()); |
| 3409 | |
| 3410 | // The root layer does not actually draw content of its own. |
| 3411 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3412 | |
| 3413 | // All layer visible content rects are expressed in content space of each |
| 3414 | // layer, so they are also scaled by the device_scale_factor. |
| 3415 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8), |
| 3416 | render_surface1->visible_content_rect()); |
| 3417 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26), |
| 3418 | render_surface2->visible_content_rect()); |
| 3419 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect()); |
| 3420 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect()); |
| 3421 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect()); |
| 3422 | } |
| 3423 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3424 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3425 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3426 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3427 | // "flattened" to each parent layer according to current W3C spec. |
| 3428 | |
| 3429 | const gfx::Transform identity_matrix; |
| 3430 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3431 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3432 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3433 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3434 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3435 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3436 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3437 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3438 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3439 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3440 | front_facing_child_of_front_facing_surface = |
| 3441 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3442 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3443 | back_facing_child_of_front_facing_surface = |
| 3444 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3445 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3446 | front_facing_child_of_back_facing_surface = |
| 3447 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3448 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3449 | back_facing_child_of_back_facing_surface = |
| 3450 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3451 | |
| 3452 | parent->AddChild(front_facing_child); |
| 3453 | parent->AddChild(back_facing_child); |
| 3454 | parent->AddChild(front_facing_surface); |
| 3455 | parent->AddChild(back_facing_surface); |
| 3456 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3457 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3458 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3459 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3460 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3461 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3462 | host->SetRootLayer(parent); |
| 3463 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3464 | // Nothing is double-sided |
| 3465 | front_facing_child->SetDoubleSided(false); |
| 3466 | back_facing_child->SetDoubleSided(false); |
| 3467 | front_facing_surface->SetDoubleSided(false); |
| 3468 | back_facing_surface->SetDoubleSided(false); |
| 3469 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3470 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3471 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3472 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3473 | |
| 3474 | gfx::Transform backface_matrix; |
| 3475 | backface_matrix.Translate(50.0, 50.0); |
| 3476 | backface_matrix.RotateAboutYAxis(180.0); |
| 3477 | backface_matrix.Translate(-50.0, -50.0); |
| 3478 | |
| 3479 | // Having a descendant and opacity will force these to have render surfaces. |
| 3480 | front_facing_surface->SetOpacity(0.5f); |
| 3481 | back_facing_surface->SetOpacity(0.5f); |
| 3482 | |
| 3483 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3484 | // these layers should blindly use their own local transforms to determine |
| 3485 | // back-face culling. |
| 3486 | SetLayerPropertiesForTesting(parent.get(), |
| 3487 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3488 | gfx::PointF(), |
| 3489 | gfx::PointF(), |
| 3490 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3491 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3492 | false); |
| 3493 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3494 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3495 | gfx::PointF(), |
| 3496 | gfx::PointF(), |
| 3497 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3498 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3499 | false); |
| 3500 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3501 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3502 | gfx::PointF(), |
| 3503 | gfx::PointF(), |
| 3504 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3505 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3506 | false); |
| 3507 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3508 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3509 | gfx::PointF(), |
| 3510 | gfx::PointF(), |
| 3511 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3512 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3513 | false); |
| 3514 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3515 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3516 | gfx::PointF(), |
| 3517 | gfx::PointF(), |
| 3518 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3519 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3520 | false); |
| 3521 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3522 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3523 | gfx::PointF(), |
| 3524 | gfx::PointF(), |
| 3525 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3526 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3527 | false); |
| 3528 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3529 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3530 | gfx::PointF(), |
| 3531 | gfx::PointF(), |
| 3532 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3533 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3534 | false); |
| 3535 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3536 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3537 | gfx::PointF(), |
| 3538 | gfx::PointF(), |
| 3539 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3540 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3541 | false); |
| 3542 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3543 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3544 | gfx::PointF(), |
| 3545 | gfx::PointF(), |
| 3546 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3547 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3548 | false); |
| 3549 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3550 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3551 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3552 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3553 | inputs.can_adjust_raster_scales = true; |
| 3554 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3555 | |
| 3556 | // Verify which render surfaces were created. |
| 3557 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3558 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3559 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3560 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3561 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3562 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3563 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3564 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3565 | |
| 3566 | // Verify the render_surface_layer_list. |
| 3567 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3568 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3569 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3570 | // Even though the back facing surface LAYER gets culled, the other |
| 3571 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3572 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3573 | |
| 3574 | // Verify root surface's layer list. |
| 3575 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3576 | 3u, |
| 3577 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3578 | EXPECT_EQ(front_facing_child->id(), |
| 3579 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3580 | ->render_surface() |
| 3581 | ->layer_list() |
| 3582 | .at(0) |
| 3583 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3584 | EXPECT_EQ(front_facing_surface->id(), |
| 3585 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3586 | ->render_surface() |
| 3587 | ->layer_list() |
| 3588 | .at(1) |
| 3589 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3590 | EXPECT_EQ(back_facing_surface->id(), |
| 3591 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3592 | ->render_surface() |
| 3593 | ->layer_list() |
| 3594 | .at(2) |
| 3595 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3596 | |
| 3597 | // Verify front_facing_surface's layer list. |
| 3598 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3599 | 2u, |
| 3600 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3601 | EXPECT_EQ(front_facing_surface->id(), |
| 3602 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3603 | ->render_surface() |
| 3604 | ->layer_list() |
| 3605 | .at(0) |
| 3606 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3607 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3608 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3609 | ->render_surface() |
| 3610 | ->layer_list() |
| 3611 | .at(1) |
| 3612 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3613 | |
| 3614 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3615 | // from the surface list. |
| 3616 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3617 | 1u, |
| 3618 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3619 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3620 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3621 | ->render_surface() |
| 3622 | ->layer_list() |
| 3623 | .at(0) |
| 3624 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3625 | } |
| 3626 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3627 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3628 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3629 | // is used. |
| 3630 | |
| 3631 | const gfx::Transform identity_matrix; |
| 3632 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3633 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3634 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3635 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3636 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3637 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3638 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3639 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3640 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3641 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3642 | front_facing_child_of_front_facing_surface = |
| 3643 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3644 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3645 | back_facing_child_of_front_facing_surface = |
| 3646 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3647 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3648 | front_facing_child_of_back_facing_surface = |
| 3649 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3650 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3651 | back_facing_child_of_back_facing_surface = |
| 3652 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3653 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3654 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3655 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3656 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3657 | |
| 3658 | parent->AddChild(front_facing_child); |
| 3659 | parent->AddChild(back_facing_child); |
| 3660 | parent->AddChild(front_facing_surface); |
| 3661 | parent->AddChild(back_facing_surface); |
| 3662 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3663 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3664 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3665 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3666 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3667 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3668 | host->SetRootLayer(parent); |
| 3669 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3670 | // Nothing is double-sided |
| 3671 | front_facing_child->SetDoubleSided(false); |
| 3672 | back_facing_child->SetDoubleSided(false); |
| 3673 | front_facing_surface->SetDoubleSided(false); |
| 3674 | back_facing_surface->SetDoubleSided(false); |
| 3675 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3676 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3677 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3678 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3679 | |
| 3680 | gfx::Transform backface_matrix; |
| 3681 | backface_matrix.Translate(50.0, 50.0); |
| 3682 | backface_matrix.RotateAboutYAxis(180.0); |
| 3683 | backface_matrix.Translate(-50.0, -50.0); |
| 3684 | |
| 3685 | // Opacity will not force creation of render surfaces in this case because of |
| 3686 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3687 | // would be created with preserve-3d is when there is a replica layer. |
| 3688 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3689 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3690 | |
| 3691 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3692 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3693 | // rendering context should use the transform with respect to that context. |
| 3694 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3695 | // and (b) the layer's transform style is preserve-3d. |
| 3696 | SetLayerPropertiesForTesting(parent.get(), |
| 3697 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3698 | gfx::PointF(), |
| 3699 | gfx::PointF(), |
| 3700 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3701 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3702 | false); // parent transform style is flat. |
| 3703 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3704 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3705 | gfx::PointF(), |
| 3706 | gfx::PointF(), |
| 3707 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3708 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3709 | false); |
| 3710 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3711 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3712 | gfx::PointF(), |
| 3713 | gfx::PointF(), |
| 3714 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3715 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3716 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3717 | // surface transform style is preserve-3d. |
| 3718 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3719 | identity_matrix, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3720 | gfx::PointF(), |
| 3721 | gfx::PointF(), |
| 3722 | gfx::Size(100, 100), |
| 3723 | false, |
| 3724 | true); |
| 3725 | // surface transform style is preserve-3d. |
| 3726 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3727 | backface_matrix, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3728 | gfx::PointF(), |
| 3729 | gfx::PointF(), |
| 3730 | gfx::Size(100, 100), |
| 3731 | false, |
| 3732 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3733 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3734 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3735 | gfx::PointF(), |
| 3736 | gfx::PointF(), |
| 3737 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3738 | true, |
| 3739 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3740 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3741 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3742 | gfx::PointF(), |
| 3743 | gfx::PointF(), |
| 3744 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3745 | true, |
| 3746 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3747 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3748 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3749 | gfx::PointF(), |
| 3750 | gfx::PointF(), |
| 3751 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3752 | true, |
| 3753 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3754 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3755 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3756 | gfx::PointF(), |
| 3757 | gfx::PointF(), |
| 3758 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3759 | true, |
| 3760 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3761 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3762 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3763 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3764 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3765 | inputs.can_adjust_raster_scales = true; |
| 3766 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3767 | |
| 3768 | // Verify which render surfaces were created. |
| 3769 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3770 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3771 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3772 | EXPECT_FALSE(back_facing_surface->render_surface()); |
| 3773 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3774 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3775 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3776 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3777 | |
| 3778 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3779 | // culled. |
| 3780 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3781 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3782 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3783 | |
| 3784 | // Verify root surface's layer list. |
| 3785 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3786 | 2u, |
| 3787 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3788 | EXPECT_EQ(front_facing_child->id(), |
| 3789 | render_surface_layer_list.at(0) |
| 3790 | ->render_surface()->layer_list().at(0)->id()); |
| 3791 | EXPECT_EQ(front_facing_surface->id(), |
| 3792 | render_surface_layer_list.at(0) |
| 3793 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3794 | |
| 3795 | // Verify front_facing_surface's layer list. |
| 3796 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3797 | 2u, |
| 3798 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3799 | EXPECT_EQ(front_facing_surface->id(), |
| 3800 | render_surface_layer_list.at(1) |
| 3801 | ->render_surface()->layer_list().at(0)->id()); |
| 3802 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3803 | render_surface_layer_list.at(1) |
| 3804 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3805 | } |
| 3806 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3807 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3808 | // Verify that layers are appropriately culled when their back face is showing |
| 3809 | // and they are not double sided, while animations are going on. |
| 3810 | // |
| 3811 | // Layers that are animating do not get culled on the main thread, as their |
| 3812 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3813 | // back face is really showing. |
| 3814 | const gfx::Transform identity_matrix; |
| 3815 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3816 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3817 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3818 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3819 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3820 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3821 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3822 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3823 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3824 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3825 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3826 | |
| 3827 | parent->AddChild(child); |
| 3828 | parent->AddChild(animating_surface); |
| 3829 | animating_surface->AddChild(child_of_animating_surface); |
| 3830 | parent->AddChild(animating_child); |
| 3831 | parent->AddChild(child2); |
| 3832 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3833 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3834 | host->SetRootLayer(parent); |
| 3835 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3836 | // Nothing is double-sided |
| 3837 | child->SetDoubleSided(false); |
| 3838 | child2->SetDoubleSided(false); |
| 3839 | animating_surface->SetDoubleSided(false); |
| 3840 | child_of_animating_surface->SetDoubleSided(false); |
| 3841 | animating_child->SetDoubleSided(false); |
| 3842 | |
| 3843 | gfx::Transform backface_matrix; |
| 3844 | backface_matrix.Translate(50.0, 50.0); |
| 3845 | backface_matrix.RotateAboutYAxis(180.0); |
| 3846 | backface_matrix.Translate(-50.0, -50.0); |
| 3847 | |
| 3848 | // Make our render surface. |
| 3849 | animating_surface->SetForceRenderSurface(true); |
| 3850 | |
| 3851 | // Animate the transform on the render surface. |
| 3852 | AddAnimatedTransformToController( |
| 3853 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 3854 | // This is just an animating layer, not a surface. |
| 3855 | AddAnimatedTransformToController( |
| 3856 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 3857 | |
| 3858 | SetLayerPropertiesForTesting(parent.get(), |
| 3859 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3860 | gfx::PointF(), |
| 3861 | gfx::PointF(), |
| 3862 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3863 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3864 | false); |
| 3865 | SetLayerPropertiesForTesting(child.get(), |
| 3866 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3867 | gfx::PointF(), |
| 3868 | gfx::PointF(), |
| 3869 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3870 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3871 | false); |
| 3872 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 3873 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3874 | gfx::PointF(), |
| 3875 | gfx::PointF(), |
| 3876 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3877 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3878 | false); |
| 3879 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 3880 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3881 | gfx::PointF(), |
| 3882 | gfx::PointF(), |
| 3883 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3884 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3885 | false); |
| 3886 | SetLayerPropertiesForTesting(animating_child.get(), |
| 3887 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3888 | gfx::PointF(), |
| 3889 | gfx::PointF(), |
| 3890 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3891 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3892 | false); |
| 3893 | SetLayerPropertiesForTesting(child2.get(), |
| 3894 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3895 | gfx::PointF(), |
| 3896 | gfx::PointF(), |
| 3897 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3898 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3899 | false); |
| 3900 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3901 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3902 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3903 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3904 | inputs.can_adjust_raster_scales = true; |
| 3905 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3906 | |
| 3907 | EXPECT_FALSE(child->render_surface()); |
| 3908 | EXPECT_TRUE(animating_surface->render_surface()); |
| 3909 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 3910 | EXPECT_FALSE(animating_child->render_surface()); |
| 3911 | EXPECT_FALSE(child2->render_surface()); |
| 3912 | |
| 3913 | // Verify that the animating_child and child_of_animating_surface were not |
| 3914 | // culled, but that child was. |
| 3915 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3916 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3917 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3918 | |
| 3919 | // The non-animating child be culled from the layer list for the parent render |
| 3920 | // surface. |
| 3921 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3922 | 3u, |
| 3923 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3924 | EXPECT_EQ(animating_surface->id(), |
| 3925 | render_surface_layer_list.at(0) |
| 3926 | ->render_surface()->layer_list().at(0)->id()); |
| 3927 | EXPECT_EQ(animating_child->id(), |
| 3928 | render_surface_layer_list.at(0) |
| 3929 | ->render_surface()->layer_list().at(1)->id()); |
| 3930 | EXPECT_EQ(child2->id(), |
| 3931 | render_surface_layer_list.at(0) |
| 3932 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3933 | |
| 3934 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3935 | 2u, |
| 3936 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3937 | EXPECT_EQ(animating_surface->id(), |
| 3938 | render_surface_layer_list.at(1) |
| 3939 | ->render_surface()->layer_list().at(0)->id()); |
| 3940 | EXPECT_EQ(child_of_animating_surface->id(), |
| 3941 | render_surface_layer_list.at(1) |
| 3942 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3943 | |
| 3944 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 3945 | |
| 3946 | // The animating layers should have a visible content rect that represents the |
| 3947 | // area of the front face that is within the viewport. |
| 3948 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3949 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3950 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3951 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3952 | // And layers in the subtree of the animating layer should have valid visible |
| 3953 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3954 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 3955 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3956 | } |
| 3957 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3958 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3959 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 3960 | // Verify the behavior of back-face culling for a render surface that is |
| 3961 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 3962 | |
| 3963 | const gfx::Transform identity_matrix; |
| 3964 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3965 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3966 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3967 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3968 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3969 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3970 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3971 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3972 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3973 | |
| 3974 | parent->AddChild(front_facing_surface); |
| 3975 | parent->AddChild(back_facing_surface); |
| 3976 | front_facing_surface->AddChild(child1); |
| 3977 | back_facing_surface->AddChild(child2); |
| 3978 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3979 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3980 | host->SetRootLayer(parent); |
| 3981 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3982 | // RenderSurfaces are not double-sided |
| 3983 | front_facing_surface->SetDoubleSided(false); |
| 3984 | back_facing_surface->SetDoubleSided(false); |
| 3985 | |
| 3986 | gfx::Transform backface_matrix; |
| 3987 | backface_matrix.Translate(50.0, 50.0); |
| 3988 | backface_matrix.RotateAboutYAxis(180.0); |
| 3989 | backface_matrix.Translate(-50.0, -50.0); |
| 3990 | |
| 3991 | SetLayerPropertiesForTesting(parent.get(), |
| 3992 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3993 | gfx::PointF(), |
| 3994 | gfx::PointF(), |
| 3995 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3996 | false, |
| 3997 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3998 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3999 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4000 | gfx::PointF(), |
| 4001 | gfx::PointF(), |
| 4002 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4003 | true, |
| 4004 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4005 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4006 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4007 | gfx::PointF(), |
| 4008 | gfx::PointF(), |
| 4009 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4010 | true, |
| 4011 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4012 | SetLayerPropertiesForTesting(child1.get(), |
| 4013 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4014 | gfx::PointF(), |
| 4015 | gfx::PointF(), |
| 4016 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4017 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4018 | false); |
| 4019 | SetLayerPropertiesForTesting(child2.get(), |
| 4020 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4021 | gfx::PointF(), |
| 4022 | gfx::PointF(), |
| 4023 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4024 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4025 | false); |
| 4026 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4027 | front_facing_surface->SetIs3dSorted(true); |
| 4028 | back_facing_surface->SetIs3dSorted(true); |
| 4029 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4030 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4031 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4032 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4033 | inputs.can_adjust_raster_scales = true; |
| 4034 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4035 | |
| 4036 | // Verify which render surfaces were created. |
| 4037 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 4038 | EXPECT_FALSE( |
| 4039 | back_facing_surface->render_surface()); // because it should be culled |
| 4040 | EXPECT_FALSE(child1->render_surface()); |
| 4041 | EXPECT_FALSE(child2->render_surface()); |
| 4042 | |
| 4043 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4044 | // culled. |
| 4045 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4046 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4047 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4048 | |
| 4049 | // Verify root surface's layer list. |
| 4050 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4051 | 1u, |
| 4052 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4053 | EXPECT_EQ(front_facing_surface->id(), |
| 4054 | render_surface_layer_list.at(0) |
| 4055 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4056 | |
| 4057 | // Verify front_facing_surface's layer list. |
| 4058 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4059 | 2u, |
| 4060 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4061 | EXPECT_EQ(front_facing_surface->id(), |
| 4062 | render_surface_layer_list.at(1) |
| 4063 | ->render_surface()->layer_list().at(0)->id()); |
| 4064 | EXPECT_EQ(child1->id(), |
| 4065 | render_surface_layer_list.at(1) |
| 4066 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4067 | } |
| 4068 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4069 | |
| 4070 | TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4071 | // Hit testing on an empty render_surface_layer_list should return a null |
| 4072 | // pointer. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4073 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4074 | |
| 4075 | gfx::Point test_point(0, 0); |
| 4076 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4077 | test_point, render_surface_layer_list); |
| 4078 | EXPECT_FALSE(result_layer); |
| 4079 | |
| 4080 | test_point = gfx::Point(10, 20); |
| 4081 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4082 | test_point, render_surface_layer_list); |
| 4083 | EXPECT_FALSE(result_layer); |
| 4084 | } |
| 4085 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4086 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4087 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4088 | TestSharedBitmapManager shared_bitmap_manager; |
| 4089 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4090 | scoped_ptr<LayerImpl> root = |
| 4091 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4092 | |
| 4093 | gfx::Transform identity_matrix; |
| 4094 | gfx::PointF anchor; |
| 4095 | gfx::PointF position; |
| 4096 | gfx::Size bounds(100, 100); |
| 4097 | SetLayerPropertiesForTesting(root.get(), |
| 4098 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4099 | anchor, |
| 4100 | position, |
| 4101 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4102 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4103 | false); |
| 4104 | root->SetDrawsContent(true); |
| 4105 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4106 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4107 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4108 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4109 | inputs.can_adjust_raster_scales = true; |
| 4110 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4111 | |
| 4112 | // Sanity check the scenario we just created. |
| 4113 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4114 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4115 | |
| 4116 | // Hit testing for a point outside the layer should return a null pointer. |
| 4117 | gfx::Point test_point(101, 101); |
| 4118 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4119 | test_point, render_surface_layer_list); |
| 4120 | EXPECT_FALSE(result_layer); |
| 4121 | |
| 4122 | test_point = gfx::Point(-1, -1); |
| 4123 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4124 | test_point, render_surface_layer_list); |
| 4125 | EXPECT_FALSE(result_layer); |
| 4126 | |
| 4127 | // Hit testing for a point inside should return the root layer. |
| 4128 | test_point = gfx::Point(1, 1); |
| 4129 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4130 | test_point, render_surface_layer_list); |
| 4131 | ASSERT_TRUE(result_layer); |
| 4132 | EXPECT_EQ(12345, result_layer->id()); |
| 4133 | |
| 4134 | test_point = gfx::Point(99, 99); |
| 4135 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4136 | test_point, render_surface_layer_list); |
| 4137 | ASSERT_TRUE(result_layer); |
| 4138 | EXPECT_EQ(12345, result_layer->id()); |
| 4139 | } |
| 4140 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4141 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4142 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4143 | TestSharedBitmapManager shared_bitmap_manager; |
| 4144 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4145 | scoped_ptr<LayerImpl> root = |
| 4146 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4147 | scoped_ptr<HeadsUpDisplayLayerImpl> hud = |
| 4148 | HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111); |
| 4149 | |
| 4150 | gfx::Transform identity_matrix; |
| 4151 | gfx::PointF anchor; |
| 4152 | gfx::PointF position; |
| 4153 | gfx::Size bounds(100, 100); |
| 4154 | SetLayerPropertiesForTesting(root.get(), |
| 4155 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4156 | anchor, |
| 4157 | position, |
| 4158 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4159 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4160 | false); |
| 4161 | root->SetDrawsContent(true); |
| 4162 | |
| 4163 | // Create hud and add it as a child of root. |
| 4164 | gfx::Size hud_bounds(200, 200); |
| 4165 | SetLayerPropertiesForTesting(hud.get(), |
| 4166 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4167 | anchor, |
| 4168 | position, |
| 4169 | hud_bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4170 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4171 | false); |
| 4172 | hud->SetDrawsContent(true); |
| 4173 | |
| 4174 | host_impl.active_tree()->set_hud_layer(hud.get()); |
| 4175 | root->AddChild(hud.PassAs<LayerImpl>()); |
| 4176 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4177 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4178 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4179 | root.get(), hud_bounds, &render_surface_layer_list); |
| 4180 | inputs.can_adjust_raster_scales = true; |
| 4181 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4182 | |
| 4183 | // Sanity check the scenario we just created. |
| 4184 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4185 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 4186 | |
| 4187 | // Hit testing for a point inside HUD, but outside root should return null |
| 4188 | gfx::Point test_point(101, 101); |
| 4189 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4190 | test_point, render_surface_layer_list); |
| 4191 | EXPECT_FALSE(result_layer); |
| 4192 | |
| 4193 | test_point = gfx::Point(-1, -1); |
| 4194 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4195 | test_point, render_surface_layer_list); |
| 4196 | EXPECT_FALSE(result_layer); |
| 4197 | |
| 4198 | // Hit testing for a point inside should return the root layer, never the HUD |
| 4199 | // layer. |
| 4200 | test_point = gfx::Point(1, 1); |
| 4201 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4202 | test_point, render_surface_layer_list); |
| 4203 | ASSERT_TRUE(result_layer); |
| 4204 | EXPECT_EQ(12345, result_layer->id()); |
| 4205 | |
| 4206 | test_point = gfx::Point(99, 99); |
| 4207 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4208 | test_point, render_surface_layer_list); |
| 4209 | ASSERT_TRUE(result_layer); |
| 4210 | EXPECT_EQ(12345, result_layer->id()); |
| 4211 | } |
| 4212 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4213 | TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4214 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4215 | TestSharedBitmapManager shared_bitmap_manager; |
| 4216 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4217 | scoped_ptr<LayerImpl> root = |
| 4218 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4219 | |
| 4220 | gfx::Transform uninvertible_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4221 | uninvertible_transform.matrix().set(0, 0, 0.0); |
| 4222 | uninvertible_transform.matrix().set(1, 1, 0.0); |
| 4223 | uninvertible_transform.matrix().set(2, 2, 0.0); |
| 4224 | uninvertible_transform.matrix().set(3, 3, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4225 | ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
| 4226 | |
| 4227 | gfx::Transform identity_matrix; |
| 4228 | gfx::PointF anchor; |
| 4229 | gfx::PointF position; |
| 4230 | gfx::Size bounds(100, 100); |
| 4231 | SetLayerPropertiesForTesting(root.get(), |
| 4232 | uninvertible_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4233 | anchor, |
| 4234 | position, |
| 4235 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4236 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4237 | false); |
| 4238 | root->SetDrawsContent(true); |
| 4239 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4240 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4241 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4242 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4243 | inputs.can_adjust_raster_scales = true; |
| 4244 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4245 | |
| 4246 | // Sanity check the scenario we just created. |
| 4247 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4248 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4249 | ASSERT_FALSE(root->screen_space_transform().IsInvertible()); |
| 4250 | |
| 4251 | // Hit testing any point should not hit the layer. If the invertible matrix is |
| 4252 | // accidentally ignored and treated like an identity, then the hit testing |
| 4253 | // will incorrectly hit the layer when it shouldn't. |
| 4254 | gfx::Point test_point(1, 1); |
| 4255 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4256 | test_point, render_surface_layer_list); |
| 4257 | EXPECT_FALSE(result_layer); |
| 4258 | |
| 4259 | test_point = gfx::Point(10, 10); |
| 4260 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4261 | test_point, render_surface_layer_list); |
| 4262 | EXPECT_FALSE(result_layer); |
| 4263 | |
| 4264 | test_point = gfx::Point(10, 30); |
| 4265 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4266 | test_point, render_surface_layer_list); |
| 4267 | EXPECT_FALSE(result_layer); |
| 4268 | |
| 4269 | test_point = gfx::Point(50, 50); |
| 4270 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4271 | test_point, render_surface_layer_list); |
| 4272 | EXPECT_FALSE(result_layer); |
| 4273 | |
| 4274 | test_point = gfx::Point(67, 48); |
| 4275 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4276 | test_point, render_surface_layer_list); |
| 4277 | EXPECT_FALSE(result_layer); |
| 4278 | |
| 4279 | test_point = gfx::Point(99, 99); |
| 4280 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4281 | test_point, render_surface_layer_list); |
| 4282 | EXPECT_FALSE(result_layer); |
| 4283 | |
| 4284 | test_point = gfx::Point(-1, -1); |
| 4285 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4286 | test_point, render_surface_layer_list); |
| 4287 | EXPECT_FALSE(result_layer); |
| 4288 | } |
| 4289 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4290 | TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4291 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4292 | TestSharedBitmapManager shared_bitmap_manager; |
| 4293 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4294 | scoped_ptr<LayerImpl> root = |
| 4295 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4296 | |
| 4297 | gfx::Transform identity_matrix; |
| 4298 | gfx::PointF anchor; |
| 4299 | // this layer is positioned, and hit testing should correctly know where the |
| 4300 | // layer is located. |
| 4301 | gfx::PointF position(50.f, 50.f); |
| 4302 | gfx::Size bounds(100, 100); |
| 4303 | SetLayerPropertiesForTesting(root.get(), |
| 4304 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4305 | anchor, |
| 4306 | position, |
| 4307 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4308 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4309 | false); |
| 4310 | root->SetDrawsContent(true); |
| 4311 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4312 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4313 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4314 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4315 | inputs.can_adjust_raster_scales = true; |
| 4316 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4317 | |
| 4318 | // Sanity check the scenario we just created. |
| 4319 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4320 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4321 | |
| 4322 | // Hit testing for a point outside the layer should return a null pointer. |
| 4323 | gfx::Point test_point(49, 49); |
| 4324 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4325 | test_point, render_surface_layer_list); |
| 4326 | EXPECT_FALSE(result_layer); |
| 4327 | |
| 4328 | // Even though the layer exists at (101, 101), it should not be visible there |
| 4329 | // since the root render surface would clamp it. |
| 4330 | test_point = gfx::Point(101, 101); |
| 4331 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4332 | test_point, render_surface_layer_list); |
| 4333 | EXPECT_FALSE(result_layer); |
| 4334 | |
| 4335 | // Hit testing for a point inside should return the root layer. |
| 4336 | test_point = gfx::Point(51, 51); |
| 4337 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4338 | test_point, render_surface_layer_list); |
| 4339 | ASSERT_TRUE(result_layer); |
| 4340 | EXPECT_EQ(12345, result_layer->id()); |
| 4341 | |
| 4342 | test_point = gfx::Point(99, 99); |
| 4343 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4344 | test_point, render_surface_layer_list); |
| 4345 | ASSERT_TRUE(result_layer); |
| 4346 | EXPECT_EQ(12345, result_layer->id()); |
| 4347 | } |
| 4348 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4349 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4350 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4351 | TestSharedBitmapManager shared_bitmap_manager; |
| 4352 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4353 | scoped_ptr<LayerImpl> root = |
| 4354 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4355 | |
| 4356 | gfx::Transform identity_matrix; |
| 4357 | gfx::Transform rotation45_degrees_about_center; |
| 4358 | rotation45_degrees_about_center.Translate(50.0, 50.0); |
| 4359 | rotation45_degrees_about_center.RotateAboutZAxis(45.0); |
| 4360 | rotation45_degrees_about_center.Translate(-50.0, -50.0); |
| 4361 | gfx::PointF anchor; |
| 4362 | gfx::PointF position; |
| 4363 | gfx::Size bounds(100, 100); |
| 4364 | SetLayerPropertiesForTesting(root.get(), |
| 4365 | rotation45_degrees_about_center, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4366 | anchor, |
| 4367 | position, |
| 4368 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4369 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4370 | false); |
| 4371 | root->SetDrawsContent(true); |
| 4372 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4373 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4374 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4375 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4376 | inputs.can_adjust_raster_scales = true; |
| 4377 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4378 | |
| 4379 | // Sanity check the scenario we just created. |
| 4380 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4381 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4382 | |
| 4383 | // Hit testing for points outside the layer. |
| 4384 | // These corners would have been inside the un-transformed layer, but they |
| 4385 | // should not hit the correctly transformed layer. |
| 4386 | gfx::Point test_point(99, 99); |
| 4387 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4388 | test_point, render_surface_layer_list); |
| 4389 | EXPECT_FALSE(result_layer); |
| 4390 | |
| 4391 | test_point = gfx::Point(1, 1); |
| 4392 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4393 | test_point, render_surface_layer_list); |
| 4394 | EXPECT_FALSE(result_layer); |
| 4395 | |
| 4396 | // Hit testing for a point inside should return the root layer. |
| 4397 | test_point = gfx::Point(1, 50); |
| 4398 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4399 | test_point, render_surface_layer_list); |
| 4400 | ASSERT_TRUE(result_layer); |
| 4401 | EXPECT_EQ(12345, result_layer->id()); |
| 4402 | |
| 4403 | // Hit testing the corners that would overlap the unclipped layer, but are |
| 4404 | // outside the clipped region. |
| 4405 | test_point = gfx::Point(50, -1); |
| 4406 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4407 | test_point, render_surface_layer_list); |
| 4408 | ASSERT_FALSE(result_layer); |
| 4409 | |
| 4410 | test_point = gfx::Point(-1, 50); |
| 4411 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4412 | test_point, render_surface_layer_list); |
| 4413 | ASSERT_FALSE(result_layer); |
| 4414 | } |
| 4415 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4416 | TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4417 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4418 | TestSharedBitmapManager shared_bitmap_manager; |
| 4419 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4420 | scoped_ptr<LayerImpl> root = |
| 4421 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4422 | |
| 4423 | gfx::Transform identity_matrix; |
| 4424 | |
| 4425 | // perspective_projection_about_center * translation_by_z is designed so that |
| 4426 | // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). |
| 4427 | gfx::Transform perspective_projection_about_center; |
| 4428 | perspective_projection_about_center.Translate(50.0, 50.0); |
| 4429 | perspective_projection_about_center.ApplyPerspectiveDepth(1.0); |
| 4430 | perspective_projection_about_center.Translate(-50.0, -50.0); |
| 4431 | gfx::Transform translation_by_z; |
| 4432 | translation_by_z.Translate3d(0.0, 0.0, -1.0); |
| 4433 | |
| 4434 | gfx::PointF anchor; |
| 4435 | gfx::PointF position; |
| 4436 | gfx::Size bounds(100, 100); |
| 4437 | SetLayerPropertiesForTesting( |
| 4438 | root.get(), |
| 4439 | perspective_projection_about_center * translation_by_z, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4440 | anchor, |
| 4441 | position, |
| 4442 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4443 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4444 | false); |
| 4445 | root->SetDrawsContent(true); |
| 4446 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4447 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4448 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4449 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4450 | inputs.can_adjust_raster_scales = true; |
| 4451 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4452 | |
| 4453 | // Sanity check the scenario we just created. |
| 4454 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4455 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4456 | |
| 4457 | // Hit testing for points outside the layer. |
| 4458 | // These corners would have been inside the un-transformed layer, but they |
| 4459 | // should not hit the correctly transformed layer. |
| 4460 | gfx::Point test_point(24, 24); |
| 4461 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4462 | test_point, render_surface_layer_list); |
| 4463 | EXPECT_FALSE(result_layer); |
| 4464 | |
| 4465 | test_point = gfx::Point(76, 76); |
| 4466 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4467 | test_point, render_surface_layer_list); |
| 4468 | EXPECT_FALSE(result_layer); |
| 4469 | |
| 4470 | // Hit testing for a point inside should return the root layer. |
| 4471 | test_point = gfx::Point(26, 26); |
| 4472 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4473 | test_point, render_surface_layer_list); |
| 4474 | ASSERT_TRUE(result_layer); |
| 4475 | EXPECT_EQ(12345, result_layer->id()); |
| 4476 | |
| 4477 | test_point = gfx::Point(74, 74); |
| 4478 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4479 | test_point, render_surface_layer_list); |
| 4480 | ASSERT_TRUE(result_layer); |
| 4481 | EXPECT_EQ(12345, result_layer->id()); |
| 4482 | } |
| 4483 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4484 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4485 | // A layer's visible content rect is actually in the layer's content space. |
| 4486 | // The screen space transform converts from the layer's origin space to screen |
| 4487 | // space. This test makes sure that hit testing works correctly accounts for |
| 4488 | // the contents scale. A contents scale that is not 1 effectively forces a |
| 4489 | // non-identity transform between layer's content space and layer's origin |
| 4490 | // space. The hit testing code must take this into account. |
| 4491 | // |
| 4492 | // To test this, the layer is positioned at (25, 25), and is size (50, 50). If |
| 4493 | // contents scale is ignored, then hit testing will mis-interpret the visible |
| 4494 | // content rect as being larger than the actual bounds of the layer. |
| 4495 | // |
| 4496 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4497 | TestSharedBitmapManager shared_bitmap_manager; |
| 4498 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4499 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4500 | |
| 4501 | gfx::Transform identity_matrix; |
| 4502 | gfx::PointF anchor; |
| 4503 | |
| 4504 | SetLayerPropertiesForTesting(root.get(), |
| 4505 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4506 | anchor, |
| 4507 | gfx::PointF(), |
| 4508 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4509 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4510 | false); |
| 4511 | { |
| 4512 | gfx::PointF position(25.f, 25.f); |
| 4513 | gfx::Size bounds(50, 50); |
| 4514 | scoped_ptr<LayerImpl> test_layer = |
| 4515 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4516 | SetLayerPropertiesForTesting(test_layer.get(), |
| 4517 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4518 | anchor, |
| 4519 | position, |
| 4520 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4521 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4522 | false); |
| 4523 | |
| 4524 | // override content bounds and contents scale |
| 4525 | test_layer->SetContentBounds(gfx::Size(100, 100)); |
| 4526 | test_layer->SetContentsScale(2, 2); |
| 4527 | |
| 4528 | test_layer->SetDrawsContent(true); |
| 4529 | root->AddChild(test_layer.Pass()); |
| 4530 | } |
| 4531 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4532 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4533 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4534 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4535 | inputs.can_adjust_raster_scales = true; |
| 4536 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4537 | |
| 4538 | // Sanity check the scenario we just created. |
| 4539 | // The visible content rect for test_layer is actually 100x100, even though |
| 4540 | // its layout size is 50x50, positioned at 25x25. |
| 4541 | LayerImpl* test_layer = root->children()[0]; |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4542 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4543 | test_layer->visible_content_rect()); |
| 4544 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4545 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4546 | |
| 4547 | // Hit testing for a point outside the layer should return a null pointer (the |
| 4548 | // root layer does not draw content, so it will not be hit tested either). |
| 4549 | gfx::Point test_point(101, 101); |
| 4550 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4551 | test_point, render_surface_layer_list); |
| 4552 | EXPECT_FALSE(result_layer); |
| 4553 | |
| 4554 | test_point = gfx::Point(24, 24); |
| 4555 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4556 | test_point, render_surface_layer_list); |
| 4557 | EXPECT_FALSE(result_layer); |
| 4558 | |
| 4559 | test_point = gfx::Point(76, 76); |
| 4560 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4561 | test_point, render_surface_layer_list); |
| 4562 | EXPECT_FALSE(result_layer); |
| 4563 | |
| 4564 | // Hit testing for a point inside should return the test layer. |
| 4565 | test_point = gfx::Point(26, 26); |
| 4566 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4567 | test_point, render_surface_layer_list); |
| 4568 | ASSERT_TRUE(result_layer); |
| 4569 | EXPECT_EQ(12345, result_layer->id()); |
| 4570 | |
| 4571 | test_point = gfx::Point(74, 74); |
| 4572 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4573 | test_point, render_surface_layer_list); |
| 4574 | ASSERT_TRUE(result_layer); |
| 4575 | EXPECT_EQ(12345, result_layer->id()); |
| 4576 | } |
| 4577 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4578 | TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4579 | // Test that hit-testing will only work for the visible portion of a layer, |
| 4580 | // and not the entire layer bounds. Here we just test the simple axis-aligned |
| 4581 | // case. |
| 4582 | gfx::Transform identity_matrix; |
| 4583 | gfx::PointF anchor; |
| 4584 | |
| 4585 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4586 | TestSharedBitmapManager shared_bitmap_manager; |
| 4587 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4588 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4589 | SetLayerPropertiesForTesting(root.get(), |
| 4590 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4591 | anchor, |
| 4592 | gfx::PointF(), |
| 4593 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4594 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4595 | false); |
| 4596 | { |
| 4597 | scoped_ptr<LayerImpl> clipping_layer = |
| 4598 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 4599 | // this layer is positioned, and hit testing should correctly know where the |
| 4600 | // layer is located. |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4601 | gfx::PointF position(25.f, 25.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4602 | gfx::Size bounds(50, 50); |
| 4603 | SetLayerPropertiesForTesting(clipping_layer.get(), |
| 4604 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4605 | anchor, |
| 4606 | position, |
| 4607 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4608 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4609 | false); |
| 4610 | clipping_layer->SetMasksToBounds(true); |
| 4611 | |
| 4612 | scoped_ptr<LayerImpl> child = |
| 4613 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4614 | position = gfx::PointF(-50.f, -50.f); |
| 4615 | bounds = gfx::Size(300, 300); |
| 4616 | SetLayerPropertiesForTesting(child.get(), |
| 4617 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4618 | anchor, |
| 4619 | position, |
| 4620 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4621 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4622 | false); |
| 4623 | child->SetDrawsContent(true); |
| 4624 | clipping_layer->AddChild(child.Pass()); |
| 4625 | root->AddChild(clipping_layer.Pass()); |
| 4626 | } |
| 4627 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4628 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4629 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4630 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4631 | inputs.can_adjust_raster_scales = true; |
| 4632 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4633 | |
| 4634 | // Sanity check the scenario we just created. |
| 4635 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4636 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4637 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4638 | |
| 4639 | // Hit testing for a point outside the layer should return a null pointer. |
| 4640 | // Despite the child layer being very large, it should be clipped to the root |
| 4641 | // layer's bounds. |
| 4642 | gfx::Point test_point(24, 24); |
| 4643 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4644 | test_point, render_surface_layer_list); |
| 4645 | EXPECT_FALSE(result_layer); |
| 4646 | |
| 4647 | // Even though the layer exists at (101, 101), it should not be visible there |
| 4648 | // since the clipping_layer would clamp it. |
| 4649 | test_point = gfx::Point(76, 76); |
| 4650 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4651 | test_point, render_surface_layer_list); |
| 4652 | EXPECT_FALSE(result_layer); |
| 4653 | |
| 4654 | // Hit testing for a point inside should return the child layer. |
| 4655 | test_point = gfx::Point(26, 26); |
| 4656 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4657 | test_point, render_surface_layer_list); |
| 4658 | ASSERT_TRUE(result_layer); |
| 4659 | EXPECT_EQ(456, result_layer->id()); |
| 4660 | |
| 4661 | test_point = gfx::Point(74, 74); |
| 4662 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4663 | test_point, render_surface_layer_list); |
| 4664 | ASSERT_TRUE(result_layer); |
| 4665 | EXPECT_EQ(456, result_layer->id()); |
| 4666 | } |
| 4667 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4668 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4669 | // This test checks whether hit testing correctly avoids hit testing with |
| 4670 | // multiple ancestors that clip in non axis-aligned ways. To pass this test, |
| 4671 | // the hit testing algorithm needs to recognize that multiple parent layers |
| 4672 | // may clip the layer, and should not actually hit those clipped areas. |
| 4673 | // |
| 4674 | // The child and grand_child layers are both initialized to clip the |
| 4675 | // rotated_leaf. The child layer is rotated about the top-left corner, so that |
| 4676 | // the root + child clips combined create a triangle. The rotated_leaf will |
| 4677 | // only be visible where it overlaps this triangle. |
| 4678 | // |
| 4679 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4680 | TestSharedBitmapManager shared_bitmap_manager; |
| 4681 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4682 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123); |
| 4683 | |
| 4684 | gfx::Transform identity_matrix; |
| 4685 | gfx::PointF anchor; |
| 4686 | gfx::PointF position; |
| 4687 | gfx::Size bounds(100, 100); |
| 4688 | SetLayerPropertiesForTesting(root.get(), |
| 4689 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4690 | anchor, |
| 4691 | position, |
| 4692 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4693 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4694 | false); |
| 4695 | root->SetMasksToBounds(true); |
| 4696 | { |
| 4697 | scoped_ptr<LayerImpl> child = |
| 4698 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4699 | scoped_ptr<LayerImpl> grand_child = |
| 4700 | LayerImpl::Create(host_impl.active_tree(), 789); |
| 4701 | scoped_ptr<LayerImpl> rotated_leaf = |
| 4702 | LayerImpl::Create(host_impl.active_tree(), 2468); |
| 4703 | |
| 4704 | position = gfx::PointF(10.f, 10.f); |
| 4705 | bounds = gfx::Size(80, 80); |
| 4706 | SetLayerPropertiesForTesting(child.get(), |
| 4707 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4708 | anchor, |
| 4709 | position, |
| 4710 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4711 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4712 | false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4713 | child->SetMasksToBounds(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4714 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4715 | gfx::Transform rotation45_degrees_about_corner; |
| 4716 | rotation45_degrees_about_corner.RotateAboutZAxis(45.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4717 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4718 | // remember, positioned with respect to its parent which is already at 10, |
| 4719 | // 10 |
| 4720 | position = gfx::PointF(); |
| 4721 | bounds = |
| 4722 | gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100. |
| 4723 | SetLayerPropertiesForTesting(grand_child.get(), |
| 4724 | rotation45_degrees_about_corner, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4725 | anchor, |
| 4726 | position, |
| 4727 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4728 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4729 | false); |
| 4730 | grand_child->SetMasksToBounds(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4731 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4732 | // Rotates about the center of the layer |
| 4733 | gfx::Transform rotated_leaf_transform; |
| 4734 | rotated_leaf_transform.Translate( |
| 4735 | -10.0, -10.0); // cancel out the grand_parent's position |
| 4736 | rotated_leaf_transform.RotateAboutZAxis( |
| 4737 | -45.0); // cancel out the corner 45-degree rotation of the parent. |
| 4738 | rotated_leaf_transform.Translate(50.0, 50.0); |
| 4739 | rotated_leaf_transform.RotateAboutZAxis(45.0); |
| 4740 | rotated_leaf_transform.Translate(-50.0, -50.0); |
| 4741 | position = gfx::PointF(); |
| 4742 | bounds = gfx::Size(100, 100); |
| 4743 | SetLayerPropertiesForTesting(rotated_leaf.get(), |
| 4744 | rotated_leaf_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4745 | anchor, |
| 4746 | position, |
| 4747 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4748 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4749 | false); |
| 4750 | rotated_leaf->SetDrawsContent(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4751 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4752 | grand_child->AddChild(rotated_leaf.Pass()); |
| 4753 | child->AddChild(grand_child.Pass()); |
| 4754 | root->AddChild(child.Pass()); |
| 4755 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4756 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4757 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4758 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4759 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4760 | inputs.can_adjust_raster_scales = true; |
| 4761 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4762 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4763 | // Sanity check the scenario we just created. |
| 4764 | // The grand_child is expected to create a render surface because it |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4765 | // MasksToBounds and is not axis aligned. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4766 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
| 4767 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4768 | 1u, |
| 4769 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4770 | ASSERT_EQ(789, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4771 | render_surface_layer_list.at(0)->render_surface()->layer_list().at( |
| 4772 | 0)->id()); // grand_child's surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4773 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4774 | 1u, |
| 4775 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4776 | ASSERT_EQ( |
| 4777 | 2468, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4778 | render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4779 | |
| 4780 | // (11, 89) is close to the the bottom left corner within the clip, but it is |
| 4781 | // not inside the layer. |
| 4782 | gfx::Point test_point(11, 89); |
| 4783 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4784 | test_point, render_surface_layer_list); |
| 4785 | EXPECT_FALSE(result_layer); |
| 4786 | |
| 4787 | // Closer inwards from the bottom left will overlap the layer. |
| 4788 | test_point = gfx::Point(25, 75); |
| 4789 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4790 | test_point, render_surface_layer_list); |
| 4791 | ASSERT_TRUE(result_layer); |
| 4792 | EXPECT_EQ(2468, result_layer->id()); |
| 4793 | |
| 4794 | // (4, 50) is inside the unclipped layer, but that corner of the layer should |
| 4795 | // be clipped away by the grandparent and should not get hit. If hit testing |
| 4796 | // blindly uses visible content rect without considering how parent may clip |
| 4797 | // the layer, then hit testing would accidentally think that the point |
| 4798 | // successfully hits the layer. |
| 4799 | test_point = gfx::Point(4, 50); |
| 4800 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4801 | test_point, render_surface_layer_list); |
| 4802 | EXPECT_FALSE(result_layer); |
| 4803 | |
| 4804 | // (11, 50) is inside the layer and within the clipped area. |
| 4805 | test_point = gfx::Point(11, 50); |
| 4806 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4807 | test_point, render_surface_layer_list); |
| 4808 | ASSERT_TRUE(result_layer); |
| 4809 | EXPECT_EQ(2468, result_layer->id()); |
| 4810 | |
| 4811 | // Around the middle, just to the right and up, would have hit the layer |
| 4812 | // except that that area should be clipped away by the parent. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4813 | test_point = gfx::Point(51, 49); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4814 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4815 | test_point, render_surface_layer_list); |
| 4816 | EXPECT_FALSE(result_layer); |
| 4817 | |
| 4818 | // Around the middle, just to the left and down, should successfully hit the |
| 4819 | // layer. |
| 4820 | test_point = gfx::Point(49, 51); |
| 4821 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4822 | test_point, render_surface_layer_list); |
| 4823 | ASSERT_TRUE(result_layer); |
| 4824 | EXPECT_EQ(2468, result_layer->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4825 | } |
| 4826 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4827 | TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4828 | // This test checks that hit testing code does not accidentally clip to layer |
| 4829 | // bounds for a layer that actually does not clip. |
| 4830 | gfx::Transform identity_matrix; |
| 4831 | gfx::PointF anchor; |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4832 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4833 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4834 | TestSharedBitmapManager shared_bitmap_manager; |
| 4835 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4836 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4837 | SetLayerPropertiesForTesting(root.get(), |
| 4838 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4839 | anchor, |
| 4840 | gfx::PointF(), |
| 4841 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4842 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4843 | false); |
| 4844 | { |
| 4845 | scoped_ptr<LayerImpl> intermediate_layer = |
| 4846 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 4847 | // this layer is positioned, and hit testing should correctly know where the |
| 4848 | // layer is located. |
| 4849 | gfx::PointF position(10.f, 10.f); |
| 4850 | gfx::Size bounds(50, 50); |
| 4851 | SetLayerPropertiesForTesting(intermediate_layer.get(), |
| 4852 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4853 | anchor, |
| 4854 | position, |
| 4855 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4856 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4857 | false); |
| 4858 | // Sanity check the intermediate layer should not clip. |
| 4859 | ASSERT_FALSE(intermediate_layer->masks_to_bounds()); |
| 4860 | ASSERT_FALSE(intermediate_layer->mask_layer()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4861 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4862 | // The child of the intermediate_layer is translated so that it does not |
| 4863 | // overlap intermediate_layer at all. If child is incorrectly clipped, we |
| 4864 | // would not be able to hit it successfully. |
| 4865 | scoped_ptr<LayerImpl> child = |
| 4866 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4867 | position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space |
| 4868 | bounds = gfx::Size(20, 20); |
| 4869 | SetLayerPropertiesForTesting(child.get(), |
| 4870 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4871 | anchor, |
| 4872 | position, |
| 4873 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4874 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4875 | false); |
| 4876 | child->SetDrawsContent(true); |
| 4877 | intermediate_layer->AddChild(child.Pass()); |
| 4878 | root->AddChild(intermediate_layer.Pass()); |
| 4879 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4880 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4881 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4882 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4883 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4884 | inputs.can_adjust_raster_scales = true; |
| 4885 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4886 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4887 | // Sanity check the scenario we just created. |
| 4888 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4889 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4890 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4891 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4892 | // Hit testing for a point outside the layer should return a null pointer. |
| 4893 | gfx::Point test_point(69, 69); |
| 4894 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4895 | test_point, render_surface_layer_list); |
| 4896 | EXPECT_FALSE(result_layer); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4897 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4898 | test_point = gfx::Point(91, 91); |
| 4899 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4900 | test_point, render_surface_layer_list); |
| 4901 | EXPECT_FALSE(result_layer); |
| 4902 | |
| 4903 | // Hit testing for a point inside should return the child layer. |
| 4904 | test_point = gfx::Point(71, 71); |
| 4905 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4906 | test_point, render_surface_layer_list); |
| 4907 | ASSERT_TRUE(result_layer); |
| 4908 | EXPECT_EQ(456, result_layer->id()); |
| 4909 | |
| 4910 | test_point = gfx::Point(89, 89); |
| 4911 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4912 | test_point, render_surface_layer_list); |
| 4913 | ASSERT_TRUE(result_layer); |
| 4914 | EXPECT_EQ(456, result_layer->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4915 | } |
| 4916 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4917 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4918 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4919 | TestSharedBitmapManager shared_bitmap_manager; |
| 4920 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4921 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4922 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4923 | gfx::Transform identity_matrix; |
| 4924 | gfx::PointF anchor; |
| 4925 | gfx::PointF position; |
| 4926 | gfx::Size bounds(100, 100); |
| 4927 | SetLayerPropertiesForTesting(root.get(), |
| 4928 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4929 | anchor, |
| 4930 | position, |
| 4931 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4932 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4933 | false); |
| 4934 | root->SetDrawsContent(true); |
| 4935 | { |
| 4936 | // child 1 and child2 are initialized to overlap between x=50 and x=60. |
| 4937 | // grand_child is set to overlap both child1 and child2 between y=50 and |
| 4938 | // y=60. The expected stacking order is: (front) child2, (second) |
| 4939 | // grand_child, (third) child1, and (back) the root layer behind all other |
| 4940 | // layers. |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 4941 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4942 | scoped_ptr<LayerImpl> child1 = |
| 4943 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 4944 | scoped_ptr<LayerImpl> child2 = |
| 4945 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 4946 | scoped_ptr<LayerImpl> grand_child1 = |
| 4947 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4948 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4949 | position = gfx::PointF(10.f, 10.f); |
| 4950 | bounds = gfx::Size(50, 50); |
| 4951 | SetLayerPropertiesForTesting(child1.get(), |
| 4952 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4953 | anchor, |
| 4954 | position, |
| 4955 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4956 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4957 | false); |
| 4958 | child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4959 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4960 | position = gfx::PointF(50.f, 10.f); |
| 4961 | bounds = gfx::Size(50, 50); |
| 4962 | SetLayerPropertiesForTesting(child2.get(), |
| 4963 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4964 | anchor, |
| 4965 | position, |
| 4966 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4967 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4968 | false); |
| 4969 | child2->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4970 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4971 | // Remember that grand_child is positioned with respect to its parent (i.e. |
| 4972 | // child1). In screen space, the intended position is (10, 50), with size |
| 4973 | // 100 x 50. |
| 4974 | position = gfx::PointF(0.f, 40.f); |
| 4975 | bounds = gfx::Size(100, 50); |
| 4976 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 4977 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4978 | anchor, |
| 4979 | position, |
| 4980 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4981 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4982 | false); |
| 4983 | grand_child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4984 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4985 | child1->AddChild(grand_child1.Pass()); |
| 4986 | root->AddChild(child1.Pass()); |
| 4987 | root->AddChild(child2.Pass()); |
| 4988 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4989 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4990 | LayerImpl* child1 = root->children()[0]; |
| 4991 | LayerImpl* child2 = root->children()[1]; |
| 4992 | LayerImpl* grand_child1 = child1->children()[0]; |
| 4993 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4994 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4995 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4996 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4997 | inputs.can_adjust_raster_scales = true; |
| 4998 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4999 | |
| 5000 | // Sanity check the scenario we just created. |
| 5001 | ASSERT_TRUE(child1); |
| 5002 | ASSERT_TRUE(child2); |
| 5003 | ASSERT_TRUE(grand_child1); |
| 5004 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5005 | |
| 5006 | RenderSurfaceImpl* root_render_surface = root->render_surface(); |
| 5007 | ASSERT_EQ(4u, root_render_surface->layer_list().size()); |
| 5008 | ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer |
| 5009 | ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1 |
| 5010 | ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1 |
| 5011 | ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2 |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5012 | |
| 5013 | // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
| 5014 | // the root layer. |
| 5015 | gfx::Point test_point = gfx::Point(1, 1); |
| 5016 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5017 | test_point, render_surface_layer_list); |
| 5018 | ASSERT_TRUE(result_layer); |
| 5019 | EXPECT_EQ(1, result_layer->id()); |
| 5020 | |
| 5021 | // At (15, 15), child1 and root are the only layers. child1 is expected to be |
| 5022 | // on top. |
| 5023 | test_point = gfx::Point(15, 15); |
| 5024 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5025 | test_point, render_surface_layer_list); |
| 5026 | ASSERT_TRUE(result_layer); |
| 5027 | EXPECT_EQ(2, result_layer->id()); |
| 5028 | |
| 5029 | // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. |
| 5030 | test_point = gfx::Point(51, 20); |
| 5031 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5032 | test_point, render_surface_layer_list); |
| 5033 | ASSERT_TRUE(result_layer); |
| 5034 | EXPECT_EQ(3, result_layer->id()); |
| 5035 | |
| 5036 | // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on |
| 5037 | // top. |
| 5038 | test_point = gfx::Point(80, 51); |
| 5039 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5040 | test_point, render_surface_layer_list); |
| 5041 | ASSERT_TRUE(result_layer); |
| 5042 | EXPECT_EQ(3, result_layer->id()); |
| 5043 | |
| 5044 | // At (51, 51), all layers overlap each other. child2 is expected to be on top |
| 5045 | // of all other layers. |
| 5046 | test_point = gfx::Point(51, 51); |
| 5047 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5048 | test_point, render_surface_layer_list); |
| 5049 | ASSERT_TRUE(result_layer); |
| 5050 | EXPECT_EQ(3, result_layer->id()); |
| 5051 | |
| 5052 | // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to |
| 5053 | // be on top. |
| 5054 | test_point = gfx::Point(20, 51); |
| 5055 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5056 | test_point, render_surface_layer_list); |
| 5057 | ASSERT_TRUE(result_layer); |
| 5058 | EXPECT_EQ(4, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5059 | } |
| 5060 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5061 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5062 | // |
| 5063 | // The geometry is set up similarly to the previous case, but |
| 5064 | // all layers are forced to be render surfaces now. |
| 5065 | // |
| 5066 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5067 | TestSharedBitmapManager shared_bitmap_manager; |
| 5068 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5069 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5070 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5071 | gfx::Transform identity_matrix; |
| 5072 | gfx::PointF anchor; |
| 5073 | gfx::PointF position; |
| 5074 | gfx::Size bounds(100, 100); |
| 5075 | SetLayerPropertiesForTesting(root.get(), |
| 5076 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5077 | anchor, |
| 5078 | position, |
| 5079 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5080 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5081 | false); |
| 5082 | root->SetDrawsContent(true); |
| 5083 | { |
| 5084 | // child 1 and child2 are initialized to overlap between x=50 and x=60. |
| 5085 | // grand_child is set to overlap both child1 and child2 between y=50 and |
| 5086 | // y=60. The expected stacking order is: (front) child2, (second) |
| 5087 | // grand_child, (third) child1, and (back) the root layer behind all other |
| 5088 | // layers. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5089 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5090 | scoped_ptr<LayerImpl> child1 = |
| 5091 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 5092 | scoped_ptr<LayerImpl> child2 = |
| 5093 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 5094 | scoped_ptr<LayerImpl> grand_child1 = |
| 5095 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5096 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5097 | position = gfx::PointF(10.f, 10.f); |
| 5098 | bounds = gfx::Size(50, 50); |
| 5099 | SetLayerPropertiesForTesting(child1.get(), |
| 5100 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5101 | anchor, |
| 5102 | position, |
| 5103 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5104 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5105 | false); |
| 5106 | child1->SetDrawsContent(true); |
| 5107 | child1->SetForceRenderSurface(true); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 5108 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5109 | position = gfx::PointF(50.f, 10.f); |
| 5110 | bounds = gfx::Size(50, 50); |
| 5111 | SetLayerPropertiesForTesting(child2.get(), |
| 5112 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5113 | anchor, |
| 5114 | position, |
| 5115 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5116 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5117 | false); |
| 5118 | child2->SetDrawsContent(true); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 5119 | child2->SetForceRenderSurface(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5120 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5121 | // Remember that grand_child is positioned with respect to its parent (i.e. |
| 5122 | // child1). In screen space, the intended position is (10, 50), with size |
| 5123 | // 100 x 50. |
| 5124 | position = gfx::PointF(0.f, 40.f); |
| 5125 | bounds = gfx::Size(100, 50); |
| 5126 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 5127 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5128 | anchor, |
| 5129 | position, |
| 5130 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5131 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5132 | false); |
| 5133 | grand_child1->SetDrawsContent(true); |
| 5134 | grand_child1->SetForceRenderSurface(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5135 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5136 | child1->AddChild(grand_child1.Pass()); |
| 5137 | root->AddChild(child1.Pass()); |
| 5138 | root->AddChild(child2.Pass()); |
| 5139 | } |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5140 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5141 | LayerImpl* child1 = root->children()[0]; |
| 5142 | LayerImpl* child2 = root->children()[1]; |
| 5143 | LayerImpl* grand_child1 = child1->children()[0]; |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5144 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5145 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5146 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5147 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5148 | inputs.can_adjust_raster_scales = true; |
| 5149 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5150 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5151 | // Sanity check the scenario we just created. |
| 5152 | ASSERT_TRUE(child1); |
| 5153 | ASSERT_TRUE(child2); |
| 5154 | ASSERT_TRUE(grand_child1); |
| 5155 | ASSERT_TRUE(child1->render_surface()); |
| 5156 | ASSERT_TRUE(child2->render_surface()); |
| 5157 | ASSERT_TRUE(grand_child1->render_surface()); |
| 5158 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
| 5159 | // The root surface has the root layer, and child1's and child2's render |
| 5160 | // surfaces. |
| 5161 | ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
| 5162 | // The child1 surface has the child1 layer and grand_child1's render surface. |
| 5163 | ASSERT_EQ(2u, child1->render_surface()->layer_list().size()); |
| 5164 | ASSERT_EQ(1u, child2->render_surface()->layer_list().size()); |
| 5165 | ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5166 | ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5167 | ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1 |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5168 | ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1 |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5169 | ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2 |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5170 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5171 | // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
| 5172 | // the root layer. |
| 5173 | gfx::Point test_point = gfx::Point(1, 1); |
| 5174 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5175 | test_point, render_surface_layer_list); |
| 5176 | ASSERT_TRUE(result_layer); |
| 5177 | EXPECT_EQ(1, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5178 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5179 | // At (15, 15), child1 and root are the only layers. child1 is expected to be |
| 5180 | // on top. |
| 5181 | test_point = gfx::Point(15, 15); |
| 5182 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5183 | test_point, render_surface_layer_list); |
| 5184 | ASSERT_TRUE(result_layer); |
| 5185 | EXPECT_EQ(2, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5186 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5187 | // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. |
| 5188 | test_point = gfx::Point(51, 20); |
| 5189 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5190 | test_point, render_surface_layer_list); |
| 5191 | ASSERT_TRUE(result_layer); |
| 5192 | EXPECT_EQ(3, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5193 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5194 | // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on |
| 5195 | // top. |
| 5196 | test_point = gfx::Point(80, 51); |
| 5197 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5198 | test_point, render_surface_layer_list); |
| 5199 | ASSERT_TRUE(result_layer); |
| 5200 | EXPECT_EQ(3, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5201 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5202 | // At (51, 51), all layers overlap each other. child2 is expected to be on top |
| 5203 | // of all other layers. |
| 5204 | test_point = gfx::Point(51, 51); |
| 5205 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5206 | test_point, render_surface_layer_list); |
| 5207 | ASSERT_TRUE(result_layer); |
| 5208 | EXPECT_EQ(3, result_layer->id()); |
| 5209 | |
| 5210 | // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to |
| 5211 | // be on top. |
| 5212 | test_point = gfx::Point(20, 51); |
| 5213 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5214 | test_point, render_surface_layer_list); |
| 5215 | ASSERT_TRUE(result_layer); |
| 5216 | EXPECT_EQ(4, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5217 | } |
| 5218 | |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5219 | TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) { |
| 5220 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5221 | TestSharedBitmapManager shared_bitmap_manager; |
| 5222 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5223 | |
| 5224 | // Layer 1 - root |
| 5225 | scoped_ptr<LayerImpl> root = |
| 5226 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 5227 | gfx::Transform identity_matrix; |
| 5228 | gfx::PointF anchor; |
| 5229 | gfx::PointF position; |
| 5230 | gfx::Size bounds(100, 100); |
| 5231 | SetLayerPropertiesForTesting(root.get(), |
| 5232 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5233 | anchor, |
| 5234 | position, |
| 5235 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5236 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5237 | false); |
| 5238 | root->SetDrawsContent(true); |
| 5239 | |
| 5240 | { |
| 5241 | // Layer 2 - empty: drawsContent=false |
| 5242 | gfx::PointF position(10.f, 10.f); |
| 5243 | gfx::Size bounds(30, 30); |
| 5244 | scoped_ptr<LayerImpl> empty_layer = |
| 5245 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 5246 | SetLayerPropertiesForTesting(empty_layer.get(), |
| 5247 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5248 | anchor, |
| 5249 | position, |
| 5250 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5251 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5252 | false); |
| 5253 | |
| 5254 | empty_layer->SetDrawsContent(false); |
| 5255 | root->AddChild(empty_layer.Pass()); |
| 5256 | } |
| 5257 | |
| 5258 | { |
| 5259 | // Layer 3 - empty, but has touch handler |
| 5260 | gfx::PointF position(10.f, 60.f); |
| 5261 | gfx::Size bounds(30, 30); |
| 5262 | scoped_ptr<LayerImpl> test_layer = |
| 5263 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 5264 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5265 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5266 | anchor, |
| 5267 | position, |
| 5268 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5269 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5270 | false); |
| 5271 | |
| 5272 | test_layer->SetDrawsContent(false); |
| 5273 | Region touch_handler_region(gfx::Rect(10, 10, 10, 10)); |
| 5274 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5275 | root->AddChild(test_layer.Pass()); |
| 5276 | } |
| 5277 | |
| 5278 | { |
| 5279 | // Layer 4 - empty, but has mousewheel handler |
| 5280 | gfx::PointF position(60.f, 60.f); |
| 5281 | gfx::Size bounds(30, 30); |
| 5282 | scoped_ptr<LayerImpl> test_layer = |
| 5283 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 5284 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5285 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5286 | anchor, |
| 5287 | position, |
| 5288 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5289 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5290 | false); |
| 5291 | |
| 5292 | test_layer->SetDrawsContent(false); |
| 5293 | test_layer->SetHaveWheelEventHandlers(true); |
| 5294 | root->AddChild(test_layer.Pass()); |
| 5295 | } |
| 5296 | |
| 5297 | LayerImplList render_surface_layer_list; |
| 5298 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5299 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5300 | inputs.can_adjust_raster_scales = true; |
| 5301 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5302 | |
| 5303 | // Verify that the root layer and empty layers with touch/wheel handlers |
| 5304 | // (but not the empty layer without a touch handler) are in the RSSL. |
| 5305 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5306 | EXPECT_EQ(1, render_surface_layer_list[0]->id()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5307 | ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5308 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5309 | EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id()); |
| 5310 | EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5311 | |
| 5312 | // Hit testing for a point inside the empty no-handlers layer should return |
| 5313 | // the root layer. |
| 5314 | gfx::Point test_point = gfx::Point(15, 15); |
| 5315 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5316 | test_point, render_surface_layer_list); |
| 5317 | ASSERT_TRUE(result_layer); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5318 | EXPECT_EQ(1, result_layer->id()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5319 | |
| 5320 | // Hit testing for a point inside the touch handler layer should return it. |
| 5321 | test_point = gfx::Point(15, 75); |
| 5322 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5323 | test_point, render_surface_layer_list); |
| 5324 | ASSERT_TRUE(result_layer); |
| 5325 | EXPECT_EQ(3, result_layer->id()); |
| 5326 | |
| 5327 | // Hit testing for a point inside the mousewheel layer should return it. |
| 5328 | test_point = gfx::Point(75, 75); |
| 5329 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5330 | test_point, render_surface_layer_list); |
| 5331 | ASSERT_TRUE(result_layer); |
| 5332 | EXPECT_EQ(4, result_layer->id()); |
| 5333 | } |
| 5334 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5335 | TEST_F(LayerTreeHostCommonTest, |
| 5336 | HitCheckingTouchHandlerRegionsForEmptyLayerList) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5337 | // Hit checking on an empty render_surface_layer_list should return a null |
| 5338 | // pointer. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5339 | LayerImplList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5340 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5341 | gfx::Point test_point(0, 0); |
| 5342 | LayerImpl* result_layer = |
| 5343 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5344 | test_point, render_surface_layer_list); |
| 5345 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5346 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5347 | test_point = gfx::Point(10, 20); |
| 5348 | result_layer = |
| 5349 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5350 | test_point, render_surface_layer_list); |
| 5351 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5352 | } |
| 5353 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5354 | TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5355 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5356 | TestSharedBitmapManager shared_bitmap_manager; |
| 5357 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5358 | scoped_ptr<LayerImpl> root = |
| 5359 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5360 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5361 | gfx::Transform identity_matrix; |
| 5362 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5363 | gfx::PointF anchor; |
| 5364 | gfx::PointF position; |
| 5365 | gfx::Size bounds(100, 100); |
| 5366 | SetLayerPropertiesForTesting(root.get(), |
| 5367 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5368 | anchor, |
| 5369 | position, |
| 5370 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5371 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5372 | false); |
| 5373 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5374 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5375 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5376 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5377 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5378 | inputs.can_adjust_raster_scales = true; |
| 5379 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5380 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5381 | // Sanity check the scenario we just created. |
| 5382 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5383 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5384 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5385 | // Hit checking for any point should return a null pointer for a layer without |
| 5386 | // any touch event handler regions. |
| 5387 | gfx::Point test_point(11, 11); |
| 5388 | LayerImpl* result_layer = |
| 5389 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5390 | test_point, render_surface_layer_list); |
| 5391 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5392 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5393 | root->SetTouchEventHandlerRegion(touch_handler_region); |
| 5394 | // Hit checking for a point outside the layer should return a null pointer. |
| 5395 | test_point = gfx::Point(101, 101); |
| 5396 | result_layer = |
| 5397 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5398 | test_point, render_surface_layer_list); |
| 5399 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5400 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5401 | test_point = gfx::Point(-1, -1); |
| 5402 | result_layer = |
| 5403 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5404 | test_point, render_surface_layer_list); |
| 5405 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5406 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5407 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5408 | // region should return a null pointer. |
| 5409 | test_point = gfx::Point(1, 1); |
| 5410 | result_layer = |
| 5411 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5412 | test_point, render_surface_layer_list); |
| 5413 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5414 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5415 | test_point = gfx::Point(99, 99); |
| 5416 | result_layer = |
| 5417 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5418 | test_point, render_surface_layer_list); |
| 5419 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5420 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5421 | // Hit checking for a point inside the touch event handler region should |
| 5422 | // return the root layer. |
| 5423 | test_point = gfx::Point(11, 11); |
| 5424 | result_layer = |
| 5425 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5426 | test_point, render_surface_layer_list); |
| 5427 | ASSERT_TRUE(result_layer); |
| 5428 | EXPECT_EQ(12345, result_layer->id()); |
| 5429 | |
| 5430 | test_point = gfx::Point(59, 59); |
| 5431 | result_layer = |
| 5432 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5433 | test_point, render_surface_layer_list); |
| 5434 | ASSERT_TRUE(result_layer); |
| 5435 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5436 | } |
| 5437 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5438 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5439 | HitCheckingTouchHandlerRegionsForUninvertibleTransform) { |
| 5440 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5441 | TestSharedBitmapManager shared_bitmap_manager; |
| 5442 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5443 | scoped_ptr<LayerImpl> root = |
| 5444 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5445 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5446 | gfx::Transform uninvertible_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5447 | uninvertible_transform.matrix().set(0, 0, 0.0); |
| 5448 | uninvertible_transform.matrix().set(1, 1, 0.0); |
| 5449 | uninvertible_transform.matrix().set(2, 2, 0.0); |
| 5450 | uninvertible_transform.matrix().set(3, 3, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5451 | ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5452 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5453 | gfx::Transform identity_matrix; |
| 5454 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5455 | gfx::PointF anchor; |
| 5456 | gfx::PointF position; |
| 5457 | gfx::Size bounds(100, 100); |
| 5458 | SetLayerPropertiesForTesting(root.get(), |
| 5459 | uninvertible_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5460 | anchor, |
| 5461 | position, |
| 5462 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5463 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5464 | false); |
| 5465 | root->SetDrawsContent(true); |
| 5466 | root->SetTouchEventHandlerRegion(touch_handler_region); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5467 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5468 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5469 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5470 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5471 | inputs.can_adjust_raster_scales = true; |
| 5472 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5473 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5474 | // Sanity check the scenario we just created. |
| 5475 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5476 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5477 | ASSERT_FALSE(root->screen_space_transform().IsInvertible()); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5478 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5479 | // Hit checking any point should not hit the touch handler region on the |
| 5480 | // layer. If the invertible matrix is accidentally ignored and treated like an |
| 5481 | // identity, then the hit testing will incorrectly hit the layer when it |
| 5482 | // shouldn't. |
| 5483 | gfx::Point test_point(1, 1); |
| 5484 | LayerImpl* result_layer = |
| 5485 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5486 | test_point, render_surface_layer_list); |
| 5487 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5488 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5489 | test_point = gfx::Point(10, 10); |
| 5490 | result_layer = |
| 5491 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5492 | test_point, render_surface_layer_list); |
| 5493 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5494 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5495 | test_point = gfx::Point(10, 30); |
| 5496 | result_layer = |
| 5497 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5498 | test_point, render_surface_layer_list); |
| 5499 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5500 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5501 | test_point = gfx::Point(50, 50); |
| 5502 | result_layer = |
| 5503 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5504 | test_point, render_surface_layer_list); |
| 5505 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5506 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5507 | test_point = gfx::Point(67, 48); |
| 5508 | result_layer = |
| 5509 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5510 | test_point, render_surface_layer_list); |
| 5511 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5512 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5513 | test_point = gfx::Point(99, 99); |
| 5514 | result_layer = |
| 5515 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5516 | test_point, render_surface_layer_list); |
| 5517 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5518 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5519 | test_point = gfx::Point(-1, -1); |
| 5520 | result_layer = |
| 5521 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5522 | test_point, render_surface_layer_list); |
| 5523 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5524 | } |
| 5525 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5526 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5527 | HitCheckingTouchHandlerRegionsForSinglePositionedLayer) { |
| 5528 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5529 | TestSharedBitmapManager shared_bitmap_manager; |
| 5530 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5531 | scoped_ptr<LayerImpl> root = |
| 5532 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5533 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5534 | gfx::Transform identity_matrix; |
| 5535 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5536 | gfx::PointF anchor; |
| 5537 | // this layer is positioned, and hit testing should correctly know where the |
| 5538 | // layer is located. |
| 5539 | gfx::PointF position(50.f, 50.f); |
| 5540 | gfx::Size bounds(100, 100); |
| 5541 | SetLayerPropertiesForTesting(root.get(), |
| 5542 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5543 | anchor, |
| 5544 | position, |
| 5545 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5546 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5547 | false); |
| 5548 | root->SetDrawsContent(true); |
| 5549 | root->SetTouchEventHandlerRegion(touch_handler_region); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5550 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5551 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5552 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5553 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5554 | inputs.can_adjust_raster_scales = true; |
| 5555 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5556 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5557 | // Sanity check the scenario we just created. |
| 5558 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5559 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5560 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5561 | // Hit checking for a point outside the layer should return a null pointer. |
| 5562 | gfx::Point test_point(49, 49); |
| 5563 | LayerImpl* result_layer = |
| 5564 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5565 | test_point, render_surface_layer_list); |
| 5566 | EXPECT_FALSE(result_layer); |
| 5567 | |
| 5568 | // Even though the layer has a touch handler region containing (101, 101), it |
| 5569 | // should not be visible there since the root render surface would clamp it. |
| 5570 | test_point = gfx::Point(101, 101); |
| 5571 | result_layer = |
| 5572 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5573 | test_point, render_surface_layer_list); |
| 5574 | EXPECT_FALSE(result_layer); |
| 5575 | |
| 5576 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5577 | // region should return a null pointer. |
| 5578 | test_point = gfx::Point(51, 51); |
| 5579 | result_layer = |
| 5580 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5581 | test_point, render_surface_layer_list); |
| 5582 | EXPECT_FALSE(result_layer); |
| 5583 | |
| 5584 | // Hit checking for a point inside the touch event handler region should |
| 5585 | // return the root layer. |
| 5586 | test_point = gfx::Point(61, 61); |
| 5587 | result_layer = |
| 5588 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5589 | test_point, render_surface_layer_list); |
| 5590 | ASSERT_TRUE(result_layer); |
| 5591 | EXPECT_EQ(12345, result_layer->id()); |
| 5592 | |
| 5593 | test_point = gfx::Point(99, 99); |
| 5594 | result_layer = |
| 5595 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5596 | test_point, render_surface_layer_list); |
| 5597 | ASSERT_TRUE(result_layer); |
| 5598 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5599 | } |
| 5600 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5601 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5602 | HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) { |
| 5603 | // A layer's visible content rect is actually in the layer's content space. |
| 5604 | // The screen space transform converts from the layer's origin space to screen |
| 5605 | // space. This test makes sure that hit testing works correctly accounts for |
| 5606 | // the contents scale. A contents scale that is not 1 effectively forces a |
| 5607 | // non-identity transform between layer's content space and layer's origin |
| 5608 | // space. The hit testing code must take this into account. |
| 5609 | // |
| 5610 | // To test this, the layer is positioned at (25, 25), and is size (50, 50). If |
| 5611 | // contents scale is ignored, then hit checking will mis-interpret the visible |
| 5612 | // content rect as being larger than the actual bounds of the layer. |
| 5613 | // |
| 5614 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5615 | TestSharedBitmapManager shared_bitmap_manager; |
| 5616 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5617 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5618 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5619 | gfx::Transform identity_matrix; |
| 5620 | gfx::PointF anchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5621 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5622 | SetLayerPropertiesForTesting(root.get(), |
| 5623 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5624 | anchor, |
| 5625 | gfx::PointF(), |
| 5626 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5627 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5628 | false); |
| 5629 | { |
| 5630 | Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); |
| 5631 | gfx::PointF position(25.f, 25.f); |
| 5632 | gfx::Size bounds(50, 50); |
| 5633 | scoped_ptr<LayerImpl> test_layer = |
| 5634 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 5635 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5636 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5637 | anchor, |
| 5638 | position, |
| 5639 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5640 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5641 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5642 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5643 | // override content bounds and contents scale |
| 5644 | test_layer->SetContentBounds(gfx::Size(100, 100)); |
| 5645 | test_layer->SetContentsScale(2, 2); |
[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_layer->SetDrawsContent(true); |
| 5648 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5649 | root->AddChild(test_layer.Pass()); |
| 5650 | } |
| 5651 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5652 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5653 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5654 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5655 | inputs.can_adjust_raster_scales = true; |
| 5656 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5657 | |
| 5658 | // Sanity check the scenario we just created. |
| 5659 | // The visible content rect for test_layer is actually 100x100, even though |
| 5660 | // its layout size is 50x50, positioned at 25x25. |
| 5661 | LayerImpl* test_layer = root->children()[0]; |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 5662 | 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] | 5663 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5664 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5665 | |
| 5666 | // Hit checking for a point outside the layer should return a null pointer |
| 5667 | // (the root layer does not draw content, so it will not be tested either). |
| 5668 | gfx::Point test_point(76, 76); |
| 5669 | LayerImpl* result_layer = |
| 5670 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5671 | test_point, render_surface_layer_list); |
| 5672 | EXPECT_FALSE(result_layer); |
| 5673 | |
| 5674 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5675 | // region should return a null pointer. |
| 5676 | test_point = gfx::Point(26, 26); |
| 5677 | result_layer = |
| 5678 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5679 | test_point, render_surface_layer_list); |
| 5680 | EXPECT_FALSE(result_layer); |
| 5681 | |
| 5682 | test_point = gfx::Point(34, 34); |
| 5683 | result_layer = |
| 5684 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5685 | test_point, render_surface_layer_list); |
| 5686 | EXPECT_FALSE(result_layer); |
| 5687 | |
| 5688 | test_point = gfx::Point(65, 65); |
| 5689 | result_layer = |
| 5690 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5691 | test_point, render_surface_layer_list); |
| 5692 | EXPECT_FALSE(result_layer); |
| 5693 | |
| 5694 | test_point = gfx::Point(74, 74); |
| 5695 | result_layer = |
| 5696 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5697 | test_point, render_surface_layer_list); |
| 5698 | EXPECT_FALSE(result_layer); |
| 5699 | |
| 5700 | // Hit checking for a point inside the touch event handler region should |
| 5701 | // return the root layer. |
| 5702 | test_point = gfx::Point(35, 35); |
| 5703 | result_layer = |
| 5704 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5705 | test_point, render_surface_layer_list); |
| 5706 | ASSERT_TRUE(result_layer); |
| 5707 | EXPECT_EQ(12345, result_layer->id()); |
| 5708 | |
| 5709 | test_point = gfx::Point(64, 64); |
| 5710 | result_layer = |
| 5711 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5712 | test_point, render_surface_layer_list); |
| 5713 | ASSERT_TRUE(result_layer); |
| 5714 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5715 | } |
| 5716 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5717 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5718 | HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) { |
| 5719 | // The layer's device_scale_factor and page_scale_factor should scale the |
| 5720 | // content rect and we should be able to hit the touch handler region by |
| 5721 | // scaling the points accordingly. |
| 5722 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5723 | TestSharedBitmapManager shared_bitmap_manager; |
| 5724 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5725 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5726 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5727 | gfx::Transform identity_matrix; |
| 5728 | gfx::PointF anchor; |
| 5729 | // Set the bounds of the root layer big enough to fit the child when scaled. |
| 5730 | SetLayerPropertiesForTesting(root.get(), |
| 5731 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5732 | anchor, |
| 5733 | gfx::PointF(), |
| 5734 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5735 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5736 | false); |
| 5737 | { |
| 5738 | Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); |
| 5739 | gfx::PointF position(25.f, 25.f); |
| 5740 | gfx::Size bounds(50, 50); |
| 5741 | scoped_ptr<LayerImpl> test_layer = |
| 5742 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 5743 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5744 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5745 | anchor, |
| 5746 | position, |
| 5747 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5748 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5749 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5750 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5751 | test_layer->SetDrawsContent(true); |
| 5752 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5753 | root->AddChild(test_layer.Pass()); |
| 5754 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5755 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5756 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5757 | float device_scale_factor = 3.f; |
| 5758 | float page_scale_factor = 5.f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5759 | gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize( |
| 5760 | gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor)); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5761 | |
| 5762 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5763 | root.get(), scaled_bounds_for_root, &render_surface_layer_list); |
| 5764 | inputs.device_scale_factor = device_scale_factor; |
| 5765 | inputs.page_scale_factor = page_scale_factor; |
| 5766 | inputs.page_scale_application_layer = root.get(); |
| 5767 | inputs.can_adjust_raster_scales = true; |
| 5768 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5769 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5770 | // Sanity check the scenario we just created. |
| 5771 | // The visible content rect for test_layer is actually 100x100, even though |
| 5772 | // its layout size is 50x50, positioned at 25x25. |
| 5773 | LayerImpl* test_layer = root->children()[0]; |
| 5774 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5775 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5776 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5777 | // Check whether the child layer fits into the root after scaled. |
| 5778 | EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()), |
| 5779 | test_layer->visible_content_rect()); |
| 5780 | |
| 5781 | // Hit checking for a point outside the layer should return a null pointer |
| 5782 | // (the root layer does not draw content, so it will not be tested either). |
| 5783 | gfx::PointF test_point(76.f, 76.f); |
| 5784 | test_point = |
| 5785 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5786 | LayerImpl* result_layer = |
| 5787 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5788 | test_point, render_surface_layer_list); |
| 5789 | EXPECT_FALSE(result_layer); |
| 5790 | |
| 5791 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5792 | // region should return a null pointer. |
| 5793 | test_point = gfx::Point(26, 26); |
| 5794 | test_point = |
| 5795 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5796 | result_layer = |
| 5797 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5798 | test_point, render_surface_layer_list); |
| 5799 | EXPECT_FALSE(result_layer); |
| 5800 | |
| 5801 | test_point = gfx::Point(34, 34); |
| 5802 | test_point = |
| 5803 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5804 | result_layer = |
| 5805 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5806 | test_point, render_surface_layer_list); |
| 5807 | EXPECT_FALSE(result_layer); |
| 5808 | |
| 5809 | test_point = gfx::Point(65, 65); |
| 5810 | test_point = |
| 5811 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5812 | result_layer = |
| 5813 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5814 | test_point, render_surface_layer_list); |
| 5815 | EXPECT_FALSE(result_layer); |
| 5816 | |
| 5817 | test_point = gfx::Point(74, 74); |
| 5818 | test_point = |
| 5819 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5820 | result_layer = |
| 5821 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5822 | test_point, render_surface_layer_list); |
| 5823 | EXPECT_FALSE(result_layer); |
| 5824 | |
| 5825 | // Hit checking for a point inside the touch event handler region should |
| 5826 | // return the root layer. |
| 5827 | test_point = gfx::Point(35, 35); |
| 5828 | test_point = |
| 5829 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5830 | result_layer = |
| 5831 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5832 | test_point, render_surface_layer_list); |
| 5833 | ASSERT_TRUE(result_layer); |
| 5834 | EXPECT_EQ(12345, result_layer->id()); |
| 5835 | |
| 5836 | test_point = gfx::Point(64, 64); |
| 5837 | test_point = |
| 5838 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5839 | result_layer = |
| 5840 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5841 | test_point, render_surface_layer_list); |
| 5842 | ASSERT_TRUE(result_layer); |
| 5843 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5844 | } |
| 5845 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5846 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5847 | HitCheckingTouchHandlerRegionsForSimpleClippedLayer) { |
| 5848 | // Test that hit-checking will only work for the visible portion of a layer, |
| 5849 | // and not the entire layer bounds. Here we just test the simple axis-aligned |
| 5850 | // case. |
| 5851 | gfx::Transform identity_matrix; |
| 5852 | gfx::PointF anchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5853 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5854 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5855 | TestSharedBitmapManager shared_bitmap_manager; |
| 5856 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5857 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 5858 | SetLayerPropertiesForTesting(root.get(), |
| 5859 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5860 | anchor, |
| 5861 | gfx::PointF(), |
| 5862 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5863 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5864 | false); |
| 5865 | { |
| 5866 | scoped_ptr<LayerImpl> clipping_layer = |
| 5867 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 5868 | // this layer is positioned, and hit testing should correctly know where the |
| 5869 | // layer is located. |
| 5870 | gfx::PointF position(25.f, 25.f); |
| 5871 | gfx::Size bounds(50, 50); |
| 5872 | SetLayerPropertiesForTesting(clipping_layer.get(), |
| 5873 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5874 | anchor, |
| 5875 | position, |
| 5876 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5877 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5878 | false); |
| 5879 | clipping_layer->SetMasksToBounds(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5880 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5881 | scoped_ptr<LayerImpl> child = |
| 5882 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 5883 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5884 | position = gfx::PointF(-50.f, -50.f); |
| 5885 | bounds = gfx::Size(300, 300); |
| 5886 | SetLayerPropertiesForTesting(child.get(), |
| 5887 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5888 | anchor, |
| 5889 | position, |
| 5890 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5891 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5892 | false); |
| 5893 | child->SetDrawsContent(true); |
| 5894 | child->SetTouchEventHandlerRegion(touch_handler_region); |
| 5895 | clipping_layer->AddChild(child.Pass()); |
| 5896 | root->AddChild(clipping_layer.Pass()); |
| 5897 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5898 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5899 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5900 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5901 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5902 | inputs.can_adjust_raster_scales = true; |
| 5903 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5904 | |
| 5905 | // Sanity check the scenario we just created. |
| 5906 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5907 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5908 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5909 | |
| 5910 | // Hit checking for a point outside the layer should return a null pointer. |
| 5911 | // Despite the child layer being very large, it should be clipped to the root |
| 5912 | // layer's bounds. |
| 5913 | gfx::Point test_point(24, 24); |
| 5914 | LayerImpl* result_layer = |
| 5915 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5916 | test_point, render_surface_layer_list); |
| 5917 | EXPECT_FALSE(result_layer); |
| 5918 | |
| 5919 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5920 | // region should return a null pointer. |
| 5921 | test_point = gfx::Point(35, 35); |
| 5922 | result_layer = |
| 5923 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5924 | test_point, render_surface_layer_list); |
| 5925 | EXPECT_FALSE(result_layer); |
| 5926 | |
| 5927 | test_point = gfx::Point(74, 74); |
| 5928 | 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 touch event handler region should |
| 5934 | // return the root layer. |
| 5935 | test_point = gfx::Point(25, 25); |
| 5936 | result_layer = |
| 5937 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5938 | test_point, render_surface_layer_list); |
| 5939 | ASSERT_TRUE(result_layer); |
| 5940 | EXPECT_EQ(456, result_layer->id()); |
| 5941 | |
| 5942 | test_point = gfx::Point(34, 34); |
| 5943 | result_layer = |
| 5944 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5945 | test_point, render_surface_layer_list); |
| 5946 | ASSERT_TRUE(result_layer); |
| 5947 | EXPECT_EQ(456, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5948 | } |
| 5949 | |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5950 | TEST_F(LayerTreeHostCommonTest, |
| 5951 | HitCheckingTouchHandlerOverlappingRegions) { |
| 5952 | gfx::Transform identity_matrix; |
| 5953 | gfx::PointF anchor; |
| 5954 | |
| 5955 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5956 | TestSharedBitmapManager shared_bitmap_manager; |
| 5957 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5958 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 5959 | SetLayerPropertiesForTesting(root.get(), |
| 5960 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5961 | anchor, |
| 5962 | gfx::PointF(), |
| 5963 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5964 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5965 | false); |
| 5966 | { |
| 5967 | scoped_ptr<LayerImpl> touch_layer = |
| 5968 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 5969 | // this layer is positioned, and hit testing should correctly know where the |
| 5970 | // layer is located. |
| 5971 | gfx::PointF position; |
| 5972 | gfx::Size bounds(50, 50); |
| 5973 | SetLayerPropertiesForTesting(touch_layer.get(), |
| 5974 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5975 | anchor, |
| 5976 | position, |
| 5977 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5978 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5979 | false); |
| 5980 | touch_layer->SetDrawsContent(true); |
| 5981 | touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); |
| 5982 | root->AddChild(touch_layer.Pass()); |
| 5983 | } |
| 5984 | |
| 5985 | { |
| 5986 | scoped_ptr<LayerImpl> notouch_layer = |
| 5987 | LayerImpl::Create(host_impl.active_tree(), 1234); |
| 5988 | // this layer is positioned, and hit testing should correctly know where the |
| 5989 | // layer is located. |
| 5990 | gfx::PointF position(0, 25); |
| 5991 | gfx::Size bounds(50, 50); |
| 5992 | SetLayerPropertiesForTesting(notouch_layer.get(), |
| 5993 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5994 | anchor, |
| 5995 | position, |
| 5996 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5997 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5998 | false); |
| 5999 | notouch_layer->SetDrawsContent(true); |
| 6000 | root->AddChild(notouch_layer.Pass()); |
| 6001 | } |
| 6002 | |
| 6003 | LayerImplList render_surface_layer_list; |
| 6004 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 6005 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6006 | inputs.can_adjust_raster_scales = true; |
| 6007 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6008 | |
| 6009 | // Sanity check the scenario we just created. |
| 6010 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 6011 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 6012 | ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id()); |
| 6013 | ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6014 | |
| 6015 | gfx::Point test_point(35, 35); |
| 6016 | LayerImpl* result_layer = |
| 6017 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6018 | test_point, render_surface_layer_list); |
| 6019 | EXPECT_FALSE(result_layer); |
| 6020 | |
| 6021 | test_point = gfx::Point(35, 15); |
| 6022 | result_layer = |
| 6023 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6024 | test_point, render_surface_layer_list); |
| 6025 | ASSERT_TRUE(result_layer); |
| 6026 | EXPECT_EQ(123, result_layer->id()); |
| 6027 | |
| 6028 | test_point = gfx::Point(35, 65); |
| 6029 | result_layer = |
| 6030 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6031 | test_point, render_surface_layer_list); |
| 6032 | EXPECT_FALSE(result_layer); |
| 6033 | } |
| 6034 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6035 | class NoScaleContentLayer : public ContentLayer { |
| 6036 | public: |
| 6037 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 6038 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 6039 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6040 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6041 | virtual void CalculateContentsScale(float ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 6042 | float device_scale_factor, |
| 6043 | float page_scale_factor, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6044 | bool animating_transform_to_screen, |
| 6045 | float* contents_scale_x, |
| 6046 | float* contents_scale_y, |
| 6047 | gfx::Size* content_bounds) OVERRIDE { |
| 6048 | // Skip over the ContentLayer to the base Layer class. |
| 6049 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 6050 | device_scale_factor, |
| 6051 | page_scale_factor, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6052 | animating_transform_to_screen, |
| 6053 | contents_scale_x, |
| 6054 | contents_scale_y, |
| 6055 | content_bounds); |
| 6056 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6057 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6058 | protected: |
| 6059 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 6060 | : ContentLayer(client) {} |
| 6061 | virtual ~NoScaleContentLayer() {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6062 | }; |
| 6063 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6064 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 6065 | ContentLayerClient* delegate) { |
| 6066 | scoped_refptr<NoScaleContentLayer> to_return = |
| 6067 | NoScaleContentLayer::Create(delegate); |
| 6068 | to_return->SetIsDrawable(true); |
| 6069 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6070 | } |
| 6071 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6072 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6073 | // Verify draw and screen space transforms of layers not in a surface. |
| 6074 | MockContentLayerClient delegate; |
| 6075 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6076 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6077 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6078 | SetLayerPropertiesForTesting(parent.get(), |
| 6079 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6080 | gfx::PointF(), |
| 6081 | gfx::PointF(), |
| 6082 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6083 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6084 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6085 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6086 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 6087 | SetLayerPropertiesForTesting(child.get(), |
| 6088 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6089 | gfx::PointF(), |
| 6090 | gfx::PointF(2.f, 2.f), |
| 6091 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6092 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6093 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6094 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6095 | scoped_refptr<ContentLayer> child_empty = |
| 6096 | CreateDrawableContentLayer(&delegate); |
| 6097 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6098 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6099 | gfx::PointF(), |
| 6100 | gfx::PointF(2.f, 2.f), |
| 6101 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6102 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6103 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6104 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6105 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6106 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6107 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6108 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6109 | gfx::PointF(), |
| 6110 | gfx::PointF(2.f, 2.f), |
| 6111 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6112 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6113 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6114 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6115 | parent->AddChild(child); |
| 6116 | parent->AddChild(child_empty); |
| 6117 | parent->AddChild(child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6118 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6119 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6120 | host->SetRootLayer(parent); |
| 6121 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6122 | float device_scale_factor = 2.5f; |
| 6123 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6124 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6125 | RenderSurfaceLayerList render_surface_layer_list; |
| 6126 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6127 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 6128 | inputs.device_scale_factor = device_scale_factor; |
| 6129 | inputs.page_scale_factor = page_scale_factor; |
| 6130 | inputs.can_adjust_raster_scales = true; |
| 6131 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6132 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6133 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6134 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 6135 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6136 | child_empty); |
| 6137 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6138 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6139 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6140 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6141 | // Verify parent transforms |
| 6142 | gfx::Transform expected_parent_transform; |
| 6143 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6144 | parent->screen_space_transform()); |
| 6145 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6146 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6147 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6148 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6149 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6150 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6151 | gfx::RectF parent_draw_rect = |
| 6152 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 6153 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 6154 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6155 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6156 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6157 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 6158 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 6159 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6160 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6161 | // Verify child and child_empty transforms. They should match. |
| 6162 | gfx::Transform expected_child_transform; |
| 6163 | expected_child_transform.Translate( |
| 6164 | device_scale_factor * child->position().x(), |
| 6165 | device_scale_factor * child->position().y()); |
| 6166 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6167 | child->draw_transform()); |
| 6168 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6169 | child->screen_space_transform()); |
| 6170 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6171 | child_empty->draw_transform()); |
| 6172 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6173 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6174 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6175 | // Verify results of transformed child and child_empty rects. They should |
| 6176 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6177 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6178 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6179 | gfx::RectF child_draw_rect = |
| 6180 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 6181 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 6182 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6183 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6184 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 6185 | child_empty->draw_transform(), child_content_bounds); |
| 6186 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 6187 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6188 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6189 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 6190 | expected_child_draw_rect.Scale(device_scale_factor); |
| 6191 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 6192 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 6193 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 6194 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6195 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6196 | // Verify child_no_scale transforms |
| 6197 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 6198 | // All transforms operate on content rects. The child's content rect |
| 6199 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 6200 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 6201 | device_scale_factor); |
| 6202 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6203 | child_no_scale->draw_transform()); |
| 6204 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6205 | child_no_scale->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6206 | } |
| 6207 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6208 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6209 | // Verify draw and screen space transforms of layers in a surface. |
| 6210 | MockContentLayerClient delegate; |
| 6211 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6212 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6213 | gfx::Transform perspective_matrix; |
| 6214 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6215 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6216 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 6217 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6218 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 6219 | scoped_refptr<Layer> root = Layer::Create(); |
| 6220 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6221 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6222 | SetLayerPropertiesForTesting(parent.get(), |
| 6223 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6224 | gfx::PointF(), |
| 6225 | gfx::PointF(), |
| 6226 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6227 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6228 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6229 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6230 | scoped_refptr<ContentLayer> perspective_surface = |
| 6231 | CreateDrawableContentLayer(&delegate); |
| 6232 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 6233 | perspective_matrix * scale_small_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6234 | gfx::PointF(), |
| 6235 | gfx::PointF(2.f, 2.f), |
| 6236 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6237 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6238 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6239 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6240 | scoped_refptr<ContentLayer> scale_surface = |
| 6241 | CreateDrawableContentLayer(&delegate); |
| 6242 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 6243 | scale_small_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6244 | gfx::PointF(), |
| 6245 | gfx::PointF(2.f, 2.f), |
| 6246 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6247 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6248 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6249 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6250 | perspective_surface->SetForceRenderSurface(true); |
| 6251 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6252 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6253 | parent->AddChild(perspective_surface); |
| 6254 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 6255 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6256 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6257 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6258 | host->SetRootLayer(root); |
| 6259 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6260 | float device_scale_factor = 2.5f; |
| 6261 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6262 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6263 | RenderSurfaceLayerList render_surface_layer_list; |
| 6264 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6265 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 6266 | inputs.device_scale_factor = device_scale_factor; |
| 6267 | inputs.page_scale_factor = page_scale_factor; |
| 6268 | inputs.page_scale_application_layer = root; |
| 6269 | inputs.can_adjust_raster_scales = true; |
| 6270 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6272 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6273 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6274 | perspective_surface); |
| 6275 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6276 | scale_surface); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6277 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6278 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6279 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6280 | gfx::Transform expected_parent_draw_transform; |
| 6281 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 6282 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6283 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6284 | // The scaled surface is rendered at its appropriate scale, and drawn 1:1 |
| 6285 | // into its target. |
| 6286 | gfx::Transform expected_scale_surface_draw_transform; |
| 6287 | expected_scale_surface_draw_transform.Translate( |
| 6288 | device_scale_factor * page_scale_factor * scale_surface->position().x(), |
| 6289 | device_scale_factor * page_scale_factor * scale_surface->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6290 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6291 | expected_scale_surface_draw_transform, |
| 6292 | scale_surface->render_surface()->draw_transform()); |
[email protected] | a52c6ff | 2013-05-04 05:33:15 | [diff] [blame] | 6293 | gfx::Transform expected_scale_surface_layer_draw_transform = |
| 6294 | scale_small_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6295 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform, |
| 6296 | scale_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6297 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6298 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 6299 | // with the screen, and then scaled during drawing. |
| 6300 | gfx::Transform expected_perspective_surface_draw_transform; |
| 6301 | expected_perspective_surface_draw_transform.Translate( |
| 6302 | device_scale_factor * page_scale_factor * |
| 6303 | perspective_surface->position().x(), |
| 6304 | device_scale_factor * page_scale_factor * |
| 6305 | perspective_surface->position().y()); |
| 6306 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 6307 | perspective_matrix); |
| 6308 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 6309 | scale_small_matrix); |
| 6310 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
| 6311 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6312 | expected_perspective_surface_draw_transform, |
| 6313 | perspective_surface->render_surface()->draw_transform()); |
| 6314 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6315 | expected_perspective_surface_layer_draw_transform, |
| 6316 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6317 | } |
| 6318 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6319 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6320 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 6321 | // Verify draw and screen space transforms of layers not in a surface. |
| 6322 | MockContentLayerClient delegate; |
| 6323 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6324 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6325 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6326 | SetLayerPropertiesForTesting(parent.get(), |
| 6327 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6328 | gfx::PointF(), |
| 6329 | gfx::PointF(), |
| 6330 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6331 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6332 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6333 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6334 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 6335 | SetLayerPropertiesForTesting(child.get(), |
| 6336 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6337 | gfx::PointF(), |
| 6338 | gfx::PointF(), |
| 6339 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6340 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6341 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6342 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6343 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6344 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6345 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6346 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6347 | gfx::PointF(), |
| 6348 | gfx::PointF(), |
| 6349 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6350 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6351 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6352 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6353 | parent->AddChild(child); |
| 6354 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6355 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6356 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6357 | host->SetRootLayer(parent); |
| 6358 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6359 | float device_scale_factor = 1.7f; |
| 6360 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6361 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6362 | RenderSurfaceLayerList render_surface_layer_list; |
| 6363 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6364 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 6365 | inputs.device_scale_factor = device_scale_factor; |
| 6366 | inputs.page_scale_factor = page_scale_factor; |
| 6367 | inputs.page_scale_application_layer = parent.get(); |
| 6368 | inputs.can_adjust_raster_scales = true; |
| 6369 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6370 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6371 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6372 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 6373 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6374 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6375 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6376 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6377 | // Verify parent transforms |
| 6378 | gfx::Transform expected_parent_transform; |
| 6379 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6380 | parent->screen_space_transform()); |
| 6381 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6382 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6383 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6384 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6385 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6386 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6387 | gfx::RectF parent_draw_rect = |
| 6388 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 6389 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 6390 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6391 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6392 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6393 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 6394 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 6395 | expected_parent_draw_rect.set_height( |
| 6396 | ceil(expected_parent_draw_rect.height())); |
| 6397 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 6398 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6399 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6400 | // Verify child transforms |
| 6401 | gfx::Transform expected_child_transform; |
| 6402 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6403 | child->draw_transform()); |
| 6404 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6405 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6406 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6407 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6408 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6409 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6410 | gfx::RectF child_draw_rect = |
| 6411 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 6412 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 6413 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6414 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6415 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6416 | expected_child_draw_rect.Scale(device_scale_factor); |
| 6417 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 6418 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 6419 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 6420 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6421 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6422 | // Verify child_no_scale transforms |
| 6423 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 6424 | // All transforms operate on content rects. The child's content rect |
| 6425 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 6426 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 6427 | device_scale_factor); |
| 6428 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6429 | child_no_scale->draw_transform()); |
| 6430 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6431 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6432 | } |
| 6433 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6434 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6435 | MockContentLayerClient delegate; |
| 6436 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6437 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6438 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6439 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6440 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6441 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6442 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6443 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6444 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6445 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6446 | scoped_refptr<Layer> root = Layer::Create(); |
| 6447 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6448 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6449 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6450 | SetLayerPropertiesForTesting(parent.get(), |
| 6451 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6452 | gfx::PointF(), |
| 6453 | gfx::PointF(), |
| 6454 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6455 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6456 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6457 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6458 | scoped_refptr<ContentLayer> child_scale = |
| 6459 | CreateDrawableContentLayer(&delegate); |
| 6460 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6461 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6462 | gfx::PointF(), |
| 6463 | gfx::PointF(2.f, 2.f), |
| 6464 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6465 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6466 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6467 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6468 | scoped_refptr<ContentLayer> child_empty = |
| 6469 | CreateDrawableContentLayer(&delegate); |
| 6470 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6471 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6472 | gfx::PointF(), |
| 6473 | gfx::PointF(2.f, 2.f), |
| 6474 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6475 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6476 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6477 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6478 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6479 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6480 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6481 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6482 | gfx::PointF(), |
| 6483 | gfx::PointF(12.f, 12.f), |
| 6484 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6485 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6486 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6487 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6488 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6489 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6490 | parent->AddChild(child_scale); |
| 6491 | parent->AddChild(child_empty); |
| 6492 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6493 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6494 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6495 | host->SetRootLayer(root); |
| 6496 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6497 | float device_scale_factor = 2.5f; |
| 6498 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6499 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6500 | { |
| 6501 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6502 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6503 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6504 | inputs.device_scale_factor = device_scale_factor; |
| 6505 | inputs.page_scale_factor = page_scale_factor; |
| 6506 | inputs.page_scale_application_layer = root.get(); |
| 6507 | inputs.can_adjust_raster_scales = true; |
| 6508 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6509 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6510 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6511 | initial_parent_scale, parent); |
| 6512 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6513 | initial_parent_scale * initial_child_scale, |
| 6514 | child_scale); |
| 6515 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6516 | initial_parent_scale * initial_child_scale, |
| 6517 | child_empty); |
| 6518 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6519 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6520 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 6521 | // child that can scale its contents should also not need to scale during |
| 6522 | // draw. This shouldn't change if the child has empty bounds. The other |
| 6523 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6524 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 6525 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 6526 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 6527 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 6528 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 6529 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6530 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 6531 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6532 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6533 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6534 | initial_parent_scale * initial_child_scale, |
| 6535 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6536 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6537 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6538 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 6539 | // updated using the initial transform as the raster scale. |
| 6540 | device_scale_factor = 2.25f; |
| 6541 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6542 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6543 | { |
| 6544 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6545 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6546 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6547 | inputs.device_scale_factor = device_scale_factor; |
| 6548 | inputs.page_scale_factor = page_scale_factor; |
| 6549 | inputs.page_scale_application_layer = root.get(); |
| 6550 | inputs.can_adjust_raster_scales = true; |
| 6551 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6552 | |
| 6553 | EXPECT_CONTENTS_SCALE_EQ( |
| 6554 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6555 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6556 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6557 | child_scale); |
| 6558 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6559 | initial_parent_scale * initial_child_scale, |
| 6560 | child_empty); |
| 6561 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6562 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6563 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6564 | // If the transform changes, we expect the raster scale to be reset to 1.0. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6565 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6566 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 6567 | second_child_scale / initial_child_scale); |
| 6568 | child_scale->SetTransform(child_scale_matrix); |
| 6569 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6570 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6571 | { |
| 6572 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6573 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6574 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6575 | inputs.device_scale_factor = device_scale_factor; |
| 6576 | inputs.page_scale_factor = page_scale_factor; |
| 6577 | inputs.page_scale_application_layer = root.get(); |
| 6578 | inputs.can_adjust_raster_scales = true; |
| 6579 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6580 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6581 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6582 | initial_parent_scale, |
| 6583 | parent); |
| 6584 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6585 | child_scale); |
| 6586 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6587 | child_empty); |
| 6588 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6589 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6590 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6591 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 6592 | // updated, but still using 1.0 as the raster scale. |
| 6593 | device_scale_factor = 2.75f; |
| 6594 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6595 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6596 | { |
| 6597 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6598 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6599 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6600 | inputs.device_scale_factor = device_scale_factor; |
| 6601 | inputs.page_scale_factor = page_scale_factor; |
| 6602 | inputs.page_scale_application_layer = root.get(); |
| 6603 | inputs.can_adjust_raster_scales = true; |
| 6604 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6605 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6606 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6607 | initial_parent_scale, |
| 6608 | parent); |
| 6609 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6610 | child_scale); |
| 6611 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6612 | child_empty); |
| 6613 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6614 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6615 | } |
| 6616 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6617 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6618 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6619 | MockContentLayerClient delegate; |
| 6620 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6621 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6622 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6623 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6624 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6625 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6626 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6627 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6628 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6629 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6630 | scoped_refptr<Layer> root = Layer::Create(); |
| 6631 | root->SetBounds(gfx::Size(100, 100)); |
| 6632 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6633 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6634 | SetLayerPropertiesForTesting(parent.get(), |
| 6635 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6636 | gfx::PointF(), |
| 6637 | gfx::PointF(), |
| 6638 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6639 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6640 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6641 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6642 | scoped_refptr<ContentLayer> child_scale = |
| 6643 | CreateDrawableContentLayer(&delegate); |
| 6644 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6645 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6646 | gfx::PointF(), |
| 6647 | gfx::PointF(2.f, 2.f), |
| 6648 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6649 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6650 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6651 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6652 | scoped_refptr<ContentLayer> child_empty = |
| 6653 | CreateDrawableContentLayer(&delegate); |
| 6654 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6655 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6656 | gfx::PointF(), |
| 6657 | gfx::PointF(2.f, 2.f), |
| 6658 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6659 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6660 | true); |
| 6661 | |
| 6662 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6663 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6664 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6665 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6666 | gfx::PointF(), |
| 6667 | gfx::PointF(12.f, 12.f), |
| 6668 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6669 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6670 | true); |
| 6671 | |
| 6672 | root->AddChild(parent); |
| 6673 | |
| 6674 | parent->AddChild(child_scale); |
| 6675 | parent->AddChild(child_empty); |
| 6676 | parent->AddChild(child_no_scale); |
| 6677 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6678 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6679 | host->SetRootLayer(root); |
| 6680 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6681 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6682 | |
| 6683 | float device_scale_factor = 2.5f; |
| 6684 | float page_scale_factor = 1.f; |
| 6685 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6686 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6687 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6688 | inputs.device_scale_factor = device_scale_factor; |
| 6689 | inputs.page_scale_factor = page_scale_factor; |
| 6690 | inputs.page_scale_application_layer = root.get(), |
| 6691 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6692 | |
| 6693 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6694 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6695 | child_scale); |
| 6696 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6697 | child_empty); |
| 6698 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6699 | |
| 6700 | // Since the transform scale does not affect contents scale, it should affect |
| 6701 | // the draw transform instead. |
| 6702 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6703 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6704 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6705 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6706 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6707 | child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6708 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6709 | child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6710 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6711 | child_empty->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6712 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6713 | child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6714 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6715 | initial_parent_scale * initial_child_scale, |
| 6716 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6717 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6718 | initial_parent_scale * initial_child_scale, |
| 6719 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6720 | } |
| 6721 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6722 | TEST_F(LayerTreeHostCommonTest, SmallContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6723 | MockContentLayerClient delegate; |
| 6724 | gfx::Transform identity_matrix; |
| 6725 | |
| 6726 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6727 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6728 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 6729 | |
| 6730 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6731 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6732 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 6733 | |
| 6734 | scoped_refptr<Layer> root = Layer::Create(); |
| 6735 | root->SetBounds(gfx::Size(100, 100)); |
| 6736 | |
| 6737 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6738 | SetLayerPropertiesForTesting(parent.get(), |
| 6739 | parent_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6740 | gfx::PointF(), |
| 6741 | gfx::PointF(), |
| 6742 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6743 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6744 | true); |
| 6745 | |
| 6746 | scoped_refptr<ContentLayer> child_scale = |
| 6747 | CreateDrawableContentLayer(&delegate); |
| 6748 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6749 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6750 | gfx::PointF(), |
| 6751 | gfx::PointF(2.f, 2.f), |
| 6752 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6753 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6754 | true); |
| 6755 | |
| 6756 | root->AddChild(parent); |
| 6757 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6758 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6759 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6760 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6761 | host->SetRootLayer(root); |
| 6762 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6763 | float device_scale_factor = 2.5f; |
| 6764 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6765 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6766 | { |
| 6767 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6768 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6769 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6770 | inputs.device_scale_factor = device_scale_factor; |
| 6771 | inputs.page_scale_factor = page_scale_factor; |
| 6772 | inputs.page_scale_application_layer = root.get(); |
| 6773 | inputs.can_adjust_raster_scales = true; |
| 6774 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6775 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6776 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6777 | initial_parent_scale, |
| 6778 | parent); |
| 6779 | // The child's scale is < 1, so we should not save and use that scale |
| 6780 | // factor. |
| 6781 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1, |
| 6782 | child_scale); |
| 6783 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6784 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6785 | // When chilld's total scale becomes >= 1, we should save and use that scale |
| 6786 | // factor. |
| 6787 | child_scale_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6788 | SkMScalar final_child_scale = 0.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6789 | child_scale_matrix.Scale(final_child_scale, final_child_scale); |
| 6790 | child_scale->SetTransform(child_scale_matrix); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6791 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6792 | { |
| 6793 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6794 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6795 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6796 | inputs.device_scale_factor = device_scale_factor; |
| 6797 | inputs.page_scale_factor = page_scale_factor; |
| 6798 | inputs.page_scale_application_layer = root.get(); |
| 6799 | inputs.can_adjust_raster_scales = true; |
| 6800 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6801 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6802 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6803 | initial_parent_scale, |
| 6804 | parent); |
| 6805 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6806 | initial_parent_scale * final_child_scale, |
| 6807 | child_scale); |
| 6808 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6809 | } |
| 6810 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6811 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6812 | MockContentLayerClient delegate; |
| 6813 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6814 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6815 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6816 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6817 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6818 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6819 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6820 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6821 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6822 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6823 | scoped_refptr<Layer> root = Layer::Create(); |
| 6824 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6825 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6826 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6827 | SetLayerPropertiesForTesting(parent.get(), |
| 6828 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6829 | gfx::PointF(), |
| 6830 | gfx::PointF(), |
| 6831 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6832 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6833 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6834 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6835 | scoped_refptr<ContentLayer> surface_scale = |
| 6836 | CreateDrawableContentLayer(&delegate); |
| 6837 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 6838 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6839 | gfx::PointF(), |
| 6840 | gfx::PointF(2.f, 2.f), |
| 6841 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6842 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6843 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6844 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6845 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 6846 | CreateDrawableContentLayer(&delegate); |
| 6847 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 6848 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6849 | gfx::PointF(), |
| 6850 | gfx::PointF(), |
| 6851 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6852 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6853 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6854 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6855 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 6856 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6857 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 6858 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6859 | gfx::PointF(), |
| 6860 | gfx::PointF(), |
| 6861 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6862 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6863 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6864 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6865 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 6866 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6867 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 6868 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6869 | gfx::PointF(), |
| 6870 | gfx::PointF(12.f, 12.f), |
| 6871 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6872 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6873 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6874 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6875 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 6876 | CreateDrawableContentLayer(&delegate); |
| 6877 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 6878 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6879 | gfx::PointF(), |
| 6880 | gfx::PointF(), |
| 6881 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6882 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6883 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6884 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6885 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 6886 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6887 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 6888 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6889 | gfx::PointF(), |
| 6890 | gfx::PointF(), |
| 6891 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6892 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6893 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6894 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6895 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6896 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6897 | parent->AddChild(surface_scale); |
| 6898 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6899 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6900 | surface_scale->SetForceRenderSurface(true); |
| 6901 | surface_scale->AddChild(surface_scale_child_scale); |
| 6902 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6903 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6904 | surface_no_scale->SetForceRenderSurface(true); |
| 6905 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 6906 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6907 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6908 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6909 | host->SetRootLayer(root); |
| 6910 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6911 | SkMScalar device_scale_factor = 5; |
| 6912 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6913 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6914 | RenderSurfaceLayerList render_surface_layer_list; |
| 6915 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6916 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6917 | inputs.device_scale_factor = device_scale_factor; |
| 6918 | inputs.page_scale_factor = page_scale_factor; |
| 6919 | inputs.page_scale_application_layer = root.get(); |
| 6920 | inputs.can_adjust_raster_scales = true; |
| 6921 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6922 | |
| 6923 | EXPECT_CONTENTS_SCALE_EQ( |
| 6924 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6925 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6926 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6927 | surface_scale); |
| 6928 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 6929 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6930 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 6931 | initial_child_scale * initial_child_scale, |
| 6932 | surface_scale_child_scale); |
| 6933 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 6934 | EXPECT_CONTENTS_SCALE_EQ( |
| 6935 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 6936 | initial_child_scale * initial_child_scale, |
| 6937 | surface_no_scale_child_scale); |
| 6938 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6939 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6940 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6941 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 6942 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6943 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6944 | // RenderSurfaces should always be 1:1 with their target. |
| 6945 | EXPECT_FLOAT_EQ( |
| 6946 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6947 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6948 | EXPECT_FLOAT_EQ( |
| 6949 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6950 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6951 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6952 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 6953 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6954 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 6955 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6956 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6957 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 6958 | // to scale during draw. |
| 6959 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6960 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6961 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6962 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6963 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6964 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 6965 | // to be scaled during draw. |
| 6966 | EXPECT_FLOAT_EQ( |
| 6967 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6968 | initial_child_scale * initial_child_scale, |
| 6969 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6970 | EXPECT_FLOAT_EQ( |
| 6971 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6972 | initial_child_scale * initial_child_scale, |
| 6973 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6974 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6975 | // RenderSurfaces should always be 1:1 with their target. |
| 6976 | EXPECT_FLOAT_EQ( |
| 6977 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6978 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6979 | EXPECT_FLOAT_EQ( |
| 6980 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6981 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6982 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6983 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 6984 | // scaled during draw. |
| 6985 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6986 | initial_parent_scale * initial_child_scale, |
| 6987 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6988 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6989 | initial_parent_scale * initial_child_scale, |
| 6990 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6991 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6992 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 6993 | // to scale during draw. |
| 6994 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6995 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6996 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6997 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6998 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6999 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 7000 | // to be scaled during draw. |
| 7001 | EXPECT_FLOAT_EQ( |
| 7002 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7003 | initial_child_scale * initial_child_scale, |
| 7004 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7005 | EXPECT_FLOAT_EQ( |
| 7006 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7007 | initial_child_scale * initial_child_scale, |
| 7008 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7009 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7010 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7011 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7012 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
| 7013 | MockContentLayerClient delegate; |
| 7014 | gfx::Transform identity_matrix; |
| 7015 | |
| 7016 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7017 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7018 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 7019 | |
| 7020 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7021 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7022 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 7023 | |
| 7024 | scoped_refptr<Layer> root = Layer::Create(); |
| 7025 | root->SetBounds(gfx::Size(100, 100)); |
| 7026 | |
| 7027 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7028 | SetLayerPropertiesForTesting(parent.get(), |
| 7029 | parent_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7030 | gfx::PointF(), |
| 7031 | gfx::PointF(), |
| 7032 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7033 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7034 | true); |
| 7035 | |
| 7036 | scoped_refptr<ContentLayer> surface_scale = |
| 7037 | CreateDrawableContentLayer(&delegate); |
| 7038 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 7039 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7040 | gfx::PointF(), |
| 7041 | gfx::PointF(2.f, 2.f), |
| 7042 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7043 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7044 | true); |
| 7045 | |
| 7046 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 7047 | CreateDrawableContentLayer(&delegate); |
| 7048 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 7049 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7050 | gfx::PointF(), |
| 7051 | gfx::PointF(), |
| 7052 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7053 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7054 | true); |
| 7055 | |
| 7056 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 7057 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7058 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 7059 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7060 | gfx::PointF(), |
| 7061 | gfx::PointF(), |
| 7062 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7063 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7064 | true); |
| 7065 | |
| 7066 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 7067 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7068 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 7069 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7070 | gfx::PointF(), |
| 7071 | gfx::PointF(12.f, 12.f), |
| 7072 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7073 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7074 | true); |
| 7075 | |
| 7076 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 7077 | CreateDrawableContentLayer(&delegate); |
| 7078 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 7079 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7080 | gfx::PointF(), |
| 7081 | gfx::PointF(), |
| 7082 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7083 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7084 | true); |
| 7085 | |
| 7086 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 7087 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7088 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 7089 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7090 | gfx::PointF(), |
| 7091 | gfx::PointF(), |
| 7092 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7093 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7094 | true); |
| 7095 | |
| 7096 | root->AddChild(parent); |
| 7097 | |
| 7098 | parent->AddChild(surface_scale); |
| 7099 | parent->AddChild(surface_no_scale); |
| 7100 | |
| 7101 | surface_scale->SetForceRenderSurface(true); |
| 7102 | surface_scale->AddChild(surface_scale_child_scale); |
| 7103 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 7104 | |
| 7105 | surface_no_scale->SetForceRenderSurface(true); |
| 7106 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 7107 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 7108 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7109 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7110 | host->SetRootLayer(root); |
| 7111 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7112 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7113 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7114 | SkMScalar device_scale_factor = 5.0; |
| 7115 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7116 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7117 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7118 | inputs.device_scale_factor = device_scale_factor; |
| 7119 | inputs.page_scale_factor = page_scale_factor; |
| 7120 | inputs.page_scale_application_layer = root.get(); |
| 7121 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7122 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7123 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7124 | parent); |
| 7125 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7126 | surface_scale); |
| 7127 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 7128 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7129 | surface_scale_child_scale); |
| 7130 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 7131 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7132 | surface_no_scale_child_scale); |
| 7133 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 7134 | |
| 7135 | // The parent is scaled up during draw, since its contents are not scaled by |
| 7136 | // the transform hierarchy. |
| 7137 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7138 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7139 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7140 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7141 | |
| 7142 | // The child surface is scaled up during draw since its subtree is not scaled |
| 7143 | // by the transform hierarchy. |
| 7144 | EXPECT_FLOAT_EQ( |
| 7145 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7146 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7147 | EXPECT_FLOAT_EQ( |
| 7148 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7149 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7150 | |
| 7151 | // The surface_scale's RenderSurface is scaled during draw, so the layer does |
| 7152 | // not need to be scaled when drawing into its surface. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7153 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 7154 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7155 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7156 | // The surface_scale_child_scale is scaled when drawing into its surface, |
| 7157 | // since its content bounds are not scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7158 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7159 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7160 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7161 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7162 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7163 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7164 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7165 | // The surface_scale_child_no_scale has a fixed contents scale of 1, so it |
| 7166 | // needs to be scaled by the device and page scale factors, along with the |
| 7167 | // transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7168 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7169 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7170 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7171 | EXPECT_FLOAT_EQ( |
| 7172 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7173 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7174 | |
| 7175 | // The child surface is scaled up during draw since its subtree is not scaled |
| 7176 | // by the transform hierarchy. |
| 7177 | EXPECT_FLOAT_EQ( |
| 7178 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7179 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7180 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7181 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7182 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7183 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7184 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 7185 | // be scaled by the device and page scale factors. Its surface is already |
| 7186 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 7187 | // drawing. |
| 7188 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7189 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7190 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7191 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7192 | |
| 7193 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 7194 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 7195 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7196 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7197 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7198 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7199 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7200 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7201 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7202 | |
| 7203 | // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it |
| 7204 | // needs to be scaled by the device and page scale factors. It also needs to |
| 7205 | // be scaled by any transform heirarchy below its target surface. |
| 7206 | EXPECT_FLOAT_EQ( |
| 7207 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7208 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7209 | EXPECT_FLOAT_EQ( |
| 7210 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7211 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7212 | } |
| 7213 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7214 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7215 | MockContentLayerClient delegate; |
| 7216 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7217 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7218 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7219 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7220 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7221 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7222 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7223 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7224 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7225 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7226 | scoped_refptr<Layer> root = Layer::Create(); |
| 7227 | root->SetBounds(gfx::Size(100, 100)); |
| 7228 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7229 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7230 | SetLayerPropertiesForTesting(parent.get(), |
| 7231 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7232 | gfx::PointF(), |
| 7233 | gfx::PointF(), |
| 7234 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7235 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7236 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7237 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7238 | scoped_refptr<ContentLayer> child_scale = |
| 7239 | CreateDrawableContentLayer(&delegate); |
| 7240 | SetLayerPropertiesForTesting(child_scale.get(), |
| 7241 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7242 | gfx::PointF(), |
| 7243 | gfx::PointF(2.f, 2.f), |
| 7244 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7245 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7246 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7247 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7248 | root->AddChild(parent); |
| 7249 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7250 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7251 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7252 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7253 | host->SetRootLayer(root); |
| 7254 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7255 | // Now put an animating transform on child. |
| 7256 | int animation_id = AddAnimatedTransformToController( |
| 7257 | child_scale->layer_animation_controller(), 10.0, 30, 0); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7258 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7259 | { |
| 7260 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7261 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7262 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7263 | inputs.can_adjust_raster_scales = true; |
| 7264 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7265 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7266 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 7267 | // The layers with animating transforms should not compute a contents scale |
| 7268 | // other than 1 until they finish animating. |
| 7269 | EXPECT_CONTENTS_SCALE_EQ(1, child_scale); |
| 7270 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7272 | // Remove the animation, now it can save a raster scale. |
| 7273 | child_scale->layer_animation_controller()->RemoveAnimation(animation_id); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7274 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7275 | { |
| 7276 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7277 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7278 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7279 | inputs.can_adjust_raster_scales = true; |
| 7280 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7281 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7282 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 7283 | // The layers with animating transforms should not compute a contents scale |
| 7284 | // other than 1 until they finish animating. |
| 7285 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale, |
| 7286 | child_scale); |
| 7287 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7288 | } |
| 7289 | |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 7290 | TEST_F(LayerTreeHostCommonTest, |
| 7291 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 7292 | MockContentLayerClient delegate; |
| 7293 | scoped_refptr<Layer> root = Layer::Create(); |
| 7294 | scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 7295 | root->AddChild(child); |
| 7296 | |
| 7297 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7298 | host->SetRootLayer(root); |
| 7299 | |
| 7300 | gfx::Transform identity_matrix; |
| 7301 | SetLayerPropertiesForTesting(root.get(), |
| 7302 | identity_matrix, |
| 7303 | gfx::PointF(), |
| 7304 | gfx::PointF(), |
| 7305 | gfx::Size(100, 100), |
| 7306 | true, |
| 7307 | false); |
| 7308 | SetLayerPropertiesForTesting(child.get(), |
| 7309 | identity_matrix, |
| 7310 | gfx::PointF(), |
| 7311 | gfx::PointF(), |
| 7312 | gfx::Size(100, 100), |
| 7313 | true, |
| 7314 | false); |
| 7315 | |
| 7316 | root->reset_needs_push_properties_for_testing(); |
| 7317 | child->reset_needs_push_properties_for_testing(); |
| 7318 | |
| 7319 | // This will change both layers' content bounds. |
| 7320 | ExecuteCalculateDrawProperties(root.get()); |
| 7321 | EXPECT_TRUE(root->needs_push_properties()); |
| 7322 | EXPECT_TRUE(child->needs_push_properties()); |
| 7323 | |
| 7324 | root->reset_needs_push_properties_for_testing(); |
| 7325 | child->reset_needs_push_properties_for_testing(); |
| 7326 | |
| 7327 | // This will change only the child layer's contents scale and content bounds, |
| 7328 | // since the root layer is not a ContentsScalingLayer. |
| 7329 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 7330 | EXPECT_FALSE(root->needs_push_properties()); |
| 7331 | EXPECT_TRUE(child->needs_push_properties()); |
| 7332 | |
| 7333 | root->reset_needs_push_properties_for_testing(); |
| 7334 | child->reset_needs_push_properties_for_testing(); |
| 7335 | |
| 7336 | // This will not change either layer's contents scale or content bounds. |
| 7337 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 7338 | EXPECT_FALSE(root->needs_push_properties()); |
| 7339 | EXPECT_FALSE(child->needs_push_properties()); |
| 7340 | } |
| 7341 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7342 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7343 | MockContentLayerClient delegate; |
| 7344 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7345 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7346 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7347 | SetLayerPropertiesForTesting(parent.get(), |
| 7348 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7349 | gfx::PointF(), |
| 7350 | gfx::PointF(), |
| 7351 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7352 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7353 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7354 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7355 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 7356 | SetLayerPropertiesForTesting(child.get(), |
| 7357 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7358 | gfx::PointF(), |
| 7359 | gfx::PointF(2.f, 2.f), |
| 7360 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7361 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7362 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7363 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7364 | gfx::Transform replica_transform; |
| 7365 | replica_transform.Scale(1.0, -1.0); |
| 7366 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 7367 | SetLayerPropertiesForTesting(replica.get(), |
| 7368 | replica_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7369 | gfx::PointF(), |
| 7370 | gfx::PointF(2.f, 2.f), |
| 7371 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7372 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7373 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7374 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7375 | // This layer should end up in the same surface as child, with the same draw |
| 7376 | // and screen space transforms. |
| 7377 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 7378 | CreateDrawableContentLayer(&delegate); |
| 7379 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 7380 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7381 | gfx::PointF(), |
| 7382 | gfx::PointF(), |
| 7383 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7384 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7385 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7386 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7387 | parent->AddChild(child); |
| 7388 | child->AddChild(duplicate_child_non_owner); |
| 7389 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7390 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7391 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7392 | host->SetRootLayer(parent); |
| 7393 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7394 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7395 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7396 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7397 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7398 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 7399 | inputs.device_scale_factor = device_scale_factor; |
| 7400 | inputs.can_adjust_raster_scales = true; |
| 7401 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7402 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7403 | // We should have two render surfaces. The root's render surface and child's |
| 7404 | // render surface (it needs one because it has a replica layer). |
| 7405 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7406 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7407 | gfx::Transform expected_parent_transform; |
| 7408 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 7409 | parent->screen_space_transform()); |
| 7410 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 7411 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7412 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7413 | gfx::Transform expected_draw_transform; |
| 7414 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 7415 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7416 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7417 | gfx::Transform expected_screen_space_transform; |
| 7418 | expected_screen_space_transform.Translate( |
| 7419 | device_scale_factor * child->position().x(), |
| 7420 | device_scale_factor * child->position().y()); |
| 7421 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 7422 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7423 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7424 | gfx::Transform expected_duplicate_child_draw_transform = |
| 7425 | child->draw_transform(); |
| 7426 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 7427 | duplicate_child_non_owner->draw_transform()); |
| 7428 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7429 | child->screen_space_transform(), |
| 7430 | duplicate_child_non_owner->screen_space_transform()); |
| 7431 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 7432 | duplicate_child_non_owner->drawable_content_rect()); |
| 7433 | EXPECT_EQ(child->content_bounds(), |
| 7434 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7435 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7436 | gfx::Transform expected_render_surface_draw_transform; |
| 7437 | expected_render_surface_draw_transform.Translate( |
| 7438 | device_scale_factor * child->position().x(), |
| 7439 | device_scale_factor * child->position().y()); |
| 7440 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 7441 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7442 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7443 | gfx::Transform expected_surface_draw_transform; |
| 7444 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 7445 | device_scale_factor * 2.f); |
| 7446 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 7447 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7448 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7449 | gfx::Transform expected_surface_screen_space_transform; |
| 7450 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 7451 | device_scale_factor * 2.f); |
| 7452 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7453 | expected_surface_screen_space_transform, |
| 7454 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7455 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7456 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7457 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 7458 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 7459 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7460 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7461 | expected_replica_draw_transform, |
| 7462 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7463 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7464 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7465 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 7466 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 7467 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7468 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7469 | expected_replica_screen_space_transform, |
| 7470 | child->render_surface()->replica_screen_space_transform()); |
| 7471 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7472 | expected_replica_screen_space_transform, |
| 7473 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7474 | } |
| 7475 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7476 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7477 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 7478 | MockContentLayerClient delegate; |
| 7479 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7480 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7481 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7482 | SetLayerPropertiesForTesting(parent.get(), |
| 7483 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7484 | gfx::PointF(), |
| 7485 | gfx::PointF(), |
| 7486 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7487 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7488 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7489 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7490 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 7491 | SetLayerPropertiesForTesting(child.get(), |
| 7492 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7493 | gfx::PointF(), |
| 7494 | gfx::PointF(), |
| 7495 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7496 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7497 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7498 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7499 | gfx::Transform replica_transform; |
| 7500 | replica_transform.Scale(1.0, -1.0); |
| 7501 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 7502 | SetLayerPropertiesForTesting(replica.get(), |
| 7503 | replica_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7504 | gfx::PointF(), |
| 7505 | gfx::PointF(), |
| 7506 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7507 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7508 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7509 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7510 | // This layer should end up in the same surface as child, with the same draw |
| 7511 | // and screen space transforms. |
| 7512 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 7513 | CreateDrawableContentLayer(&delegate); |
| 7514 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 7515 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7516 | gfx::PointF(), |
| 7517 | gfx::PointF(), |
| 7518 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7519 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7520 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7521 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7522 | parent->AddChild(child); |
| 7523 | child->AddChild(duplicate_child_non_owner); |
| 7524 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7525 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7526 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7527 | host->SetRootLayer(parent); |
| 7528 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 7529 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7530 | |
| 7531 | RenderSurfaceLayerList render_surface_layer_list; |
| 7532 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7533 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 7534 | inputs.device_scale_factor = device_scale_factor; |
| 7535 | inputs.can_adjust_raster_scales = true; |
| 7536 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7537 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7538 | // We should have two render surfaces. The root's render surface and child's |
| 7539 | // render surface (it needs one because it has a replica layer). |
| 7540 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7541 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7542 | gfx::Transform identity_transform; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7543 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7544 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7545 | parent->screen_space_transform()); |
| 7546 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform()); |
| 7547 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform()); |
| 7548 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7549 | child->screen_space_transform()); |
| 7550 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7551 | duplicate_child_non_owner->draw_transform()); |
| 7552 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7553 | identity_transform, duplicate_child_non_owner->screen_space_transform()); |
| 7554 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 7555 | duplicate_child_non_owner->drawable_content_rect()); |
| 7556 | EXPECT_EQ(child->content_bounds(), |
| 7557 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7558 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7559 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7560 | child->render_surface()->draw_transform()); |
| 7561 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7562 | child->render_surface()->draw_transform()); |
| 7563 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7564 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7565 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7566 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7567 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7568 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7569 | expected_replica_draw_transform, |
| 7570 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7571 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7572 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7573 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7574 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7575 | expected_replica_screen_space_transform, |
| 7576 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7577 | } |
| 7578 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7579 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7580 | scoped_refptr<Layer> root = Layer::Create(); |
| 7581 | scoped_refptr<Layer> child = Layer::Create(); |
| 7582 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 7583 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 7584 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7585 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7586 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 7587 | child->AddChild(grand_child.get()); |
| 7588 | child->SetMaskLayer(mask_layer.get()); |
| 7589 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7590 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7591 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7592 | host->SetRootLayer(root); |
| 7593 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7594 | int nonexistent_id = -1; |
| 7595 | EXPECT_EQ(root, |
| 7596 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
| 7597 | EXPECT_EQ(child, |
| 7598 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 7599 | EXPECT_EQ( |
| 7600 | grand_child, |
| 7601 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 7602 | EXPECT_EQ( |
| 7603 | mask_layer, |
| 7604 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 7605 | EXPECT_EQ( |
| 7606 | replica_layer, |
| 7607 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 7608 | EXPECT_EQ( |
| 7609 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7610 | } |
| 7611 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7612 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7613 | scoped_refptr<Layer> root = Layer::Create(); |
| 7614 | scoped_refptr<Layer> child = Layer::Create(); |
| 7615 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 7616 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7617 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7618 | const gfx::Transform identity_matrix; |
| 7619 | SetLayerPropertiesForTesting(root.get(), |
| 7620 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7621 | gfx::PointF(), |
| 7622 | gfx::PointF(), |
| 7623 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7624 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7625 | false); |
| 7626 | SetLayerPropertiesForTesting(child.get(), |
| 7627 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7628 | gfx::PointF(), |
| 7629 | gfx::PointF(), |
| 7630 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7631 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7632 | false); |
| 7633 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7634 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7635 | gfx::PointF(), |
| 7636 | gfx::PointF(), |
| 7637 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7638 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7639 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7640 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7641 | root->AddChild(child); |
| 7642 | child->AddChild(grand_child); |
| 7643 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7644 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7645 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7646 | host->SetRootLayer(root); |
| 7647 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7648 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7649 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7650 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7651 | } |
| 7652 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7653 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7654 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7655 | TestSharedBitmapManager shared_bitmap_manager; |
| 7656 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7657 | host_impl.CreatePendingTree(); |
| 7658 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 7659 | |
| 7660 | const gfx::Transform identity_matrix; |
| 7661 | SetLayerPropertiesForTesting(root.get(), |
| 7662 | identity_matrix, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7663 | gfx::PointF(), |
| 7664 | gfx::PointF(), |
| 7665 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7666 | true, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7667 | false); |
| 7668 | root->SetDrawsContent(true); |
| 7669 | |
| 7670 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 7671 | SetLayerPropertiesForTesting(child.get(), |
| 7672 | identity_matrix, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7673 | gfx::PointF(), |
| 7674 | gfx::PointF(), |
| 7675 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7676 | true, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7677 | false); |
| 7678 | child->SetDrawsContent(true); |
| 7679 | child->SetOpacity(0.0f); |
| 7680 | |
| 7681 | // Add opacity animation. |
| 7682 | AddOpacityTransitionToController( |
| 7683 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 7684 | |
| 7685 | root->AddChild(child.Pass()); |
| 7686 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7687 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7688 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7689 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7690 | inputs.can_adjust_raster_scales = true; |
| 7691 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7692 | |
| 7693 | // We should have one render surface and two layers. The child |
| 7694 | // layer should be included even though it is transparent. |
| 7695 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 7696 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 7697 | } |
| 7698 | |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7699 | typedef std::tr1::tuple<bool, bool> LCDTextTestParam; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7700 | class LCDTextTest |
| 7701 | : public LayerTreeHostCommonTestBase, |
| 7702 | public testing::TestWithParam<LCDTextTestParam> { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7703 | protected: |
| 7704 | virtual void SetUp() { |
| 7705 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7706 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7707 | root_ = Layer::Create(); |
| 7708 | child_ = Layer::Create(); |
| 7709 | grand_child_ = Layer::Create(); |
| 7710 | child_->AddChild(grand_child_.get()); |
| 7711 | root_->AddChild(child_.get()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7712 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7713 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7714 | SetLayerPropertiesForTesting(root_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7715 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7716 | gfx::PointF(), |
| 7717 | gfx::PointF(), |
| 7718 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7719 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7720 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7721 | SetLayerPropertiesForTesting(child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7722 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7723 | gfx::PointF(), |
| 7724 | gfx::PointF(), |
| 7725 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7726 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7727 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7728 | SetLayerPropertiesForTesting(grand_child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7729 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7730 | gfx::PointF(), |
| 7731 | gfx::PointF(), |
| 7732 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7733 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7734 | false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7735 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7736 | child_->SetForceRenderSurface(std::tr1::get<1>(GetParam())); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7737 | |
| 7738 | host_ = FakeLayerTreeHost::Create(); |
| 7739 | host_->SetRootLayer(root_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7740 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7741 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7742 | bool can_use_lcd_text_; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7743 | scoped_ptr<FakeLayerTreeHost> host_; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7744 | scoped_refptr<Layer> root_; |
| 7745 | scoped_refptr<Layer> child_; |
| 7746 | scoped_refptr<Layer> grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7747 | }; |
| 7748 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7749 | TEST_P(LCDTextTest, CanUseLCDText) { |
| 7750 | // Case 1: Identity transform. |
| 7751 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7752 | ExecuteCalculateDrawProperties( |
| 7753 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7754 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7755 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7756 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7757 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7758 | // Case 2: Integral translation. |
| 7759 | gfx::Transform integral_translation; |
| 7760 | integral_translation.Translate(1.0, 2.0); |
| 7761 | child_->SetTransform(integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7762 | ExecuteCalculateDrawProperties( |
| 7763 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7764 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7765 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7766 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7767 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7768 | // Case 3: Non-integral translation. |
| 7769 | gfx::Transform non_integral_translation; |
| 7770 | non_integral_translation.Translate(1.5, 2.5); |
| 7771 | child_->SetTransform(non_integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7772 | ExecuteCalculateDrawProperties( |
| 7773 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7774 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7775 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7776 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7777 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7778 | // Case 4: Rotation. |
| 7779 | gfx::Transform rotation; |
| 7780 | rotation.Rotate(10.0); |
| 7781 | child_->SetTransform(rotation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7782 | ExecuteCalculateDrawProperties( |
| 7783 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7784 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7785 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7786 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7787 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7788 | // Case 5: Scale. |
| 7789 | gfx::Transform scale; |
| 7790 | scale.Scale(2.0, 2.0); |
| 7791 | child_->SetTransform(scale); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7792 | ExecuteCalculateDrawProperties( |
| 7793 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7794 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7795 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7796 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7797 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7798 | // Case 6: Skew. |
| 7799 | gfx::Transform skew; |
| 7800 | skew.SkewX(10.0); |
| 7801 | child_->SetTransform(skew); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7802 | ExecuteCalculateDrawProperties( |
| 7803 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7804 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7805 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7806 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7807 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7808 | // Case 7: Translucent. |
| 7809 | child_->SetTransform(identity_matrix); |
| 7810 | child_->SetOpacity(0.5f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7811 | ExecuteCalculateDrawProperties( |
| 7812 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7813 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7814 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7815 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7816 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7817 | // Case 8: Sanity check: restore transform and opacity. |
| 7818 | child_->SetTransform(identity_matrix); |
| 7819 | child_->SetOpacity(1.f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7820 | ExecuteCalculateDrawProperties( |
| 7821 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7822 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7823 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7824 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7825 | } |
| 7826 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 7827 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7828 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7829 | ExecuteCalculateDrawProperties( |
| 7830 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7831 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7832 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7833 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7834 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7835 | // Add opacity animation. |
| 7836 | child_->SetOpacity(0.9f); |
| 7837 | AddOpacityTransitionToController( |
| 7838 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7839 | |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7840 | ExecuteCalculateDrawProperties( |
| 7841 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7842 | // Text AA should not be adjusted while animation is active. |
| 7843 | // Make sure LCD text AA setting remains unchanged. |
| 7844 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7845 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7846 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7847 | } |
| 7848 | |
| 7849 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 7850 | LCDTextTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7851 | testing::Combine(testing::Bool(), testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7852 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7853 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7854 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7855 | TestSharedBitmapManager shared_bitmap_manager; |
| 7856 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7857 | host_impl.CreatePendingTree(); |
| 7858 | const gfx::Transform identity_matrix; |
| 7859 | |
| 7860 | scoped_refptr<Layer> root = Layer::Create(); |
| 7861 | SetLayerPropertiesForTesting(root.get(), |
| 7862 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7863 | gfx::PointF(), |
| 7864 | gfx::PointF(), |
| 7865 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7866 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7867 | false); |
| 7868 | root->SetIsDrawable(true); |
| 7869 | |
| 7870 | scoped_refptr<Layer> child = Layer::Create(); |
| 7871 | SetLayerPropertiesForTesting(child.get(), |
| 7872 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7873 | gfx::PointF(), |
| 7874 | gfx::PointF(), |
| 7875 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7876 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7877 | false); |
| 7878 | child->SetIsDrawable(true); |
| 7879 | |
| 7880 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 7881 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7882 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7883 | gfx::PointF(), |
| 7884 | gfx::PointF(), |
| 7885 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7886 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7887 | false); |
| 7888 | grand_child->SetIsDrawable(true); |
| 7889 | grand_child->SetHideLayerAndSubtree(true); |
| 7890 | |
| 7891 | child->AddChild(grand_child); |
| 7892 | root->AddChild(child); |
| 7893 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7894 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7895 | host->SetRootLayer(root); |
| 7896 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7897 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7898 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7899 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7900 | inputs.can_adjust_raster_scales = true; |
| 7901 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7902 | |
| 7903 | // We should have one render surface and two layers. The grand child has |
| 7904 | // hidden itself. |
| 7905 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 7906 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7907 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 7908 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7909 | } |
| 7910 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7911 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7912 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7913 | TestSharedBitmapManager shared_bitmap_manager; |
| 7914 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7915 | host_impl.CreatePendingTree(); |
| 7916 | const gfx::Transform identity_matrix; |
| 7917 | |
| 7918 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 7919 | SetLayerPropertiesForTesting(root.get(), |
| 7920 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7921 | gfx::PointF(), |
| 7922 | gfx::PointF(), |
| 7923 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7924 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7925 | false); |
| 7926 | root->SetDrawsContent(true); |
| 7927 | |
| 7928 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 7929 | SetLayerPropertiesForTesting(child.get(), |
| 7930 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7931 | gfx::PointF(), |
| 7932 | gfx::PointF(), |
| 7933 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7934 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7935 | false); |
| 7936 | child->SetDrawsContent(true); |
| 7937 | |
| 7938 | scoped_ptr<LayerImpl> grand_child = |
| 7939 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 7940 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7941 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7942 | gfx::PointF(), |
| 7943 | gfx::PointF(), |
| 7944 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7945 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7946 | false); |
| 7947 | grand_child->SetDrawsContent(true); |
| 7948 | grand_child->SetHideLayerAndSubtree(true); |
| 7949 | |
| 7950 | child->AddChild(grand_child.Pass()); |
| 7951 | root->AddChild(child.Pass()); |
| 7952 | |
| 7953 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7954 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7955 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7956 | inputs.can_adjust_raster_scales = true; |
| 7957 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7958 | |
| 7959 | // We should have one render surface and two layers. The grand child has |
| 7960 | // hidden itself. |
| 7961 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 7962 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7963 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 7964 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7965 | } |
| 7966 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7967 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7968 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7969 | TestSharedBitmapManager shared_bitmap_manager; |
| 7970 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7971 | host_impl.CreatePendingTree(); |
| 7972 | const gfx::Transform identity_matrix; |
| 7973 | |
| 7974 | scoped_refptr<Layer> root = Layer::Create(); |
| 7975 | SetLayerPropertiesForTesting(root.get(), |
| 7976 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7977 | gfx::PointF(), |
| 7978 | gfx::PointF(), |
| 7979 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7980 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7981 | false); |
| 7982 | root->SetIsDrawable(true); |
| 7983 | |
| 7984 | scoped_refptr<Layer> child = Layer::Create(); |
| 7985 | SetLayerPropertiesForTesting(child.get(), |
| 7986 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7987 | gfx::PointF(), |
| 7988 | gfx::PointF(), |
| 7989 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7990 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7991 | false); |
| 7992 | child->SetIsDrawable(true); |
| 7993 | child->SetHideLayerAndSubtree(true); |
| 7994 | |
| 7995 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 7996 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7997 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7998 | gfx::PointF(), |
| 7999 | gfx::PointF(), |
| 8000 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8001 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8002 | false); |
| 8003 | grand_child->SetIsDrawable(true); |
| 8004 | |
| 8005 | child->AddChild(grand_child); |
| 8006 | root->AddChild(child); |
| 8007 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8008 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8009 | host->SetRootLayer(root); |
| 8010 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8011 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8012 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8013 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8014 | inputs.can_adjust_raster_scales = true; |
| 8015 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8016 | |
| 8017 | // We should have one render surface and one layers. The child has |
| 8018 | // hidden itself and the grand child. |
| 8019 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 8020 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8021 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8022 | } |
| 8023 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8024 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8025 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8026 | TestSharedBitmapManager shared_bitmap_manager; |
| 8027 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8028 | host_impl.CreatePendingTree(); |
| 8029 | const gfx::Transform identity_matrix; |
| 8030 | |
| 8031 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8032 | SetLayerPropertiesForTesting(root.get(), |
| 8033 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8034 | gfx::PointF(), |
| 8035 | gfx::PointF(), |
| 8036 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8037 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8038 | false); |
| 8039 | root->SetDrawsContent(true); |
| 8040 | |
| 8041 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8042 | SetLayerPropertiesForTesting(child.get(), |
| 8043 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8044 | gfx::PointF(), |
| 8045 | gfx::PointF(), |
| 8046 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8047 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8048 | false); |
| 8049 | child->SetDrawsContent(true); |
| 8050 | child->SetHideLayerAndSubtree(true); |
| 8051 | |
| 8052 | scoped_ptr<LayerImpl> grand_child = |
| 8053 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8054 | SetLayerPropertiesForTesting(grand_child.get(), |
| 8055 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8056 | gfx::PointF(), |
| 8057 | gfx::PointF(), |
| 8058 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8059 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8060 | false); |
| 8061 | grand_child->SetDrawsContent(true); |
| 8062 | |
| 8063 | child->AddChild(grand_child.Pass()); |
| 8064 | root->AddChild(child.Pass()); |
| 8065 | |
| 8066 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8067 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8068 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8069 | inputs.can_adjust_raster_scales = true; |
| 8070 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8071 | |
| 8072 | // We should have one render surface and one layers. The child has |
| 8073 | // hidden itself and the grand child. |
| 8074 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 8075 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8076 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8077 | } |
| 8078 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8079 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 8080 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8081 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8082 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8083 | TestSharedBitmapManager shared_bitmap_manager; |
| 8084 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8085 | host_impl.CreatePendingTree(); |
| 8086 | const gfx::Transform identity_matrix; |
| 8087 | |
| 8088 | scoped_refptr<Layer> root = Layer::Create(); |
| 8089 | SetLayerPropertiesForTesting(root.get(), |
| 8090 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8091 | gfx::PointF(), |
| 8092 | gfx::PointF(), |
| 8093 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8094 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8095 | false); |
| 8096 | root->SetIsDrawable(true); |
| 8097 | |
| 8098 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(); |
| 8099 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 8100 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8101 | gfx::PointF(), |
| 8102 | gfx::PointF(), |
| 8103 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8104 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8105 | false); |
| 8106 | copy_grand_parent->SetIsDrawable(true); |
| 8107 | |
| 8108 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 8109 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 8110 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8111 | gfx::PointF(), |
| 8112 | gfx::PointF(), |
| 8113 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8114 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8115 | false); |
| 8116 | copy_parent->SetIsDrawable(true); |
| 8117 | copy_parent->SetForceRenderSurface(true); |
| 8118 | |
| 8119 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 8120 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 8121 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8122 | gfx::PointF(), |
| 8123 | gfx::PointF(), |
| 8124 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8125 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8126 | false); |
| 8127 | copy_layer->SetIsDrawable(true); |
| 8128 | |
| 8129 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 8130 | SetLayerPropertiesForTesting(copy_child.get(), |
| 8131 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8132 | gfx::PointF(), |
| 8133 | gfx::PointF(), |
| 8134 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8135 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8136 | false); |
| 8137 | copy_child->SetIsDrawable(true); |
| 8138 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8139 | scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); |
| 8140 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 8141 | identity_matrix, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8142 | gfx::PointF(), |
| 8143 | gfx::PointF(), |
| 8144 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8145 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8146 | false); |
| 8147 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 8148 | |
| 8149 | scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); |
| 8150 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 8151 | identity_matrix, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8152 | gfx::PointF(), |
| 8153 | gfx::PointF(), |
| 8154 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8155 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8156 | false); |
| 8157 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 8158 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8159 | copy_layer->AddChild(copy_child); |
| 8160 | copy_parent->AddChild(copy_layer); |
| 8161 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8162 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8163 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8164 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8165 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8166 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8167 | host->SetRootLayer(root); |
| 8168 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8169 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 8170 | // hidden subtree on copy_layer. |
| 8171 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8172 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 8173 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8174 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 8175 | base::Bind(&EmptyCopyOutputCallback))); |
| 8176 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 8177 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8178 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8179 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8180 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8181 | inputs.can_adjust_raster_scales = true; |
| 8182 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8183 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8184 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 8185 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 8186 | layer_or_descendant_has_copy_request); |
| 8187 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 8188 | layer_or_descendant_has_copy_request); |
| 8189 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 8190 | layer_or_descendant_has_copy_request); |
| 8191 | EXPECT_FALSE(copy_child->draw_properties(). |
| 8192 | layer_or_descendant_has_copy_request); |
| 8193 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 8194 | layer_or_descendant_has_copy_request); |
| 8195 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 8196 | layer_or_descendant_has_copy_request); |
| 8197 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8198 | // We should have three render surfaces, one for the root, one for the parent |
| 8199 | // since it owns a surface, and one for the copy_layer. |
| 8200 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8201 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 8202 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 8203 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8204 | |
| 8205 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8206 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 8207 | // will appear since something in its subtree needs to be drawn for a copy |
| 8208 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8209 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8210 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 8211 | EXPECT_EQ(copy_parent->id(), |
| 8212 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8213 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 8214 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8215 | // appear in its list, since it needs to be drawn for the copy request. |
| 8216 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 8217 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8218 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8219 | |
| 8220 | // The copy_layer's render surface should have two contributing layers. |
| 8221 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 8222 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8223 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8224 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8225 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8226 | } |
| 8227 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8228 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8229 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8230 | TestSharedBitmapManager shared_bitmap_manager; |
| 8231 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8232 | host_impl.CreatePendingTree(); |
| 8233 | const gfx::Transform identity_matrix; |
| 8234 | |
| 8235 | scoped_refptr<Layer> root = Layer::Create(); |
| 8236 | SetLayerPropertiesForTesting(root.get(), |
| 8237 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8238 | gfx::PointF(), |
| 8239 | gfx::PointF(), |
| 8240 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8241 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8242 | false); |
| 8243 | root->SetIsDrawable(true); |
| 8244 | |
| 8245 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 8246 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 8247 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8248 | gfx::PointF(), |
| 8249 | gfx::PointF(), |
| 8250 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8251 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8252 | false); |
| 8253 | copy_parent->SetIsDrawable(true); |
| 8254 | copy_parent->SetMasksToBounds(true); |
| 8255 | |
| 8256 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 8257 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 8258 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8259 | gfx::PointF(), |
| 8260 | gfx::PointF(), |
| 8261 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8262 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8263 | false); |
| 8264 | copy_layer->SetIsDrawable(true); |
| 8265 | |
| 8266 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 8267 | SetLayerPropertiesForTesting(copy_child.get(), |
| 8268 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8269 | gfx::PointF(), |
| 8270 | gfx::PointF(), |
| 8271 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8272 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8273 | false); |
| 8274 | copy_child->SetIsDrawable(true); |
| 8275 | |
| 8276 | copy_layer->AddChild(copy_child); |
| 8277 | copy_parent->AddChild(copy_layer); |
| 8278 | root->AddChild(copy_parent); |
| 8279 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8280 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8281 | host->SetRootLayer(root); |
| 8282 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8283 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 8284 | base::Bind(&EmptyCopyOutputCallback))); |
| 8285 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 8286 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8287 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8288 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8289 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8290 | inputs.can_adjust_raster_scales = true; |
| 8291 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8292 | |
| 8293 | // We should have one render surface, as the others are clipped out. |
| 8294 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8295 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8296 | |
| 8297 | // The root render surface should only have 1 contributing layer, since the |
| 8298 | // other layers are empty/clipped away. |
| 8299 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8300 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8301 | } |
| 8302 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8303 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 8304 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8305 | TestSharedBitmapManager shared_bitmap_manager; |
| 8306 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8307 | host_impl.CreatePendingTree(); |
| 8308 | const gfx::Transform identity_matrix; |
| 8309 | |
| 8310 | scoped_refptr<Layer> root = Layer::Create(); |
| 8311 | SetLayerPropertiesForTesting(root.get(), |
| 8312 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8313 | gfx::PointF(), |
| 8314 | gfx::PointF(), |
| 8315 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8316 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8317 | false); |
| 8318 | root->SetIsDrawable(true); |
| 8319 | |
| 8320 | // The surface is moved slightly outside of the viewport. |
| 8321 | scoped_refptr<Layer> surface = Layer::Create(); |
| 8322 | SetLayerPropertiesForTesting(surface.get(), |
| 8323 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8324 | gfx::PointF(), |
| 8325 | gfx::PointF(-10, -20), |
| 8326 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8327 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8328 | false); |
| 8329 | surface->SetForceRenderSurface(true); |
| 8330 | |
| 8331 | scoped_refptr<Layer> surface_child = Layer::Create(); |
| 8332 | SetLayerPropertiesForTesting(surface_child.get(), |
| 8333 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8334 | gfx::PointF(), |
| 8335 | gfx::PointF(), |
| 8336 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8337 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8338 | false); |
| 8339 | surface_child->SetIsDrawable(true); |
| 8340 | |
| 8341 | surface->AddChild(surface_child); |
| 8342 | root->AddChild(surface); |
| 8343 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8344 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8345 | host->SetRootLayer(root); |
| 8346 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8347 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8348 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8349 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8350 | inputs.can_adjust_raster_scales = true; |
| 8351 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8352 | |
| 8353 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 8354 | // the viewport. |
| 8355 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 8356 | surface_child->visible_content_rect().ToString()); |
| 8357 | } |
| 8358 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8359 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 8360 | // Ensure that a transform between the layer and its render surface is not a |
| 8361 | // problem. Constructs the following layer tree. |
| 8362 | // |
| 8363 | // root (a render surface) |
| 8364 | // + render_surface |
| 8365 | // + clip_parent (scaled) |
| 8366 | // + intervening_clipping_layer |
| 8367 | // + clip_child |
| 8368 | // |
| 8369 | // The render surface should be resized correctly and the clip child should |
| 8370 | // inherit the right clip rect. |
| 8371 | scoped_refptr<Layer> root = Layer::Create(); |
| 8372 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 8373 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8374 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8375 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8376 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8377 | |
| 8378 | root->AddChild(render_surface); |
| 8379 | render_surface->AddChild(clip_parent); |
| 8380 | clip_parent->AddChild(intervening); |
| 8381 | intervening->AddChild(clip_child); |
| 8382 | |
| 8383 | clip_child->SetClipParent(clip_parent.get()); |
| 8384 | |
| 8385 | intervening->SetMasksToBounds(true); |
| 8386 | clip_parent->SetMasksToBounds(true); |
| 8387 | |
| 8388 | render_surface->SetForceRenderSurface(true); |
| 8389 | |
| 8390 | gfx::Transform scale_transform; |
| 8391 | scale_transform.Scale(2, 2); |
| 8392 | |
| 8393 | gfx::Transform identity_transform; |
| 8394 | |
| 8395 | SetLayerPropertiesForTesting(root.get(), |
| 8396 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8397 | gfx::PointF(), |
| 8398 | gfx::PointF(), |
| 8399 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8400 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8401 | false); |
| 8402 | SetLayerPropertiesForTesting(render_surface.get(), |
| 8403 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8404 | gfx::PointF(), |
| 8405 | gfx::PointF(), |
| 8406 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8407 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8408 | false); |
| 8409 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8410 | scale_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8411 | gfx::PointF(), |
| 8412 | gfx::PointF(1.f, 1.f), |
| 8413 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8414 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8415 | false); |
| 8416 | SetLayerPropertiesForTesting(intervening.get(), |
| 8417 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8418 | gfx::PointF(), |
| 8419 | gfx::PointF(1.f, 1.f), |
| 8420 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8421 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8422 | false); |
| 8423 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8424 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8425 | gfx::PointF(), |
| 8426 | gfx::PointF(1.f, 1.f), |
| 8427 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8428 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8429 | false); |
| 8430 | |
| 8431 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8432 | host->SetRootLayer(root); |
| 8433 | |
| 8434 | ExecuteCalculateDrawProperties(root.get()); |
| 8435 | |
| 8436 | ASSERT_TRUE(root->render_surface()); |
| 8437 | ASSERT_TRUE(render_surface->render_surface()); |
| 8438 | |
| 8439 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 8440 | // by the intervening clip layer. |
| 8441 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 8442 | clip_parent->clip_rect().ToString()); |
| 8443 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 8444 | clip_child->clip_rect().ToString()); |
| 8445 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 8446 | intervening->clip_rect().ToString()); |
| 8447 | |
| 8448 | // Ensure that the render surface reports a content rect that has been grown |
| 8449 | // to accomodate for the clip child. |
| 8450 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 8451 | render_surface->render_surface()->content_rect().ToString()); |
| 8452 | |
| 8453 | // The above check implies the two below, but they nicely demonstrate that |
| 8454 | // we've grown, despite the intervening layer's clip. |
| 8455 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 8456 | render_surface->render_surface()->content_rect())); |
| 8457 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 8458 | render_surface->render_surface()->content_rect())); |
| 8459 | } |
| 8460 | |
| 8461 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 8462 | // Ensure that intervening render surfaces are not a problem in the basic |
| 8463 | // case. In the following tree, both render surfaces should be resized to |
| 8464 | // accomodate for the clip child, despite an intervening clip. |
| 8465 | // |
| 8466 | // root (a render surface) |
| 8467 | // + clip_parent (masks to bounds) |
| 8468 | // + render_surface1 (sets opacity) |
| 8469 | // + intervening (masks to bounds) |
| 8470 | // + render_surface2 (also sets opacity) |
| 8471 | // + clip_child |
| 8472 | // |
| 8473 | scoped_refptr<Layer> root = Layer::Create(); |
| 8474 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8475 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8476 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8477 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8478 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8479 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8480 | |
| 8481 | root->AddChild(clip_parent); |
| 8482 | clip_parent->AddChild(render_surface1); |
| 8483 | render_surface1->AddChild(intervening); |
| 8484 | intervening->AddChild(render_surface2); |
| 8485 | render_surface2->AddChild(clip_child); |
| 8486 | |
| 8487 | clip_child->SetClipParent(clip_parent.get()); |
| 8488 | |
| 8489 | intervening->SetMasksToBounds(true); |
| 8490 | clip_parent->SetMasksToBounds(true); |
| 8491 | |
| 8492 | render_surface1->SetForceRenderSurface(true); |
| 8493 | render_surface2->SetForceRenderSurface(true); |
| 8494 | |
| 8495 | gfx::Transform translation_transform; |
| 8496 | translation_transform.Translate(2, 2); |
| 8497 | |
| 8498 | gfx::Transform identity_transform; |
| 8499 | SetLayerPropertiesForTesting(root.get(), |
| 8500 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8501 | gfx::PointF(), |
| 8502 | gfx::PointF(), |
| 8503 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8504 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8505 | false); |
| 8506 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8507 | translation_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8508 | gfx::PointF(), |
| 8509 | gfx::PointF(1.f, 1.f), |
| 8510 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8511 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8512 | false); |
| 8513 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8514 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8515 | gfx::PointF(), |
| 8516 | gfx::PointF(), |
| 8517 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8518 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8519 | false); |
| 8520 | SetLayerPropertiesForTesting(intervening.get(), |
| 8521 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8522 | gfx::PointF(), |
| 8523 | gfx::PointF(1.f, 1.f), |
| 8524 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8525 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8526 | false); |
| 8527 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8528 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8529 | gfx::PointF(), |
| 8530 | gfx::PointF(), |
| 8531 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8532 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8533 | false); |
| 8534 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8535 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8536 | gfx::PointF(), |
| 8537 | gfx::PointF(-10.f, -10.f), |
| 8538 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8539 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8540 | false); |
| 8541 | |
| 8542 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8543 | host->SetRootLayer(root); |
| 8544 | |
| 8545 | ExecuteCalculateDrawProperties(root.get()); |
| 8546 | |
| 8547 | EXPECT_TRUE(root->render_surface()); |
| 8548 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8549 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8550 | |
| 8551 | // Since the render surfaces could have expanded, they should not clip (their |
| 8552 | // bounds would no longer be reliable). We should resort to layer clipping |
| 8553 | // in this case. |
| 8554 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8555 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8556 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8557 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8558 | render_surface2->render_surface()->clip_rect().ToString()); |
| 8559 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 8560 | |
| 8561 | // NB: clip rects are in target space. |
| 8562 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8563 | render_surface1->clip_rect().ToString()); |
| 8564 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8565 | |
| 8566 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 8567 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8568 | render_surface2->clip_rect().ToString()); |
| 8569 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 8570 | |
| 8571 | // The content rects of both render surfaces should both have expanded to |
| 8572 | // contain the clip child. |
| 8573 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8574 | render_surface1->render_surface()->content_rect().ToString()); |
| 8575 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 8576 | render_surface2->render_surface()->content_rect().ToString()); |
| 8577 | |
| 8578 | // The clip child should have inherited the clip parent's clip (projected to |
| 8579 | // the right space, of course), and should have the correctly sized visible |
| 8580 | // content rect. |
| 8581 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 8582 | clip_child->clip_rect().ToString()); |
| 8583 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 8584 | clip_child->visible_content_rect().ToString()); |
| 8585 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8586 | } |
| 8587 | |
| 8588 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 8589 | // Ensure that intervening render surfaces are not a problem, even if there |
| 8590 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 8591 | // of transform. |
| 8592 | // |
| 8593 | // root (a render surface) |
| 8594 | // + clip_parent (masks to bounds) |
| 8595 | // + render_surface1 (sets opacity) |
| 8596 | // + intervening (masks to bounds AND scrolls) |
| 8597 | // + render_surface2 (also sets opacity) |
| 8598 | // + clip_child |
| 8599 | // |
| 8600 | scoped_refptr<Layer> root = Layer::Create(); |
| 8601 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8602 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8603 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8604 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8605 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8606 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8607 | |
| 8608 | root->AddChild(clip_parent); |
| 8609 | clip_parent->AddChild(render_surface1); |
| 8610 | render_surface1->AddChild(intervening); |
| 8611 | intervening->AddChild(render_surface2); |
| 8612 | render_surface2->AddChild(clip_child); |
| 8613 | |
| 8614 | clip_child->SetClipParent(clip_parent.get()); |
| 8615 | |
| 8616 | intervening->SetMasksToBounds(true); |
| 8617 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8618 | intervening->SetScrollClipLayerId(clip_parent->id()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8619 | intervening->SetScrollOffset(gfx::Vector2d(3, 3)); |
| 8620 | |
| 8621 | render_surface1->SetForceRenderSurface(true); |
| 8622 | render_surface2->SetForceRenderSurface(true); |
| 8623 | |
| 8624 | gfx::Transform translation_transform; |
| 8625 | translation_transform.Translate(2, 2); |
| 8626 | |
| 8627 | gfx::Transform identity_transform; |
| 8628 | SetLayerPropertiesForTesting(root.get(), |
| 8629 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8630 | gfx::PointF(), |
| 8631 | gfx::PointF(), |
| 8632 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8633 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8634 | false); |
| 8635 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8636 | translation_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8637 | gfx::PointF(), |
| 8638 | gfx::PointF(1.f, 1.f), |
| 8639 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8640 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8641 | false); |
| 8642 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8643 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8644 | gfx::PointF(), |
| 8645 | gfx::PointF(), |
| 8646 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8647 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8648 | false); |
| 8649 | SetLayerPropertiesForTesting(intervening.get(), |
| 8650 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8651 | gfx::PointF(), |
| 8652 | gfx::PointF(1.f, 1.f), |
| 8653 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8654 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8655 | false); |
| 8656 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8657 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8658 | gfx::PointF(), |
| 8659 | gfx::PointF(), |
| 8660 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8661 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8662 | false); |
| 8663 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8664 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8665 | gfx::PointF(), |
| 8666 | gfx::PointF(-10.f, -10.f), |
| 8667 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8668 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8669 | false); |
| 8670 | |
| 8671 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8672 | host->SetRootLayer(root); |
| 8673 | |
| 8674 | ExecuteCalculateDrawProperties(root.get()); |
| 8675 | |
| 8676 | EXPECT_TRUE(root->render_surface()); |
| 8677 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8678 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8679 | |
| 8680 | // Since the render surfaces could have expanded, they should not clip (their |
| 8681 | // bounds would no longer be reliable). We should resort to layer clipping |
| 8682 | // in this case. |
| 8683 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8684 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8685 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8686 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8687 | render_surface2->render_surface()->clip_rect().ToString()); |
| 8688 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 8689 | |
| 8690 | // NB: clip rects are in target space. |
| 8691 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8692 | render_surface1->clip_rect().ToString()); |
| 8693 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8694 | |
| 8695 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 8696 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 8697 | render_surface2->clip_rect().ToString()); |
| 8698 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 8699 | |
| 8700 | // The content rects of both render surfaces should both have expanded to |
| 8701 | // contain the clip child. |
| 8702 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8703 | render_surface1->render_surface()->content_rect().ToString()); |
| 8704 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 8705 | render_surface2->render_surface()->content_rect().ToString()); |
| 8706 | |
| 8707 | // The clip child should have inherited the clip parent's clip (projected to |
| 8708 | // the right space, of course), and should have the correctly sized visible |
| 8709 | // content rect. |
| 8710 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 8711 | clip_child->clip_rect().ToString()); |
| 8712 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 8713 | clip_child->visible_content_rect().ToString()); |
| 8714 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8715 | } |
| 8716 | |
| 8717 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 8718 | // Ensures that descendants of the clip child inherit the correct clip. |
| 8719 | // |
| 8720 | // root (a render surface) |
| 8721 | // + clip_parent (masks to bounds) |
| 8722 | // + intervening (masks to bounds) |
| 8723 | // + clip_child |
| 8724 | // + child |
| 8725 | // |
| 8726 | scoped_refptr<Layer> root = Layer::Create(); |
| 8727 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8728 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8729 | scoped_refptr<Layer> clip_child = Layer::Create(); |
| 8730 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 8731 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8732 | |
| 8733 | root->AddChild(clip_parent); |
| 8734 | clip_parent->AddChild(intervening); |
| 8735 | intervening->AddChild(clip_child); |
| 8736 | clip_child->AddChild(child); |
| 8737 | |
| 8738 | clip_child->SetClipParent(clip_parent.get()); |
| 8739 | |
| 8740 | intervening->SetMasksToBounds(true); |
| 8741 | clip_parent->SetMasksToBounds(true); |
| 8742 | |
| 8743 | gfx::Transform identity_transform; |
| 8744 | SetLayerPropertiesForTesting(root.get(), |
| 8745 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8746 | gfx::PointF(), |
| 8747 | gfx::PointF(), |
| 8748 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8749 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8750 | false); |
| 8751 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8752 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8753 | gfx::PointF(), |
| 8754 | gfx::PointF(), |
| 8755 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8756 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8757 | false); |
| 8758 | SetLayerPropertiesForTesting(intervening.get(), |
| 8759 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8760 | gfx::PointF(), |
| 8761 | gfx::PointF(), |
| 8762 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8763 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8764 | false); |
| 8765 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8766 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8767 | gfx::PointF(), |
| 8768 | gfx::PointF(), |
| 8769 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8770 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8771 | false); |
| 8772 | SetLayerPropertiesForTesting(child.get(), |
| 8773 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8774 | gfx::PointF(), |
| 8775 | gfx::PointF(), |
| 8776 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8777 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8778 | false); |
| 8779 | |
| 8780 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8781 | host->SetRootLayer(root); |
| 8782 | |
| 8783 | ExecuteCalculateDrawProperties(root.get()); |
| 8784 | |
| 8785 | EXPECT_TRUE(root->render_surface()); |
| 8786 | |
| 8787 | // Neither the clip child nor its descendant should have inherited the clip |
| 8788 | // from |intervening|. |
| 8789 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8790 | clip_child->clip_rect().ToString()); |
| 8791 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8792 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8793 | child->visible_content_rect().ToString()); |
| 8794 | EXPECT_TRUE(child->is_clipped()); |
| 8795 | } |
| 8796 | |
| 8797 | TEST_F(LayerTreeHostCommonTest, |
| 8798 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 8799 | // Ensures that non-descendant clip children in the tree do not affect |
| 8800 | // render surfaces. |
| 8801 | // |
| 8802 | // root (a render surface) |
| 8803 | // + clip_parent (masks to bounds) |
| 8804 | // + render_surface1 |
| 8805 | // + clip_child |
| 8806 | // + render_surface2 |
| 8807 | // + non_clip_child |
| 8808 | // |
| 8809 | // In this example render_surface2 should be unaffected by clip_child. |
| 8810 | scoped_refptr<Layer> root = Layer::Create(); |
| 8811 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8812 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8813 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8814 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8815 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8816 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
| 8817 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8818 | |
| 8819 | root->AddChild(clip_parent); |
| 8820 | clip_parent->AddChild(render_surface1); |
| 8821 | render_surface1->AddChild(clip_child); |
| 8822 | clip_parent->AddChild(render_surface2); |
| 8823 | render_surface2->AddChild(non_clip_child); |
| 8824 | |
| 8825 | clip_child->SetClipParent(clip_parent.get()); |
| 8826 | |
| 8827 | clip_parent->SetMasksToBounds(true); |
| 8828 | render_surface1->SetMasksToBounds(true); |
| 8829 | |
| 8830 | gfx::Transform identity_transform; |
| 8831 | SetLayerPropertiesForTesting(root.get(), |
| 8832 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8833 | gfx::PointF(), |
| 8834 | gfx::PointF(), |
| 8835 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8836 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8837 | false); |
| 8838 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8839 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8840 | gfx::PointF(), |
| 8841 | gfx::PointF(), |
| 8842 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8843 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8844 | false); |
| 8845 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8846 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8847 | gfx::PointF(), |
| 8848 | gfx::PointF(5, 5), |
| 8849 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8850 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8851 | false); |
| 8852 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8853 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8854 | gfx::PointF(), |
| 8855 | gfx::PointF(), |
| 8856 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8857 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8858 | false); |
| 8859 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8860 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8861 | gfx::PointF(), |
| 8862 | gfx::PointF(-1, 1), |
| 8863 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8864 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8865 | false); |
| 8866 | SetLayerPropertiesForTesting(non_clip_child.get(), |
| 8867 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8868 | gfx::PointF(), |
| 8869 | gfx::PointF(), |
| 8870 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8871 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8872 | false); |
| 8873 | |
| 8874 | render_surface1->SetForceRenderSurface(true); |
| 8875 | render_surface2->SetForceRenderSurface(true); |
| 8876 | |
| 8877 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8878 | host->SetRootLayer(root); |
| 8879 | |
| 8880 | ExecuteCalculateDrawProperties(root.get()); |
| 8881 | |
| 8882 | EXPECT_TRUE(root->render_surface()); |
| 8883 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8884 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8885 | |
| 8886 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8887 | render_surface1->clip_rect().ToString()); |
| 8888 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8889 | |
| 8890 | // The render surface should not clip (it has unclipped descendants), instead |
| 8891 | // it should rely on layer clipping. |
| 8892 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8893 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8894 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8895 | |
| 8896 | // That said, it should have grown to accomodate the unclipped descendant. |
| 8897 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 8898 | render_surface1->render_surface()->content_rect().ToString()); |
| 8899 | |
| 8900 | // This render surface should clip. It has no unclipped descendants. |
| 8901 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8902 | render_surface2->clip_rect().ToString()); |
| 8903 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 8904 | |
| 8905 | // It also shouldn't have grown to accomodate the clip child. |
| 8906 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8907 | render_surface2->render_surface()->content_rect().ToString()); |
| 8908 | |
| 8909 | // Sanity check our num_unclipped_descendants values. |
| 8910 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 8911 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 8912 | } |
| 8913 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8914 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 8915 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8916 | TestSharedBitmapManager shared_bitmap_manager; |
| 8917 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8918 | scoped_ptr<LayerImpl> root = |
| 8919 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 8920 | scoped_ptr<LayerImpl> child1 = |
| 8921 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 8922 | scoped_ptr<LayerImpl> child2 = |
| 8923 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 8924 | scoped_ptr<LayerImpl> child3 = |
| 8925 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 8926 | |
| 8927 | gfx::Transform identity_matrix; |
| 8928 | gfx::PointF anchor; |
| 8929 | gfx::PointF position; |
| 8930 | gfx::Size bounds(100, 100); |
| 8931 | SetLayerPropertiesForTesting(root.get(), |
| 8932 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8933 | anchor, |
| 8934 | position, |
| 8935 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8936 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8937 | false); |
| 8938 | root->SetDrawsContent(true); |
| 8939 | |
| 8940 | // This layer structure normally forces render surface due to preserves3d |
| 8941 | // behavior. |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8942 | SetLayerPropertiesForTesting(child1.get(), |
| 8943 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8944 | anchor, |
| 8945 | position, |
| 8946 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8947 | false, |
| 8948 | true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8949 | child1->SetDrawsContent(true); |
| 8950 | SetLayerPropertiesForTesting(child2.get(), |
| 8951 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8952 | anchor, |
| 8953 | position, |
| 8954 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8955 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8956 | false); |
| 8957 | child2->SetDrawsContent(true); |
| 8958 | SetLayerPropertiesForTesting(child3.get(), |
| 8959 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8960 | anchor, |
| 8961 | position, |
| 8962 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8963 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8964 | false); |
| 8965 | child3->SetDrawsContent(true); |
| 8966 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8967 | child2->SetIs3dSorted(true); |
| 8968 | child3->SetIs3dSorted(true); |
| 8969 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8970 | child2->AddChild(child3.Pass()); |
| 8971 | child1->AddChild(child2.Pass()); |
| 8972 | root->AddChild(child1.Pass()); |
| 8973 | |
| 8974 | { |
| 8975 | LayerImplList render_surface_layer_list; |
| 8976 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8977 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8978 | inputs.can_render_to_separate_surface = true; |
| 8979 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8980 | |
| 8981 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 8982 | } |
| 8983 | |
| 8984 | { |
| 8985 | LayerImplList render_surface_layer_list; |
| 8986 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8987 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8988 | inputs.can_render_to_separate_surface = false; |
| 8989 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8990 | |
| 8991 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
| 8992 | } |
| 8993 | } |
| 8994 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 8995 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 8996 | scoped_refptr<Layer> root = Layer::Create(); |
| 8997 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 8998 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 8999 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9000 | |
| 9001 | root->AddChild(render_surface); |
| 9002 | render_surface->AddChild(child); |
| 9003 | |
| 9004 | gfx::Transform identity_transform; |
| 9005 | SetLayerPropertiesForTesting(root.get(), |
| 9006 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9007 | gfx::PointF(), |
| 9008 | gfx::PointF(), |
| 9009 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9010 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9011 | false); |
| 9012 | SetLayerPropertiesForTesting(render_surface.get(), |
| 9013 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9014 | gfx::PointF(), |
| 9015 | gfx::PointF(), |
| 9016 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9017 | false, |
| 9018 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9019 | SetLayerPropertiesForTesting(child.get(), |
| 9020 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9021 | gfx::PointF(), |
| 9022 | gfx::PointF(), |
| 9023 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9024 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9025 | false); |
| 9026 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9027 | root->SetShouldFlattenTransform(false); |
| 9028 | root->SetIs3dSorted(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9029 | render_surface->SetDoubleSided(false); |
| 9030 | render_surface->SetForceRenderSurface(true); |
| 9031 | |
| 9032 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9033 | host->SetRootLayer(root); |
| 9034 | |
| 9035 | ExecuteCalculateDrawProperties(root.get()); |
| 9036 | |
| 9037 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 9038 | EXPECT_EQ(1u, |
| 9039 | render_surface_layer_list()->at(0) |
| 9040 | ->render_surface()->layer_list().size()); |
| 9041 | EXPECT_EQ(1u, |
| 9042 | render_surface_layer_list()->at(1) |
| 9043 | ->render_surface()->layer_list().size()); |
| 9044 | |
| 9045 | gfx::Transform rotation_transform = identity_transform; |
| 9046 | rotation_transform.RotateAboutXAxis(180.0); |
| 9047 | |
| 9048 | render_surface->SetTransform(rotation_transform); |
| 9049 | |
| 9050 | ExecuteCalculateDrawProperties(root.get()); |
| 9051 | |
| 9052 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 9053 | EXPECT_EQ(0u, |
| 9054 | render_surface_layer_list()->at(0) |
| 9055 | ->render_surface()->layer_list().size()); |
| 9056 | } |
| 9057 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9058 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 9059 | // Checks that the simple case (being clipped by a scroll parent that would |
| 9060 | // have been processed before you anyhow) results in the right clips. |
| 9061 | // |
| 9062 | // + root |
| 9063 | // + scroll_parent_border |
| 9064 | // | + scroll_parent_clip |
| 9065 | // | + scroll_parent |
| 9066 | // + scroll_child |
| 9067 | // |
| 9068 | scoped_refptr<Layer> root = Layer::Create(); |
| 9069 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9070 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9071 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9072 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9073 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9074 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9075 | |
| 9076 | root->AddChild(scroll_child); |
| 9077 | |
| 9078 | root->AddChild(scroll_parent_border); |
| 9079 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9080 | scroll_parent_clip->AddChild(scroll_parent); |
| 9081 | |
| 9082 | scroll_parent_clip->SetMasksToBounds(true); |
| 9083 | |
| 9084 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9085 | |
| 9086 | gfx::Transform identity_transform; |
| 9087 | SetLayerPropertiesForTesting(root.get(), |
| 9088 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9089 | gfx::PointF(), |
| 9090 | gfx::PointF(), |
| 9091 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9092 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9093 | false); |
| 9094 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9095 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9096 | gfx::PointF(), |
| 9097 | gfx::PointF(), |
| 9098 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9099 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9100 | false); |
| 9101 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9102 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9103 | gfx::PointF(), |
| 9104 | gfx::PointF(), |
| 9105 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9106 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9107 | false); |
| 9108 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9109 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9110 | gfx::PointF(), |
| 9111 | gfx::PointF(), |
| 9112 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9113 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9114 | false); |
| 9115 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9116 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9117 | gfx::PointF(), |
| 9118 | gfx::PointF(), |
| 9119 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9120 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9121 | false); |
| 9122 | |
| 9123 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9124 | host->SetRootLayer(root); |
| 9125 | |
| 9126 | ExecuteCalculateDrawProperties(root.get()); |
| 9127 | |
| 9128 | EXPECT_TRUE(root->render_surface()); |
| 9129 | |
| 9130 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 9131 | scroll_child->clip_rect().ToString()); |
| 9132 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9133 | } |
| 9134 | |
| 9135 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 9136 | // Checks that clipping by a scroll parent that follows you in paint order |
| 9137 | // still results in correct clipping. |
| 9138 | // |
| 9139 | // + root |
| 9140 | // + scroll_child |
| 9141 | // + scroll_parent_border |
| 9142 | // + scroll_parent_clip |
| 9143 | // + scroll_parent |
| 9144 | // |
| 9145 | scoped_refptr<Layer> root = Layer::Create(); |
| 9146 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9147 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9148 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9149 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9150 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9151 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9152 | |
| 9153 | root->AddChild(scroll_parent_border); |
| 9154 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9155 | scroll_parent_clip->AddChild(scroll_parent); |
| 9156 | |
| 9157 | root->AddChild(scroll_child); |
| 9158 | |
| 9159 | scroll_parent_clip->SetMasksToBounds(true); |
| 9160 | |
| 9161 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9162 | |
| 9163 | gfx::Transform identity_transform; |
| 9164 | SetLayerPropertiesForTesting(root.get(), |
| 9165 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9166 | gfx::PointF(), |
| 9167 | gfx::PointF(), |
| 9168 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9169 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9170 | false); |
| 9171 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9172 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9173 | gfx::PointF(), |
| 9174 | gfx::PointF(), |
| 9175 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9176 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9177 | false); |
| 9178 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9179 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9180 | gfx::PointF(), |
| 9181 | gfx::PointF(), |
| 9182 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9183 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9184 | false); |
| 9185 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9186 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9187 | gfx::PointF(), |
| 9188 | gfx::PointF(), |
| 9189 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9190 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9191 | false); |
| 9192 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9193 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9194 | gfx::PointF(), |
| 9195 | gfx::PointF(), |
| 9196 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9197 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9198 | false); |
| 9199 | |
| 9200 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9201 | host->SetRootLayer(root); |
| 9202 | |
| 9203 | ExecuteCalculateDrawProperties(root.get()); |
| 9204 | |
| 9205 | EXPECT_TRUE(root->render_surface()); |
| 9206 | |
| 9207 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 9208 | scroll_child->clip_rect().ToString()); |
| 9209 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9210 | } |
| 9211 | |
| 9212 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 9213 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 9214 | // you in paint order still results in correct clipping. |
| 9215 | // |
| 9216 | // + root |
| 9217 | // + scroll_child |
| 9218 | // + scroll_parent_border |
| 9219 | // | + scroll_parent_clip |
| 9220 | // | + scroll_parent |
| 9221 | // + scroll_grandparent_border |
| 9222 | // + scroll_grandparent_clip |
| 9223 | // + scroll_grandparent |
| 9224 | // |
| 9225 | scoped_refptr<Layer> root = Layer::Create(); |
| 9226 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9227 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9228 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9229 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9230 | |
| 9231 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 9232 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 9233 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 9234 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9235 | |
| 9236 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9237 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9238 | |
| 9239 | root->AddChild(scroll_child); |
| 9240 | |
| 9241 | root->AddChild(scroll_parent_border); |
| 9242 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9243 | scroll_parent_clip->AddChild(scroll_parent); |
| 9244 | |
| 9245 | root->AddChild(scroll_grandparent_border); |
| 9246 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 9247 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 9248 | |
| 9249 | scroll_parent_clip->SetMasksToBounds(true); |
| 9250 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 9251 | |
| 9252 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9253 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 9254 | |
| 9255 | gfx::Transform identity_transform; |
| 9256 | SetLayerPropertiesForTesting(root.get(), |
| 9257 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9258 | gfx::PointF(), |
| 9259 | gfx::PointF(), |
| 9260 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9261 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9262 | false); |
| 9263 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 9264 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9265 | gfx::PointF(), |
| 9266 | gfx::PointF(), |
| 9267 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9268 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9269 | false); |
| 9270 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 9271 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9272 | gfx::PointF(), |
| 9273 | gfx::PointF(), |
| 9274 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9275 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9276 | false); |
| 9277 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 9278 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9279 | gfx::PointF(), |
| 9280 | gfx::PointF(), |
| 9281 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9282 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9283 | false); |
| 9284 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9285 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9286 | gfx::PointF(), |
| 9287 | gfx::PointF(), |
| 9288 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9289 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9290 | false); |
| 9291 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9292 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9293 | gfx::PointF(), |
| 9294 | gfx::PointF(), |
| 9295 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9296 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9297 | false); |
| 9298 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9299 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9300 | gfx::PointF(), |
| 9301 | gfx::PointF(), |
| 9302 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9303 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9304 | false); |
| 9305 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9306 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9307 | gfx::PointF(), |
| 9308 | gfx::PointF(), |
| 9309 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9310 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9311 | false); |
| 9312 | |
| 9313 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9314 | host->SetRootLayer(root); |
| 9315 | |
| 9316 | ExecuteCalculateDrawProperties(root.get()); |
| 9317 | |
| 9318 | EXPECT_TRUE(root->render_surface()); |
| 9319 | |
| 9320 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 9321 | scroll_child->clip_rect().ToString()); |
| 9322 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9323 | |
| 9324 | // Despite the fact that we visited the above layers out of order to get the |
| 9325 | // correct clip, the layer lists should be unaffected. |
| 9326 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 9327 | EXPECT_EQ(scroll_child.get(), |
| 9328 | root->render_surface()->layer_list().at(0)); |
| 9329 | EXPECT_EQ(scroll_parent.get(), |
| 9330 | root->render_surface()->layer_list().at(1)); |
| 9331 | EXPECT_EQ(scroll_grandparent.get(), |
| 9332 | root->render_surface()->layer_list().at(2)); |
| 9333 | } |
| 9334 | |
| 9335 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 9336 | // Ensures that even if we visit layers out of order, we still produce a |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 9337 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9338 | // + root |
| 9339 | // + scroll_child |
| 9340 | // + scroll_parent_border |
| 9341 | // + scroll_parent_clip |
| 9342 | // + scroll_parent |
| 9343 | // + render_surface1 |
| 9344 | // + scroll_grandparent_border |
| 9345 | // + scroll_grandparent_clip |
| 9346 | // + scroll_grandparent |
| 9347 | // + render_surface2 |
| 9348 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 9349 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 9350 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9351 | |
| 9352 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9353 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9354 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9355 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9356 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
| 9357 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9358 | |
| 9359 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 9360 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 9361 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 9362 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9363 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
| 9364 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9365 | |
| 9366 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9367 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9368 | |
| 9369 | root->AddChild(scroll_child); |
| 9370 | |
| 9371 | root->AddChild(scroll_parent_border); |
| 9372 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9373 | scroll_parent_clip->AddChild(scroll_parent); |
| 9374 | scroll_parent->AddChild(render_surface2); |
| 9375 | |
| 9376 | root->AddChild(scroll_grandparent_border); |
| 9377 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 9378 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 9379 | scroll_grandparent->AddChild(render_surface1); |
| 9380 | |
| 9381 | scroll_parent_clip->SetMasksToBounds(true); |
| 9382 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 9383 | |
| 9384 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9385 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 9386 | |
| 9387 | render_surface1->SetForceRenderSurface(true); |
| 9388 | render_surface2->SetForceRenderSurface(true); |
| 9389 | |
| 9390 | gfx::Transform identity_transform; |
| 9391 | SetLayerPropertiesForTesting(root.get(), |
| 9392 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9393 | gfx::PointF(), |
| 9394 | gfx::PointF(), |
| 9395 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9396 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9397 | false); |
| 9398 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 9399 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9400 | gfx::PointF(), |
| 9401 | gfx::PointF(), |
| 9402 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9403 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9404 | false); |
| 9405 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 9406 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9407 | gfx::PointF(), |
| 9408 | gfx::PointF(), |
| 9409 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9410 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9411 | false); |
| 9412 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 9413 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9414 | gfx::PointF(), |
| 9415 | gfx::PointF(), |
| 9416 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9417 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9418 | false); |
| 9419 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 9420 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9421 | gfx::PointF(), |
| 9422 | gfx::PointF(), |
| 9423 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9424 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9425 | false); |
| 9426 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9427 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9428 | gfx::PointF(), |
| 9429 | gfx::PointF(), |
| 9430 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9431 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9432 | false); |
| 9433 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9434 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9435 | gfx::PointF(), |
| 9436 | gfx::PointF(), |
| 9437 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9438 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9439 | false); |
| 9440 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9441 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9442 | gfx::PointF(), |
| 9443 | gfx::PointF(), |
| 9444 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9445 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9446 | false); |
| 9447 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 9448 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9449 | gfx::PointF(), |
| 9450 | gfx::PointF(), |
| 9451 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9452 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9453 | false); |
| 9454 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9455 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9456 | gfx::PointF(), |
| 9457 | gfx::PointF(), |
| 9458 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9459 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9460 | false); |
| 9461 | |
| 9462 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9463 | host->SetRootLayer(root); |
| 9464 | |
| 9465 | RenderSurfaceLayerList render_surface_layer_list; |
| 9466 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 9467 | root.get(), |
| 9468 | root->bounds(), |
| 9469 | identity_transform, |
| 9470 | &render_surface_layer_list); |
| 9471 | |
| 9472 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9473 | |
| 9474 | EXPECT_TRUE(root->render_surface()); |
| 9475 | |
| 9476 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 9477 | scroll_child->clip_rect().ToString()); |
| 9478 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9479 | |
| 9480 | // Despite the fact that we had to process the layers out of order to get the |
| 9481 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 9482 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 9483 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 9484 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 9485 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 9486 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 9487 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 9488 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9489 | } |
| 9490 | |
| 9491 | TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { |
| 9492 | // We rearrange layer list contributions if we have to visit children out of |
| 9493 | // order, but it should be a 'stable' rearrangement. That is, the layer list |
| 9494 | // additions for a single layer should not be reordered, though their position |
| 9495 | // wrt to the contributions due to a sibling may vary. |
| 9496 | // |
| 9497 | // + root |
| 9498 | // + scroll_child |
| 9499 | // + top_content |
| 9500 | // + bottom_content |
| 9501 | // + scroll_parent_border |
| 9502 | // + scroll_parent_clip |
| 9503 | // + scroll_parent |
| 9504 | // |
| 9505 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 9506 | TestSharedBitmapManager shared_bitmap_manager; |
| 9507 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9508 | host_impl.CreatePendingTree(); |
| 9509 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 9510 | scoped_ptr<LayerImpl> scroll_parent_border = |
| 9511 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9512 | scoped_ptr<LayerImpl> scroll_parent_clip = |
| 9513 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9514 | scoped_ptr<LayerImpl> scroll_parent = |
| 9515 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 9516 | scoped_ptr<LayerImpl> scroll_child = |
| 9517 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 9518 | scoped_ptr<LayerImpl> bottom_content = |
| 9519 | LayerImpl::Create(host_impl.active_tree(), 6); |
| 9520 | scoped_ptr<LayerImpl> top_content = |
| 9521 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 9522 | |
| 9523 | scroll_parent_clip->SetMasksToBounds(true); |
| 9524 | |
| 9525 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9526 | scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>); |
| 9527 | scroll_children->insert(scroll_child.get()); |
| 9528 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 9529 | |
| 9530 | scroll_child->SetDrawsContent(true); |
| 9531 | scroll_parent->SetDrawsContent(true); |
| 9532 | top_content->SetDrawsContent(true); |
| 9533 | bottom_content->SetDrawsContent(true); |
| 9534 | |
| 9535 | gfx::Transform identity_transform; |
| 9536 | gfx::Transform top_transform; |
| 9537 | top_transform.Translate3d(0.0, 0.0, 5.0); |
| 9538 | gfx::Transform bottom_transform; |
| 9539 | bottom_transform.Translate3d(0.0, 0.0, 3.0); |
| 9540 | |
| 9541 | SetLayerPropertiesForTesting(root.get(), |
| 9542 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9543 | gfx::PointF(), |
| 9544 | gfx::PointF(), |
| 9545 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9546 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9547 | false); |
| 9548 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9549 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9550 | gfx::PointF(), |
| 9551 | gfx::PointF(), |
| 9552 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9553 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9554 | false); |
| 9555 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9556 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9557 | gfx::PointF(), |
| 9558 | gfx::PointF(), |
| 9559 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9560 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9561 | false); |
| 9562 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9563 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9564 | gfx::PointF(), |
| 9565 | gfx::PointF(), |
| 9566 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9567 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9568 | false); |
| 9569 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9570 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9571 | gfx::PointF(), |
| 9572 | gfx::PointF(), |
| 9573 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9574 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9575 | false); |
| 9576 | SetLayerPropertiesForTesting(top_content.get(), |
| 9577 | top_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9578 | gfx::PointF(), |
| 9579 | gfx::PointF(), |
| 9580 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9581 | false, |
| 9582 | true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9583 | SetLayerPropertiesForTesting(bottom_content.get(), |
| 9584 | bottom_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9585 | gfx::PointF(), |
| 9586 | gfx::PointF(), |
| 9587 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9588 | false, |
| 9589 | true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9590 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9591 | scroll_child->SetShouldFlattenTransform(false); |
| 9592 | scroll_child->SetIs3dSorted(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9593 | |
| 9594 | scroll_child->AddChild(top_content.Pass()); |
| 9595 | scroll_child->AddChild(bottom_content.Pass()); |
| 9596 | root->AddChild(scroll_child.Pass()); |
| 9597 | |
| 9598 | scroll_parent_clip->AddChild(scroll_parent.Pass()); |
| 9599 | scroll_parent_border->AddChild(scroll_parent_clip.Pass()); |
| 9600 | root->AddChild(scroll_parent_border.Pass()); |
| 9601 | |
| 9602 | LayerImplList render_surface_layer_list; |
| 9603 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9604 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9605 | |
| 9606 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9607 | |
| 9608 | EXPECT_TRUE(root->render_surface()); |
| 9609 | |
| 9610 | // If we don't sort by depth and let the layers get added in the order they |
| 9611 | // would normally be visited in, then layers 6 and 7 will be out of order. In |
| 9612 | // other words, although we've had to shift 5, 6, and 7 to appear before 4 |
| 9613 | // in the list (because of the scroll parent relationship), this should not |
| 9614 | // have an effect on the the order of 5, 6, and 7 (which had been reordered |
| 9615 | // due to layer sorting). |
| 9616 | EXPECT_EQ(4u, root->render_surface()->layer_list().size()); |
| 9617 | EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id()); |
| 9618 | EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id()); |
| 9619 | EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id()); |
| 9620 | EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id()); |
| 9621 | } |
| 9622 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9623 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 9624 | // This test verifies that a scrolling layer that gets snapped to |
| 9625 | // integer coordinates doesn't move a fixed position child. |
| 9626 | // |
| 9627 | // + root |
| 9628 | // + container |
| 9629 | // + scroller |
| 9630 | // + fixed |
| 9631 | // |
| 9632 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 9633 | TestSharedBitmapManager shared_bitmap_manager; |
| 9634 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9635 | host_impl.CreatePendingTree(); |
| 9636 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 9637 | scoped_ptr<LayerImpl> container = |
| 9638 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9639 | LayerImpl* container_layer = container.get(); |
| 9640 | scoped_ptr<LayerImpl> scroller = |
| 9641 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9642 | LayerImpl* scroll_layer = scroller.get(); |
| 9643 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 9644 | LayerImpl* fixed_layer = fixed.get(); |
| 9645 | |
| 9646 | container->SetIsContainerForFixedPositionLayers(true); |
| 9647 | |
| 9648 | LayerPositionConstraint constraint; |
| 9649 | constraint.set_is_fixed_position(true); |
| 9650 | fixed->SetPositionConstraint(constraint); |
| 9651 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 9652 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9653 | |
| 9654 | gfx::Transform identity_transform; |
| 9655 | gfx::Transform container_transform; |
| 9656 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 9657 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 9658 | |
| 9659 | SetLayerPropertiesForTesting(root.get(), |
| 9660 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9661 | gfx::PointF(), |
| 9662 | gfx::PointF(), |
| 9663 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9664 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9665 | false); |
| 9666 | SetLayerPropertiesForTesting(container.get(), |
| 9667 | container_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9668 | gfx::PointF(), |
| 9669 | gfx::PointF(), |
| 9670 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9671 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9672 | false); |
| 9673 | SetLayerPropertiesForTesting(scroller.get(), |
| 9674 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9675 | gfx::PointF(), |
| 9676 | gfx::PointF(), |
| 9677 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9678 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9679 | false); |
| 9680 | SetLayerPropertiesForTesting(fixed.get(), |
| 9681 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9682 | gfx::PointF(), |
| 9683 | gfx::PointF(), |
| 9684 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9685 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9686 | false); |
| 9687 | |
| 9688 | scroller->AddChild(fixed.Pass()); |
| 9689 | container->AddChild(scroller.Pass()); |
| 9690 | root->AddChild(container.Pass()); |
| 9691 | |
| 9692 | // Rounded to integers already. |
| 9693 | { |
| 9694 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 9695 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9696 | |
| 9697 | LayerImplList render_surface_layer_list; |
| 9698 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9699 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9700 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9701 | |
| 9702 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9703 | container_layer->draw_properties().screen_space_transform, |
| 9704 | fixed_layer->draw_properties().screen_space_transform); |
| 9705 | EXPECT_VECTOR_EQ( |
| 9706 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9707 | container_offset); |
| 9708 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 9709 | .screen_space_transform.To2dTranslation(), |
| 9710 | container_offset - scroll_delta); |
| 9711 | } |
| 9712 | |
| 9713 | // Scroll delta requiring rounding. |
| 9714 | { |
| 9715 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 9716 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9717 | |
| 9718 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 9719 | |
| 9720 | LayerImplList render_surface_layer_list; |
| 9721 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9722 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9723 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9724 | |
| 9725 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9726 | container_layer->draw_properties().screen_space_transform, |
| 9727 | fixed_layer->draw_properties().screen_space_transform); |
| 9728 | EXPECT_VECTOR_EQ( |
| 9729 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9730 | container_offset); |
| 9731 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 9732 | .screen_space_transform.To2dTranslation(), |
| 9733 | container_offset - rounded_scroll_delta); |
| 9734 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 9735 | |
| 9736 | // Scale is applied earlier in the tree. |
| 9737 | { |
| 9738 | gfx::Transform scaled_container_transform = container_transform; |
| 9739 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 9740 | container_layer->SetTransform(scaled_container_transform); |
| 9741 | |
| 9742 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 9743 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9744 | |
| 9745 | LayerImplList render_surface_layer_list; |
| 9746 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9747 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9748 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9749 | |
| 9750 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9751 | container_layer->draw_properties().screen_space_transform, |
| 9752 | fixed_layer->draw_properties().screen_space_transform); |
| 9753 | EXPECT_VECTOR_EQ( |
| 9754 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9755 | container_offset); |
| 9756 | |
| 9757 | container_layer->SetTransform(container_transform); |
| 9758 | } |
| 9759 | |
| 9760 | // Scale is applied on the scroll layer itself. |
| 9761 | { |
| 9762 | gfx::Transform scale_transform; |
| 9763 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 9764 | scroll_layer->SetTransform(scale_transform); |
| 9765 | |
| 9766 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 9767 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9768 | |
| 9769 | LayerImplList render_surface_layer_list; |
| 9770 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9771 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9772 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9773 | |
| 9774 | EXPECT_VECTOR_EQ( |
| 9775 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9776 | container_offset); |
| 9777 | |
| 9778 | scroll_layer->SetTransform(identity_transform); |
| 9779 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9780 | } |
| 9781 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 9782 | } // namespace |
| 9783 | } // namespace cc |