[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] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 10 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 11 | #include "cc/base/math_util.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 12 | #include "cc/layers/content_layer.h" |
| 13 | #include "cc/layers/content_layer_client.h" |
| 14 | #include "cc/layers/heads_up_display_layer_impl.h" |
| 15 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 16 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 17 | #include "cc/layers/layer_impl.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 18 | #include "cc/layers/render_surface.h" |
| 19 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 20 | #include "cc/output/copy_output_request.h" |
| 21 | #include "cc/output/copy_output_result.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 22 | #include "cc/test/animation_test_common.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 23 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 24 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 25 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 26 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 27 | #include "cc/trees/layer_tree_impl.h" |
| 28 | #include "cc/trees/proxy.h" |
| 29 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 30 | #include "testing/gmock/include/gmock/gmock.h" |
| 31 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 93698c1 | 2012-12-07 00:43:56 | [diff] [blame] | 32 | #include "ui/gfx/quad_f.h" |
| 33 | #include "ui/gfx/size_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 34 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 35 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 36 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 37 | namespace { |
| 38 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 39 | class LayerTreeHostCommonTestBase { |
| 40 | protected: |
| 41 | template <typename LayerType> |
| 42 | void SetLayerPropertiesForTestingInternal( |
| 43 | LayerType* layer, |
| 44 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 45 | const gfx::PointF& anchor, |
| 46 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 47 | const gfx::Size& bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 48 | bool flatten_transform, |
| 49 | bool is_3d_sorted) { |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 50 | layer->SetTransform(transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 51 | layer->SetAnchorPoint(anchor); |
| 52 | layer->SetPosition(position); |
| 53 | layer->SetBounds(bounds); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 54 | layer->SetShouldFlattenTransform(flatten_transform); |
| 55 | layer->SetIs3dSorted(is_3d_sorted); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 56 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 57 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 58 | void SetLayerPropertiesForTesting(Layer* layer, |
| 59 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 60 | const gfx::PointF& anchor, |
| 61 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 62 | const gfx::Size& bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 63 | bool flatten_transform, |
| 64 | bool is_3d_sorted) { |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 65 | SetLayerPropertiesForTestingInternal<Layer>(layer, |
| 66 | transform, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 67 | anchor, |
| 68 | position, |
| 69 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 70 | flatten_transform, |
| 71 | is_3d_sorted); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 72 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 73 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 74 | void SetLayerPropertiesForTesting(LayerImpl* layer, |
| 75 | const gfx::Transform& transform, |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 76 | const gfx::PointF& anchor, |
| 77 | const gfx::PointF& position, |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 78 | const gfx::Size& bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 79 | bool flatten_transform, |
| 80 | bool is_3d_sorted) { |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 81 | SetLayerPropertiesForTestingInternal<LayerImpl>(layer, |
| 82 | transform, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 83 | anchor, |
| 84 | position, |
| 85 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 86 | flatten_transform, |
| 87 | is_3d_sorted); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 88 | layer->SetContentBounds(bounds); |
| 89 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 90 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 91 | void ExecuteCalculateDrawProperties(Layer* root_layer, |
| 92 | float device_scale_factor, |
| 93 | float page_scale_factor, |
| 94 | Layer* page_scale_application_layer, |
| 95 | bool can_use_lcd_text) { |
| 96 | EXPECT_TRUE(page_scale_application_layer || (page_scale_factor == 1.f)); |
| 97 | gfx::Transform identity_matrix; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 98 | gfx::Size device_viewport_size = |
| 99 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 100 | root_layer->bounds().height() * device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 101 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 102 | render_surface_layer_list_.reset(new RenderSurfaceLayerList); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 104 | // We are probably not testing what is intended if the root_layer bounds are |
| 105 | // empty. |
| 106 | DCHECK(!root_layer->bounds().IsEmpty()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 107 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 108 | root_layer, device_viewport_size, render_surface_layer_list_.get()); |
| 109 | inputs.device_scale_factor = device_scale_factor; |
| 110 | inputs.page_scale_factor = page_scale_factor; |
| 111 | inputs.page_scale_application_layer = page_scale_application_layer; |
| 112 | inputs.can_use_lcd_text = can_use_lcd_text; |
| 113 | inputs.can_adjust_raster_scales = true; |
| 114 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 115 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 116 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 117 | void ExecuteCalculateDrawProperties(LayerImpl* root_layer, |
| 118 | float device_scale_factor, |
| 119 | float page_scale_factor, |
| 120 | LayerImpl* page_scale_application_layer, |
| 121 | bool can_use_lcd_text) { |
| 122 | gfx::Transform identity_matrix; |
| 123 | LayerImplList dummy_render_surface_layer_list; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 124 | gfx::Size device_viewport_size = |
| 125 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 126 | root_layer->bounds().height() * device_scale_factor); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 127 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 128 | // We are probably not testing what is intended if the root_layer bounds are |
| 129 | // empty. |
| 130 | DCHECK(!root_layer->bounds().IsEmpty()); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 131 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 132 | root_layer, device_viewport_size, &dummy_render_surface_layer_list); |
| 133 | inputs.device_scale_factor = device_scale_factor; |
| 134 | inputs.page_scale_factor = page_scale_factor; |
| 135 | inputs.page_scale_application_layer = page_scale_application_layer; |
| 136 | inputs.can_use_lcd_text = can_use_lcd_text; |
| 137 | inputs.can_adjust_raster_scales = true; |
| 138 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 139 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 140 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 141 | template <class LayerType> |
| 142 | void ExecuteCalculateDrawProperties(LayerType* root_layer) { |
| 143 | LayerType* page_scale_application_layer = NULL; |
| 144 | ExecuteCalculateDrawProperties( |
| 145 | root_layer, 1.f, 1.f, page_scale_application_layer, false); |
| 146 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 147 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 148 | template <class LayerType> |
| 149 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 150 | float device_scale_factor) { |
| 151 | LayerType* page_scale_application_layer = NULL; |
| 152 | ExecuteCalculateDrawProperties(root_layer, |
| 153 | device_scale_factor, |
| 154 | 1.f, |
| 155 | page_scale_application_layer, |
| 156 | false); |
| 157 | } |
| 158 | |
| 159 | template <class LayerType> |
| 160 | void ExecuteCalculateDrawProperties(LayerType* root_layer, |
| 161 | float device_scale_factor, |
| 162 | float page_scale_factor, |
| 163 | LayerType* page_scale_application_layer) { |
| 164 | ExecuteCalculateDrawProperties(root_layer, |
| 165 | device_scale_factor, |
| 166 | page_scale_factor, |
| 167 | page_scale_application_layer, |
| 168 | false); |
| 169 | } |
| 170 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 171 | RenderSurfaceLayerList* render_surface_layer_list() const { |
| 172 | return render_surface_layer_list_.get(); |
| 173 | } |
| 174 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 175 | private: |
| 176 | scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_; |
| 177 | }; |
| 178 | |
| 179 | class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase, |
| 180 | public testing::Test { |
| 181 | }; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 182 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 183 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 184 | public: |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 185 | LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 186 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 187 | virtual bool DrawsContent() const OVERRIDE; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 188 | virtual void CalculateContentsScale(float ideal_contents_scale, |
| 189 | float device_scale_factor, |
| 190 | float page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 191 | float maximum_animation_contents_scale, |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 192 | bool animating_transform_to_screen, |
| 193 | float* contents_scale_x, |
| 194 | float* contents_scale_y, |
| 195 | gfx::Size* content_bounds) OVERRIDE; |
| 196 | |
| 197 | float last_device_scale_factor() const { return last_device_scale_factor_; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 198 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 199 | private: |
| 200 | virtual ~LayerWithForcedDrawsContent() {} |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 201 | |
| 202 | // Parameters from last CalculateContentsScale. |
| 203 | float last_device_scale_factor_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 204 | }; |
| 205 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 206 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 207 | |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 208 | void LayerWithForcedDrawsContent::CalculateContentsScale( |
| 209 | float ideal_contents_scale, |
| 210 | float device_scale_factor, |
| 211 | float page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 212 | float maximum_animation_contents_scale, |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 213 | bool animating_transform_to_screen, |
| 214 | float* contents_scale_x, |
| 215 | float* contents_scale_y, |
| 216 | gfx::Size* content_bounds) { |
| 217 | last_device_scale_factor_ = device_scale_factor; |
| 218 | Layer::CalculateContentsScale(ideal_contents_scale, |
| 219 | device_scale_factor, |
| 220 | page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 221 | maximum_animation_contents_scale, |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 222 | animating_transform_to_screen, |
| 223 | contents_scale_x, |
| 224 | contents_scale_y, |
| 225 | content_bounds); |
| 226 | } |
| 227 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 228 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 229 | public: |
| 230 | MockContentLayerClient() {} |
| 231 | virtual ~MockContentLayerClient() {} |
[email protected] | 276172b | 2014-05-02 21:03:03 | [diff] [blame^] | 232 | virtual void PaintContents( |
| 233 | SkCanvas* canvas, |
| 234 | const gfx::Rect& clip, |
| 235 | gfx::RectF* opaque, |
| 236 | ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {} |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 237 | virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} |
[email protected] | 1d96e03 | 2014-03-25 05:59:08 | [diff] [blame] | 238 | virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 239 | }; |
| 240 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 241 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 242 | ContentLayerClient* delegate) { |
| 243 | scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 244 | to_return->SetIsDrawable(true); |
| 245 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 246 | } |
| 247 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 248 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 249 | do { \ |
| 250 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 251 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 252 | } while (false) |
| 253 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 254 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 255 | // Sanity check: For layers positioned at zero, with zero size, |
| 256 | // and with identity transforms, then the draw transform, |
| 257 | // screen space transform, and the hierarchy passed on to children |
| 258 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 259 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 260 | scoped_refptr<Layer> parent = Layer::Create(); |
| 261 | scoped_refptr<Layer> child = Layer::Create(); |
| 262 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 263 | parent->AddChild(child); |
| 264 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 265 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 266 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 267 | host->SetRootLayer(parent); |
| 268 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 269 | gfx::Transform identity_matrix; |
| 270 | SetLayerPropertiesForTesting(parent.get(), |
| 271 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 272 | gfx::PointF(), |
| 273 | gfx::PointF(), |
| 274 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 275 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 276 | false); |
| 277 | SetLayerPropertiesForTesting(child.get(), |
| 278 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 279 | gfx::PointF(), |
| 280 | gfx::PointF(), |
| 281 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 282 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 283 | false); |
| 284 | SetLayerPropertiesForTesting(grand_child.get(), |
| 285 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 286 | gfx::PointF(), |
| 287 | gfx::PointF(), |
| 288 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 289 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 290 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 291 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 292 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 293 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 294 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 295 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 296 | child->screen_space_transform()); |
| 297 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 298 | grand_child->draw_transform()); |
| 299 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 300 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 301 | } |
| 302 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 303 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 304 | gfx::Transform identity_matrix; |
| 305 | scoped_refptr<Layer> layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 306 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 307 | scoped_refptr<Layer> root = Layer::Create(); |
| 308 | SetLayerPropertiesForTesting(root.get(), |
| 309 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 310 | gfx::PointF(), |
| 311 | gfx::PointF(), |
| 312 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 313 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 314 | false); |
| 315 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 316 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 317 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 318 | host->SetRootLayer(root); |
| 319 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 320 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 321 | // transform or the screenspace transform. |
| 322 | gfx::Transform translation_to_center; |
| 323 | translation_to_center.Translate(5.0, 6.0); |
| 324 | SetLayerPropertiesForTesting(layer.get(), |
| 325 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 326 | gfx::PointF(), |
| 327 | gfx::PointF(), |
| 328 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 329 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 330 | false); |
| 331 | ExecuteCalculateDrawProperties(root.get()); |
| 332 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 333 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 334 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 335 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 336 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 337 | // no effect on the transforms. |
| 338 | SetLayerPropertiesForTesting(layer.get(), |
| 339 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 340 | gfx::PointF(0.25f, 0.25f), |
| 341 | gfx::PointF(), |
| 342 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 343 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 344 | false); |
| 345 | ExecuteCalculateDrawProperties(root.get()); |
| 346 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 347 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 348 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 349 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 350 | // Case 4: A change in actual position affects both the draw transform and |
| 351 | // screen space transform. |
| 352 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 353 | position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 354 | SetLayerPropertiesForTesting(layer.get(), |
| 355 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 356 | gfx::PointF(0.25f, 0.25f), |
| 357 | gfx::PointF(0.f, 1.2f), |
| 358 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 359 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 360 | false); |
| 361 | ExecuteCalculateDrawProperties(root.get()); |
| 362 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 363 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 364 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 365 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 366 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 367 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 368 | // scale transform, because scale and translation are not commutative. |
| 369 | gfx::Transform layer_transform; |
| 370 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 371 | SetLayerPropertiesForTesting(layer.get(), |
| 372 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 373 | gfx::PointF(), |
| 374 | gfx::PointF(), |
| 375 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 376 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 377 | false); |
| 378 | ExecuteCalculateDrawProperties(root.get()); |
| 379 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 380 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 381 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 382 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 383 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 384 | gfx::Transform translation_to_anchor; |
| 385 | translation_to_anchor.Translate(5.0, 0.0); |
| 386 | gfx::Transform expected_result = |
| 387 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 388 | SetLayerPropertiesForTesting(layer.get(), |
| 389 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 390 | gfx::PointF(0.5f, 0.f), |
| 391 | gfx::PointF(), |
| 392 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 393 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 394 | false); |
| 395 | ExecuteCalculateDrawProperties(root.get()); |
| 396 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 397 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 398 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 399 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 400 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 401 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 402 | // it is still worth testing to detect accidental regressions. |
| 403 | expected_result = position_transform * translation_to_anchor * |
| 404 | layer_transform * Inverse(translation_to_anchor); |
| 405 | SetLayerPropertiesForTesting(layer.get(), |
| 406 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 407 | gfx::PointF(0.5f, 0.f), |
| 408 | gfx::PointF(0.f, 1.2f), |
| 409 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 410 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 411 | false); |
| 412 | ExecuteCalculateDrawProperties(root.get()); |
| 413 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 414 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 415 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 418 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 419 | const gfx::Vector2d kScrollOffset(50, 100); |
| 420 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 421 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 422 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 423 | -kScrollOffset.y()); |
| 424 | const float kPageScale = 0.888f; |
| 425 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 426 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 427 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 428 | TestSharedBitmapManager shared_bitmap_manager; |
| 429 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 430 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 431 | gfx::Transform identity_matrix; |
| 432 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 433 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 434 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 435 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 436 | kPageScale * kDeviceScale); |
| 437 | SetLayerPropertiesForTesting(sublayer, |
| 438 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 439 | gfx::Point(), |
| 440 | gfx::PointF(), |
| 441 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 442 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 443 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 444 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 445 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 446 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 447 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 448 | SetLayerPropertiesForTesting(scroll_layer, |
| 449 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 450 | gfx::PointF(), |
[email protected] | 4ec78f8 | 2013-07-11 18:45:47 | [diff] [blame] | 451 | gfx::PointF(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 452 | gfx::Size(10, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 453 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 454 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 455 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 456 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 457 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 458 | |
| 459 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 460 | clip_layer->SetBounds( |
| 461 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 462 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 463 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 464 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 465 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 466 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 467 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
| 468 | clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
| 469 | scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 470 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 471 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
| 472 | SetLayerPropertiesForTesting(root.get(), |
| 473 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 474 | gfx::PointF(), |
| 475 | gfx::PointF(), |
| 476 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 477 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 478 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 479 | root->AddChild(clip_layer_scoped_ptr.Pass()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 480 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 481 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 482 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 483 | gfx::Transform expected_transform = identity_matrix; |
| 484 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 485 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 486 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 487 | MathUtil::Round(sub_layer_screen_position.y())); |
| 488 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 489 | sublayer->draw_transform()); |
| 490 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 491 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 492 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 493 | gfx::Transform arbitrary_translate; |
| 494 | const float kTranslateX = 10.6f; |
| 495 | const float kTranslateY = 20.6f; |
| 496 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
| 497 | SetLayerPropertiesForTesting(scroll_layer, |
| 498 | arbitrary_translate, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 499 | gfx::PointF(), |
[email protected] | 4ec78f8 | 2013-07-11 18:45:47 | [diff] [blame] | 500 | gfx::PointF(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 501 | gfx::Size(10, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 502 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 503 | false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 504 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 505 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 506 | expected_transform.MakeIdentity(); |
| 507 | expected_transform.Translate( |
| 508 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 509 | sub_layer_screen_position.x()), |
| 510 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 511 | sub_layer_screen_position.y())); |
| 512 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 513 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 514 | } |
| 515 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 516 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 517 | gfx::Transform identity_matrix; |
| 518 | scoped_refptr<Layer> root = Layer::Create(); |
| 519 | scoped_refptr<Layer> parent = Layer::Create(); |
| 520 | scoped_refptr<Layer> child = Layer::Create(); |
| 521 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 522 | root->AddChild(parent); |
| 523 | parent->AddChild(child); |
| 524 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 525 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 526 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 527 | host->SetRootLayer(root); |
| 528 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 529 | // One-time setup of root layer |
| 530 | SetLayerPropertiesForTesting(root.get(), |
| 531 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 532 | gfx::PointF(), |
| 533 | gfx::PointF(), |
| 534 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 535 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 536 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 537 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 538 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 539 | SetLayerPropertiesForTesting(parent.get(), |
| 540 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 541 | gfx::PointF(0.25f, 0.25f), |
| 542 | gfx::PointF(), |
| 543 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 544 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 545 | false); |
| 546 | SetLayerPropertiesForTesting(child.get(), |
| 547 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 548 | gfx::PointF(), |
| 549 | gfx::PointF(), |
| 550 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 551 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 552 | false); |
| 553 | SetLayerPropertiesForTesting(grand_child.get(), |
| 554 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 555 | gfx::PointF(), |
| 556 | gfx::PointF(), |
| 557 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 558 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 559 | false); |
| 560 | ExecuteCalculateDrawProperties(root.get()); |
| 561 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 562 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 563 | child->screen_space_transform()); |
| 564 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 565 | grand_child->draw_transform()); |
| 566 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 567 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 568 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 569 | // Case 2: parent's position affects child and grand_child. |
| 570 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 571 | parent_position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 572 | SetLayerPropertiesForTesting(parent.get(), |
| 573 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 574 | gfx::PointF(0.25f, 0.25f), |
| 575 | gfx::PointF(0.f, 1.2f), |
| 576 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 577 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 578 | false); |
| 579 | SetLayerPropertiesForTesting(child.get(), |
| 580 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 581 | gfx::PointF(), |
| 582 | gfx::PointF(), |
| 583 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 584 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 585 | false); |
| 586 | SetLayerPropertiesForTesting(grand_child.get(), |
| 587 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 588 | gfx::PointF(), |
| 589 | gfx::PointF(), |
| 590 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 591 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 592 | false); |
| 593 | ExecuteCalculateDrawProperties(root.get()); |
| 594 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 595 | child->draw_transform()); |
| 596 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 597 | child->screen_space_transform()); |
| 598 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 599 | grand_child->draw_transform()); |
| 600 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 601 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 602 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 603 | // Case 3: parent's local transform affects child and grandchild |
| 604 | gfx::Transform parent_layer_transform; |
| 605 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 606 | gfx::Transform parent_translation_to_anchor; |
| 607 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 608 | gfx::Transform parent_composite_transform = |
| 609 | parent_translation_to_anchor * parent_layer_transform * |
| 610 | Inverse(parent_translation_to_anchor); |
| 611 | SetLayerPropertiesForTesting(parent.get(), |
| 612 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 613 | gfx::PointF(0.25f, 0.25f), |
| 614 | gfx::PointF(), |
| 615 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 616 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 617 | false); |
| 618 | SetLayerPropertiesForTesting(child.get(), |
| 619 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 620 | gfx::PointF(), |
| 621 | gfx::PointF(), |
| 622 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 623 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 624 | false); |
| 625 | SetLayerPropertiesForTesting(grand_child.get(), |
| 626 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 627 | gfx::PointF(), |
| 628 | gfx::PointF(), |
| 629 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 630 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 631 | false); |
| 632 | ExecuteCalculateDrawProperties(root.get()); |
| 633 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 634 | child->draw_transform()); |
| 635 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 636 | child->screen_space_transform()); |
| 637 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 638 | grand_child->draw_transform()); |
| 639 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 640 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 641 | } |
| 642 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 643 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 644 | scoped_refptr<Layer> root = Layer::Create(); |
| 645 | scoped_refptr<Layer> parent = Layer::Create(); |
| 646 | scoped_refptr<Layer> child = Layer::Create(); |
| 647 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 648 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 649 | root->AddChild(parent); |
| 650 | parent->AddChild(child); |
| 651 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 652 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 653 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 654 | host->SetRootLayer(root); |
| 655 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 656 | // One-time setup of root layer |
| 657 | gfx::Transform identity_matrix; |
| 658 | SetLayerPropertiesForTesting(root.get(), |
| 659 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 660 | gfx::PointF(), |
| 661 | gfx::PointF(), |
| 662 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 663 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 664 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 665 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 666 | // Child is set up so that a new render surface should be created. |
| 667 | child->SetOpacity(0.5f); |
| 668 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 669 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 670 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 671 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 672 | gfx::Transform parent_translation_to_anchor; |
| 673 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 674 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 675 | gfx::Transform parent_composite_transform = |
| 676 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 677 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 678 | gfx::Vector2dF parent_composite_scale = |
| 679 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 680 | 1.f); |
| 681 | gfx::Transform surface_sublayer_transform; |
| 682 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 683 | parent_composite_scale.y()); |
| 684 | gfx::Transform surface_sublayer_composite_transform = |
| 685 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 686 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 687 | // Child's render surface should not exist yet. |
| 688 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 689 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 690 | SetLayerPropertiesForTesting(parent.get(), |
| 691 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 692 | gfx::PointF(0.25f, 0.25f), |
| 693 | gfx::PointF(), |
| 694 | gfx::Size(100, 120), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 695 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 696 | false); |
| 697 | SetLayerPropertiesForTesting(child.get(), |
| 698 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 699 | gfx::PointF(), |
| 700 | gfx::PointF(), |
| 701 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 702 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 703 | false); |
| 704 | SetLayerPropertiesForTesting(grand_child.get(), |
| 705 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 706 | gfx::PointF(), |
| 707 | gfx::PointF(), |
| 708 | gfx::Size(8, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 709 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 710 | false); |
| 711 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 712 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 713 | // Render surface should have been created now. |
| 714 | ASSERT_TRUE(child->render_surface()); |
| 715 | ASSERT_EQ(child, child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 716 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 717 | // The child layer's draw transform should refer to its new render surface. |
| 718 | // The screen-space transform, however, should still refer to the root. |
| 719 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 720 | child->draw_transform()); |
| 721 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 722 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 723 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 724 | // Because the grand_child is the only drawable content, the child's render |
| 725 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 726 | // surface's subtree is drawn must be removed from the composite transform. |
| 727 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 728 | surface_sublayer_composite_transform, |
| 729 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 730 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 731 | // The screen space is the same as the target since the child surface draws |
| 732 | // into the root. |
| 733 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 734 | surface_sublayer_composite_transform, |
| 735 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 736 | } |
| 737 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 738 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 739 | scoped_refptr<Layer> root = Layer::Create(); |
| 740 | scoped_refptr<Layer> parent = Layer::Create(); |
| 741 | scoped_refptr<Layer> child = Layer::Create(); |
| 742 | scoped_refptr<Layer> child_replica = Layer::Create(); |
| 743 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 744 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 745 | root->AddChild(parent); |
| 746 | parent->AddChild(child); |
| 747 | child->AddChild(grand_child); |
| 748 | child->SetReplicaLayer(child_replica.get()); |
| 749 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 750 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 751 | host->SetRootLayer(root); |
| 752 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 753 | // One-time setup of root layer |
| 754 | gfx::Transform identity_matrix; |
| 755 | SetLayerPropertiesForTesting(root.get(), |
| 756 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 757 | gfx::PointF(), |
| 758 | gfx::PointF(), |
| 759 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 760 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 761 | false); |
| 762 | |
| 763 | // Child is set up so that a new render surface should be created. |
| 764 | child->SetOpacity(0.5f); |
| 765 | |
| 766 | gfx::Transform parent_layer_transform; |
| 767 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 768 | gfx::Transform parent_translation_to_anchor; |
| 769 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 770 | gfx::Transform parent_composite_transform = |
| 771 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 772 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 773 | gfx::Transform replica_layer_transform; |
| 774 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 775 | gfx::Vector2dF parent_composite_scale = |
| 776 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 777 | 1.f); |
| 778 | gfx::Transform surface_sublayer_transform; |
| 779 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 780 | parent_composite_scale.y()); |
| 781 | gfx::Transform replica_composite_transform = |
| 782 | parent_composite_transform * replica_layer_transform * |
| 783 | Inverse(surface_sublayer_transform); |
| 784 | |
| 785 | // Child's render surface should not exist yet. |
| 786 | ASSERT_FALSE(child->render_surface()); |
| 787 | |
| 788 | SetLayerPropertiesForTesting(parent.get(), |
| 789 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 790 | gfx::PointF(0.25f, 0.25f), |
| 791 | gfx::PointF(), |
| 792 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 793 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 794 | false); |
| 795 | SetLayerPropertiesForTesting(child.get(), |
| 796 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 797 | gfx::PointF(), |
| 798 | gfx::PointF(), |
| 799 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 800 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 801 | false); |
| 802 | SetLayerPropertiesForTesting(grand_child.get(), |
| 803 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 804 | gfx::PointF(), |
| 805 | gfx::PointF(-0.5f, -0.5f), |
| 806 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 807 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 808 | false); |
| 809 | SetLayerPropertiesForTesting(child_replica.get(), |
| 810 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 811 | gfx::PointF(), |
| 812 | gfx::PointF(), |
| 813 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 814 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 815 | false); |
| 816 | ExecuteCalculateDrawProperties(root.get()); |
| 817 | |
| 818 | // Render surface should have been created now. |
| 819 | ASSERT_TRUE(child->render_surface()); |
| 820 | ASSERT_EQ(child, child->render_target()); |
| 821 | |
| 822 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 823 | replica_composite_transform, |
| 824 | child->render_target()->render_surface()->replica_draw_transform()); |
| 825 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 826 | child->render_target() |
| 827 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 828 | ->replica_screen_space_transform()); |
| 829 | } |
| 830 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 831 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 832 | // This test creates a more complex tree and verifies it all at once. This |
| 833 | // covers the following cases: |
| 834 | // - layers that are described w.r.t. a render surface: should have draw |
| 835 | // transforms described w.r.t. that surface |
| 836 | // - A render surface described w.r.t. an ancestor render surface: should |
| 837 | // have a draw transform described w.r.t. that ancestor surface |
| 838 | // - Replicas of a render surface are described w.r.t. the replica's |
| 839 | // transform around its anchor, along with the surface itself. |
| 840 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 841 | // a render surface that is described w.r.t. an ancestor render surface. |
| 842 | // - verifying that each layer has a reference to the correct render surface |
| 843 | // and render target values. |
| 844 | |
| 845 | scoped_refptr<Layer> root = Layer::Create(); |
| 846 | scoped_refptr<Layer> parent = Layer::Create(); |
| 847 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 848 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 849 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 850 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 851 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 852 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); |
| 853 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); |
| 854 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 855 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 856 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 857 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 858 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 859 | root->AddChild(parent); |
| 860 | parent->AddChild(render_surface1); |
| 861 | parent->AddChild(child_of_root); |
| 862 | render_surface1->AddChild(child_of_rs1); |
| 863 | render_surface1->AddChild(render_surface2); |
| 864 | render_surface2->AddChild(child_of_rs2); |
| 865 | child_of_root->AddChild(grand_child_of_root); |
| 866 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 867 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 868 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 869 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 870 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 871 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 872 | host->SetRootLayer(root); |
| 873 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 874 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 875 | // to have a new render surface. |
| 876 | render_surface1->SetOpacity(0.5f); |
| 877 | render_surface2->SetOpacity(0.33f); |
| 878 | |
| 879 | // One-time setup of root layer |
| 880 | gfx::Transform identity_matrix; |
| 881 | SetLayerPropertiesForTesting(root.get(), |
| 882 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 883 | gfx::PointF(), |
| 884 | gfx::PointF(), |
| 885 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 886 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 887 | false); |
| 888 | |
| 889 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 890 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 891 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 892 | gfx::Transform translation_to_anchor; |
| 893 | translation_to_anchor.Translate(2.5, 0.0); |
| 894 | gfx::Transform layer_transform; |
| 895 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 896 | gfx::Transform replica_layer_transform; |
| 897 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 898 | |
| 899 | gfx::Transform A = |
| 900 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 901 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 902 | Inverse(translation_to_anchor); |
| 903 | |
| 904 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 905 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 906 | gfx::Transform surface1_sublayer_transform; |
| 907 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 908 | surface1_parent_transform_scale.y()); |
| 909 | |
| 910 | // SS1 = transform given to the subtree of render_surface1 |
| 911 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 912 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 913 | // the owning layer |
| 914 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 915 | |
| 916 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 917 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 918 | gfx::Transform surface2_sublayer_transform; |
| 919 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 920 | surface2_parent_transform_scale.y()); |
| 921 | |
| 922 | // SS2 = transform given to the subtree of render_surface2 |
| 923 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 924 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 925 | // the owning layer |
| 926 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 927 | |
| 928 | SetLayerPropertiesForTesting(parent.get(), |
| 929 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 930 | gfx::PointF(0.25f, 0.f), |
| 931 | gfx::PointF(), |
| 932 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 933 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 934 | false); |
| 935 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 936 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 937 | gfx::PointF(0.25f, 0.f), |
| 938 | gfx::PointF(), |
| 939 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 940 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 941 | false); |
| 942 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 943 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 944 | gfx::PointF(0.25f, 0.f), |
| 945 | gfx::PointF(), |
| 946 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 947 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 948 | false); |
| 949 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 950 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 951 | gfx::PointF(0.25f, 0.f), |
| 952 | gfx::PointF(), |
| 953 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 954 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 955 | false); |
| 956 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 957 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 958 | gfx::PointF(0.25f, 0.f), |
| 959 | gfx::PointF(), |
| 960 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 961 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 962 | false); |
| 963 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 964 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 965 | gfx::PointF(0.25f, 0.f), |
| 966 | gfx::PointF(), |
| 967 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 968 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 969 | false); |
| 970 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 971 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 972 | gfx::PointF(0.25f, 0.f), |
| 973 | gfx::PointF(), |
| 974 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 975 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 976 | false); |
| 977 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 978 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 979 | gfx::PointF(0.25f, 0.f), |
| 980 | gfx::PointF(), |
| 981 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 982 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 983 | false); |
| 984 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 985 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 986 | gfx::PointF(0.25f, 0.f), |
| 987 | gfx::PointF(), |
| 988 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 989 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 990 | false); |
| 991 | SetLayerPropertiesForTesting(replica_of_rs1.get(), |
| 992 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 993 | gfx::PointF(0.25f, 0.f), |
| 994 | gfx::PointF(), |
| 995 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 996 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 997 | false); |
| 998 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 999 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1000 | gfx::PointF(0.25f, 0.f), |
| 1001 | gfx::PointF(), |
| 1002 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1003 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1004 | false); |
| 1005 | |
| 1006 | ExecuteCalculateDrawProperties(root.get()); |
| 1007 | |
| 1008 | // Only layers that are associated with render surfaces should have an actual |
| 1009 | // RenderSurface() value. |
| 1010 | ASSERT_TRUE(root->render_surface()); |
| 1011 | ASSERT_FALSE(child_of_root->render_surface()); |
| 1012 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 1013 | |
| 1014 | ASSERT_TRUE(render_surface1->render_surface()); |
| 1015 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 1016 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 1017 | |
| 1018 | ASSERT_TRUE(render_surface2->render_surface()); |
| 1019 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 1020 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 1021 | |
| 1022 | // Verify all render target accessors |
| 1023 | EXPECT_EQ(root, parent->render_target()); |
| 1024 | EXPECT_EQ(root, child_of_root->render_target()); |
| 1025 | EXPECT_EQ(root, grand_child_of_root->render_target()); |
| 1026 | |
| 1027 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 1028 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 1029 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 1030 | |
| 1031 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 1032 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 1033 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 1034 | |
| 1035 | // Verify layer draw transforms note that draw transforms are described with |
| 1036 | // respect to the nearest ancestor render surface but screen space transforms |
| 1037 | // are described with respect to the root. |
| 1038 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1039 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); |
| 1040 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1041 | grand_child_of_root->draw_transform()); |
| 1042 | |
| 1043 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1044 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); |
| 1045 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1046 | grand_child_of_rs1->draw_transform()); |
| 1047 | |
| 1048 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1049 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); |
| 1050 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1051 | grand_child_of_rs2->draw_transform()); |
| 1052 | |
| 1053 | // Verify layer screen-space transforms |
| 1054 | // |
| 1055 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1056 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1057 | child_of_root->screen_space_transform()); |
| 1058 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1059 | A * A * A, grand_child_of_root->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1060 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1061 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1062 | render_surface1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1063 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1064 | child_of_rs1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1065 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1066 | grand_child_of_rs1->screen_space_transform()); |
| 1067 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1068 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1069 | render_surface2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1070 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1071 | child_of_rs2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1072 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1073 | grand_child_of_rs2->screen_space_transform()); |
| 1074 | |
| 1075 | // Verify render surface transforms. |
| 1076 | // |
| 1077 | // Draw transform of render surface 1 is described with respect to root. |
| 1078 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1079 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1080 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1081 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1082 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1083 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1084 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1085 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1086 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 1087 | // Draw transform of render surface 2 is described with respect to render |
| 1088 | // surface 1. |
| 1089 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1090 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1091 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1092 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1093 | render_surface2->render_surface()->replica_draw_transform()); |
| 1094 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1095 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1096 | render_surface2->render_surface()->screen_space_transform()); |
| 1097 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1098 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1099 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 1100 | |
| 1101 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1102 | // is expected that we correctly set up transforms so that the y-component of |
| 1103 | // the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1104 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 1105 | EXPECT_FLOAT_EQ(2.0, |
| 1106 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1107 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1108 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1109 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1110 | EXPECT_FLOAT_EQ(2.0, |
| 1111 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 1112 | EXPECT_FLOAT_EQ(3.0, |
| 1113 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1114 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1115 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1116 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1117 | EXPECT_FLOAT_EQ(3.0, |
| 1118 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 1119 | EXPECT_FLOAT_EQ(4.0, |
| 1120 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1121 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1122 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1123 | } |
| 1124 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1125 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1126 | // For layers that flatten their subtree, there should be an orthographic |
| 1127 | // projection (for x and y values) in the middle of the transform sequence. |
| 1128 | // Note that the way the code is currently implemented, it is not expected to |
| 1129 | // use a canonical orthographic projection. |
| 1130 | |
| 1131 | scoped_refptr<Layer> root = Layer::Create(); |
| 1132 | scoped_refptr<Layer> child = Layer::Create(); |
| 1133 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1134 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1135 | |
| 1136 | gfx::Transform rotation_about_y_axis; |
| 1137 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1138 | |
| 1139 | const gfx::Transform identity_matrix; |
| 1140 | SetLayerPropertiesForTesting(root.get(), |
| 1141 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1142 | gfx::PointF(), |
| 1143 | gfx::PointF(), |
| 1144 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1145 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1146 | false); |
| 1147 | SetLayerPropertiesForTesting(child.get(), |
| 1148 | rotation_about_y_axis, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1149 | gfx::PointF(), |
| 1150 | gfx::PointF(), |
| 1151 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1152 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1153 | false); |
| 1154 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1155 | rotation_about_y_axis, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1156 | gfx::PointF(), |
| 1157 | gfx::PointF(), |
| 1158 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1159 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1160 | false); |
| 1161 | |
| 1162 | root->AddChild(child); |
| 1163 | child->AddChild(grand_child); |
| 1164 | child->SetForceRenderSurface(true); |
| 1165 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1166 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1167 | host->SetRootLayer(root); |
| 1168 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1169 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1170 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1171 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1172 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1173 | |
| 1174 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1175 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1176 | gfx::Transform expected_grand_child_draw_transform = |
| 1177 | rotation_about_y_axis; // draws onto child's render surface |
| 1178 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1179 | flattened_rotation_about_y.FlattenTo2d(); |
| 1180 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1181 | flattened_rotation_about_y * rotation_about_y_axis; |
| 1182 | |
| 1183 | ExecuteCalculateDrawProperties(root.get()); |
| 1184 | |
| 1185 | // The child's draw transform should have been taken by its surface. |
| 1186 | ASSERT_TRUE(child->render_surface()); |
| 1187 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1188 | child->render_surface()->draw_transform()); |
| 1189 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1190 | expected_child_screen_space_transform, |
| 1191 | child->render_surface()->screen_space_transform()); |
| 1192 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1193 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1194 | child->screen_space_transform()); |
| 1195 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1196 | grand_child->draw_transform()); |
| 1197 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1198 | grand_child->screen_space_transform()); |
| 1199 | } |
| 1200 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1201 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1202 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1203 | // skipping a necessary translation. Without that translation, the coordinate |
| 1204 | // space of the layer's draw transform is incorrect. |
| 1205 | // |
| 1206 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1207 | // but if that layer becomes a render surface, then its draw transform is |
| 1208 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1209 | // incorrectly as a result. |
| 1210 | |
| 1211 | scoped_refptr<Layer> root = Layer::Create(); |
| 1212 | scoped_refptr<Layer> child = Layer::Create(); |
| 1213 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1214 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1215 | |
| 1216 | // The child height is zero, but has non-zero width that should be accounted |
| 1217 | // for while computing draw transforms. |
| 1218 | const gfx::Transform identity_matrix; |
| 1219 | SetLayerPropertiesForTesting(root.get(), |
| 1220 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1221 | gfx::PointF(), |
| 1222 | gfx::PointF(), |
| 1223 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1224 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1225 | false); |
| 1226 | SetLayerPropertiesForTesting(child.get(), |
| 1227 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1228 | gfx::PointF(), |
| 1229 | gfx::PointF(), |
| 1230 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1231 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1232 | false); |
| 1233 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1234 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1235 | gfx::PointF(), |
| 1236 | gfx::PointF(), |
| 1237 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1238 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1239 | false); |
| 1240 | |
| 1241 | root->AddChild(child); |
| 1242 | child->AddChild(grand_child); |
| 1243 | child->SetForceRenderSurface(true); |
| 1244 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1245 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1246 | host->SetRootLayer(root); |
| 1247 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1248 | ExecuteCalculateDrawProperties(root.get()); |
| 1249 | |
| 1250 | ASSERT_TRUE(child->render_surface()); |
| 1251 | // This is the real test, the rest are sanity checks. |
| 1252 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1253 | child->render_surface()->draw_transform()); |
| 1254 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1255 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1256 | grand_child->draw_transform()); |
| 1257 | } |
| 1258 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1259 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1260 | // Transformations applied at the root of the tree should be forwarded |
| 1261 | // to child layers instead of applied to the root RenderSurface. |
| 1262 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1263 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 1264 | new LayerWithForcedDrawsContent; |
| 1265 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1266 | new LayerWithForcedDrawsContent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1267 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1268 | root->AddChild(child); |
| 1269 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1270 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1271 | host->SetRootLayer(root); |
| 1272 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1273 | SetLayerPropertiesForTesting(root.get(), |
| 1274 | identity_matrix, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1275 | gfx::PointF(), |
| 1276 | gfx::PointF(), |
| 1277 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1278 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1279 | false); |
| 1280 | SetLayerPropertiesForTesting(child.get(), |
| 1281 | identity_matrix, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1282 | gfx::PointF(), |
| 1283 | gfx::PointF(), |
| 1284 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1285 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1286 | false); |
| 1287 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1288 | gfx::Transform translate; |
| 1289 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1290 | { |
| 1291 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1292 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1293 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1294 | inputs.can_adjust_raster_scales = true; |
| 1295 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1296 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1297 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1298 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1299 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1300 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1301 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1302 | |
| 1303 | gfx::Transform scale; |
| 1304 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1305 | { |
| 1306 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1307 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1308 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
| 1309 | inputs.can_adjust_raster_scales = true; |
| 1310 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1311 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1312 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1313 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1314 | EXPECT_EQ(2.f, root->last_device_scale_factor()); |
| 1315 | EXPECT_EQ(2.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1316 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1317 | |
| 1318 | gfx::Transform rotate; |
| 1319 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1320 | { |
| 1321 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1322 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1323 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
| 1324 | inputs.can_adjust_raster_scales = true; |
| 1325 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1326 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1327 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1328 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1329 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1330 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1331 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1332 | |
| 1333 | gfx::Transform composite; |
| 1334 | composite.ConcatTransform(translate); |
| 1335 | composite.ConcatTransform(scale); |
| 1336 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1337 | { |
| 1338 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1339 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1340 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
| 1341 | inputs.can_adjust_raster_scales = true; |
| 1342 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1343 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1344 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1345 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1346 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1347 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1348 | // Verify it composes correctly with device scale. |
| 1349 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1350 | |
| 1351 | { |
| 1352 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1353 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1354 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1355 | inputs.device_scale_factor = device_scale_factor; |
| 1356 | inputs.can_adjust_raster_scales = true; |
| 1357 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1358 | gfx::Transform device_scaled_translate = translate; |
| 1359 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1360 | EXPECT_EQ(device_scaled_translate, |
| 1361 | root->draw_properties().target_space_transform); |
| 1362 | EXPECT_EQ(device_scaled_translate, |
| 1363 | child->draw_properties().target_space_transform); |
| 1364 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1365 | EXPECT_EQ(device_scale_factor, root->last_device_scale_factor()); |
| 1366 | EXPECT_EQ(device_scale_factor, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1367 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1368 | |
| 1369 | // Verify it composes correctly with page scale. |
| 1370 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1371 | |
| 1372 | { |
| 1373 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1374 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1375 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1376 | inputs.page_scale_factor = page_scale_factor; |
| 1377 | inputs.page_scale_application_layer = root.get(); |
| 1378 | inputs.can_adjust_raster_scales = true; |
| 1379 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1380 | gfx::Transform page_scaled_translate = translate; |
| 1381 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
| 1382 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1383 | EXPECT_EQ(page_scaled_translate, |
| 1384 | child->draw_properties().target_space_transform); |
| 1385 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1386 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1387 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1388 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1389 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1390 | // Verify that it composes correctly with transforms directly on root layer. |
| 1391 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1392 | |
| 1393 | { |
| 1394 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1395 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1396 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
| 1397 | inputs.can_adjust_raster_scales = true; |
| 1398 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1399 | gfx::Transform compositeSquared = composite; |
| 1400 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1401 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1402 | compositeSquared, root->draw_properties().target_space_transform); |
| 1403 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1404 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1405 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1406 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1407 | } |
| 1408 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1409 | TEST_F(LayerTreeHostCommonTest, |
| 1410 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1411 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1412 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1413 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1414 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1415 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1416 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1417 | host->SetRootLayer(parent); |
| 1418 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1419 | const gfx::Transform identity_matrix; |
| 1420 | SetLayerPropertiesForTesting(parent.get(), |
| 1421 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1422 | gfx::PointF(), |
| 1423 | gfx::PointF(), |
| 1424 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1425 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1426 | false); |
| 1427 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1428 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1429 | gfx::PointF(), |
| 1430 | gfx::PointF(), |
| 1431 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1432 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1433 | false); |
| 1434 | SetLayerPropertiesForTesting(child.get(), |
| 1435 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1436 | gfx::PointF(), |
| 1437 | gfx::PointF(30.f, 30.f), |
| 1438 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1439 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1440 | false); |
| 1441 | |
| 1442 | parent->AddChild(render_surface1); |
| 1443 | parent->SetMasksToBounds(true); |
| 1444 | render_surface1->AddChild(child); |
| 1445 | render_surface1->SetForceRenderSurface(true); |
| 1446 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1447 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1448 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1449 | parent.get(), |
| 1450 | parent->bounds(), |
| 1451 | gfx::Transform(), |
| 1452 | &render_surface_layer_list); |
| 1453 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1454 | |
| 1455 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1456 | // the intermediate render surface should not be listed here, even if it was |
| 1457 | // forced to be created. Render surfaces without children or visible content |
| 1458 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1459 | // of size 0). |
| 1460 | ASSERT_TRUE(parent->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1461 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1462 | } |
| 1463 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1464 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1465 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1466 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1467 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1468 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1469 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1470 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1471 | host->SetRootLayer(parent); |
| 1472 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1473 | const gfx::Transform identity_matrix; |
| 1474 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1475 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1476 | gfx::PointF(), |
| 1477 | gfx::PointF(), |
| 1478 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1479 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1480 | false); |
| 1481 | SetLayerPropertiesForTesting(child.get(), |
| 1482 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1483 | gfx::PointF(), |
| 1484 | gfx::PointF(), |
| 1485 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1486 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1487 | false); |
| 1488 | |
| 1489 | parent->AddChild(render_surface1); |
| 1490 | render_surface1->AddChild(child); |
| 1491 | render_surface1->SetForceRenderSurface(true); |
| 1492 | render_surface1->SetOpacity(0.f); |
| 1493 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1494 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1495 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1496 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1497 | inputs.can_adjust_raster_scales = true; |
| 1498 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1499 | |
| 1500 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1501 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1502 | // have been extended by the children. |
| 1503 | ASSERT_TRUE(parent->render_surface()); |
| 1504 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1505 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1506 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1507 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1508 | } |
| 1509 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1510 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1511 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1512 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1513 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1514 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1515 | render_surface1->SetForceRenderSurface(true); |
| 1516 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1517 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1518 | host->SetRootLayer(parent); |
| 1519 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1520 | const gfx::Transform identity_matrix; |
| 1521 | SetLayerPropertiesForTesting(parent.get(), |
| 1522 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1523 | gfx::PointF(), |
| 1524 | gfx::PointF(), |
| 1525 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1526 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1527 | false); |
| 1528 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1529 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1530 | gfx::PointF(), |
| 1531 | gfx::PointF(), |
| 1532 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1533 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1534 | false); |
| 1535 | SetLayerPropertiesForTesting(child.get(), |
| 1536 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1537 | gfx::PointF(), |
| 1538 | gfx::PointF(), |
| 1539 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1540 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1541 | false); |
| 1542 | |
| 1543 | parent->AddChild(render_surface1); |
| 1544 | render_surface1->AddChild(child); |
| 1545 | |
| 1546 | // Sanity check before the actual test |
| 1547 | EXPECT_FALSE(parent->render_surface()); |
| 1548 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1549 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1550 | { |
| 1551 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1552 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1553 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1554 | inputs.can_adjust_raster_scales = true; |
| 1555 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1556 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1557 | // The root layer always creates a render surface |
| 1558 | EXPECT_TRUE(parent->render_surface()); |
| 1559 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1560 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1561 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1562 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1563 | { |
| 1564 | RenderSurfaceLayerList render_surface_layer_list; |
| 1565 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1566 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1567 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1568 | inputs.can_adjust_raster_scales = true; |
| 1569 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1570 | EXPECT_TRUE(parent->render_surface()); |
| 1571 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1572 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1573 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1574 | } |
| 1575 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1576 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1577 | // The entire subtree of layers that are outside the clip rect should be |
| 1578 | // culled away, and should not affect the render_surface_layer_list. |
| 1579 | // |
| 1580 | // The test tree is set up as follows: |
| 1581 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1582 | // that have something to draw. |
| 1583 | // - parent is a large container layer. |
| 1584 | // - child has masksToBounds=true to cause clipping. |
| 1585 | // - grand_child is positioned outside of the child's bounds |
| 1586 | // - great_grand_child is also kept outside child's bounds. |
| 1587 | // |
| 1588 | // In this configuration, grand_child and great_grand_child are completely |
| 1589 | // outside the clip rect, and they should never get scheduled on the list of |
| 1590 | // render surfaces. |
| 1591 | // |
| 1592 | |
| 1593 | const gfx::Transform identity_matrix; |
| 1594 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1595 | scoped_refptr<Layer> child = Layer::Create(); |
| 1596 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1597 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1598 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1599 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1600 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1601 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1602 | parent->AddChild(child); |
| 1603 | child->AddChild(grand_child); |
| 1604 | grand_child->AddChild(great_grand_child); |
| 1605 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1606 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1607 | host->SetRootLayer(parent); |
| 1608 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1609 | // leaf_node1 ensures that parent and child are kept on the |
| 1610 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1611 | // should be clipped. |
| 1612 | child->AddChild(leaf_node1); |
| 1613 | great_grand_child->AddChild(leaf_node2); |
| 1614 | |
| 1615 | SetLayerPropertiesForTesting(parent.get(), |
| 1616 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1617 | gfx::PointF(), |
| 1618 | gfx::PointF(), |
| 1619 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1620 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1621 | false); |
| 1622 | SetLayerPropertiesForTesting(child.get(), |
| 1623 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1624 | gfx::PointF(), |
| 1625 | gfx::PointF(), |
| 1626 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1627 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1628 | false); |
| 1629 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1630 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1631 | gfx::PointF(), |
| 1632 | gfx::PointF(45.f, 45.f), |
| 1633 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1634 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1635 | false); |
| 1636 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1637 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1638 | gfx::PointF(), |
| 1639 | gfx::PointF(), |
| 1640 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1641 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1642 | false); |
| 1643 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1644 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1645 | gfx::PointF(), |
| 1646 | gfx::PointF(), |
| 1647 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1648 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1649 | false); |
| 1650 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1651 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1652 | gfx::PointF(), |
| 1653 | gfx::PointF(), |
| 1654 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1655 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1656 | false); |
| 1657 | |
| 1658 | child->SetMasksToBounds(true); |
| 1659 | child->SetOpacity(0.4f); |
| 1660 | child->SetForceRenderSurface(true); |
| 1661 | grand_child->SetOpacity(0.5f); |
| 1662 | great_grand_child->SetOpacity(0.4f); |
| 1663 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1664 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1665 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1666 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1667 | inputs.can_adjust_raster_scales = true; |
| 1668 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1669 | |
| 1670 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1671 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1672 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1673 | } |
| 1674 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1675 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1676 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1677 | // of the surface. When the render surface is animating its transforms, then |
| 1678 | // the content rect's position in the clip rect is not defined on the main |
| 1679 | // thread, and its content rect should not be clipped. |
| 1680 | |
| 1681 | // The test tree is set up as follows: |
| 1682 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1683 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1684 | // the parent. |
| 1685 | // - grand_child is a render surface, and the only visible content in child. |
| 1686 | // It is positioned outside of the clip rect from parent. |
| 1687 | |
| 1688 | // In this configuration, grand_child should be outside the clipped |
| 1689 | // content rect of the child, making grand_child not appear in the |
| 1690 | // render_surface_layer_list. However, when we place an animation on the |
| 1691 | // child, this clipping should be avoided and we should keep the grand_child |
| 1692 | // in the render_surface_layer_list. |
| 1693 | |
| 1694 | const gfx::Transform identity_matrix; |
| 1695 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1696 | scoped_refptr<Layer> child = Layer::Create(); |
| 1697 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1698 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1699 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1700 | parent->AddChild(child); |
| 1701 | child->AddChild(grand_child); |
| 1702 | grand_child->AddChild(leaf_node); |
| 1703 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1704 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1705 | host->SetRootLayer(parent); |
| 1706 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1707 | SetLayerPropertiesForTesting(parent.get(), |
| 1708 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1709 | gfx::PointF(), |
| 1710 | gfx::PointF(), |
| 1711 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1712 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1713 | false); |
| 1714 | SetLayerPropertiesForTesting(child.get(), |
| 1715 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1716 | gfx::PointF(), |
| 1717 | gfx::PointF(), |
| 1718 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1719 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1720 | false); |
| 1721 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1722 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1723 | gfx::PointF(), |
| 1724 | gfx::PointF(200.f, 200.f), |
| 1725 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1726 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1727 | false); |
| 1728 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1729 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1730 | gfx::PointF(), |
| 1731 | gfx::PointF(), |
| 1732 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1733 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1734 | false); |
| 1735 | |
| 1736 | parent->SetMasksToBounds(true); |
| 1737 | child->SetOpacity(0.4f); |
| 1738 | child->SetForceRenderSurface(true); |
| 1739 | grand_child->SetOpacity(0.4f); |
| 1740 | grand_child->SetForceRenderSurface(true); |
| 1741 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1742 | { |
| 1743 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1744 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1745 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1746 | inputs.can_adjust_raster_scales = true; |
| 1747 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1748 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1749 | // Without an animation, we should cull child and grand_child from the |
| 1750 | // render_surface_layer_list. |
| 1751 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1752 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1753 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1754 | |
| 1755 | // Now put an animating transform on child. |
| 1756 | AddAnimatedTransformToController( |
| 1757 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1758 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1759 | { |
| 1760 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1761 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1762 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1763 | inputs.can_adjust_raster_scales = true; |
| 1764 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1765 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1766 | // With an animating transform, we should keep child and grand_child in the |
| 1767 | // render_surface_layer_list. |
| 1768 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1769 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1770 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1771 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1772 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1773 | } |
| 1774 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1775 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1776 | // Layer's IsClipped() property is set to true when: |
| 1777 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1778 | // - the layer is clipped by an ancestor that contributes to the same |
| 1779 | // render target, |
| 1780 | // - a surface is clipped by an ancestor that contributes to the same |
| 1781 | // render target. |
| 1782 | // |
| 1783 | // In particular, for a layer that owns a render surface: |
| 1784 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1785 | // pass that clipped status to the layer itself. |
| 1786 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1787 | // and propagates the clip to the subtree. |
| 1788 | |
| 1789 | const gfx::Transform identity_matrix; |
| 1790 | scoped_refptr<Layer> root = Layer::Create(); |
| 1791 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1792 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 1793 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 1794 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1795 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1796 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1797 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1798 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1799 | root->AddChild(parent); |
| 1800 | parent->AddChild(child1); |
| 1801 | parent->AddChild(child2); |
| 1802 | child1->AddChild(grand_child); |
| 1803 | child2->AddChild(leaf_node2); |
| 1804 | grand_child->AddChild(leaf_node1); |
| 1805 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1806 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1807 | host->SetRootLayer(root); |
| 1808 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1809 | child2->SetForceRenderSurface(true); |
| 1810 | |
| 1811 | SetLayerPropertiesForTesting(root.get(), |
| 1812 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1813 | gfx::PointF(), |
| 1814 | gfx::PointF(), |
| 1815 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1816 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1817 | false); |
| 1818 | SetLayerPropertiesForTesting(parent.get(), |
| 1819 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1820 | gfx::PointF(), |
| 1821 | gfx::PointF(), |
| 1822 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1823 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1824 | false); |
| 1825 | SetLayerPropertiesForTesting(child1.get(), |
| 1826 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1827 | gfx::PointF(), |
| 1828 | gfx::PointF(), |
| 1829 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1830 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1831 | false); |
| 1832 | SetLayerPropertiesForTesting(child2.get(), |
| 1833 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1834 | gfx::PointF(), |
| 1835 | gfx::PointF(), |
| 1836 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1837 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1838 | false); |
| 1839 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1840 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1841 | gfx::PointF(), |
| 1842 | gfx::PointF(), |
| 1843 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1844 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1845 | false); |
| 1846 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1847 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1848 | gfx::PointF(), |
| 1849 | gfx::PointF(), |
| 1850 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1851 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1852 | false); |
| 1853 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1854 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1855 | gfx::PointF(), |
| 1856 | gfx::PointF(), |
| 1857 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1858 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1859 | false); |
| 1860 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1861 | // Case 1: nothing is clipped except the root render surface. |
| 1862 | { |
| 1863 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1864 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1865 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1866 | inputs.can_adjust_raster_scales = true; |
| 1867 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1868 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1869 | ASSERT_TRUE(root->render_surface()); |
| 1870 | ASSERT_TRUE(child2->render_surface()); |
| 1871 | |
| 1872 | EXPECT_FALSE(root->is_clipped()); |
| 1873 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1874 | EXPECT_FALSE(parent->is_clipped()); |
| 1875 | EXPECT_FALSE(child1->is_clipped()); |
| 1876 | EXPECT_FALSE(child2->is_clipped()); |
| 1877 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1878 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1879 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1880 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1881 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1882 | |
| 1883 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1884 | // surface are clipped. But layers that contribute to child2's surface are |
| 1885 | // not clipped explicitly because child2's surface already accounts for |
| 1886 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1887 | { |
| 1888 | RenderSurfaceLayerList render_surface_layer_list; |
| 1889 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1890 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1891 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1892 | inputs.can_adjust_raster_scales = true; |
| 1893 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1894 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1895 | ASSERT_TRUE(root->render_surface()); |
| 1896 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1897 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1898 | EXPECT_FALSE(root->is_clipped()); |
| 1899 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1900 | EXPECT_TRUE(parent->is_clipped()); |
| 1901 | EXPECT_TRUE(child1->is_clipped()); |
| 1902 | EXPECT_FALSE(child2->is_clipped()); |
| 1903 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1904 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1905 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1906 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1907 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1908 | |
| 1909 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1910 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1911 | { |
| 1912 | RenderSurfaceLayerList render_surface_layer_list; |
| 1913 | parent->SetMasksToBounds(false); |
| 1914 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1915 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1916 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1917 | inputs.can_adjust_raster_scales = true; |
| 1918 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1919 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1920 | ASSERT_TRUE(root->render_surface()); |
| 1921 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1922 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1923 | EXPECT_FALSE(root->is_clipped()); |
| 1924 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1925 | EXPECT_FALSE(parent->is_clipped()); |
| 1926 | EXPECT_FALSE(child1->is_clipped()); |
| 1927 | EXPECT_TRUE(child2->is_clipped()); |
| 1928 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1929 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1930 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1931 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1932 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1933 | } |
| 1934 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1935 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1936 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1937 | // parent masksToBounds is true. |
| 1938 | // |
| 1939 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1940 | // be the layer rect expressed in target space. |
| 1941 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1942 | // will be the intersection of layer bounds and the mask region. |
| 1943 | // grand_child3 - partially clipped and masksToBounds; the |
| 1944 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1945 | // the mask region. |
| 1946 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1947 | // be empty. |
| 1948 | // |
| 1949 | |
| 1950 | const gfx::Transform identity_matrix; |
| 1951 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1952 | scoped_refptr<Layer> child = Layer::Create(); |
| 1953 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1954 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1955 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1956 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1957 | |
| 1958 | parent->AddChild(child); |
| 1959 | child->AddChild(grand_child1); |
| 1960 | child->AddChild(grand_child2); |
| 1961 | child->AddChild(grand_child3); |
| 1962 | child->AddChild(grand_child4); |
| 1963 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1964 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1965 | host->SetRootLayer(parent); |
| 1966 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1967 | SetLayerPropertiesForTesting(parent.get(), |
| 1968 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1969 | gfx::PointF(), |
| 1970 | gfx::PointF(), |
| 1971 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1972 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1973 | false); |
| 1974 | SetLayerPropertiesForTesting(child.get(), |
| 1975 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1976 | gfx::PointF(), |
| 1977 | gfx::PointF(), |
| 1978 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1979 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1980 | false); |
| 1981 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1982 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1983 | gfx::PointF(), |
| 1984 | gfx::PointF(5.f, 5.f), |
| 1985 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1986 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1987 | false); |
| 1988 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1989 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1990 | gfx::PointF(), |
| 1991 | gfx::PointF(15.f, 15.f), |
| 1992 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1993 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1994 | false); |
| 1995 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 1996 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1997 | gfx::PointF(), |
| 1998 | gfx::PointF(15.f, 15.f), |
| 1999 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2000 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2001 | false); |
| 2002 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2003 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2004 | gfx::PointF(), |
| 2005 | gfx::PointF(45.f, 45.f), |
| 2006 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2007 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2008 | false); |
| 2009 | |
| 2010 | child->SetMasksToBounds(true); |
| 2011 | grand_child3->SetMasksToBounds(true); |
| 2012 | |
| 2013 | // Force everyone to be a render surface. |
| 2014 | child->SetOpacity(0.4f); |
| 2015 | grand_child1->SetOpacity(0.5f); |
| 2016 | grand_child2->SetOpacity(0.5f); |
| 2017 | grand_child3->SetOpacity(0.5f); |
| 2018 | grand_child4->SetOpacity(0.5f); |
| 2019 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2020 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2021 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2022 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2023 | inputs.can_adjust_raster_scales = true; |
| 2024 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2025 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2026 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2027 | grand_child1->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2028 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2029 | grand_child3->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2030 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2031 | grand_child3->drawable_content_rect()); |
| 2032 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2033 | } |
| 2034 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2035 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2036 | // Verify that render surfaces (and their layers) get the appropriate |
| 2037 | // clip rects when their parent masksToBounds is true. |
| 2038 | // |
| 2039 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2040 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2041 | // They may still have a clip rect of their own layer bounds, however, if |
| 2042 | // masksToBounds was true. |
| 2043 | const gfx::Transform identity_matrix; |
| 2044 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2045 | scoped_refptr<Layer> child = Layer::Create(); |
| 2046 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 2047 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 2048 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 2049 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 2050 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 2051 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2052 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 2053 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2054 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 2055 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2056 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 2057 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2058 | |
| 2059 | parent->AddChild(child); |
| 2060 | child->AddChild(grand_child1); |
| 2061 | child->AddChild(grand_child2); |
| 2062 | child->AddChild(grand_child3); |
| 2063 | child->AddChild(grand_child4); |
| 2064 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2065 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2066 | host->SetRootLayer(parent); |
| 2067 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2068 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2069 | // this test. |
| 2070 | grand_child1->AddChild(leaf_node1); |
| 2071 | grand_child2->AddChild(leaf_node2); |
| 2072 | grand_child3->AddChild(leaf_node3); |
| 2073 | grand_child4->AddChild(leaf_node4); |
| 2074 | |
| 2075 | SetLayerPropertiesForTesting(parent.get(), |
| 2076 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2077 | gfx::PointF(), |
| 2078 | gfx::PointF(), |
| 2079 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2080 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2081 | false); |
| 2082 | SetLayerPropertiesForTesting(child.get(), |
| 2083 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2084 | gfx::PointF(), |
| 2085 | gfx::PointF(), |
| 2086 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2087 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2088 | false); |
| 2089 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2090 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2091 | gfx::PointF(), |
| 2092 | gfx::PointF(5.f, 5.f), |
| 2093 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2094 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2095 | false); |
| 2096 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2097 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2098 | gfx::PointF(), |
| 2099 | gfx::PointF(15.f, 15.f), |
| 2100 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2101 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2102 | false); |
| 2103 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2104 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2105 | gfx::PointF(), |
| 2106 | gfx::PointF(15.f, 15.f), |
| 2107 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2108 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2109 | false); |
| 2110 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2111 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2112 | gfx::PointF(), |
| 2113 | gfx::PointF(45.f, 45.f), |
| 2114 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2115 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2116 | false); |
| 2117 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2118 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2119 | gfx::PointF(), |
| 2120 | gfx::PointF(), |
| 2121 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2122 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2123 | false); |
| 2124 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2125 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2126 | gfx::PointF(), |
| 2127 | gfx::PointF(), |
| 2128 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2129 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2130 | false); |
| 2131 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2132 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2133 | gfx::PointF(), |
| 2134 | gfx::PointF(), |
| 2135 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2136 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2137 | false); |
| 2138 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2139 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2140 | gfx::PointF(), |
| 2141 | gfx::PointF(), |
| 2142 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2143 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2144 | false); |
| 2145 | |
| 2146 | child->SetMasksToBounds(true); |
| 2147 | grand_child3->SetMasksToBounds(true); |
| 2148 | grand_child4->SetMasksToBounds(true); |
| 2149 | |
| 2150 | // Force everyone to be a render surface. |
| 2151 | child->SetOpacity(0.4f); |
| 2152 | child->SetForceRenderSurface(true); |
| 2153 | grand_child1->SetOpacity(0.5f); |
| 2154 | grand_child1->SetForceRenderSurface(true); |
| 2155 | grand_child2->SetOpacity(0.5f); |
| 2156 | grand_child2->SetForceRenderSurface(true); |
| 2157 | grand_child3->SetOpacity(0.5f); |
| 2158 | grand_child3->SetForceRenderSurface(true); |
| 2159 | grand_child4->SetOpacity(0.5f); |
| 2160 | grand_child4->SetForceRenderSurface(true); |
| 2161 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2162 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2163 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2164 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2165 | inputs.can_adjust_raster_scales = true; |
| 2166 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2167 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2168 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2169 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2170 | |
| 2171 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2172 | // masksToBounds. |
[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_child1->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_child2->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2177 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2178 | grand_child3->render_surface()->clip_rect()); |
| 2179 | } |
| 2180 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2181 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2182 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2183 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2184 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2185 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2186 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2187 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2188 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2189 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2190 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2191 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2192 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2193 | parent->AddChild(render_surface1); |
| 2194 | parent->AddChild(child_of_root); |
| 2195 | render_surface1->AddChild(child_of_rs1); |
| 2196 | render_surface1->AddChild(render_surface2); |
| 2197 | render_surface2->AddChild(child_of_rs2); |
| 2198 | child_of_root->AddChild(grand_child_of_root); |
| 2199 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2200 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2201 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2202 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2203 | host->SetRootLayer(parent); |
| 2204 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2205 | // Make our render surfaces. |
| 2206 | render_surface1->SetForceRenderSurface(true); |
| 2207 | render_surface2->SetForceRenderSurface(true); |
| 2208 | |
| 2209 | gfx::Transform layer_transform; |
| 2210 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2211 | |
| 2212 | SetLayerPropertiesForTesting(parent.get(), |
| 2213 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2214 | gfx::PointF(0.25f, 0.f), |
| 2215 | gfx::PointF(2.5f, 0.f), |
| 2216 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2217 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2218 | false); |
| 2219 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2220 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2221 | gfx::PointF(0.25f, 0.f), |
| 2222 | gfx::PointF(2.5f, 0.f), |
| 2223 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2224 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2225 | false); |
| 2226 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2227 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2228 | gfx::PointF(0.25f, 0.f), |
| 2229 | gfx::PointF(2.5f, 0.f), |
| 2230 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2231 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2232 | false); |
| 2233 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2234 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2235 | gfx::PointF(0.25f, 0.f), |
| 2236 | gfx::PointF(2.5f, 0.f), |
| 2237 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2238 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2239 | false); |
| 2240 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2241 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2242 | gfx::PointF(0.25f, 0.f), |
| 2243 | gfx::PointF(2.5f, 0.f), |
| 2244 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2245 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2246 | false); |
| 2247 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2248 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2249 | gfx::PointF(0.25f, 0.f), |
| 2250 | gfx::PointF(2.5f, 0.f), |
| 2251 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2252 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2253 | false); |
| 2254 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2255 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2256 | gfx::PointF(0.25f, 0.f), |
| 2257 | gfx::PointF(2.5f, 0.f), |
| 2258 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2259 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2260 | false); |
| 2261 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2262 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2263 | gfx::PointF(0.25f, 0.f), |
| 2264 | gfx::PointF(2.5f, 0.f), |
| 2265 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2266 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2267 | false); |
| 2268 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2269 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2270 | gfx::PointF(0.25f, 0.f), |
| 2271 | gfx::PointF(2.5f, 0.f), |
| 2272 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2273 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2274 | false); |
| 2275 | |
| 2276 | // Put an animated opacity on the render surface. |
| 2277 | AddOpacityTransitionToController( |
| 2278 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2279 | |
| 2280 | // Also put an animated opacity on a layer without descendants. |
| 2281 | AddOpacityTransitionToController( |
| 2282 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2283 | |
| 2284 | // Put a transform animation on the render surface. |
| 2285 | AddAnimatedTransformToController( |
| 2286 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2287 | |
| 2288 | // Also put transform animations on grand_child_of_root, and |
| 2289 | // grand_child_of_rs2 |
| 2290 | AddAnimatedTransformToController( |
| 2291 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2292 | AddAnimatedTransformToController( |
| 2293 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2294 | |
| 2295 | ExecuteCalculateDrawProperties(parent.get()); |
| 2296 | |
| 2297 | // Only layers that are associated with render surfaces should have an actual |
| 2298 | // RenderSurface() value. |
| 2299 | ASSERT_TRUE(parent->render_surface()); |
| 2300 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2301 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2302 | |
| 2303 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2304 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2305 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2306 | |
| 2307 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2308 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2309 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2310 | |
| 2311 | // Verify all render target accessors |
| 2312 | EXPECT_EQ(parent, parent->render_target()); |
| 2313 | EXPECT_EQ(parent, child_of_root->render_target()); |
| 2314 | EXPECT_EQ(parent, grand_child_of_root->render_target()); |
| 2315 | |
| 2316 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 2317 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 2318 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 2319 | |
| 2320 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 2321 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 2322 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 2323 | |
| 2324 | // Verify draw_opacity_is_animating values |
| 2325 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2326 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2327 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2328 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2329 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2330 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2331 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2332 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2333 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2334 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2335 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2336 | |
| 2337 | // Verify draw_transform_is_animating values |
| 2338 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2339 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2340 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2341 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2342 | EXPECT_FALSE(render_surface1->render_surface() |
| 2343 | ->target_surface_transforms_are_animating()); |
| 2344 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2345 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2346 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2347 | EXPECT_TRUE(render_surface2->render_surface() |
| 2348 | ->target_surface_transforms_are_animating()); |
| 2349 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2350 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2351 | |
| 2352 | // Verify screen_space_transform_is_animating values |
| 2353 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2354 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2355 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2356 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2357 | EXPECT_FALSE(render_surface1->render_surface() |
| 2358 | ->screen_space_transforms_are_animating()); |
| 2359 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2360 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2361 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2362 | EXPECT_TRUE(render_surface2->render_surface() |
| 2363 | ->screen_space_transforms_are_animating()); |
| 2364 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2365 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2366 | |
| 2367 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2368 | // It is expected that we correctly set up transforms so that the y-component |
| 2369 | // 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] | 2370 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2371 | EXPECT_FLOAT_EQ(2.0, |
| 2372 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2373 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2374 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2375 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2376 | EXPECT_FLOAT_EQ(2.0, |
| 2377 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2378 | EXPECT_FLOAT_EQ(3.0, |
| 2379 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2380 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2381 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2382 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2383 | EXPECT_FLOAT_EQ(3.0, |
| 2384 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2385 | EXPECT_FLOAT_EQ(4.0, |
| 2386 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2387 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2388 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2389 | } |
| 2390 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2391 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2392 | // Test the calculateVisibleRect() function works correctly for identity |
| 2393 | // transforms. |
| 2394 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2395 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2396 | gfx::Transform layer_to_surface_transform; |
| 2397 | |
| 2398 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2399 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2400 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2401 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2402 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2403 | EXPECT_RECT_EQ(expected, actual); |
| 2404 | |
| 2405 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2406 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2407 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2408 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2409 | EXPECT_TRUE(actual.IsEmpty()); |
| 2410 | |
| 2411 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2412 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2413 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2414 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2415 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2416 | EXPECT_RECT_EQ(expected, actual); |
| 2417 | } |
| 2418 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2419 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2420 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2421 | // transforms. |
| 2422 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2423 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2424 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2425 | gfx::Transform layer_to_surface_transform; |
| 2426 | |
| 2427 | // Case 1: Layer is contained within the surface. |
| 2428 | layer_to_surface_transform.MakeIdentity(); |
| 2429 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2430 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2431 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2432 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2433 | EXPECT_RECT_EQ(expected, actual); |
| 2434 | |
| 2435 | // Case 2: Layer is outside the surface rect. |
| 2436 | layer_to_surface_transform.MakeIdentity(); |
| 2437 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2438 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2439 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2440 | EXPECT_TRUE(actual.IsEmpty()); |
| 2441 | |
| 2442 | // Case 3: Layer is partially overlapping the surface rect. |
| 2443 | layer_to_surface_transform.MakeIdentity(); |
| 2444 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2445 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2446 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2447 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2448 | EXPECT_RECT_EQ(expected, actual); |
| 2449 | } |
| 2450 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2451 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2452 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2453 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2454 | // should return the g in the layer's space. |
| 2455 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2456 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2457 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2458 | gfx::Transform layer_to_surface_transform; |
| 2459 | |
| 2460 | // Case 1: Layer is contained within the surface. |
| 2461 | layer_to_surface_transform.MakeIdentity(); |
| 2462 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2463 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2464 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2465 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2466 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2467 | EXPECT_RECT_EQ(expected, actual); |
| 2468 | |
| 2469 | // Case 2: Layer is outside the surface rect. |
| 2470 | layer_to_surface_transform.MakeIdentity(); |
| 2471 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2472 | layer_to_surface_transform.Rotate(45.0); |
| 2473 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2474 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2475 | EXPECT_TRUE(actual.IsEmpty()); |
| 2476 | |
| 2477 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2478 | // the layer is oriented diagonally, with the left half outside of the render |
| 2479 | // surface. In this case, the g should still be the entire layer |
| 2480 | // (remember the g is computed in layer space); both the top-left |
| 2481 | // and bottom-right corners of the layer are still visible. |
| 2482 | layer_to_surface_transform.MakeIdentity(); |
| 2483 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2484 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2485 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2486 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2487 | EXPECT_RECT_EQ(expected, actual); |
| 2488 | |
| 2489 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2490 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2491 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2492 | // surface overlaps the right side of the layer. The g should be |
| 2493 | // the layer's right half. |
| 2494 | layer_to_surface_transform.MakeIdentity(); |
| 2495 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2496 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2497 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2498 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2499 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2500 | EXPECT_RECT_EQ(expected, actual); |
| 2501 | } |
| 2502 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2503 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2504 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2505 | // transforms. |
| 2506 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2507 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2508 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2509 | gfx::Transform layer_to_surface_transform; |
| 2510 | |
| 2511 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2512 | // degrees, should be fully contained in the render surface. |
| 2513 | layer_to_surface_transform.MakeIdentity(); |
| 2514 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2515 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2516 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2517 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2518 | EXPECT_RECT_EQ(expected, actual); |
| 2519 | |
| 2520 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2521 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2522 | // visible on the surface. |
| 2523 | // 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] | 2524 | SkMScalar half_width_of_rotated_layer = |
| 2525 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2526 | layer_to_surface_transform.MakeIdentity(); |
| 2527 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2528 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2529 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2530 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2531 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2532 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2533 | EXPECT_RECT_EQ(expected, actual); |
| 2534 | } |
| 2535 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2536 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2537 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2538 | // a perspective projection onto the target surface. |
| 2539 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2540 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2541 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2542 | gfx::Transform layer_to_surface_transform; |
| 2543 | |
| 2544 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2545 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2546 | // its translated more than the perspective amount. |
| 2547 | layer_to_surface_transform.MakeIdentity(); |
| 2548 | |
| 2549 | // The following sequence of transforms applies the perspective about the |
| 2550 | // center of the surface. |
| 2551 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2552 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2553 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2554 | |
| 2555 | // This translate places the layer in front of the surface's projection plane. |
| 2556 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2557 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2558 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2559 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2560 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2561 | EXPECT_RECT_EQ(expected, actual); |
| 2562 | |
| 2563 | // Case 2: same projection as before, except that the layer is also translated |
| 2564 | // to the side, so that only the right half of the layer should be visible. |
| 2565 | // |
| 2566 | // Explanation of expected result: The perspective ratio is (z distance |
| 2567 | // between layer and camera origin) / (z distance between projection plane and |
| 2568 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2569 | // move a layer by translating -50 units in projected surface units (so that |
| 2570 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2571 | // -50 == -200 in the layer's units. |
| 2572 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2573 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2574 | gfx::Size(100, 200)); // The right half of the layer's |
| 2575 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2576 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2577 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2578 | EXPECT_RECT_EQ(expected, actual); |
| 2579 | } |
| 2580 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2581 | TEST_F(LayerTreeHostCommonTest, |
| 2582 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2583 | // There is currently no explicit concept of an orthographic projection plane |
| 2584 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2585 | // are technically behind the surface in an orthographic world should not be |
| 2586 | // clipped when they are flattened to the surface. |
| 2587 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2588 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2589 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2590 | gfx::Transform layer_to_surface_transform; |
| 2591 | |
| 2592 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2593 | // at the center of the layer. |
| 2594 | layer_to_surface_transform.MakeIdentity(); |
| 2595 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2596 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2597 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2598 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2599 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2600 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2601 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2602 | EXPECT_RECT_EQ(expected, actual); |
| 2603 | } |
| 2604 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2605 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2606 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2607 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2608 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2609 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2610 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2611 | // converting to cartesian coordinates. |
| 2612 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2613 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2614 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2615 | gfx::Transform layer_to_surface_transform; |
| 2616 | |
| 2617 | // The layer is positioned so that the right half of the layer should be in |
| 2618 | // front of the camera, while the other half is behind the surface's |
| 2619 | // projection plane. The following sequence of transforms applies the |
| 2620 | // perspective and rotation about the center of the layer. |
| 2621 | layer_to_surface_transform.MakeIdentity(); |
| 2622 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2623 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2624 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2625 | |
| 2626 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2627 | // transform, otherwise this code is not testing the intended scenario. |
| 2628 | bool clipped; |
| 2629 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2630 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2631 | &clipped); |
| 2632 | ASSERT_TRUE(clipped); |
| 2633 | |
| 2634 | int expected_x_position = 0; |
| 2635 | int expected_width = 10; |
| 2636 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2637 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2638 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2639 | EXPECT_EQ(expected_width, actual.width()); |
| 2640 | } |
| 2641 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2642 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2643 | // To determine visible rect in layer space, there needs to be an |
| 2644 | // un-projection from surface space to layer space. When the original |
| 2645 | // transform was a perspective projection that was clipped, it returns a rect |
| 2646 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2647 | // clipping again. |
| 2648 | |
| 2649 | // This sequence of transforms causes one corner of the layer to protrude |
| 2650 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2651 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2652 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2653 | gfx::Transform layer_to_surface_transform; |
| 2654 | layer_to_surface_transform.MakeIdentity(); |
| 2655 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2656 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2657 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2658 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2659 | |
| 2660 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2661 | // code is not testing the intended scenario. |
| 2662 | bool clipped; |
| 2663 | gfx::RectF clipped_rect = |
| 2664 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2665 | MathUtil::ProjectQuad( |
| 2666 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2667 | ASSERT_TRUE(clipped); |
| 2668 | |
| 2669 | // Only the corner of the layer is not visible on the surface because of being |
| 2670 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2671 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2672 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2673 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2674 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2675 | EXPECT_RECT_EQ(expected, actual); |
| 2676 | } |
| 2677 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2678 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2679 | scoped_refptr<Layer> root = Layer::Create(); |
| 2680 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2681 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2682 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2683 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2684 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2685 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2686 | root->AddChild(child1); |
| 2687 | root->AddChild(child2); |
| 2688 | root->AddChild(child3); |
| 2689 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2690 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2691 | host->SetRootLayer(root); |
| 2692 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2693 | gfx::Transform identity_matrix; |
| 2694 | SetLayerPropertiesForTesting(root.get(), |
| 2695 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2696 | gfx::PointF(), |
| 2697 | gfx::PointF(), |
| 2698 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2699 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2700 | false); |
| 2701 | SetLayerPropertiesForTesting(child1.get(), |
| 2702 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2703 | gfx::PointF(), |
| 2704 | gfx::PointF(), |
| 2705 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2706 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2707 | false); |
| 2708 | SetLayerPropertiesForTesting(child2.get(), |
| 2709 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2710 | gfx::PointF(), |
| 2711 | gfx::PointF(75.f, 75.f), |
| 2712 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2713 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2714 | false); |
| 2715 | SetLayerPropertiesForTesting(child3.get(), |
| 2716 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2717 | gfx::PointF(), |
| 2718 | gfx::PointF(125.f, 125.f), |
| 2719 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2720 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2721 | false); |
| 2722 | |
| 2723 | ExecuteCalculateDrawProperties(root.get()); |
| 2724 | |
| 2725 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2726 | root->render_surface()->DrawableContentRect()); |
| 2727 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2728 | |
| 2729 | // Layers that do not draw content should have empty visible_content_rects. |
| 2730 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2731 | |
| 2732 | // layer visible_content_rects are clipped by their target surface. |
| 2733 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2734 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 2735 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2736 | |
| 2737 | // layer drawable_content_rects are not clipped. |
| 2738 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2739 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2740 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2741 | } |
| 2742 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2743 | TEST_F(LayerTreeHostCommonTest, |
| 2744 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2745 | scoped_refptr<Layer> root = Layer::Create(); |
| 2746 | scoped_refptr<Layer> child = Layer::Create(); |
| 2747 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2748 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2749 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2750 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2751 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2752 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2753 | root->AddChild(child); |
| 2754 | child->AddChild(grand_child1); |
| 2755 | child->AddChild(grand_child2); |
| 2756 | child->AddChild(grand_child3); |
| 2757 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2758 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2759 | host->SetRootLayer(root); |
| 2760 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2761 | gfx::Transform identity_matrix; |
| 2762 | SetLayerPropertiesForTesting(root.get(), |
| 2763 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2764 | gfx::PointF(), |
| 2765 | gfx::PointF(), |
| 2766 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2767 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2768 | false); |
| 2769 | SetLayerPropertiesForTesting(child.get(), |
| 2770 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2771 | gfx::PointF(), |
| 2772 | gfx::PointF(), |
| 2773 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2774 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2775 | false); |
| 2776 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2777 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2778 | gfx::PointF(), |
| 2779 | gfx::PointF(5.f, 5.f), |
| 2780 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2781 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2782 | false); |
| 2783 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2784 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2785 | gfx::PointF(), |
| 2786 | gfx::PointF(75.f, 75.f), |
| 2787 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2788 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2789 | false); |
| 2790 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2791 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2792 | gfx::PointF(), |
| 2793 | gfx::PointF(125.f, 125.f), |
| 2794 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2795 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2796 | false); |
| 2797 | |
| 2798 | child->SetMasksToBounds(true); |
| 2799 | ExecuteCalculateDrawProperties(root.get()); |
| 2800 | |
| 2801 | ASSERT_FALSE(child->render_surface()); |
| 2802 | |
| 2803 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2804 | root->render_surface()->DrawableContentRect()); |
| 2805 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2806 | |
| 2807 | // Layers that do not draw content should have empty visible content rects. |
| 2808 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2809 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
| 2810 | |
| 2811 | // All grandchild visible content rects should be clipped by child. |
| 2812 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2813 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
| 2814 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2815 | |
| 2816 | // All grandchild DrawableContentRects should also be clipped by child. |
| 2817 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), |
| 2818 | grand_child1->drawable_content_rect()); |
| 2819 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25), |
| 2820 | grand_child2->drawable_content_rect()); |
| 2821 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2822 | } |
| 2823 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2824 | TEST_F(LayerTreeHostCommonTest, |
| 2825 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2826 | scoped_refptr<Layer> root = Layer::Create(); |
| 2827 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2828 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2829 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2830 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2831 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2832 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2833 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2834 | root->AddChild(render_surface1); |
| 2835 | render_surface1->AddChild(child1); |
| 2836 | render_surface1->AddChild(child2); |
| 2837 | render_surface1->AddChild(child3); |
| 2838 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2839 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2840 | host->SetRootLayer(root); |
| 2841 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2842 | gfx::Transform identity_matrix; |
| 2843 | SetLayerPropertiesForTesting(root.get(), |
| 2844 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2845 | gfx::PointF(), |
| 2846 | gfx::PointF(), |
| 2847 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2848 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2849 | false); |
| 2850 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2851 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2852 | gfx::PointF(), |
| 2853 | gfx::PointF(), |
| 2854 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2855 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2856 | false); |
| 2857 | SetLayerPropertiesForTesting(child1.get(), |
| 2858 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2859 | gfx::PointF(), |
| 2860 | gfx::PointF(5.f, 5.f), |
| 2861 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2862 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2863 | false); |
| 2864 | SetLayerPropertiesForTesting(child2.get(), |
| 2865 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2866 | gfx::PointF(), |
| 2867 | gfx::PointF(75.f, 75.f), |
| 2868 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2869 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2870 | false); |
| 2871 | SetLayerPropertiesForTesting(child3.get(), |
| 2872 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2873 | gfx::PointF(), |
| 2874 | gfx::PointF(125.f, 125.f), |
| 2875 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2876 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2877 | false); |
| 2878 | |
| 2879 | render_surface1->SetForceRenderSurface(true); |
| 2880 | ExecuteCalculateDrawProperties(root.get()); |
| 2881 | |
| 2882 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2883 | |
| 2884 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2885 | root->render_surface()->DrawableContentRect()); |
| 2886 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2887 | |
| 2888 | // Layers that do not draw content should have empty visible content rects. |
| 2889 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2890 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 2891 | render_surface1->visible_content_rect()); |
| 2892 | |
| 2893 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2894 | // regions of the subtree. |
| 2895 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2896 | render_surface1->render_surface()->DrawableContentRect()); |
| 2897 | |
| 2898 | // All layers that draw content into the unclipped surface are also unclipped. |
| 2899 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2900 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2901 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 2902 | |
| 2903 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2904 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2905 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2906 | } |
| 2907 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2908 | TEST_F(LayerTreeHostCommonTest, |
| 2909 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2910 | scoped_refptr<Layer> root = Layer::Create(); |
| 2911 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2912 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2913 | root->AddChild(child); |
| 2914 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2915 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2916 | host->SetRootLayer(root); |
| 2917 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2918 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2919 | gfx::Transform identity_matrix; |
| 2920 | 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] | 2921 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2922 | |
| 2923 | SetLayerPropertiesForTesting(root.get(), |
| 2924 | identity_matrix, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2925 | gfx::PointF(), |
| 2926 | gfx::PointF(), |
| 2927 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2928 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2929 | false); |
| 2930 | SetLayerPropertiesForTesting(child.get(), |
| 2931 | uninvertible_matrix, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2932 | gfx::PointF(), |
| 2933 | gfx::PointF(5.f, 5.f), |
| 2934 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2935 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2936 | false); |
| 2937 | |
| 2938 | ExecuteCalculateDrawProperties(root.get()); |
| 2939 | |
| 2940 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2941 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2942 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2943 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 2944 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 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 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2959 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2960 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2961 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2962 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2963 | uninvertible_matrix.MakeIdentity(); |
| 2964 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2965 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2966 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2967 | |
| 2968 | SetLayerPropertiesForTesting(child.get(), |
| 2969 | uninvertible_matrix, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2970 | gfx::PointF(), |
| 2971 | gfx::PointF(5.f, 5.f), |
| 2972 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2973 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2974 | false); |
| 2975 | |
| 2976 | ExecuteCalculateDrawProperties(root.get()); |
| 2977 | |
| 2978 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2979 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2980 | } |
| 2981 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2982 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2983 | SingularTransformDoesNotPreventClearingDrawProperties) { |
| 2984 | scoped_refptr<Layer> root = Layer::Create(); |
| 2985 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2986 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2987 | root->AddChild(child); |
| 2988 | |
| 2989 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2990 | host->SetRootLayer(root); |
| 2991 | |
| 2992 | gfx::Transform identity_matrix; |
| 2993 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 2994 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2995 | |
| 2996 | SetLayerPropertiesForTesting(root.get(), |
| 2997 | uninvertible_matrix, |
| 2998 | gfx::PointF(), |
| 2999 | gfx::PointF(), |
| 3000 | gfx::Size(100, 100), |
| 3001 | true, |
| 3002 | false); |
| 3003 | SetLayerPropertiesForTesting(child.get(), |
| 3004 | identity_matrix, |
| 3005 | gfx::PointF(), |
| 3006 | gfx::PointF(5.f, 5.f), |
| 3007 | gfx::Size(50, 50), |
| 3008 | true, |
| 3009 | false); |
| 3010 | |
| 3011 | child->draw_properties().sorted_for_recursion = true; |
| 3012 | |
| 3013 | TransformOperations start_transform_operations; |
| 3014 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 3015 | |
| 3016 | TransformOperations end_transform_operations; |
| 3017 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 3018 | |
| 3019 | AddAnimatedTransformToLayer( |
| 3020 | root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 3021 | |
| 3022 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 3023 | |
| 3024 | ExecuteCalculateDrawProperties(root.get()); |
| 3025 | |
| 3026 | EXPECT_FALSE(child->draw_properties().sorted_for_recursion); |
| 3027 | } |
| 3028 | |
| 3029 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3030 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3031 | scoped_refptr<Layer> root = Layer::Create(); |
| 3032 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3033 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3034 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3035 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3036 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3037 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3038 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3039 | root->AddChild(render_surface1); |
| 3040 | render_surface1->AddChild(child1); |
| 3041 | render_surface1->AddChild(child2); |
| 3042 | render_surface1->AddChild(child3); |
| 3043 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3044 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3045 | host->SetRootLayer(root); |
| 3046 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3047 | gfx::Transform identity_matrix; |
| 3048 | SetLayerPropertiesForTesting(root.get(), |
| 3049 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3050 | gfx::PointF(), |
| 3051 | gfx::PointF(), |
| 3052 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3053 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3054 | false); |
| 3055 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3056 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3057 | gfx::PointF(), |
| 3058 | gfx::PointF(), |
| 3059 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3060 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3061 | false); |
| 3062 | SetLayerPropertiesForTesting(child1.get(), |
| 3063 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3064 | gfx::PointF(), |
| 3065 | gfx::PointF(5.f, 5.f), |
| 3066 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3067 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3068 | false); |
| 3069 | SetLayerPropertiesForTesting(child2.get(), |
| 3070 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3071 | gfx::PointF(), |
| 3072 | gfx::PointF(75.f, 75.f), |
| 3073 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3074 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3075 | false); |
| 3076 | SetLayerPropertiesForTesting(child3.get(), |
| 3077 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3078 | gfx::PointF(), |
| 3079 | gfx::PointF(125.f, 125.f), |
| 3080 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3081 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3082 | false); |
| 3083 | |
| 3084 | root->SetMasksToBounds(true); |
| 3085 | render_surface1->SetForceRenderSurface(true); |
| 3086 | ExecuteCalculateDrawProperties(root.get()); |
| 3087 | |
| 3088 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3089 | |
| 3090 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3091 | root->render_surface()->DrawableContentRect()); |
| 3092 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3093 | |
| 3094 | // Layers that do not draw content should have empty visible content rects. |
| 3095 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3096 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3097 | render_surface1->visible_content_rect()); |
| 3098 | |
| 3099 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3100 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3101 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3102 | render_surface1->render_surface()->DrawableContentRect()); |
| 3103 | |
| 3104 | // All layers that draw content into the surface have their visible content |
| 3105 | // rect clipped by the surface clip rect. |
| 3106 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3107 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 3108 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3109 | |
| 3110 | // But the DrawableContentRects are unclipped. |
| 3111 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3112 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3113 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3114 | } |
| 3115 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3116 | TEST_F(LayerTreeHostCommonTest, |
| 3117 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3118 | // Check that clipping does not propagate down surfaces. |
| 3119 | scoped_refptr<Layer> root = Layer::Create(); |
| 3120 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3121 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3122 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3123 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3124 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3125 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3126 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3127 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3128 | root->AddChild(render_surface1); |
| 3129 | render_surface1->AddChild(render_surface2); |
| 3130 | render_surface2->AddChild(child1); |
| 3131 | render_surface2->AddChild(child2); |
| 3132 | render_surface2->AddChild(child3); |
| 3133 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3134 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3135 | host->SetRootLayer(root); |
| 3136 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3137 | gfx::Transform identity_matrix; |
| 3138 | SetLayerPropertiesForTesting(root.get(), |
| 3139 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3140 | gfx::PointF(), |
| 3141 | gfx::PointF(), |
| 3142 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3143 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3144 | false); |
| 3145 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3146 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3147 | gfx::PointF(), |
| 3148 | gfx::PointF(), |
| 3149 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3150 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3151 | false); |
| 3152 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3153 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3154 | gfx::PointF(), |
| 3155 | gfx::PointF(), |
| 3156 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3157 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3158 | false); |
| 3159 | SetLayerPropertiesForTesting(child1.get(), |
| 3160 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3161 | gfx::PointF(), |
| 3162 | gfx::PointF(5.f, 5.f), |
| 3163 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3164 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3165 | false); |
| 3166 | SetLayerPropertiesForTesting(child2.get(), |
| 3167 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3168 | gfx::PointF(), |
| 3169 | gfx::PointF(75.f, 75.f), |
| 3170 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3171 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3172 | false); |
| 3173 | SetLayerPropertiesForTesting(child3.get(), |
| 3174 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3175 | gfx::PointF(), |
| 3176 | gfx::PointF(125.f, 125.f), |
| 3177 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3178 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3179 | false); |
| 3180 | |
| 3181 | root->SetMasksToBounds(true); |
| 3182 | render_surface1->SetForceRenderSurface(true); |
| 3183 | render_surface2->SetForceRenderSurface(true); |
| 3184 | ExecuteCalculateDrawProperties(root.get()); |
| 3185 | |
| 3186 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3187 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3188 | |
| 3189 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3190 | root->render_surface()->DrawableContentRect()); |
| 3191 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3192 | |
| 3193 | // Layers that do not draw content should have empty visible content rects. |
| 3194 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3195 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3196 | render_surface1->visible_content_rect()); |
| 3197 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3198 | render_surface2->visible_content_rect()); |
| 3199 | |
| 3200 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3201 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3202 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3203 | render_surface1->render_surface()->DrawableContentRect()); |
| 3204 | |
| 3205 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3206 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3207 | // render_surface2 grows to enclose all drawable content of its subtree. |
| 3208 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3209 | render_surface2->render_surface()->DrawableContentRect()); |
| 3210 | |
| 3211 | // All layers that draw content into render_surface2 think they are unclipped. |
| 3212 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3213 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3214 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 3215 | |
| 3216 | // DrawableContentRects are also unclipped. |
| 3217 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3218 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3219 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3220 | } |
| 3221 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3222 | TEST_F(LayerTreeHostCommonTest, |
| 3223 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3224 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3225 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3226 | |
| 3227 | scoped_refptr<Layer> root = Layer::Create(); |
| 3228 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3229 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3230 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3231 | root->AddChild(render_surface1); |
| 3232 | render_surface1->AddChild(child1); |
| 3233 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3234 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3235 | host->SetRootLayer(root); |
| 3236 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3237 | gfx::Transform identity_matrix; |
| 3238 | gfx::Transform child_rotation; |
| 3239 | child_rotation.Rotate(45.0); |
| 3240 | SetLayerPropertiesForTesting(root.get(), |
| 3241 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3242 | gfx::PointF(), |
| 3243 | gfx::PointF(), |
| 3244 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3245 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3246 | false); |
| 3247 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3248 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3249 | gfx::PointF(), |
| 3250 | gfx::PointF(), |
| 3251 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3252 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3253 | false); |
| 3254 | SetLayerPropertiesForTesting(child1.get(), |
| 3255 | child_rotation, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3256 | gfx::PointF(0.5f, 0.5f), |
| 3257 | gfx::PointF(25.f, 25.f), |
| 3258 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3259 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3260 | false); |
| 3261 | |
| 3262 | render_surface1->SetForceRenderSurface(true); |
| 3263 | ExecuteCalculateDrawProperties(root.get()); |
| 3264 | |
| 3265 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3266 | |
| 3267 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3268 | root->render_surface()->DrawableContentRect()); |
| 3269 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3270 | |
| 3271 | // Layers that do not draw content should have empty visible content rects. |
| 3272 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3273 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3274 | render_surface1->visible_content_rect()); |
| 3275 | |
| 3276 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3277 | // regions of the subtree. |
| 3278 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3279 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3280 | gfx::Rect(50 - diagonal_radius, |
| 3281 | 50 - diagonal_radius, |
| 3282 | diagonal_radius * 2, |
| 3283 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3284 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3285 | render_surface1->render_surface()->DrawableContentRect()); |
| 3286 | |
| 3287 | // All layers that draw content into the unclipped surface are also unclipped. |
| 3288 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3289 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3290 | child1->drawable_content_rect()); |
| 3291 | } |
| 3292 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3293 | TEST_F(LayerTreeHostCommonTest, |
| 3294 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3295 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3296 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3297 | |
| 3298 | scoped_refptr<Layer> root = Layer::Create(); |
| 3299 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3300 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3301 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3302 | root->AddChild(render_surface1); |
| 3303 | render_surface1->AddChild(child1); |
| 3304 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3305 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3306 | host->SetRootLayer(root); |
| 3307 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3308 | gfx::Transform identity_matrix; |
| 3309 | gfx::Transform child_rotation; |
| 3310 | child_rotation.Rotate(45.0); |
| 3311 | SetLayerPropertiesForTesting(root.get(), |
| 3312 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3313 | gfx::PointF(), |
| 3314 | gfx::PointF(), |
| 3315 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3316 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3317 | false); |
| 3318 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3319 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3320 | gfx::PointF(), |
| 3321 | gfx::PointF(), |
| 3322 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3323 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3324 | false); |
| 3325 | SetLayerPropertiesForTesting(child1.get(), |
| 3326 | child_rotation, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3327 | gfx::PointF(0.5f, 0.5f), |
| 3328 | gfx::PointF(25.f, 25.f), |
| 3329 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3330 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3331 | false); |
| 3332 | |
| 3333 | root->SetMasksToBounds(true); |
| 3334 | render_surface1->SetForceRenderSurface(true); |
| 3335 | ExecuteCalculateDrawProperties(root.get()); |
| 3336 | |
| 3337 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3338 | |
| 3339 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3340 | // rotated layer. |
| 3341 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3342 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3343 | 50 - diagonal_radius, |
| 3344 | diagonal_radius * 2, |
| 3345 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3346 | gfx::Rect expected_surface_drawable_content = |
| 3347 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
| 3348 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3349 | render_surface1->render_surface()->DrawableContentRect()); |
| 3350 | |
| 3351 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3352 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3353 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3354 | // |
| 3355 | // Given the floating point math, this number is a little bit fuzzy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3356 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
| 3357 | |
| 3358 | // The child's DrawableContentRect is unclipped. |
| 3359 | EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
| 3360 | } |
| 3361 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3362 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3363 | MockContentLayerClient client; |
| 3364 | |
| 3365 | scoped_refptr<Layer> root = Layer::Create(); |
| 3366 | scoped_refptr<ContentLayer> render_surface1 = |
| 3367 | CreateDrawableContentLayer(&client); |
| 3368 | scoped_refptr<ContentLayer> render_surface2 = |
| 3369 | CreateDrawableContentLayer(&client); |
| 3370 | scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client); |
| 3371 | scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client); |
| 3372 | scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client); |
| 3373 | root->AddChild(render_surface1); |
| 3374 | render_surface1->AddChild(render_surface2); |
| 3375 | render_surface2->AddChild(child1); |
| 3376 | render_surface2->AddChild(child2); |
| 3377 | render_surface2->AddChild(child3); |
| 3378 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3379 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3380 | host->SetRootLayer(root); |
| 3381 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3382 | gfx::Transform identity_matrix; |
| 3383 | SetLayerPropertiesForTesting(root.get(), |
| 3384 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3385 | gfx::PointF(), |
| 3386 | gfx::PointF(), |
| 3387 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3388 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3389 | false); |
| 3390 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3391 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3392 | gfx::PointF(), |
| 3393 | gfx::PointF(5.f, 5.f), |
| 3394 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3395 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3396 | false); |
| 3397 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3398 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3399 | gfx::PointF(), |
| 3400 | gfx::PointF(5.f, 5.f), |
| 3401 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3402 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3403 | false); |
| 3404 | SetLayerPropertiesForTesting(child1.get(), |
| 3405 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3406 | gfx::PointF(), |
| 3407 | gfx::PointF(5.f, 5.f), |
| 3408 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3409 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3410 | false); |
| 3411 | SetLayerPropertiesForTesting(child2.get(), |
| 3412 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3413 | gfx::PointF(), |
| 3414 | gfx::PointF(75.f, 75.f), |
| 3415 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3416 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3417 | false); |
| 3418 | SetLayerPropertiesForTesting(child3.get(), |
| 3419 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3420 | gfx::PointF(), |
| 3421 | gfx::PointF(125.f, 125.f), |
| 3422 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3423 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3424 | false); |
| 3425 | |
| 3426 | float device_scale_factor = 2.f; |
| 3427 | |
| 3428 | root->SetMasksToBounds(true); |
| 3429 | render_surface1->SetForceRenderSurface(true); |
| 3430 | render_surface2->SetForceRenderSurface(true); |
| 3431 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3432 | |
| 3433 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3434 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3435 | |
| 3436 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3437 | // device_scale_factor. |
| 3438 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3439 | root->render_surface()->DrawableContentRect()); |
| 3440 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3441 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3442 | render_surface1->render_surface()->DrawableContentRect()); |
| 3443 | |
| 3444 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3445 | // is only implicitly clipped by render_surface1. |
| 3446 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3447 | render_surface2->render_surface()->DrawableContentRect()); |
| 3448 | |
| 3449 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3450 | EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), |
| 3451 | child2->drawable_content_rect()); |
| 3452 | EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), |
| 3453 | child3->drawable_content_rect()); |
| 3454 | |
| 3455 | // The root layer does not actually draw content of its own. |
| 3456 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3457 | |
| 3458 | // All layer visible content rects are expressed in content space of each |
| 3459 | // layer, so they are also scaled by the device_scale_factor. |
| 3460 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8), |
| 3461 | render_surface1->visible_content_rect()); |
| 3462 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26), |
| 3463 | render_surface2->visible_content_rect()); |
| 3464 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect()); |
| 3465 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect()); |
| 3466 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect()); |
| 3467 | } |
| 3468 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3469 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3470 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3471 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3472 | // "flattened" to each parent layer according to current W3C spec. |
| 3473 | |
| 3474 | const gfx::Transform identity_matrix; |
| 3475 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3476 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3477 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3478 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3479 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3480 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3481 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3482 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3483 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3484 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3485 | front_facing_child_of_front_facing_surface = |
| 3486 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3487 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3488 | back_facing_child_of_front_facing_surface = |
| 3489 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3490 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3491 | front_facing_child_of_back_facing_surface = |
| 3492 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3493 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3494 | back_facing_child_of_back_facing_surface = |
| 3495 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3496 | |
| 3497 | parent->AddChild(front_facing_child); |
| 3498 | parent->AddChild(back_facing_child); |
| 3499 | parent->AddChild(front_facing_surface); |
| 3500 | parent->AddChild(back_facing_surface); |
| 3501 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3502 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3503 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3504 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3505 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3506 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3507 | host->SetRootLayer(parent); |
| 3508 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3509 | // Nothing is double-sided |
| 3510 | front_facing_child->SetDoubleSided(false); |
| 3511 | back_facing_child->SetDoubleSided(false); |
| 3512 | front_facing_surface->SetDoubleSided(false); |
| 3513 | back_facing_surface->SetDoubleSided(false); |
| 3514 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3515 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3516 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3517 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3518 | |
| 3519 | gfx::Transform backface_matrix; |
| 3520 | backface_matrix.Translate(50.0, 50.0); |
| 3521 | backface_matrix.RotateAboutYAxis(180.0); |
| 3522 | backface_matrix.Translate(-50.0, -50.0); |
| 3523 | |
| 3524 | // Having a descendant and opacity will force these to have render surfaces. |
| 3525 | front_facing_surface->SetOpacity(0.5f); |
| 3526 | back_facing_surface->SetOpacity(0.5f); |
| 3527 | |
| 3528 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3529 | // these layers should blindly use their own local transforms to determine |
| 3530 | // back-face culling. |
| 3531 | SetLayerPropertiesForTesting(parent.get(), |
| 3532 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3533 | gfx::PointF(), |
| 3534 | gfx::PointF(), |
| 3535 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3536 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3537 | false); |
| 3538 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3539 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3540 | gfx::PointF(), |
| 3541 | gfx::PointF(), |
| 3542 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3543 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3544 | false); |
| 3545 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3546 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3547 | gfx::PointF(), |
| 3548 | gfx::PointF(), |
| 3549 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3550 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3551 | false); |
| 3552 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3553 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3554 | gfx::PointF(), |
| 3555 | gfx::PointF(), |
| 3556 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3557 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3558 | false); |
| 3559 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3560 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3561 | gfx::PointF(), |
| 3562 | gfx::PointF(), |
| 3563 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3564 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3565 | false); |
| 3566 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3567 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3568 | gfx::PointF(), |
| 3569 | gfx::PointF(), |
| 3570 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3571 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3572 | false); |
| 3573 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3574 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3575 | gfx::PointF(), |
| 3576 | gfx::PointF(), |
| 3577 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3578 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3579 | false); |
| 3580 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3581 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3582 | gfx::PointF(), |
| 3583 | gfx::PointF(), |
| 3584 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3585 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3586 | false); |
| 3587 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3588 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3589 | gfx::PointF(), |
| 3590 | gfx::PointF(), |
| 3591 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3592 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3593 | false); |
| 3594 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3595 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3596 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3597 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3598 | inputs.can_adjust_raster_scales = true; |
| 3599 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3600 | |
| 3601 | // Verify which render surfaces were created. |
| 3602 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3603 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3604 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3605 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3606 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3607 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3608 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3609 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3610 | |
| 3611 | // Verify the render_surface_layer_list. |
| 3612 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3613 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3614 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3615 | // Even though the back facing surface LAYER gets culled, the other |
| 3616 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3617 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3618 | |
| 3619 | // Verify root surface's layer list. |
| 3620 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3621 | 3u, |
| 3622 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3623 | EXPECT_EQ(front_facing_child->id(), |
| 3624 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3625 | ->render_surface() |
| 3626 | ->layer_list() |
| 3627 | .at(0) |
| 3628 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3629 | EXPECT_EQ(front_facing_surface->id(), |
| 3630 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3631 | ->render_surface() |
| 3632 | ->layer_list() |
| 3633 | .at(1) |
| 3634 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3635 | EXPECT_EQ(back_facing_surface->id(), |
| 3636 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3637 | ->render_surface() |
| 3638 | ->layer_list() |
| 3639 | .at(2) |
| 3640 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3641 | |
| 3642 | // Verify front_facing_surface's layer list. |
| 3643 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3644 | 2u, |
| 3645 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3646 | EXPECT_EQ(front_facing_surface->id(), |
| 3647 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3648 | ->render_surface() |
| 3649 | ->layer_list() |
| 3650 | .at(0) |
| 3651 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3652 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3653 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3654 | ->render_surface() |
| 3655 | ->layer_list() |
| 3656 | .at(1) |
| 3657 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3658 | |
| 3659 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3660 | // from the surface list. |
| 3661 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3662 | 1u, |
| 3663 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3664 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3665 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3666 | ->render_surface() |
| 3667 | ->layer_list() |
| 3668 | .at(0) |
| 3669 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3670 | } |
| 3671 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3672 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3673 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3674 | // is used. |
| 3675 | |
| 3676 | const gfx::Transform identity_matrix; |
| 3677 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3678 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3679 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3680 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3681 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3682 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3683 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3684 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3685 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3686 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3687 | front_facing_child_of_front_facing_surface = |
| 3688 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3689 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3690 | back_facing_child_of_front_facing_surface = |
| 3691 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3692 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3693 | front_facing_child_of_back_facing_surface = |
| 3694 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3695 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3696 | back_facing_child_of_back_facing_surface = |
| 3697 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3698 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3699 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3700 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3701 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3702 | |
| 3703 | parent->AddChild(front_facing_child); |
| 3704 | parent->AddChild(back_facing_child); |
| 3705 | parent->AddChild(front_facing_surface); |
| 3706 | parent->AddChild(back_facing_surface); |
| 3707 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3708 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3709 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3710 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3711 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3712 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3713 | host->SetRootLayer(parent); |
| 3714 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3715 | // Nothing is double-sided |
| 3716 | front_facing_child->SetDoubleSided(false); |
| 3717 | back_facing_child->SetDoubleSided(false); |
| 3718 | front_facing_surface->SetDoubleSided(false); |
| 3719 | back_facing_surface->SetDoubleSided(false); |
| 3720 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3721 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3722 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3723 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3724 | |
| 3725 | gfx::Transform backface_matrix; |
| 3726 | backface_matrix.Translate(50.0, 50.0); |
| 3727 | backface_matrix.RotateAboutYAxis(180.0); |
| 3728 | backface_matrix.Translate(-50.0, -50.0); |
| 3729 | |
| 3730 | // Opacity will not force creation of render surfaces in this case because of |
| 3731 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3732 | // would be created with preserve-3d is when there is a replica layer. |
| 3733 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3734 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3735 | |
| 3736 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3737 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3738 | // rendering context should use the transform with respect to that context. |
| 3739 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3740 | // and (b) the layer's transform style is preserve-3d. |
| 3741 | SetLayerPropertiesForTesting(parent.get(), |
| 3742 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3743 | gfx::PointF(), |
| 3744 | gfx::PointF(), |
| 3745 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3746 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3747 | false); // parent transform style is flat. |
| 3748 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3749 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3750 | gfx::PointF(), |
| 3751 | gfx::PointF(), |
| 3752 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3753 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3754 | false); |
| 3755 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3756 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3757 | gfx::PointF(), |
| 3758 | gfx::PointF(), |
| 3759 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3760 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3761 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3762 | // surface transform style is preserve-3d. |
| 3763 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3764 | identity_matrix, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3765 | gfx::PointF(), |
| 3766 | gfx::PointF(), |
| 3767 | gfx::Size(100, 100), |
| 3768 | false, |
| 3769 | true); |
| 3770 | // surface transform style is preserve-3d. |
| 3771 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3772 | backface_matrix, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3773 | gfx::PointF(), |
| 3774 | gfx::PointF(), |
| 3775 | gfx::Size(100, 100), |
| 3776 | false, |
| 3777 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3778 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3779 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3780 | gfx::PointF(), |
| 3781 | gfx::PointF(), |
| 3782 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3783 | true, |
| 3784 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3785 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3786 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3787 | gfx::PointF(), |
| 3788 | gfx::PointF(), |
| 3789 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3790 | true, |
| 3791 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3792 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3793 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3794 | gfx::PointF(), |
| 3795 | gfx::PointF(), |
| 3796 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3797 | true, |
| 3798 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3799 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3800 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3801 | gfx::PointF(), |
| 3802 | gfx::PointF(), |
| 3803 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3804 | true, |
| 3805 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3806 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3807 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3808 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3809 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3810 | inputs.can_adjust_raster_scales = true; |
| 3811 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3812 | |
| 3813 | // Verify which render surfaces were created. |
| 3814 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3815 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3816 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3817 | EXPECT_FALSE(back_facing_surface->render_surface()); |
| 3818 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3819 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3820 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3821 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3822 | |
| 3823 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3824 | // culled. |
| 3825 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3826 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3827 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3828 | |
| 3829 | // Verify root surface's layer list. |
| 3830 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3831 | 2u, |
| 3832 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3833 | EXPECT_EQ(front_facing_child->id(), |
| 3834 | render_surface_layer_list.at(0) |
| 3835 | ->render_surface()->layer_list().at(0)->id()); |
| 3836 | EXPECT_EQ(front_facing_surface->id(), |
| 3837 | render_surface_layer_list.at(0) |
| 3838 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3839 | |
| 3840 | // Verify front_facing_surface's layer list. |
| 3841 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3842 | 2u, |
| 3843 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3844 | EXPECT_EQ(front_facing_surface->id(), |
| 3845 | render_surface_layer_list.at(1) |
| 3846 | ->render_surface()->layer_list().at(0)->id()); |
| 3847 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3848 | render_surface_layer_list.at(1) |
| 3849 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3850 | } |
| 3851 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3852 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3853 | // Verify that layers are appropriately culled when their back face is showing |
| 3854 | // and they are not double sided, while animations are going on. |
| 3855 | // |
| 3856 | // Layers that are animating do not get culled on the main thread, as their |
| 3857 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3858 | // back face is really showing. |
| 3859 | const gfx::Transform identity_matrix; |
| 3860 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3861 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3862 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3863 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3864 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3865 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3866 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3867 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3868 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3869 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3870 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3871 | |
| 3872 | parent->AddChild(child); |
| 3873 | parent->AddChild(animating_surface); |
| 3874 | animating_surface->AddChild(child_of_animating_surface); |
| 3875 | parent->AddChild(animating_child); |
| 3876 | parent->AddChild(child2); |
| 3877 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3878 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3879 | host->SetRootLayer(parent); |
| 3880 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3881 | // Nothing is double-sided |
| 3882 | child->SetDoubleSided(false); |
| 3883 | child2->SetDoubleSided(false); |
| 3884 | animating_surface->SetDoubleSided(false); |
| 3885 | child_of_animating_surface->SetDoubleSided(false); |
| 3886 | animating_child->SetDoubleSided(false); |
| 3887 | |
| 3888 | gfx::Transform backface_matrix; |
| 3889 | backface_matrix.Translate(50.0, 50.0); |
| 3890 | backface_matrix.RotateAboutYAxis(180.0); |
| 3891 | backface_matrix.Translate(-50.0, -50.0); |
| 3892 | |
| 3893 | // Make our render surface. |
| 3894 | animating_surface->SetForceRenderSurface(true); |
| 3895 | |
| 3896 | // Animate the transform on the render surface. |
| 3897 | AddAnimatedTransformToController( |
| 3898 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 3899 | // This is just an animating layer, not a surface. |
| 3900 | AddAnimatedTransformToController( |
| 3901 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 3902 | |
| 3903 | SetLayerPropertiesForTesting(parent.get(), |
| 3904 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3905 | gfx::PointF(), |
| 3906 | gfx::PointF(), |
| 3907 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3908 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3909 | false); |
| 3910 | SetLayerPropertiesForTesting(child.get(), |
| 3911 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3912 | gfx::PointF(), |
| 3913 | gfx::PointF(), |
| 3914 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3915 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3916 | false); |
| 3917 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 3918 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3919 | gfx::PointF(), |
| 3920 | gfx::PointF(), |
| 3921 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3922 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3923 | false); |
| 3924 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 3925 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3926 | gfx::PointF(), |
| 3927 | gfx::PointF(), |
| 3928 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3929 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3930 | false); |
| 3931 | SetLayerPropertiesForTesting(animating_child.get(), |
| 3932 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3933 | gfx::PointF(), |
| 3934 | gfx::PointF(), |
| 3935 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3936 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3937 | false); |
| 3938 | SetLayerPropertiesForTesting(child2.get(), |
| 3939 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3940 | gfx::PointF(), |
| 3941 | gfx::PointF(), |
| 3942 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3943 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3944 | false); |
| 3945 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3946 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3947 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3948 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3949 | inputs.can_adjust_raster_scales = true; |
| 3950 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3951 | |
| 3952 | EXPECT_FALSE(child->render_surface()); |
| 3953 | EXPECT_TRUE(animating_surface->render_surface()); |
| 3954 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 3955 | EXPECT_FALSE(animating_child->render_surface()); |
| 3956 | EXPECT_FALSE(child2->render_surface()); |
| 3957 | |
| 3958 | // Verify that the animating_child and child_of_animating_surface were not |
| 3959 | // culled, but that child was. |
| 3960 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3961 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3962 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3963 | |
| 3964 | // The non-animating child be culled from the layer list for the parent render |
| 3965 | // surface. |
| 3966 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3967 | 3u, |
| 3968 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3969 | EXPECT_EQ(animating_surface->id(), |
| 3970 | render_surface_layer_list.at(0) |
| 3971 | ->render_surface()->layer_list().at(0)->id()); |
| 3972 | EXPECT_EQ(animating_child->id(), |
| 3973 | render_surface_layer_list.at(0) |
| 3974 | ->render_surface()->layer_list().at(1)->id()); |
| 3975 | EXPECT_EQ(child2->id(), |
| 3976 | render_surface_layer_list.at(0) |
| 3977 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3978 | |
| 3979 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3980 | 2u, |
| 3981 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3982 | EXPECT_EQ(animating_surface->id(), |
| 3983 | render_surface_layer_list.at(1) |
| 3984 | ->render_surface()->layer_list().at(0)->id()); |
| 3985 | EXPECT_EQ(child_of_animating_surface->id(), |
| 3986 | render_surface_layer_list.at(1) |
| 3987 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3988 | |
| 3989 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 3990 | |
| 3991 | // The animating layers should have a visible content rect that represents the |
| 3992 | // area of the front face that is within the viewport. |
| 3993 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3994 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3995 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3996 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3997 | // And layers in the subtree of the animating layer should have valid visible |
| 3998 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3999 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 4000 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4001 | } |
| 4002 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4003 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4004 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4005 | // Verify the behavior of back-face culling for a render surface that is |
| 4006 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4007 | |
| 4008 | const gfx::Transform identity_matrix; |
| 4009 | scoped_refptr<Layer> parent = Layer::Create(); |
| 4010 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 4011 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4012 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 4013 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4014 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 4015 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4016 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 4017 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4018 | |
| 4019 | parent->AddChild(front_facing_surface); |
| 4020 | parent->AddChild(back_facing_surface); |
| 4021 | front_facing_surface->AddChild(child1); |
| 4022 | back_facing_surface->AddChild(child2); |
| 4023 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4024 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4025 | host->SetRootLayer(parent); |
| 4026 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4027 | // RenderSurfaces are not double-sided |
| 4028 | front_facing_surface->SetDoubleSided(false); |
| 4029 | back_facing_surface->SetDoubleSided(false); |
| 4030 | |
| 4031 | gfx::Transform backface_matrix; |
| 4032 | backface_matrix.Translate(50.0, 50.0); |
| 4033 | backface_matrix.RotateAboutYAxis(180.0); |
| 4034 | backface_matrix.Translate(-50.0, -50.0); |
| 4035 | |
| 4036 | SetLayerPropertiesForTesting(parent.get(), |
| 4037 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4038 | gfx::PointF(), |
| 4039 | gfx::PointF(), |
| 4040 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4041 | false, |
| 4042 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4043 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4044 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4045 | gfx::PointF(), |
| 4046 | gfx::PointF(), |
| 4047 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4048 | true, |
| 4049 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4050 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4051 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4052 | gfx::PointF(), |
| 4053 | gfx::PointF(), |
| 4054 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4055 | true, |
| 4056 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4057 | SetLayerPropertiesForTesting(child1.get(), |
| 4058 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4059 | gfx::PointF(), |
| 4060 | gfx::PointF(), |
| 4061 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4062 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4063 | false); |
| 4064 | SetLayerPropertiesForTesting(child2.get(), |
| 4065 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4066 | gfx::PointF(), |
| 4067 | gfx::PointF(), |
| 4068 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4069 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4070 | false); |
| 4071 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4072 | front_facing_surface->SetIs3dSorted(true); |
| 4073 | back_facing_surface->SetIs3dSorted(true); |
| 4074 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4075 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4076 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4077 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4078 | inputs.can_adjust_raster_scales = true; |
| 4079 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4080 | |
| 4081 | // Verify which render surfaces were created. |
| 4082 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 4083 | EXPECT_FALSE( |
| 4084 | back_facing_surface->render_surface()); // because it should be culled |
| 4085 | EXPECT_FALSE(child1->render_surface()); |
| 4086 | EXPECT_FALSE(child2->render_surface()); |
| 4087 | |
| 4088 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4089 | // culled. |
| 4090 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4091 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4092 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4093 | |
| 4094 | // Verify root surface's layer list. |
| 4095 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4096 | 1u, |
| 4097 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4098 | EXPECT_EQ(front_facing_surface->id(), |
| 4099 | render_surface_layer_list.at(0) |
| 4100 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4101 | |
| 4102 | // Verify front_facing_surface's layer list. |
| 4103 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4104 | 2u, |
| 4105 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4106 | EXPECT_EQ(front_facing_surface->id(), |
| 4107 | render_surface_layer_list.at(1) |
| 4108 | ->render_surface()->layer_list().at(0)->id()); |
| 4109 | EXPECT_EQ(child1->id(), |
| 4110 | render_surface_layer_list.at(1) |
| 4111 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4112 | } |
| 4113 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4114 | |
| 4115 | TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4116 | // Hit testing on an empty render_surface_layer_list should return a null |
| 4117 | // pointer. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4118 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4119 | |
| 4120 | gfx::Point test_point(0, 0); |
| 4121 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4122 | test_point, render_surface_layer_list); |
| 4123 | EXPECT_FALSE(result_layer); |
| 4124 | |
| 4125 | test_point = gfx::Point(10, 20); |
| 4126 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4127 | test_point, render_surface_layer_list); |
| 4128 | EXPECT_FALSE(result_layer); |
| 4129 | } |
| 4130 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4131 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4132 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4133 | TestSharedBitmapManager shared_bitmap_manager; |
| 4134 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4135 | scoped_ptr<LayerImpl> root = |
| 4136 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4137 | |
| 4138 | gfx::Transform identity_matrix; |
| 4139 | gfx::PointF anchor; |
| 4140 | gfx::PointF position; |
| 4141 | gfx::Size bounds(100, 100); |
| 4142 | SetLayerPropertiesForTesting(root.get(), |
| 4143 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4144 | anchor, |
| 4145 | position, |
| 4146 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4147 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4148 | false); |
| 4149 | root->SetDrawsContent(true); |
| 4150 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4151 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4152 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4153 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4154 | inputs.can_adjust_raster_scales = true; |
| 4155 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4156 | |
| 4157 | // Sanity check the scenario we just created. |
| 4158 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4159 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4160 | |
| 4161 | // Hit testing for a point outside the layer should return a null pointer. |
| 4162 | gfx::Point test_point(101, 101); |
| 4163 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4164 | test_point, render_surface_layer_list); |
| 4165 | EXPECT_FALSE(result_layer); |
| 4166 | |
| 4167 | test_point = gfx::Point(-1, -1); |
| 4168 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4169 | test_point, render_surface_layer_list); |
| 4170 | EXPECT_FALSE(result_layer); |
| 4171 | |
| 4172 | // Hit testing for a point inside should return the root layer. |
| 4173 | test_point = gfx::Point(1, 1); |
| 4174 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4175 | test_point, render_surface_layer_list); |
| 4176 | ASSERT_TRUE(result_layer); |
| 4177 | EXPECT_EQ(12345, result_layer->id()); |
| 4178 | |
| 4179 | test_point = gfx::Point(99, 99); |
| 4180 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4181 | test_point, render_surface_layer_list); |
| 4182 | ASSERT_TRUE(result_layer); |
| 4183 | EXPECT_EQ(12345, result_layer->id()); |
| 4184 | } |
| 4185 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4186 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4187 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4188 | TestSharedBitmapManager shared_bitmap_manager; |
| 4189 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4190 | scoped_ptr<LayerImpl> root = |
| 4191 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4192 | scoped_ptr<HeadsUpDisplayLayerImpl> hud = |
| 4193 | HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111); |
| 4194 | |
| 4195 | gfx::Transform identity_matrix; |
| 4196 | gfx::PointF anchor; |
| 4197 | gfx::PointF position; |
| 4198 | gfx::Size bounds(100, 100); |
| 4199 | SetLayerPropertiesForTesting(root.get(), |
| 4200 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4201 | anchor, |
| 4202 | position, |
| 4203 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4204 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4205 | false); |
| 4206 | root->SetDrawsContent(true); |
| 4207 | |
| 4208 | // Create hud and add it as a child of root. |
| 4209 | gfx::Size hud_bounds(200, 200); |
| 4210 | SetLayerPropertiesForTesting(hud.get(), |
| 4211 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4212 | anchor, |
| 4213 | position, |
| 4214 | hud_bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4215 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4216 | false); |
| 4217 | hud->SetDrawsContent(true); |
| 4218 | |
| 4219 | host_impl.active_tree()->set_hud_layer(hud.get()); |
| 4220 | root->AddChild(hud.PassAs<LayerImpl>()); |
| 4221 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4222 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4223 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4224 | root.get(), hud_bounds, &render_surface_layer_list); |
| 4225 | inputs.can_adjust_raster_scales = true; |
| 4226 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4227 | |
| 4228 | // Sanity check the scenario we just created. |
| 4229 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4230 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 4231 | |
| 4232 | // Hit testing for a point inside HUD, but outside root should return null |
| 4233 | gfx::Point test_point(101, 101); |
| 4234 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4235 | test_point, render_surface_layer_list); |
| 4236 | EXPECT_FALSE(result_layer); |
| 4237 | |
| 4238 | test_point = gfx::Point(-1, -1); |
| 4239 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4240 | test_point, render_surface_layer_list); |
| 4241 | EXPECT_FALSE(result_layer); |
| 4242 | |
| 4243 | // Hit testing for a point inside should return the root layer, never the HUD |
| 4244 | // layer. |
| 4245 | test_point = gfx::Point(1, 1); |
| 4246 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4247 | test_point, render_surface_layer_list); |
| 4248 | ASSERT_TRUE(result_layer); |
| 4249 | EXPECT_EQ(12345, result_layer->id()); |
| 4250 | |
| 4251 | test_point = gfx::Point(99, 99); |
| 4252 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4253 | test_point, render_surface_layer_list); |
| 4254 | ASSERT_TRUE(result_layer); |
| 4255 | EXPECT_EQ(12345, result_layer->id()); |
| 4256 | } |
| 4257 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4258 | TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4259 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4260 | TestSharedBitmapManager shared_bitmap_manager; |
| 4261 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4262 | scoped_ptr<LayerImpl> root = |
| 4263 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4264 | |
| 4265 | gfx::Transform uninvertible_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4266 | uninvertible_transform.matrix().set(0, 0, 0.0); |
| 4267 | uninvertible_transform.matrix().set(1, 1, 0.0); |
| 4268 | uninvertible_transform.matrix().set(2, 2, 0.0); |
| 4269 | uninvertible_transform.matrix().set(3, 3, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4270 | ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
| 4271 | |
| 4272 | gfx::Transform identity_matrix; |
| 4273 | gfx::PointF anchor; |
| 4274 | gfx::PointF position; |
| 4275 | gfx::Size bounds(100, 100); |
| 4276 | SetLayerPropertiesForTesting(root.get(), |
| 4277 | uninvertible_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4278 | anchor, |
| 4279 | position, |
| 4280 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4281 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4282 | false); |
| 4283 | root->SetDrawsContent(true); |
| 4284 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4285 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4286 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4287 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4288 | inputs.can_adjust_raster_scales = true; |
| 4289 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4290 | |
| 4291 | // Sanity check the scenario we just created. |
| 4292 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4293 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4294 | ASSERT_FALSE(root->screen_space_transform().IsInvertible()); |
| 4295 | |
| 4296 | // Hit testing any point should not hit the layer. If the invertible matrix is |
| 4297 | // accidentally ignored and treated like an identity, then the hit testing |
| 4298 | // will incorrectly hit the layer when it shouldn't. |
| 4299 | gfx::Point test_point(1, 1); |
| 4300 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4301 | test_point, render_surface_layer_list); |
| 4302 | EXPECT_FALSE(result_layer); |
| 4303 | |
| 4304 | test_point = gfx::Point(10, 10); |
| 4305 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4306 | test_point, render_surface_layer_list); |
| 4307 | EXPECT_FALSE(result_layer); |
| 4308 | |
| 4309 | test_point = gfx::Point(10, 30); |
| 4310 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4311 | test_point, render_surface_layer_list); |
| 4312 | EXPECT_FALSE(result_layer); |
| 4313 | |
| 4314 | test_point = gfx::Point(50, 50); |
| 4315 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4316 | test_point, render_surface_layer_list); |
| 4317 | EXPECT_FALSE(result_layer); |
| 4318 | |
| 4319 | test_point = gfx::Point(67, 48); |
| 4320 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4321 | test_point, render_surface_layer_list); |
| 4322 | EXPECT_FALSE(result_layer); |
| 4323 | |
| 4324 | test_point = gfx::Point(99, 99); |
| 4325 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4326 | test_point, render_surface_layer_list); |
| 4327 | EXPECT_FALSE(result_layer); |
| 4328 | |
| 4329 | test_point = gfx::Point(-1, -1); |
| 4330 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4331 | test_point, render_surface_layer_list); |
| 4332 | EXPECT_FALSE(result_layer); |
| 4333 | } |
| 4334 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4335 | TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4336 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4337 | TestSharedBitmapManager shared_bitmap_manager; |
| 4338 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4339 | scoped_ptr<LayerImpl> root = |
| 4340 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4341 | |
| 4342 | gfx::Transform identity_matrix; |
| 4343 | gfx::PointF anchor; |
| 4344 | // this layer is positioned, and hit testing should correctly know where the |
| 4345 | // layer is located. |
| 4346 | gfx::PointF position(50.f, 50.f); |
| 4347 | gfx::Size bounds(100, 100); |
| 4348 | SetLayerPropertiesForTesting(root.get(), |
| 4349 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4350 | anchor, |
| 4351 | position, |
| 4352 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4353 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4354 | false); |
| 4355 | root->SetDrawsContent(true); |
| 4356 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4357 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4358 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4359 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4360 | inputs.can_adjust_raster_scales = true; |
| 4361 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4362 | |
| 4363 | // Sanity check the scenario we just created. |
| 4364 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4365 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4366 | |
| 4367 | // Hit testing for a point outside the layer should return a null pointer. |
| 4368 | gfx::Point test_point(49, 49); |
| 4369 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4370 | test_point, render_surface_layer_list); |
| 4371 | EXPECT_FALSE(result_layer); |
| 4372 | |
| 4373 | // Even though the layer exists at (101, 101), it should not be visible there |
| 4374 | // since the root render surface would clamp it. |
| 4375 | test_point = gfx::Point(101, 101); |
| 4376 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4377 | test_point, render_surface_layer_list); |
| 4378 | EXPECT_FALSE(result_layer); |
| 4379 | |
| 4380 | // Hit testing for a point inside should return the root layer. |
| 4381 | test_point = gfx::Point(51, 51); |
| 4382 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4383 | test_point, render_surface_layer_list); |
| 4384 | ASSERT_TRUE(result_layer); |
| 4385 | EXPECT_EQ(12345, result_layer->id()); |
| 4386 | |
| 4387 | test_point = gfx::Point(99, 99); |
| 4388 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4389 | test_point, render_surface_layer_list); |
| 4390 | ASSERT_TRUE(result_layer); |
| 4391 | EXPECT_EQ(12345, result_layer->id()); |
| 4392 | } |
| 4393 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4394 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4395 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4396 | TestSharedBitmapManager shared_bitmap_manager; |
| 4397 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4398 | scoped_ptr<LayerImpl> root = |
| 4399 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4400 | |
| 4401 | gfx::Transform identity_matrix; |
| 4402 | gfx::Transform rotation45_degrees_about_center; |
| 4403 | rotation45_degrees_about_center.Translate(50.0, 50.0); |
| 4404 | rotation45_degrees_about_center.RotateAboutZAxis(45.0); |
| 4405 | rotation45_degrees_about_center.Translate(-50.0, -50.0); |
| 4406 | gfx::PointF anchor; |
| 4407 | gfx::PointF position; |
| 4408 | gfx::Size bounds(100, 100); |
| 4409 | SetLayerPropertiesForTesting(root.get(), |
| 4410 | rotation45_degrees_about_center, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4411 | anchor, |
| 4412 | position, |
| 4413 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4414 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4415 | false); |
| 4416 | root->SetDrawsContent(true); |
| 4417 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4418 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4419 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4420 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4421 | inputs.can_adjust_raster_scales = true; |
| 4422 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4423 | |
| 4424 | // Sanity check the scenario we just created. |
| 4425 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4426 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4427 | |
| 4428 | // Hit testing for points outside the layer. |
| 4429 | // These corners would have been inside the un-transformed layer, but they |
| 4430 | // should not hit the correctly transformed layer. |
| 4431 | gfx::Point test_point(99, 99); |
| 4432 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4433 | test_point, render_surface_layer_list); |
| 4434 | EXPECT_FALSE(result_layer); |
| 4435 | |
| 4436 | test_point = gfx::Point(1, 1); |
| 4437 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4438 | test_point, render_surface_layer_list); |
| 4439 | EXPECT_FALSE(result_layer); |
| 4440 | |
| 4441 | // Hit testing for a point inside should return the root layer. |
| 4442 | test_point = gfx::Point(1, 50); |
| 4443 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4444 | test_point, render_surface_layer_list); |
| 4445 | ASSERT_TRUE(result_layer); |
| 4446 | EXPECT_EQ(12345, result_layer->id()); |
| 4447 | |
| 4448 | // Hit testing the corners that would overlap the unclipped layer, but are |
| 4449 | // outside the clipped region. |
| 4450 | test_point = gfx::Point(50, -1); |
| 4451 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4452 | test_point, render_surface_layer_list); |
| 4453 | ASSERT_FALSE(result_layer); |
| 4454 | |
| 4455 | test_point = gfx::Point(-1, 50); |
| 4456 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4457 | test_point, render_surface_layer_list); |
| 4458 | ASSERT_FALSE(result_layer); |
| 4459 | } |
| 4460 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4461 | TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4462 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4463 | TestSharedBitmapManager shared_bitmap_manager; |
| 4464 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4465 | scoped_ptr<LayerImpl> root = |
| 4466 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4467 | |
| 4468 | gfx::Transform identity_matrix; |
| 4469 | |
| 4470 | // perspective_projection_about_center * translation_by_z is designed so that |
| 4471 | // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). |
| 4472 | gfx::Transform perspective_projection_about_center; |
| 4473 | perspective_projection_about_center.Translate(50.0, 50.0); |
| 4474 | perspective_projection_about_center.ApplyPerspectiveDepth(1.0); |
| 4475 | perspective_projection_about_center.Translate(-50.0, -50.0); |
| 4476 | gfx::Transform translation_by_z; |
| 4477 | translation_by_z.Translate3d(0.0, 0.0, -1.0); |
| 4478 | |
| 4479 | gfx::PointF anchor; |
| 4480 | gfx::PointF position; |
| 4481 | gfx::Size bounds(100, 100); |
| 4482 | SetLayerPropertiesForTesting( |
| 4483 | root.get(), |
| 4484 | perspective_projection_about_center * translation_by_z, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4485 | anchor, |
| 4486 | position, |
| 4487 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4488 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4489 | false); |
| 4490 | root->SetDrawsContent(true); |
| 4491 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4492 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4493 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4494 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4495 | inputs.can_adjust_raster_scales = true; |
| 4496 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4497 | |
| 4498 | // Sanity check the scenario we just created. |
| 4499 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4500 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4501 | |
| 4502 | // Hit testing for points outside the layer. |
| 4503 | // These corners would have been inside the un-transformed layer, but they |
| 4504 | // should not hit the correctly transformed layer. |
| 4505 | gfx::Point test_point(24, 24); |
| 4506 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4507 | test_point, render_surface_layer_list); |
| 4508 | EXPECT_FALSE(result_layer); |
| 4509 | |
| 4510 | test_point = gfx::Point(76, 76); |
| 4511 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4512 | test_point, render_surface_layer_list); |
| 4513 | EXPECT_FALSE(result_layer); |
| 4514 | |
| 4515 | // Hit testing for a point inside should return the root layer. |
| 4516 | test_point = gfx::Point(26, 26); |
| 4517 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4518 | test_point, render_surface_layer_list); |
| 4519 | ASSERT_TRUE(result_layer); |
| 4520 | EXPECT_EQ(12345, result_layer->id()); |
| 4521 | |
| 4522 | test_point = gfx::Point(74, 74); |
| 4523 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4524 | test_point, render_surface_layer_list); |
| 4525 | ASSERT_TRUE(result_layer); |
| 4526 | EXPECT_EQ(12345, result_layer->id()); |
| 4527 | } |
| 4528 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4529 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4530 | // A layer's visible content rect is actually in the layer's content space. |
| 4531 | // The screen space transform converts from the layer's origin space to screen |
| 4532 | // space. This test makes sure that hit testing works correctly accounts for |
| 4533 | // the contents scale. A contents scale that is not 1 effectively forces a |
| 4534 | // non-identity transform between layer's content space and layer's origin |
| 4535 | // space. The hit testing code must take this into account. |
| 4536 | // |
| 4537 | // To test this, the layer is positioned at (25, 25), and is size (50, 50). If |
| 4538 | // contents scale is ignored, then hit testing will mis-interpret the visible |
| 4539 | // content rect as being larger than the actual bounds of the layer. |
| 4540 | // |
| 4541 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4542 | TestSharedBitmapManager shared_bitmap_manager; |
| 4543 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4544 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4545 | |
| 4546 | gfx::Transform identity_matrix; |
| 4547 | gfx::PointF anchor; |
| 4548 | |
| 4549 | SetLayerPropertiesForTesting(root.get(), |
| 4550 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4551 | anchor, |
| 4552 | gfx::PointF(), |
| 4553 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4554 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4555 | false); |
| 4556 | { |
| 4557 | gfx::PointF position(25.f, 25.f); |
| 4558 | gfx::Size bounds(50, 50); |
| 4559 | scoped_ptr<LayerImpl> test_layer = |
| 4560 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4561 | SetLayerPropertiesForTesting(test_layer.get(), |
| 4562 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4563 | anchor, |
| 4564 | position, |
| 4565 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4566 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4567 | false); |
| 4568 | |
| 4569 | // override content bounds and contents scale |
| 4570 | test_layer->SetContentBounds(gfx::Size(100, 100)); |
| 4571 | test_layer->SetContentsScale(2, 2); |
| 4572 | |
| 4573 | test_layer->SetDrawsContent(true); |
| 4574 | root->AddChild(test_layer.Pass()); |
| 4575 | } |
| 4576 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4577 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4578 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4579 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4580 | inputs.can_adjust_raster_scales = true; |
| 4581 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4582 | |
| 4583 | // Sanity check the scenario we just created. |
| 4584 | // The visible content rect for test_layer is actually 100x100, even though |
| 4585 | // its layout size is 50x50, positioned at 25x25. |
| 4586 | LayerImpl* test_layer = root->children()[0]; |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4587 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4588 | test_layer->visible_content_rect()); |
| 4589 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4590 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4591 | |
| 4592 | // Hit testing for a point outside the layer should return a null pointer (the |
| 4593 | // root layer does not draw content, so it will not be hit tested either). |
| 4594 | gfx::Point test_point(101, 101); |
| 4595 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4596 | test_point, render_surface_layer_list); |
| 4597 | EXPECT_FALSE(result_layer); |
| 4598 | |
| 4599 | test_point = gfx::Point(24, 24); |
| 4600 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4601 | test_point, render_surface_layer_list); |
| 4602 | EXPECT_FALSE(result_layer); |
| 4603 | |
| 4604 | test_point = gfx::Point(76, 76); |
| 4605 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4606 | test_point, render_surface_layer_list); |
| 4607 | EXPECT_FALSE(result_layer); |
| 4608 | |
| 4609 | // Hit testing for a point inside should return the test layer. |
| 4610 | test_point = gfx::Point(26, 26); |
| 4611 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4612 | test_point, render_surface_layer_list); |
| 4613 | ASSERT_TRUE(result_layer); |
| 4614 | EXPECT_EQ(12345, result_layer->id()); |
| 4615 | |
| 4616 | test_point = gfx::Point(74, 74); |
| 4617 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4618 | test_point, render_surface_layer_list); |
| 4619 | ASSERT_TRUE(result_layer); |
| 4620 | EXPECT_EQ(12345, result_layer->id()); |
| 4621 | } |
| 4622 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4623 | TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4624 | // Test that hit-testing will only work for the visible portion of a layer, |
| 4625 | // and not the entire layer bounds. Here we just test the simple axis-aligned |
| 4626 | // case. |
| 4627 | gfx::Transform identity_matrix; |
| 4628 | gfx::PointF anchor; |
| 4629 | |
| 4630 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4631 | TestSharedBitmapManager shared_bitmap_manager; |
| 4632 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4633 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4634 | SetLayerPropertiesForTesting(root.get(), |
| 4635 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4636 | anchor, |
| 4637 | gfx::PointF(), |
| 4638 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4639 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4640 | false); |
| 4641 | { |
| 4642 | scoped_ptr<LayerImpl> clipping_layer = |
| 4643 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 4644 | // this layer is positioned, and hit testing should correctly know where the |
| 4645 | // layer is located. |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4646 | gfx::PointF position(25.f, 25.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4647 | gfx::Size bounds(50, 50); |
| 4648 | SetLayerPropertiesForTesting(clipping_layer.get(), |
| 4649 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4650 | anchor, |
| 4651 | position, |
| 4652 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4653 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4654 | false); |
| 4655 | clipping_layer->SetMasksToBounds(true); |
| 4656 | |
| 4657 | scoped_ptr<LayerImpl> child = |
| 4658 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4659 | position = gfx::PointF(-50.f, -50.f); |
| 4660 | bounds = gfx::Size(300, 300); |
| 4661 | SetLayerPropertiesForTesting(child.get(), |
| 4662 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4663 | anchor, |
| 4664 | position, |
| 4665 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4666 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4667 | false); |
| 4668 | child->SetDrawsContent(true); |
| 4669 | clipping_layer->AddChild(child.Pass()); |
| 4670 | root->AddChild(clipping_layer.Pass()); |
| 4671 | } |
| 4672 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4673 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4674 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4675 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4676 | inputs.can_adjust_raster_scales = true; |
| 4677 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4678 | |
| 4679 | // Sanity check the scenario we just created. |
| 4680 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4681 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4682 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4683 | |
| 4684 | // Hit testing for a point outside the layer should return a null pointer. |
| 4685 | // Despite the child layer being very large, it should be clipped to the root |
| 4686 | // layer's bounds. |
| 4687 | gfx::Point test_point(24, 24); |
| 4688 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4689 | test_point, render_surface_layer_list); |
| 4690 | EXPECT_FALSE(result_layer); |
| 4691 | |
| 4692 | // Even though the layer exists at (101, 101), it should not be visible there |
| 4693 | // since the clipping_layer would clamp it. |
| 4694 | test_point = gfx::Point(76, 76); |
| 4695 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4696 | test_point, render_surface_layer_list); |
| 4697 | EXPECT_FALSE(result_layer); |
| 4698 | |
| 4699 | // Hit testing for a point inside should return the child layer. |
| 4700 | test_point = gfx::Point(26, 26); |
| 4701 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4702 | test_point, render_surface_layer_list); |
| 4703 | ASSERT_TRUE(result_layer); |
| 4704 | EXPECT_EQ(456, result_layer->id()); |
| 4705 | |
| 4706 | test_point = gfx::Point(74, 74); |
| 4707 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4708 | test_point, render_surface_layer_list); |
| 4709 | ASSERT_TRUE(result_layer); |
| 4710 | EXPECT_EQ(456, result_layer->id()); |
| 4711 | } |
| 4712 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4713 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4714 | // This test checks whether hit testing correctly avoids hit testing with |
| 4715 | // multiple ancestors that clip in non axis-aligned ways. To pass this test, |
| 4716 | // the hit testing algorithm needs to recognize that multiple parent layers |
| 4717 | // may clip the layer, and should not actually hit those clipped areas. |
| 4718 | // |
| 4719 | // The child and grand_child layers are both initialized to clip the |
| 4720 | // rotated_leaf. The child layer is rotated about the top-left corner, so that |
| 4721 | // the root + child clips combined create a triangle. The rotated_leaf will |
| 4722 | // only be visible where it overlaps this triangle. |
| 4723 | // |
| 4724 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4725 | TestSharedBitmapManager shared_bitmap_manager; |
| 4726 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4727 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123); |
| 4728 | |
| 4729 | gfx::Transform identity_matrix; |
| 4730 | gfx::PointF anchor; |
| 4731 | gfx::PointF position; |
| 4732 | gfx::Size bounds(100, 100); |
| 4733 | SetLayerPropertiesForTesting(root.get(), |
| 4734 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4735 | anchor, |
| 4736 | position, |
| 4737 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4738 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4739 | false); |
| 4740 | root->SetMasksToBounds(true); |
| 4741 | { |
| 4742 | scoped_ptr<LayerImpl> child = |
| 4743 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4744 | scoped_ptr<LayerImpl> grand_child = |
| 4745 | LayerImpl::Create(host_impl.active_tree(), 789); |
| 4746 | scoped_ptr<LayerImpl> rotated_leaf = |
| 4747 | LayerImpl::Create(host_impl.active_tree(), 2468); |
| 4748 | |
| 4749 | position = gfx::PointF(10.f, 10.f); |
| 4750 | bounds = gfx::Size(80, 80); |
| 4751 | SetLayerPropertiesForTesting(child.get(), |
| 4752 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4753 | anchor, |
| 4754 | position, |
| 4755 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4756 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4757 | false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4758 | child->SetMasksToBounds(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4759 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4760 | gfx::Transform rotation45_degrees_about_corner; |
| 4761 | rotation45_degrees_about_corner.RotateAboutZAxis(45.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4762 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4763 | // remember, positioned with respect to its parent which is already at 10, |
| 4764 | // 10 |
| 4765 | position = gfx::PointF(); |
| 4766 | bounds = |
| 4767 | gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100. |
| 4768 | SetLayerPropertiesForTesting(grand_child.get(), |
| 4769 | rotation45_degrees_about_corner, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4770 | anchor, |
| 4771 | position, |
| 4772 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4773 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4774 | false); |
| 4775 | grand_child->SetMasksToBounds(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4776 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4777 | // Rotates about the center of the layer |
| 4778 | gfx::Transform rotated_leaf_transform; |
| 4779 | rotated_leaf_transform.Translate( |
| 4780 | -10.0, -10.0); // cancel out the grand_parent's position |
| 4781 | rotated_leaf_transform.RotateAboutZAxis( |
| 4782 | -45.0); // cancel out the corner 45-degree rotation of the parent. |
| 4783 | rotated_leaf_transform.Translate(50.0, 50.0); |
| 4784 | rotated_leaf_transform.RotateAboutZAxis(45.0); |
| 4785 | rotated_leaf_transform.Translate(-50.0, -50.0); |
| 4786 | position = gfx::PointF(); |
| 4787 | bounds = gfx::Size(100, 100); |
| 4788 | SetLayerPropertiesForTesting(rotated_leaf.get(), |
| 4789 | rotated_leaf_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4790 | anchor, |
| 4791 | position, |
| 4792 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4793 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4794 | false); |
| 4795 | rotated_leaf->SetDrawsContent(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4796 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4797 | grand_child->AddChild(rotated_leaf.Pass()); |
| 4798 | child->AddChild(grand_child.Pass()); |
| 4799 | root->AddChild(child.Pass()); |
| 4800 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4801 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4802 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4803 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4804 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4805 | inputs.can_adjust_raster_scales = true; |
| 4806 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4807 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4808 | // Sanity check the scenario we just created. |
| 4809 | // The grand_child is expected to create a render surface because it |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4810 | // MasksToBounds and is not axis aligned. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4811 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
| 4812 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4813 | 1u, |
| 4814 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4815 | ASSERT_EQ(789, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4816 | render_surface_layer_list.at(0)->render_surface()->layer_list().at( |
| 4817 | 0)->id()); // grand_child's surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4818 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4819 | 1u, |
| 4820 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4821 | ASSERT_EQ( |
| 4822 | 2468, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4823 | render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4824 | |
| 4825 | // (11, 89) is close to the the bottom left corner within the clip, but it is |
| 4826 | // not inside the layer. |
| 4827 | gfx::Point test_point(11, 89); |
| 4828 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4829 | test_point, render_surface_layer_list); |
| 4830 | EXPECT_FALSE(result_layer); |
| 4831 | |
| 4832 | // Closer inwards from the bottom left will overlap the layer. |
| 4833 | test_point = gfx::Point(25, 75); |
| 4834 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4835 | test_point, render_surface_layer_list); |
| 4836 | ASSERT_TRUE(result_layer); |
| 4837 | EXPECT_EQ(2468, result_layer->id()); |
| 4838 | |
| 4839 | // (4, 50) is inside the unclipped layer, but that corner of the layer should |
| 4840 | // be clipped away by the grandparent and should not get hit. If hit testing |
| 4841 | // blindly uses visible content rect without considering how parent may clip |
| 4842 | // the layer, then hit testing would accidentally think that the point |
| 4843 | // successfully hits the layer. |
| 4844 | test_point = gfx::Point(4, 50); |
| 4845 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4846 | test_point, render_surface_layer_list); |
| 4847 | EXPECT_FALSE(result_layer); |
| 4848 | |
| 4849 | // (11, 50) is inside the layer and within the clipped area. |
| 4850 | test_point = gfx::Point(11, 50); |
| 4851 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4852 | test_point, render_surface_layer_list); |
| 4853 | ASSERT_TRUE(result_layer); |
| 4854 | EXPECT_EQ(2468, result_layer->id()); |
| 4855 | |
| 4856 | // Around the middle, just to the right and up, would have hit the layer |
| 4857 | // except that that area should be clipped away by the parent. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4858 | test_point = gfx::Point(51, 49); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4859 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4860 | test_point, render_surface_layer_list); |
| 4861 | EXPECT_FALSE(result_layer); |
| 4862 | |
| 4863 | // Around the middle, just to the left and down, should successfully hit the |
| 4864 | // layer. |
| 4865 | test_point = gfx::Point(49, 51); |
| 4866 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4867 | test_point, render_surface_layer_list); |
| 4868 | ASSERT_TRUE(result_layer); |
| 4869 | EXPECT_EQ(2468, result_layer->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4870 | } |
| 4871 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4872 | TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4873 | // This test checks that hit testing code does not accidentally clip to layer |
| 4874 | // bounds for a layer that actually does not clip. |
| 4875 | gfx::Transform identity_matrix; |
| 4876 | gfx::PointF anchor; |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4877 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4878 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4879 | TestSharedBitmapManager shared_bitmap_manager; |
| 4880 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4881 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4882 | SetLayerPropertiesForTesting(root.get(), |
| 4883 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4884 | anchor, |
| 4885 | gfx::PointF(), |
| 4886 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4887 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4888 | false); |
| 4889 | { |
| 4890 | scoped_ptr<LayerImpl> intermediate_layer = |
| 4891 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 4892 | // this layer is positioned, and hit testing should correctly know where the |
| 4893 | // layer is located. |
| 4894 | gfx::PointF position(10.f, 10.f); |
| 4895 | gfx::Size bounds(50, 50); |
| 4896 | SetLayerPropertiesForTesting(intermediate_layer.get(), |
| 4897 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4898 | anchor, |
| 4899 | position, |
| 4900 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4901 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4902 | false); |
| 4903 | // Sanity check the intermediate layer should not clip. |
| 4904 | ASSERT_FALSE(intermediate_layer->masks_to_bounds()); |
| 4905 | ASSERT_FALSE(intermediate_layer->mask_layer()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4906 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4907 | // The child of the intermediate_layer is translated so that it does not |
| 4908 | // overlap intermediate_layer at all. If child is incorrectly clipped, we |
| 4909 | // would not be able to hit it successfully. |
| 4910 | scoped_ptr<LayerImpl> child = |
| 4911 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4912 | position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space |
| 4913 | bounds = gfx::Size(20, 20); |
| 4914 | SetLayerPropertiesForTesting(child.get(), |
| 4915 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4916 | anchor, |
| 4917 | position, |
| 4918 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4919 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4920 | false); |
| 4921 | child->SetDrawsContent(true); |
| 4922 | intermediate_layer->AddChild(child.Pass()); |
| 4923 | root->AddChild(intermediate_layer.Pass()); |
| 4924 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4925 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4926 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4927 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4928 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4929 | inputs.can_adjust_raster_scales = true; |
| 4930 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4931 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4932 | // Sanity check the scenario we just created. |
| 4933 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4934 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4935 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4936 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4937 | // Hit testing for a point outside the layer should return a null pointer. |
| 4938 | gfx::Point test_point(69, 69); |
| 4939 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4940 | test_point, render_surface_layer_list); |
| 4941 | EXPECT_FALSE(result_layer); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4942 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4943 | test_point = gfx::Point(91, 91); |
| 4944 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4945 | test_point, render_surface_layer_list); |
| 4946 | EXPECT_FALSE(result_layer); |
| 4947 | |
| 4948 | // Hit testing for a point inside should return the child layer. |
| 4949 | test_point = gfx::Point(71, 71); |
| 4950 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4951 | test_point, render_surface_layer_list); |
| 4952 | ASSERT_TRUE(result_layer); |
| 4953 | EXPECT_EQ(456, result_layer->id()); |
| 4954 | |
| 4955 | test_point = gfx::Point(89, 89); |
| 4956 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4957 | test_point, render_surface_layer_list); |
| 4958 | ASSERT_TRUE(result_layer); |
| 4959 | EXPECT_EQ(456, result_layer->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4960 | } |
| 4961 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4962 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4963 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4964 | TestSharedBitmapManager shared_bitmap_manager; |
| 4965 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4966 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4967 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4968 | gfx::Transform identity_matrix; |
| 4969 | gfx::PointF anchor; |
| 4970 | gfx::PointF position; |
| 4971 | gfx::Size bounds(100, 100); |
| 4972 | SetLayerPropertiesForTesting(root.get(), |
| 4973 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4974 | anchor, |
| 4975 | position, |
| 4976 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4977 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4978 | false); |
| 4979 | root->SetDrawsContent(true); |
| 4980 | { |
| 4981 | // child 1 and child2 are initialized to overlap between x=50 and x=60. |
| 4982 | // grand_child is set to overlap both child1 and child2 between y=50 and |
| 4983 | // y=60. The expected stacking order is: (front) child2, (second) |
| 4984 | // grand_child, (third) child1, and (back) the root layer behind all other |
| 4985 | // layers. |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 4986 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4987 | scoped_ptr<LayerImpl> child1 = |
| 4988 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 4989 | scoped_ptr<LayerImpl> child2 = |
| 4990 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 4991 | scoped_ptr<LayerImpl> grand_child1 = |
| 4992 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4993 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4994 | position = gfx::PointF(10.f, 10.f); |
| 4995 | bounds = gfx::Size(50, 50); |
| 4996 | SetLayerPropertiesForTesting(child1.get(), |
| 4997 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4998 | anchor, |
| 4999 | position, |
| 5000 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5001 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5002 | false); |
| 5003 | child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5004 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5005 | position = gfx::PointF(50.f, 10.f); |
| 5006 | bounds = gfx::Size(50, 50); |
| 5007 | SetLayerPropertiesForTesting(child2.get(), |
| 5008 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5009 | anchor, |
| 5010 | position, |
| 5011 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5012 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5013 | false); |
| 5014 | child2->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5015 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5016 | // Remember that grand_child is positioned with respect to its parent (i.e. |
| 5017 | // child1). In screen space, the intended position is (10, 50), with size |
| 5018 | // 100 x 50. |
| 5019 | position = gfx::PointF(0.f, 40.f); |
| 5020 | bounds = gfx::Size(100, 50); |
| 5021 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 5022 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5023 | anchor, |
| 5024 | position, |
| 5025 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5026 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5027 | false); |
| 5028 | grand_child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5029 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5030 | child1->AddChild(grand_child1.Pass()); |
| 5031 | root->AddChild(child1.Pass()); |
| 5032 | root->AddChild(child2.Pass()); |
| 5033 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5034 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5035 | LayerImpl* child1 = root->children()[0]; |
| 5036 | LayerImpl* child2 = root->children()[1]; |
| 5037 | LayerImpl* grand_child1 = child1->children()[0]; |
| 5038 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5039 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5040 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5041 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5042 | inputs.can_adjust_raster_scales = true; |
| 5043 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5044 | |
| 5045 | // Sanity check the scenario we just created. |
| 5046 | ASSERT_TRUE(child1); |
| 5047 | ASSERT_TRUE(child2); |
| 5048 | ASSERT_TRUE(grand_child1); |
| 5049 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5050 | |
| 5051 | RenderSurfaceImpl* root_render_surface = root->render_surface(); |
| 5052 | ASSERT_EQ(4u, root_render_surface->layer_list().size()); |
| 5053 | ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer |
| 5054 | ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1 |
| 5055 | ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1 |
| 5056 | ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2 |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5057 | |
| 5058 | // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
| 5059 | // the root layer. |
| 5060 | gfx::Point test_point = gfx::Point(1, 1); |
| 5061 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5062 | test_point, render_surface_layer_list); |
| 5063 | ASSERT_TRUE(result_layer); |
| 5064 | EXPECT_EQ(1, result_layer->id()); |
| 5065 | |
| 5066 | // At (15, 15), child1 and root are the only layers. child1 is expected to be |
| 5067 | // on top. |
| 5068 | test_point = gfx::Point(15, 15); |
| 5069 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5070 | test_point, render_surface_layer_list); |
| 5071 | ASSERT_TRUE(result_layer); |
| 5072 | EXPECT_EQ(2, result_layer->id()); |
| 5073 | |
| 5074 | // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. |
| 5075 | test_point = gfx::Point(51, 20); |
| 5076 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5077 | test_point, render_surface_layer_list); |
| 5078 | ASSERT_TRUE(result_layer); |
| 5079 | EXPECT_EQ(3, result_layer->id()); |
| 5080 | |
| 5081 | // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on |
| 5082 | // top. |
| 5083 | test_point = gfx::Point(80, 51); |
| 5084 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5085 | test_point, render_surface_layer_list); |
| 5086 | ASSERT_TRUE(result_layer); |
| 5087 | EXPECT_EQ(3, result_layer->id()); |
| 5088 | |
| 5089 | // At (51, 51), all layers overlap each other. child2 is expected to be on top |
| 5090 | // of all other layers. |
| 5091 | test_point = gfx::Point(51, 51); |
| 5092 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5093 | test_point, render_surface_layer_list); |
| 5094 | ASSERT_TRUE(result_layer); |
| 5095 | EXPECT_EQ(3, result_layer->id()); |
| 5096 | |
| 5097 | // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to |
| 5098 | // be on top. |
| 5099 | test_point = gfx::Point(20, 51); |
| 5100 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5101 | test_point, render_surface_layer_list); |
| 5102 | ASSERT_TRUE(result_layer); |
| 5103 | EXPECT_EQ(4, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5104 | } |
| 5105 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5106 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5107 | // |
| 5108 | // The geometry is set up similarly to the previous case, but |
| 5109 | // all layers are forced to be render surfaces now. |
| 5110 | // |
| 5111 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5112 | TestSharedBitmapManager shared_bitmap_manager; |
| 5113 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5114 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5115 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5116 | gfx::Transform identity_matrix; |
| 5117 | gfx::PointF anchor; |
| 5118 | gfx::PointF position; |
| 5119 | gfx::Size bounds(100, 100); |
| 5120 | SetLayerPropertiesForTesting(root.get(), |
| 5121 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5122 | anchor, |
| 5123 | position, |
| 5124 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5125 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5126 | false); |
| 5127 | root->SetDrawsContent(true); |
| 5128 | { |
| 5129 | // child 1 and child2 are initialized to overlap between x=50 and x=60. |
| 5130 | // grand_child is set to overlap both child1 and child2 between y=50 and |
| 5131 | // y=60. The expected stacking order is: (front) child2, (second) |
| 5132 | // grand_child, (third) child1, and (back) the root layer behind all other |
| 5133 | // layers. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5134 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5135 | scoped_ptr<LayerImpl> child1 = |
| 5136 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 5137 | scoped_ptr<LayerImpl> child2 = |
| 5138 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 5139 | scoped_ptr<LayerImpl> grand_child1 = |
| 5140 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5141 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5142 | position = gfx::PointF(10.f, 10.f); |
| 5143 | bounds = gfx::Size(50, 50); |
| 5144 | SetLayerPropertiesForTesting(child1.get(), |
| 5145 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5146 | anchor, |
| 5147 | position, |
| 5148 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5149 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5150 | false); |
| 5151 | child1->SetDrawsContent(true); |
| 5152 | child1->SetForceRenderSurface(true); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 5153 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5154 | position = gfx::PointF(50.f, 10.f); |
| 5155 | bounds = gfx::Size(50, 50); |
| 5156 | SetLayerPropertiesForTesting(child2.get(), |
| 5157 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5158 | anchor, |
| 5159 | position, |
| 5160 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5161 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5162 | false); |
| 5163 | child2->SetDrawsContent(true); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 5164 | child2->SetForceRenderSurface(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5165 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5166 | // Remember that grand_child is positioned with respect to its parent (i.e. |
| 5167 | // child1). In screen space, the intended position is (10, 50), with size |
| 5168 | // 100 x 50. |
| 5169 | position = gfx::PointF(0.f, 40.f); |
| 5170 | bounds = gfx::Size(100, 50); |
| 5171 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 5172 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5173 | anchor, |
| 5174 | position, |
| 5175 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5176 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5177 | false); |
| 5178 | grand_child1->SetDrawsContent(true); |
| 5179 | grand_child1->SetForceRenderSurface(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5180 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5181 | child1->AddChild(grand_child1.Pass()); |
| 5182 | root->AddChild(child1.Pass()); |
| 5183 | root->AddChild(child2.Pass()); |
| 5184 | } |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5185 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5186 | LayerImpl* child1 = root->children()[0]; |
| 5187 | LayerImpl* child2 = root->children()[1]; |
| 5188 | LayerImpl* grand_child1 = child1->children()[0]; |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5189 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5190 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5191 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5192 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5193 | inputs.can_adjust_raster_scales = true; |
| 5194 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5195 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5196 | // Sanity check the scenario we just created. |
| 5197 | ASSERT_TRUE(child1); |
| 5198 | ASSERT_TRUE(child2); |
| 5199 | ASSERT_TRUE(grand_child1); |
| 5200 | ASSERT_TRUE(child1->render_surface()); |
| 5201 | ASSERT_TRUE(child2->render_surface()); |
| 5202 | ASSERT_TRUE(grand_child1->render_surface()); |
| 5203 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
| 5204 | // The root surface has the root layer, and child1's and child2's render |
| 5205 | // surfaces. |
| 5206 | ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
| 5207 | // The child1 surface has the child1 layer and grand_child1's render surface. |
| 5208 | ASSERT_EQ(2u, child1->render_surface()->layer_list().size()); |
| 5209 | ASSERT_EQ(1u, child2->render_surface()->layer_list().size()); |
| 5210 | ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5211 | ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5212 | ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1 |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5213 | ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1 |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5214 | ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2 |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5215 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5216 | // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
| 5217 | // the root layer. |
| 5218 | gfx::Point test_point = gfx::Point(1, 1); |
| 5219 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5220 | test_point, render_surface_layer_list); |
| 5221 | ASSERT_TRUE(result_layer); |
| 5222 | EXPECT_EQ(1, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5223 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5224 | // At (15, 15), child1 and root are the only layers. child1 is expected to be |
| 5225 | // on top. |
| 5226 | test_point = gfx::Point(15, 15); |
| 5227 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5228 | test_point, render_surface_layer_list); |
| 5229 | ASSERT_TRUE(result_layer); |
| 5230 | EXPECT_EQ(2, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5231 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5232 | // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. |
| 5233 | test_point = gfx::Point(51, 20); |
| 5234 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5235 | test_point, render_surface_layer_list); |
| 5236 | ASSERT_TRUE(result_layer); |
| 5237 | EXPECT_EQ(3, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5238 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5239 | // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on |
| 5240 | // top. |
| 5241 | test_point = gfx::Point(80, 51); |
| 5242 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5243 | test_point, render_surface_layer_list); |
| 5244 | ASSERT_TRUE(result_layer); |
| 5245 | EXPECT_EQ(3, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5246 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5247 | // At (51, 51), all layers overlap each other. child2 is expected to be on top |
| 5248 | // of all other layers. |
| 5249 | test_point = gfx::Point(51, 51); |
| 5250 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5251 | test_point, render_surface_layer_list); |
| 5252 | ASSERT_TRUE(result_layer); |
| 5253 | EXPECT_EQ(3, result_layer->id()); |
| 5254 | |
| 5255 | // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to |
| 5256 | // be on top. |
| 5257 | test_point = gfx::Point(20, 51); |
| 5258 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5259 | test_point, render_surface_layer_list); |
| 5260 | ASSERT_TRUE(result_layer); |
| 5261 | EXPECT_EQ(4, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5262 | } |
| 5263 | |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5264 | TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) { |
| 5265 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5266 | TestSharedBitmapManager shared_bitmap_manager; |
| 5267 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5268 | |
| 5269 | // Layer 1 - root |
| 5270 | scoped_ptr<LayerImpl> root = |
| 5271 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 5272 | gfx::Transform identity_matrix; |
| 5273 | gfx::PointF anchor; |
| 5274 | gfx::PointF position; |
| 5275 | gfx::Size bounds(100, 100); |
| 5276 | SetLayerPropertiesForTesting(root.get(), |
| 5277 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5278 | anchor, |
| 5279 | position, |
| 5280 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5281 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5282 | false); |
| 5283 | root->SetDrawsContent(true); |
| 5284 | |
| 5285 | { |
| 5286 | // Layer 2 - empty: drawsContent=false |
| 5287 | gfx::PointF position(10.f, 10.f); |
| 5288 | gfx::Size bounds(30, 30); |
| 5289 | scoped_ptr<LayerImpl> empty_layer = |
| 5290 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 5291 | SetLayerPropertiesForTesting(empty_layer.get(), |
| 5292 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5293 | anchor, |
| 5294 | position, |
| 5295 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5296 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5297 | false); |
| 5298 | |
| 5299 | empty_layer->SetDrawsContent(false); |
| 5300 | root->AddChild(empty_layer.Pass()); |
| 5301 | } |
| 5302 | |
| 5303 | { |
| 5304 | // Layer 3 - empty, but has touch handler |
| 5305 | gfx::PointF position(10.f, 60.f); |
| 5306 | gfx::Size bounds(30, 30); |
| 5307 | scoped_ptr<LayerImpl> test_layer = |
| 5308 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 5309 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5310 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5311 | anchor, |
| 5312 | position, |
| 5313 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5314 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5315 | false); |
| 5316 | |
| 5317 | test_layer->SetDrawsContent(false); |
| 5318 | Region touch_handler_region(gfx::Rect(10, 10, 10, 10)); |
| 5319 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5320 | root->AddChild(test_layer.Pass()); |
| 5321 | } |
| 5322 | |
| 5323 | { |
| 5324 | // Layer 4 - empty, but has mousewheel handler |
| 5325 | gfx::PointF position(60.f, 60.f); |
| 5326 | gfx::Size bounds(30, 30); |
| 5327 | scoped_ptr<LayerImpl> test_layer = |
| 5328 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 5329 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5330 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5331 | anchor, |
| 5332 | position, |
| 5333 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5334 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5335 | false); |
| 5336 | |
| 5337 | test_layer->SetDrawsContent(false); |
| 5338 | test_layer->SetHaveWheelEventHandlers(true); |
| 5339 | root->AddChild(test_layer.Pass()); |
| 5340 | } |
| 5341 | |
| 5342 | LayerImplList render_surface_layer_list; |
| 5343 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5344 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5345 | inputs.can_adjust_raster_scales = true; |
| 5346 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5347 | |
| 5348 | // Verify that the root layer and empty layers with touch/wheel handlers |
| 5349 | // (but not the empty layer without a touch handler) are in the RSSL. |
| 5350 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5351 | EXPECT_EQ(1, render_surface_layer_list[0]->id()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5352 | ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5353 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5354 | EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id()); |
| 5355 | EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5356 | |
| 5357 | // Hit testing for a point inside the empty no-handlers layer should return |
| 5358 | // the root layer. |
| 5359 | gfx::Point test_point = gfx::Point(15, 15); |
| 5360 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5361 | test_point, render_surface_layer_list); |
| 5362 | ASSERT_TRUE(result_layer); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5363 | EXPECT_EQ(1, result_layer->id()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5364 | |
| 5365 | // Hit testing for a point inside the touch handler layer should return it. |
| 5366 | test_point = gfx::Point(15, 75); |
| 5367 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5368 | test_point, render_surface_layer_list); |
| 5369 | ASSERT_TRUE(result_layer); |
| 5370 | EXPECT_EQ(3, result_layer->id()); |
| 5371 | |
| 5372 | // Hit testing for a point inside the mousewheel layer should return it. |
| 5373 | test_point = gfx::Point(75, 75); |
| 5374 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5375 | test_point, render_surface_layer_list); |
| 5376 | ASSERT_TRUE(result_layer); |
| 5377 | EXPECT_EQ(4, result_layer->id()); |
| 5378 | } |
| 5379 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5380 | TEST_F(LayerTreeHostCommonTest, |
| 5381 | HitCheckingTouchHandlerRegionsForEmptyLayerList) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5382 | // Hit checking on an empty render_surface_layer_list should return a null |
| 5383 | // pointer. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5384 | LayerImplList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5385 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5386 | gfx::Point test_point(0, 0); |
| 5387 | LayerImpl* result_layer = |
| 5388 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5389 | test_point, render_surface_layer_list); |
| 5390 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5391 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5392 | test_point = gfx::Point(10, 20); |
| 5393 | result_layer = |
| 5394 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5395 | test_point, render_surface_layer_list); |
| 5396 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5397 | } |
| 5398 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5399 | TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5400 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5401 | TestSharedBitmapManager shared_bitmap_manager; |
| 5402 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5403 | scoped_ptr<LayerImpl> root = |
| 5404 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5405 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5406 | gfx::Transform identity_matrix; |
| 5407 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5408 | gfx::PointF anchor; |
| 5409 | gfx::PointF position; |
| 5410 | gfx::Size bounds(100, 100); |
| 5411 | SetLayerPropertiesForTesting(root.get(), |
| 5412 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5413 | anchor, |
| 5414 | position, |
| 5415 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5416 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5417 | false); |
| 5418 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5419 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5420 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5421 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5422 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5423 | inputs.can_adjust_raster_scales = true; |
| 5424 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5425 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5426 | // Sanity check the scenario we just created. |
| 5427 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5428 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5429 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5430 | // Hit checking for any point should return a null pointer for a layer without |
| 5431 | // any touch event handler regions. |
| 5432 | gfx::Point test_point(11, 11); |
| 5433 | LayerImpl* result_layer = |
| 5434 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5435 | test_point, render_surface_layer_list); |
| 5436 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5437 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5438 | root->SetTouchEventHandlerRegion(touch_handler_region); |
| 5439 | // Hit checking for a point outside the layer should return a null pointer. |
| 5440 | test_point = gfx::Point(101, 101); |
| 5441 | result_layer = |
| 5442 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5443 | test_point, render_surface_layer_list); |
| 5444 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5445 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5446 | test_point = gfx::Point(-1, -1); |
| 5447 | result_layer = |
| 5448 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5449 | test_point, render_surface_layer_list); |
| 5450 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5451 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5452 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5453 | // region should return a null pointer. |
| 5454 | test_point = gfx::Point(1, 1); |
| 5455 | result_layer = |
| 5456 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5457 | test_point, render_surface_layer_list); |
| 5458 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5459 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5460 | test_point = gfx::Point(99, 99); |
| 5461 | result_layer = |
| 5462 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5463 | test_point, render_surface_layer_list); |
| 5464 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5465 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5466 | // Hit checking for a point inside the touch event handler region should |
| 5467 | // return the root layer. |
| 5468 | test_point = gfx::Point(11, 11); |
| 5469 | result_layer = |
| 5470 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5471 | test_point, render_surface_layer_list); |
| 5472 | ASSERT_TRUE(result_layer); |
| 5473 | EXPECT_EQ(12345, result_layer->id()); |
| 5474 | |
| 5475 | test_point = gfx::Point(59, 59); |
| 5476 | result_layer = |
| 5477 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5478 | test_point, render_surface_layer_list); |
| 5479 | ASSERT_TRUE(result_layer); |
| 5480 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5481 | } |
| 5482 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5483 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5484 | HitCheckingTouchHandlerRegionsForUninvertibleTransform) { |
| 5485 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5486 | TestSharedBitmapManager shared_bitmap_manager; |
| 5487 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5488 | scoped_ptr<LayerImpl> root = |
| 5489 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5490 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5491 | gfx::Transform uninvertible_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5492 | uninvertible_transform.matrix().set(0, 0, 0.0); |
| 5493 | uninvertible_transform.matrix().set(1, 1, 0.0); |
| 5494 | uninvertible_transform.matrix().set(2, 2, 0.0); |
| 5495 | uninvertible_transform.matrix().set(3, 3, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5496 | ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5497 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5498 | gfx::Transform identity_matrix; |
| 5499 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5500 | gfx::PointF anchor; |
| 5501 | gfx::PointF position; |
| 5502 | gfx::Size bounds(100, 100); |
| 5503 | SetLayerPropertiesForTesting(root.get(), |
| 5504 | uninvertible_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5505 | anchor, |
| 5506 | position, |
| 5507 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5508 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5509 | false); |
| 5510 | root->SetDrawsContent(true); |
| 5511 | root->SetTouchEventHandlerRegion(touch_handler_region); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5512 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5513 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5514 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5515 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5516 | inputs.can_adjust_raster_scales = true; |
| 5517 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5518 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5519 | // Sanity check the scenario we just created. |
| 5520 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5521 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5522 | ASSERT_FALSE(root->screen_space_transform().IsInvertible()); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5523 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5524 | // Hit checking any point should not hit the touch handler region on the |
| 5525 | // layer. If the invertible matrix is accidentally ignored and treated like an |
| 5526 | // identity, then the hit testing will incorrectly hit the layer when it |
| 5527 | // shouldn't. |
| 5528 | gfx::Point test_point(1, 1); |
| 5529 | LayerImpl* result_layer = |
| 5530 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5531 | test_point, render_surface_layer_list); |
| 5532 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5533 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5534 | test_point = gfx::Point(10, 10); |
| 5535 | result_layer = |
| 5536 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5537 | test_point, render_surface_layer_list); |
| 5538 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5539 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5540 | test_point = gfx::Point(10, 30); |
| 5541 | result_layer = |
| 5542 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5543 | test_point, render_surface_layer_list); |
| 5544 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5545 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5546 | test_point = gfx::Point(50, 50); |
| 5547 | result_layer = |
| 5548 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5549 | test_point, render_surface_layer_list); |
| 5550 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5551 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5552 | test_point = gfx::Point(67, 48); |
| 5553 | result_layer = |
| 5554 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5555 | test_point, render_surface_layer_list); |
| 5556 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5557 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5558 | test_point = gfx::Point(99, 99); |
| 5559 | result_layer = |
| 5560 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5561 | test_point, render_surface_layer_list); |
| 5562 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5563 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5564 | test_point = gfx::Point(-1, -1); |
| 5565 | result_layer = |
| 5566 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5567 | test_point, render_surface_layer_list); |
| 5568 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5569 | } |
| 5570 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5571 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5572 | HitCheckingTouchHandlerRegionsForSinglePositionedLayer) { |
| 5573 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5574 | TestSharedBitmapManager shared_bitmap_manager; |
| 5575 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5576 | scoped_ptr<LayerImpl> root = |
| 5577 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5578 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5579 | gfx::Transform identity_matrix; |
| 5580 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5581 | gfx::PointF anchor; |
| 5582 | // this layer is positioned, and hit testing should correctly know where the |
| 5583 | // layer is located. |
| 5584 | gfx::PointF position(50.f, 50.f); |
| 5585 | gfx::Size bounds(100, 100); |
| 5586 | SetLayerPropertiesForTesting(root.get(), |
| 5587 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5588 | anchor, |
| 5589 | position, |
| 5590 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5591 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5592 | false); |
| 5593 | root->SetDrawsContent(true); |
| 5594 | root->SetTouchEventHandlerRegion(touch_handler_region); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5595 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5596 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5597 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5598 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5599 | inputs.can_adjust_raster_scales = true; |
| 5600 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5601 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5602 | // Sanity check the scenario we just created. |
| 5603 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5604 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5605 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5606 | // Hit checking for a point outside the layer should return a null pointer. |
| 5607 | gfx::Point test_point(49, 49); |
| 5608 | LayerImpl* result_layer = |
| 5609 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5610 | test_point, render_surface_layer_list); |
| 5611 | EXPECT_FALSE(result_layer); |
| 5612 | |
| 5613 | // Even though the layer has a touch handler region containing (101, 101), it |
| 5614 | // should not be visible there since the root render surface would clamp it. |
| 5615 | test_point = gfx::Point(101, 101); |
| 5616 | result_layer = |
| 5617 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5618 | test_point, render_surface_layer_list); |
| 5619 | EXPECT_FALSE(result_layer); |
| 5620 | |
| 5621 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5622 | // region should return a null pointer. |
| 5623 | test_point = gfx::Point(51, 51); |
| 5624 | result_layer = |
| 5625 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5626 | test_point, render_surface_layer_list); |
| 5627 | EXPECT_FALSE(result_layer); |
| 5628 | |
| 5629 | // Hit checking for a point inside the touch event handler region should |
| 5630 | // return the root layer. |
| 5631 | test_point = gfx::Point(61, 61); |
| 5632 | result_layer = |
| 5633 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5634 | test_point, render_surface_layer_list); |
| 5635 | ASSERT_TRUE(result_layer); |
| 5636 | EXPECT_EQ(12345, result_layer->id()); |
| 5637 | |
| 5638 | test_point = gfx::Point(99, 99); |
| 5639 | result_layer = |
| 5640 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5641 | test_point, render_surface_layer_list); |
| 5642 | ASSERT_TRUE(result_layer); |
| 5643 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5644 | } |
| 5645 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5646 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5647 | HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) { |
| 5648 | // A layer's visible content rect is actually in the layer's content space. |
| 5649 | // The screen space transform converts from the layer's origin space to screen |
| 5650 | // space. This test makes sure that hit testing works correctly accounts for |
| 5651 | // the contents scale. A contents scale that is not 1 effectively forces a |
| 5652 | // non-identity transform between layer's content space and layer's origin |
| 5653 | // space. The hit testing code must take this into account. |
| 5654 | // |
| 5655 | // To test this, the layer is positioned at (25, 25), and is size (50, 50). If |
| 5656 | // contents scale is ignored, then hit checking will mis-interpret the visible |
| 5657 | // content rect as being larger than the actual bounds of the layer. |
| 5658 | // |
| 5659 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5660 | TestSharedBitmapManager shared_bitmap_manager; |
| 5661 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5662 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5663 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5664 | gfx::Transform identity_matrix; |
| 5665 | gfx::PointF anchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5666 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5667 | SetLayerPropertiesForTesting(root.get(), |
| 5668 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5669 | anchor, |
| 5670 | gfx::PointF(), |
| 5671 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5672 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5673 | false); |
| 5674 | { |
| 5675 | Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); |
| 5676 | gfx::PointF position(25.f, 25.f); |
| 5677 | gfx::Size bounds(50, 50); |
| 5678 | scoped_ptr<LayerImpl> test_layer = |
| 5679 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 5680 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5681 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5682 | anchor, |
| 5683 | position, |
| 5684 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5685 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5686 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5687 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5688 | // override content bounds and contents scale |
| 5689 | test_layer->SetContentBounds(gfx::Size(100, 100)); |
| 5690 | test_layer->SetContentsScale(2, 2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5691 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5692 | test_layer->SetDrawsContent(true); |
| 5693 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5694 | root->AddChild(test_layer.Pass()); |
| 5695 | } |
| 5696 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5697 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5698 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5699 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5700 | inputs.can_adjust_raster_scales = true; |
| 5701 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5702 | |
| 5703 | // Sanity check the scenario we just created. |
| 5704 | // The visible content rect for test_layer is actually 100x100, even though |
| 5705 | // its layout size is 50x50, positioned at 25x25. |
| 5706 | LayerImpl* test_layer = root->children()[0]; |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 5707 | 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] | 5708 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5709 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5710 | |
| 5711 | // Hit checking for a point outside the layer should return a null pointer |
| 5712 | // (the root layer does not draw content, so it will not be tested either). |
| 5713 | gfx::Point test_point(76, 76); |
| 5714 | LayerImpl* result_layer = |
| 5715 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5716 | test_point, render_surface_layer_list); |
| 5717 | EXPECT_FALSE(result_layer); |
| 5718 | |
| 5719 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5720 | // region should return a null pointer. |
| 5721 | test_point = gfx::Point(26, 26); |
| 5722 | result_layer = |
| 5723 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5724 | test_point, render_surface_layer_list); |
| 5725 | EXPECT_FALSE(result_layer); |
| 5726 | |
| 5727 | test_point = gfx::Point(34, 34); |
| 5728 | result_layer = |
| 5729 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5730 | test_point, render_surface_layer_list); |
| 5731 | EXPECT_FALSE(result_layer); |
| 5732 | |
| 5733 | test_point = gfx::Point(65, 65); |
| 5734 | result_layer = |
| 5735 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5736 | test_point, render_surface_layer_list); |
| 5737 | EXPECT_FALSE(result_layer); |
| 5738 | |
| 5739 | test_point = gfx::Point(74, 74); |
| 5740 | result_layer = |
| 5741 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5742 | test_point, render_surface_layer_list); |
| 5743 | EXPECT_FALSE(result_layer); |
| 5744 | |
| 5745 | // Hit checking for a point inside the touch event handler region should |
| 5746 | // return the root layer. |
| 5747 | test_point = gfx::Point(35, 35); |
| 5748 | result_layer = |
| 5749 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5750 | test_point, render_surface_layer_list); |
| 5751 | ASSERT_TRUE(result_layer); |
| 5752 | EXPECT_EQ(12345, result_layer->id()); |
| 5753 | |
| 5754 | test_point = gfx::Point(64, 64); |
| 5755 | result_layer = |
| 5756 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5757 | test_point, render_surface_layer_list); |
| 5758 | ASSERT_TRUE(result_layer); |
| 5759 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5760 | } |
| 5761 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5762 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5763 | HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) { |
| 5764 | // The layer's device_scale_factor and page_scale_factor should scale the |
| 5765 | // content rect and we should be able to hit the touch handler region by |
| 5766 | // scaling the points accordingly. |
| 5767 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5768 | TestSharedBitmapManager shared_bitmap_manager; |
| 5769 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5770 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5771 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5772 | gfx::Transform identity_matrix; |
| 5773 | gfx::PointF anchor; |
| 5774 | // Set the bounds of the root layer big enough to fit the child when scaled. |
| 5775 | SetLayerPropertiesForTesting(root.get(), |
| 5776 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5777 | anchor, |
| 5778 | gfx::PointF(), |
| 5779 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5780 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5781 | false); |
| 5782 | { |
| 5783 | Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); |
| 5784 | gfx::PointF position(25.f, 25.f); |
| 5785 | gfx::Size bounds(50, 50); |
| 5786 | scoped_ptr<LayerImpl> test_layer = |
| 5787 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 5788 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5789 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5790 | anchor, |
| 5791 | position, |
| 5792 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5793 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5794 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5795 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5796 | test_layer->SetDrawsContent(true); |
| 5797 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5798 | root->AddChild(test_layer.Pass()); |
| 5799 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5800 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5801 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5802 | float device_scale_factor = 3.f; |
| 5803 | float page_scale_factor = 5.f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5804 | gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize( |
| 5805 | gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor)); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5806 | |
| 5807 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5808 | root.get(), scaled_bounds_for_root, &render_surface_layer_list); |
| 5809 | inputs.device_scale_factor = device_scale_factor; |
| 5810 | inputs.page_scale_factor = page_scale_factor; |
| 5811 | inputs.page_scale_application_layer = root.get(); |
| 5812 | inputs.can_adjust_raster_scales = true; |
| 5813 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5814 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5815 | // Sanity check the scenario we just created. |
| 5816 | // The visible content rect for test_layer is actually 100x100, even though |
| 5817 | // its layout size is 50x50, positioned at 25x25. |
| 5818 | LayerImpl* test_layer = root->children()[0]; |
| 5819 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5820 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5821 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5822 | // Check whether the child layer fits into the root after scaled. |
| 5823 | EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()), |
| 5824 | test_layer->visible_content_rect()); |
| 5825 | |
| 5826 | // Hit checking for a point outside the layer should return a null pointer |
| 5827 | // (the root layer does not draw content, so it will not be tested either). |
| 5828 | gfx::PointF test_point(76.f, 76.f); |
| 5829 | test_point = |
| 5830 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5831 | LayerImpl* result_layer = |
| 5832 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5833 | test_point, render_surface_layer_list); |
| 5834 | EXPECT_FALSE(result_layer); |
| 5835 | |
| 5836 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5837 | // region should return a null pointer. |
| 5838 | test_point = gfx::Point(26, 26); |
| 5839 | test_point = |
| 5840 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5841 | result_layer = |
| 5842 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5843 | test_point, render_surface_layer_list); |
| 5844 | EXPECT_FALSE(result_layer); |
| 5845 | |
| 5846 | test_point = gfx::Point(34, 34); |
| 5847 | test_point = |
| 5848 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5849 | result_layer = |
| 5850 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5851 | test_point, render_surface_layer_list); |
| 5852 | EXPECT_FALSE(result_layer); |
| 5853 | |
| 5854 | test_point = gfx::Point(65, 65); |
| 5855 | test_point = |
| 5856 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5857 | result_layer = |
| 5858 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5859 | test_point, render_surface_layer_list); |
| 5860 | EXPECT_FALSE(result_layer); |
| 5861 | |
| 5862 | test_point = gfx::Point(74, 74); |
| 5863 | test_point = |
| 5864 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5865 | result_layer = |
| 5866 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5867 | test_point, render_surface_layer_list); |
| 5868 | EXPECT_FALSE(result_layer); |
| 5869 | |
| 5870 | // Hit checking for a point inside the touch event handler region should |
| 5871 | // return the root layer. |
| 5872 | test_point = gfx::Point(35, 35); |
| 5873 | test_point = |
| 5874 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5875 | result_layer = |
| 5876 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5877 | test_point, render_surface_layer_list); |
| 5878 | ASSERT_TRUE(result_layer); |
| 5879 | EXPECT_EQ(12345, result_layer->id()); |
| 5880 | |
| 5881 | test_point = gfx::Point(64, 64); |
| 5882 | test_point = |
| 5883 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5884 | result_layer = |
| 5885 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5886 | test_point, render_surface_layer_list); |
| 5887 | ASSERT_TRUE(result_layer); |
| 5888 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5889 | } |
| 5890 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5891 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5892 | HitCheckingTouchHandlerRegionsForSimpleClippedLayer) { |
| 5893 | // Test that hit-checking will only work for the visible portion of a layer, |
| 5894 | // and not the entire layer bounds. Here we just test the simple axis-aligned |
| 5895 | // case. |
| 5896 | gfx::Transform identity_matrix; |
| 5897 | gfx::PointF anchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5898 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5899 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5900 | TestSharedBitmapManager shared_bitmap_manager; |
| 5901 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5902 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 5903 | SetLayerPropertiesForTesting(root.get(), |
| 5904 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5905 | anchor, |
| 5906 | gfx::PointF(), |
| 5907 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5908 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5909 | false); |
| 5910 | { |
| 5911 | scoped_ptr<LayerImpl> clipping_layer = |
| 5912 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 5913 | // this layer is positioned, and hit testing should correctly know where the |
| 5914 | // layer is located. |
| 5915 | gfx::PointF position(25.f, 25.f); |
| 5916 | gfx::Size bounds(50, 50); |
| 5917 | SetLayerPropertiesForTesting(clipping_layer.get(), |
| 5918 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5919 | anchor, |
| 5920 | position, |
| 5921 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5922 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5923 | false); |
| 5924 | clipping_layer->SetMasksToBounds(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5925 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5926 | scoped_ptr<LayerImpl> child = |
| 5927 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 5928 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5929 | position = gfx::PointF(-50.f, -50.f); |
| 5930 | bounds = gfx::Size(300, 300); |
| 5931 | SetLayerPropertiesForTesting(child.get(), |
| 5932 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5933 | anchor, |
| 5934 | position, |
| 5935 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5936 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5937 | false); |
| 5938 | child->SetDrawsContent(true); |
| 5939 | child->SetTouchEventHandlerRegion(touch_handler_region); |
| 5940 | clipping_layer->AddChild(child.Pass()); |
| 5941 | root->AddChild(clipping_layer.Pass()); |
| 5942 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5943 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5944 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5945 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5946 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5947 | inputs.can_adjust_raster_scales = true; |
| 5948 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5949 | |
| 5950 | // Sanity check the scenario we just created. |
| 5951 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5952 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5953 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5954 | |
| 5955 | // Hit checking for a point outside the layer should return a null pointer. |
| 5956 | // Despite the child layer being very large, it should be clipped to the root |
| 5957 | // layer's bounds. |
| 5958 | gfx::Point test_point(24, 24); |
| 5959 | LayerImpl* result_layer = |
| 5960 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5961 | test_point, render_surface_layer_list); |
| 5962 | EXPECT_FALSE(result_layer); |
| 5963 | |
| 5964 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5965 | // region should return a null pointer. |
| 5966 | test_point = gfx::Point(35, 35); |
| 5967 | result_layer = |
| 5968 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5969 | test_point, render_surface_layer_list); |
| 5970 | EXPECT_FALSE(result_layer); |
| 5971 | |
| 5972 | test_point = gfx::Point(74, 74); |
| 5973 | result_layer = |
| 5974 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5975 | test_point, render_surface_layer_list); |
| 5976 | EXPECT_FALSE(result_layer); |
| 5977 | |
| 5978 | // Hit checking for a point inside the touch event handler region should |
| 5979 | // return the root layer. |
| 5980 | test_point = gfx::Point(25, 25); |
| 5981 | result_layer = |
| 5982 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5983 | test_point, render_surface_layer_list); |
| 5984 | ASSERT_TRUE(result_layer); |
| 5985 | EXPECT_EQ(456, result_layer->id()); |
| 5986 | |
| 5987 | test_point = gfx::Point(34, 34); |
| 5988 | result_layer = |
| 5989 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5990 | test_point, render_surface_layer_list); |
| 5991 | ASSERT_TRUE(result_layer); |
| 5992 | EXPECT_EQ(456, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5993 | } |
| 5994 | |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5995 | TEST_F(LayerTreeHostCommonTest, |
| 5996 | HitCheckingTouchHandlerOverlappingRegions) { |
| 5997 | gfx::Transform identity_matrix; |
| 5998 | gfx::PointF anchor; |
| 5999 | |
| 6000 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6001 | TestSharedBitmapManager shared_bitmap_manager; |
| 6002 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6003 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 6004 | SetLayerPropertiesForTesting(root.get(), |
| 6005 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6006 | anchor, |
| 6007 | gfx::PointF(), |
| 6008 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6009 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6010 | false); |
| 6011 | { |
| 6012 | scoped_ptr<LayerImpl> touch_layer = |
| 6013 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 6014 | // this layer is positioned, and hit testing should correctly know where the |
| 6015 | // layer is located. |
| 6016 | gfx::PointF position; |
| 6017 | gfx::Size bounds(50, 50); |
| 6018 | SetLayerPropertiesForTesting(touch_layer.get(), |
| 6019 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6020 | anchor, |
| 6021 | position, |
| 6022 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6023 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6024 | false); |
| 6025 | touch_layer->SetDrawsContent(true); |
| 6026 | touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); |
| 6027 | root->AddChild(touch_layer.Pass()); |
| 6028 | } |
| 6029 | |
| 6030 | { |
| 6031 | scoped_ptr<LayerImpl> notouch_layer = |
| 6032 | LayerImpl::Create(host_impl.active_tree(), 1234); |
| 6033 | // this layer is positioned, and hit testing should correctly know where the |
| 6034 | // layer is located. |
| 6035 | gfx::PointF position(0, 25); |
| 6036 | gfx::Size bounds(50, 50); |
| 6037 | SetLayerPropertiesForTesting(notouch_layer.get(), |
| 6038 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6039 | anchor, |
| 6040 | position, |
| 6041 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6042 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6043 | false); |
| 6044 | notouch_layer->SetDrawsContent(true); |
| 6045 | root->AddChild(notouch_layer.Pass()); |
| 6046 | } |
| 6047 | |
| 6048 | LayerImplList render_surface_layer_list; |
| 6049 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 6050 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6051 | inputs.can_adjust_raster_scales = true; |
| 6052 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6053 | |
| 6054 | // Sanity check the scenario we just created. |
| 6055 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 6056 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 6057 | ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id()); |
| 6058 | ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6059 | |
| 6060 | gfx::Point test_point(35, 35); |
| 6061 | LayerImpl* result_layer = |
| 6062 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6063 | test_point, render_surface_layer_list); |
[email protected] | 5183605e | 2014-04-17 03:57:18 | [diff] [blame] | 6064 | |
| 6065 | // We should have passed through the no-touch layer and found the layer |
| 6066 | // behind it. |
| 6067 | EXPECT_TRUE(result_layer); |
| 6068 | |
| 6069 | host_impl.active_tree()->LayerById(1234)->SetContentsOpaque(true); |
| 6070 | result_layer = |
| 6071 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6072 | test_point, render_surface_layer_list); |
| 6073 | |
[email protected] | 489eb9989 | 2014-04-27 00:27:34 | [diff] [blame] | 6074 | // Even with an opaque layer in the middle, we should still find the layer |
| 6075 | // with |
| 6076 | // the touch handler behind it (since we can't assume that opaque layers are |
| 6077 | // opaque to hit testing). |
| 6078 | EXPECT_TRUE(result_layer); |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6079 | |
| 6080 | test_point = gfx::Point(35, 15); |
| 6081 | result_layer = |
| 6082 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6083 | test_point, render_surface_layer_list); |
| 6084 | ASSERT_TRUE(result_layer); |
| 6085 | EXPECT_EQ(123, result_layer->id()); |
| 6086 | |
| 6087 | test_point = gfx::Point(35, 65); |
| 6088 | result_layer = |
| 6089 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6090 | test_point, render_surface_layer_list); |
| 6091 | EXPECT_FALSE(result_layer); |
| 6092 | } |
| 6093 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6094 | class NoScaleContentLayer : public ContentLayer { |
| 6095 | public: |
| 6096 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 6097 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 6098 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6099 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6100 | virtual void CalculateContentsScale(float ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 6101 | float device_scale_factor, |
| 6102 | float page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6103 | float maximum_animation_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6104 | bool animating_transform_to_screen, |
| 6105 | float* contents_scale_x, |
| 6106 | float* contents_scale_y, |
| 6107 | gfx::Size* content_bounds) OVERRIDE { |
| 6108 | // Skip over the ContentLayer to the base Layer class. |
| 6109 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 6110 | device_scale_factor, |
| 6111 | page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6112 | maximum_animation_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6113 | animating_transform_to_screen, |
| 6114 | contents_scale_x, |
| 6115 | contents_scale_y, |
| 6116 | content_bounds); |
| 6117 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6118 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6119 | protected: |
| 6120 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 6121 | : ContentLayer(client) {} |
| 6122 | virtual ~NoScaleContentLayer() {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6123 | }; |
| 6124 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6125 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 6126 | ContentLayerClient* delegate) { |
| 6127 | scoped_refptr<NoScaleContentLayer> to_return = |
| 6128 | NoScaleContentLayer::Create(delegate); |
| 6129 | to_return->SetIsDrawable(true); |
| 6130 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6131 | } |
| 6132 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6133 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6134 | // Verify draw and screen space transforms of layers not in a surface. |
| 6135 | MockContentLayerClient delegate; |
| 6136 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6137 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6138 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6139 | SetLayerPropertiesForTesting(parent.get(), |
| 6140 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6141 | gfx::PointF(), |
| 6142 | gfx::PointF(), |
| 6143 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6144 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6145 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6146 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6147 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 6148 | SetLayerPropertiesForTesting(child.get(), |
| 6149 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6150 | gfx::PointF(), |
| 6151 | gfx::PointF(2.f, 2.f), |
| 6152 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6153 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6154 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6155 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6156 | scoped_refptr<ContentLayer> child_empty = |
| 6157 | CreateDrawableContentLayer(&delegate); |
| 6158 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6159 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6160 | gfx::PointF(), |
| 6161 | gfx::PointF(2.f, 2.f), |
| 6162 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6163 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6164 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6165 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6166 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6167 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6168 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6169 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6170 | gfx::PointF(), |
| 6171 | gfx::PointF(2.f, 2.f), |
| 6172 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6173 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6174 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6175 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6176 | parent->AddChild(child); |
| 6177 | parent->AddChild(child_empty); |
| 6178 | parent->AddChild(child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6179 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6180 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6181 | host->SetRootLayer(parent); |
| 6182 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6183 | float device_scale_factor = 2.5f; |
| 6184 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6185 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6186 | RenderSurfaceLayerList render_surface_layer_list; |
| 6187 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6188 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 6189 | inputs.device_scale_factor = device_scale_factor; |
| 6190 | inputs.page_scale_factor = page_scale_factor; |
| 6191 | inputs.can_adjust_raster_scales = true; |
| 6192 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6193 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6194 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6195 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 6196 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6197 | child_empty); |
| 6198 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6199 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6200 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6201 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6202 | // Verify parent transforms |
| 6203 | gfx::Transform expected_parent_transform; |
| 6204 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6205 | parent->screen_space_transform()); |
| 6206 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6207 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6208 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6209 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6210 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6211 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6212 | gfx::RectF parent_draw_rect = |
| 6213 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 6214 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 6215 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6216 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6217 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6218 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 6219 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 6220 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6221 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6222 | // Verify child and child_empty transforms. They should match. |
| 6223 | gfx::Transform expected_child_transform; |
| 6224 | expected_child_transform.Translate( |
| 6225 | device_scale_factor * child->position().x(), |
| 6226 | device_scale_factor * child->position().y()); |
| 6227 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6228 | child->draw_transform()); |
| 6229 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6230 | child->screen_space_transform()); |
| 6231 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6232 | child_empty->draw_transform()); |
| 6233 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6234 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6235 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6236 | // Verify results of transformed child and child_empty rects. They should |
| 6237 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6238 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6239 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6240 | gfx::RectF child_draw_rect = |
| 6241 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 6242 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 6243 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6244 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6245 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 6246 | child_empty->draw_transform(), child_content_bounds); |
| 6247 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 6248 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6249 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6250 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 6251 | expected_child_draw_rect.Scale(device_scale_factor); |
| 6252 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 6253 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 6254 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 6255 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6256 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6257 | // Verify child_no_scale transforms |
| 6258 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 6259 | // All transforms operate on content rects. The child's content rect |
| 6260 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 6261 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 6262 | device_scale_factor); |
| 6263 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6264 | child_no_scale->draw_transform()); |
| 6265 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6266 | child_no_scale->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6267 | } |
| 6268 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6269 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6270 | // Verify draw and screen space transforms of layers in a surface. |
| 6271 | MockContentLayerClient delegate; |
| 6272 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6273 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6274 | gfx::Transform perspective_matrix; |
| 6275 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6276 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6277 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 6278 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6279 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 6280 | scoped_refptr<Layer> root = Layer::Create(); |
| 6281 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6282 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6283 | SetLayerPropertiesForTesting(parent.get(), |
| 6284 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6285 | gfx::PointF(), |
| 6286 | gfx::PointF(), |
| 6287 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6288 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6289 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6290 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6291 | scoped_refptr<ContentLayer> perspective_surface = |
| 6292 | CreateDrawableContentLayer(&delegate); |
| 6293 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 6294 | perspective_matrix * scale_small_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6295 | gfx::PointF(), |
| 6296 | gfx::PointF(2.f, 2.f), |
| 6297 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6298 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6299 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6300 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6301 | scoped_refptr<ContentLayer> scale_surface = |
| 6302 | CreateDrawableContentLayer(&delegate); |
| 6303 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 6304 | scale_small_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6305 | gfx::PointF(), |
| 6306 | gfx::PointF(2.f, 2.f), |
| 6307 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6308 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6309 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6310 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6311 | perspective_surface->SetForceRenderSurface(true); |
| 6312 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6313 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6314 | parent->AddChild(perspective_surface); |
| 6315 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 6316 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6317 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6318 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6319 | host->SetRootLayer(root); |
| 6320 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6321 | float device_scale_factor = 2.5f; |
| 6322 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6323 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6324 | RenderSurfaceLayerList render_surface_layer_list; |
| 6325 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6326 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 6327 | inputs.device_scale_factor = device_scale_factor; |
| 6328 | inputs.page_scale_factor = page_scale_factor; |
| 6329 | inputs.page_scale_application_layer = root; |
| 6330 | inputs.can_adjust_raster_scales = true; |
| 6331 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6332 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6333 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6334 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6335 | perspective_surface); |
| 6336 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6337 | scale_surface); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6338 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6339 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6340 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6341 | gfx::Transform expected_parent_draw_transform; |
| 6342 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 6343 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6344 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6345 | // The scaled surface is rendered at its appropriate scale, and drawn 1:1 |
| 6346 | // into its target. |
| 6347 | gfx::Transform expected_scale_surface_draw_transform; |
| 6348 | expected_scale_surface_draw_transform.Translate( |
| 6349 | device_scale_factor * page_scale_factor * scale_surface->position().x(), |
| 6350 | device_scale_factor * page_scale_factor * scale_surface->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6351 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6352 | expected_scale_surface_draw_transform, |
| 6353 | scale_surface->render_surface()->draw_transform()); |
[email protected] | a52c6ff | 2013-05-04 05:33:15 | [diff] [blame] | 6354 | gfx::Transform expected_scale_surface_layer_draw_transform = |
| 6355 | scale_small_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6356 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform, |
| 6357 | scale_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6358 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6359 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 6360 | // with the screen, and then scaled during drawing. |
| 6361 | gfx::Transform expected_perspective_surface_draw_transform; |
| 6362 | expected_perspective_surface_draw_transform.Translate( |
| 6363 | device_scale_factor * page_scale_factor * |
| 6364 | perspective_surface->position().x(), |
| 6365 | device_scale_factor * page_scale_factor * |
| 6366 | perspective_surface->position().y()); |
| 6367 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 6368 | perspective_matrix); |
| 6369 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 6370 | scale_small_matrix); |
| 6371 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
| 6372 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6373 | expected_perspective_surface_draw_transform, |
| 6374 | perspective_surface->render_surface()->draw_transform()); |
| 6375 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6376 | expected_perspective_surface_layer_draw_transform, |
| 6377 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6378 | } |
| 6379 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6380 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6381 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 6382 | // Verify draw and screen space transforms of layers not in a surface. |
| 6383 | MockContentLayerClient delegate; |
| 6384 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6385 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6386 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6387 | SetLayerPropertiesForTesting(parent.get(), |
| 6388 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6389 | gfx::PointF(), |
| 6390 | gfx::PointF(), |
| 6391 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6392 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6393 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6394 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6395 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 6396 | SetLayerPropertiesForTesting(child.get(), |
| 6397 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6398 | gfx::PointF(), |
| 6399 | gfx::PointF(), |
| 6400 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6401 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6402 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6403 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6404 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6405 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6406 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6407 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6408 | gfx::PointF(), |
| 6409 | gfx::PointF(), |
| 6410 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6411 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6412 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6413 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6414 | parent->AddChild(child); |
| 6415 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6416 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6417 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6418 | host->SetRootLayer(parent); |
| 6419 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6420 | float device_scale_factor = 1.7f; |
| 6421 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6422 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6423 | RenderSurfaceLayerList render_surface_layer_list; |
| 6424 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6425 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 6426 | inputs.device_scale_factor = device_scale_factor; |
| 6427 | inputs.page_scale_factor = page_scale_factor; |
| 6428 | inputs.page_scale_application_layer = parent.get(); |
| 6429 | inputs.can_adjust_raster_scales = true; |
| 6430 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6431 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6432 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6433 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 6434 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6435 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6436 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6437 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6438 | // Verify parent transforms |
| 6439 | gfx::Transform expected_parent_transform; |
| 6440 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6441 | parent->screen_space_transform()); |
| 6442 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6443 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6444 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6445 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6446 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6447 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6448 | gfx::RectF parent_draw_rect = |
| 6449 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 6450 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 6451 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6452 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6453 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6454 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 6455 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 6456 | expected_parent_draw_rect.set_height( |
| 6457 | ceil(expected_parent_draw_rect.height())); |
| 6458 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 6459 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6460 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6461 | // Verify child transforms |
| 6462 | gfx::Transform expected_child_transform; |
| 6463 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6464 | child->draw_transform()); |
| 6465 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6466 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6467 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6468 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6469 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6470 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6471 | gfx::RectF child_draw_rect = |
| 6472 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 6473 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 6474 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6475 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6476 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6477 | expected_child_draw_rect.Scale(device_scale_factor); |
| 6478 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 6479 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 6480 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 6481 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6482 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6483 | // Verify child_no_scale transforms |
| 6484 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 6485 | // All transforms operate on content rects. The child's content rect |
| 6486 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 6487 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 6488 | device_scale_factor); |
| 6489 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6490 | child_no_scale->draw_transform()); |
| 6491 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6492 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6493 | } |
| 6494 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6495 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6496 | MockContentLayerClient delegate; |
| 6497 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6498 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6499 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6500 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6501 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6502 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6503 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6504 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6505 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6506 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6507 | scoped_refptr<Layer> root = Layer::Create(); |
| 6508 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6509 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6510 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6511 | SetLayerPropertiesForTesting(parent.get(), |
| 6512 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6513 | gfx::PointF(), |
| 6514 | gfx::PointF(), |
| 6515 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6516 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6517 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6518 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6519 | scoped_refptr<ContentLayer> child_scale = |
| 6520 | CreateDrawableContentLayer(&delegate); |
| 6521 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6522 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6523 | gfx::PointF(), |
| 6524 | gfx::PointF(2.f, 2.f), |
| 6525 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6526 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6527 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6528 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6529 | scoped_refptr<ContentLayer> child_empty = |
| 6530 | CreateDrawableContentLayer(&delegate); |
| 6531 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6532 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6533 | gfx::PointF(), |
| 6534 | gfx::PointF(2.f, 2.f), |
| 6535 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6536 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6537 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6538 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6539 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6540 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6541 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6542 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6543 | gfx::PointF(), |
| 6544 | gfx::PointF(12.f, 12.f), |
| 6545 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6546 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6547 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6548 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6549 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6550 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6551 | parent->AddChild(child_scale); |
| 6552 | parent->AddChild(child_empty); |
| 6553 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6554 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6555 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6556 | host->SetRootLayer(root); |
| 6557 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6558 | float device_scale_factor = 2.5f; |
| 6559 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6560 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6561 | { |
| 6562 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6563 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6564 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6565 | inputs.device_scale_factor = device_scale_factor; |
| 6566 | inputs.page_scale_factor = page_scale_factor; |
| 6567 | inputs.page_scale_application_layer = root.get(); |
| 6568 | inputs.can_adjust_raster_scales = true; |
| 6569 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6570 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6571 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6572 | initial_parent_scale, parent); |
| 6573 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6574 | initial_parent_scale * initial_child_scale, |
| 6575 | child_scale); |
| 6576 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6577 | initial_parent_scale * initial_child_scale, |
| 6578 | child_empty); |
| 6579 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6580 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6581 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 6582 | // child that can scale its contents should also not need to scale during |
| 6583 | // draw. This shouldn't change if the child has empty bounds. The other |
| 6584 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6585 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 6586 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 6587 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 6588 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 6589 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 6590 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6591 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 6592 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6593 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6594 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6595 | initial_parent_scale * initial_child_scale, |
| 6596 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6597 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6599 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 6600 | // updated using the initial transform as the raster scale. |
| 6601 | device_scale_factor = 2.25f; |
| 6602 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6603 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6604 | { |
| 6605 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6606 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6607 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6608 | inputs.device_scale_factor = device_scale_factor; |
| 6609 | inputs.page_scale_factor = page_scale_factor; |
| 6610 | inputs.page_scale_application_layer = root.get(); |
| 6611 | inputs.can_adjust_raster_scales = true; |
| 6612 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6613 | |
| 6614 | EXPECT_CONTENTS_SCALE_EQ( |
| 6615 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6616 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6617 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6618 | child_scale); |
| 6619 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6620 | initial_parent_scale * initial_child_scale, |
| 6621 | child_empty); |
| 6622 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6623 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6624 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6625 | // 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] | 6626 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6627 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 6628 | second_child_scale / initial_child_scale); |
| 6629 | child_scale->SetTransform(child_scale_matrix); |
| 6630 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6631 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6632 | { |
| 6633 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6634 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6635 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6636 | inputs.device_scale_factor = device_scale_factor; |
| 6637 | inputs.page_scale_factor = page_scale_factor; |
| 6638 | inputs.page_scale_application_layer = root.get(); |
| 6639 | inputs.can_adjust_raster_scales = true; |
| 6640 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6641 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6642 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6643 | initial_parent_scale, |
| 6644 | parent); |
| 6645 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6646 | child_scale); |
| 6647 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6648 | child_empty); |
| 6649 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6650 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6651 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6652 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 6653 | // updated, but still using 1.0 as the raster scale. |
| 6654 | device_scale_factor = 2.75f; |
| 6655 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6656 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6657 | { |
| 6658 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6659 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6660 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6661 | inputs.device_scale_factor = device_scale_factor; |
| 6662 | inputs.page_scale_factor = page_scale_factor; |
| 6663 | inputs.page_scale_application_layer = root.get(); |
| 6664 | inputs.can_adjust_raster_scales = true; |
| 6665 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6666 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6667 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6668 | initial_parent_scale, |
| 6669 | parent); |
| 6670 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6671 | child_scale); |
| 6672 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6673 | child_empty); |
| 6674 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6675 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6676 | } |
| 6677 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6678 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6679 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6680 | MockContentLayerClient delegate; |
| 6681 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6682 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6683 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6684 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6685 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6686 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6687 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6688 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6689 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6690 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6691 | scoped_refptr<Layer> root = Layer::Create(); |
| 6692 | root->SetBounds(gfx::Size(100, 100)); |
| 6693 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6694 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6695 | SetLayerPropertiesForTesting(parent.get(), |
| 6696 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6697 | gfx::PointF(), |
| 6698 | gfx::PointF(), |
| 6699 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6700 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6701 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6702 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6703 | scoped_refptr<ContentLayer> child_scale = |
| 6704 | CreateDrawableContentLayer(&delegate); |
| 6705 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6706 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6707 | gfx::PointF(), |
| 6708 | gfx::PointF(2.f, 2.f), |
| 6709 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6710 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6711 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6712 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6713 | scoped_refptr<ContentLayer> child_empty = |
| 6714 | CreateDrawableContentLayer(&delegate); |
| 6715 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6716 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6717 | gfx::PointF(), |
| 6718 | gfx::PointF(2.f, 2.f), |
| 6719 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6720 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6721 | true); |
| 6722 | |
| 6723 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6724 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6725 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6726 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6727 | gfx::PointF(), |
| 6728 | gfx::PointF(12.f, 12.f), |
| 6729 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6730 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6731 | true); |
| 6732 | |
| 6733 | root->AddChild(parent); |
| 6734 | |
| 6735 | parent->AddChild(child_scale); |
| 6736 | parent->AddChild(child_empty); |
| 6737 | parent->AddChild(child_no_scale); |
| 6738 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6739 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6740 | host->SetRootLayer(root); |
| 6741 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6742 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6743 | |
| 6744 | float device_scale_factor = 2.5f; |
| 6745 | float page_scale_factor = 1.f; |
| 6746 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6747 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6748 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6749 | inputs.device_scale_factor = device_scale_factor; |
| 6750 | inputs.page_scale_factor = page_scale_factor; |
| 6751 | inputs.page_scale_application_layer = root.get(), |
| 6752 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6753 | |
| 6754 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6755 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6756 | child_scale); |
| 6757 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6758 | child_empty); |
| 6759 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6760 | |
| 6761 | // Since the transform scale does not affect contents scale, it should affect |
| 6762 | // the draw transform instead. |
| 6763 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6764 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6765 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6766 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6767 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6768 | child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6769 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6770 | child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6771 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6772 | child_empty->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6773 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6774 | child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6775 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6776 | initial_parent_scale * initial_child_scale, |
| 6777 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6778 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6779 | initial_parent_scale * initial_child_scale, |
| 6780 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6781 | } |
| 6782 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6783 | TEST_F(LayerTreeHostCommonTest, SmallContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6784 | MockContentLayerClient delegate; |
| 6785 | gfx::Transform identity_matrix; |
| 6786 | |
| 6787 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6788 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6789 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 6790 | |
| 6791 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6792 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6793 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 6794 | |
| 6795 | scoped_refptr<Layer> root = Layer::Create(); |
| 6796 | root->SetBounds(gfx::Size(100, 100)); |
| 6797 | |
| 6798 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6799 | SetLayerPropertiesForTesting(parent.get(), |
| 6800 | parent_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6801 | gfx::PointF(), |
| 6802 | gfx::PointF(), |
| 6803 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6804 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6805 | true); |
| 6806 | |
| 6807 | scoped_refptr<ContentLayer> child_scale = |
| 6808 | CreateDrawableContentLayer(&delegate); |
| 6809 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6810 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6811 | gfx::PointF(), |
| 6812 | gfx::PointF(2.f, 2.f), |
| 6813 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6814 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6815 | true); |
| 6816 | |
| 6817 | root->AddChild(parent); |
| 6818 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6819 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6820 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6821 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6822 | host->SetRootLayer(root); |
| 6823 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6824 | float device_scale_factor = 2.5f; |
| 6825 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6826 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6827 | { |
| 6828 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6829 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6830 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6831 | inputs.device_scale_factor = device_scale_factor; |
| 6832 | inputs.page_scale_factor = page_scale_factor; |
| 6833 | inputs.page_scale_application_layer = root.get(); |
| 6834 | inputs.can_adjust_raster_scales = true; |
| 6835 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6836 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6837 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6838 | initial_parent_scale, |
| 6839 | parent); |
| 6840 | // The child's scale is < 1, so we should not save and use that scale |
| 6841 | // factor. |
| 6842 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1, |
| 6843 | child_scale); |
| 6844 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6845 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6846 | // When chilld's total scale becomes >= 1, we should save and use that scale |
| 6847 | // factor. |
| 6848 | child_scale_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6849 | SkMScalar final_child_scale = 0.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6850 | child_scale_matrix.Scale(final_child_scale, final_child_scale); |
| 6851 | child_scale->SetTransform(child_scale_matrix); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6852 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6853 | { |
| 6854 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6855 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6856 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6857 | inputs.device_scale_factor = device_scale_factor; |
| 6858 | inputs.page_scale_factor = page_scale_factor; |
| 6859 | inputs.page_scale_application_layer = root.get(); |
| 6860 | inputs.can_adjust_raster_scales = true; |
| 6861 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6862 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6863 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6864 | initial_parent_scale, |
| 6865 | parent); |
| 6866 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6867 | initial_parent_scale * final_child_scale, |
| 6868 | child_scale); |
| 6869 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6870 | } |
| 6871 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6872 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6873 | MockContentLayerClient delegate; |
| 6874 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6875 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6876 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6877 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6878 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6879 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6880 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6881 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6882 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6883 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6884 | scoped_refptr<Layer> root = Layer::Create(); |
| 6885 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6886 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6887 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6888 | SetLayerPropertiesForTesting(parent.get(), |
| 6889 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6890 | gfx::PointF(), |
| 6891 | gfx::PointF(), |
| 6892 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6893 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6894 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6895 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6896 | scoped_refptr<ContentLayer> surface_scale = |
| 6897 | CreateDrawableContentLayer(&delegate); |
| 6898 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 6899 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6900 | gfx::PointF(), |
| 6901 | gfx::PointF(2.f, 2.f), |
| 6902 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6903 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6904 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6905 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6906 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 6907 | CreateDrawableContentLayer(&delegate); |
| 6908 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 6909 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6910 | gfx::PointF(), |
| 6911 | gfx::PointF(), |
| 6912 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6913 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6914 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6915 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6916 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 6917 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6918 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 6919 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6920 | gfx::PointF(), |
| 6921 | gfx::PointF(), |
| 6922 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6923 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6924 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6925 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6926 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 6927 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6928 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 6929 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6930 | gfx::PointF(), |
| 6931 | gfx::PointF(12.f, 12.f), |
| 6932 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6933 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6934 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6935 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6936 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 6937 | CreateDrawableContentLayer(&delegate); |
| 6938 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 6939 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6940 | gfx::PointF(), |
| 6941 | gfx::PointF(), |
| 6942 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6943 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6944 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6945 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6946 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 6947 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6948 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 6949 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6950 | gfx::PointF(), |
| 6951 | gfx::PointF(), |
| 6952 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6953 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6954 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6955 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6956 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6957 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6958 | parent->AddChild(surface_scale); |
| 6959 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6960 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6961 | surface_scale->SetForceRenderSurface(true); |
| 6962 | surface_scale->AddChild(surface_scale_child_scale); |
| 6963 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6964 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6965 | surface_no_scale->SetForceRenderSurface(true); |
| 6966 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 6967 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6968 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6969 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6970 | host->SetRootLayer(root); |
| 6971 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6972 | SkMScalar device_scale_factor = 5; |
| 6973 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6974 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6975 | RenderSurfaceLayerList render_surface_layer_list; |
| 6976 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6977 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6978 | inputs.device_scale_factor = device_scale_factor; |
| 6979 | inputs.page_scale_factor = page_scale_factor; |
| 6980 | inputs.page_scale_application_layer = root.get(); |
| 6981 | inputs.can_adjust_raster_scales = true; |
| 6982 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6983 | |
| 6984 | EXPECT_CONTENTS_SCALE_EQ( |
| 6985 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6986 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6987 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6988 | surface_scale); |
| 6989 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 6990 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6991 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 6992 | initial_child_scale * initial_child_scale, |
| 6993 | surface_scale_child_scale); |
| 6994 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 6995 | EXPECT_CONTENTS_SCALE_EQ( |
| 6996 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 6997 | initial_child_scale * initial_child_scale, |
| 6998 | surface_no_scale_child_scale); |
| 6999 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7000 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7001 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7002 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 7003 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7004 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7005 | // RenderSurfaces should always be 1:1 with their target. |
| 7006 | EXPECT_FLOAT_EQ( |
| 7007 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7008 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7009 | EXPECT_FLOAT_EQ( |
| 7010 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7011 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7012 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7013 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 7014 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7015 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 7016 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7017 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7018 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 7019 | // to scale during draw. |
| 7020 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7021 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7022 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7023 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7024 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7025 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 7026 | // to be scaled during draw. |
| 7027 | EXPECT_FLOAT_EQ( |
| 7028 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7029 | initial_child_scale * initial_child_scale, |
| 7030 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7031 | EXPECT_FLOAT_EQ( |
| 7032 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7033 | initial_child_scale * initial_child_scale, |
| 7034 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7035 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7036 | // RenderSurfaces should always be 1:1 with their target. |
| 7037 | EXPECT_FLOAT_EQ( |
| 7038 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7039 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7040 | EXPECT_FLOAT_EQ( |
| 7041 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7042 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7043 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7044 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 7045 | // scaled during draw. |
| 7046 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7047 | initial_parent_scale * initial_child_scale, |
| 7048 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7049 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7050 | initial_parent_scale * initial_child_scale, |
| 7051 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7052 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7053 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 7054 | // to scale during draw. |
| 7055 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7056 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7057 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7058 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7059 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7060 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 7061 | // to be scaled during draw. |
| 7062 | EXPECT_FLOAT_EQ( |
| 7063 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7064 | initial_child_scale * initial_child_scale, |
| 7065 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7066 | EXPECT_FLOAT_EQ( |
| 7067 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7068 | initial_child_scale * initial_child_scale, |
| 7069 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7070 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7071 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7072 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7073 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
| 7074 | MockContentLayerClient delegate; |
| 7075 | gfx::Transform identity_matrix; |
| 7076 | |
| 7077 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7078 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7079 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 7080 | |
| 7081 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7082 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7083 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 7084 | |
| 7085 | scoped_refptr<Layer> root = Layer::Create(); |
| 7086 | root->SetBounds(gfx::Size(100, 100)); |
| 7087 | |
| 7088 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7089 | SetLayerPropertiesForTesting(parent.get(), |
| 7090 | parent_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7091 | gfx::PointF(), |
| 7092 | gfx::PointF(), |
| 7093 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7094 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7095 | true); |
| 7096 | |
| 7097 | scoped_refptr<ContentLayer> surface_scale = |
| 7098 | CreateDrawableContentLayer(&delegate); |
| 7099 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 7100 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7101 | gfx::PointF(), |
| 7102 | gfx::PointF(2.f, 2.f), |
| 7103 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7104 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7105 | true); |
| 7106 | |
| 7107 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 7108 | CreateDrawableContentLayer(&delegate); |
| 7109 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 7110 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7111 | gfx::PointF(), |
| 7112 | gfx::PointF(), |
| 7113 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7114 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7115 | true); |
| 7116 | |
| 7117 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 7118 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7119 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 7120 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7121 | gfx::PointF(), |
| 7122 | gfx::PointF(), |
| 7123 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7124 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7125 | true); |
| 7126 | |
| 7127 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 7128 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7129 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 7130 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7131 | gfx::PointF(), |
| 7132 | gfx::PointF(12.f, 12.f), |
| 7133 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7134 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7135 | true); |
| 7136 | |
| 7137 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 7138 | CreateDrawableContentLayer(&delegate); |
| 7139 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 7140 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7141 | gfx::PointF(), |
| 7142 | gfx::PointF(), |
| 7143 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7144 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7145 | true); |
| 7146 | |
| 7147 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 7148 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7149 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 7150 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7151 | gfx::PointF(), |
| 7152 | gfx::PointF(), |
| 7153 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7154 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7155 | true); |
| 7156 | |
| 7157 | root->AddChild(parent); |
| 7158 | |
| 7159 | parent->AddChild(surface_scale); |
| 7160 | parent->AddChild(surface_no_scale); |
| 7161 | |
| 7162 | surface_scale->SetForceRenderSurface(true); |
| 7163 | surface_scale->AddChild(surface_scale_child_scale); |
| 7164 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 7165 | |
| 7166 | surface_no_scale->SetForceRenderSurface(true); |
| 7167 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 7168 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 7169 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7170 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7171 | host->SetRootLayer(root); |
| 7172 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7173 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7174 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7175 | SkMScalar device_scale_factor = 5.0; |
| 7176 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7177 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7178 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7179 | inputs.device_scale_factor = device_scale_factor; |
| 7180 | inputs.page_scale_factor = page_scale_factor; |
| 7181 | inputs.page_scale_application_layer = root.get(); |
| 7182 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7183 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7184 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7185 | parent); |
| 7186 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7187 | surface_scale); |
| 7188 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 7189 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7190 | surface_scale_child_scale); |
| 7191 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 7192 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7193 | surface_no_scale_child_scale); |
| 7194 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 7195 | |
| 7196 | // The parent is scaled up during draw, since its contents are not scaled by |
| 7197 | // the transform hierarchy. |
| 7198 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7199 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7200 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7201 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7202 | |
| 7203 | // The child surface is scaled up during draw since its subtree is not scaled |
| 7204 | // by the transform hierarchy. |
| 7205 | EXPECT_FLOAT_EQ( |
| 7206 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7207 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7208 | EXPECT_FLOAT_EQ( |
| 7209 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7210 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7211 | |
| 7212 | // The surface_scale's RenderSurface is scaled during draw, so the layer does |
| 7213 | // not need to be scaled when drawing into its surface. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7214 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 7215 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7216 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7217 | // The surface_scale_child_scale is scaled when drawing into its surface, |
| 7218 | // since its content bounds are not scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7219 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7220 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7221 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7222 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7223 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7224 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7225 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7226 | // The surface_scale_child_no_scale has a fixed contents scale of 1, so it |
| 7227 | // needs to be scaled by the device and page scale factors, along with the |
| 7228 | // transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7229 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7230 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7231 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7232 | EXPECT_FLOAT_EQ( |
| 7233 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7234 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7235 | |
| 7236 | // The child surface is scaled up during draw since its subtree is not scaled |
| 7237 | // by the transform hierarchy. |
| 7238 | EXPECT_FLOAT_EQ( |
| 7239 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7240 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7241 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7242 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7243 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7244 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7245 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 7246 | // be scaled by the device and page scale factors. Its surface is already |
| 7247 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 7248 | // drawing. |
| 7249 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7250 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7251 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7252 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7253 | |
| 7254 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 7255 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 7256 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7257 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7258 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7259 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7260 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7261 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7262 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7263 | |
| 7264 | // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it |
| 7265 | // needs to be scaled by the device and page scale factors. It also needs to |
| 7266 | // be scaled by any transform heirarchy below its target surface. |
| 7267 | EXPECT_FLOAT_EQ( |
| 7268 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7269 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7270 | EXPECT_FLOAT_EQ( |
| 7271 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7272 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7273 | } |
| 7274 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7275 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7276 | MockContentLayerClient delegate; |
| 7277 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7278 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7279 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7280 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7281 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7282 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7283 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7284 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7285 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7286 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7287 | scoped_refptr<Layer> root = Layer::Create(); |
| 7288 | root->SetBounds(gfx::Size(100, 100)); |
| 7289 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7290 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7291 | SetLayerPropertiesForTesting(parent.get(), |
| 7292 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7293 | gfx::PointF(), |
| 7294 | gfx::PointF(), |
| 7295 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7296 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7297 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7298 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7299 | scoped_refptr<ContentLayer> child_scale = |
| 7300 | CreateDrawableContentLayer(&delegate); |
| 7301 | SetLayerPropertiesForTesting(child_scale.get(), |
| 7302 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7303 | gfx::PointF(), |
| 7304 | gfx::PointF(2.f, 2.f), |
| 7305 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7306 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7307 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7308 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7309 | root->AddChild(parent); |
| 7310 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7311 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7312 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7313 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7314 | host->SetRootLayer(root); |
| 7315 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7316 | // Now put an animating transform on child. |
| 7317 | int animation_id = AddAnimatedTransformToController( |
| 7318 | child_scale->layer_animation_controller(), 10.0, 30, 0); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7319 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7320 | { |
| 7321 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7322 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7323 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7324 | inputs.can_adjust_raster_scales = true; |
| 7325 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7326 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7327 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 7328 | // The layers with animating transforms should not compute a contents scale |
| 7329 | // other than 1 until they finish animating. |
| 7330 | EXPECT_CONTENTS_SCALE_EQ(1, child_scale); |
| 7331 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7332 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7333 | // Remove the animation, now it can save a raster scale. |
| 7334 | child_scale->layer_animation_controller()->RemoveAnimation(animation_id); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7335 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7336 | { |
| 7337 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7338 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7339 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7340 | inputs.can_adjust_raster_scales = true; |
| 7341 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7342 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7343 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 7344 | // The layers with animating transforms should not compute a contents scale |
| 7345 | // other than 1 until they finish animating. |
| 7346 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale, |
| 7347 | child_scale); |
| 7348 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7349 | } |
| 7350 | |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 7351 | TEST_F(LayerTreeHostCommonTest, |
| 7352 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 7353 | MockContentLayerClient delegate; |
| 7354 | scoped_refptr<Layer> root = Layer::Create(); |
| 7355 | scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 7356 | root->AddChild(child); |
| 7357 | |
| 7358 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7359 | host->SetRootLayer(root); |
| 7360 | |
| 7361 | gfx::Transform identity_matrix; |
| 7362 | SetLayerPropertiesForTesting(root.get(), |
| 7363 | identity_matrix, |
| 7364 | gfx::PointF(), |
| 7365 | gfx::PointF(), |
| 7366 | gfx::Size(100, 100), |
| 7367 | true, |
| 7368 | false); |
| 7369 | SetLayerPropertiesForTesting(child.get(), |
| 7370 | identity_matrix, |
| 7371 | gfx::PointF(), |
| 7372 | gfx::PointF(), |
| 7373 | gfx::Size(100, 100), |
| 7374 | true, |
| 7375 | false); |
| 7376 | |
| 7377 | root->reset_needs_push_properties_for_testing(); |
| 7378 | child->reset_needs_push_properties_for_testing(); |
| 7379 | |
| 7380 | // This will change both layers' content bounds. |
| 7381 | ExecuteCalculateDrawProperties(root.get()); |
| 7382 | EXPECT_TRUE(root->needs_push_properties()); |
| 7383 | EXPECT_TRUE(child->needs_push_properties()); |
| 7384 | |
| 7385 | root->reset_needs_push_properties_for_testing(); |
| 7386 | child->reset_needs_push_properties_for_testing(); |
| 7387 | |
| 7388 | // This will change only the child layer's contents scale and content bounds, |
| 7389 | // since the root layer is not a ContentsScalingLayer. |
| 7390 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 7391 | EXPECT_FALSE(root->needs_push_properties()); |
| 7392 | EXPECT_TRUE(child->needs_push_properties()); |
| 7393 | |
| 7394 | root->reset_needs_push_properties_for_testing(); |
| 7395 | child->reset_needs_push_properties_for_testing(); |
| 7396 | |
| 7397 | // This will not change either layer's contents scale or content bounds. |
| 7398 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 7399 | EXPECT_FALSE(root->needs_push_properties()); |
| 7400 | EXPECT_FALSE(child->needs_push_properties()); |
| 7401 | } |
| 7402 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7403 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7404 | MockContentLayerClient delegate; |
| 7405 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7406 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7407 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7408 | SetLayerPropertiesForTesting(parent.get(), |
| 7409 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7410 | gfx::PointF(), |
| 7411 | gfx::PointF(), |
| 7412 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7413 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7414 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7415 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7416 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 7417 | SetLayerPropertiesForTesting(child.get(), |
| 7418 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7419 | gfx::PointF(), |
| 7420 | gfx::PointF(2.f, 2.f), |
| 7421 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7422 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7423 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7424 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7425 | gfx::Transform replica_transform; |
| 7426 | replica_transform.Scale(1.0, -1.0); |
| 7427 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 7428 | SetLayerPropertiesForTesting(replica.get(), |
| 7429 | replica_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7430 | gfx::PointF(), |
| 7431 | gfx::PointF(2.f, 2.f), |
| 7432 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7433 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7434 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7435 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7436 | // This layer should end up in the same surface as child, with the same draw |
| 7437 | // and screen space transforms. |
| 7438 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 7439 | CreateDrawableContentLayer(&delegate); |
| 7440 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 7441 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7442 | gfx::PointF(), |
| 7443 | gfx::PointF(), |
| 7444 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7445 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7446 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7447 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7448 | parent->AddChild(child); |
| 7449 | child->AddChild(duplicate_child_non_owner); |
| 7450 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7451 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7452 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7453 | host->SetRootLayer(parent); |
| 7454 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7455 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7456 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7457 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7458 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7459 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 7460 | inputs.device_scale_factor = device_scale_factor; |
| 7461 | inputs.can_adjust_raster_scales = true; |
| 7462 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7463 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7464 | // We should have two render surfaces. The root's render surface and child's |
| 7465 | // render surface (it needs one because it has a replica layer). |
| 7466 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7467 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7468 | gfx::Transform expected_parent_transform; |
| 7469 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 7470 | parent->screen_space_transform()); |
| 7471 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 7472 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7473 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7474 | gfx::Transform expected_draw_transform; |
| 7475 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 7476 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7477 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7478 | gfx::Transform expected_screen_space_transform; |
| 7479 | expected_screen_space_transform.Translate( |
| 7480 | device_scale_factor * child->position().x(), |
| 7481 | device_scale_factor * child->position().y()); |
| 7482 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 7483 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7484 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7485 | gfx::Transform expected_duplicate_child_draw_transform = |
| 7486 | child->draw_transform(); |
| 7487 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 7488 | duplicate_child_non_owner->draw_transform()); |
| 7489 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7490 | child->screen_space_transform(), |
| 7491 | duplicate_child_non_owner->screen_space_transform()); |
| 7492 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 7493 | duplicate_child_non_owner->drawable_content_rect()); |
| 7494 | EXPECT_EQ(child->content_bounds(), |
| 7495 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7496 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7497 | gfx::Transform expected_render_surface_draw_transform; |
| 7498 | expected_render_surface_draw_transform.Translate( |
| 7499 | device_scale_factor * child->position().x(), |
| 7500 | device_scale_factor * child->position().y()); |
| 7501 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 7502 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7503 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7504 | gfx::Transform expected_surface_draw_transform; |
| 7505 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 7506 | device_scale_factor * 2.f); |
| 7507 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 7508 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7509 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7510 | gfx::Transform expected_surface_screen_space_transform; |
| 7511 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 7512 | device_scale_factor * 2.f); |
| 7513 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7514 | expected_surface_screen_space_transform, |
| 7515 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7516 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7517 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7518 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 7519 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 7520 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7521 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7522 | expected_replica_draw_transform, |
| 7523 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7524 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7525 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7526 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 7527 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 7528 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7529 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7530 | expected_replica_screen_space_transform, |
| 7531 | child->render_surface()->replica_screen_space_transform()); |
| 7532 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7533 | expected_replica_screen_space_transform, |
| 7534 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7535 | } |
| 7536 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7537 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7538 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 7539 | MockContentLayerClient delegate; |
| 7540 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7541 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7542 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7543 | SetLayerPropertiesForTesting(parent.get(), |
| 7544 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7545 | gfx::PointF(), |
| 7546 | gfx::PointF(), |
| 7547 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7548 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7549 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7550 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7551 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 7552 | SetLayerPropertiesForTesting(child.get(), |
| 7553 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7554 | gfx::PointF(), |
| 7555 | gfx::PointF(), |
| 7556 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7557 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7558 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7559 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7560 | gfx::Transform replica_transform; |
| 7561 | replica_transform.Scale(1.0, -1.0); |
| 7562 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 7563 | SetLayerPropertiesForTesting(replica.get(), |
| 7564 | replica_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7565 | gfx::PointF(), |
| 7566 | gfx::PointF(), |
| 7567 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7568 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7569 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7570 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7571 | // This layer should end up in the same surface as child, with the same draw |
| 7572 | // and screen space transforms. |
| 7573 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 7574 | CreateDrawableContentLayer(&delegate); |
| 7575 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 7576 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7577 | gfx::PointF(), |
| 7578 | gfx::PointF(), |
| 7579 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7580 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7581 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7582 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7583 | parent->AddChild(child); |
| 7584 | child->AddChild(duplicate_child_non_owner); |
| 7585 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7586 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7587 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7588 | host->SetRootLayer(parent); |
| 7589 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 7590 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7591 | |
| 7592 | RenderSurfaceLayerList render_surface_layer_list; |
| 7593 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7594 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 7595 | inputs.device_scale_factor = device_scale_factor; |
| 7596 | inputs.can_adjust_raster_scales = true; |
| 7597 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7599 | // We should have two render surfaces. The root's render surface and child's |
| 7600 | // render surface (it needs one because it has a replica layer). |
| 7601 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7602 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7603 | gfx::Transform identity_transform; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7604 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7605 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7606 | parent->screen_space_transform()); |
| 7607 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform()); |
| 7608 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform()); |
| 7609 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7610 | child->screen_space_transform()); |
| 7611 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7612 | duplicate_child_non_owner->draw_transform()); |
| 7613 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7614 | identity_transform, duplicate_child_non_owner->screen_space_transform()); |
| 7615 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 7616 | duplicate_child_non_owner->drawable_content_rect()); |
| 7617 | EXPECT_EQ(child->content_bounds(), |
| 7618 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7619 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7620 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7621 | child->render_surface()->draw_transform()); |
| 7622 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7623 | child->render_surface()->draw_transform()); |
| 7624 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7625 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7626 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7627 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7628 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7629 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7630 | expected_replica_draw_transform, |
| 7631 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7632 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7633 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7634 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7635 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7636 | expected_replica_screen_space_transform, |
| 7637 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7638 | } |
| 7639 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7640 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7641 | scoped_refptr<Layer> root = Layer::Create(); |
| 7642 | scoped_refptr<Layer> child = Layer::Create(); |
| 7643 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 7644 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 7645 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7646 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7647 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 7648 | child->AddChild(grand_child.get()); |
| 7649 | child->SetMaskLayer(mask_layer.get()); |
| 7650 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7651 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7652 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7653 | host->SetRootLayer(root); |
| 7654 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7655 | int nonexistent_id = -1; |
| 7656 | EXPECT_EQ(root, |
| 7657 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
| 7658 | EXPECT_EQ(child, |
| 7659 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 7660 | EXPECT_EQ( |
| 7661 | grand_child, |
| 7662 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 7663 | EXPECT_EQ( |
| 7664 | mask_layer, |
| 7665 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 7666 | EXPECT_EQ( |
| 7667 | replica_layer, |
| 7668 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 7669 | EXPECT_EQ( |
| 7670 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7671 | } |
| 7672 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7673 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7674 | scoped_refptr<Layer> root = Layer::Create(); |
| 7675 | scoped_refptr<Layer> child = Layer::Create(); |
| 7676 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 7677 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7678 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7679 | const gfx::Transform identity_matrix; |
| 7680 | SetLayerPropertiesForTesting(root.get(), |
| 7681 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7682 | gfx::PointF(), |
| 7683 | gfx::PointF(), |
| 7684 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7685 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7686 | false); |
| 7687 | SetLayerPropertiesForTesting(child.get(), |
| 7688 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7689 | gfx::PointF(), |
| 7690 | gfx::PointF(), |
| 7691 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7692 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7693 | false); |
| 7694 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7695 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7696 | gfx::PointF(), |
| 7697 | gfx::PointF(), |
| 7698 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7699 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7700 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7701 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7702 | root->AddChild(child); |
| 7703 | child->AddChild(grand_child); |
| 7704 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7705 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7706 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7707 | host->SetRootLayer(root); |
| 7708 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7709 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7711 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7712 | } |
| 7713 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7714 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7715 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7716 | TestSharedBitmapManager shared_bitmap_manager; |
| 7717 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7718 | host_impl.CreatePendingTree(); |
| 7719 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 7720 | |
| 7721 | const gfx::Transform identity_matrix; |
| 7722 | SetLayerPropertiesForTesting(root.get(), |
| 7723 | identity_matrix, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7724 | gfx::PointF(), |
| 7725 | gfx::PointF(), |
| 7726 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7727 | true, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7728 | false); |
| 7729 | root->SetDrawsContent(true); |
| 7730 | |
| 7731 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 7732 | SetLayerPropertiesForTesting(child.get(), |
| 7733 | identity_matrix, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7734 | gfx::PointF(), |
| 7735 | gfx::PointF(), |
| 7736 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7737 | true, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7738 | false); |
| 7739 | child->SetDrawsContent(true); |
| 7740 | child->SetOpacity(0.0f); |
| 7741 | |
| 7742 | // Add opacity animation. |
| 7743 | AddOpacityTransitionToController( |
| 7744 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 7745 | |
| 7746 | root->AddChild(child.Pass()); |
| 7747 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7748 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7749 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7750 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7751 | inputs.can_adjust_raster_scales = true; |
| 7752 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7753 | |
| 7754 | // We should have one render surface and two layers. The child |
| 7755 | // layer should be included even though it is transparent. |
| 7756 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 7757 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 7758 | } |
| 7759 | |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7760 | typedef std::tr1::tuple<bool, bool> LCDTextTestParam; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7761 | class LCDTextTest |
| 7762 | : public LayerTreeHostCommonTestBase, |
| 7763 | public testing::TestWithParam<LCDTextTestParam> { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7764 | protected: |
| 7765 | virtual void SetUp() { |
| 7766 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7767 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7768 | root_ = Layer::Create(); |
| 7769 | child_ = Layer::Create(); |
| 7770 | grand_child_ = Layer::Create(); |
| 7771 | child_->AddChild(grand_child_.get()); |
| 7772 | root_->AddChild(child_.get()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7773 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7774 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7775 | SetLayerPropertiesForTesting(root_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7776 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7777 | gfx::PointF(), |
| 7778 | gfx::PointF(), |
| 7779 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7780 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7781 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7782 | SetLayerPropertiesForTesting(child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7783 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7784 | gfx::PointF(), |
| 7785 | gfx::PointF(), |
| 7786 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7787 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7788 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7789 | SetLayerPropertiesForTesting(grand_child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7790 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7791 | gfx::PointF(), |
| 7792 | gfx::PointF(), |
| 7793 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7794 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7795 | false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7796 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7797 | child_->SetForceRenderSurface(std::tr1::get<1>(GetParam())); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7798 | |
| 7799 | host_ = FakeLayerTreeHost::Create(); |
| 7800 | host_->SetRootLayer(root_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7801 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7802 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7803 | bool can_use_lcd_text_; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7804 | scoped_ptr<FakeLayerTreeHost> host_; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7805 | scoped_refptr<Layer> root_; |
| 7806 | scoped_refptr<Layer> child_; |
| 7807 | scoped_refptr<Layer> grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7808 | }; |
| 7809 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7810 | TEST_P(LCDTextTest, CanUseLCDText) { |
| 7811 | // Case 1: Identity transform. |
| 7812 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7813 | ExecuteCalculateDrawProperties( |
| 7814 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7815 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7816 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7817 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7818 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7819 | // Case 2: Integral translation. |
| 7820 | gfx::Transform integral_translation; |
| 7821 | integral_translation.Translate(1.0, 2.0); |
| 7822 | child_->SetTransform(integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7823 | ExecuteCalculateDrawProperties( |
| 7824 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7825 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7826 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7827 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7828 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7829 | // Case 3: Non-integral translation. |
| 7830 | gfx::Transform non_integral_translation; |
| 7831 | non_integral_translation.Translate(1.5, 2.5); |
| 7832 | child_->SetTransform(non_integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7833 | ExecuteCalculateDrawProperties( |
| 7834 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7835 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7836 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7837 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7838 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7839 | // Case 4: Rotation. |
| 7840 | gfx::Transform rotation; |
| 7841 | rotation.Rotate(10.0); |
| 7842 | child_->SetTransform(rotation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7843 | ExecuteCalculateDrawProperties( |
| 7844 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7845 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7846 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7847 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7848 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7849 | // Case 5: Scale. |
| 7850 | gfx::Transform scale; |
| 7851 | scale.Scale(2.0, 2.0); |
| 7852 | child_->SetTransform(scale); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7853 | ExecuteCalculateDrawProperties( |
| 7854 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7855 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7856 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7857 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7858 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7859 | // Case 6: Skew. |
| 7860 | gfx::Transform skew; |
| 7861 | skew.SkewX(10.0); |
| 7862 | child_->SetTransform(skew); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7863 | ExecuteCalculateDrawProperties( |
| 7864 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7865 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7866 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7867 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7868 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7869 | // Case 7: Translucent. |
| 7870 | child_->SetTransform(identity_matrix); |
| 7871 | child_->SetOpacity(0.5f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7872 | ExecuteCalculateDrawProperties( |
| 7873 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7874 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7875 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7876 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7877 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7878 | // Case 8: Sanity check: restore transform and opacity. |
| 7879 | child_->SetTransform(identity_matrix); |
| 7880 | child_->SetOpacity(1.f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7881 | ExecuteCalculateDrawProperties( |
| 7882 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7883 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7884 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7885 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7886 | } |
| 7887 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 7888 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7889 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7890 | ExecuteCalculateDrawProperties( |
| 7891 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7892 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7893 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7894 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7895 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7896 | // Add opacity animation. |
| 7897 | child_->SetOpacity(0.9f); |
| 7898 | AddOpacityTransitionToController( |
| 7899 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7900 | |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7901 | ExecuteCalculateDrawProperties( |
| 7902 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7903 | // Text AA should not be adjusted while animation is active. |
| 7904 | // Make sure LCD text AA setting remains unchanged. |
| 7905 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7906 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7907 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7908 | } |
| 7909 | |
| 7910 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 7911 | LCDTextTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7912 | testing::Combine(testing::Bool(), testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7913 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7914 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7915 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7916 | TestSharedBitmapManager shared_bitmap_manager; |
| 7917 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7918 | host_impl.CreatePendingTree(); |
| 7919 | const gfx::Transform identity_matrix; |
| 7920 | |
| 7921 | scoped_refptr<Layer> root = Layer::Create(); |
| 7922 | SetLayerPropertiesForTesting(root.get(), |
| 7923 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7924 | gfx::PointF(), |
| 7925 | gfx::PointF(), |
| 7926 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7927 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7928 | false); |
| 7929 | root->SetIsDrawable(true); |
| 7930 | |
| 7931 | scoped_refptr<Layer> child = Layer::Create(); |
| 7932 | SetLayerPropertiesForTesting(child.get(), |
| 7933 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7934 | gfx::PointF(), |
| 7935 | gfx::PointF(), |
| 7936 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7937 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7938 | false); |
| 7939 | child->SetIsDrawable(true); |
| 7940 | |
| 7941 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 7942 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7943 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7944 | gfx::PointF(), |
| 7945 | gfx::PointF(), |
| 7946 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7947 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7948 | false); |
| 7949 | grand_child->SetIsDrawable(true); |
| 7950 | grand_child->SetHideLayerAndSubtree(true); |
| 7951 | |
| 7952 | child->AddChild(grand_child); |
| 7953 | root->AddChild(child); |
| 7954 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7955 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7956 | host->SetRootLayer(root); |
| 7957 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7958 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7959 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7960 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7961 | inputs.can_adjust_raster_scales = true; |
| 7962 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7963 | |
| 7964 | // We should have one render surface and two layers. The grand child has |
| 7965 | // hidden itself. |
| 7966 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 7967 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7968 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 7969 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7970 | } |
| 7971 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7972 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7973 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7974 | TestSharedBitmapManager shared_bitmap_manager; |
| 7975 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7976 | host_impl.CreatePendingTree(); |
| 7977 | const gfx::Transform identity_matrix; |
| 7978 | |
| 7979 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 7980 | SetLayerPropertiesForTesting(root.get(), |
| 7981 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7982 | gfx::PointF(), |
| 7983 | gfx::PointF(), |
| 7984 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7985 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7986 | false); |
| 7987 | root->SetDrawsContent(true); |
| 7988 | |
| 7989 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 7990 | SetLayerPropertiesForTesting(child.get(), |
| 7991 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7992 | gfx::PointF(), |
| 7993 | gfx::PointF(), |
| 7994 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7995 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7996 | false); |
| 7997 | child->SetDrawsContent(true); |
| 7998 | |
| 7999 | scoped_ptr<LayerImpl> grand_child = |
| 8000 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8001 | SetLayerPropertiesForTesting(grand_child.get(), |
| 8002 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8003 | gfx::PointF(), |
| 8004 | gfx::PointF(), |
| 8005 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8006 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8007 | false); |
| 8008 | grand_child->SetDrawsContent(true); |
| 8009 | grand_child->SetHideLayerAndSubtree(true); |
| 8010 | |
| 8011 | child->AddChild(grand_child.Pass()); |
| 8012 | root->AddChild(child.Pass()); |
| 8013 | |
| 8014 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8015 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8016 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8017 | inputs.can_adjust_raster_scales = true; |
| 8018 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8019 | |
| 8020 | // We should have one render surface and two layers. The grand child has |
| 8021 | // hidden itself. |
| 8022 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 8023 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8024 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 8025 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8026 | } |
| 8027 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8028 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8029 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8030 | TestSharedBitmapManager shared_bitmap_manager; |
| 8031 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8032 | host_impl.CreatePendingTree(); |
| 8033 | const gfx::Transform identity_matrix; |
| 8034 | |
| 8035 | scoped_refptr<Layer> root = Layer::Create(); |
| 8036 | SetLayerPropertiesForTesting(root.get(), |
| 8037 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8038 | gfx::PointF(), |
| 8039 | gfx::PointF(), |
| 8040 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8041 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8042 | false); |
| 8043 | root->SetIsDrawable(true); |
| 8044 | |
| 8045 | scoped_refptr<Layer> child = Layer::Create(); |
| 8046 | SetLayerPropertiesForTesting(child.get(), |
| 8047 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8048 | gfx::PointF(), |
| 8049 | gfx::PointF(), |
| 8050 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8051 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8052 | false); |
| 8053 | child->SetIsDrawable(true); |
| 8054 | child->SetHideLayerAndSubtree(true); |
| 8055 | |
| 8056 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 8057 | SetLayerPropertiesForTesting(grand_child.get(), |
| 8058 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8059 | gfx::PointF(), |
| 8060 | gfx::PointF(), |
| 8061 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8062 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8063 | false); |
| 8064 | grand_child->SetIsDrawable(true); |
| 8065 | |
| 8066 | child->AddChild(grand_child); |
| 8067 | root->AddChild(child); |
| 8068 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8069 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8070 | host->SetRootLayer(root); |
| 8071 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8072 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8073 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8074 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8075 | inputs.can_adjust_raster_scales = true; |
| 8076 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8077 | |
| 8078 | // We should have one render surface and one layers. The child has |
| 8079 | // hidden itself and the grand child. |
| 8080 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 8081 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8082 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8083 | } |
| 8084 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8085 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8086 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8087 | TestSharedBitmapManager shared_bitmap_manager; |
| 8088 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8089 | host_impl.CreatePendingTree(); |
| 8090 | const gfx::Transform identity_matrix; |
| 8091 | |
| 8092 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8093 | SetLayerPropertiesForTesting(root.get(), |
| 8094 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8095 | gfx::PointF(), |
| 8096 | gfx::PointF(), |
| 8097 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8098 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8099 | false); |
| 8100 | root->SetDrawsContent(true); |
| 8101 | |
| 8102 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8103 | SetLayerPropertiesForTesting(child.get(), |
| 8104 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8105 | gfx::PointF(), |
| 8106 | gfx::PointF(), |
| 8107 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8108 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8109 | false); |
| 8110 | child->SetDrawsContent(true); |
| 8111 | child->SetHideLayerAndSubtree(true); |
| 8112 | |
| 8113 | scoped_ptr<LayerImpl> grand_child = |
| 8114 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8115 | SetLayerPropertiesForTesting(grand_child.get(), |
| 8116 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8117 | gfx::PointF(), |
| 8118 | gfx::PointF(), |
| 8119 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8120 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8121 | false); |
| 8122 | grand_child->SetDrawsContent(true); |
| 8123 | |
| 8124 | child->AddChild(grand_child.Pass()); |
| 8125 | root->AddChild(child.Pass()); |
| 8126 | |
| 8127 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8128 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8129 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8130 | inputs.can_adjust_raster_scales = true; |
| 8131 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8132 | |
| 8133 | // We should have one render surface and one layers. The child has |
| 8134 | // hidden itself and the grand child. |
| 8135 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 8136 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8137 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8138 | } |
| 8139 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8140 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 8141 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8142 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8143 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8144 | TestSharedBitmapManager shared_bitmap_manager; |
| 8145 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8146 | host_impl.CreatePendingTree(); |
| 8147 | const gfx::Transform identity_matrix; |
| 8148 | |
| 8149 | scoped_refptr<Layer> root = Layer::Create(); |
| 8150 | SetLayerPropertiesForTesting(root.get(), |
| 8151 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8152 | gfx::PointF(), |
| 8153 | gfx::PointF(), |
| 8154 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8155 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8156 | false); |
| 8157 | root->SetIsDrawable(true); |
| 8158 | |
| 8159 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(); |
| 8160 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 8161 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8162 | gfx::PointF(), |
| 8163 | gfx::PointF(), |
| 8164 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8165 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8166 | false); |
| 8167 | copy_grand_parent->SetIsDrawable(true); |
| 8168 | |
| 8169 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 8170 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 8171 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8172 | gfx::PointF(), |
| 8173 | gfx::PointF(), |
| 8174 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8175 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8176 | false); |
| 8177 | copy_parent->SetIsDrawable(true); |
| 8178 | copy_parent->SetForceRenderSurface(true); |
| 8179 | |
| 8180 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 8181 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 8182 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8183 | gfx::PointF(), |
| 8184 | gfx::PointF(), |
| 8185 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8186 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8187 | false); |
| 8188 | copy_layer->SetIsDrawable(true); |
| 8189 | |
| 8190 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 8191 | SetLayerPropertiesForTesting(copy_child.get(), |
| 8192 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8193 | gfx::PointF(), |
| 8194 | gfx::PointF(), |
| 8195 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8196 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8197 | false); |
| 8198 | copy_child->SetIsDrawable(true); |
| 8199 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8200 | scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); |
| 8201 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 8202 | identity_matrix, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8203 | gfx::PointF(), |
| 8204 | gfx::PointF(), |
| 8205 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8206 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8207 | false); |
| 8208 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 8209 | |
| 8210 | scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); |
| 8211 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 8212 | identity_matrix, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8213 | gfx::PointF(), |
| 8214 | gfx::PointF(), |
| 8215 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8216 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8217 | false); |
| 8218 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 8219 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8220 | copy_layer->AddChild(copy_child); |
| 8221 | copy_parent->AddChild(copy_layer); |
| 8222 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8223 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8224 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8225 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8226 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8227 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8228 | host->SetRootLayer(root); |
| 8229 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8230 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 8231 | // hidden subtree on copy_layer. |
| 8232 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8233 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 8234 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8235 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 8236 | base::Bind(&EmptyCopyOutputCallback))); |
| 8237 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 8238 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8239 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8240 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8241 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8242 | inputs.can_adjust_raster_scales = true; |
| 8243 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8244 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8245 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 8246 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 8247 | layer_or_descendant_has_copy_request); |
| 8248 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 8249 | layer_or_descendant_has_copy_request); |
| 8250 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 8251 | layer_or_descendant_has_copy_request); |
| 8252 | EXPECT_FALSE(copy_child->draw_properties(). |
| 8253 | layer_or_descendant_has_copy_request); |
| 8254 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 8255 | layer_or_descendant_has_copy_request); |
| 8256 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 8257 | layer_or_descendant_has_copy_request); |
| 8258 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8259 | // We should have three render surfaces, one for the root, one for the parent |
| 8260 | // since it owns a surface, and one for the copy_layer. |
| 8261 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8262 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 8263 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 8264 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8265 | |
| 8266 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8267 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 8268 | // will appear since something in its subtree needs to be drawn for a copy |
| 8269 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8270 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8271 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 8272 | EXPECT_EQ(copy_parent->id(), |
| 8273 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8274 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 8275 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8276 | // appear in its list, since it needs to be drawn for the copy request. |
| 8277 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 8278 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8279 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8280 | |
| 8281 | // The copy_layer's render surface should have two contributing layers. |
| 8282 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 8283 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8284 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8285 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8286 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8287 | } |
| 8288 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8289 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8290 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8291 | TestSharedBitmapManager shared_bitmap_manager; |
| 8292 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8293 | host_impl.CreatePendingTree(); |
| 8294 | const gfx::Transform identity_matrix; |
| 8295 | |
| 8296 | scoped_refptr<Layer> root = Layer::Create(); |
| 8297 | SetLayerPropertiesForTesting(root.get(), |
| 8298 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8299 | gfx::PointF(), |
| 8300 | gfx::PointF(), |
| 8301 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8302 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8303 | false); |
| 8304 | root->SetIsDrawable(true); |
| 8305 | |
| 8306 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 8307 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 8308 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8309 | gfx::PointF(), |
| 8310 | gfx::PointF(), |
| 8311 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8312 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8313 | false); |
| 8314 | copy_parent->SetIsDrawable(true); |
| 8315 | copy_parent->SetMasksToBounds(true); |
| 8316 | |
| 8317 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 8318 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 8319 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8320 | gfx::PointF(), |
| 8321 | gfx::PointF(), |
| 8322 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8323 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8324 | false); |
| 8325 | copy_layer->SetIsDrawable(true); |
| 8326 | |
| 8327 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 8328 | SetLayerPropertiesForTesting(copy_child.get(), |
| 8329 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8330 | gfx::PointF(), |
| 8331 | gfx::PointF(), |
| 8332 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8333 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8334 | false); |
| 8335 | copy_child->SetIsDrawable(true); |
| 8336 | |
| 8337 | copy_layer->AddChild(copy_child); |
| 8338 | copy_parent->AddChild(copy_layer); |
| 8339 | root->AddChild(copy_parent); |
| 8340 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8341 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8342 | host->SetRootLayer(root); |
| 8343 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8344 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 8345 | base::Bind(&EmptyCopyOutputCallback))); |
| 8346 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 8347 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8348 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8349 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8350 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8351 | inputs.can_adjust_raster_scales = true; |
| 8352 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8353 | |
| 8354 | // We should have one render surface, as the others are clipped out. |
| 8355 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8356 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8357 | |
| 8358 | // The root render surface should only have 1 contributing layer, since the |
| 8359 | // other layers are empty/clipped away. |
| 8360 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8361 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8362 | } |
| 8363 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8364 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 8365 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8366 | TestSharedBitmapManager shared_bitmap_manager; |
| 8367 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8368 | host_impl.CreatePendingTree(); |
| 8369 | const gfx::Transform identity_matrix; |
| 8370 | |
| 8371 | scoped_refptr<Layer> root = Layer::Create(); |
| 8372 | SetLayerPropertiesForTesting(root.get(), |
| 8373 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8374 | gfx::PointF(), |
| 8375 | gfx::PointF(), |
| 8376 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8377 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8378 | false); |
| 8379 | root->SetIsDrawable(true); |
| 8380 | |
| 8381 | // The surface is moved slightly outside of the viewport. |
| 8382 | scoped_refptr<Layer> surface = Layer::Create(); |
| 8383 | SetLayerPropertiesForTesting(surface.get(), |
| 8384 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8385 | gfx::PointF(), |
| 8386 | gfx::PointF(-10, -20), |
| 8387 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8388 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8389 | false); |
| 8390 | surface->SetForceRenderSurface(true); |
| 8391 | |
| 8392 | scoped_refptr<Layer> surface_child = Layer::Create(); |
| 8393 | SetLayerPropertiesForTesting(surface_child.get(), |
| 8394 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8395 | gfx::PointF(), |
| 8396 | gfx::PointF(), |
| 8397 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8398 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8399 | false); |
| 8400 | surface_child->SetIsDrawable(true); |
| 8401 | |
| 8402 | surface->AddChild(surface_child); |
| 8403 | root->AddChild(surface); |
| 8404 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8405 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8406 | host->SetRootLayer(root); |
| 8407 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8408 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8409 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8410 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8411 | inputs.can_adjust_raster_scales = true; |
| 8412 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8413 | |
| 8414 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 8415 | // the viewport. |
| 8416 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 8417 | surface_child->visible_content_rect().ToString()); |
| 8418 | } |
| 8419 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8420 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 8421 | // Ensure that a transform between the layer and its render surface is not a |
| 8422 | // problem. Constructs the following layer tree. |
| 8423 | // |
| 8424 | // root (a render surface) |
| 8425 | // + render_surface |
| 8426 | // + clip_parent (scaled) |
| 8427 | // + intervening_clipping_layer |
| 8428 | // + clip_child |
| 8429 | // |
| 8430 | // The render surface should be resized correctly and the clip child should |
| 8431 | // inherit the right clip rect. |
| 8432 | scoped_refptr<Layer> root = Layer::Create(); |
| 8433 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 8434 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8435 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8436 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8437 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8438 | |
| 8439 | root->AddChild(render_surface); |
| 8440 | render_surface->AddChild(clip_parent); |
| 8441 | clip_parent->AddChild(intervening); |
| 8442 | intervening->AddChild(clip_child); |
| 8443 | |
| 8444 | clip_child->SetClipParent(clip_parent.get()); |
| 8445 | |
| 8446 | intervening->SetMasksToBounds(true); |
| 8447 | clip_parent->SetMasksToBounds(true); |
| 8448 | |
| 8449 | render_surface->SetForceRenderSurface(true); |
| 8450 | |
| 8451 | gfx::Transform scale_transform; |
| 8452 | scale_transform.Scale(2, 2); |
| 8453 | |
| 8454 | gfx::Transform identity_transform; |
| 8455 | |
| 8456 | SetLayerPropertiesForTesting(root.get(), |
| 8457 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8458 | gfx::PointF(), |
| 8459 | gfx::PointF(), |
| 8460 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8461 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8462 | false); |
| 8463 | SetLayerPropertiesForTesting(render_surface.get(), |
| 8464 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8465 | gfx::PointF(), |
| 8466 | gfx::PointF(), |
| 8467 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8468 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8469 | false); |
| 8470 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8471 | scale_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8472 | gfx::PointF(), |
| 8473 | gfx::PointF(1.f, 1.f), |
| 8474 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8475 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8476 | false); |
| 8477 | SetLayerPropertiesForTesting(intervening.get(), |
| 8478 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8479 | gfx::PointF(), |
| 8480 | gfx::PointF(1.f, 1.f), |
| 8481 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8482 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8483 | false); |
| 8484 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8485 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8486 | gfx::PointF(), |
| 8487 | gfx::PointF(1.f, 1.f), |
| 8488 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8489 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8490 | false); |
| 8491 | |
| 8492 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8493 | host->SetRootLayer(root); |
| 8494 | |
| 8495 | ExecuteCalculateDrawProperties(root.get()); |
| 8496 | |
| 8497 | ASSERT_TRUE(root->render_surface()); |
| 8498 | ASSERT_TRUE(render_surface->render_surface()); |
| 8499 | |
| 8500 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 8501 | // by the intervening clip layer. |
| 8502 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 8503 | clip_parent->clip_rect().ToString()); |
| 8504 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 8505 | clip_child->clip_rect().ToString()); |
| 8506 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 8507 | intervening->clip_rect().ToString()); |
| 8508 | |
| 8509 | // Ensure that the render surface reports a content rect that has been grown |
| 8510 | // to accomodate for the clip child. |
| 8511 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 8512 | render_surface->render_surface()->content_rect().ToString()); |
| 8513 | |
| 8514 | // The above check implies the two below, but they nicely demonstrate that |
| 8515 | // we've grown, despite the intervening layer's clip. |
| 8516 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 8517 | render_surface->render_surface()->content_rect())); |
| 8518 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 8519 | render_surface->render_surface()->content_rect())); |
| 8520 | } |
| 8521 | |
| 8522 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 8523 | // Ensure that intervening render surfaces are not a problem in the basic |
| 8524 | // case. In the following tree, both render surfaces should be resized to |
| 8525 | // accomodate for the clip child, despite an intervening clip. |
| 8526 | // |
| 8527 | // root (a render surface) |
| 8528 | // + clip_parent (masks to bounds) |
| 8529 | // + render_surface1 (sets opacity) |
| 8530 | // + intervening (masks to bounds) |
| 8531 | // + render_surface2 (also sets opacity) |
| 8532 | // + clip_child |
| 8533 | // |
| 8534 | scoped_refptr<Layer> root = Layer::Create(); |
| 8535 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8536 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8537 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8538 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8539 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8540 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8541 | |
| 8542 | root->AddChild(clip_parent); |
| 8543 | clip_parent->AddChild(render_surface1); |
| 8544 | render_surface1->AddChild(intervening); |
| 8545 | intervening->AddChild(render_surface2); |
| 8546 | render_surface2->AddChild(clip_child); |
| 8547 | |
| 8548 | clip_child->SetClipParent(clip_parent.get()); |
| 8549 | |
| 8550 | intervening->SetMasksToBounds(true); |
| 8551 | clip_parent->SetMasksToBounds(true); |
| 8552 | |
| 8553 | render_surface1->SetForceRenderSurface(true); |
| 8554 | render_surface2->SetForceRenderSurface(true); |
| 8555 | |
| 8556 | gfx::Transform translation_transform; |
| 8557 | translation_transform.Translate(2, 2); |
| 8558 | |
| 8559 | gfx::Transform identity_transform; |
| 8560 | SetLayerPropertiesForTesting(root.get(), |
| 8561 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8562 | gfx::PointF(), |
| 8563 | gfx::PointF(), |
| 8564 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8565 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8566 | false); |
| 8567 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8568 | translation_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8569 | gfx::PointF(), |
| 8570 | gfx::PointF(1.f, 1.f), |
| 8571 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8572 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8573 | false); |
| 8574 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8575 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8576 | gfx::PointF(), |
| 8577 | gfx::PointF(), |
| 8578 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8579 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8580 | false); |
| 8581 | SetLayerPropertiesForTesting(intervening.get(), |
| 8582 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8583 | gfx::PointF(), |
| 8584 | gfx::PointF(1.f, 1.f), |
| 8585 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8586 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8587 | false); |
| 8588 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8589 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8590 | gfx::PointF(), |
| 8591 | gfx::PointF(), |
| 8592 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8593 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8594 | false); |
| 8595 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8596 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8597 | gfx::PointF(), |
| 8598 | gfx::PointF(-10.f, -10.f), |
| 8599 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8600 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8601 | false); |
| 8602 | |
| 8603 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8604 | host->SetRootLayer(root); |
| 8605 | |
| 8606 | ExecuteCalculateDrawProperties(root.get()); |
| 8607 | |
| 8608 | EXPECT_TRUE(root->render_surface()); |
| 8609 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8610 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8611 | |
| 8612 | // Since the render surfaces could have expanded, they should not clip (their |
| 8613 | // bounds would no longer be reliable). We should resort to layer clipping |
| 8614 | // in this case. |
| 8615 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8616 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8617 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8618 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8619 | render_surface2->render_surface()->clip_rect().ToString()); |
| 8620 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 8621 | |
| 8622 | // NB: clip rects are in target space. |
| 8623 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8624 | render_surface1->clip_rect().ToString()); |
| 8625 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8626 | |
| 8627 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 8628 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8629 | render_surface2->clip_rect().ToString()); |
| 8630 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 8631 | |
| 8632 | // The content rects of both render surfaces should both have expanded to |
| 8633 | // contain the clip child. |
| 8634 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8635 | render_surface1->render_surface()->content_rect().ToString()); |
| 8636 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 8637 | render_surface2->render_surface()->content_rect().ToString()); |
| 8638 | |
| 8639 | // The clip child should have inherited the clip parent's clip (projected to |
| 8640 | // the right space, of course), and should have the correctly sized visible |
| 8641 | // content rect. |
| 8642 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 8643 | clip_child->clip_rect().ToString()); |
| 8644 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 8645 | clip_child->visible_content_rect().ToString()); |
| 8646 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8647 | } |
| 8648 | |
| 8649 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 8650 | // Ensure that intervening render surfaces are not a problem, even if there |
| 8651 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 8652 | // of transform. |
| 8653 | // |
| 8654 | // root (a render surface) |
| 8655 | // + clip_parent (masks to bounds) |
| 8656 | // + render_surface1 (sets opacity) |
| 8657 | // + intervening (masks to bounds AND scrolls) |
| 8658 | // + render_surface2 (also sets opacity) |
| 8659 | // + clip_child |
| 8660 | // |
| 8661 | scoped_refptr<Layer> root = Layer::Create(); |
| 8662 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8663 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8664 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8665 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8666 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8667 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8668 | |
| 8669 | root->AddChild(clip_parent); |
| 8670 | clip_parent->AddChild(render_surface1); |
| 8671 | render_surface1->AddChild(intervening); |
| 8672 | intervening->AddChild(render_surface2); |
| 8673 | render_surface2->AddChild(clip_child); |
| 8674 | |
| 8675 | clip_child->SetClipParent(clip_parent.get()); |
| 8676 | |
| 8677 | intervening->SetMasksToBounds(true); |
| 8678 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8679 | intervening->SetScrollClipLayerId(clip_parent->id()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8680 | intervening->SetScrollOffset(gfx::Vector2d(3, 3)); |
| 8681 | |
| 8682 | render_surface1->SetForceRenderSurface(true); |
| 8683 | render_surface2->SetForceRenderSurface(true); |
| 8684 | |
| 8685 | gfx::Transform translation_transform; |
| 8686 | translation_transform.Translate(2, 2); |
| 8687 | |
| 8688 | gfx::Transform identity_transform; |
| 8689 | SetLayerPropertiesForTesting(root.get(), |
| 8690 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8691 | gfx::PointF(), |
| 8692 | gfx::PointF(), |
| 8693 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8694 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8695 | false); |
| 8696 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8697 | translation_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8698 | gfx::PointF(), |
| 8699 | gfx::PointF(1.f, 1.f), |
| 8700 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8701 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8702 | false); |
| 8703 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8704 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8705 | gfx::PointF(), |
| 8706 | gfx::PointF(), |
| 8707 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8708 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8709 | false); |
| 8710 | SetLayerPropertiesForTesting(intervening.get(), |
| 8711 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8712 | gfx::PointF(), |
| 8713 | gfx::PointF(1.f, 1.f), |
| 8714 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8715 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8716 | false); |
| 8717 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8718 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8719 | gfx::PointF(), |
| 8720 | gfx::PointF(), |
| 8721 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8722 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8723 | false); |
| 8724 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8725 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8726 | gfx::PointF(), |
| 8727 | gfx::PointF(-10.f, -10.f), |
| 8728 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8729 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8730 | false); |
| 8731 | |
| 8732 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8733 | host->SetRootLayer(root); |
| 8734 | |
| 8735 | ExecuteCalculateDrawProperties(root.get()); |
| 8736 | |
| 8737 | EXPECT_TRUE(root->render_surface()); |
| 8738 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8739 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8740 | |
| 8741 | // Since the render surfaces could have expanded, they should not clip (their |
| 8742 | // bounds would no longer be reliable). We should resort to layer clipping |
| 8743 | // in this case. |
| 8744 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8745 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8746 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8747 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8748 | render_surface2->render_surface()->clip_rect().ToString()); |
| 8749 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 8750 | |
| 8751 | // NB: clip rects are in target space. |
| 8752 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8753 | render_surface1->clip_rect().ToString()); |
| 8754 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8755 | |
| 8756 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 8757 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 8758 | render_surface2->clip_rect().ToString()); |
| 8759 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 8760 | |
| 8761 | // The content rects of both render surfaces should both have expanded to |
| 8762 | // contain the clip child. |
| 8763 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8764 | render_surface1->render_surface()->content_rect().ToString()); |
| 8765 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 8766 | render_surface2->render_surface()->content_rect().ToString()); |
| 8767 | |
| 8768 | // The clip child should have inherited the clip parent's clip (projected to |
| 8769 | // the right space, of course), and should have the correctly sized visible |
| 8770 | // content rect. |
| 8771 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 8772 | clip_child->clip_rect().ToString()); |
| 8773 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 8774 | clip_child->visible_content_rect().ToString()); |
| 8775 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8776 | } |
| 8777 | |
| 8778 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 8779 | // Ensures that descendants of the clip child inherit the correct clip. |
| 8780 | // |
| 8781 | // root (a render surface) |
| 8782 | // + clip_parent (masks to bounds) |
| 8783 | // + intervening (masks to bounds) |
| 8784 | // + clip_child |
| 8785 | // + child |
| 8786 | // |
| 8787 | scoped_refptr<Layer> root = Layer::Create(); |
| 8788 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8789 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8790 | scoped_refptr<Layer> clip_child = Layer::Create(); |
| 8791 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 8792 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8793 | |
| 8794 | root->AddChild(clip_parent); |
| 8795 | clip_parent->AddChild(intervening); |
| 8796 | intervening->AddChild(clip_child); |
| 8797 | clip_child->AddChild(child); |
| 8798 | |
| 8799 | clip_child->SetClipParent(clip_parent.get()); |
| 8800 | |
| 8801 | intervening->SetMasksToBounds(true); |
| 8802 | clip_parent->SetMasksToBounds(true); |
| 8803 | |
| 8804 | gfx::Transform identity_transform; |
| 8805 | SetLayerPropertiesForTesting(root.get(), |
| 8806 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8807 | gfx::PointF(), |
| 8808 | gfx::PointF(), |
| 8809 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8810 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8811 | false); |
| 8812 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8813 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8814 | gfx::PointF(), |
| 8815 | gfx::PointF(), |
| 8816 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8817 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8818 | false); |
| 8819 | SetLayerPropertiesForTesting(intervening.get(), |
| 8820 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8821 | gfx::PointF(), |
| 8822 | gfx::PointF(), |
| 8823 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8824 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8825 | false); |
| 8826 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8827 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8828 | gfx::PointF(), |
| 8829 | gfx::PointF(), |
| 8830 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8831 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8832 | false); |
| 8833 | SetLayerPropertiesForTesting(child.get(), |
| 8834 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8835 | gfx::PointF(), |
| 8836 | gfx::PointF(), |
| 8837 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8838 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8839 | false); |
| 8840 | |
| 8841 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8842 | host->SetRootLayer(root); |
| 8843 | |
| 8844 | ExecuteCalculateDrawProperties(root.get()); |
| 8845 | |
| 8846 | EXPECT_TRUE(root->render_surface()); |
| 8847 | |
| 8848 | // Neither the clip child nor its descendant should have inherited the clip |
| 8849 | // from |intervening|. |
| 8850 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8851 | clip_child->clip_rect().ToString()); |
| 8852 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8853 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8854 | child->visible_content_rect().ToString()); |
| 8855 | EXPECT_TRUE(child->is_clipped()); |
| 8856 | } |
| 8857 | |
| 8858 | TEST_F(LayerTreeHostCommonTest, |
| 8859 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 8860 | // Ensures that non-descendant clip children in the tree do not affect |
| 8861 | // render surfaces. |
| 8862 | // |
| 8863 | // root (a render surface) |
| 8864 | // + clip_parent (masks to bounds) |
| 8865 | // + render_surface1 |
| 8866 | // + clip_child |
| 8867 | // + render_surface2 |
| 8868 | // + non_clip_child |
| 8869 | // |
| 8870 | // In this example render_surface2 should be unaffected by clip_child. |
| 8871 | scoped_refptr<Layer> root = Layer::Create(); |
| 8872 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8873 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8874 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8875 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8876 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8877 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
| 8878 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8879 | |
| 8880 | root->AddChild(clip_parent); |
| 8881 | clip_parent->AddChild(render_surface1); |
| 8882 | render_surface1->AddChild(clip_child); |
| 8883 | clip_parent->AddChild(render_surface2); |
| 8884 | render_surface2->AddChild(non_clip_child); |
| 8885 | |
| 8886 | clip_child->SetClipParent(clip_parent.get()); |
| 8887 | |
| 8888 | clip_parent->SetMasksToBounds(true); |
| 8889 | render_surface1->SetMasksToBounds(true); |
| 8890 | |
| 8891 | gfx::Transform identity_transform; |
| 8892 | SetLayerPropertiesForTesting(root.get(), |
| 8893 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8894 | gfx::PointF(), |
| 8895 | gfx::PointF(), |
| 8896 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8897 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8898 | false); |
| 8899 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8900 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8901 | gfx::PointF(), |
| 8902 | gfx::PointF(), |
| 8903 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8904 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8905 | false); |
| 8906 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8907 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8908 | gfx::PointF(), |
| 8909 | gfx::PointF(5, 5), |
| 8910 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8911 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8912 | false); |
| 8913 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8914 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8915 | gfx::PointF(), |
| 8916 | gfx::PointF(), |
| 8917 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8918 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8919 | false); |
| 8920 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8921 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8922 | gfx::PointF(), |
| 8923 | gfx::PointF(-1, 1), |
| 8924 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8925 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8926 | false); |
| 8927 | SetLayerPropertiesForTesting(non_clip_child.get(), |
| 8928 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8929 | gfx::PointF(), |
| 8930 | gfx::PointF(), |
| 8931 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8932 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8933 | false); |
| 8934 | |
| 8935 | render_surface1->SetForceRenderSurface(true); |
| 8936 | render_surface2->SetForceRenderSurface(true); |
| 8937 | |
| 8938 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8939 | host->SetRootLayer(root); |
| 8940 | |
| 8941 | ExecuteCalculateDrawProperties(root.get()); |
| 8942 | |
| 8943 | EXPECT_TRUE(root->render_surface()); |
| 8944 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8945 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8946 | |
| 8947 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8948 | render_surface1->clip_rect().ToString()); |
| 8949 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8950 | |
| 8951 | // The render surface should not clip (it has unclipped descendants), instead |
| 8952 | // it should rely on layer clipping. |
| 8953 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8954 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8955 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8956 | |
| 8957 | // That said, it should have grown to accomodate the unclipped descendant. |
| 8958 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 8959 | render_surface1->render_surface()->content_rect().ToString()); |
| 8960 | |
| 8961 | // This render surface should clip. It has no unclipped descendants. |
| 8962 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8963 | render_surface2->clip_rect().ToString()); |
| 8964 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 8965 | |
| 8966 | // It also shouldn't have grown to accomodate the clip child. |
| 8967 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8968 | render_surface2->render_surface()->content_rect().ToString()); |
| 8969 | |
| 8970 | // Sanity check our num_unclipped_descendants values. |
| 8971 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 8972 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 8973 | } |
| 8974 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8975 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 8976 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8977 | TestSharedBitmapManager shared_bitmap_manager; |
| 8978 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8979 | scoped_ptr<LayerImpl> root = |
| 8980 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 8981 | scoped_ptr<LayerImpl> child1 = |
| 8982 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 8983 | scoped_ptr<LayerImpl> child2 = |
| 8984 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 8985 | scoped_ptr<LayerImpl> child3 = |
| 8986 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 8987 | |
| 8988 | gfx::Transform identity_matrix; |
| 8989 | gfx::PointF anchor; |
| 8990 | gfx::PointF position; |
| 8991 | gfx::Size bounds(100, 100); |
| 8992 | SetLayerPropertiesForTesting(root.get(), |
| 8993 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8994 | anchor, |
| 8995 | position, |
| 8996 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8997 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8998 | false); |
| 8999 | root->SetDrawsContent(true); |
| 9000 | |
| 9001 | // This layer structure normally forces render surface due to preserves3d |
| 9002 | // behavior. |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9003 | SetLayerPropertiesForTesting(child1.get(), |
| 9004 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9005 | anchor, |
| 9006 | position, |
| 9007 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9008 | false, |
| 9009 | true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9010 | child1->SetDrawsContent(true); |
| 9011 | SetLayerPropertiesForTesting(child2.get(), |
| 9012 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9013 | anchor, |
| 9014 | position, |
| 9015 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9016 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9017 | false); |
| 9018 | child2->SetDrawsContent(true); |
| 9019 | SetLayerPropertiesForTesting(child3.get(), |
| 9020 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9021 | anchor, |
| 9022 | position, |
| 9023 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9024 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9025 | false); |
| 9026 | child3->SetDrawsContent(true); |
| 9027 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9028 | child2->SetIs3dSorted(true); |
| 9029 | child3->SetIs3dSorted(true); |
| 9030 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9031 | child2->AddChild(child3.Pass()); |
| 9032 | child1->AddChild(child2.Pass()); |
| 9033 | root->AddChild(child1.Pass()); |
| 9034 | |
| 9035 | { |
| 9036 | LayerImplList render_surface_layer_list; |
| 9037 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9038 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9039 | inputs.can_render_to_separate_surface = true; |
| 9040 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9041 | |
| 9042 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 9043 | } |
| 9044 | |
| 9045 | { |
| 9046 | LayerImplList render_surface_layer_list; |
| 9047 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9048 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9049 | inputs.can_render_to_separate_surface = false; |
| 9050 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9051 | |
| 9052 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
| 9053 | } |
| 9054 | } |
| 9055 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9056 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 9057 | scoped_refptr<Layer> root = Layer::Create(); |
| 9058 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 9059 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9060 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9061 | |
| 9062 | root->AddChild(render_surface); |
| 9063 | render_surface->AddChild(child); |
| 9064 | |
| 9065 | gfx::Transform identity_transform; |
| 9066 | SetLayerPropertiesForTesting(root.get(), |
| 9067 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9068 | gfx::PointF(), |
| 9069 | gfx::PointF(), |
| 9070 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9071 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9072 | false); |
| 9073 | SetLayerPropertiesForTesting(render_surface.get(), |
| 9074 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9075 | gfx::PointF(), |
| 9076 | gfx::PointF(), |
| 9077 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9078 | false, |
| 9079 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9080 | SetLayerPropertiesForTesting(child.get(), |
| 9081 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9082 | gfx::PointF(), |
| 9083 | gfx::PointF(), |
| 9084 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9085 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9086 | false); |
| 9087 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9088 | root->SetShouldFlattenTransform(false); |
| 9089 | root->SetIs3dSorted(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9090 | render_surface->SetDoubleSided(false); |
| 9091 | render_surface->SetForceRenderSurface(true); |
| 9092 | |
| 9093 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9094 | host->SetRootLayer(root); |
| 9095 | |
| 9096 | ExecuteCalculateDrawProperties(root.get()); |
| 9097 | |
| 9098 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 9099 | EXPECT_EQ(1u, |
| 9100 | render_surface_layer_list()->at(0) |
| 9101 | ->render_surface()->layer_list().size()); |
| 9102 | EXPECT_EQ(1u, |
| 9103 | render_surface_layer_list()->at(1) |
| 9104 | ->render_surface()->layer_list().size()); |
| 9105 | |
| 9106 | gfx::Transform rotation_transform = identity_transform; |
| 9107 | rotation_transform.RotateAboutXAxis(180.0); |
| 9108 | |
| 9109 | render_surface->SetTransform(rotation_transform); |
| 9110 | |
| 9111 | ExecuteCalculateDrawProperties(root.get()); |
| 9112 | |
| 9113 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 9114 | EXPECT_EQ(0u, |
| 9115 | render_surface_layer_list()->at(0) |
| 9116 | ->render_surface()->layer_list().size()); |
| 9117 | } |
| 9118 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9119 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 9120 | // Checks that the simple case (being clipped by a scroll parent that would |
| 9121 | // have been processed before you anyhow) results in the right clips. |
| 9122 | // |
| 9123 | // + root |
| 9124 | // + scroll_parent_border |
| 9125 | // | + scroll_parent_clip |
| 9126 | // | + scroll_parent |
| 9127 | // + scroll_child |
| 9128 | // |
| 9129 | scoped_refptr<Layer> root = Layer::Create(); |
| 9130 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9131 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9132 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9133 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9134 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9135 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9136 | |
| 9137 | root->AddChild(scroll_child); |
| 9138 | |
| 9139 | root->AddChild(scroll_parent_border); |
| 9140 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9141 | scroll_parent_clip->AddChild(scroll_parent); |
| 9142 | |
| 9143 | scroll_parent_clip->SetMasksToBounds(true); |
| 9144 | |
| 9145 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9146 | |
| 9147 | gfx::Transform identity_transform; |
| 9148 | SetLayerPropertiesForTesting(root.get(), |
| 9149 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9150 | gfx::PointF(), |
| 9151 | gfx::PointF(), |
| 9152 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9153 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9154 | false); |
| 9155 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9156 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9157 | gfx::PointF(), |
| 9158 | gfx::PointF(), |
| 9159 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9160 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9161 | false); |
| 9162 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9163 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9164 | gfx::PointF(), |
| 9165 | gfx::PointF(), |
| 9166 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9167 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9168 | false); |
| 9169 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9170 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9171 | gfx::PointF(), |
| 9172 | gfx::PointF(), |
| 9173 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9174 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9175 | false); |
| 9176 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9177 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9178 | gfx::PointF(), |
| 9179 | gfx::PointF(), |
| 9180 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9181 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9182 | false); |
| 9183 | |
| 9184 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9185 | host->SetRootLayer(root); |
| 9186 | |
| 9187 | ExecuteCalculateDrawProperties(root.get()); |
| 9188 | |
| 9189 | EXPECT_TRUE(root->render_surface()); |
| 9190 | |
| 9191 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 9192 | scroll_child->clip_rect().ToString()); |
| 9193 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9194 | } |
| 9195 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 9196 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 9197 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 9198 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9199 | scoped_refptr<LayerWithForcedDrawsContent> parent = |
| 9200 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9201 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9202 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9203 | |
| 9204 | root->AddChild(parent); |
| 9205 | parent->AddChild(child); |
| 9206 | |
| 9207 | gfx::Transform identity_transform; |
| 9208 | SetLayerPropertiesForTesting(root.get(), |
| 9209 | identity_transform, |
| 9210 | gfx::PointF(), |
| 9211 | gfx::PointF(), |
| 9212 | gfx::Size(50, 50), |
| 9213 | true, |
| 9214 | true); |
| 9215 | root->SetForceRenderSurface(true); |
| 9216 | SetLayerPropertiesForTesting(parent.get(), |
| 9217 | identity_transform, |
| 9218 | gfx::PointF(), |
| 9219 | gfx::PointF(), |
| 9220 | gfx::Size(30, 30), |
| 9221 | true, |
| 9222 | true); |
| 9223 | parent->SetForceRenderSurface(true); |
| 9224 | SetLayerPropertiesForTesting(child.get(), |
| 9225 | identity_transform, |
| 9226 | gfx::PointF(), |
| 9227 | gfx::PointF(), |
| 9228 | gfx::Size(20, 20), |
| 9229 | true, |
| 9230 | true); |
| 9231 | child->SetForceRenderSurface(true); |
| 9232 | |
| 9233 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9234 | host->SetRootLayer(root); |
| 9235 | |
| 9236 | ExecuteCalculateDrawProperties(root.get()); |
| 9237 | |
| 9238 | EXPECT_EQ(3u, render_surface_layer_list()->size()); |
| 9239 | |
| 9240 | gfx::Transform singular_transform; |
| 9241 | singular_transform.Scale3d( |
| 9242 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 9243 | |
| 9244 | child->SetTransform(singular_transform); |
| 9245 | |
| 9246 | ExecuteCalculateDrawProperties(root.get()); |
| 9247 | |
| 9248 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 9249 | |
| 9250 | // Ensure that the entire subtree under a layer with singular transform does |
| 9251 | // not get rendered. |
| 9252 | parent->SetTransform(singular_transform); |
| 9253 | child->SetTransform(identity_transform); |
| 9254 | |
| 9255 | ExecuteCalculateDrawProperties(root.get()); |
| 9256 | |
| 9257 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 9258 | } |
| 9259 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9260 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 9261 | // Checks that clipping by a scroll parent that follows you in paint order |
| 9262 | // still results in correct clipping. |
| 9263 | // |
| 9264 | // + root |
| 9265 | // + scroll_child |
| 9266 | // + scroll_parent_border |
| 9267 | // + scroll_parent_clip |
| 9268 | // + scroll_parent |
| 9269 | // |
| 9270 | scoped_refptr<Layer> root = Layer::Create(); |
| 9271 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9272 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9273 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9274 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9275 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9276 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9277 | |
| 9278 | root->AddChild(scroll_parent_border); |
| 9279 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9280 | scroll_parent_clip->AddChild(scroll_parent); |
| 9281 | |
| 9282 | root->AddChild(scroll_child); |
| 9283 | |
| 9284 | scroll_parent_clip->SetMasksToBounds(true); |
| 9285 | |
| 9286 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9287 | |
| 9288 | gfx::Transform identity_transform; |
| 9289 | SetLayerPropertiesForTesting(root.get(), |
| 9290 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9291 | gfx::PointF(), |
| 9292 | gfx::PointF(), |
| 9293 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9294 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9295 | false); |
| 9296 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9297 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9298 | gfx::PointF(), |
| 9299 | gfx::PointF(), |
| 9300 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9301 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9302 | false); |
| 9303 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9304 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9305 | gfx::PointF(), |
| 9306 | gfx::PointF(), |
| 9307 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9308 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9309 | false); |
| 9310 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9311 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9312 | gfx::PointF(), |
| 9313 | gfx::PointF(), |
| 9314 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9315 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9316 | false); |
| 9317 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9318 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9319 | gfx::PointF(), |
| 9320 | gfx::PointF(), |
| 9321 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9322 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9323 | false); |
| 9324 | |
| 9325 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9326 | host->SetRootLayer(root); |
| 9327 | |
| 9328 | ExecuteCalculateDrawProperties(root.get()); |
| 9329 | |
| 9330 | EXPECT_TRUE(root->render_surface()); |
| 9331 | |
| 9332 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 9333 | scroll_child->clip_rect().ToString()); |
| 9334 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9335 | } |
| 9336 | |
| 9337 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 9338 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 9339 | // you in paint order still results in correct clipping. |
| 9340 | // |
| 9341 | // + root |
| 9342 | // + scroll_child |
| 9343 | // + scroll_parent_border |
| 9344 | // | + scroll_parent_clip |
| 9345 | // | + scroll_parent |
| 9346 | // + scroll_grandparent_border |
| 9347 | // + scroll_grandparent_clip |
| 9348 | // + scroll_grandparent |
| 9349 | // |
| 9350 | scoped_refptr<Layer> root = Layer::Create(); |
| 9351 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9352 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9353 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9354 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9355 | |
| 9356 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 9357 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 9358 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 9359 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9360 | |
| 9361 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9362 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9363 | |
| 9364 | root->AddChild(scroll_child); |
| 9365 | |
| 9366 | root->AddChild(scroll_parent_border); |
| 9367 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9368 | scroll_parent_clip->AddChild(scroll_parent); |
| 9369 | |
| 9370 | root->AddChild(scroll_grandparent_border); |
| 9371 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 9372 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 9373 | |
| 9374 | scroll_parent_clip->SetMasksToBounds(true); |
| 9375 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 9376 | |
| 9377 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9378 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 9379 | |
| 9380 | gfx::Transform identity_transform; |
| 9381 | SetLayerPropertiesForTesting(root.get(), |
| 9382 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9383 | gfx::PointF(), |
| 9384 | gfx::PointF(), |
| 9385 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9386 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9387 | false); |
| 9388 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 9389 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9390 | gfx::PointF(), |
| 9391 | gfx::PointF(), |
| 9392 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9393 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9394 | false); |
| 9395 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 9396 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9397 | gfx::PointF(), |
| 9398 | gfx::PointF(), |
| 9399 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9400 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9401 | false); |
| 9402 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 9403 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9404 | gfx::PointF(), |
| 9405 | gfx::PointF(), |
| 9406 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9407 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9408 | false); |
| 9409 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9410 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9411 | gfx::PointF(), |
| 9412 | gfx::PointF(), |
| 9413 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9414 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9415 | false); |
| 9416 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9417 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9418 | gfx::PointF(), |
| 9419 | gfx::PointF(), |
| 9420 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9421 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9422 | false); |
| 9423 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9424 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9425 | gfx::PointF(), |
| 9426 | gfx::PointF(), |
| 9427 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9428 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9429 | false); |
| 9430 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9431 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9432 | gfx::PointF(), |
| 9433 | gfx::PointF(), |
| 9434 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9435 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9436 | false); |
| 9437 | |
| 9438 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9439 | host->SetRootLayer(root); |
| 9440 | |
| 9441 | ExecuteCalculateDrawProperties(root.get()); |
| 9442 | |
| 9443 | EXPECT_TRUE(root->render_surface()); |
| 9444 | |
| 9445 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 9446 | scroll_child->clip_rect().ToString()); |
| 9447 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9448 | |
| 9449 | // Despite the fact that we visited the above layers out of order to get the |
| 9450 | // correct clip, the layer lists should be unaffected. |
| 9451 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 9452 | EXPECT_EQ(scroll_child.get(), |
| 9453 | root->render_surface()->layer_list().at(0)); |
| 9454 | EXPECT_EQ(scroll_parent.get(), |
| 9455 | root->render_surface()->layer_list().at(1)); |
| 9456 | EXPECT_EQ(scroll_grandparent.get(), |
| 9457 | root->render_surface()->layer_list().at(2)); |
| 9458 | } |
| 9459 | |
| 9460 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 9461 | // 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] | 9462 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9463 | // + root |
| 9464 | // + scroll_child |
| 9465 | // + scroll_parent_border |
| 9466 | // + scroll_parent_clip |
| 9467 | // + scroll_parent |
| 9468 | // + render_surface1 |
| 9469 | // + scroll_grandparent_border |
| 9470 | // + scroll_grandparent_clip |
| 9471 | // + scroll_grandparent |
| 9472 | // + render_surface2 |
| 9473 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 9474 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 9475 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9476 | |
| 9477 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9478 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9479 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9480 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9481 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
| 9482 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9483 | |
| 9484 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 9485 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 9486 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 9487 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9488 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
| 9489 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9490 | |
| 9491 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9492 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9493 | |
| 9494 | root->AddChild(scroll_child); |
| 9495 | |
| 9496 | root->AddChild(scroll_parent_border); |
| 9497 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9498 | scroll_parent_clip->AddChild(scroll_parent); |
| 9499 | scroll_parent->AddChild(render_surface2); |
| 9500 | |
| 9501 | root->AddChild(scroll_grandparent_border); |
| 9502 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 9503 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 9504 | scroll_grandparent->AddChild(render_surface1); |
| 9505 | |
| 9506 | scroll_parent_clip->SetMasksToBounds(true); |
| 9507 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 9508 | |
| 9509 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9510 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 9511 | |
| 9512 | render_surface1->SetForceRenderSurface(true); |
| 9513 | render_surface2->SetForceRenderSurface(true); |
| 9514 | |
| 9515 | gfx::Transform identity_transform; |
| 9516 | SetLayerPropertiesForTesting(root.get(), |
| 9517 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9518 | gfx::PointF(), |
| 9519 | gfx::PointF(), |
| 9520 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9521 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9522 | false); |
| 9523 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 9524 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9525 | gfx::PointF(), |
| 9526 | gfx::PointF(), |
| 9527 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9528 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9529 | false); |
| 9530 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 9531 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9532 | gfx::PointF(), |
| 9533 | gfx::PointF(), |
| 9534 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9535 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9536 | false); |
| 9537 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 9538 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9539 | gfx::PointF(), |
| 9540 | gfx::PointF(), |
| 9541 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9542 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9543 | false); |
| 9544 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 9545 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9546 | gfx::PointF(), |
| 9547 | gfx::PointF(), |
| 9548 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9549 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9550 | false); |
| 9551 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9552 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9553 | gfx::PointF(), |
| 9554 | gfx::PointF(), |
| 9555 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9556 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9557 | false); |
| 9558 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9559 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9560 | gfx::PointF(), |
| 9561 | gfx::PointF(), |
| 9562 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9563 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9564 | false); |
| 9565 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9566 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9567 | gfx::PointF(), |
| 9568 | gfx::PointF(), |
| 9569 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9570 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9571 | false); |
| 9572 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 9573 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9574 | gfx::PointF(), |
| 9575 | gfx::PointF(), |
| 9576 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9577 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9578 | false); |
| 9579 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9580 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9581 | gfx::PointF(), |
| 9582 | gfx::PointF(), |
| 9583 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9584 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9585 | false); |
| 9586 | |
| 9587 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9588 | host->SetRootLayer(root); |
| 9589 | |
| 9590 | RenderSurfaceLayerList render_surface_layer_list; |
| 9591 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 9592 | root.get(), |
| 9593 | root->bounds(), |
| 9594 | identity_transform, |
| 9595 | &render_surface_layer_list); |
| 9596 | |
| 9597 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9598 | |
| 9599 | EXPECT_TRUE(root->render_surface()); |
| 9600 | |
| 9601 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 9602 | scroll_child->clip_rect().ToString()); |
| 9603 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9604 | |
| 9605 | // Despite the fact that we had to process the layers out of order to get the |
| 9606 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 9607 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 9608 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 9609 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 9610 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 9611 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 9612 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 9613 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9614 | } |
| 9615 | |
| 9616 | TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { |
| 9617 | // We rearrange layer list contributions if we have to visit children out of |
| 9618 | // order, but it should be a 'stable' rearrangement. That is, the layer list |
| 9619 | // additions for a single layer should not be reordered, though their position |
| 9620 | // wrt to the contributions due to a sibling may vary. |
| 9621 | // |
| 9622 | // + root |
| 9623 | // + scroll_child |
| 9624 | // + top_content |
| 9625 | // + bottom_content |
| 9626 | // + scroll_parent_border |
| 9627 | // + scroll_parent_clip |
| 9628 | // + scroll_parent |
| 9629 | // |
| 9630 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 9631 | TestSharedBitmapManager shared_bitmap_manager; |
| 9632 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9633 | host_impl.CreatePendingTree(); |
| 9634 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 9635 | scoped_ptr<LayerImpl> scroll_parent_border = |
| 9636 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9637 | scoped_ptr<LayerImpl> scroll_parent_clip = |
| 9638 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9639 | scoped_ptr<LayerImpl> scroll_parent = |
| 9640 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 9641 | scoped_ptr<LayerImpl> scroll_child = |
| 9642 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 9643 | scoped_ptr<LayerImpl> bottom_content = |
| 9644 | LayerImpl::Create(host_impl.active_tree(), 6); |
| 9645 | scoped_ptr<LayerImpl> top_content = |
| 9646 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 9647 | |
| 9648 | scroll_parent_clip->SetMasksToBounds(true); |
| 9649 | |
| 9650 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9651 | scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>); |
| 9652 | scroll_children->insert(scroll_child.get()); |
| 9653 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 9654 | |
| 9655 | scroll_child->SetDrawsContent(true); |
| 9656 | scroll_parent->SetDrawsContent(true); |
| 9657 | top_content->SetDrawsContent(true); |
| 9658 | bottom_content->SetDrawsContent(true); |
| 9659 | |
| 9660 | gfx::Transform identity_transform; |
| 9661 | gfx::Transform top_transform; |
| 9662 | top_transform.Translate3d(0.0, 0.0, 5.0); |
| 9663 | gfx::Transform bottom_transform; |
| 9664 | bottom_transform.Translate3d(0.0, 0.0, 3.0); |
| 9665 | |
| 9666 | SetLayerPropertiesForTesting(root.get(), |
| 9667 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9668 | gfx::PointF(), |
| 9669 | gfx::PointF(), |
| 9670 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9671 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9672 | false); |
| 9673 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9674 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9675 | gfx::PointF(), |
| 9676 | gfx::PointF(), |
| 9677 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9678 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9679 | false); |
| 9680 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9681 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9682 | gfx::PointF(), |
| 9683 | gfx::PointF(), |
| 9684 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9685 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9686 | false); |
| 9687 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9688 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9689 | gfx::PointF(), |
| 9690 | gfx::PointF(), |
| 9691 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9692 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9693 | false); |
| 9694 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9695 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9696 | gfx::PointF(), |
| 9697 | gfx::PointF(), |
| 9698 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9699 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9700 | false); |
| 9701 | SetLayerPropertiesForTesting(top_content.get(), |
| 9702 | top_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9703 | gfx::PointF(), |
| 9704 | gfx::PointF(), |
| 9705 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9706 | false, |
| 9707 | true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9708 | SetLayerPropertiesForTesting(bottom_content.get(), |
| 9709 | bottom_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9710 | gfx::PointF(), |
| 9711 | gfx::PointF(), |
| 9712 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9713 | false, |
| 9714 | true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9715 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9716 | scroll_child->SetShouldFlattenTransform(false); |
| 9717 | scroll_child->SetIs3dSorted(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9718 | |
| 9719 | scroll_child->AddChild(top_content.Pass()); |
| 9720 | scroll_child->AddChild(bottom_content.Pass()); |
| 9721 | root->AddChild(scroll_child.Pass()); |
| 9722 | |
| 9723 | scroll_parent_clip->AddChild(scroll_parent.Pass()); |
| 9724 | scroll_parent_border->AddChild(scroll_parent_clip.Pass()); |
| 9725 | root->AddChild(scroll_parent_border.Pass()); |
| 9726 | |
| 9727 | LayerImplList render_surface_layer_list; |
| 9728 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9729 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9730 | |
| 9731 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9732 | |
| 9733 | EXPECT_TRUE(root->render_surface()); |
| 9734 | |
| 9735 | // If we don't sort by depth and let the layers get added in the order they |
| 9736 | // would normally be visited in, then layers 6 and 7 will be out of order. In |
| 9737 | // other words, although we've had to shift 5, 6, and 7 to appear before 4 |
| 9738 | // in the list (because of the scroll parent relationship), this should not |
| 9739 | // have an effect on the the order of 5, 6, and 7 (which had been reordered |
| 9740 | // due to layer sorting). |
| 9741 | EXPECT_EQ(4u, root->render_surface()->layer_list().size()); |
| 9742 | EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id()); |
| 9743 | EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id()); |
| 9744 | EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id()); |
| 9745 | EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id()); |
| 9746 | } |
| 9747 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9748 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 9749 | // This test verifies that a scrolling layer that gets snapped to |
| 9750 | // integer coordinates doesn't move a fixed position child. |
| 9751 | // |
| 9752 | // + root |
| 9753 | // + container |
| 9754 | // + scroller |
| 9755 | // + fixed |
| 9756 | // |
| 9757 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 9758 | TestSharedBitmapManager shared_bitmap_manager; |
| 9759 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9760 | host_impl.CreatePendingTree(); |
| 9761 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 9762 | scoped_ptr<LayerImpl> container = |
| 9763 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9764 | LayerImpl* container_layer = container.get(); |
| 9765 | scoped_ptr<LayerImpl> scroller = |
| 9766 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9767 | LayerImpl* scroll_layer = scroller.get(); |
| 9768 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 9769 | LayerImpl* fixed_layer = fixed.get(); |
| 9770 | |
| 9771 | container->SetIsContainerForFixedPositionLayers(true); |
| 9772 | |
| 9773 | LayerPositionConstraint constraint; |
| 9774 | constraint.set_is_fixed_position(true); |
| 9775 | fixed->SetPositionConstraint(constraint); |
| 9776 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 9777 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9778 | |
| 9779 | gfx::Transform identity_transform; |
| 9780 | gfx::Transform container_transform; |
| 9781 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 9782 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 9783 | |
| 9784 | SetLayerPropertiesForTesting(root.get(), |
| 9785 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9786 | gfx::PointF(), |
| 9787 | gfx::PointF(), |
| 9788 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9789 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9790 | false); |
| 9791 | SetLayerPropertiesForTesting(container.get(), |
| 9792 | container_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9793 | gfx::PointF(), |
| 9794 | gfx::PointF(), |
| 9795 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9796 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9797 | false); |
| 9798 | SetLayerPropertiesForTesting(scroller.get(), |
| 9799 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9800 | gfx::PointF(), |
| 9801 | gfx::PointF(), |
| 9802 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9803 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9804 | false); |
| 9805 | SetLayerPropertiesForTesting(fixed.get(), |
| 9806 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9807 | gfx::PointF(), |
| 9808 | gfx::PointF(), |
| 9809 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9810 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9811 | false); |
| 9812 | |
| 9813 | scroller->AddChild(fixed.Pass()); |
| 9814 | container->AddChild(scroller.Pass()); |
| 9815 | root->AddChild(container.Pass()); |
| 9816 | |
| 9817 | // Rounded to integers already. |
| 9818 | { |
| 9819 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 9820 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9821 | |
| 9822 | LayerImplList render_surface_layer_list; |
| 9823 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9824 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9825 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9826 | |
| 9827 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9828 | container_layer->draw_properties().screen_space_transform, |
| 9829 | fixed_layer->draw_properties().screen_space_transform); |
| 9830 | EXPECT_VECTOR_EQ( |
| 9831 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9832 | container_offset); |
| 9833 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 9834 | .screen_space_transform.To2dTranslation(), |
| 9835 | container_offset - scroll_delta); |
| 9836 | } |
| 9837 | |
| 9838 | // Scroll delta requiring rounding. |
| 9839 | { |
| 9840 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 9841 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9842 | |
| 9843 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 9844 | |
| 9845 | LayerImplList render_surface_layer_list; |
| 9846 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9847 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9848 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9849 | |
| 9850 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9851 | container_layer->draw_properties().screen_space_transform, |
| 9852 | fixed_layer->draw_properties().screen_space_transform); |
| 9853 | EXPECT_VECTOR_EQ( |
| 9854 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9855 | container_offset); |
| 9856 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 9857 | .screen_space_transform.To2dTranslation(), |
| 9858 | container_offset - rounded_scroll_delta); |
| 9859 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 9860 | |
| 9861 | // Scale is applied earlier in the tree. |
| 9862 | { |
| 9863 | gfx::Transform scaled_container_transform = container_transform; |
| 9864 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 9865 | container_layer->SetTransform(scaled_container_transform); |
| 9866 | |
| 9867 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 9868 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9869 | |
| 9870 | LayerImplList render_surface_layer_list; |
| 9871 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9872 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9873 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9874 | |
| 9875 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9876 | container_layer->draw_properties().screen_space_transform, |
| 9877 | fixed_layer->draw_properties().screen_space_transform); |
| 9878 | EXPECT_VECTOR_EQ( |
| 9879 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9880 | container_offset); |
| 9881 | |
| 9882 | container_layer->SetTransform(container_transform); |
| 9883 | } |
| 9884 | |
| 9885 | // Scale is applied on the scroll layer itself. |
| 9886 | { |
| 9887 | gfx::Transform scale_transform; |
| 9888 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 9889 | scroll_layer->SetTransform(scale_transform); |
| 9890 | |
| 9891 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 9892 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9893 | |
| 9894 | LayerImplList render_surface_layer_list; |
| 9895 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9896 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9897 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9898 | |
| 9899 | EXPECT_VECTOR_EQ( |
| 9900 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9901 | container_offset); |
| 9902 | |
| 9903 | scroll_layer->SetTransform(identity_transform); |
| 9904 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9905 | } |
| 9906 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 9907 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 9908 | public: |
| 9909 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 9910 | LayerTreeImpl* tree_impl, |
| 9911 | int id) { |
| 9912 | return make_scoped_ptr( |
| 9913 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 9914 | } |
| 9915 | |
| 9916 | virtual ~AnimationScaleFactorTrackingLayerImpl() {} |
| 9917 | |
| 9918 | virtual void CalculateContentsScale(float ideal_contents_scale, |
| 9919 | float device_scale_factor, |
| 9920 | float page_scale_factor, |
| 9921 | float maximum_animation_contents_scale, |
| 9922 | bool animating_transform_to_screen, |
| 9923 | float* contents_scale_x, |
| 9924 | float* contents_scale_y, |
| 9925 | gfx::Size* content_bounds) OVERRIDE { |
| 9926 | last_maximum_animation_contents_scale_ = maximum_animation_contents_scale; |
| 9927 | LayerImpl::CalculateContentsScale(ideal_contents_scale, |
| 9928 | device_scale_factor, |
| 9929 | page_scale_factor, |
| 9930 | maximum_animation_contents_scale, |
| 9931 | animating_transform_to_screen, |
| 9932 | contents_scale_x, |
| 9933 | contents_scale_y, |
| 9934 | content_bounds); |
| 9935 | } |
| 9936 | |
| 9937 | float last_maximum_animation_contents_scale() { |
| 9938 | return last_maximum_animation_contents_scale_; |
| 9939 | } |
| 9940 | |
| 9941 | private: |
| 9942 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 9943 | int id) |
| 9944 | : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) { |
| 9945 | SetDrawsContent(true); |
| 9946 | } |
| 9947 | |
| 9948 | float last_maximum_animation_contents_scale_; |
| 9949 | }; |
| 9950 | |
| 9951 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 9952 | FakeImplProxy proxy; |
| 9953 | TestSharedBitmapManager shared_bitmap_manager; |
| 9954 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 9955 | gfx::Transform identity_matrix; |
| 9956 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 9957 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 9958 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 9959 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 9960 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 9961 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 9962 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 9963 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 9964 | |
| 9965 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 9966 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 9967 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 9968 | |
| 9969 | child->AddChild(grand_child.PassAs<LayerImpl>()); |
| 9970 | parent->AddChild(child.PassAs<LayerImpl>()); |
| 9971 | grand_parent->AddChild(parent.PassAs<LayerImpl>()); |
| 9972 | |
| 9973 | SetLayerPropertiesForTesting(grand_parent.get(), |
| 9974 | identity_matrix, |
| 9975 | gfx::PointF(), |
| 9976 | gfx::PointF(), |
| 9977 | gfx::Size(1, 2), |
| 9978 | true, |
| 9979 | false); |
| 9980 | SetLayerPropertiesForTesting(parent_raw, |
| 9981 | identity_matrix, |
| 9982 | gfx::PointF(), |
| 9983 | gfx::PointF(), |
| 9984 | gfx::Size(1, 2), |
| 9985 | true, |
| 9986 | false); |
| 9987 | SetLayerPropertiesForTesting(child_raw, |
| 9988 | identity_matrix, |
| 9989 | gfx::PointF(), |
| 9990 | gfx::PointF(), |
| 9991 | gfx::Size(1, 2), |
| 9992 | true, |
| 9993 | false); |
| 9994 | SetLayerPropertiesForTesting(grand_child_raw, |
| 9995 | identity_matrix, |
| 9996 | gfx::PointF(), |
| 9997 | gfx::PointF(), |
| 9998 | gfx::Size(1, 2), |
| 9999 | true, |
| 10000 | false); |
| 10001 | |
| 10002 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10003 | |
| 10004 | // No layers have animations. |
| 10005 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10006 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10007 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10008 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10009 | |
| 10010 | TransformOperations translation; |
| 10011 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 10012 | |
| 10013 | AddAnimatedTransformToLayer( |
| 10014 | parent_raw, 1.0, TransformOperations(), translation); |
| 10015 | |
| 10016 | // No layers have scale-affecting animations. |
| 10017 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10018 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10019 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10020 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10021 | |
| 10022 | TransformOperations scale; |
| 10023 | scale.AppendScale(5.f, 4.f, 3.f); |
| 10024 | |
| 10025 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 10026 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10027 | |
| 10028 | // Only |child| has a scale-affecting animation. |
| 10029 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10030 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10031 | EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale()); |
| 10032 | EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10033 | |
| 10034 | AddAnimatedTransformToLayer( |
| 10035 | grand_parent.get(), 1.0, TransformOperations(), scale); |
| 10036 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10037 | |
| 10038 | // |grand_parent| and |child| have scale-affecting animations. |
| 10039 | EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10040 | EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10041 | // We don't support combining animated scales from two nodes; 0.f means |
| 10042 | // that the maximum scale could not be computed. |
| 10043 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10044 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10045 | |
| 10046 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 10047 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10048 | |
| 10049 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
| 10050 | EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10051 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10052 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10053 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10054 | |
| 10055 | grand_parent->layer_animation_controller()->AbortAnimations( |
| 10056 | Animation::Transform); |
| 10057 | parent_raw->layer_animation_controller()->AbortAnimations( |
| 10058 | Animation::Transform); |
| 10059 | child_raw->layer_animation_controller()->AbortAnimations( |
| 10060 | Animation::Transform); |
| 10061 | |
| 10062 | TransformOperations perspective; |
| 10063 | perspective.AppendPerspective(10.f); |
| 10064 | |
| 10065 | AddAnimatedTransformToLayer( |
| 10066 | child_raw, 1.0, TransformOperations(), perspective); |
| 10067 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10068 | |
| 10069 | // |child| has a scale-affecting animation but computing the maximum of this |
| 10070 | // animation is not supported. |
| 10071 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10072 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10073 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10074 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10075 | |
| 10076 | child_raw->layer_animation_controller()->AbortAnimations( |
| 10077 | Animation::Transform); |
| 10078 | |
| 10079 | gfx::Transform scale_matrix; |
| 10080 | scale_matrix.Scale(1.f, 2.f); |
| 10081 | grand_parent->SetTransform(scale_matrix); |
| 10082 | parent_raw->SetTransform(scale_matrix); |
| 10083 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 10084 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10085 | |
| 10086 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 10087 | // animation with maximum scale 5.f. |
| 10088 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10089 | EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10090 | EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale()); |
| 10091 | EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10092 | |
| 10093 | gfx::Transform perspective_matrix; |
| 10094 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 10095 | child_raw->SetTransform(perspective_matrix); |
| 10096 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10097 | |
| 10098 | // |child| has a transform that's neither a translation nor a scale. |
| 10099 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10100 | EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10101 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10102 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10103 | |
| 10104 | parent_raw->SetTransform(perspective_matrix); |
| 10105 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10106 | |
| 10107 | // |parent| and |child| have transforms that are neither translations nor |
| 10108 | // scales. |
| 10109 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10110 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10111 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10112 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10113 | |
| 10114 | parent_raw->SetTransform(identity_matrix); |
| 10115 | child_raw->SetTransform(identity_matrix); |
| 10116 | grand_parent->SetTransform(perspective_matrix); |
| 10117 | |
| 10118 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10119 | |
| 10120 | // |grand_parent| has a transform that's neither a translation nor a scale. |
| 10121 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10122 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10123 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10124 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10125 | } |
| 10126 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10127 | } // namespace |
| 10128 | } // namespace cc |