[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() {} |
| 232 | virtual void PaintContents(SkCanvas* canvas, |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 233 | const gfx::Rect& clip, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 234 | gfx::RectF* opaque) OVERRIDE {} |
| 235 | virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} |
[email protected] | 1d96e03 | 2014-03-25 05:59:08 | [diff] [blame] | 236 | virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 237 | }; |
| 238 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 239 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 240 | ContentLayerClient* delegate) { |
| 241 | scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 242 | to_return->SetIsDrawable(true); |
| 243 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 246 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 247 | do { \ |
| 248 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 249 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 250 | } while (false) |
| 251 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 252 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 253 | // Sanity check: For layers positioned at zero, with zero size, |
| 254 | // and with identity transforms, then the draw transform, |
| 255 | // screen space transform, and the hierarchy passed on to children |
| 256 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 257 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 258 | scoped_refptr<Layer> parent = Layer::Create(); |
| 259 | scoped_refptr<Layer> child = Layer::Create(); |
| 260 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 261 | parent->AddChild(child); |
| 262 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 263 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 264 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 265 | host->SetRootLayer(parent); |
| 266 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 267 | gfx::Transform identity_matrix; |
| 268 | SetLayerPropertiesForTesting(parent.get(), |
| 269 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 270 | gfx::PointF(), |
| 271 | gfx::PointF(), |
| 272 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 273 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 274 | false); |
| 275 | SetLayerPropertiesForTesting(child.get(), |
| 276 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 277 | gfx::PointF(), |
| 278 | gfx::PointF(), |
| 279 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 280 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 281 | false); |
| 282 | SetLayerPropertiesForTesting(grand_child.get(), |
| 283 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 284 | gfx::PointF(), |
| 285 | gfx::PointF(), |
| 286 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 287 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 288 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 289 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 290 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 291 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 292 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 293 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 294 | child->screen_space_transform()); |
| 295 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 296 | grand_child->draw_transform()); |
| 297 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 298 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 299 | } |
| 300 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 301 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 302 | gfx::Transform identity_matrix; |
| 303 | scoped_refptr<Layer> layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 304 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 305 | scoped_refptr<Layer> root = Layer::Create(); |
| 306 | SetLayerPropertiesForTesting(root.get(), |
| 307 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 308 | gfx::PointF(), |
| 309 | gfx::PointF(), |
| 310 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 311 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 312 | false); |
| 313 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 314 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 315 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 316 | host->SetRootLayer(root); |
| 317 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 318 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 319 | // transform or the screenspace transform. |
| 320 | gfx::Transform translation_to_center; |
| 321 | translation_to_center.Translate(5.0, 6.0); |
| 322 | SetLayerPropertiesForTesting(layer.get(), |
| 323 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 324 | gfx::PointF(), |
| 325 | gfx::PointF(), |
| 326 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 327 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 328 | false); |
| 329 | ExecuteCalculateDrawProperties(root.get()); |
| 330 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 331 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 332 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 333 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 334 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 335 | // no effect on the transforms. |
| 336 | SetLayerPropertiesForTesting(layer.get(), |
| 337 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 338 | gfx::PointF(0.25f, 0.25f), |
| 339 | gfx::PointF(), |
| 340 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 341 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 342 | false); |
| 343 | ExecuteCalculateDrawProperties(root.get()); |
| 344 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 345 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 346 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 347 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 348 | // Case 4: A change in actual position affects both the draw transform and |
| 349 | // screen space transform. |
| 350 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 351 | position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 352 | SetLayerPropertiesForTesting(layer.get(), |
| 353 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 354 | gfx::PointF(0.25f, 0.25f), |
| 355 | gfx::PointF(0.f, 1.2f), |
| 356 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 357 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 358 | false); |
| 359 | ExecuteCalculateDrawProperties(root.get()); |
| 360 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 361 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 362 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 363 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 364 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 365 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 366 | // scale transform, because scale and translation are not commutative. |
| 367 | gfx::Transform layer_transform; |
| 368 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 369 | SetLayerPropertiesForTesting(layer.get(), |
| 370 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 371 | gfx::PointF(), |
| 372 | gfx::PointF(), |
| 373 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 374 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 375 | false); |
| 376 | ExecuteCalculateDrawProperties(root.get()); |
| 377 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 378 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 379 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 380 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 381 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 382 | gfx::Transform translation_to_anchor; |
| 383 | translation_to_anchor.Translate(5.0, 0.0); |
| 384 | gfx::Transform expected_result = |
| 385 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 386 | SetLayerPropertiesForTesting(layer.get(), |
| 387 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 388 | gfx::PointF(0.5f, 0.f), |
| 389 | gfx::PointF(), |
| 390 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 391 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 392 | false); |
| 393 | ExecuteCalculateDrawProperties(root.get()); |
| 394 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 395 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 396 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 397 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 398 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 399 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 400 | // it is still worth testing to detect accidental regressions. |
| 401 | expected_result = position_transform * translation_to_anchor * |
| 402 | layer_transform * Inverse(translation_to_anchor); |
| 403 | SetLayerPropertiesForTesting(layer.get(), |
| 404 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 405 | gfx::PointF(0.5f, 0.f), |
| 406 | gfx::PointF(0.f, 1.2f), |
| 407 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 408 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 409 | false); |
| 410 | ExecuteCalculateDrawProperties(root.get()); |
| 411 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 412 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 413 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 414 | } |
| 415 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 416 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 417 | const gfx::Vector2d kScrollOffset(50, 100); |
| 418 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 419 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 420 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 421 | -kScrollOffset.y()); |
| 422 | const float kPageScale = 0.888f; |
| 423 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 424 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 425 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 426 | TestSharedBitmapManager shared_bitmap_manager; |
| 427 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 428 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 429 | gfx::Transform identity_matrix; |
| 430 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 431 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 432 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 433 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 434 | kPageScale * kDeviceScale); |
| 435 | SetLayerPropertiesForTesting(sublayer, |
| 436 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 437 | gfx::Point(), |
| 438 | gfx::PointF(), |
| 439 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 440 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 441 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 442 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 443 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 444 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 445 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 446 | SetLayerPropertiesForTesting(scroll_layer, |
| 447 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 448 | gfx::PointF(), |
[email protected] | 4ec78f8 | 2013-07-11 18:45:47 | [diff] [blame] | 449 | gfx::PointF(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 450 | gfx::Size(10, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 451 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 452 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 453 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 454 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 455 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 456 | |
| 457 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 458 | clip_layer->SetBounds( |
| 459 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 460 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 461 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 462 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 463 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 464 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 465 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
| 466 | clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
| 467 | scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 468 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 469 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
| 470 | SetLayerPropertiesForTesting(root.get(), |
| 471 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 472 | gfx::PointF(), |
| 473 | gfx::PointF(), |
| 474 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 475 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 476 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 477 | root->AddChild(clip_layer_scoped_ptr.Pass()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 478 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 479 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 480 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 481 | gfx::Transform expected_transform = identity_matrix; |
| 482 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 483 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 484 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 485 | MathUtil::Round(sub_layer_screen_position.y())); |
| 486 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 487 | sublayer->draw_transform()); |
| 488 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 489 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 490 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 491 | gfx::Transform arbitrary_translate; |
| 492 | const float kTranslateX = 10.6f; |
| 493 | const float kTranslateY = 20.6f; |
| 494 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
| 495 | SetLayerPropertiesForTesting(scroll_layer, |
| 496 | arbitrary_translate, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 497 | gfx::PointF(), |
[email protected] | 4ec78f8 | 2013-07-11 18:45:47 | [diff] [blame] | 498 | gfx::PointF(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 499 | gfx::Size(10, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 500 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 501 | false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 502 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 503 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 504 | expected_transform.MakeIdentity(); |
| 505 | expected_transform.Translate( |
| 506 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 507 | sub_layer_screen_position.x()), |
| 508 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 509 | sub_layer_screen_position.y())); |
| 510 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 511 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 512 | } |
| 513 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 514 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 515 | gfx::Transform identity_matrix; |
| 516 | scoped_refptr<Layer> root = Layer::Create(); |
| 517 | scoped_refptr<Layer> parent = Layer::Create(); |
| 518 | scoped_refptr<Layer> child = Layer::Create(); |
| 519 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 520 | root->AddChild(parent); |
| 521 | parent->AddChild(child); |
| 522 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 523 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 524 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 525 | host->SetRootLayer(root); |
| 526 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 527 | // One-time setup of root layer |
| 528 | SetLayerPropertiesForTesting(root.get(), |
| 529 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 530 | gfx::PointF(), |
| 531 | gfx::PointF(), |
| 532 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 533 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 534 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 535 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 536 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 537 | SetLayerPropertiesForTesting(parent.get(), |
| 538 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 539 | gfx::PointF(0.25f, 0.25f), |
| 540 | gfx::PointF(), |
| 541 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 542 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 543 | false); |
| 544 | SetLayerPropertiesForTesting(child.get(), |
| 545 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 546 | gfx::PointF(), |
| 547 | gfx::PointF(), |
| 548 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 549 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 550 | false); |
| 551 | SetLayerPropertiesForTesting(grand_child.get(), |
| 552 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 553 | gfx::PointF(), |
| 554 | gfx::PointF(), |
| 555 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 556 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 557 | false); |
| 558 | ExecuteCalculateDrawProperties(root.get()); |
| 559 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 560 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 561 | child->screen_space_transform()); |
| 562 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 563 | grand_child->draw_transform()); |
| 564 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 565 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 566 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 567 | // Case 2: parent's position affects child and grand_child. |
| 568 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 569 | parent_position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 570 | SetLayerPropertiesForTesting(parent.get(), |
| 571 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 572 | gfx::PointF(0.25f, 0.25f), |
| 573 | gfx::PointF(0.f, 1.2f), |
| 574 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 575 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 576 | false); |
| 577 | SetLayerPropertiesForTesting(child.get(), |
| 578 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 579 | gfx::PointF(), |
| 580 | gfx::PointF(), |
| 581 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 582 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 583 | false); |
| 584 | SetLayerPropertiesForTesting(grand_child.get(), |
| 585 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 586 | gfx::PointF(), |
| 587 | gfx::PointF(), |
| 588 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 589 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 590 | false); |
| 591 | ExecuteCalculateDrawProperties(root.get()); |
| 592 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 593 | child->draw_transform()); |
| 594 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 595 | child->screen_space_transform()); |
| 596 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 597 | grand_child->draw_transform()); |
| 598 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 599 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 600 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 601 | // Case 3: parent's local transform affects child and grandchild |
| 602 | gfx::Transform parent_layer_transform; |
| 603 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 604 | gfx::Transform parent_translation_to_anchor; |
| 605 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 606 | gfx::Transform parent_composite_transform = |
| 607 | parent_translation_to_anchor * parent_layer_transform * |
| 608 | Inverse(parent_translation_to_anchor); |
| 609 | SetLayerPropertiesForTesting(parent.get(), |
| 610 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 611 | gfx::PointF(0.25f, 0.25f), |
| 612 | gfx::PointF(), |
| 613 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 614 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 615 | false); |
| 616 | SetLayerPropertiesForTesting(child.get(), |
| 617 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 618 | gfx::PointF(), |
| 619 | gfx::PointF(), |
| 620 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 621 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 622 | false); |
| 623 | SetLayerPropertiesForTesting(grand_child.get(), |
| 624 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 625 | gfx::PointF(), |
| 626 | gfx::PointF(), |
| 627 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 628 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 629 | false); |
| 630 | ExecuteCalculateDrawProperties(root.get()); |
| 631 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 632 | child->draw_transform()); |
| 633 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 634 | child->screen_space_transform()); |
| 635 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 636 | grand_child->draw_transform()); |
| 637 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 638 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 641 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 642 | scoped_refptr<Layer> root = Layer::Create(); |
| 643 | scoped_refptr<Layer> parent = Layer::Create(); |
| 644 | scoped_refptr<Layer> child = Layer::Create(); |
| 645 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 646 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 647 | root->AddChild(parent); |
| 648 | parent->AddChild(child); |
| 649 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 650 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 651 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 652 | host->SetRootLayer(root); |
| 653 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 654 | // One-time setup of root layer |
| 655 | gfx::Transform identity_matrix; |
| 656 | SetLayerPropertiesForTesting(root.get(), |
| 657 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 658 | gfx::PointF(), |
| 659 | gfx::PointF(), |
| 660 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 661 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 662 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 663 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 664 | // Child is set up so that a new render surface should be created. |
| 665 | child->SetOpacity(0.5f); |
| 666 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 667 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 668 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 669 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 670 | gfx::Transform parent_translation_to_anchor; |
| 671 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 672 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 673 | gfx::Transform parent_composite_transform = |
| 674 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 675 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 676 | gfx::Vector2dF parent_composite_scale = |
| 677 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 678 | 1.f); |
| 679 | gfx::Transform surface_sublayer_transform; |
| 680 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 681 | parent_composite_scale.y()); |
| 682 | gfx::Transform surface_sublayer_composite_transform = |
| 683 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 684 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 685 | // Child's render surface should not exist yet. |
| 686 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 687 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 688 | SetLayerPropertiesForTesting(parent.get(), |
| 689 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 690 | gfx::PointF(0.25f, 0.25f), |
| 691 | gfx::PointF(), |
| 692 | gfx::Size(100, 120), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 693 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 694 | false); |
| 695 | SetLayerPropertiesForTesting(child.get(), |
| 696 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 697 | gfx::PointF(), |
| 698 | gfx::PointF(), |
| 699 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 700 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 701 | false); |
| 702 | SetLayerPropertiesForTesting(grand_child.get(), |
| 703 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 704 | gfx::PointF(), |
| 705 | gfx::PointF(), |
| 706 | gfx::Size(8, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 707 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 708 | false); |
| 709 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 711 | // Render surface should have been created now. |
| 712 | ASSERT_TRUE(child->render_surface()); |
| 713 | ASSERT_EQ(child, child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 714 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 715 | // The child layer's draw transform should refer to its new render surface. |
| 716 | // The screen-space transform, however, should still refer to the root. |
| 717 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 718 | child->draw_transform()); |
| 719 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 720 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 721 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 722 | // Because the grand_child is the only drawable content, the child's render |
| 723 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 724 | // surface's subtree is drawn must be removed from the composite transform. |
| 725 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 726 | surface_sublayer_composite_transform, |
| 727 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 728 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 729 | // The screen space is the same as the target since the child surface draws |
| 730 | // into the root. |
| 731 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 732 | surface_sublayer_composite_transform, |
| 733 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 734 | } |
| 735 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 736 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 737 | scoped_refptr<Layer> root = Layer::Create(); |
| 738 | scoped_refptr<Layer> parent = Layer::Create(); |
| 739 | scoped_refptr<Layer> child = Layer::Create(); |
| 740 | scoped_refptr<Layer> child_replica = Layer::Create(); |
| 741 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 742 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 743 | root->AddChild(parent); |
| 744 | parent->AddChild(child); |
| 745 | child->AddChild(grand_child); |
| 746 | child->SetReplicaLayer(child_replica.get()); |
| 747 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 748 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 749 | host->SetRootLayer(root); |
| 750 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 751 | // One-time setup of root layer |
| 752 | gfx::Transform identity_matrix; |
| 753 | SetLayerPropertiesForTesting(root.get(), |
| 754 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 755 | gfx::PointF(), |
| 756 | gfx::PointF(), |
| 757 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 758 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 759 | false); |
| 760 | |
| 761 | // Child is set up so that a new render surface should be created. |
| 762 | child->SetOpacity(0.5f); |
| 763 | |
| 764 | gfx::Transform parent_layer_transform; |
| 765 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 766 | gfx::Transform parent_translation_to_anchor; |
| 767 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 768 | gfx::Transform parent_composite_transform = |
| 769 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 770 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 771 | gfx::Transform replica_layer_transform; |
| 772 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 773 | gfx::Vector2dF parent_composite_scale = |
| 774 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 775 | 1.f); |
| 776 | gfx::Transform surface_sublayer_transform; |
| 777 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 778 | parent_composite_scale.y()); |
| 779 | gfx::Transform replica_composite_transform = |
| 780 | parent_composite_transform * replica_layer_transform * |
| 781 | Inverse(surface_sublayer_transform); |
| 782 | |
| 783 | // Child's render surface should not exist yet. |
| 784 | ASSERT_FALSE(child->render_surface()); |
| 785 | |
| 786 | SetLayerPropertiesForTesting(parent.get(), |
| 787 | parent_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 788 | gfx::PointF(0.25f, 0.25f), |
| 789 | gfx::PointF(), |
| 790 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 791 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 792 | false); |
| 793 | SetLayerPropertiesForTesting(child.get(), |
| 794 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 795 | gfx::PointF(), |
| 796 | gfx::PointF(), |
| 797 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 798 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 799 | false); |
| 800 | SetLayerPropertiesForTesting(grand_child.get(), |
| 801 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 802 | gfx::PointF(), |
| 803 | gfx::PointF(-0.5f, -0.5f), |
| 804 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 805 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 806 | false); |
| 807 | SetLayerPropertiesForTesting(child_replica.get(), |
| 808 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 809 | gfx::PointF(), |
| 810 | gfx::PointF(), |
| 811 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 812 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 813 | false); |
| 814 | ExecuteCalculateDrawProperties(root.get()); |
| 815 | |
| 816 | // Render surface should have been created now. |
| 817 | ASSERT_TRUE(child->render_surface()); |
| 818 | ASSERT_EQ(child, child->render_target()); |
| 819 | |
| 820 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 821 | replica_composite_transform, |
| 822 | child->render_target()->render_surface()->replica_draw_transform()); |
| 823 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 824 | child->render_target() |
| 825 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 826 | ->replica_screen_space_transform()); |
| 827 | } |
| 828 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 829 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 830 | // This test creates a more complex tree and verifies it all at once. This |
| 831 | // covers the following cases: |
| 832 | // - layers that are described w.r.t. a render surface: should have draw |
| 833 | // transforms described w.r.t. that surface |
| 834 | // - A render surface described w.r.t. an ancestor render surface: should |
| 835 | // have a draw transform described w.r.t. that ancestor surface |
| 836 | // - Replicas of a render surface are described w.r.t. the replica's |
| 837 | // transform around its anchor, along with the surface itself. |
| 838 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 839 | // a render surface that is described w.r.t. an ancestor render surface. |
| 840 | // - verifying that each layer has a reference to the correct render surface |
| 841 | // and render target values. |
| 842 | |
| 843 | scoped_refptr<Layer> root = Layer::Create(); |
| 844 | scoped_refptr<Layer> parent = Layer::Create(); |
| 845 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 846 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 847 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 848 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 849 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 850 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); |
| 851 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); |
| 852 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 853 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 854 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 855 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 856 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 857 | root->AddChild(parent); |
| 858 | parent->AddChild(render_surface1); |
| 859 | parent->AddChild(child_of_root); |
| 860 | render_surface1->AddChild(child_of_rs1); |
| 861 | render_surface1->AddChild(render_surface2); |
| 862 | render_surface2->AddChild(child_of_rs2); |
| 863 | child_of_root->AddChild(grand_child_of_root); |
| 864 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 865 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 866 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 867 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 868 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 869 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 870 | host->SetRootLayer(root); |
| 871 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 872 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 873 | // to have a new render surface. |
| 874 | render_surface1->SetOpacity(0.5f); |
| 875 | render_surface2->SetOpacity(0.33f); |
| 876 | |
| 877 | // One-time setup of root layer |
| 878 | gfx::Transform identity_matrix; |
| 879 | SetLayerPropertiesForTesting(root.get(), |
| 880 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 881 | gfx::PointF(), |
| 882 | gfx::PointF(), |
| 883 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 884 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 885 | false); |
| 886 | |
| 887 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 888 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 889 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 890 | gfx::Transform translation_to_anchor; |
| 891 | translation_to_anchor.Translate(2.5, 0.0); |
| 892 | gfx::Transform layer_transform; |
| 893 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 894 | gfx::Transform replica_layer_transform; |
| 895 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 896 | |
| 897 | gfx::Transform A = |
| 898 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 899 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 900 | Inverse(translation_to_anchor); |
| 901 | |
| 902 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 903 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 904 | gfx::Transform surface1_sublayer_transform; |
| 905 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 906 | surface1_parent_transform_scale.y()); |
| 907 | |
| 908 | // SS1 = transform given to the subtree of render_surface1 |
| 909 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 910 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 911 | // the owning layer |
| 912 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 913 | |
| 914 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 915 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 916 | gfx::Transform surface2_sublayer_transform; |
| 917 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 918 | surface2_parent_transform_scale.y()); |
| 919 | |
| 920 | // SS2 = transform given to the subtree of render_surface2 |
| 921 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 922 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 923 | // the owning layer |
| 924 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 925 | |
| 926 | SetLayerPropertiesForTesting(parent.get(), |
| 927 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 928 | gfx::PointF(0.25f, 0.f), |
| 929 | gfx::PointF(), |
| 930 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 931 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 932 | false); |
| 933 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 934 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 935 | gfx::PointF(0.25f, 0.f), |
| 936 | gfx::PointF(), |
| 937 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 938 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 939 | false); |
| 940 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 941 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 942 | gfx::PointF(0.25f, 0.f), |
| 943 | gfx::PointF(), |
| 944 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 945 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 946 | false); |
| 947 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 948 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 949 | gfx::PointF(0.25f, 0.f), |
| 950 | gfx::PointF(), |
| 951 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 952 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 953 | false); |
| 954 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 955 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 956 | gfx::PointF(0.25f, 0.f), |
| 957 | gfx::PointF(), |
| 958 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 959 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 960 | false); |
| 961 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 962 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 963 | gfx::PointF(0.25f, 0.f), |
| 964 | gfx::PointF(), |
| 965 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 966 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 967 | false); |
| 968 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 969 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 970 | gfx::PointF(0.25f, 0.f), |
| 971 | gfx::PointF(), |
| 972 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 973 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 974 | false); |
| 975 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 976 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 977 | gfx::PointF(0.25f, 0.f), |
| 978 | gfx::PointF(), |
| 979 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 980 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 981 | false); |
| 982 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 983 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 984 | gfx::PointF(0.25f, 0.f), |
| 985 | gfx::PointF(), |
| 986 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 987 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 988 | false); |
| 989 | SetLayerPropertiesForTesting(replica_of_rs1.get(), |
| 990 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 991 | gfx::PointF(0.25f, 0.f), |
| 992 | gfx::PointF(), |
| 993 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 994 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 995 | false); |
| 996 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 997 | replica_layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 998 | gfx::PointF(0.25f, 0.f), |
| 999 | gfx::PointF(), |
| 1000 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1001 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1002 | false); |
| 1003 | |
| 1004 | ExecuteCalculateDrawProperties(root.get()); |
| 1005 | |
| 1006 | // Only layers that are associated with render surfaces should have an actual |
| 1007 | // RenderSurface() value. |
| 1008 | ASSERT_TRUE(root->render_surface()); |
| 1009 | ASSERT_FALSE(child_of_root->render_surface()); |
| 1010 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 1011 | |
| 1012 | ASSERT_TRUE(render_surface1->render_surface()); |
| 1013 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 1014 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 1015 | |
| 1016 | ASSERT_TRUE(render_surface2->render_surface()); |
| 1017 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 1018 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 1019 | |
| 1020 | // Verify all render target accessors |
| 1021 | EXPECT_EQ(root, parent->render_target()); |
| 1022 | EXPECT_EQ(root, child_of_root->render_target()); |
| 1023 | EXPECT_EQ(root, grand_child_of_root->render_target()); |
| 1024 | |
| 1025 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 1026 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 1027 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 1028 | |
| 1029 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 1030 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 1031 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 1032 | |
| 1033 | // Verify layer draw transforms note that draw transforms are described with |
| 1034 | // respect to the nearest ancestor render surface but screen space transforms |
| 1035 | // are described with respect to the root. |
| 1036 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1037 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); |
| 1038 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1039 | grand_child_of_root->draw_transform()); |
| 1040 | |
| 1041 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1042 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); |
| 1043 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1044 | grand_child_of_rs1->draw_transform()); |
| 1045 | |
| 1046 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1047 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); |
| 1048 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1049 | grand_child_of_rs2->draw_transform()); |
| 1050 | |
| 1051 | // Verify layer screen-space transforms |
| 1052 | // |
| 1053 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1054 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1055 | child_of_root->screen_space_transform()); |
| 1056 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1057 | A * A * A, grand_child_of_root->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1058 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1059 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1060 | render_surface1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1061 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1062 | child_of_rs1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1063 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1064 | grand_child_of_rs1->screen_space_transform()); |
| 1065 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1066 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1067 | render_surface2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1068 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1069 | child_of_rs2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1070 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1071 | grand_child_of_rs2->screen_space_transform()); |
| 1072 | |
| 1073 | // Verify render surface transforms. |
| 1074 | // |
| 1075 | // Draw transform of render surface 1 is described with respect to root. |
| 1076 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1077 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1078 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1079 | A * R * S1, render_surface1->render_surface()->replica_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 * A * S1, render_surface1->render_surface()->screen_space_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 * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1084 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 1085 | // Draw transform of render surface 2 is described with respect to render |
| 1086 | // surface 1. |
| 1087 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1088 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1089 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1090 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1091 | render_surface2->render_surface()->replica_draw_transform()); |
| 1092 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1093 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1094 | render_surface2->render_surface()->screen_space_transform()); |
| 1095 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1096 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1097 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 1098 | |
| 1099 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1100 | // is expected that we correctly set up transforms so that the y-component of |
| 1101 | // the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1102 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 1103 | EXPECT_FLOAT_EQ(2.0, |
| 1104 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1105 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1106 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1107 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1108 | EXPECT_FLOAT_EQ(2.0, |
| 1109 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 1110 | EXPECT_FLOAT_EQ(3.0, |
| 1111 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1112 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1113 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1114 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1115 | EXPECT_FLOAT_EQ(3.0, |
| 1116 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 1117 | EXPECT_FLOAT_EQ(4.0, |
| 1118 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1119 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1120 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1121 | } |
| 1122 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1123 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1124 | // For layers that flatten their subtree, there should be an orthographic |
| 1125 | // projection (for x and y values) in the middle of the transform sequence. |
| 1126 | // Note that the way the code is currently implemented, it is not expected to |
| 1127 | // use a canonical orthographic projection. |
| 1128 | |
| 1129 | scoped_refptr<Layer> root = Layer::Create(); |
| 1130 | scoped_refptr<Layer> child = Layer::Create(); |
| 1131 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1132 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1133 | |
| 1134 | gfx::Transform rotation_about_y_axis; |
| 1135 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1136 | |
| 1137 | const gfx::Transform identity_matrix; |
| 1138 | SetLayerPropertiesForTesting(root.get(), |
| 1139 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1140 | gfx::PointF(), |
| 1141 | gfx::PointF(), |
| 1142 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1143 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1144 | false); |
| 1145 | SetLayerPropertiesForTesting(child.get(), |
| 1146 | rotation_about_y_axis, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1147 | gfx::PointF(), |
| 1148 | gfx::PointF(), |
| 1149 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1150 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1151 | false); |
| 1152 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1153 | rotation_about_y_axis, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1154 | gfx::PointF(), |
| 1155 | gfx::PointF(), |
| 1156 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1157 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1158 | false); |
| 1159 | |
| 1160 | root->AddChild(child); |
| 1161 | child->AddChild(grand_child); |
| 1162 | child->SetForceRenderSurface(true); |
| 1163 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1164 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1165 | host->SetRootLayer(root); |
| 1166 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1167 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1168 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1169 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1170 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1171 | |
| 1172 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1173 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1174 | gfx::Transform expected_grand_child_draw_transform = |
| 1175 | rotation_about_y_axis; // draws onto child's render surface |
| 1176 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1177 | flattened_rotation_about_y.FlattenTo2d(); |
| 1178 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1179 | flattened_rotation_about_y * rotation_about_y_axis; |
| 1180 | |
| 1181 | ExecuteCalculateDrawProperties(root.get()); |
| 1182 | |
| 1183 | // The child's draw transform should have been taken by its surface. |
| 1184 | ASSERT_TRUE(child->render_surface()); |
| 1185 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1186 | child->render_surface()->draw_transform()); |
| 1187 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1188 | expected_child_screen_space_transform, |
| 1189 | child->render_surface()->screen_space_transform()); |
| 1190 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1191 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1192 | child->screen_space_transform()); |
| 1193 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1194 | grand_child->draw_transform()); |
| 1195 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1196 | grand_child->screen_space_transform()); |
| 1197 | } |
| 1198 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1199 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1200 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1201 | // skipping a necessary translation. Without that translation, the coordinate |
| 1202 | // space of the layer's draw transform is incorrect. |
| 1203 | // |
| 1204 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1205 | // but if that layer becomes a render surface, then its draw transform is |
| 1206 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1207 | // incorrectly as a result. |
| 1208 | |
| 1209 | scoped_refptr<Layer> root = Layer::Create(); |
| 1210 | scoped_refptr<Layer> child = Layer::Create(); |
| 1211 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1212 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1213 | |
| 1214 | // The child height is zero, but has non-zero width that should be accounted |
| 1215 | // for while computing draw transforms. |
| 1216 | const gfx::Transform identity_matrix; |
| 1217 | SetLayerPropertiesForTesting(root.get(), |
| 1218 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1219 | gfx::PointF(), |
| 1220 | gfx::PointF(), |
| 1221 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1222 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1223 | false); |
| 1224 | SetLayerPropertiesForTesting(child.get(), |
| 1225 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1226 | gfx::PointF(), |
| 1227 | gfx::PointF(), |
| 1228 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1229 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1230 | false); |
| 1231 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1232 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1233 | gfx::PointF(), |
| 1234 | gfx::PointF(), |
| 1235 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1236 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1237 | false); |
| 1238 | |
| 1239 | root->AddChild(child); |
| 1240 | child->AddChild(grand_child); |
| 1241 | child->SetForceRenderSurface(true); |
| 1242 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1243 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1244 | host->SetRootLayer(root); |
| 1245 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1246 | ExecuteCalculateDrawProperties(root.get()); |
| 1247 | |
| 1248 | ASSERT_TRUE(child->render_surface()); |
| 1249 | // This is the real test, the rest are sanity checks. |
| 1250 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1251 | child->render_surface()->draw_transform()); |
| 1252 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1253 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1254 | grand_child->draw_transform()); |
| 1255 | } |
| 1256 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1257 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1258 | // Transformations applied at the root of the tree should be forwarded |
| 1259 | // to child layers instead of applied to the root RenderSurface. |
| 1260 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1261 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 1262 | new LayerWithForcedDrawsContent; |
| 1263 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1264 | new LayerWithForcedDrawsContent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1265 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1266 | root->AddChild(child); |
| 1267 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1268 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1269 | host->SetRootLayer(root); |
| 1270 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1271 | SetLayerPropertiesForTesting(root.get(), |
| 1272 | identity_matrix, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1273 | gfx::PointF(), |
| 1274 | gfx::PointF(), |
| 1275 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1276 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1277 | false); |
| 1278 | SetLayerPropertiesForTesting(child.get(), |
| 1279 | identity_matrix, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1280 | gfx::PointF(), |
| 1281 | gfx::PointF(), |
| 1282 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1283 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1284 | false); |
| 1285 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1286 | gfx::Transform translate; |
| 1287 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1288 | { |
| 1289 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1290 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1291 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1292 | inputs.can_adjust_raster_scales = true; |
| 1293 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1294 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1295 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1296 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1297 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1298 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1299 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1300 | |
| 1301 | gfx::Transform scale; |
| 1302 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1303 | { |
| 1304 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1305 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1306 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
| 1307 | inputs.can_adjust_raster_scales = true; |
| 1308 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1309 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1310 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1311 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1312 | EXPECT_EQ(2.f, root->last_device_scale_factor()); |
| 1313 | EXPECT_EQ(2.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1314 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1315 | |
| 1316 | gfx::Transform rotate; |
| 1317 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1318 | { |
| 1319 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1320 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1321 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
| 1322 | inputs.can_adjust_raster_scales = true; |
| 1323 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1324 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1325 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1326 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1327 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1328 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1329 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1330 | |
| 1331 | gfx::Transform composite; |
| 1332 | composite.ConcatTransform(translate); |
| 1333 | composite.ConcatTransform(scale); |
| 1334 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1335 | { |
| 1336 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1337 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1338 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
| 1339 | inputs.can_adjust_raster_scales = true; |
| 1340 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1341 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1342 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1343 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1344 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1345 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1346 | // Verify it composes correctly with device scale. |
| 1347 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1348 | |
| 1349 | { |
| 1350 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1351 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1352 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1353 | inputs.device_scale_factor = device_scale_factor; |
| 1354 | inputs.can_adjust_raster_scales = true; |
| 1355 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1356 | gfx::Transform device_scaled_translate = translate; |
| 1357 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1358 | EXPECT_EQ(device_scaled_translate, |
| 1359 | root->draw_properties().target_space_transform); |
| 1360 | EXPECT_EQ(device_scaled_translate, |
| 1361 | child->draw_properties().target_space_transform); |
| 1362 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1363 | EXPECT_EQ(device_scale_factor, root->last_device_scale_factor()); |
| 1364 | EXPECT_EQ(device_scale_factor, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1365 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1366 | |
| 1367 | // Verify it composes correctly with page scale. |
| 1368 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1369 | |
| 1370 | { |
| 1371 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1372 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1373 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1374 | inputs.page_scale_factor = page_scale_factor; |
| 1375 | inputs.page_scale_application_layer = root.get(); |
| 1376 | inputs.can_adjust_raster_scales = true; |
| 1377 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1378 | gfx::Transform page_scaled_translate = translate; |
| 1379 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
| 1380 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1381 | EXPECT_EQ(page_scaled_translate, |
| 1382 | child->draw_properties().target_space_transform); |
| 1383 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1384 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1385 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1386 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1387 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1388 | // Verify that it composes correctly with transforms directly on root layer. |
| 1389 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1390 | |
| 1391 | { |
| 1392 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1393 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1394 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
| 1395 | inputs.can_adjust_raster_scales = true; |
| 1396 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1397 | gfx::Transform compositeSquared = composite; |
| 1398 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1399 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1400 | compositeSquared, root->draw_properties().target_space_transform); |
| 1401 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1402 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1403 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1404 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1405 | } |
| 1406 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1407 | TEST_F(LayerTreeHostCommonTest, |
| 1408 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1409 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1410 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1411 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1412 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1413 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1414 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1415 | host->SetRootLayer(parent); |
| 1416 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1417 | const gfx::Transform identity_matrix; |
| 1418 | SetLayerPropertiesForTesting(parent.get(), |
| 1419 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1420 | gfx::PointF(), |
| 1421 | gfx::PointF(), |
| 1422 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1423 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1424 | false); |
| 1425 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1426 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1427 | gfx::PointF(), |
| 1428 | gfx::PointF(), |
| 1429 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1430 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1431 | false); |
| 1432 | SetLayerPropertiesForTesting(child.get(), |
| 1433 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1434 | gfx::PointF(), |
| 1435 | gfx::PointF(30.f, 30.f), |
| 1436 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1437 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1438 | false); |
| 1439 | |
| 1440 | parent->AddChild(render_surface1); |
| 1441 | parent->SetMasksToBounds(true); |
| 1442 | render_surface1->AddChild(child); |
| 1443 | render_surface1->SetForceRenderSurface(true); |
| 1444 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1445 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1446 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1447 | parent.get(), |
| 1448 | parent->bounds(), |
| 1449 | gfx::Transform(), |
| 1450 | &render_surface_layer_list); |
| 1451 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1452 | |
| 1453 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1454 | // the intermediate render surface should not be listed here, even if it was |
| 1455 | // forced to be created. Render surfaces without children or visible content |
| 1456 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1457 | // of size 0). |
| 1458 | ASSERT_TRUE(parent->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1459 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1460 | } |
| 1461 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1462 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1463 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1464 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1465 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1466 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1467 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1468 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1469 | host->SetRootLayer(parent); |
| 1470 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1471 | const gfx::Transform identity_matrix; |
| 1472 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1473 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1474 | gfx::PointF(), |
| 1475 | gfx::PointF(), |
| 1476 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1477 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1478 | false); |
| 1479 | SetLayerPropertiesForTesting(child.get(), |
| 1480 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1481 | gfx::PointF(), |
| 1482 | gfx::PointF(), |
| 1483 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1484 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1485 | false); |
| 1486 | |
| 1487 | parent->AddChild(render_surface1); |
| 1488 | render_surface1->AddChild(child); |
| 1489 | render_surface1->SetForceRenderSurface(true); |
| 1490 | render_surface1->SetOpacity(0.f); |
| 1491 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1492 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1493 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1494 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1495 | inputs.can_adjust_raster_scales = true; |
| 1496 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1497 | |
| 1498 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1499 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1500 | // have been extended by the children. |
| 1501 | ASSERT_TRUE(parent->render_surface()); |
| 1502 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1503 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1504 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1505 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1506 | } |
| 1507 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1508 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1509 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1510 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1511 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1512 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1513 | render_surface1->SetForceRenderSurface(true); |
| 1514 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1515 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1516 | host->SetRootLayer(parent); |
| 1517 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1518 | const gfx::Transform identity_matrix; |
| 1519 | SetLayerPropertiesForTesting(parent.get(), |
| 1520 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1521 | gfx::PointF(), |
| 1522 | gfx::PointF(), |
| 1523 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1524 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1525 | false); |
| 1526 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1527 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1528 | gfx::PointF(), |
| 1529 | gfx::PointF(), |
| 1530 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1531 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1532 | false); |
| 1533 | SetLayerPropertiesForTesting(child.get(), |
| 1534 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1535 | gfx::PointF(), |
| 1536 | gfx::PointF(), |
| 1537 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1538 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1539 | false); |
| 1540 | |
| 1541 | parent->AddChild(render_surface1); |
| 1542 | render_surface1->AddChild(child); |
| 1543 | |
| 1544 | // Sanity check before the actual test |
| 1545 | EXPECT_FALSE(parent->render_surface()); |
| 1546 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1547 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1548 | { |
| 1549 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1550 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1551 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1552 | inputs.can_adjust_raster_scales = true; |
| 1553 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1554 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1555 | // The root layer always creates a render surface |
| 1556 | EXPECT_TRUE(parent->render_surface()); |
| 1557 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1558 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1559 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1560 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1561 | { |
| 1562 | RenderSurfaceLayerList render_surface_layer_list; |
| 1563 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1564 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1565 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1566 | inputs.can_adjust_raster_scales = true; |
| 1567 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1568 | EXPECT_TRUE(parent->render_surface()); |
| 1569 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1570 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1571 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1572 | } |
| 1573 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1574 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1575 | // The entire subtree of layers that are outside the clip rect should be |
| 1576 | // culled away, and should not affect the render_surface_layer_list. |
| 1577 | // |
| 1578 | // The test tree is set up as follows: |
| 1579 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1580 | // that have something to draw. |
| 1581 | // - parent is a large container layer. |
| 1582 | // - child has masksToBounds=true to cause clipping. |
| 1583 | // - grand_child is positioned outside of the child's bounds |
| 1584 | // - great_grand_child is also kept outside child's bounds. |
| 1585 | // |
| 1586 | // In this configuration, grand_child and great_grand_child are completely |
| 1587 | // outside the clip rect, and they should never get scheduled on the list of |
| 1588 | // render surfaces. |
| 1589 | // |
| 1590 | |
| 1591 | const gfx::Transform identity_matrix; |
| 1592 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1593 | scoped_refptr<Layer> child = Layer::Create(); |
| 1594 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1595 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1596 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1597 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1598 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1599 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1600 | parent->AddChild(child); |
| 1601 | child->AddChild(grand_child); |
| 1602 | grand_child->AddChild(great_grand_child); |
| 1603 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1604 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1605 | host->SetRootLayer(parent); |
| 1606 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1607 | // leaf_node1 ensures that parent and child are kept on the |
| 1608 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1609 | // should be clipped. |
| 1610 | child->AddChild(leaf_node1); |
| 1611 | great_grand_child->AddChild(leaf_node2); |
| 1612 | |
| 1613 | SetLayerPropertiesForTesting(parent.get(), |
| 1614 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1615 | gfx::PointF(), |
| 1616 | gfx::PointF(), |
| 1617 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1618 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1619 | false); |
| 1620 | SetLayerPropertiesForTesting(child.get(), |
| 1621 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1622 | gfx::PointF(), |
| 1623 | gfx::PointF(), |
| 1624 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1625 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1626 | false); |
| 1627 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1628 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1629 | gfx::PointF(), |
| 1630 | gfx::PointF(45.f, 45.f), |
| 1631 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1632 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1633 | false); |
| 1634 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1635 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1636 | gfx::PointF(), |
| 1637 | gfx::PointF(), |
| 1638 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1639 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1640 | false); |
| 1641 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1642 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1643 | gfx::PointF(), |
| 1644 | gfx::PointF(), |
| 1645 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1646 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1647 | false); |
| 1648 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1649 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1650 | gfx::PointF(), |
| 1651 | gfx::PointF(), |
| 1652 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1653 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1654 | false); |
| 1655 | |
| 1656 | child->SetMasksToBounds(true); |
| 1657 | child->SetOpacity(0.4f); |
| 1658 | child->SetForceRenderSurface(true); |
| 1659 | grand_child->SetOpacity(0.5f); |
| 1660 | great_grand_child->SetOpacity(0.4f); |
| 1661 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1662 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1663 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1664 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1665 | inputs.can_adjust_raster_scales = true; |
| 1666 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1667 | |
| 1668 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1669 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1670 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1671 | } |
| 1672 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1673 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1674 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1675 | // of the surface. When the render surface is animating its transforms, then |
| 1676 | // the content rect's position in the clip rect is not defined on the main |
| 1677 | // thread, and its content rect should not be clipped. |
| 1678 | |
| 1679 | // The test tree is set up as follows: |
| 1680 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1681 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1682 | // the parent. |
| 1683 | // - grand_child is a render surface, and the only visible content in child. |
| 1684 | // It is positioned outside of the clip rect from parent. |
| 1685 | |
| 1686 | // In this configuration, grand_child should be outside the clipped |
| 1687 | // content rect of the child, making grand_child not appear in the |
| 1688 | // render_surface_layer_list. However, when we place an animation on the |
| 1689 | // child, this clipping should be avoided and we should keep the grand_child |
| 1690 | // in the render_surface_layer_list. |
| 1691 | |
| 1692 | const gfx::Transform identity_matrix; |
| 1693 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1694 | scoped_refptr<Layer> child = Layer::Create(); |
| 1695 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1696 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1697 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1698 | parent->AddChild(child); |
| 1699 | child->AddChild(grand_child); |
| 1700 | grand_child->AddChild(leaf_node); |
| 1701 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1702 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1703 | host->SetRootLayer(parent); |
| 1704 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1705 | SetLayerPropertiesForTesting(parent.get(), |
| 1706 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1707 | gfx::PointF(), |
| 1708 | gfx::PointF(), |
| 1709 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1710 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1711 | false); |
| 1712 | SetLayerPropertiesForTesting(child.get(), |
| 1713 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1714 | gfx::PointF(), |
| 1715 | gfx::PointF(), |
| 1716 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1717 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1718 | false); |
| 1719 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1720 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1721 | gfx::PointF(), |
| 1722 | gfx::PointF(200.f, 200.f), |
| 1723 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1724 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1725 | false); |
| 1726 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1727 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1728 | gfx::PointF(), |
| 1729 | gfx::PointF(), |
| 1730 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1731 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1732 | false); |
| 1733 | |
| 1734 | parent->SetMasksToBounds(true); |
| 1735 | child->SetOpacity(0.4f); |
| 1736 | child->SetForceRenderSurface(true); |
| 1737 | grand_child->SetOpacity(0.4f); |
| 1738 | grand_child->SetForceRenderSurface(true); |
| 1739 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1740 | { |
| 1741 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1742 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1743 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1744 | inputs.can_adjust_raster_scales = true; |
| 1745 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1746 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1747 | // Without an animation, we should cull child and grand_child from the |
| 1748 | // render_surface_layer_list. |
| 1749 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1750 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1751 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1752 | |
| 1753 | // Now put an animating transform on child. |
| 1754 | AddAnimatedTransformToController( |
| 1755 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1756 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1757 | { |
| 1758 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1759 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1760 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1761 | inputs.can_adjust_raster_scales = true; |
| 1762 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1763 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1764 | // With an animating transform, we should keep child and grand_child in the |
| 1765 | // render_surface_layer_list. |
| 1766 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1767 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1768 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1769 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1770 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1771 | } |
| 1772 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1773 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1774 | // Layer's IsClipped() property is set to true when: |
| 1775 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1776 | // - the layer is clipped by an ancestor that contributes to the same |
| 1777 | // render target, |
| 1778 | // - a surface is clipped by an ancestor that contributes to the same |
| 1779 | // render target. |
| 1780 | // |
| 1781 | // In particular, for a layer that owns a render surface: |
| 1782 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1783 | // pass that clipped status to the layer itself. |
| 1784 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1785 | // and propagates the clip to the subtree. |
| 1786 | |
| 1787 | const gfx::Transform identity_matrix; |
| 1788 | scoped_refptr<Layer> root = Layer::Create(); |
| 1789 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1790 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 1791 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 1792 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1793 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1794 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1795 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1796 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1797 | root->AddChild(parent); |
| 1798 | parent->AddChild(child1); |
| 1799 | parent->AddChild(child2); |
| 1800 | child1->AddChild(grand_child); |
| 1801 | child2->AddChild(leaf_node2); |
| 1802 | grand_child->AddChild(leaf_node1); |
| 1803 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1804 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1805 | host->SetRootLayer(root); |
| 1806 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1807 | child2->SetForceRenderSurface(true); |
| 1808 | |
| 1809 | SetLayerPropertiesForTesting(root.get(), |
| 1810 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1811 | gfx::PointF(), |
| 1812 | gfx::PointF(), |
| 1813 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1814 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1815 | false); |
| 1816 | SetLayerPropertiesForTesting(parent.get(), |
| 1817 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1818 | gfx::PointF(), |
| 1819 | gfx::PointF(), |
| 1820 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1821 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1822 | false); |
| 1823 | SetLayerPropertiesForTesting(child1.get(), |
| 1824 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1825 | gfx::PointF(), |
| 1826 | gfx::PointF(), |
| 1827 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1828 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1829 | false); |
| 1830 | SetLayerPropertiesForTesting(child2.get(), |
| 1831 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1832 | gfx::PointF(), |
| 1833 | gfx::PointF(), |
| 1834 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1835 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1836 | false); |
| 1837 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1838 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1839 | gfx::PointF(), |
| 1840 | gfx::PointF(), |
| 1841 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1842 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1843 | false); |
| 1844 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1845 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1846 | gfx::PointF(), |
| 1847 | gfx::PointF(), |
| 1848 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1849 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1850 | false); |
| 1851 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1852 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1853 | gfx::PointF(), |
| 1854 | gfx::PointF(), |
| 1855 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1856 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1857 | false); |
| 1858 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1859 | // Case 1: nothing is clipped except the root render surface. |
| 1860 | { |
| 1861 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1862 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1863 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1864 | inputs.can_adjust_raster_scales = true; |
| 1865 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1866 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1867 | ASSERT_TRUE(root->render_surface()); |
| 1868 | ASSERT_TRUE(child2->render_surface()); |
| 1869 | |
| 1870 | EXPECT_FALSE(root->is_clipped()); |
| 1871 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1872 | EXPECT_FALSE(parent->is_clipped()); |
| 1873 | EXPECT_FALSE(child1->is_clipped()); |
| 1874 | EXPECT_FALSE(child2->is_clipped()); |
| 1875 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1876 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1877 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1878 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1879 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1880 | |
| 1881 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1882 | // surface are clipped. But layers that contribute to child2's surface are |
| 1883 | // not clipped explicitly because child2's surface already accounts for |
| 1884 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1885 | { |
| 1886 | RenderSurfaceLayerList render_surface_layer_list; |
| 1887 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1888 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1889 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1890 | inputs.can_adjust_raster_scales = true; |
| 1891 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1892 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1893 | ASSERT_TRUE(root->render_surface()); |
| 1894 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1895 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1896 | EXPECT_FALSE(root->is_clipped()); |
| 1897 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1898 | EXPECT_TRUE(parent->is_clipped()); |
| 1899 | EXPECT_TRUE(child1->is_clipped()); |
| 1900 | EXPECT_FALSE(child2->is_clipped()); |
| 1901 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1902 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1903 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1904 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1905 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1906 | |
| 1907 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1908 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1909 | { |
| 1910 | RenderSurfaceLayerList render_surface_layer_list; |
| 1911 | parent->SetMasksToBounds(false); |
| 1912 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1913 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1914 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1915 | inputs.can_adjust_raster_scales = true; |
| 1916 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1917 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1918 | ASSERT_TRUE(root->render_surface()); |
| 1919 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1920 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1921 | EXPECT_FALSE(root->is_clipped()); |
| 1922 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1923 | EXPECT_FALSE(parent->is_clipped()); |
| 1924 | EXPECT_FALSE(child1->is_clipped()); |
| 1925 | EXPECT_TRUE(child2->is_clipped()); |
| 1926 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1927 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1928 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1929 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1930 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1931 | } |
| 1932 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1933 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1934 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1935 | // parent masksToBounds is true. |
| 1936 | // |
| 1937 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1938 | // be the layer rect expressed in target space. |
| 1939 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1940 | // will be the intersection of layer bounds and the mask region. |
| 1941 | // grand_child3 - partially clipped and masksToBounds; the |
| 1942 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1943 | // the mask region. |
| 1944 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1945 | // be empty. |
| 1946 | // |
| 1947 | |
| 1948 | const gfx::Transform identity_matrix; |
| 1949 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1950 | scoped_refptr<Layer> child = Layer::Create(); |
| 1951 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1952 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1953 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1954 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1955 | |
| 1956 | parent->AddChild(child); |
| 1957 | child->AddChild(grand_child1); |
| 1958 | child->AddChild(grand_child2); |
| 1959 | child->AddChild(grand_child3); |
| 1960 | child->AddChild(grand_child4); |
| 1961 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1962 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1963 | host->SetRootLayer(parent); |
| 1964 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1965 | SetLayerPropertiesForTesting(parent.get(), |
| 1966 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1967 | gfx::PointF(), |
| 1968 | gfx::PointF(), |
| 1969 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1970 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1971 | false); |
| 1972 | SetLayerPropertiesForTesting(child.get(), |
| 1973 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1974 | gfx::PointF(), |
| 1975 | gfx::PointF(), |
| 1976 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1977 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1978 | false); |
| 1979 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1980 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1981 | gfx::PointF(), |
| 1982 | gfx::PointF(5.f, 5.f), |
| 1983 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1984 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1985 | false); |
| 1986 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1987 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1988 | gfx::PointF(), |
| 1989 | gfx::PointF(15.f, 15.f), |
| 1990 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1991 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1992 | false); |
| 1993 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 1994 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1995 | gfx::PointF(), |
| 1996 | gfx::PointF(15.f, 15.f), |
| 1997 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1998 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1999 | false); |
| 2000 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2001 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2002 | gfx::PointF(), |
| 2003 | gfx::PointF(45.f, 45.f), |
| 2004 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2005 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2006 | false); |
| 2007 | |
| 2008 | child->SetMasksToBounds(true); |
| 2009 | grand_child3->SetMasksToBounds(true); |
| 2010 | |
| 2011 | // Force everyone to be a render surface. |
| 2012 | child->SetOpacity(0.4f); |
| 2013 | grand_child1->SetOpacity(0.5f); |
| 2014 | grand_child2->SetOpacity(0.5f); |
| 2015 | grand_child3->SetOpacity(0.5f); |
| 2016 | grand_child4->SetOpacity(0.5f); |
| 2017 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2018 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2019 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2020 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2021 | inputs.can_adjust_raster_scales = true; |
| 2022 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2023 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2024 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2025 | grand_child1->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2026 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2027 | grand_child3->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()); |
| 2030 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2031 | } |
| 2032 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2033 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2034 | // Verify that render surfaces (and their layers) get the appropriate |
| 2035 | // clip rects when their parent masksToBounds is true. |
| 2036 | // |
| 2037 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2038 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2039 | // They may still have a clip rect of their own layer bounds, however, if |
| 2040 | // masksToBounds was true. |
| 2041 | const gfx::Transform identity_matrix; |
| 2042 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2043 | scoped_refptr<Layer> child = Layer::Create(); |
| 2044 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 2045 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 2046 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 2047 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 2048 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 2049 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2050 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 2051 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2052 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 2053 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2054 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 2055 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2056 | |
| 2057 | parent->AddChild(child); |
| 2058 | child->AddChild(grand_child1); |
| 2059 | child->AddChild(grand_child2); |
| 2060 | child->AddChild(grand_child3); |
| 2061 | child->AddChild(grand_child4); |
| 2062 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2063 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2064 | host->SetRootLayer(parent); |
| 2065 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2066 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2067 | // this test. |
| 2068 | grand_child1->AddChild(leaf_node1); |
| 2069 | grand_child2->AddChild(leaf_node2); |
| 2070 | grand_child3->AddChild(leaf_node3); |
| 2071 | grand_child4->AddChild(leaf_node4); |
| 2072 | |
| 2073 | SetLayerPropertiesForTesting(parent.get(), |
| 2074 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2075 | gfx::PointF(), |
| 2076 | gfx::PointF(), |
| 2077 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2078 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2079 | false); |
| 2080 | SetLayerPropertiesForTesting(child.get(), |
| 2081 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2082 | gfx::PointF(), |
| 2083 | gfx::PointF(), |
| 2084 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2085 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2086 | false); |
| 2087 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2088 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2089 | gfx::PointF(), |
| 2090 | gfx::PointF(5.f, 5.f), |
| 2091 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2092 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2093 | false); |
| 2094 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2095 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2096 | gfx::PointF(), |
| 2097 | gfx::PointF(15.f, 15.f), |
| 2098 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2099 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2100 | false); |
| 2101 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2102 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2103 | gfx::PointF(), |
| 2104 | gfx::PointF(15.f, 15.f), |
| 2105 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2106 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2107 | false); |
| 2108 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2109 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2110 | gfx::PointF(), |
| 2111 | gfx::PointF(45.f, 45.f), |
| 2112 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2113 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2114 | false); |
| 2115 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2116 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2117 | gfx::PointF(), |
| 2118 | gfx::PointF(), |
| 2119 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2120 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2121 | false); |
| 2122 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2123 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2124 | gfx::PointF(), |
| 2125 | gfx::PointF(), |
| 2126 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2127 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2128 | false); |
| 2129 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2130 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2131 | gfx::PointF(), |
| 2132 | gfx::PointF(), |
| 2133 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2134 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2135 | false); |
| 2136 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2137 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2138 | gfx::PointF(), |
| 2139 | gfx::PointF(), |
| 2140 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2141 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2142 | false); |
| 2143 | |
| 2144 | child->SetMasksToBounds(true); |
| 2145 | grand_child3->SetMasksToBounds(true); |
| 2146 | grand_child4->SetMasksToBounds(true); |
| 2147 | |
| 2148 | // Force everyone to be a render surface. |
| 2149 | child->SetOpacity(0.4f); |
| 2150 | child->SetForceRenderSurface(true); |
| 2151 | grand_child1->SetOpacity(0.5f); |
| 2152 | grand_child1->SetForceRenderSurface(true); |
| 2153 | grand_child2->SetOpacity(0.5f); |
| 2154 | grand_child2->SetForceRenderSurface(true); |
| 2155 | grand_child3->SetOpacity(0.5f); |
| 2156 | grand_child3->SetForceRenderSurface(true); |
| 2157 | grand_child4->SetOpacity(0.5f); |
| 2158 | grand_child4->SetForceRenderSurface(true); |
| 2159 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2160 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2161 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2162 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2163 | inputs.can_adjust_raster_scales = true; |
| 2164 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2165 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2166 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2167 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2168 | |
| 2169 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2170 | // masksToBounds. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2171 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2172 | grand_child1->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2173 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2174 | grand_child2->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2175 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2176 | grand_child3->render_surface()->clip_rect()); |
| 2177 | } |
| 2178 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2179 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2180 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2181 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2182 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2183 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2184 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2185 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2186 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2187 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2188 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2189 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2190 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2191 | parent->AddChild(render_surface1); |
| 2192 | parent->AddChild(child_of_root); |
| 2193 | render_surface1->AddChild(child_of_rs1); |
| 2194 | render_surface1->AddChild(render_surface2); |
| 2195 | render_surface2->AddChild(child_of_rs2); |
| 2196 | child_of_root->AddChild(grand_child_of_root); |
| 2197 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2198 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2199 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2200 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2201 | host->SetRootLayer(parent); |
| 2202 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2203 | // Make our render surfaces. |
| 2204 | render_surface1->SetForceRenderSurface(true); |
| 2205 | render_surface2->SetForceRenderSurface(true); |
| 2206 | |
| 2207 | gfx::Transform layer_transform; |
| 2208 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2209 | |
| 2210 | SetLayerPropertiesForTesting(parent.get(), |
| 2211 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2212 | gfx::PointF(0.25f, 0.f), |
| 2213 | gfx::PointF(2.5f, 0.f), |
| 2214 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2215 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2216 | false); |
| 2217 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2218 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2219 | gfx::PointF(0.25f, 0.f), |
| 2220 | gfx::PointF(2.5f, 0.f), |
| 2221 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2222 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2223 | false); |
| 2224 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2225 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2226 | gfx::PointF(0.25f, 0.f), |
| 2227 | gfx::PointF(2.5f, 0.f), |
| 2228 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2229 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2230 | false); |
| 2231 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2232 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2233 | gfx::PointF(0.25f, 0.f), |
| 2234 | gfx::PointF(2.5f, 0.f), |
| 2235 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2236 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2237 | false); |
| 2238 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2239 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2240 | gfx::PointF(0.25f, 0.f), |
| 2241 | gfx::PointF(2.5f, 0.f), |
| 2242 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2243 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2244 | false); |
| 2245 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2246 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2247 | gfx::PointF(0.25f, 0.f), |
| 2248 | gfx::PointF(2.5f, 0.f), |
| 2249 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2250 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2251 | false); |
| 2252 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2253 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2254 | gfx::PointF(0.25f, 0.f), |
| 2255 | gfx::PointF(2.5f, 0.f), |
| 2256 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2257 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2258 | false); |
| 2259 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2260 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2261 | gfx::PointF(0.25f, 0.f), |
| 2262 | gfx::PointF(2.5f, 0.f), |
| 2263 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2264 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2265 | false); |
| 2266 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2267 | layer_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2268 | gfx::PointF(0.25f, 0.f), |
| 2269 | gfx::PointF(2.5f, 0.f), |
| 2270 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2271 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2272 | false); |
| 2273 | |
| 2274 | // Put an animated opacity on the render surface. |
| 2275 | AddOpacityTransitionToController( |
| 2276 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2277 | |
| 2278 | // Also put an animated opacity on a layer without descendants. |
| 2279 | AddOpacityTransitionToController( |
| 2280 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2281 | |
| 2282 | // Put a transform animation on the render surface. |
| 2283 | AddAnimatedTransformToController( |
| 2284 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2285 | |
| 2286 | // Also put transform animations on grand_child_of_root, and |
| 2287 | // grand_child_of_rs2 |
| 2288 | AddAnimatedTransformToController( |
| 2289 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2290 | AddAnimatedTransformToController( |
| 2291 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2292 | |
| 2293 | ExecuteCalculateDrawProperties(parent.get()); |
| 2294 | |
| 2295 | // Only layers that are associated with render surfaces should have an actual |
| 2296 | // RenderSurface() value. |
| 2297 | ASSERT_TRUE(parent->render_surface()); |
| 2298 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2299 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2300 | |
| 2301 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2302 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2303 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2304 | |
| 2305 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2306 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2307 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2308 | |
| 2309 | // Verify all render target accessors |
| 2310 | EXPECT_EQ(parent, parent->render_target()); |
| 2311 | EXPECT_EQ(parent, child_of_root->render_target()); |
| 2312 | EXPECT_EQ(parent, grand_child_of_root->render_target()); |
| 2313 | |
| 2314 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 2315 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 2316 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 2317 | |
| 2318 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 2319 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 2320 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 2321 | |
| 2322 | // Verify draw_opacity_is_animating values |
| 2323 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2324 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2325 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2326 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2327 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2328 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2329 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2330 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2331 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2332 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2333 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2334 | |
| 2335 | // Verify draw_transform_is_animating values |
| 2336 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2337 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2338 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2339 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2340 | EXPECT_FALSE(render_surface1->render_surface() |
| 2341 | ->target_surface_transforms_are_animating()); |
| 2342 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2343 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2344 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2345 | EXPECT_TRUE(render_surface2->render_surface() |
| 2346 | ->target_surface_transforms_are_animating()); |
| 2347 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2348 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2349 | |
| 2350 | // Verify screen_space_transform_is_animating values |
| 2351 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2352 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2353 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2354 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2355 | EXPECT_FALSE(render_surface1->render_surface() |
| 2356 | ->screen_space_transforms_are_animating()); |
| 2357 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2358 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2359 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2360 | EXPECT_TRUE(render_surface2->render_surface() |
| 2361 | ->screen_space_transforms_are_animating()); |
| 2362 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2363 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2364 | |
| 2365 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2366 | // It is expected that we correctly set up transforms so that the y-component |
| 2367 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2368 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2369 | EXPECT_FLOAT_EQ(2.0, |
| 2370 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2371 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2372 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2373 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2374 | EXPECT_FLOAT_EQ(2.0, |
| 2375 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2376 | EXPECT_FLOAT_EQ(3.0, |
| 2377 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2378 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2379 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2380 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2381 | EXPECT_FLOAT_EQ(3.0, |
| 2382 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2383 | EXPECT_FLOAT_EQ(4.0, |
| 2384 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2385 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2386 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2387 | } |
| 2388 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2389 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2390 | // Test the calculateVisibleRect() function works correctly for identity |
| 2391 | // transforms. |
| 2392 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2393 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2394 | gfx::Transform layer_to_surface_transform; |
| 2395 | |
| 2396 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2397 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2398 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2399 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2400 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2401 | EXPECT_RECT_EQ(expected, actual); |
| 2402 | |
| 2403 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2404 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2405 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2406 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2407 | EXPECT_TRUE(actual.IsEmpty()); |
| 2408 | |
| 2409 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2410 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2411 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2412 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2413 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2414 | EXPECT_RECT_EQ(expected, actual); |
| 2415 | } |
| 2416 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2417 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2418 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2419 | // transforms. |
| 2420 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2421 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2422 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2423 | gfx::Transform layer_to_surface_transform; |
| 2424 | |
| 2425 | // Case 1: Layer is contained within the surface. |
| 2426 | layer_to_surface_transform.MakeIdentity(); |
| 2427 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2428 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2429 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2430 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2431 | EXPECT_RECT_EQ(expected, actual); |
| 2432 | |
| 2433 | // Case 2: Layer is outside the surface rect. |
| 2434 | layer_to_surface_transform.MakeIdentity(); |
| 2435 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2436 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2437 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2438 | EXPECT_TRUE(actual.IsEmpty()); |
| 2439 | |
| 2440 | // Case 3: Layer is partially overlapping the surface rect. |
| 2441 | layer_to_surface_transform.MakeIdentity(); |
| 2442 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2443 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2444 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2445 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2446 | EXPECT_RECT_EQ(expected, actual); |
| 2447 | } |
| 2448 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2449 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2450 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2451 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2452 | // should return the g in the layer's space. |
| 2453 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2454 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2455 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2456 | gfx::Transform layer_to_surface_transform; |
| 2457 | |
| 2458 | // Case 1: Layer is contained within the surface. |
| 2459 | layer_to_surface_transform.MakeIdentity(); |
| 2460 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2461 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2462 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2463 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2464 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2465 | EXPECT_RECT_EQ(expected, actual); |
| 2466 | |
| 2467 | // Case 2: Layer is outside the surface rect. |
| 2468 | layer_to_surface_transform.MakeIdentity(); |
| 2469 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2470 | layer_to_surface_transform.Rotate(45.0); |
| 2471 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2472 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2473 | EXPECT_TRUE(actual.IsEmpty()); |
| 2474 | |
| 2475 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2476 | // the layer is oriented diagonally, with the left half outside of the render |
| 2477 | // surface. In this case, the g should still be the entire layer |
| 2478 | // (remember the g is computed in layer space); both the top-left |
| 2479 | // and bottom-right corners of the layer are still visible. |
| 2480 | layer_to_surface_transform.MakeIdentity(); |
| 2481 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2482 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2483 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2484 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2485 | EXPECT_RECT_EQ(expected, actual); |
| 2486 | |
| 2487 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2488 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2489 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2490 | // surface overlaps the right side of the layer. The g should be |
| 2491 | // the layer's right half. |
| 2492 | layer_to_surface_transform.MakeIdentity(); |
| 2493 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2494 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2495 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2496 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2497 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2498 | EXPECT_RECT_EQ(expected, actual); |
| 2499 | } |
| 2500 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2501 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2502 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2503 | // transforms. |
| 2504 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2505 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2506 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2507 | gfx::Transform layer_to_surface_transform; |
| 2508 | |
| 2509 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2510 | // degrees, should be fully contained in the render surface. |
| 2511 | layer_to_surface_transform.MakeIdentity(); |
| 2512 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2513 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2514 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2515 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2516 | EXPECT_RECT_EQ(expected, actual); |
| 2517 | |
| 2518 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2519 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2520 | // visible on the surface. |
| 2521 | // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2522 | SkMScalar half_width_of_rotated_layer = |
| 2523 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2524 | layer_to_surface_transform.MakeIdentity(); |
| 2525 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2526 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2527 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2528 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2529 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2530 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2531 | EXPECT_RECT_EQ(expected, actual); |
| 2532 | } |
| 2533 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2534 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2535 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2536 | // a perspective projection onto the target surface. |
| 2537 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2538 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2539 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2540 | gfx::Transform layer_to_surface_transform; |
| 2541 | |
| 2542 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2543 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2544 | // its translated more than the perspective amount. |
| 2545 | layer_to_surface_transform.MakeIdentity(); |
| 2546 | |
| 2547 | // The following sequence of transforms applies the perspective about the |
| 2548 | // center of the surface. |
| 2549 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2550 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2551 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2552 | |
| 2553 | // This translate places the layer in front of the surface's projection plane. |
| 2554 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2555 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2556 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2557 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2558 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2559 | EXPECT_RECT_EQ(expected, actual); |
| 2560 | |
| 2561 | // Case 2: same projection as before, except that the layer is also translated |
| 2562 | // to the side, so that only the right half of the layer should be visible. |
| 2563 | // |
| 2564 | // Explanation of expected result: The perspective ratio is (z distance |
| 2565 | // between layer and camera origin) / (z distance between projection plane and |
| 2566 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2567 | // move a layer by translating -50 units in projected surface units (so that |
| 2568 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2569 | // -50 == -200 in the layer's units. |
| 2570 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2571 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2572 | gfx::Size(100, 200)); // The right half of the layer's |
| 2573 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2574 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2575 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2576 | EXPECT_RECT_EQ(expected, actual); |
| 2577 | } |
| 2578 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2579 | TEST_F(LayerTreeHostCommonTest, |
| 2580 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2581 | // There is currently no explicit concept of an orthographic projection plane |
| 2582 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2583 | // are technically behind the surface in an orthographic world should not be |
| 2584 | // clipped when they are flattened to the surface. |
| 2585 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2586 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2587 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2588 | gfx::Transform layer_to_surface_transform; |
| 2589 | |
| 2590 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2591 | // at the center of the layer. |
| 2592 | layer_to_surface_transform.MakeIdentity(); |
| 2593 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2594 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2595 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2596 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2597 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2598 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2599 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2600 | EXPECT_RECT_EQ(expected, actual); |
| 2601 | } |
| 2602 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2603 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2604 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2605 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2606 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2607 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2608 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2609 | // converting to cartesian coordinates. |
| 2610 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2611 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2612 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2613 | gfx::Transform layer_to_surface_transform; |
| 2614 | |
| 2615 | // The layer is positioned so that the right half of the layer should be in |
| 2616 | // front of the camera, while the other half is behind the surface's |
| 2617 | // projection plane. The following sequence of transforms applies the |
| 2618 | // perspective and rotation about the center of the layer. |
| 2619 | layer_to_surface_transform.MakeIdentity(); |
| 2620 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2621 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2622 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2623 | |
| 2624 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2625 | // transform, otherwise this code is not testing the intended scenario. |
| 2626 | bool clipped; |
| 2627 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2628 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2629 | &clipped); |
| 2630 | ASSERT_TRUE(clipped); |
| 2631 | |
| 2632 | int expected_x_position = 0; |
| 2633 | int expected_width = 10; |
| 2634 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2635 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2636 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2637 | EXPECT_EQ(expected_width, actual.width()); |
| 2638 | } |
| 2639 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2640 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2641 | // To determine visible rect in layer space, there needs to be an |
| 2642 | // un-projection from surface space to layer space. When the original |
| 2643 | // transform was a perspective projection that was clipped, it returns a rect |
| 2644 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2645 | // clipping again. |
| 2646 | |
| 2647 | // This sequence of transforms causes one corner of the layer to protrude |
| 2648 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2649 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2650 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2651 | gfx::Transform layer_to_surface_transform; |
| 2652 | layer_to_surface_transform.MakeIdentity(); |
| 2653 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2654 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2655 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2656 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2657 | |
| 2658 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2659 | // code is not testing the intended scenario. |
| 2660 | bool clipped; |
| 2661 | gfx::RectF clipped_rect = |
| 2662 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2663 | MathUtil::ProjectQuad( |
| 2664 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2665 | ASSERT_TRUE(clipped); |
| 2666 | |
| 2667 | // Only the corner of the layer is not visible on the surface because of being |
| 2668 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2669 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2670 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2671 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2672 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2673 | EXPECT_RECT_EQ(expected, actual); |
| 2674 | } |
| 2675 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2676 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2677 | scoped_refptr<Layer> root = Layer::Create(); |
| 2678 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2679 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2680 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2681 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2682 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2683 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2684 | root->AddChild(child1); |
| 2685 | root->AddChild(child2); |
| 2686 | root->AddChild(child3); |
| 2687 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2688 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2689 | host->SetRootLayer(root); |
| 2690 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2691 | gfx::Transform identity_matrix; |
| 2692 | SetLayerPropertiesForTesting(root.get(), |
| 2693 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2694 | gfx::PointF(), |
| 2695 | gfx::PointF(), |
| 2696 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2697 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2698 | false); |
| 2699 | SetLayerPropertiesForTesting(child1.get(), |
| 2700 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2701 | gfx::PointF(), |
| 2702 | gfx::PointF(), |
| 2703 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2704 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2705 | false); |
| 2706 | SetLayerPropertiesForTesting(child2.get(), |
| 2707 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2708 | gfx::PointF(), |
| 2709 | gfx::PointF(75.f, 75.f), |
| 2710 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2711 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2712 | false); |
| 2713 | SetLayerPropertiesForTesting(child3.get(), |
| 2714 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2715 | gfx::PointF(), |
| 2716 | gfx::PointF(125.f, 125.f), |
| 2717 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2718 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2719 | false); |
| 2720 | |
| 2721 | ExecuteCalculateDrawProperties(root.get()); |
| 2722 | |
| 2723 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2724 | root->render_surface()->DrawableContentRect()); |
| 2725 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2726 | |
| 2727 | // Layers that do not draw content should have empty visible_content_rects. |
| 2728 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2729 | |
| 2730 | // layer visible_content_rects are clipped by their target surface. |
| 2731 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2732 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 2733 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2734 | |
| 2735 | // layer drawable_content_rects are not clipped. |
| 2736 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2737 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2738 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2739 | } |
| 2740 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2741 | TEST_F(LayerTreeHostCommonTest, |
| 2742 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2743 | scoped_refptr<Layer> root = Layer::Create(); |
| 2744 | scoped_refptr<Layer> child = Layer::Create(); |
| 2745 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2746 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2747 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2748 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2749 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2750 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2751 | root->AddChild(child); |
| 2752 | child->AddChild(grand_child1); |
| 2753 | child->AddChild(grand_child2); |
| 2754 | child->AddChild(grand_child3); |
| 2755 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2756 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2757 | host->SetRootLayer(root); |
| 2758 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2759 | gfx::Transform identity_matrix; |
| 2760 | SetLayerPropertiesForTesting(root.get(), |
| 2761 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2762 | gfx::PointF(), |
| 2763 | gfx::PointF(), |
| 2764 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2765 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2766 | false); |
| 2767 | SetLayerPropertiesForTesting(child.get(), |
| 2768 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2769 | gfx::PointF(), |
| 2770 | gfx::PointF(), |
| 2771 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2772 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2773 | false); |
| 2774 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2775 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2776 | gfx::PointF(), |
| 2777 | gfx::PointF(5.f, 5.f), |
| 2778 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2779 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2780 | false); |
| 2781 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2782 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2783 | gfx::PointF(), |
| 2784 | gfx::PointF(75.f, 75.f), |
| 2785 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2786 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2787 | false); |
| 2788 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2789 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2790 | gfx::PointF(), |
| 2791 | gfx::PointF(125.f, 125.f), |
| 2792 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2793 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2794 | false); |
| 2795 | |
| 2796 | child->SetMasksToBounds(true); |
| 2797 | ExecuteCalculateDrawProperties(root.get()); |
| 2798 | |
| 2799 | ASSERT_FALSE(child->render_surface()); |
| 2800 | |
| 2801 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2802 | root->render_surface()->DrawableContentRect()); |
| 2803 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2804 | |
| 2805 | // Layers that do not draw content should have empty visible content rects. |
| 2806 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2807 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
| 2808 | |
| 2809 | // All grandchild visible content rects should be clipped by child. |
| 2810 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2811 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
| 2812 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2813 | |
| 2814 | // All grandchild DrawableContentRects should also be clipped by child. |
| 2815 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), |
| 2816 | grand_child1->drawable_content_rect()); |
| 2817 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25), |
| 2818 | grand_child2->drawable_content_rect()); |
| 2819 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2820 | } |
| 2821 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2822 | TEST_F(LayerTreeHostCommonTest, |
| 2823 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2824 | scoped_refptr<Layer> root = Layer::Create(); |
| 2825 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2826 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2827 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2828 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2829 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2830 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2831 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2832 | root->AddChild(render_surface1); |
| 2833 | render_surface1->AddChild(child1); |
| 2834 | render_surface1->AddChild(child2); |
| 2835 | render_surface1->AddChild(child3); |
| 2836 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2837 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2838 | host->SetRootLayer(root); |
| 2839 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2840 | gfx::Transform identity_matrix; |
| 2841 | SetLayerPropertiesForTesting(root.get(), |
| 2842 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2843 | gfx::PointF(), |
| 2844 | gfx::PointF(), |
| 2845 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2846 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2847 | false); |
| 2848 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2849 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2850 | gfx::PointF(), |
| 2851 | gfx::PointF(), |
| 2852 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2853 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2854 | false); |
| 2855 | SetLayerPropertiesForTesting(child1.get(), |
| 2856 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2857 | gfx::PointF(), |
| 2858 | gfx::PointF(5.f, 5.f), |
| 2859 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2860 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2861 | false); |
| 2862 | SetLayerPropertiesForTesting(child2.get(), |
| 2863 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2864 | gfx::PointF(), |
| 2865 | gfx::PointF(75.f, 75.f), |
| 2866 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2867 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2868 | false); |
| 2869 | SetLayerPropertiesForTesting(child3.get(), |
| 2870 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2871 | gfx::PointF(), |
| 2872 | gfx::PointF(125.f, 125.f), |
| 2873 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2874 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2875 | false); |
| 2876 | |
| 2877 | render_surface1->SetForceRenderSurface(true); |
| 2878 | ExecuteCalculateDrawProperties(root.get()); |
| 2879 | |
| 2880 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2881 | |
| 2882 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2883 | root->render_surface()->DrawableContentRect()); |
| 2884 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2885 | |
| 2886 | // Layers that do not draw content should have empty visible content rects. |
| 2887 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2888 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 2889 | render_surface1->visible_content_rect()); |
| 2890 | |
| 2891 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2892 | // regions of the subtree. |
| 2893 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2894 | render_surface1->render_surface()->DrawableContentRect()); |
| 2895 | |
| 2896 | // All layers that draw content into the unclipped surface are also unclipped. |
| 2897 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2898 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2899 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 2900 | |
| 2901 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2902 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2903 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2904 | } |
| 2905 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2906 | TEST_F(LayerTreeHostCommonTest, |
| 2907 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2908 | scoped_refptr<Layer> root = Layer::Create(); |
| 2909 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2910 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2911 | root->AddChild(child); |
| 2912 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2913 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2914 | host->SetRootLayer(root); |
| 2915 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2916 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2917 | gfx::Transform identity_matrix; |
| 2918 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2919 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2920 | |
| 2921 | SetLayerPropertiesForTesting(root.get(), |
| 2922 | identity_matrix, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2923 | gfx::PointF(), |
| 2924 | gfx::PointF(), |
| 2925 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2926 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2927 | false); |
| 2928 | SetLayerPropertiesForTesting(child.get(), |
| 2929 | uninvertible_matrix, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2930 | gfx::PointF(), |
| 2931 | gfx::PointF(5.f, 5.f), |
| 2932 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2933 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2934 | false); |
| 2935 | |
| 2936 | ExecuteCalculateDrawProperties(root.get()); |
| 2937 | |
| 2938 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2939 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2940 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2941 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 2942 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2943 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2944 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2945 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2946 | |
| 2947 | SetLayerPropertiesForTesting(child.get(), |
| 2948 | uninvertible_matrix, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2949 | gfx::PointF(), |
| 2950 | gfx::PointF(5.f, 5.f), |
| 2951 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2952 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2953 | false); |
| 2954 | |
| 2955 | ExecuteCalculateDrawProperties(root.get()); |
| 2956 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2957 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2958 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2959 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2960 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2961 | uninvertible_matrix.MakeIdentity(); |
| 2962 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2963 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2964 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2965 | |
| 2966 | SetLayerPropertiesForTesting(child.get(), |
| 2967 | uninvertible_matrix, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2968 | gfx::PointF(), |
| 2969 | gfx::PointF(5.f, 5.f), |
| 2970 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2971 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2972 | false); |
| 2973 | |
| 2974 | ExecuteCalculateDrawProperties(root.get()); |
| 2975 | |
| 2976 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2977 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2978 | } |
| 2979 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2980 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame^] | 2981 | SingularTransformDoesNotPreventClearingDrawProperties) { |
| 2982 | scoped_refptr<Layer> root = Layer::Create(); |
| 2983 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2984 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2985 | root->AddChild(child); |
| 2986 | |
| 2987 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2988 | host->SetRootLayer(root); |
| 2989 | |
| 2990 | gfx::Transform identity_matrix; |
| 2991 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 2992 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2993 | |
| 2994 | SetLayerPropertiesForTesting(root.get(), |
| 2995 | uninvertible_matrix, |
| 2996 | gfx::PointF(), |
| 2997 | gfx::PointF(), |
| 2998 | gfx::Size(100, 100), |
| 2999 | true, |
| 3000 | false); |
| 3001 | SetLayerPropertiesForTesting(child.get(), |
| 3002 | identity_matrix, |
| 3003 | gfx::PointF(), |
| 3004 | gfx::PointF(5.f, 5.f), |
| 3005 | gfx::Size(50, 50), |
| 3006 | true, |
| 3007 | false); |
| 3008 | |
| 3009 | child->draw_properties().sorted_for_recursion = true; |
| 3010 | |
| 3011 | TransformOperations start_transform_operations; |
| 3012 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 3013 | |
| 3014 | TransformOperations end_transform_operations; |
| 3015 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 3016 | |
| 3017 | AddAnimatedTransformToLayer( |
| 3018 | root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 3019 | |
| 3020 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 3021 | |
| 3022 | ExecuteCalculateDrawProperties(root.get()); |
| 3023 | |
| 3024 | EXPECT_FALSE(child->draw_properties().sorted_for_recursion); |
| 3025 | } |
| 3026 | |
| 3027 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3028 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3029 | scoped_refptr<Layer> root = Layer::Create(); |
| 3030 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3031 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3032 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3033 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3034 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3035 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3036 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3037 | root->AddChild(render_surface1); |
| 3038 | render_surface1->AddChild(child1); |
| 3039 | render_surface1->AddChild(child2); |
| 3040 | render_surface1->AddChild(child3); |
| 3041 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3042 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3043 | host->SetRootLayer(root); |
| 3044 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3045 | gfx::Transform identity_matrix; |
| 3046 | SetLayerPropertiesForTesting(root.get(), |
| 3047 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3048 | gfx::PointF(), |
| 3049 | gfx::PointF(), |
| 3050 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3051 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3052 | false); |
| 3053 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3054 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3055 | gfx::PointF(), |
| 3056 | gfx::PointF(), |
| 3057 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3058 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3059 | false); |
| 3060 | SetLayerPropertiesForTesting(child1.get(), |
| 3061 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3062 | gfx::PointF(), |
| 3063 | gfx::PointF(5.f, 5.f), |
| 3064 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3065 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3066 | false); |
| 3067 | SetLayerPropertiesForTesting(child2.get(), |
| 3068 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3069 | gfx::PointF(), |
| 3070 | gfx::PointF(75.f, 75.f), |
| 3071 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3072 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3073 | false); |
| 3074 | SetLayerPropertiesForTesting(child3.get(), |
| 3075 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3076 | gfx::PointF(), |
| 3077 | gfx::PointF(125.f, 125.f), |
| 3078 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3079 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3080 | false); |
| 3081 | |
| 3082 | root->SetMasksToBounds(true); |
| 3083 | render_surface1->SetForceRenderSurface(true); |
| 3084 | ExecuteCalculateDrawProperties(root.get()); |
| 3085 | |
| 3086 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3087 | |
| 3088 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3089 | root->render_surface()->DrawableContentRect()); |
| 3090 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3091 | |
| 3092 | // Layers that do not draw content should have empty visible content rects. |
| 3093 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3094 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3095 | render_surface1->visible_content_rect()); |
| 3096 | |
| 3097 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3098 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3099 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3100 | render_surface1->render_surface()->DrawableContentRect()); |
| 3101 | |
| 3102 | // All layers that draw content into the surface have their visible content |
| 3103 | // rect clipped by the surface clip rect. |
| 3104 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3105 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 3106 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3107 | |
| 3108 | // But the DrawableContentRects are unclipped. |
| 3109 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3110 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3111 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3112 | } |
| 3113 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3114 | TEST_F(LayerTreeHostCommonTest, |
| 3115 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3116 | // Check that clipping does not propagate down surfaces. |
| 3117 | scoped_refptr<Layer> root = Layer::Create(); |
| 3118 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3119 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3120 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3121 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3122 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3123 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3124 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3125 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3126 | root->AddChild(render_surface1); |
| 3127 | render_surface1->AddChild(render_surface2); |
| 3128 | render_surface2->AddChild(child1); |
| 3129 | render_surface2->AddChild(child2); |
| 3130 | render_surface2->AddChild(child3); |
| 3131 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3132 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3133 | host->SetRootLayer(root); |
| 3134 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3135 | gfx::Transform identity_matrix; |
| 3136 | SetLayerPropertiesForTesting(root.get(), |
| 3137 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3138 | gfx::PointF(), |
| 3139 | gfx::PointF(), |
| 3140 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3141 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3142 | false); |
| 3143 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3144 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3145 | gfx::PointF(), |
| 3146 | gfx::PointF(), |
| 3147 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3148 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3149 | false); |
| 3150 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3151 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3152 | gfx::PointF(), |
| 3153 | gfx::PointF(), |
| 3154 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3155 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3156 | false); |
| 3157 | SetLayerPropertiesForTesting(child1.get(), |
| 3158 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3159 | gfx::PointF(), |
| 3160 | gfx::PointF(5.f, 5.f), |
| 3161 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3162 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3163 | false); |
| 3164 | SetLayerPropertiesForTesting(child2.get(), |
| 3165 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3166 | gfx::PointF(), |
| 3167 | gfx::PointF(75.f, 75.f), |
| 3168 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3169 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3170 | false); |
| 3171 | SetLayerPropertiesForTesting(child3.get(), |
| 3172 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3173 | gfx::PointF(), |
| 3174 | gfx::PointF(125.f, 125.f), |
| 3175 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3176 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3177 | false); |
| 3178 | |
| 3179 | root->SetMasksToBounds(true); |
| 3180 | render_surface1->SetForceRenderSurface(true); |
| 3181 | render_surface2->SetForceRenderSurface(true); |
| 3182 | ExecuteCalculateDrawProperties(root.get()); |
| 3183 | |
| 3184 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3185 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3186 | |
| 3187 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3188 | root->render_surface()->DrawableContentRect()); |
| 3189 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3190 | |
| 3191 | // Layers that do not draw content should have empty visible content rects. |
| 3192 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3193 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3194 | render_surface1->visible_content_rect()); |
| 3195 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3196 | render_surface2->visible_content_rect()); |
| 3197 | |
| 3198 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3199 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3200 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3201 | render_surface1->render_surface()->DrawableContentRect()); |
| 3202 | |
| 3203 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3204 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3205 | // render_surface2 grows to enclose all drawable content of its subtree. |
| 3206 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3207 | render_surface2->render_surface()->DrawableContentRect()); |
| 3208 | |
| 3209 | // All layers that draw content into render_surface2 think they are unclipped. |
| 3210 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3211 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3212 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 3213 | |
| 3214 | // DrawableContentRects are also unclipped. |
| 3215 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3216 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3217 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3218 | } |
| 3219 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3220 | TEST_F(LayerTreeHostCommonTest, |
| 3221 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3222 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3223 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3224 | |
| 3225 | scoped_refptr<Layer> root = Layer::Create(); |
| 3226 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3227 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3228 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3229 | root->AddChild(render_surface1); |
| 3230 | render_surface1->AddChild(child1); |
| 3231 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3232 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3233 | host->SetRootLayer(root); |
| 3234 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3235 | gfx::Transform identity_matrix; |
| 3236 | gfx::Transform child_rotation; |
| 3237 | child_rotation.Rotate(45.0); |
| 3238 | SetLayerPropertiesForTesting(root.get(), |
| 3239 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3240 | gfx::PointF(), |
| 3241 | gfx::PointF(), |
| 3242 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3243 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3244 | false); |
| 3245 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3246 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3247 | gfx::PointF(), |
| 3248 | gfx::PointF(), |
| 3249 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3250 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3251 | false); |
| 3252 | SetLayerPropertiesForTesting(child1.get(), |
| 3253 | child_rotation, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3254 | gfx::PointF(0.5f, 0.5f), |
| 3255 | gfx::PointF(25.f, 25.f), |
| 3256 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3257 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3258 | false); |
| 3259 | |
| 3260 | render_surface1->SetForceRenderSurface(true); |
| 3261 | ExecuteCalculateDrawProperties(root.get()); |
| 3262 | |
| 3263 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3264 | |
| 3265 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3266 | root->render_surface()->DrawableContentRect()); |
| 3267 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3268 | |
| 3269 | // Layers that do not draw content should have empty visible content rects. |
| 3270 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3271 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3272 | render_surface1->visible_content_rect()); |
| 3273 | |
| 3274 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3275 | // regions of the subtree. |
| 3276 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3277 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3278 | gfx::Rect(50 - diagonal_radius, |
| 3279 | 50 - diagonal_radius, |
| 3280 | diagonal_radius * 2, |
| 3281 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3282 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3283 | render_surface1->render_surface()->DrawableContentRect()); |
| 3284 | |
| 3285 | // All layers that draw content into the unclipped surface are also unclipped. |
| 3286 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3287 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3288 | child1->drawable_content_rect()); |
| 3289 | } |
| 3290 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3291 | TEST_F(LayerTreeHostCommonTest, |
| 3292 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3293 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3294 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3295 | |
| 3296 | scoped_refptr<Layer> root = Layer::Create(); |
| 3297 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3298 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3299 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3300 | root->AddChild(render_surface1); |
| 3301 | render_surface1->AddChild(child1); |
| 3302 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3303 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3304 | host->SetRootLayer(root); |
| 3305 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3306 | gfx::Transform identity_matrix; |
| 3307 | gfx::Transform child_rotation; |
| 3308 | child_rotation.Rotate(45.0); |
| 3309 | SetLayerPropertiesForTesting(root.get(), |
| 3310 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3311 | gfx::PointF(), |
| 3312 | gfx::PointF(), |
| 3313 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3314 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3315 | false); |
| 3316 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3317 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3318 | gfx::PointF(), |
| 3319 | gfx::PointF(), |
| 3320 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3321 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3322 | false); |
| 3323 | SetLayerPropertiesForTesting(child1.get(), |
| 3324 | child_rotation, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3325 | gfx::PointF(0.5f, 0.5f), |
| 3326 | gfx::PointF(25.f, 25.f), |
| 3327 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3328 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3329 | false); |
| 3330 | |
| 3331 | root->SetMasksToBounds(true); |
| 3332 | render_surface1->SetForceRenderSurface(true); |
| 3333 | ExecuteCalculateDrawProperties(root.get()); |
| 3334 | |
| 3335 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3336 | |
| 3337 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3338 | // rotated layer. |
| 3339 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3340 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3341 | 50 - diagonal_radius, |
| 3342 | diagonal_radius * 2, |
| 3343 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3344 | gfx::Rect expected_surface_drawable_content = |
| 3345 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
| 3346 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3347 | render_surface1->render_surface()->DrawableContentRect()); |
| 3348 | |
| 3349 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3350 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3351 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3352 | // |
| 3353 | // Given the floating point math, this number is a little bit fuzzy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3354 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
| 3355 | |
| 3356 | // The child's DrawableContentRect is unclipped. |
| 3357 | EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
| 3358 | } |
| 3359 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3360 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3361 | MockContentLayerClient client; |
| 3362 | |
| 3363 | scoped_refptr<Layer> root = Layer::Create(); |
| 3364 | scoped_refptr<ContentLayer> render_surface1 = |
| 3365 | CreateDrawableContentLayer(&client); |
| 3366 | scoped_refptr<ContentLayer> render_surface2 = |
| 3367 | CreateDrawableContentLayer(&client); |
| 3368 | scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client); |
| 3369 | scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client); |
| 3370 | scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client); |
| 3371 | root->AddChild(render_surface1); |
| 3372 | render_surface1->AddChild(render_surface2); |
| 3373 | render_surface2->AddChild(child1); |
| 3374 | render_surface2->AddChild(child2); |
| 3375 | render_surface2->AddChild(child3); |
| 3376 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3377 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3378 | host->SetRootLayer(root); |
| 3379 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3380 | gfx::Transform identity_matrix; |
| 3381 | SetLayerPropertiesForTesting(root.get(), |
| 3382 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3383 | gfx::PointF(), |
| 3384 | gfx::PointF(), |
| 3385 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3386 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3387 | false); |
| 3388 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3389 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3390 | gfx::PointF(), |
| 3391 | gfx::PointF(5.f, 5.f), |
| 3392 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3393 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3394 | false); |
| 3395 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3396 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3397 | gfx::PointF(), |
| 3398 | gfx::PointF(5.f, 5.f), |
| 3399 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3400 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3401 | false); |
| 3402 | SetLayerPropertiesForTesting(child1.get(), |
| 3403 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3404 | gfx::PointF(), |
| 3405 | gfx::PointF(5.f, 5.f), |
| 3406 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3407 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3408 | false); |
| 3409 | SetLayerPropertiesForTesting(child2.get(), |
| 3410 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3411 | gfx::PointF(), |
| 3412 | gfx::PointF(75.f, 75.f), |
| 3413 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3414 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3415 | false); |
| 3416 | SetLayerPropertiesForTesting(child3.get(), |
| 3417 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3418 | gfx::PointF(), |
| 3419 | gfx::PointF(125.f, 125.f), |
| 3420 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3421 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3422 | false); |
| 3423 | |
| 3424 | float device_scale_factor = 2.f; |
| 3425 | |
| 3426 | root->SetMasksToBounds(true); |
| 3427 | render_surface1->SetForceRenderSurface(true); |
| 3428 | render_surface2->SetForceRenderSurface(true); |
| 3429 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3430 | |
| 3431 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3432 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3433 | |
| 3434 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3435 | // device_scale_factor. |
| 3436 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3437 | root->render_surface()->DrawableContentRect()); |
| 3438 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3439 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3440 | render_surface1->render_surface()->DrawableContentRect()); |
| 3441 | |
| 3442 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3443 | // is only implicitly clipped by render_surface1. |
| 3444 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3445 | render_surface2->render_surface()->DrawableContentRect()); |
| 3446 | |
| 3447 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3448 | EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), |
| 3449 | child2->drawable_content_rect()); |
| 3450 | EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), |
| 3451 | child3->drawable_content_rect()); |
| 3452 | |
| 3453 | // The root layer does not actually draw content of its own. |
| 3454 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3455 | |
| 3456 | // All layer visible content rects are expressed in content space of each |
| 3457 | // layer, so they are also scaled by the device_scale_factor. |
| 3458 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8), |
| 3459 | render_surface1->visible_content_rect()); |
| 3460 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26), |
| 3461 | render_surface2->visible_content_rect()); |
| 3462 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect()); |
| 3463 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect()); |
| 3464 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect()); |
| 3465 | } |
| 3466 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3467 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3468 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3469 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3470 | // "flattened" to each parent layer according to current W3C spec. |
| 3471 | |
| 3472 | const gfx::Transform identity_matrix; |
| 3473 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3474 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3475 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3476 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3477 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3478 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3479 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3480 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3481 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3482 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3483 | front_facing_child_of_front_facing_surface = |
| 3484 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3485 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3486 | back_facing_child_of_front_facing_surface = |
| 3487 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3488 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3489 | front_facing_child_of_back_facing_surface = |
| 3490 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3491 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3492 | back_facing_child_of_back_facing_surface = |
| 3493 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3494 | |
| 3495 | parent->AddChild(front_facing_child); |
| 3496 | parent->AddChild(back_facing_child); |
| 3497 | parent->AddChild(front_facing_surface); |
| 3498 | parent->AddChild(back_facing_surface); |
| 3499 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3500 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3501 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3502 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3503 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3504 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3505 | host->SetRootLayer(parent); |
| 3506 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3507 | // Nothing is double-sided |
| 3508 | front_facing_child->SetDoubleSided(false); |
| 3509 | back_facing_child->SetDoubleSided(false); |
| 3510 | front_facing_surface->SetDoubleSided(false); |
| 3511 | back_facing_surface->SetDoubleSided(false); |
| 3512 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3513 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3514 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3515 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3516 | |
| 3517 | gfx::Transform backface_matrix; |
| 3518 | backface_matrix.Translate(50.0, 50.0); |
| 3519 | backface_matrix.RotateAboutYAxis(180.0); |
| 3520 | backface_matrix.Translate(-50.0, -50.0); |
| 3521 | |
| 3522 | // Having a descendant and opacity will force these to have render surfaces. |
| 3523 | front_facing_surface->SetOpacity(0.5f); |
| 3524 | back_facing_surface->SetOpacity(0.5f); |
| 3525 | |
| 3526 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3527 | // these layers should blindly use their own local transforms to determine |
| 3528 | // back-face culling. |
| 3529 | SetLayerPropertiesForTesting(parent.get(), |
| 3530 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3531 | gfx::PointF(), |
| 3532 | gfx::PointF(), |
| 3533 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3534 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3535 | false); |
| 3536 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3537 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3538 | gfx::PointF(), |
| 3539 | gfx::PointF(), |
| 3540 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3541 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3542 | false); |
| 3543 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3544 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3545 | gfx::PointF(), |
| 3546 | gfx::PointF(), |
| 3547 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3548 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3549 | false); |
| 3550 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3551 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3552 | gfx::PointF(), |
| 3553 | gfx::PointF(), |
| 3554 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3555 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3556 | false); |
| 3557 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3558 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3559 | gfx::PointF(), |
| 3560 | gfx::PointF(), |
| 3561 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3562 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3563 | false); |
| 3564 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3565 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3566 | gfx::PointF(), |
| 3567 | gfx::PointF(), |
| 3568 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3569 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3570 | false); |
| 3571 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3572 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3573 | gfx::PointF(), |
| 3574 | gfx::PointF(), |
| 3575 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3576 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3577 | false); |
| 3578 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3579 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3580 | gfx::PointF(), |
| 3581 | gfx::PointF(), |
| 3582 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3583 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3584 | false); |
| 3585 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3586 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3587 | gfx::PointF(), |
| 3588 | gfx::PointF(), |
| 3589 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3590 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3591 | false); |
| 3592 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3593 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3594 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3595 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3596 | inputs.can_adjust_raster_scales = true; |
| 3597 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3598 | |
| 3599 | // Verify which render surfaces were created. |
| 3600 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3601 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3602 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3603 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3604 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3605 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3606 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3607 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3608 | |
| 3609 | // Verify the render_surface_layer_list. |
| 3610 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3611 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3612 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3613 | // Even though the back facing surface LAYER gets culled, the other |
| 3614 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3615 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3616 | |
| 3617 | // Verify root surface's layer list. |
| 3618 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3619 | 3u, |
| 3620 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3621 | EXPECT_EQ(front_facing_child->id(), |
| 3622 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3623 | ->render_surface() |
| 3624 | ->layer_list() |
| 3625 | .at(0) |
| 3626 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3627 | EXPECT_EQ(front_facing_surface->id(), |
| 3628 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3629 | ->render_surface() |
| 3630 | ->layer_list() |
| 3631 | .at(1) |
| 3632 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3633 | EXPECT_EQ(back_facing_surface->id(), |
| 3634 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3635 | ->render_surface() |
| 3636 | ->layer_list() |
| 3637 | .at(2) |
| 3638 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3639 | |
| 3640 | // Verify front_facing_surface's layer list. |
| 3641 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3642 | 2u, |
| 3643 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3644 | EXPECT_EQ(front_facing_surface->id(), |
| 3645 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3646 | ->render_surface() |
| 3647 | ->layer_list() |
| 3648 | .at(0) |
| 3649 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3650 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3651 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3652 | ->render_surface() |
| 3653 | ->layer_list() |
| 3654 | .at(1) |
| 3655 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3656 | |
| 3657 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3658 | // from the surface list. |
| 3659 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3660 | 1u, |
| 3661 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3662 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3663 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3664 | ->render_surface() |
| 3665 | ->layer_list() |
| 3666 | .at(0) |
| 3667 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3668 | } |
| 3669 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3670 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3671 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3672 | // is used. |
| 3673 | |
| 3674 | const gfx::Transform identity_matrix; |
| 3675 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3676 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3677 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3678 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3679 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3680 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3681 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3682 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3683 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3684 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3685 | front_facing_child_of_front_facing_surface = |
| 3686 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3687 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3688 | back_facing_child_of_front_facing_surface = |
| 3689 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3690 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3691 | front_facing_child_of_back_facing_surface = |
| 3692 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3693 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3694 | back_facing_child_of_back_facing_surface = |
| 3695 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3696 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3697 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3698 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3699 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3700 | |
| 3701 | parent->AddChild(front_facing_child); |
| 3702 | parent->AddChild(back_facing_child); |
| 3703 | parent->AddChild(front_facing_surface); |
| 3704 | parent->AddChild(back_facing_surface); |
| 3705 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3706 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3707 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3708 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3709 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3710 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3711 | host->SetRootLayer(parent); |
| 3712 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3713 | // Nothing is double-sided |
| 3714 | front_facing_child->SetDoubleSided(false); |
| 3715 | back_facing_child->SetDoubleSided(false); |
| 3716 | front_facing_surface->SetDoubleSided(false); |
| 3717 | back_facing_surface->SetDoubleSided(false); |
| 3718 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3719 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3720 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3721 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3722 | |
| 3723 | gfx::Transform backface_matrix; |
| 3724 | backface_matrix.Translate(50.0, 50.0); |
| 3725 | backface_matrix.RotateAboutYAxis(180.0); |
| 3726 | backface_matrix.Translate(-50.0, -50.0); |
| 3727 | |
| 3728 | // Opacity will not force creation of render surfaces in this case because of |
| 3729 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3730 | // would be created with preserve-3d is when there is a replica layer. |
| 3731 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3732 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3733 | |
| 3734 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3735 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3736 | // rendering context should use the transform with respect to that context. |
| 3737 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3738 | // and (b) the layer's transform style is preserve-3d. |
| 3739 | SetLayerPropertiesForTesting(parent.get(), |
| 3740 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3741 | gfx::PointF(), |
| 3742 | gfx::PointF(), |
| 3743 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3744 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3745 | false); // parent transform style is flat. |
| 3746 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3747 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3748 | gfx::PointF(), |
| 3749 | gfx::PointF(), |
| 3750 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3751 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3752 | false); |
| 3753 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3754 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3755 | gfx::PointF(), |
| 3756 | gfx::PointF(), |
| 3757 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3758 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3759 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3760 | // surface transform style is preserve-3d. |
| 3761 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3762 | identity_matrix, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3763 | gfx::PointF(), |
| 3764 | gfx::PointF(), |
| 3765 | gfx::Size(100, 100), |
| 3766 | false, |
| 3767 | true); |
| 3768 | // surface transform style is preserve-3d. |
| 3769 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3770 | backface_matrix, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3771 | gfx::PointF(), |
| 3772 | gfx::PointF(), |
| 3773 | gfx::Size(100, 100), |
| 3774 | false, |
| 3775 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3776 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3777 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3778 | gfx::PointF(), |
| 3779 | gfx::PointF(), |
| 3780 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3781 | true, |
| 3782 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3783 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3784 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3785 | gfx::PointF(), |
| 3786 | gfx::PointF(), |
| 3787 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3788 | true, |
| 3789 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3790 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3791 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3792 | gfx::PointF(), |
| 3793 | gfx::PointF(), |
| 3794 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3795 | true, |
| 3796 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3797 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3798 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3799 | gfx::PointF(), |
| 3800 | gfx::PointF(), |
| 3801 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3802 | true, |
| 3803 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3804 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3805 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3806 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3807 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3808 | inputs.can_adjust_raster_scales = true; |
| 3809 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3810 | |
| 3811 | // Verify which render surfaces were created. |
| 3812 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3813 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3814 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3815 | EXPECT_FALSE(back_facing_surface->render_surface()); |
| 3816 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3817 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3818 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3819 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3820 | |
| 3821 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3822 | // culled. |
| 3823 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3824 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3825 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3826 | |
| 3827 | // Verify root surface's layer list. |
| 3828 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3829 | 2u, |
| 3830 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3831 | EXPECT_EQ(front_facing_child->id(), |
| 3832 | render_surface_layer_list.at(0) |
| 3833 | ->render_surface()->layer_list().at(0)->id()); |
| 3834 | EXPECT_EQ(front_facing_surface->id(), |
| 3835 | render_surface_layer_list.at(0) |
| 3836 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3837 | |
| 3838 | // Verify front_facing_surface's layer list. |
| 3839 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3840 | 2u, |
| 3841 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3842 | EXPECT_EQ(front_facing_surface->id(), |
| 3843 | render_surface_layer_list.at(1) |
| 3844 | ->render_surface()->layer_list().at(0)->id()); |
| 3845 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3846 | render_surface_layer_list.at(1) |
| 3847 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3848 | } |
| 3849 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3850 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3851 | // Verify that layers are appropriately culled when their back face is showing |
| 3852 | // and they are not double sided, while animations are going on. |
| 3853 | // |
| 3854 | // Layers that are animating do not get culled on the main thread, as their |
| 3855 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3856 | // back face is really showing. |
| 3857 | const gfx::Transform identity_matrix; |
| 3858 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3859 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3860 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3861 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3862 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3863 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3864 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3865 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3866 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3867 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3868 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3869 | |
| 3870 | parent->AddChild(child); |
| 3871 | parent->AddChild(animating_surface); |
| 3872 | animating_surface->AddChild(child_of_animating_surface); |
| 3873 | parent->AddChild(animating_child); |
| 3874 | parent->AddChild(child2); |
| 3875 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3876 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3877 | host->SetRootLayer(parent); |
| 3878 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3879 | // Nothing is double-sided |
| 3880 | child->SetDoubleSided(false); |
| 3881 | child2->SetDoubleSided(false); |
| 3882 | animating_surface->SetDoubleSided(false); |
| 3883 | child_of_animating_surface->SetDoubleSided(false); |
| 3884 | animating_child->SetDoubleSided(false); |
| 3885 | |
| 3886 | gfx::Transform backface_matrix; |
| 3887 | backface_matrix.Translate(50.0, 50.0); |
| 3888 | backface_matrix.RotateAboutYAxis(180.0); |
| 3889 | backface_matrix.Translate(-50.0, -50.0); |
| 3890 | |
| 3891 | // Make our render surface. |
| 3892 | animating_surface->SetForceRenderSurface(true); |
| 3893 | |
| 3894 | // Animate the transform on the render surface. |
| 3895 | AddAnimatedTransformToController( |
| 3896 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 3897 | // This is just an animating layer, not a surface. |
| 3898 | AddAnimatedTransformToController( |
| 3899 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 3900 | |
| 3901 | SetLayerPropertiesForTesting(parent.get(), |
| 3902 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3903 | gfx::PointF(), |
| 3904 | gfx::PointF(), |
| 3905 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3906 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3907 | false); |
| 3908 | SetLayerPropertiesForTesting(child.get(), |
| 3909 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3910 | gfx::PointF(), |
| 3911 | gfx::PointF(), |
| 3912 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3913 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3914 | false); |
| 3915 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 3916 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3917 | gfx::PointF(), |
| 3918 | gfx::PointF(), |
| 3919 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3920 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3921 | false); |
| 3922 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 3923 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3924 | gfx::PointF(), |
| 3925 | gfx::PointF(), |
| 3926 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3927 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3928 | false); |
| 3929 | SetLayerPropertiesForTesting(animating_child.get(), |
| 3930 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3931 | gfx::PointF(), |
| 3932 | gfx::PointF(), |
| 3933 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3934 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3935 | false); |
| 3936 | SetLayerPropertiesForTesting(child2.get(), |
| 3937 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3938 | gfx::PointF(), |
| 3939 | gfx::PointF(), |
| 3940 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3941 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3942 | false); |
| 3943 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3944 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3945 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3946 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3947 | inputs.can_adjust_raster_scales = true; |
| 3948 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3949 | |
| 3950 | EXPECT_FALSE(child->render_surface()); |
| 3951 | EXPECT_TRUE(animating_surface->render_surface()); |
| 3952 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 3953 | EXPECT_FALSE(animating_child->render_surface()); |
| 3954 | EXPECT_FALSE(child2->render_surface()); |
| 3955 | |
| 3956 | // Verify that the animating_child and child_of_animating_surface were not |
| 3957 | // culled, but that child was. |
| 3958 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3959 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3960 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3961 | |
| 3962 | // The non-animating child be culled from the layer list for the parent render |
| 3963 | // surface. |
| 3964 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3965 | 3u, |
| 3966 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3967 | EXPECT_EQ(animating_surface->id(), |
| 3968 | render_surface_layer_list.at(0) |
| 3969 | ->render_surface()->layer_list().at(0)->id()); |
| 3970 | EXPECT_EQ(animating_child->id(), |
| 3971 | render_surface_layer_list.at(0) |
| 3972 | ->render_surface()->layer_list().at(1)->id()); |
| 3973 | EXPECT_EQ(child2->id(), |
| 3974 | render_surface_layer_list.at(0) |
| 3975 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3976 | |
| 3977 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3978 | 2u, |
| 3979 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3980 | EXPECT_EQ(animating_surface->id(), |
| 3981 | render_surface_layer_list.at(1) |
| 3982 | ->render_surface()->layer_list().at(0)->id()); |
| 3983 | EXPECT_EQ(child_of_animating_surface->id(), |
| 3984 | render_surface_layer_list.at(1) |
| 3985 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3986 | |
| 3987 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 3988 | |
| 3989 | // The animating layers should have a visible content rect that represents the |
| 3990 | // area of the front face that is within the viewport. |
| 3991 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3992 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3993 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3994 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3995 | // And layers in the subtree of the animating layer should have valid visible |
| 3996 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3997 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 3998 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3999 | } |
| 4000 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4001 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4002 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4003 | // Verify the behavior of back-face culling for a render surface that is |
| 4004 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4005 | |
| 4006 | const gfx::Transform identity_matrix; |
| 4007 | scoped_refptr<Layer> parent = Layer::Create(); |
| 4008 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 4009 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4010 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 4011 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4012 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 4013 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4014 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 4015 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4016 | |
| 4017 | parent->AddChild(front_facing_surface); |
| 4018 | parent->AddChild(back_facing_surface); |
| 4019 | front_facing_surface->AddChild(child1); |
| 4020 | back_facing_surface->AddChild(child2); |
| 4021 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4022 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4023 | host->SetRootLayer(parent); |
| 4024 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4025 | // RenderSurfaces are not double-sided |
| 4026 | front_facing_surface->SetDoubleSided(false); |
| 4027 | back_facing_surface->SetDoubleSided(false); |
| 4028 | |
| 4029 | gfx::Transform backface_matrix; |
| 4030 | backface_matrix.Translate(50.0, 50.0); |
| 4031 | backface_matrix.RotateAboutYAxis(180.0); |
| 4032 | backface_matrix.Translate(-50.0, -50.0); |
| 4033 | |
| 4034 | SetLayerPropertiesForTesting(parent.get(), |
| 4035 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4036 | gfx::PointF(), |
| 4037 | gfx::PointF(), |
| 4038 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4039 | false, |
| 4040 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4041 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4042 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4043 | gfx::PointF(), |
| 4044 | gfx::PointF(), |
| 4045 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4046 | true, |
| 4047 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4048 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4049 | backface_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4050 | gfx::PointF(), |
| 4051 | gfx::PointF(), |
| 4052 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4053 | true, |
| 4054 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4055 | SetLayerPropertiesForTesting(child1.get(), |
| 4056 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4057 | gfx::PointF(), |
| 4058 | gfx::PointF(), |
| 4059 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4060 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4061 | false); |
| 4062 | SetLayerPropertiesForTesting(child2.get(), |
| 4063 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4064 | gfx::PointF(), |
| 4065 | gfx::PointF(), |
| 4066 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4067 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4068 | false); |
| 4069 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4070 | front_facing_surface->SetIs3dSorted(true); |
| 4071 | back_facing_surface->SetIs3dSorted(true); |
| 4072 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4073 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4074 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4075 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4076 | inputs.can_adjust_raster_scales = true; |
| 4077 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4078 | |
| 4079 | // Verify which render surfaces were created. |
| 4080 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 4081 | EXPECT_FALSE( |
| 4082 | back_facing_surface->render_surface()); // because it should be culled |
| 4083 | EXPECT_FALSE(child1->render_surface()); |
| 4084 | EXPECT_FALSE(child2->render_surface()); |
| 4085 | |
| 4086 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4087 | // culled. |
| 4088 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4089 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4090 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4091 | |
| 4092 | // Verify root surface's layer list. |
| 4093 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4094 | 1u, |
| 4095 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4096 | EXPECT_EQ(front_facing_surface->id(), |
| 4097 | render_surface_layer_list.at(0) |
| 4098 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4099 | |
| 4100 | // Verify front_facing_surface's layer list. |
| 4101 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4102 | 2u, |
| 4103 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4104 | EXPECT_EQ(front_facing_surface->id(), |
| 4105 | render_surface_layer_list.at(1) |
| 4106 | ->render_surface()->layer_list().at(0)->id()); |
| 4107 | EXPECT_EQ(child1->id(), |
| 4108 | render_surface_layer_list.at(1) |
| 4109 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4110 | } |
| 4111 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4112 | |
| 4113 | TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayerList) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4114 | // Hit testing on an empty render_surface_layer_list should return a null |
| 4115 | // pointer. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4116 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4117 | |
| 4118 | gfx::Point test_point(0, 0); |
| 4119 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4120 | test_point, render_surface_layer_list); |
| 4121 | EXPECT_FALSE(result_layer); |
| 4122 | |
| 4123 | test_point = gfx::Point(10, 20); |
| 4124 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4125 | test_point, render_surface_layer_list); |
| 4126 | EXPECT_FALSE(result_layer); |
| 4127 | } |
| 4128 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4129 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4130 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4131 | TestSharedBitmapManager shared_bitmap_manager; |
| 4132 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4133 | scoped_ptr<LayerImpl> root = |
| 4134 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4135 | |
| 4136 | gfx::Transform identity_matrix; |
| 4137 | gfx::PointF anchor; |
| 4138 | gfx::PointF position; |
| 4139 | gfx::Size bounds(100, 100); |
| 4140 | SetLayerPropertiesForTesting(root.get(), |
| 4141 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4142 | anchor, |
| 4143 | position, |
| 4144 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4145 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4146 | false); |
| 4147 | root->SetDrawsContent(true); |
| 4148 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4149 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4150 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4151 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4152 | inputs.can_adjust_raster_scales = true; |
| 4153 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4154 | |
| 4155 | // Sanity check the scenario we just created. |
| 4156 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4157 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4158 | |
| 4159 | // Hit testing for a point outside the layer should return a null pointer. |
| 4160 | gfx::Point test_point(101, 101); |
| 4161 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4162 | test_point, render_surface_layer_list); |
| 4163 | EXPECT_FALSE(result_layer); |
| 4164 | |
| 4165 | test_point = gfx::Point(-1, -1); |
| 4166 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4167 | test_point, render_surface_layer_list); |
| 4168 | EXPECT_FALSE(result_layer); |
| 4169 | |
| 4170 | // Hit testing for a point inside should return the root layer. |
| 4171 | test_point = gfx::Point(1, 1); |
| 4172 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4173 | test_point, render_surface_layer_list); |
| 4174 | ASSERT_TRUE(result_layer); |
| 4175 | EXPECT_EQ(12345, result_layer->id()); |
| 4176 | |
| 4177 | test_point = gfx::Point(99, 99); |
| 4178 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4179 | test_point, render_surface_layer_list); |
| 4180 | ASSERT_TRUE(result_layer); |
| 4181 | EXPECT_EQ(12345, result_layer->id()); |
| 4182 | } |
| 4183 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4184 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerAndHud) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4185 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4186 | TestSharedBitmapManager shared_bitmap_manager; |
| 4187 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4188 | scoped_ptr<LayerImpl> root = |
| 4189 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4190 | scoped_ptr<HeadsUpDisplayLayerImpl> hud = |
| 4191 | HeadsUpDisplayLayerImpl::Create(host_impl.active_tree(), 11111); |
| 4192 | |
| 4193 | gfx::Transform identity_matrix; |
| 4194 | gfx::PointF anchor; |
| 4195 | gfx::PointF position; |
| 4196 | gfx::Size bounds(100, 100); |
| 4197 | SetLayerPropertiesForTesting(root.get(), |
| 4198 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4199 | anchor, |
| 4200 | position, |
| 4201 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4202 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4203 | false); |
| 4204 | root->SetDrawsContent(true); |
| 4205 | |
| 4206 | // Create hud and add it as a child of root. |
| 4207 | gfx::Size hud_bounds(200, 200); |
| 4208 | SetLayerPropertiesForTesting(hud.get(), |
| 4209 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4210 | anchor, |
| 4211 | position, |
| 4212 | hud_bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4213 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4214 | false); |
| 4215 | hud->SetDrawsContent(true); |
| 4216 | |
| 4217 | host_impl.active_tree()->set_hud_layer(hud.get()); |
| 4218 | root->AddChild(hud.PassAs<LayerImpl>()); |
| 4219 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4220 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4221 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4222 | root.get(), hud_bounds, &render_surface_layer_list); |
| 4223 | inputs.can_adjust_raster_scales = true; |
| 4224 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4225 | |
| 4226 | // Sanity check the scenario we just created. |
| 4227 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4228 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 4229 | |
| 4230 | // Hit testing for a point inside HUD, but outside root should return null |
| 4231 | gfx::Point test_point(101, 101); |
| 4232 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4233 | test_point, render_surface_layer_list); |
| 4234 | EXPECT_FALSE(result_layer); |
| 4235 | |
| 4236 | test_point = gfx::Point(-1, -1); |
| 4237 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4238 | test_point, render_surface_layer_list); |
| 4239 | EXPECT_FALSE(result_layer); |
| 4240 | |
| 4241 | // Hit testing for a point inside should return the root layer, never the HUD |
| 4242 | // layer. |
| 4243 | test_point = gfx::Point(1, 1); |
| 4244 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4245 | test_point, render_surface_layer_list); |
| 4246 | ASSERT_TRUE(result_layer); |
| 4247 | EXPECT_EQ(12345, result_layer->id()); |
| 4248 | |
| 4249 | test_point = gfx::Point(99, 99); |
| 4250 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4251 | test_point, render_surface_layer_list); |
| 4252 | ASSERT_TRUE(result_layer); |
| 4253 | EXPECT_EQ(12345, result_layer->id()); |
| 4254 | } |
| 4255 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4256 | TEST_F(LayerTreeHostCommonTest, HitTestingForUninvertibleTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4257 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4258 | TestSharedBitmapManager shared_bitmap_manager; |
| 4259 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4260 | scoped_ptr<LayerImpl> root = |
| 4261 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4262 | |
| 4263 | gfx::Transform uninvertible_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4264 | uninvertible_transform.matrix().set(0, 0, 0.0); |
| 4265 | uninvertible_transform.matrix().set(1, 1, 0.0); |
| 4266 | uninvertible_transform.matrix().set(2, 2, 0.0); |
| 4267 | uninvertible_transform.matrix().set(3, 3, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4268 | ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
| 4269 | |
| 4270 | gfx::Transform identity_matrix; |
| 4271 | gfx::PointF anchor; |
| 4272 | gfx::PointF position; |
| 4273 | gfx::Size bounds(100, 100); |
| 4274 | SetLayerPropertiesForTesting(root.get(), |
| 4275 | uninvertible_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4276 | anchor, |
| 4277 | position, |
| 4278 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4279 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4280 | false); |
| 4281 | root->SetDrawsContent(true); |
| 4282 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4283 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4284 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4285 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4286 | inputs.can_adjust_raster_scales = true; |
| 4287 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4288 | |
| 4289 | // Sanity check the scenario we just created. |
| 4290 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4291 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4292 | ASSERT_FALSE(root->screen_space_transform().IsInvertible()); |
| 4293 | |
| 4294 | // Hit testing any point should not hit the layer. If the invertible matrix is |
| 4295 | // accidentally ignored and treated like an identity, then the hit testing |
| 4296 | // will incorrectly hit the layer when it shouldn't. |
| 4297 | gfx::Point test_point(1, 1); |
| 4298 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4299 | test_point, render_surface_layer_list); |
| 4300 | EXPECT_FALSE(result_layer); |
| 4301 | |
| 4302 | test_point = gfx::Point(10, 10); |
| 4303 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4304 | test_point, render_surface_layer_list); |
| 4305 | EXPECT_FALSE(result_layer); |
| 4306 | |
| 4307 | test_point = gfx::Point(10, 30); |
| 4308 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4309 | test_point, render_surface_layer_list); |
| 4310 | EXPECT_FALSE(result_layer); |
| 4311 | |
| 4312 | test_point = gfx::Point(50, 50); |
| 4313 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4314 | test_point, render_surface_layer_list); |
| 4315 | EXPECT_FALSE(result_layer); |
| 4316 | |
| 4317 | test_point = gfx::Point(67, 48); |
| 4318 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4319 | test_point, render_surface_layer_list); |
| 4320 | EXPECT_FALSE(result_layer); |
| 4321 | |
| 4322 | test_point = gfx::Point(99, 99); |
| 4323 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4324 | test_point, render_surface_layer_list); |
| 4325 | EXPECT_FALSE(result_layer); |
| 4326 | |
| 4327 | test_point = gfx::Point(-1, -1); |
| 4328 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4329 | test_point, render_surface_layer_list); |
| 4330 | EXPECT_FALSE(result_layer); |
| 4331 | } |
| 4332 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4333 | TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePositionedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4334 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4335 | TestSharedBitmapManager shared_bitmap_manager; |
| 4336 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4337 | scoped_ptr<LayerImpl> root = |
| 4338 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4339 | |
| 4340 | gfx::Transform identity_matrix; |
| 4341 | gfx::PointF anchor; |
| 4342 | // this layer is positioned, and hit testing should correctly know where the |
| 4343 | // layer is located. |
| 4344 | gfx::PointF position(50.f, 50.f); |
| 4345 | gfx::Size bounds(100, 100); |
| 4346 | SetLayerPropertiesForTesting(root.get(), |
| 4347 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4348 | anchor, |
| 4349 | position, |
| 4350 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4351 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4352 | false); |
| 4353 | root->SetDrawsContent(true); |
| 4354 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4355 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4356 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4357 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4358 | inputs.can_adjust_raster_scales = true; |
| 4359 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4360 | |
| 4361 | // Sanity check the scenario we just created. |
| 4362 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4363 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4364 | |
| 4365 | // Hit testing for a point outside the layer should return a null pointer. |
| 4366 | gfx::Point test_point(49, 49); |
| 4367 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4368 | test_point, render_surface_layer_list); |
| 4369 | EXPECT_FALSE(result_layer); |
| 4370 | |
| 4371 | // Even though the layer exists at (101, 101), it should not be visible there |
| 4372 | // since the root render surface would clamp it. |
| 4373 | test_point = gfx::Point(101, 101); |
| 4374 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4375 | test_point, render_surface_layer_list); |
| 4376 | EXPECT_FALSE(result_layer); |
| 4377 | |
| 4378 | // Hit testing for a point inside should return the root layer. |
| 4379 | test_point = gfx::Point(51, 51); |
| 4380 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4381 | test_point, render_surface_layer_list); |
| 4382 | ASSERT_TRUE(result_layer); |
| 4383 | EXPECT_EQ(12345, result_layer->id()); |
| 4384 | |
| 4385 | test_point = gfx::Point(99, 99); |
| 4386 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4387 | test_point, render_surface_layer_list); |
| 4388 | ASSERT_TRUE(result_layer); |
| 4389 | EXPECT_EQ(12345, result_layer->id()); |
| 4390 | } |
| 4391 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4392 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleRotatedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4393 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4394 | TestSharedBitmapManager shared_bitmap_manager; |
| 4395 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4396 | scoped_ptr<LayerImpl> root = |
| 4397 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4398 | |
| 4399 | gfx::Transform identity_matrix; |
| 4400 | gfx::Transform rotation45_degrees_about_center; |
| 4401 | rotation45_degrees_about_center.Translate(50.0, 50.0); |
| 4402 | rotation45_degrees_about_center.RotateAboutZAxis(45.0); |
| 4403 | rotation45_degrees_about_center.Translate(-50.0, -50.0); |
| 4404 | gfx::PointF anchor; |
| 4405 | gfx::PointF position; |
| 4406 | gfx::Size bounds(100, 100); |
| 4407 | SetLayerPropertiesForTesting(root.get(), |
| 4408 | rotation45_degrees_about_center, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4409 | anchor, |
| 4410 | position, |
| 4411 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4412 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4413 | false); |
| 4414 | root->SetDrawsContent(true); |
| 4415 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4416 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4417 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4418 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4419 | inputs.can_adjust_raster_scales = true; |
| 4420 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4421 | |
| 4422 | // Sanity check the scenario we just created. |
| 4423 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4424 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4425 | |
| 4426 | // Hit testing for points outside the layer. |
| 4427 | // These corners would have been inside the un-transformed layer, but they |
| 4428 | // should not hit the correctly transformed layer. |
| 4429 | gfx::Point test_point(99, 99); |
| 4430 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4431 | test_point, render_surface_layer_list); |
| 4432 | EXPECT_FALSE(result_layer); |
| 4433 | |
| 4434 | test_point = gfx::Point(1, 1); |
| 4435 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4436 | test_point, render_surface_layer_list); |
| 4437 | EXPECT_FALSE(result_layer); |
| 4438 | |
| 4439 | // Hit testing for a point inside should return the root layer. |
| 4440 | test_point = gfx::Point(1, 50); |
| 4441 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4442 | test_point, render_surface_layer_list); |
| 4443 | ASSERT_TRUE(result_layer); |
| 4444 | EXPECT_EQ(12345, result_layer->id()); |
| 4445 | |
| 4446 | // Hit testing the corners that would overlap the unclipped layer, but are |
| 4447 | // outside the clipped region. |
| 4448 | test_point = gfx::Point(50, -1); |
| 4449 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4450 | test_point, render_surface_layer_list); |
| 4451 | ASSERT_FALSE(result_layer); |
| 4452 | |
| 4453 | test_point = gfx::Point(-1, 50); |
| 4454 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4455 | test_point, render_surface_layer_list); |
| 4456 | ASSERT_FALSE(result_layer); |
| 4457 | } |
| 4458 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4459 | TEST_F(LayerTreeHostCommonTest, HitTestingForSinglePerspectiveLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4460 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4461 | TestSharedBitmapManager shared_bitmap_manager; |
| 4462 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4463 | scoped_ptr<LayerImpl> root = |
| 4464 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4465 | |
| 4466 | gfx::Transform identity_matrix; |
| 4467 | |
| 4468 | // perspective_projection_about_center * translation_by_z is designed so that |
| 4469 | // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). |
| 4470 | gfx::Transform perspective_projection_about_center; |
| 4471 | perspective_projection_about_center.Translate(50.0, 50.0); |
| 4472 | perspective_projection_about_center.ApplyPerspectiveDepth(1.0); |
| 4473 | perspective_projection_about_center.Translate(-50.0, -50.0); |
| 4474 | gfx::Transform translation_by_z; |
| 4475 | translation_by_z.Translate3d(0.0, 0.0, -1.0); |
| 4476 | |
| 4477 | gfx::PointF anchor; |
| 4478 | gfx::PointF position; |
| 4479 | gfx::Size bounds(100, 100); |
| 4480 | SetLayerPropertiesForTesting( |
| 4481 | root.get(), |
| 4482 | perspective_projection_about_center * translation_by_z, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4483 | anchor, |
| 4484 | position, |
| 4485 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4486 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4487 | false); |
| 4488 | root->SetDrawsContent(true); |
| 4489 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4490 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4491 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4492 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4493 | inputs.can_adjust_raster_scales = true; |
| 4494 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4495 | |
| 4496 | // Sanity check the scenario we just created. |
| 4497 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4498 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4499 | |
| 4500 | // Hit testing for points outside the layer. |
| 4501 | // These corners would have been inside the un-transformed layer, but they |
| 4502 | // should not hit the correctly transformed layer. |
| 4503 | gfx::Point test_point(24, 24); |
| 4504 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4505 | test_point, render_surface_layer_list); |
| 4506 | EXPECT_FALSE(result_layer); |
| 4507 | |
| 4508 | test_point = gfx::Point(76, 76); |
| 4509 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4510 | test_point, render_surface_layer_list); |
| 4511 | EXPECT_FALSE(result_layer); |
| 4512 | |
| 4513 | // Hit testing for a point inside should return the root layer. |
| 4514 | test_point = gfx::Point(26, 26); |
| 4515 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4516 | test_point, render_surface_layer_list); |
| 4517 | ASSERT_TRUE(result_layer); |
| 4518 | EXPECT_EQ(12345, result_layer->id()); |
| 4519 | |
| 4520 | test_point = gfx::Point(74, 74); |
| 4521 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4522 | test_point, render_surface_layer_list); |
| 4523 | ASSERT_TRUE(result_layer); |
| 4524 | EXPECT_EQ(12345, result_layer->id()); |
| 4525 | } |
| 4526 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4527 | TEST_F(LayerTreeHostCommonTest, HitTestingForSingleLayerWithScaledContents) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4528 | // A layer's visible content rect is actually in the layer's content space. |
| 4529 | // The screen space transform converts from the layer's origin space to screen |
| 4530 | // space. This test makes sure that hit testing works correctly accounts for |
| 4531 | // the contents scale. A contents scale that is not 1 effectively forces a |
| 4532 | // non-identity transform between layer's content space and layer's origin |
| 4533 | // space. The hit testing code must take this into account. |
| 4534 | // |
| 4535 | // To test this, the layer is positioned at (25, 25), and is size (50, 50). If |
| 4536 | // contents scale is ignored, then hit testing will mis-interpret the visible |
| 4537 | // content rect as being larger than the actual bounds of the layer. |
| 4538 | // |
| 4539 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4540 | TestSharedBitmapManager shared_bitmap_manager; |
| 4541 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4542 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4543 | |
| 4544 | gfx::Transform identity_matrix; |
| 4545 | gfx::PointF anchor; |
| 4546 | |
| 4547 | SetLayerPropertiesForTesting(root.get(), |
| 4548 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4549 | anchor, |
| 4550 | gfx::PointF(), |
| 4551 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4552 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4553 | false); |
| 4554 | { |
| 4555 | gfx::PointF position(25.f, 25.f); |
| 4556 | gfx::Size bounds(50, 50); |
| 4557 | scoped_ptr<LayerImpl> test_layer = |
| 4558 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 4559 | SetLayerPropertiesForTesting(test_layer.get(), |
| 4560 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4561 | anchor, |
| 4562 | position, |
| 4563 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4564 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4565 | false); |
| 4566 | |
| 4567 | // override content bounds and contents scale |
| 4568 | test_layer->SetContentBounds(gfx::Size(100, 100)); |
| 4569 | test_layer->SetContentsScale(2, 2); |
| 4570 | |
| 4571 | test_layer->SetDrawsContent(true); |
| 4572 | root->AddChild(test_layer.Pass()); |
| 4573 | } |
| 4574 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4575 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4576 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4577 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4578 | inputs.can_adjust_raster_scales = true; |
| 4579 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4580 | |
| 4581 | // Sanity check the scenario we just created. |
| 4582 | // The visible content rect for test_layer is actually 100x100, even though |
| 4583 | // its layout size is 50x50, positioned at 25x25. |
| 4584 | LayerImpl* test_layer = root->children()[0]; |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4585 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4586 | test_layer->visible_content_rect()); |
| 4587 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4588 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 4589 | |
| 4590 | // Hit testing for a point outside the layer should return a null pointer (the |
| 4591 | // root layer does not draw content, so it will not be hit tested either). |
| 4592 | gfx::Point test_point(101, 101); |
| 4593 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4594 | test_point, render_surface_layer_list); |
| 4595 | EXPECT_FALSE(result_layer); |
| 4596 | |
| 4597 | test_point = gfx::Point(24, 24); |
| 4598 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4599 | test_point, render_surface_layer_list); |
| 4600 | EXPECT_FALSE(result_layer); |
| 4601 | |
| 4602 | test_point = gfx::Point(76, 76); |
| 4603 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4604 | test_point, render_surface_layer_list); |
| 4605 | EXPECT_FALSE(result_layer); |
| 4606 | |
| 4607 | // Hit testing for a point inside should return the test layer. |
| 4608 | test_point = gfx::Point(26, 26); |
| 4609 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4610 | test_point, render_surface_layer_list); |
| 4611 | ASSERT_TRUE(result_layer); |
| 4612 | EXPECT_EQ(12345, result_layer->id()); |
| 4613 | |
| 4614 | test_point = gfx::Point(74, 74); |
| 4615 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4616 | test_point, render_surface_layer_list); |
| 4617 | ASSERT_TRUE(result_layer); |
| 4618 | EXPECT_EQ(12345, result_layer->id()); |
| 4619 | } |
| 4620 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4621 | TEST_F(LayerTreeHostCommonTest, HitTestingForSimpleClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4622 | // Test that hit-testing will only work for the visible portion of a layer, |
| 4623 | // and not the entire layer bounds. Here we just test the simple axis-aligned |
| 4624 | // case. |
| 4625 | gfx::Transform identity_matrix; |
| 4626 | gfx::PointF anchor; |
| 4627 | |
| 4628 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4629 | TestSharedBitmapManager shared_bitmap_manager; |
| 4630 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4631 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4632 | SetLayerPropertiesForTesting(root.get(), |
| 4633 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4634 | anchor, |
| 4635 | gfx::PointF(), |
| 4636 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4637 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4638 | false); |
| 4639 | { |
| 4640 | scoped_ptr<LayerImpl> clipping_layer = |
| 4641 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 4642 | // this layer is positioned, and hit testing should correctly know where the |
| 4643 | // layer is located. |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 4644 | gfx::PointF position(25.f, 25.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4645 | gfx::Size bounds(50, 50); |
| 4646 | SetLayerPropertiesForTesting(clipping_layer.get(), |
| 4647 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4648 | anchor, |
| 4649 | position, |
| 4650 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4651 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4652 | false); |
| 4653 | clipping_layer->SetMasksToBounds(true); |
| 4654 | |
| 4655 | scoped_ptr<LayerImpl> child = |
| 4656 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4657 | position = gfx::PointF(-50.f, -50.f); |
| 4658 | bounds = gfx::Size(300, 300); |
| 4659 | SetLayerPropertiesForTesting(child.get(), |
| 4660 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4661 | anchor, |
| 4662 | position, |
| 4663 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4664 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4665 | false); |
| 4666 | child->SetDrawsContent(true); |
| 4667 | clipping_layer->AddChild(child.Pass()); |
| 4668 | root->AddChild(clipping_layer.Pass()); |
| 4669 | } |
| 4670 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4671 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4672 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4673 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4674 | inputs.can_adjust_raster_scales = true; |
| 4675 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4676 | |
| 4677 | // Sanity check the scenario we just created. |
| 4678 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4679 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4680 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4681 | |
| 4682 | // Hit testing for a point outside the layer should return a null pointer. |
| 4683 | // Despite the child layer being very large, it should be clipped to the root |
| 4684 | // layer's bounds. |
| 4685 | gfx::Point test_point(24, 24); |
| 4686 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4687 | test_point, render_surface_layer_list); |
| 4688 | EXPECT_FALSE(result_layer); |
| 4689 | |
| 4690 | // Even though the layer exists at (101, 101), it should not be visible there |
| 4691 | // since the clipping_layer would clamp it. |
| 4692 | test_point = gfx::Point(76, 76); |
| 4693 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4694 | test_point, render_surface_layer_list); |
| 4695 | EXPECT_FALSE(result_layer); |
| 4696 | |
| 4697 | // Hit testing for a point inside should return the child layer. |
| 4698 | test_point = gfx::Point(26, 26); |
| 4699 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4700 | test_point, render_surface_layer_list); |
| 4701 | ASSERT_TRUE(result_layer); |
| 4702 | EXPECT_EQ(456, result_layer->id()); |
| 4703 | |
| 4704 | test_point = gfx::Point(74, 74); |
| 4705 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4706 | test_point, render_surface_layer_list); |
| 4707 | ASSERT_TRUE(result_layer); |
| 4708 | EXPECT_EQ(456, result_layer->id()); |
| 4709 | } |
| 4710 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4711 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultiClippedRotatedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4712 | // This test checks whether hit testing correctly avoids hit testing with |
| 4713 | // multiple ancestors that clip in non axis-aligned ways. To pass this test, |
| 4714 | // the hit testing algorithm needs to recognize that multiple parent layers |
| 4715 | // may clip the layer, and should not actually hit those clipped areas. |
| 4716 | // |
| 4717 | // The child and grand_child layers are both initialized to clip the |
| 4718 | // rotated_leaf. The child layer is rotated about the top-left corner, so that |
| 4719 | // the root + child clips combined create a triangle. The rotated_leaf will |
| 4720 | // only be visible where it overlaps this triangle. |
| 4721 | // |
| 4722 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4723 | TestSharedBitmapManager shared_bitmap_manager; |
| 4724 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4725 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 123); |
| 4726 | |
| 4727 | gfx::Transform identity_matrix; |
| 4728 | gfx::PointF anchor; |
| 4729 | gfx::PointF position; |
| 4730 | gfx::Size bounds(100, 100); |
| 4731 | SetLayerPropertiesForTesting(root.get(), |
| 4732 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4733 | anchor, |
| 4734 | position, |
| 4735 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4736 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4737 | false); |
| 4738 | root->SetMasksToBounds(true); |
| 4739 | { |
| 4740 | scoped_ptr<LayerImpl> child = |
| 4741 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4742 | scoped_ptr<LayerImpl> grand_child = |
| 4743 | LayerImpl::Create(host_impl.active_tree(), 789); |
| 4744 | scoped_ptr<LayerImpl> rotated_leaf = |
| 4745 | LayerImpl::Create(host_impl.active_tree(), 2468); |
| 4746 | |
| 4747 | position = gfx::PointF(10.f, 10.f); |
| 4748 | bounds = gfx::Size(80, 80); |
| 4749 | SetLayerPropertiesForTesting(child.get(), |
| 4750 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4751 | anchor, |
| 4752 | position, |
| 4753 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4754 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4755 | false); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 4756 | child->SetMasksToBounds(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4757 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4758 | gfx::Transform rotation45_degrees_about_corner; |
| 4759 | rotation45_degrees_about_corner.RotateAboutZAxis(45.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4760 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4761 | // remember, positioned with respect to its parent which is already at 10, |
| 4762 | // 10 |
| 4763 | position = gfx::PointF(); |
| 4764 | bounds = |
| 4765 | gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100. |
| 4766 | SetLayerPropertiesForTesting(grand_child.get(), |
| 4767 | rotation45_degrees_about_corner, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4768 | anchor, |
| 4769 | position, |
| 4770 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4771 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4772 | false); |
| 4773 | grand_child->SetMasksToBounds(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4774 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4775 | // Rotates about the center of the layer |
| 4776 | gfx::Transform rotated_leaf_transform; |
| 4777 | rotated_leaf_transform.Translate( |
| 4778 | -10.0, -10.0); // cancel out the grand_parent's position |
| 4779 | rotated_leaf_transform.RotateAboutZAxis( |
| 4780 | -45.0); // cancel out the corner 45-degree rotation of the parent. |
| 4781 | rotated_leaf_transform.Translate(50.0, 50.0); |
| 4782 | rotated_leaf_transform.RotateAboutZAxis(45.0); |
| 4783 | rotated_leaf_transform.Translate(-50.0, -50.0); |
| 4784 | position = gfx::PointF(); |
| 4785 | bounds = gfx::Size(100, 100); |
| 4786 | SetLayerPropertiesForTesting(rotated_leaf.get(), |
| 4787 | rotated_leaf_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4788 | anchor, |
| 4789 | position, |
| 4790 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4791 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4792 | false); |
| 4793 | rotated_leaf->SetDrawsContent(true); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4794 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4795 | grand_child->AddChild(rotated_leaf.Pass()); |
| 4796 | child->AddChild(grand_child.Pass()); |
| 4797 | root->AddChild(child.Pass()); |
| 4798 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4799 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4800 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4801 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4802 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4803 | inputs.can_adjust_raster_scales = true; |
| 4804 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4805 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4806 | // Sanity check the scenario we just created. |
| 4807 | // The grand_child is expected to create a render surface because it |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4808 | // MasksToBounds and is not axis aligned. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4809 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
| 4810 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4811 | 1u, |
| 4812 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4813 | ASSERT_EQ(789, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4814 | render_surface_layer_list.at(0)->render_surface()->layer_list().at( |
| 4815 | 0)->id()); // grand_child's surface. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4816 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4817 | 1u, |
| 4818 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4819 | ASSERT_EQ( |
| 4820 | 2468, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4821 | render_surface_layer_list[1]->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4822 | |
| 4823 | // (11, 89) is close to the the bottom left corner within the clip, but it is |
| 4824 | // not inside the layer. |
| 4825 | gfx::Point test_point(11, 89); |
| 4826 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4827 | test_point, render_surface_layer_list); |
| 4828 | EXPECT_FALSE(result_layer); |
| 4829 | |
| 4830 | // Closer inwards from the bottom left will overlap the layer. |
| 4831 | test_point = gfx::Point(25, 75); |
| 4832 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4833 | test_point, render_surface_layer_list); |
| 4834 | ASSERT_TRUE(result_layer); |
| 4835 | EXPECT_EQ(2468, result_layer->id()); |
| 4836 | |
| 4837 | // (4, 50) is inside the unclipped layer, but that corner of the layer should |
| 4838 | // be clipped away by the grandparent and should not get hit. If hit testing |
| 4839 | // blindly uses visible content rect without considering how parent may clip |
| 4840 | // the layer, then hit testing would accidentally think that the point |
| 4841 | // successfully hits the layer. |
| 4842 | test_point = gfx::Point(4, 50); |
| 4843 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4844 | test_point, render_surface_layer_list); |
| 4845 | EXPECT_FALSE(result_layer); |
| 4846 | |
| 4847 | // (11, 50) is inside the layer and within the clipped area. |
| 4848 | test_point = gfx::Point(11, 50); |
| 4849 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4850 | test_point, render_surface_layer_list); |
| 4851 | ASSERT_TRUE(result_layer); |
| 4852 | EXPECT_EQ(2468, result_layer->id()); |
| 4853 | |
| 4854 | // Around the middle, just to the right and up, would have hit the layer |
| 4855 | // except that that area should be clipped away by the parent. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4856 | test_point = gfx::Point(51, 49); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4857 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4858 | test_point, render_surface_layer_list); |
| 4859 | EXPECT_FALSE(result_layer); |
| 4860 | |
| 4861 | // Around the middle, just to the left and down, should successfully hit the |
| 4862 | // layer. |
| 4863 | test_point = gfx::Point(49, 51); |
| 4864 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4865 | test_point, render_surface_layer_list); |
| 4866 | ASSERT_TRUE(result_layer); |
| 4867 | EXPECT_EQ(2468, result_layer->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4868 | } |
| 4869 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4870 | TEST_F(LayerTreeHostCommonTest, HitTestingForNonClippingIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4871 | // This test checks that hit testing code does not accidentally clip to layer |
| 4872 | // bounds for a layer that actually does not clip. |
| 4873 | gfx::Transform identity_matrix; |
| 4874 | gfx::PointF anchor; |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4875 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4876 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4877 | TestSharedBitmapManager shared_bitmap_manager; |
| 4878 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4879 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 4880 | SetLayerPropertiesForTesting(root.get(), |
| 4881 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4882 | anchor, |
| 4883 | gfx::PointF(), |
| 4884 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4885 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4886 | false); |
| 4887 | { |
| 4888 | scoped_ptr<LayerImpl> intermediate_layer = |
| 4889 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 4890 | // this layer is positioned, and hit testing should correctly know where the |
| 4891 | // layer is located. |
| 4892 | gfx::PointF position(10.f, 10.f); |
| 4893 | gfx::Size bounds(50, 50); |
| 4894 | SetLayerPropertiesForTesting(intermediate_layer.get(), |
| 4895 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4896 | anchor, |
| 4897 | position, |
| 4898 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4899 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4900 | false); |
| 4901 | // Sanity check the intermediate layer should not clip. |
| 4902 | ASSERT_FALSE(intermediate_layer->masks_to_bounds()); |
| 4903 | ASSERT_FALSE(intermediate_layer->mask_layer()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4904 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4905 | // The child of the intermediate_layer is translated so that it does not |
| 4906 | // overlap intermediate_layer at all. If child is incorrectly clipped, we |
| 4907 | // would not be able to hit it successfully. |
| 4908 | scoped_ptr<LayerImpl> child = |
| 4909 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 4910 | position = gfx::PointF(60.f, 60.f); // 70, 70 in screen space |
| 4911 | bounds = gfx::Size(20, 20); |
| 4912 | SetLayerPropertiesForTesting(child.get(), |
| 4913 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4914 | anchor, |
| 4915 | position, |
| 4916 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4917 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4918 | false); |
| 4919 | child->SetDrawsContent(true); |
| 4920 | intermediate_layer->AddChild(child.Pass()); |
| 4921 | root->AddChild(intermediate_layer.Pass()); |
| 4922 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4923 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 4924 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4925 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 4926 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4927 | inputs.can_adjust_raster_scales = true; |
| 4928 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4929 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4930 | // Sanity check the scenario we just created. |
| 4931 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 4932 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4933 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4934 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4935 | // Hit testing for a point outside the layer should return a null pointer. |
| 4936 | gfx::Point test_point(69, 69); |
| 4937 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4938 | test_point, render_surface_layer_list); |
| 4939 | EXPECT_FALSE(result_layer); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4940 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4941 | test_point = gfx::Point(91, 91); |
| 4942 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4943 | test_point, render_surface_layer_list); |
| 4944 | EXPECT_FALSE(result_layer); |
| 4945 | |
| 4946 | // Hit testing for a point inside should return the child layer. |
| 4947 | test_point = gfx::Point(71, 71); |
| 4948 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4949 | test_point, render_surface_layer_list); |
| 4950 | ASSERT_TRUE(result_layer); |
| 4951 | EXPECT_EQ(456, result_layer->id()); |
| 4952 | |
| 4953 | test_point = gfx::Point(89, 89); |
| 4954 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 4955 | test_point, render_surface_layer_list); |
| 4956 | ASSERT_TRUE(result_layer); |
| 4957 | EXPECT_EQ(456, result_layer->id()); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 4958 | } |
| 4959 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4960 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4961 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 4962 | TestSharedBitmapManager shared_bitmap_manager; |
| 4963 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4964 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4965 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4966 | gfx::Transform identity_matrix; |
| 4967 | gfx::PointF anchor; |
| 4968 | gfx::PointF position; |
| 4969 | gfx::Size bounds(100, 100); |
| 4970 | SetLayerPropertiesForTesting(root.get(), |
| 4971 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4972 | anchor, |
| 4973 | position, |
| 4974 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4975 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4976 | false); |
| 4977 | root->SetDrawsContent(true); |
| 4978 | { |
| 4979 | // child 1 and child2 are initialized to overlap between x=50 and x=60. |
| 4980 | // grand_child is set to overlap both child1 and child2 between y=50 and |
| 4981 | // y=60. The expected stacking order is: (front) child2, (second) |
| 4982 | // grand_child, (third) child1, and (back) the root layer behind all other |
| 4983 | // layers. |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 4984 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4985 | scoped_ptr<LayerImpl> child1 = |
| 4986 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 4987 | scoped_ptr<LayerImpl> child2 = |
| 4988 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 4989 | scoped_ptr<LayerImpl> grand_child1 = |
| 4990 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4991 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4992 | position = gfx::PointF(10.f, 10.f); |
| 4993 | bounds = gfx::Size(50, 50); |
| 4994 | SetLayerPropertiesForTesting(child1.get(), |
| 4995 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4996 | anchor, |
| 4997 | position, |
| 4998 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4999 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5000 | false); |
| 5001 | child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5002 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5003 | position = gfx::PointF(50.f, 10.f); |
| 5004 | bounds = gfx::Size(50, 50); |
| 5005 | SetLayerPropertiesForTesting(child2.get(), |
| 5006 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5007 | anchor, |
| 5008 | position, |
| 5009 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5010 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5011 | false); |
| 5012 | child2->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5013 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5014 | // Remember that grand_child is positioned with respect to its parent (i.e. |
| 5015 | // child1). In screen space, the intended position is (10, 50), with size |
| 5016 | // 100 x 50. |
| 5017 | position = gfx::PointF(0.f, 40.f); |
| 5018 | bounds = gfx::Size(100, 50); |
| 5019 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 5020 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5021 | anchor, |
| 5022 | position, |
| 5023 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5024 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5025 | false); |
| 5026 | grand_child1->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5027 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5028 | child1->AddChild(grand_child1.Pass()); |
| 5029 | root->AddChild(child1.Pass()); |
| 5030 | root->AddChild(child2.Pass()); |
| 5031 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5032 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5033 | LayerImpl* child1 = root->children()[0]; |
| 5034 | LayerImpl* child2 = root->children()[1]; |
| 5035 | LayerImpl* grand_child1 = child1->children()[0]; |
| 5036 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5037 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5038 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5039 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5040 | inputs.can_adjust_raster_scales = true; |
| 5041 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5042 | |
| 5043 | // Sanity check the scenario we just created. |
| 5044 | ASSERT_TRUE(child1); |
| 5045 | ASSERT_TRUE(child2); |
| 5046 | ASSERT_TRUE(grand_child1); |
| 5047 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5048 | |
| 5049 | RenderSurfaceImpl* root_render_surface = root->render_surface(); |
| 5050 | ASSERT_EQ(4u, root_render_surface->layer_list().size()); |
| 5051 | ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer |
| 5052 | ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1 |
| 5053 | ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1 |
| 5054 | ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2 |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5055 | |
| 5056 | // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
| 5057 | // the root layer. |
| 5058 | gfx::Point test_point = gfx::Point(1, 1); |
| 5059 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5060 | test_point, render_surface_layer_list); |
| 5061 | ASSERT_TRUE(result_layer); |
| 5062 | EXPECT_EQ(1, result_layer->id()); |
| 5063 | |
| 5064 | // At (15, 15), child1 and root are the only layers. child1 is expected to be |
| 5065 | // on top. |
| 5066 | test_point = gfx::Point(15, 15); |
| 5067 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5068 | test_point, render_surface_layer_list); |
| 5069 | ASSERT_TRUE(result_layer); |
| 5070 | EXPECT_EQ(2, result_layer->id()); |
| 5071 | |
| 5072 | // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. |
| 5073 | test_point = gfx::Point(51, 20); |
| 5074 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5075 | test_point, render_surface_layer_list); |
| 5076 | ASSERT_TRUE(result_layer); |
| 5077 | EXPECT_EQ(3, result_layer->id()); |
| 5078 | |
| 5079 | // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on |
| 5080 | // top. |
| 5081 | test_point = gfx::Point(80, 51); |
| 5082 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5083 | test_point, render_surface_layer_list); |
| 5084 | ASSERT_TRUE(result_layer); |
| 5085 | EXPECT_EQ(3, result_layer->id()); |
| 5086 | |
| 5087 | // At (51, 51), all layers overlap each other. child2 is expected to be on top |
| 5088 | // of all other layers. |
| 5089 | test_point = gfx::Point(51, 51); |
| 5090 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5091 | test_point, render_surface_layer_list); |
| 5092 | ASSERT_TRUE(result_layer); |
| 5093 | EXPECT_EQ(3, result_layer->id()); |
| 5094 | |
| 5095 | // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to |
| 5096 | // be on top. |
| 5097 | test_point = gfx::Point(20, 51); |
| 5098 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5099 | test_point, render_surface_layer_list); |
| 5100 | ASSERT_TRUE(result_layer); |
| 5101 | EXPECT_EQ(4, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5102 | } |
| 5103 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5104 | TEST_F(LayerTreeHostCommonTest, HitTestingForMultipleLayerLists) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5105 | // |
| 5106 | // The geometry is set up similarly to the previous case, but |
| 5107 | // all layers are forced to be render surfaces now. |
| 5108 | // |
| 5109 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5110 | TestSharedBitmapManager shared_bitmap_manager; |
| 5111 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5112 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5113 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5114 | gfx::Transform identity_matrix; |
| 5115 | gfx::PointF anchor; |
| 5116 | gfx::PointF position; |
| 5117 | gfx::Size bounds(100, 100); |
| 5118 | SetLayerPropertiesForTesting(root.get(), |
| 5119 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5120 | anchor, |
| 5121 | position, |
| 5122 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5123 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5124 | false); |
| 5125 | root->SetDrawsContent(true); |
| 5126 | { |
| 5127 | // child 1 and child2 are initialized to overlap between x=50 and x=60. |
| 5128 | // grand_child is set to overlap both child1 and child2 between y=50 and |
| 5129 | // y=60. The expected stacking order is: (front) child2, (second) |
| 5130 | // grand_child, (third) child1, and (back) the root layer behind all other |
| 5131 | // layers. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5132 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5133 | scoped_ptr<LayerImpl> child1 = |
| 5134 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 5135 | scoped_ptr<LayerImpl> child2 = |
| 5136 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 5137 | scoped_ptr<LayerImpl> grand_child1 = |
| 5138 | LayerImpl::Create(host_impl.active_tree(), 4); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5139 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5140 | position = gfx::PointF(10.f, 10.f); |
| 5141 | bounds = gfx::Size(50, 50); |
| 5142 | SetLayerPropertiesForTesting(child1.get(), |
| 5143 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5144 | anchor, |
| 5145 | position, |
| 5146 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5147 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5148 | false); |
| 5149 | child1->SetDrawsContent(true); |
| 5150 | child1->SetForceRenderSurface(true); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 5151 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5152 | position = gfx::PointF(50.f, 10.f); |
| 5153 | bounds = gfx::Size(50, 50); |
| 5154 | SetLayerPropertiesForTesting(child2.get(), |
| 5155 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5156 | anchor, |
| 5157 | position, |
| 5158 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5159 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5160 | false); |
| 5161 | child2->SetDrawsContent(true); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 5162 | child2->SetForceRenderSurface(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5163 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5164 | // Remember that grand_child is positioned with respect to its parent (i.e. |
| 5165 | // child1). In screen space, the intended position is (10, 50), with size |
| 5166 | // 100 x 50. |
| 5167 | position = gfx::PointF(0.f, 40.f); |
| 5168 | bounds = gfx::Size(100, 50); |
| 5169 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 5170 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5171 | anchor, |
| 5172 | position, |
| 5173 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5174 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5175 | false); |
| 5176 | grand_child1->SetDrawsContent(true); |
| 5177 | grand_child1->SetForceRenderSurface(true); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5178 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5179 | child1->AddChild(grand_child1.Pass()); |
| 5180 | root->AddChild(child1.Pass()); |
| 5181 | root->AddChild(child2.Pass()); |
| 5182 | } |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5183 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5184 | LayerImpl* child1 = root->children()[0]; |
| 5185 | LayerImpl* child2 = root->children()[1]; |
| 5186 | LayerImpl* grand_child1 = child1->children()[0]; |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5187 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5188 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5189 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5190 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5191 | inputs.can_adjust_raster_scales = true; |
| 5192 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5193 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5194 | // Sanity check the scenario we just created. |
| 5195 | ASSERT_TRUE(child1); |
| 5196 | ASSERT_TRUE(child2); |
| 5197 | ASSERT_TRUE(grand_child1); |
| 5198 | ASSERT_TRUE(child1->render_surface()); |
| 5199 | ASSERT_TRUE(child2->render_surface()); |
| 5200 | ASSERT_TRUE(grand_child1->render_surface()); |
| 5201 | ASSERT_EQ(4u, render_surface_layer_list.size()); |
| 5202 | // The root surface has the root layer, and child1's and child2's render |
| 5203 | // surfaces. |
| 5204 | ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
| 5205 | // The child1 surface has the child1 layer and grand_child1's render surface. |
| 5206 | ASSERT_EQ(2u, child1->render_surface()->layer_list().size()); |
| 5207 | ASSERT_EQ(1u, child2->render_surface()->layer_list().size()); |
| 5208 | ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5209 | ASSERT_EQ(1, render_surface_layer_list.at(0)->id()); // root layer |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5210 | ASSERT_EQ(2, render_surface_layer_list[1]->id()); // child1 |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5211 | ASSERT_EQ(4, render_surface_layer_list.at(2)->id()); // grand_child1 |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5212 | ASSERT_EQ(3, render_surface_layer_list[3]->id()); // child2 |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5213 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5214 | // Nothing overlaps the root_layer at (1, 1), so hit testing there should find |
| 5215 | // the root layer. |
| 5216 | gfx::Point test_point = gfx::Point(1, 1); |
| 5217 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5218 | test_point, render_surface_layer_list); |
| 5219 | ASSERT_TRUE(result_layer); |
| 5220 | EXPECT_EQ(1, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5221 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5222 | // At (15, 15), child1 and root are the only layers. child1 is expected to be |
| 5223 | // on top. |
| 5224 | test_point = gfx::Point(15, 15); |
| 5225 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5226 | test_point, render_surface_layer_list); |
| 5227 | ASSERT_TRUE(result_layer); |
| 5228 | EXPECT_EQ(2, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5229 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5230 | // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. |
| 5231 | test_point = gfx::Point(51, 20); |
| 5232 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5233 | test_point, render_surface_layer_list); |
| 5234 | ASSERT_TRUE(result_layer); |
| 5235 | EXPECT_EQ(3, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5236 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5237 | // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on |
| 5238 | // top. |
| 5239 | test_point = gfx::Point(80, 51); |
| 5240 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5241 | test_point, render_surface_layer_list); |
| 5242 | ASSERT_TRUE(result_layer); |
| 5243 | EXPECT_EQ(3, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5244 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5245 | // At (51, 51), all layers overlap each other. child2 is expected to be on top |
| 5246 | // of all other layers. |
| 5247 | test_point = gfx::Point(51, 51); |
| 5248 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5249 | test_point, render_surface_layer_list); |
| 5250 | ASSERT_TRUE(result_layer); |
| 5251 | EXPECT_EQ(3, result_layer->id()); |
| 5252 | |
| 5253 | // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to |
| 5254 | // be on top. |
| 5255 | test_point = gfx::Point(20, 51); |
| 5256 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5257 | test_point, render_surface_layer_list); |
| 5258 | ASSERT_TRUE(result_layer); |
| 5259 | EXPECT_EQ(4, result_layer->id()); |
[email protected] | dc462d78 | 2012-11-21 21:43:01 | [diff] [blame] | 5260 | } |
| 5261 | |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5262 | TEST_F(LayerTreeHostCommonTest, HitTestingForEmptyLayers) { |
| 5263 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5264 | TestSharedBitmapManager shared_bitmap_manager; |
| 5265 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5266 | |
| 5267 | // Layer 1 - root |
| 5268 | scoped_ptr<LayerImpl> root = |
| 5269 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 5270 | gfx::Transform identity_matrix; |
| 5271 | gfx::PointF anchor; |
| 5272 | gfx::PointF position; |
| 5273 | gfx::Size bounds(100, 100); |
| 5274 | SetLayerPropertiesForTesting(root.get(), |
| 5275 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5276 | anchor, |
| 5277 | position, |
| 5278 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5279 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5280 | false); |
| 5281 | root->SetDrawsContent(true); |
| 5282 | |
| 5283 | { |
| 5284 | // Layer 2 - empty: drawsContent=false |
| 5285 | gfx::PointF position(10.f, 10.f); |
| 5286 | gfx::Size bounds(30, 30); |
| 5287 | scoped_ptr<LayerImpl> empty_layer = |
| 5288 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 5289 | SetLayerPropertiesForTesting(empty_layer.get(), |
| 5290 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5291 | anchor, |
| 5292 | position, |
| 5293 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5294 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5295 | false); |
| 5296 | |
| 5297 | empty_layer->SetDrawsContent(false); |
| 5298 | root->AddChild(empty_layer.Pass()); |
| 5299 | } |
| 5300 | |
| 5301 | { |
| 5302 | // Layer 3 - empty, but has touch handler |
| 5303 | gfx::PointF position(10.f, 60.f); |
| 5304 | gfx::Size bounds(30, 30); |
| 5305 | scoped_ptr<LayerImpl> test_layer = |
| 5306 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 5307 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5308 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5309 | anchor, |
| 5310 | position, |
| 5311 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5312 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5313 | false); |
| 5314 | |
| 5315 | test_layer->SetDrawsContent(false); |
| 5316 | Region touch_handler_region(gfx::Rect(10, 10, 10, 10)); |
| 5317 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5318 | root->AddChild(test_layer.Pass()); |
| 5319 | } |
| 5320 | |
| 5321 | { |
| 5322 | // Layer 4 - empty, but has mousewheel handler |
| 5323 | gfx::PointF position(60.f, 60.f); |
| 5324 | gfx::Size bounds(30, 30); |
| 5325 | scoped_ptr<LayerImpl> test_layer = |
| 5326 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 5327 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5328 | identity_matrix, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5329 | anchor, |
| 5330 | position, |
| 5331 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5332 | true, |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5333 | false); |
| 5334 | |
| 5335 | test_layer->SetDrawsContent(false); |
| 5336 | test_layer->SetHaveWheelEventHandlers(true); |
| 5337 | root->AddChild(test_layer.Pass()); |
| 5338 | } |
| 5339 | |
| 5340 | LayerImplList render_surface_layer_list; |
| 5341 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5342 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5343 | inputs.can_adjust_raster_scales = true; |
| 5344 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5345 | |
| 5346 | // Verify that the root layer and empty layers with touch/wheel handlers |
| 5347 | // (but not the empty layer without a touch handler) are in the RSSL. |
| 5348 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5349 | EXPECT_EQ(1, render_surface_layer_list[0]->id()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5350 | ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5351 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5352 | EXPECT_EQ(3, root->render_surface()->layer_list().at(1)->id()); |
| 5353 | EXPECT_EQ(4, root->render_surface()->layer_list().at(2)->id()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5354 | |
| 5355 | // Hit testing for a point inside the empty no-handlers layer should return |
| 5356 | // the root layer. |
| 5357 | gfx::Point test_point = gfx::Point(15, 15); |
| 5358 | LayerImpl* result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5359 | test_point, render_surface_layer_list); |
| 5360 | ASSERT_TRUE(result_layer); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5361 | EXPECT_EQ(1, result_layer->id()); |
[email protected] | afc4f26 | 2013-10-05 01:14:10 | [diff] [blame] | 5362 | |
| 5363 | // Hit testing for a point inside the touch handler layer should return it. |
| 5364 | test_point = gfx::Point(15, 75); |
| 5365 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5366 | test_point, render_surface_layer_list); |
| 5367 | ASSERT_TRUE(result_layer); |
| 5368 | EXPECT_EQ(3, result_layer->id()); |
| 5369 | |
| 5370 | // Hit testing for a point inside the mousewheel layer should return it. |
| 5371 | test_point = gfx::Point(75, 75); |
| 5372 | result_layer = LayerTreeHostCommon::FindLayerThatIsHitByPoint( |
| 5373 | test_point, render_surface_layer_list); |
| 5374 | ASSERT_TRUE(result_layer); |
| 5375 | EXPECT_EQ(4, result_layer->id()); |
| 5376 | } |
| 5377 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5378 | TEST_F(LayerTreeHostCommonTest, |
| 5379 | HitCheckingTouchHandlerRegionsForEmptyLayerList) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5380 | // Hit checking on an empty render_surface_layer_list should return a null |
| 5381 | // pointer. |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5382 | LayerImplList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5383 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5384 | gfx::Point test_point(0, 0); |
| 5385 | LayerImpl* result_layer = |
| 5386 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5387 | test_point, render_surface_layer_list); |
| 5388 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5389 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5390 | test_point = gfx::Point(10, 20); |
| 5391 | result_layer = |
| 5392 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5393 | test_point, render_surface_layer_list); |
| 5394 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5395 | } |
| 5396 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5397 | TEST_F(LayerTreeHostCommonTest, HitCheckingTouchHandlerRegionsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5398 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5399 | TestSharedBitmapManager shared_bitmap_manager; |
| 5400 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5401 | scoped_ptr<LayerImpl> root = |
| 5402 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5403 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5404 | gfx::Transform identity_matrix; |
| 5405 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5406 | gfx::PointF anchor; |
| 5407 | gfx::PointF position; |
| 5408 | gfx::Size bounds(100, 100); |
| 5409 | SetLayerPropertiesForTesting(root.get(), |
| 5410 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5411 | anchor, |
| 5412 | position, |
| 5413 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5414 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5415 | false); |
| 5416 | root->SetDrawsContent(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5417 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5418 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5419 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5420 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5421 | inputs.can_adjust_raster_scales = true; |
| 5422 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5423 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5424 | // Sanity check the scenario we just created. |
| 5425 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5426 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5427 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5428 | // Hit checking for any point should return a null pointer for a layer without |
| 5429 | // any touch event handler regions. |
| 5430 | gfx::Point test_point(11, 11); |
| 5431 | LayerImpl* result_layer = |
| 5432 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5433 | test_point, render_surface_layer_list); |
| 5434 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5435 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5436 | root->SetTouchEventHandlerRegion(touch_handler_region); |
| 5437 | // Hit checking for a point outside the layer should return a null pointer. |
| 5438 | test_point = gfx::Point(101, 101); |
| 5439 | result_layer = |
| 5440 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5441 | test_point, render_surface_layer_list); |
| 5442 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5443 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5444 | test_point = gfx::Point(-1, -1); |
| 5445 | result_layer = |
| 5446 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5447 | test_point, render_surface_layer_list); |
| 5448 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5449 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5450 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5451 | // region should return a null pointer. |
| 5452 | test_point = gfx::Point(1, 1); |
| 5453 | result_layer = |
| 5454 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5455 | test_point, render_surface_layer_list); |
| 5456 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5457 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5458 | test_point = gfx::Point(99, 99); |
| 5459 | result_layer = |
| 5460 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5461 | test_point, render_surface_layer_list); |
| 5462 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5463 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5464 | // Hit checking for a point inside the touch event handler region should |
| 5465 | // return the root layer. |
| 5466 | test_point = gfx::Point(11, 11); |
| 5467 | result_layer = |
| 5468 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5469 | test_point, render_surface_layer_list); |
| 5470 | ASSERT_TRUE(result_layer); |
| 5471 | EXPECT_EQ(12345, result_layer->id()); |
| 5472 | |
| 5473 | test_point = gfx::Point(59, 59); |
| 5474 | result_layer = |
| 5475 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5476 | test_point, render_surface_layer_list); |
| 5477 | ASSERT_TRUE(result_layer); |
| 5478 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5479 | } |
| 5480 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5481 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5482 | HitCheckingTouchHandlerRegionsForUninvertibleTransform) { |
| 5483 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5484 | TestSharedBitmapManager shared_bitmap_manager; |
| 5485 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5486 | scoped_ptr<LayerImpl> root = |
| 5487 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5488 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5489 | gfx::Transform uninvertible_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5490 | uninvertible_transform.matrix().set(0, 0, 0.0); |
| 5491 | uninvertible_transform.matrix().set(1, 1, 0.0); |
| 5492 | uninvertible_transform.matrix().set(2, 2, 0.0); |
| 5493 | uninvertible_transform.matrix().set(3, 3, 0.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5494 | ASSERT_FALSE(uninvertible_transform.IsInvertible()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5495 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5496 | gfx::Transform identity_matrix; |
| 5497 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5498 | gfx::PointF anchor; |
| 5499 | gfx::PointF position; |
| 5500 | gfx::Size bounds(100, 100); |
| 5501 | SetLayerPropertiesForTesting(root.get(), |
| 5502 | uninvertible_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5503 | anchor, |
| 5504 | position, |
| 5505 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5506 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5507 | false); |
| 5508 | root->SetDrawsContent(true); |
| 5509 | root->SetTouchEventHandlerRegion(touch_handler_region); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5510 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5511 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5512 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5513 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5514 | inputs.can_adjust_raster_scales = true; |
| 5515 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5516 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5517 | // Sanity check the scenario we just created. |
| 5518 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5519 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5520 | ASSERT_FALSE(root->screen_space_transform().IsInvertible()); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5521 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5522 | // Hit checking any point should not hit the touch handler region on the |
| 5523 | // layer. If the invertible matrix is accidentally ignored and treated like an |
| 5524 | // identity, then the hit testing will incorrectly hit the layer when it |
| 5525 | // shouldn't. |
| 5526 | gfx::Point test_point(1, 1); |
| 5527 | LayerImpl* result_layer = |
| 5528 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5529 | test_point, render_surface_layer_list); |
| 5530 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5531 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5532 | test_point = gfx::Point(10, 10); |
| 5533 | result_layer = |
| 5534 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5535 | test_point, render_surface_layer_list); |
| 5536 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5537 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5538 | test_point = gfx::Point(10, 30); |
| 5539 | result_layer = |
| 5540 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5541 | test_point, render_surface_layer_list); |
| 5542 | EXPECT_FALSE(result_layer); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 5543 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5544 | test_point = gfx::Point(50, 50); |
| 5545 | result_layer = |
| 5546 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5547 | test_point, render_surface_layer_list); |
| 5548 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5549 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5550 | test_point = gfx::Point(67, 48); |
| 5551 | result_layer = |
| 5552 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5553 | test_point, render_surface_layer_list); |
| 5554 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5555 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5556 | test_point = gfx::Point(99, 99); |
| 5557 | result_layer = |
| 5558 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5559 | test_point, render_surface_layer_list); |
| 5560 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5561 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5562 | test_point = gfx::Point(-1, -1); |
| 5563 | result_layer = |
| 5564 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5565 | test_point, render_surface_layer_list); |
| 5566 | EXPECT_FALSE(result_layer); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5567 | } |
| 5568 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5569 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5570 | HitCheckingTouchHandlerRegionsForSinglePositionedLayer) { |
| 5571 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5572 | TestSharedBitmapManager shared_bitmap_manager; |
| 5573 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5574 | scoped_ptr<LayerImpl> root = |
| 5575 | LayerImpl::Create(host_impl.active_tree(), 12345); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5576 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5577 | gfx::Transform identity_matrix; |
| 5578 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5579 | gfx::PointF anchor; |
| 5580 | // this layer is positioned, and hit testing should correctly know where the |
| 5581 | // layer is located. |
| 5582 | gfx::PointF position(50.f, 50.f); |
| 5583 | gfx::Size bounds(100, 100); |
| 5584 | SetLayerPropertiesForTesting(root.get(), |
| 5585 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5586 | anchor, |
| 5587 | position, |
| 5588 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5589 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5590 | false); |
| 5591 | root->SetDrawsContent(true); |
| 5592 | root->SetTouchEventHandlerRegion(touch_handler_region); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5593 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5594 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5595 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5596 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5597 | inputs.can_adjust_raster_scales = true; |
| 5598 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5599 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5600 | // Sanity check the scenario we just created. |
| 5601 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5602 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5603 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5604 | // Hit checking for a point outside the layer should return a null pointer. |
| 5605 | gfx::Point test_point(49, 49); |
| 5606 | LayerImpl* result_layer = |
| 5607 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5608 | test_point, render_surface_layer_list); |
| 5609 | EXPECT_FALSE(result_layer); |
| 5610 | |
| 5611 | // Even though the layer has a touch handler region containing (101, 101), it |
| 5612 | // should not be visible there since the root render surface would clamp it. |
| 5613 | test_point = gfx::Point(101, 101); |
| 5614 | result_layer = |
| 5615 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5616 | test_point, render_surface_layer_list); |
| 5617 | EXPECT_FALSE(result_layer); |
| 5618 | |
| 5619 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5620 | // region should return a null pointer. |
| 5621 | test_point = gfx::Point(51, 51); |
| 5622 | result_layer = |
| 5623 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5624 | test_point, render_surface_layer_list); |
| 5625 | EXPECT_FALSE(result_layer); |
| 5626 | |
| 5627 | // Hit checking for a point inside the touch event handler region should |
| 5628 | // return the root layer. |
| 5629 | test_point = gfx::Point(61, 61); |
| 5630 | result_layer = |
| 5631 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5632 | test_point, render_surface_layer_list); |
| 5633 | ASSERT_TRUE(result_layer); |
| 5634 | EXPECT_EQ(12345, result_layer->id()); |
| 5635 | |
| 5636 | test_point = gfx::Point(99, 99); |
| 5637 | result_layer = |
| 5638 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5639 | test_point, render_surface_layer_list); |
| 5640 | ASSERT_TRUE(result_layer); |
| 5641 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5642 | } |
| 5643 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5644 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5645 | HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents) { |
| 5646 | // A layer's visible content rect is actually in the layer's content space. |
| 5647 | // The screen space transform converts from the layer's origin space to screen |
| 5648 | // space. This test makes sure that hit testing works correctly accounts for |
| 5649 | // the contents scale. A contents scale that is not 1 effectively forces a |
| 5650 | // non-identity transform between layer's content space and layer's origin |
| 5651 | // space. The hit testing code must take this into account. |
| 5652 | // |
| 5653 | // To test this, the layer is positioned at (25, 25), and is size (50, 50). If |
| 5654 | // contents scale is ignored, then hit checking will mis-interpret the visible |
| 5655 | // content rect as being larger than the actual bounds of the layer. |
| 5656 | // |
| 5657 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5658 | TestSharedBitmapManager shared_bitmap_manager; |
| 5659 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5660 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5661 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5662 | gfx::Transform identity_matrix; |
| 5663 | gfx::PointF anchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5664 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5665 | SetLayerPropertiesForTesting(root.get(), |
| 5666 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5667 | anchor, |
| 5668 | gfx::PointF(), |
| 5669 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5670 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5671 | false); |
| 5672 | { |
| 5673 | Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); |
| 5674 | gfx::PointF position(25.f, 25.f); |
| 5675 | gfx::Size bounds(50, 50); |
| 5676 | scoped_ptr<LayerImpl> test_layer = |
| 5677 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 5678 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5679 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5680 | anchor, |
| 5681 | position, |
| 5682 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5683 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5684 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5685 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5686 | // override content bounds and contents scale |
| 5687 | test_layer->SetContentBounds(gfx::Size(100, 100)); |
| 5688 | test_layer->SetContentsScale(2, 2); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5689 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5690 | test_layer->SetDrawsContent(true); |
| 5691 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5692 | root->AddChild(test_layer.Pass()); |
| 5693 | } |
| 5694 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5695 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5696 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5697 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5698 | inputs.can_adjust_raster_scales = true; |
| 5699 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5700 | |
| 5701 | // Sanity check the scenario we just created. |
| 5702 | // The visible content rect for test_layer is actually 100x100, even though |
| 5703 | // its layout size is 50x50, positioned at 25x25. |
| 5704 | LayerImpl* test_layer = root->children()[0]; |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 5705 | 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] | 5706 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5707 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5708 | |
| 5709 | // Hit checking for a point outside the layer should return a null pointer |
| 5710 | // (the root layer does not draw content, so it will not be tested either). |
| 5711 | gfx::Point test_point(76, 76); |
| 5712 | LayerImpl* result_layer = |
| 5713 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5714 | test_point, render_surface_layer_list); |
| 5715 | EXPECT_FALSE(result_layer); |
| 5716 | |
| 5717 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5718 | // region should return a null pointer. |
| 5719 | test_point = gfx::Point(26, 26); |
| 5720 | result_layer = |
| 5721 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5722 | test_point, render_surface_layer_list); |
| 5723 | EXPECT_FALSE(result_layer); |
| 5724 | |
| 5725 | test_point = gfx::Point(34, 34); |
| 5726 | result_layer = |
| 5727 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5728 | test_point, render_surface_layer_list); |
| 5729 | EXPECT_FALSE(result_layer); |
| 5730 | |
| 5731 | test_point = gfx::Point(65, 65); |
| 5732 | result_layer = |
| 5733 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5734 | test_point, render_surface_layer_list); |
| 5735 | EXPECT_FALSE(result_layer); |
| 5736 | |
| 5737 | test_point = gfx::Point(74, 74); |
| 5738 | result_layer = |
| 5739 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5740 | test_point, render_surface_layer_list); |
| 5741 | EXPECT_FALSE(result_layer); |
| 5742 | |
| 5743 | // Hit checking for a point inside the touch event handler region should |
| 5744 | // return the root layer. |
| 5745 | test_point = gfx::Point(35, 35); |
| 5746 | result_layer = |
| 5747 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5748 | test_point, render_surface_layer_list); |
| 5749 | ASSERT_TRUE(result_layer); |
| 5750 | EXPECT_EQ(12345, result_layer->id()); |
| 5751 | |
| 5752 | test_point = gfx::Point(64, 64); |
| 5753 | result_layer = |
| 5754 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5755 | test_point, render_surface_layer_list); |
| 5756 | ASSERT_TRUE(result_layer); |
| 5757 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5758 | } |
| 5759 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5760 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5761 | HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) { |
| 5762 | // The layer's device_scale_factor and page_scale_factor should scale the |
| 5763 | // content rect and we should be able to hit the touch handler region by |
| 5764 | // scaling the points accordingly. |
| 5765 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5766 | TestSharedBitmapManager shared_bitmap_manager; |
| 5767 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5768 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5769 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5770 | gfx::Transform identity_matrix; |
| 5771 | gfx::PointF anchor; |
| 5772 | // Set the bounds of the root layer big enough to fit the child when scaled. |
| 5773 | SetLayerPropertiesForTesting(root.get(), |
| 5774 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5775 | anchor, |
| 5776 | gfx::PointF(), |
| 5777 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5778 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5779 | false); |
| 5780 | { |
| 5781 | Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); |
| 5782 | gfx::PointF position(25.f, 25.f); |
| 5783 | gfx::Size bounds(50, 50); |
| 5784 | scoped_ptr<LayerImpl> test_layer = |
| 5785 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 5786 | SetLayerPropertiesForTesting(test_layer.get(), |
| 5787 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5788 | anchor, |
| 5789 | position, |
| 5790 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5791 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5792 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5793 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5794 | test_layer->SetDrawsContent(true); |
| 5795 | test_layer->SetTouchEventHandlerRegion(touch_handler_region); |
| 5796 | root->AddChild(test_layer.Pass()); |
| 5797 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5798 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5799 | LayerImplList render_surface_layer_list; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5800 | float device_scale_factor = 3.f; |
| 5801 | float page_scale_factor = 5.f; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5802 | gfx::Size scaled_bounds_for_root = gfx::ToCeiledSize( |
| 5803 | gfx::ScaleSize(root->bounds(), device_scale_factor * page_scale_factor)); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5804 | |
| 5805 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5806 | root.get(), scaled_bounds_for_root, &render_surface_layer_list); |
| 5807 | inputs.device_scale_factor = device_scale_factor; |
| 5808 | inputs.page_scale_factor = page_scale_factor; |
| 5809 | inputs.page_scale_application_layer = root.get(); |
| 5810 | inputs.can_adjust_raster_scales = true; |
| 5811 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5812 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5813 | // Sanity check the scenario we just created. |
| 5814 | // The visible content rect for test_layer is actually 100x100, even though |
| 5815 | // its layout size is 50x50, positioned at 25x25. |
| 5816 | LayerImpl* test_layer = root->children()[0]; |
| 5817 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5818 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5819 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5820 | // Check whether the child layer fits into the root after scaled. |
| 5821 | EXPECT_RECT_EQ(gfx::Rect(test_layer->content_bounds()), |
| 5822 | test_layer->visible_content_rect()); |
| 5823 | |
| 5824 | // Hit checking for a point outside the layer should return a null pointer |
| 5825 | // (the root layer does not draw content, so it will not be tested either). |
| 5826 | gfx::PointF test_point(76.f, 76.f); |
| 5827 | test_point = |
| 5828 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5829 | LayerImpl* result_layer = |
| 5830 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5831 | test_point, render_surface_layer_list); |
| 5832 | EXPECT_FALSE(result_layer); |
| 5833 | |
| 5834 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5835 | // region should return a null pointer. |
| 5836 | test_point = gfx::Point(26, 26); |
| 5837 | test_point = |
| 5838 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5839 | result_layer = |
| 5840 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5841 | test_point, render_surface_layer_list); |
| 5842 | EXPECT_FALSE(result_layer); |
| 5843 | |
| 5844 | test_point = gfx::Point(34, 34); |
| 5845 | test_point = |
| 5846 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5847 | result_layer = |
| 5848 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5849 | test_point, render_surface_layer_list); |
| 5850 | EXPECT_FALSE(result_layer); |
| 5851 | |
| 5852 | test_point = gfx::Point(65, 65); |
| 5853 | test_point = |
| 5854 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5855 | result_layer = |
| 5856 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5857 | test_point, render_surface_layer_list); |
| 5858 | EXPECT_FALSE(result_layer); |
| 5859 | |
| 5860 | test_point = gfx::Point(74, 74); |
| 5861 | test_point = |
| 5862 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5863 | result_layer = |
| 5864 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5865 | test_point, render_surface_layer_list); |
| 5866 | EXPECT_FALSE(result_layer); |
| 5867 | |
| 5868 | // Hit checking for a point inside the touch event handler region should |
| 5869 | // return the root layer. |
| 5870 | test_point = gfx::Point(35, 35); |
| 5871 | test_point = |
| 5872 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5873 | result_layer = |
| 5874 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5875 | test_point, render_surface_layer_list); |
| 5876 | ASSERT_TRUE(result_layer); |
| 5877 | EXPECT_EQ(12345, result_layer->id()); |
| 5878 | |
| 5879 | test_point = gfx::Point(64, 64); |
| 5880 | test_point = |
| 5881 | gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); |
| 5882 | result_layer = |
| 5883 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5884 | test_point, render_surface_layer_list); |
| 5885 | ASSERT_TRUE(result_layer); |
| 5886 | EXPECT_EQ(12345, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5887 | } |
| 5888 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5889 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5890 | HitCheckingTouchHandlerRegionsForSimpleClippedLayer) { |
| 5891 | // Test that hit-checking will only work for the visible portion of a layer, |
| 5892 | // and not the entire layer bounds. Here we just test the simple axis-aligned |
| 5893 | // case. |
| 5894 | gfx::Transform identity_matrix; |
| 5895 | gfx::PointF anchor; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5896 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5897 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5898 | TestSharedBitmapManager shared_bitmap_manager; |
| 5899 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5900 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 5901 | SetLayerPropertiesForTesting(root.get(), |
| 5902 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5903 | anchor, |
| 5904 | gfx::PointF(), |
| 5905 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5906 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5907 | false); |
| 5908 | { |
| 5909 | scoped_ptr<LayerImpl> clipping_layer = |
| 5910 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 5911 | // this layer is positioned, and hit testing should correctly know where the |
| 5912 | // layer is located. |
| 5913 | gfx::PointF position(25.f, 25.f); |
| 5914 | gfx::Size bounds(50, 50); |
| 5915 | SetLayerPropertiesForTesting(clipping_layer.get(), |
| 5916 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5917 | anchor, |
| 5918 | position, |
| 5919 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5920 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5921 | false); |
| 5922 | clipping_layer->SetMasksToBounds(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5923 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5924 | scoped_ptr<LayerImpl> child = |
| 5925 | LayerImpl::Create(host_impl.active_tree(), 456); |
| 5926 | Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); |
| 5927 | position = gfx::PointF(-50.f, -50.f); |
| 5928 | bounds = gfx::Size(300, 300); |
| 5929 | SetLayerPropertiesForTesting(child.get(), |
| 5930 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5931 | anchor, |
| 5932 | position, |
| 5933 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5934 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5935 | false); |
| 5936 | child->SetDrawsContent(true); |
| 5937 | child->SetTouchEventHandlerRegion(touch_handler_region); |
| 5938 | clipping_layer->AddChild(child.Pass()); |
| 5939 | root->AddChild(clipping_layer.Pass()); |
| 5940 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5941 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 5942 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5943 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5944 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5945 | inputs.can_adjust_raster_scales = true; |
| 5946 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5947 | |
| 5948 | // Sanity check the scenario we just created. |
| 5949 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 5950 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
| 5951 | ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5952 | |
| 5953 | // Hit checking for a point outside the layer should return a null pointer. |
| 5954 | // Despite the child layer being very large, it should be clipped to the root |
| 5955 | // layer's bounds. |
| 5956 | gfx::Point test_point(24, 24); |
| 5957 | LayerImpl* result_layer = |
| 5958 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5959 | test_point, render_surface_layer_list); |
| 5960 | EXPECT_FALSE(result_layer); |
| 5961 | |
| 5962 | // Hit checking for a point inside the layer, but outside the touch handler |
| 5963 | // region should return a null pointer. |
| 5964 | test_point = gfx::Point(35, 35); |
| 5965 | result_layer = |
| 5966 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5967 | test_point, render_surface_layer_list); |
| 5968 | EXPECT_FALSE(result_layer); |
| 5969 | |
| 5970 | test_point = gfx::Point(74, 74); |
| 5971 | result_layer = |
| 5972 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5973 | test_point, render_surface_layer_list); |
| 5974 | EXPECT_FALSE(result_layer); |
| 5975 | |
| 5976 | // Hit checking for a point inside the touch event handler region should |
| 5977 | // return the root layer. |
| 5978 | test_point = gfx::Point(25, 25); |
| 5979 | result_layer = |
| 5980 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5981 | test_point, render_surface_layer_list); |
| 5982 | ASSERT_TRUE(result_layer); |
| 5983 | EXPECT_EQ(456, result_layer->id()); |
| 5984 | |
| 5985 | test_point = gfx::Point(34, 34); |
| 5986 | result_layer = |
| 5987 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 5988 | test_point, render_surface_layer_list); |
| 5989 | ASSERT_TRUE(result_layer); |
| 5990 | EXPECT_EQ(456, result_layer->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5991 | } |
| 5992 | |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 5993 | TEST_F(LayerTreeHostCommonTest, |
| 5994 | HitCheckingTouchHandlerOverlappingRegions) { |
| 5995 | gfx::Transform identity_matrix; |
| 5996 | gfx::PointF anchor; |
| 5997 | |
| 5998 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5999 | TestSharedBitmapManager shared_bitmap_manager; |
| 6000 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6001 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 6002 | SetLayerPropertiesForTesting(root.get(), |
| 6003 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6004 | anchor, |
| 6005 | gfx::PointF(), |
| 6006 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6007 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6008 | false); |
| 6009 | { |
| 6010 | scoped_ptr<LayerImpl> touch_layer = |
| 6011 | LayerImpl::Create(host_impl.active_tree(), 123); |
| 6012 | // this layer is positioned, and hit testing should correctly know where the |
| 6013 | // layer is located. |
| 6014 | gfx::PointF position; |
| 6015 | gfx::Size bounds(50, 50); |
| 6016 | SetLayerPropertiesForTesting(touch_layer.get(), |
| 6017 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6018 | anchor, |
| 6019 | position, |
| 6020 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6021 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6022 | false); |
| 6023 | touch_layer->SetDrawsContent(true); |
| 6024 | touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); |
| 6025 | root->AddChild(touch_layer.Pass()); |
| 6026 | } |
| 6027 | |
| 6028 | { |
| 6029 | scoped_ptr<LayerImpl> notouch_layer = |
| 6030 | LayerImpl::Create(host_impl.active_tree(), 1234); |
| 6031 | // this layer is positioned, and hit testing should correctly know where the |
| 6032 | // layer is located. |
| 6033 | gfx::PointF position(0, 25); |
| 6034 | gfx::Size bounds(50, 50); |
| 6035 | SetLayerPropertiesForTesting(notouch_layer.get(), |
| 6036 | identity_matrix, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6037 | anchor, |
| 6038 | position, |
| 6039 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6040 | true, |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6041 | false); |
| 6042 | notouch_layer->SetDrawsContent(true); |
| 6043 | root->AddChild(notouch_layer.Pass()); |
| 6044 | } |
| 6045 | |
| 6046 | LayerImplList render_surface_layer_list; |
| 6047 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 6048 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6049 | inputs.can_adjust_raster_scales = true; |
| 6050 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6051 | |
| 6052 | // Sanity check the scenario we just created. |
| 6053 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 22538a2d | 2013-11-12 11:24:45 | [diff] [blame] | 6054 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 6055 | ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id()); |
| 6056 | ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6057 | |
| 6058 | gfx::Point test_point(35, 35); |
| 6059 | LayerImpl* result_layer = |
| 6060 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6061 | test_point, render_surface_layer_list); |
[email protected] | 5183605e | 2014-04-17 03:57:18 | [diff] [blame] | 6062 | |
| 6063 | // We should have passed through the no-touch layer and found the layer |
| 6064 | // behind it. |
| 6065 | EXPECT_TRUE(result_layer); |
| 6066 | |
| 6067 | host_impl.active_tree()->LayerById(1234)->SetContentsOpaque(true); |
| 6068 | result_layer = |
| 6069 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6070 | test_point, render_surface_layer_list); |
| 6071 | |
[email protected] | 489eb9989 | 2014-04-27 00:27:34 | [diff] [blame] | 6072 | // Even with an opaque layer in the middle, we should still find the layer |
| 6073 | // with |
| 6074 | // the touch handler behind it (since we can't assume that opaque layers are |
| 6075 | // opaque to hit testing). |
| 6076 | EXPECT_TRUE(result_layer); |
[email protected] | c974d5d | 2013-10-24 01:02:48 | [diff] [blame] | 6077 | |
| 6078 | test_point = gfx::Point(35, 15); |
| 6079 | result_layer = |
| 6080 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6081 | test_point, render_surface_layer_list); |
| 6082 | ASSERT_TRUE(result_layer); |
| 6083 | EXPECT_EQ(123, result_layer->id()); |
| 6084 | |
| 6085 | test_point = gfx::Point(35, 65); |
| 6086 | result_layer = |
| 6087 | LayerTreeHostCommon::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 6088 | test_point, render_surface_layer_list); |
| 6089 | EXPECT_FALSE(result_layer); |
| 6090 | } |
| 6091 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6092 | class NoScaleContentLayer : public ContentLayer { |
| 6093 | public: |
| 6094 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 6095 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 6096 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6097 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6098 | virtual void CalculateContentsScale(float ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 6099 | float device_scale_factor, |
| 6100 | float page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6101 | float maximum_animation_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6102 | bool animating_transform_to_screen, |
| 6103 | float* contents_scale_x, |
| 6104 | float* contents_scale_y, |
| 6105 | gfx::Size* content_bounds) OVERRIDE { |
| 6106 | // Skip over the ContentLayer to the base Layer class. |
| 6107 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 6108 | device_scale_factor, |
| 6109 | page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 6110 | maximum_animation_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6111 | animating_transform_to_screen, |
| 6112 | contents_scale_x, |
| 6113 | contents_scale_y, |
| 6114 | content_bounds); |
| 6115 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6116 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6117 | protected: |
| 6118 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 6119 | : ContentLayer(client) {} |
| 6120 | virtual ~NoScaleContentLayer() {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6121 | }; |
| 6122 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6123 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 6124 | ContentLayerClient* delegate) { |
| 6125 | scoped_refptr<NoScaleContentLayer> to_return = |
| 6126 | NoScaleContentLayer::Create(delegate); |
| 6127 | to_return->SetIsDrawable(true); |
| 6128 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6129 | } |
| 6130 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6131 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6132 | // Verify draw and screen space transforms of layers not in a surface. |
| 6133 | MockContentLayerClient delegate; |
| 6134 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6135 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6136 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6137 | SetLayerPropertiesForTesting(parent.get(), |
| 6138 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6139 | gfx::PointF(), |
| 6140 | gfx::PointF(), |
| 6141 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6142 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6143 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6144 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6145 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 6146 | SetLayerPropertiesForTesting(child.get(), |
| 6147 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6148 | gfx::PointF(), |
| 6149 | gfx::PointF(2.f, 2.f), |
| 6150 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6151 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6152 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6153 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6154 | scoped_refptr<ContentLayer> child_empty = |
| 6155 | CreateDrawableContentLayer(&delegate); |
| 6156 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6157 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6158 | gfx::PointF(), |
| 6159 | gfx::PointF(2.f, 2.f), |
| 6160 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6161 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6162 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6163 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6164 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6165 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6166 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6167 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6168 | gfx::PointF(), |
| 6169 | gfx::PointF(2.f, 2.f), |
| 6170 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6171 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6172 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6173 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6174 | parent->AddChild(child); |
| 6175 | parent->AddChild(child_empty); |
| 6176 | parent->AddChild(child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6177 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6178 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6179 | host->SetRootLayer(parent); |
| 6180 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6181 | float device_scale_factor = 2.5f; |
| 6182 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6183 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6184 | RenderSurfaceLayerList render_surface_layer_list; |
| 6185 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6186 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 6187 | inputs.device_scale_factor = device_scale_factor; |
| 6188 | inputs.page_scale_factor = page_scale_factor; |
| 6189 | inputs.can_adjust_raster_scales = true; |
| 6190 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6191 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6192 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6193 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 6194 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6195 | child_empty); |
| 6196 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6197 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6198 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6199 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6200 | // Verify parent transforms |
| 6201 | gfx::Transform expected_parent_transform; |
| 6202 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6203 | parent->screen_space_transform()); |
| 6204 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6205 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6206 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6207 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6208 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6209 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6210 | gfx::RectF parent_draw_rect = |
| 6211 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 6212 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 6213 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6214 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6215 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6216 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 6217 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 6218 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6219 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6220 | // Verify child and child_empty transforms. They should match. |
| 6221 | gfx::Transform expected_child_transform; |
| 6222 | expected_child_transform.Translate( |
| 6223 | device_scale_factor * child->position().x(), |
| 6224 | device_scale_factor * child->position().y()); |
| 6225 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6226 | child->draw_transform()); |
| 6227 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6228 | child->screen_space_transform()); |
| 6229 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6230 | child_empty->draw_transform()); |
| 6231 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6232 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6233 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6234 | // Verify results of transformed child and child_empty rects. They should |
| 6235 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6236 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6237 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6238 | gfx::RectF child_draw_rect = |
| 6239 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 6240 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 6241 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6242 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6243 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 6244 | child_empty->draw_transform(), child_content_bounds); |
| 6245 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 6246 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6247 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6248 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 6249 | expected_child_draw_rect.Scale(device_scale_factor); |
| 6250 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 6251 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 6252 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 6253 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6254 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6255 | // Verify child_no_scale transforms |
| 6256 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 6257 | // All transforms operate on content rects. The child's content rect |
| 6258 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 6259 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 6260 | device_scale_factor); |
| 6261 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6262 | child_no_scale->draw_transform()); |
| 6263 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6264 | child_no_scale->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6265 | } |
| 6266 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6267 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6268 | // Verify draw and screen space transforms of layers in a surface. |
| 6269 | MockContentLayerClient delegate; |
| 6270 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6272 | gfx::Transform perspective_matrix; |
| 6273 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6274 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6275 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 6276 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6277 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 6278 | scoped_refptr<Layer> root = Layer::Create(); |
| 6279 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6280 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6281 | SetLayerPropertiesForTesting(parent.get(), |
| 6282 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6283 | gfx::PointF(), |
| 6284 | gfx::PointF(), |
| 6285 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6286 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6287 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6288 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6289 | scoped_refptr<ContentLayer> perspective_surface = |
| 6290 | CreateDrawableContentLayer(&delegate); |
| 6291 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 6292 | perspective_matrix * scale_small_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6293 | gfx::PointF(), |
| 6294 | gfx::PointF(2.f, 2.f), |
| 6295 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6296 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6297 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6298 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6299 | scoped_refptr<ContentLayer> scale_surface = |
| 6300 | CreateDrawableContentLayer(&delegate); |
| 6301 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 6302 | scale_small_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6303 | gfx::PointF(), |
| 6304 | gfx::PointF(2.f, 2.f), |
| 6305 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6306 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6307 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6308 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6309 | perspective_surface->SetForceRenderSurface(true); |
| 6310 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6311 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6312 | parent->AddChild(perspective_surface); |
| 6313 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 6314 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6315 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6316 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6317 | host->SetRootLayer(root); |
| 6318 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6319 | float device_scale_factor = 2.5f; |
| 6320 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6321 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6322 | RenderSurfaceLayerList render_surface_layer_list; |
| 6323 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6324 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 6325 | inputs.device_scale_factor = device_scale_factor; |
| 6326 | inputs.page_scale_factor = page_scale_factor; |
| 6327 | inputs.page_scale_application_layer = root; |
| 6328 | inputs.can_adjust_raster_scales = true; |
| 6329 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6330 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6331 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6332 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6333 | perspective_surface); |
| 6334 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6335 | scale_surface); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6336 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6337 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6338 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6339 | gfx::Transform expected_parent_draw_transform; |
| 6340 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 6341 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6342 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6343 | // The scaled surface is rendered at its appropriate scale, and drawn 1:1 |
| 6344 | // into its target. |
| 6345 | gfx::Transform expected_scale_surface_draw_transform; |
| 6346 | expected_scale_surface_draw_transform.Translate( |
| 6347 | device_scale_factor * page_scale_factor * scale_surface->position().x(), |
| 6348 | device_scale_factor * page_scale_factor * scale_surface->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6349 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6350 | expected_scale_surface_draw_transform, |
| 6351 | scale_surface->render_surface()->draw_transform()); |
[email protected] | a52c6ff | 2013-05-04 05:33:15 | [diff] [blame] | 6352 | gfx::Transform expected_scale_surface_layer_draw_transform = |
| 6353 | scale_small_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6354 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform, |
| 6355 | scale_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6356 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6357 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 6358 | // with the screen, and then scaled during drawing. |
| 6359 | gfx::Transform expected_perspective_surface_draw_transform; |
| 6360 | expected_perspective_surface_draw_transform.Translate( |
| 6361 | device_scale_factor * page_scale_factor * |
| 6362 | perspective_surface->position().x(), |
| 6363 | device_scale_factor * page_scale_factor * |
| 6364 | perspective_surface->position().y()); |
| 6365 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 6366 | perspective_matrix); |
| 6367 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 6368 | scale_small_matrix); |
| 6369 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
| 6370 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6371 | expected_perspective_surface_draw_transform, |
| 6372 | perspective_surface->render_surface()->draw_transform()); |
| 6373 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 6374 | expected_perspective_surface_layer_draw_transform, |
| 6375 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 6376 | } |
| 6377 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6378 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6379 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 6380 | // Verify draw and screen space transforms of layers not in a surface. |
| 6381 | MockContentLayerClient delegate; |
| 6382 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6383 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6384 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6385 | SetLayerPropertiesForTesting(parent.get(), |
| 6386 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6387 | gfx::PointF(), |
| 6388 | gfx::PointF(), |
| 6389 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6390 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6391 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6392 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6393 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 6394 | SetLayerPropertiesForTesting(child.get(), |
| 6395 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6396 | gfx::PointF(), |
| 6397 | gfx::PointF(), |
| 6398 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6399 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6400 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6401 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6402 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6403 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6404 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6405 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6406 | gfx::PointF(), |
| 6407 | gfx::PointF(), |
| 6408 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6409 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6410 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6411 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6412 | parent->AddChild(child); |
| 6413 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6414 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6415 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6416 | host->SetRootLayer(parent); |
| 6417 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6418 | float device_scale_factor = 1.7f; |
| 6419 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6420 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6421 | RenderSurfaceLayerList render_surface_layer_list; |
| 6422 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6423 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 6424 | inputs.device_scale_factor = device_scale_factor; |
| 6425 | inputs.page_scale_factor = page_scale_factor; |
| 6426 | inputs.page_scale_application_layer = parent.get(); |
| 6427 | inputs.can_adjust_raster_scales = true; |
| 6428 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6429 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6430 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6431 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 6432 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6433 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6434 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6435 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6436 | // Verify parent transforms |
| 6437 | gfx::Transform expected_parent_transform; |
| 6438 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6439 | parent->screen_space_transform()); |
| 6440 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 6441 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6442 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6443 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6444 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6445 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6446 | gfx::RectF parent_draw_rect = |
| 6447 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 6448 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 6449 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6450 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6451 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6452 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 6453 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 6454 | expected_parent_draw_rect.set_height( |
| 6455 | ceil(expected_parent_draw_rect.height())); |
| 6456 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 6457 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6458 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6459 | // Verify child transforms |
| 6460 | gfx::Transform expected_child_transform; |
| 6461 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6462 | child->draw_transform()); |
| 6463 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 6464 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6465 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6466 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6467 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6468 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6469 | gfx::RectF child_draw_rect = |
| 6470 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 6471 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 6472 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6473 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 6474 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6475 | expected_child_draw_rect.Scale(device_scale_factor); |
| 6476 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 6477 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 6478 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 6479 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6480 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6481 | // Verify child_no_scale transforms |
| 6482 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 6483 | // All transforms operate on content rects. The child's content rect |
| 6484 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 6485 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 6486 | device_scale_factor); |
| 6487 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6488 | child_no_scale->draw_transform()); |
| 6489 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 6490 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 6491 | } |
| 6492 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6493 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6494 | MockContentLayerClient delegate; |
| 6495 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6496 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6497 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6498 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6499 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6500 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6501 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6502 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6503 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6504 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6505 | scoped_refptr<Layer> root = Layer::Create(); |
| 6506 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6507 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6508 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6509 | SetLayerPropertiesForTesting(parent.get(), |
| 6510 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6511 | gfx::PointF(), |
| 6512 | gfx::PointF(), |
| 6513 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6514 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6515 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6516 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6517 | scoped_refptr<ContentLayer> child_scale = |
| 6518 | CreateDrawableContentLayer(&delegate); |
| 6519 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6520 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6521 | gfx::PointF(), |
| 6522 | gfx::PointF(2.f, 2.f), |
| 6523 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6524 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6525 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6526 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6527 | scoped_refptr<ContentLayer> child_empty = |
| 6528 | CreateDrawableContentLayer(&delegate); |
| 6529 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6530 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6531 | gfx::PointF(), |
| 6532 | gfx::PointF(2.f, 2.f), |
| 6533 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6534 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6535 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 6536 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6537 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6538 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6539 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6540 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6541 | gfx::PointF(), |
| 6542 | gfx::PointF(12.f, 12.f), |
| 6543 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6544 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6545 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6546 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6547 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6548 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6549 | parent->AddChild(child_scale); |
| 6550 | parent->AddChild(child_empty); |
| 6551 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6552 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6553 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6554 | host->SetRootLayer(root); |
| 6555 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6556 | float device_scale_factor = 2.5f; |
| 6557 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6558 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6559 | { |
| 6560 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6561 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6562 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6563 | inputs.device_scale_factor = device_scale_factor; |
| 6564 | inputs.page_scale_factor = page_scale_factor; |
| 6565 | inputs.page_scale_application_layer = root.get(); |
| 6566 | inputs.can_adjust_raster_scales = true; |
| 6567 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6568 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6569 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6570 | initial_parent_scale, parent); |
| 6571 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6572 | initial_parent_scale * initial_child_scale, |
| 6573 | child_scale); |
| 6574 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6575 | initial_parent_scale * initial_child_scale, |
| 6576 | child_empty); |
| 6577 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6578 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6579 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 6580 | // child that can scale its contents should also not need to scale during |
| 6581 | // draw. This shouldn't change if the child has empty bounds. The other |
| 6582 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6583 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 6584 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 6585 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 6586 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 6587 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 6588 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6589 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 6590 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6591 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6592 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6593 | initial_parent_scale * initial_child_scale, |
| 6594 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6595 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6596 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6597 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 6598 | // updated using the initial transform as the raster scale. |
| 6599 | device_scale_factor = 2.25f; |
| 6600 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6601 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6602 | { |
| 6603 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6604 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6605 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6606 | inputs.device_scale_factor = device_scale_factor; |
| 6607 | inputs.page_scale_factor = page_scale_factor; |
| 6608 | inputs.page_scale_application_layer = root.get(); |
| 6609 | inputs.can_adjust_raster_scales = true; |
| 6610 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6611 | |
| 6612 | EXPECT_CONTENTS_SCALE_EQ( |
| 6613 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6614 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6615 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6616 | child_scale); |
| 6617 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6618 | initial_parent_scale * initial_child_scale, |
| 6619 | child_empty); |
| 6620 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6621 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6622 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6623 | // 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] | 6624 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6625 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 6626 | second_child_scale / initial_child_scale); |
| 6627 | child_scale->SetTransform(child_scale_matrix); |
| 6628 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6629 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6630 | { |
| 6631 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6632 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6633 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6634 | inputs.device_scale_factor = device_scale_factor; |
| 6635 | inputs.page_scale_factor = page_scale_factor; |
| 6636 | inputs.page_scale_application_layer = root.get(); |
| 6637 | inputs.can_adjust_raster_scales = true; |
| 6638 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6639 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6640 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6641 | initial_parent_scale, |
| 6642 | parent); |
| 6643 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6644 | child_scale); |
| 6645 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6646 | child_empty); |
| 6647 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6648 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6649 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6650 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 6651 | // updated, but still using 1.0 as the raster scale. |
| 6652 | device_scale_factor = 2.75f; |
| 6653 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6654 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6655 | { |
| 6656 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6657 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6658 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6659 | inputs.device_scale_factor = device_scale_factor; |
| 6660 | inputs.page_scale_factor = page_scale_factor; |
| 6661 | inputs.page_scale_application_layer = root.get(); |
| 6662 | inputs.can_adjust_raster_scales = true; |
| 6663 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 6664 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6665 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6666 | initial_parent_scale, |
| 6667 | parent); |
| 6668 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6669 | child_scale); |
| 6670 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6671 | child_empty); |
| 6672 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6673 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6674 | } |
| 6675 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6676 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6677 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6678 | MockContentLayerClient delegate; |
| 6679 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6680 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6681 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6682 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6683 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6684 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6685 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6686 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6687 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6688 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6689 | scoped_refptr<Layer> root = Layer::Create(); |
| 6690 | root->SetBounds(gfx::Size(100, 100)); |
| 6691 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6692 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6693 | SetLayerPropertiesForTesting(parent.get(), |
| 6694 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6695 | gfx::PointF(), |
| 6696 | gfx::PointF(), |
| 6697 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6698 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6699 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6700 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6701 | scoped_refptr<ContentLayer> child_scale = |
| 6702 | CreateDrawableContentLayer(&delegate); |
| 6703 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6704 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6705 | gfx::PointF(), |
| 6706 | gfx::PointF(2.f, 2.f), |
| 6707 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6708 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6709 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6710 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6711 | scoped_refptr<ContentLayer> child_empty = |
| 6712 | CreateDrawableContentLayer(&delegate); |
| 6713 | SetLayerPropertiesForTesting(child_empty.get(), |
| 6714 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6715 | gfx::PointF(), |
| 6716 | gfx::PointF(2.f, 2.f), |
| 6717 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6718 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6719 | true); |
| 6720 | |
| 6721 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 6722 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6723 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 6724 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6725 | gfx::PointF(), |
| 6726 | gfx::PointF(12.f, 12.f), |
| 6727 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6728 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6729 | true); |
| 6730 | |
| 6731 | root->AddChild(parent); |
| 6732 | |
| 6733 | parent->AddChild(child_scale); |
| 6734 | parent->AddChild(child_empty); |
| 6735 | parent->AddChild(child_no_scale); |
| 6736 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6737 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6738 | host->SetRootLayer(root); |
| 6739 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6740 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6741 | |
| 6742 | float device_scale_factor = 2.5f; |
| 6743 | float page_scale_factor = 1.f; |
| 6744 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6745 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6746 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6747 | inputs.device_scale_factor = device_scale_factor; |
| 6748 | inputs.page_scale_factor = page_scale_factor; |
| 6749 | inputs.page_scale_application_layer = root.get(), |
| 6750 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6751 | |
| 6752 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 6753 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6754 | child_scale); |
| 6755 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 6756 | child_empty); |
| 6757 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 6758 | |
| 6759 | // Since the transform scale does not affect contents scale, it should affect |
| 6760 | // the draw transform instead. |
| 6761 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6762 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6763 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6764 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6765 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6766 | child_scale->draw_transform().matrix().get(0, 0)); |
[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(1, 1)); |
[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_empty->draw_transform().matrix().get(0, 0)); |
[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(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6773 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6774 | initial_parent_scale * initial_child_scale, |
| 6775 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6776 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6777 | initial_parent_scale * initial_child_scale, |
| 6778 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6779 | } |
| 6780 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6781 | TEST_F(LayerTreeHostCommonTest, SmallContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6782 | MockContentLayerClient delegate; |
| 6783 | gfx::Transform identity_matrix; |
| 6784 | |
| 6785 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6786 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6787 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 6788 | |
| 6789 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6790 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6791 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 6792 | |
| 6793 | scoped_refptr<Layer> root = Layer::Create(); |
| 6794 | root->SetBounds(gfx::Size(100, 100)); |
| 6795 | |
| 6796 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6797 | SetLayerPropertiesForTesting(parent.get(), |
| 6798 | parent_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6799 | gfx::PointF(), |
| 6800 | gfx::PointF(), |
| 6801 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6802 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6803 | true); |
| 6804 | |
| 6805 | scoped_refptr<ContentLayer> child_scale = |
| 6806 | CreateDrawableContentLayer(&delegate); |
| 6807 | SetLayerPropertiesForTesting(child_scale.get(), |
| 6808 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6809 | gfx::PointF(), |
| 6810 | gfx::PointF(2.f, 2.f), |
| 6811 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6812 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6813 | true); |
| 6814 | |
| 6815 | root->AddChild(parent); |
| 6816 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6817 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6818 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6819 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6820 | host->SetRootLayer(root); |
| 6821 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6822 | float device_scale_factor = 2.5f; |
| 6823 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6824 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6825 | { |
| 6826 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6827 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6828 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6829 | inputs.device_scale_factor = device_scale_factor; |
| 6830 | inputs.page_scale_factor = page_scale_factor; |
| 6831 | inputs.page_scale_application_layer = root.get(); |
| 6832 | inputs.can_adjust_raster_scales = true; |
| 6833 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6834 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6835 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6836 | initial_parent_scale, |
| 6837 | parent); |
| 6838 | // The child's scale is < 1, so we should not save and use that scale |
| 6839 | // factor. |
| 6840 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1, |
| 6841 | child_scale); |
| 6842 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6843 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6844 | // When chilld's total scale becomes >= 1, we should save and use that scale |
| 6845 | // factor. |
| 6846 | child_scale_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6847 | SkMScalar final_child_scale = 0.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6848 | child_scale_matrix.Scale(final_child_scale, final_child_scale); |
| 6849 | child_scale->SetTransform(child_scale_matrix); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6850 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6851 | { |
| 6852 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6853 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6854 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6855 | inputs.device_scale_factor = device_scale_factor; |
| 6856 | inputs.page_scale_factor = page_scale_factor; |
| 6857 | inputs.page_scale_application_layer = root.get(); |
| 6858 | inputs.can_adjust_raster_scales = true; |
| 6859 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6860 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6861 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6862 | initial_parent_scale, |
| 6863 | parent); |
| 6864 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 6865 | initial_parent_scale * final_child_scale, |
| 6866 | child_scale); |
| 6867 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 6868 | } |
| 6869 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6870 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6871 | MockContentLayerClient delegate; |
| 6872 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6873 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6874 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6875 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6876 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6877 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6878 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6879 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6880 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6881 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6882 | scoped_refptr<Layer> root = Layer::Create(); |
| 6883 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6884 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6885 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 6886 | SetLayerPropertiesForTesting(parent.get(), |
| 6887 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6888 | gfx::PointF(), |
| 6889 | gfx::PointF(), |
| 6890 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6891 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6892 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6893 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6894 | scoped_refptr<ContentLayer> surface_scale = |
| 6895 | CreateDrawableContentLayer(&delegate); |
| 6896 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 6897 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6898 | gfx::PointF(), |
| 6899 | gfx::PointF(2.f, 2.f), |
| 6900 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6901 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6902 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6903 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6904 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 6905 | CreateDrawableContentLayer(&delegate); |
| 6906 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 6907 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6908 | gfx::PointF(), |
| 6909 | gfx::PointF(), |
| 6910 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6911 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6912 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6913 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6914 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 6915 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6916 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 6917 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6918 | gfx::PointF(), |
| 6919 | gfx::PointF(), |
| 6920 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6921 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6922 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6923 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6924 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 6925 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6926 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 6927 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6928 | gfx::PointF(), |
| 6929 | gfx::PointF(12.f, 12.f), |
| 6930 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6931 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6932 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6933 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6934 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 6935 | CreateDrawableContentLayer(&delegate); |
| 6936 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 6937 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6938 | gfx::PointF(), |
| 6939 | gfx::PointF(), |
| 6940 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6941 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6942 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6943 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6944 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 6945 | CreateNoScaleDrawableContentLayer(&delegate); |
| 6946 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 6947 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6948 | gfx::PointF(), |
| 6949 | gfx::PointF(), |
| 6950 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6951 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6952 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6953 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 6954 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6955 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6956 | parent->AddChild(surface_scale); |
| 6957 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6958 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6959 | surface_scale->SetForceRenderSurface(true); |
| 6960 | surface_scale->AddChild(surface_scale_child_scale); |
| 6961 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6962 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6963 | surface_no_scale->SetForceRenderSurface(true); |
| 6964 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 6965 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6966 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6967 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6968 | host->SetRootLayer(root); |
| 6969 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 6970 | SkMScalar device_scale_factor = 5; |
| 6971 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6972 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6973 | RenderSurfaceLayerList render_surface_layer_list; |
| 6974 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6975 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6976 | inputs.device_scale_factor = device_scale_factor; |
| 6977 | inputs.page_scale_factor = page_scale_factor; |
| 6978 | inputs.page_scale_application_layer = root.get(); |
| 6979 | inputs.can_adjust_raster_scales = true; |
| 6980 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6981 | |
| 6982 | EXPECT_CONTENTS_SCALE_EQ( |
| 6983 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 6984 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6985 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6986 | surface_scale); |
| 6987 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 6988 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6989 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 6990 | initial_child_scale * initial_child_scale, |
| 6991 | surface_scale_child_scale); |
| 6992 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 6993 | EXPECT_CONTENTS_SCALE_EQ( |
| 6994 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 6995 | initial_child_scale * initial_child_scale, |
| 6996 | surface_no_scale_child_scale); |
| 6997 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 6998 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6999 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7000 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 7001 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7002 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7003 | // RenderSurfaces should always be 1:1 with their target. |
| 7004 | EXPECT_FLOAT_EQ( |
| 7005 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7006 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7007 | EXPECT_FLOAT_EQ( |
| 7008 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7009 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7010 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7011 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 7012 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7013 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 7014 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7015 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7016 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 7017 | // to scale during draw. |
| 7018 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7019 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 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(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7022 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7023 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 7024 | // to be scaled during draw. |
| 7025 | EXPECT_FLOAT_EQ( |
| 7026 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7027 | initial_child_scale * initial_child_scale, |
| 7028 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7029 | EXPECT_FLOAT_EQ( |
| 7030 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7031 | initial_child_scale * initial_child_scale, |
| 7032 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7033 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7034 | // RenderSurfaces should always be 1:1 with their target. |
| 7035 | EXPECT_FLOAT_EQ( |
| 7036 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7037 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7038 | EXPECT_FLOAT_EQ( |
| 7039 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7040 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7041 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7042 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 7043 | // scaled during draw. |
| 7044 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7045 | initial_parent_scale * initial_child_scale, |
| 7046 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7047 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7048 | initial_parent_scale * initial_child_scale, |
| 7049 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7050 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7051 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 7052 | // to scale during draw. |
| 7053 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7054 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 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(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7057 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7058 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 7059 | // to be scaled during draw. |
| 7060 | EXPECT_FLOAT_EQ( |
| 7061 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7062 | initial_child_scale * initial_child_scale, |
| 7063 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7064 | EXPECT_FLOAT_EQ( |
| 7065 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7066 | initial_child_scale * initial_child_scale, |
| 7067 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7068 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7069 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7070 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7071 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
| 7072 | MockContentLayerClient delegate; |
| 7073 | gfx::Transform identity_matrix; |
| 7074 | |
| 7075 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7076 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7077 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 7078 | |
| 7079 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7080 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7081 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 7082 | |
| 7083 | scoped_refptr<Layer> root = Layer::Create(); |
| 7084 | root->SetBounds(gfx::Size(100, 100)); |
| 7085 | |
| 7086 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7087 | SetLayerPropertiesForTesting(parent.get(), |
| 7088 | parent_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7089 | gfx::PointF(), |
| 7090 | gfx::PointF(), |
| 7091 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7092 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7093 | true); |
| 7094 | |
| 7095 | scoped_refptr<ContentLayer> surface_scale = |
| 7096 | CreateDrawableContentLayer(&delegate); |
| 7097 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 7098 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7099 | gfx::PointF(), |
| 7100 | gfx::PointF(2.f, 2.f), |
| 7101 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7102 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7103 | true); |
| 7104 | |
| 7105 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 7106 | CreateDrawableContentLayer(&delegate); |
| 7107 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 7108 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7109 | gfx::PointF(), |
| 7110 | gfx::PointF(), |
| 7111 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7112 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7113 | true); |
| 7114 | |
| 7115 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 7116 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7117 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 7118 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7119 | gfx::PointF(), |
| 7120 | gfx::PointF(), |
| 7121 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7122 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7123 | true); |
| 7124 | |
| 7125 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 7126 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7127 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 7128 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7129 | gfx::PointF(), |
| 7130 | gfx::PointF(12.f, 12.f), |
| 7131 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7132 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7133 | true); |
| 7134 | |
| 7135 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 7136 | CreateDrawableContentLayer(&delegate); |
| 7137 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 7138 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7139 | gfx::PointF(), |
| 7140 | gfx::PointF(), |
| 7141 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7142 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7143 | true); |
| 7144 | |
| 7145 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 7146 | CreateNoScaleDrawableContentLayer(&delegate); |
| 7147 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 7148 | child_scale_matrix, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7149 | gfx::PointF(), |
| 7150 | gfx::PointF(), |
| 7151 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7152 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7153 | true); |
| 7154 | |
| 7155 | root->AddChild(parent); |
| 7156 | |
| 7157 | parent->AddChild(surface_scale); |
| 7158 | parent->AddChild(surface_no_scale); |
| 7159 | |
| 7160 | surface_scale->SetForceRenderSurface(true); |
| 7161 | surface_scale->AddChild(surface_scale_child_scale); |
| 7162 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 7163 | |
| 7164 | surface_no_scale->SetForceRenderSurface(true); |
| 7165 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 7166 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 7167 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7168 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7169 | host->SetRootLayer(root); |
| 7170 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7171 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7172 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7173 | SkMScalar device_scale_factor = 5.0; |
| 7174 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7175 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7176 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7177 | inputs.device_scale_factor = device_scale_factor; |
| 7178 | inputs.page_scale_factor = page_scale_factor; |
| 7179 | inputs.page_scale_application_layer = root.get(); |
| 7180 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7181 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7182 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7183 | parent); |
| 7184 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7185 | surface_scale); |
| 7186 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 7187 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7188 | surface_scale_child_scale); |
| 7189 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 7190 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 7191 | surface_no_scale_child_scale); |
| 7192 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 7193 | |
| 7194 | // The parent is scaled up during draw, since its contents are not scaled by |
| 7195 | // the transform hierarchy. |
| 7196 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7197 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7198 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7199 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7200 | |
| 7201 | // The child surface is scaled up during draw since its subtree is not scaled |
| 7202 | // by the transform hierarchy. |
| 7203 | EXPECT_FLOAT_EQ( |
| 7204 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7205 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7206 | EXPECT_FLOAT_EQ( |
| 7207 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7208 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7209 | |
| 7210 | // The surface_scale's RenderSurface is scaled during draw, so the layer does |
| 7211 | // not need to be scaled when drawing into its surface. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7212 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 7213 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7214 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7215 | // The surface_scale_child_scale is scaled when drawing into its surface, |
| 7216 | // since its content bounds are not scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7217 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7218 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7219 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7220 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7221 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7222 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7223 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7224 | // The surface_scale_child_no_scale has a fixed contents scale of 1, so it |
| 7225 | // needs to be scaled by the device and page scale factors, along with the |
| 7226 | // transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7227 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7228 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7229 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7230 | EXPECT_FLOAT_EQ( |
| 7231 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7232 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7233 | |
| 7234 | // The child surface is scaled up during draw since its subtree is not scaled |
| 7235 | // by the transform hierarchy. |
| 7236 | EXPECT_FLOAT_EQ( |
| 7237 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7238 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7239 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7240 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7241 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7242 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7243 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 7244 | // be scaled by the device and page scale factors. Its surface is already |
| 7245 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 7246 | // drawing. |
| 7247 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7248 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 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(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7251 | |
| 7252 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 7253 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 7254 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7255 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7256 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7257 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7258 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7259 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7260 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7261 | |
| 7262 | // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it |
| 7263 | // needs to be scaled by the device and page scale factors. It also needs to |
| 7264 | // be scaled by any transform heirarchy below its target surface. |
| 7265 | EXPECT_FLOAT_EQ( |
| 7266 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7267 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7268 | EXPECT_FLOAT_EQ( |
| 7269 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7270 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 7271 | } |
| 7272 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7273 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7274 | MockContentLayerClient delegate; |
| 7275 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7276 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7277 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7278 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7279 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7280 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7281 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7282 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7283 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7284 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7285 | scoped_refptr<Layer> root = Layer::Create(); |
| 7286 | root->SetBounds(gfx::Size(100, 100)); |
| 7287 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7288 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7289 | SetLayerPropertiesForTesting(parent.get(), |
| 7290 | parent_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7291 | gfx::PointF(), |
| 7292 | gfx::PointF(), |
| 7293 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7294 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7295 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7296 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7297 | scoped_refptr<ContentLayer> child_scale = |
| 7298 | CreateDrawableContentLayer(&delegate); |
| 7299 | SetLayerPropertiesForTesting(child_scale.get(), |
| 7300 | child_scale_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7301 | gfx::PointF(), |
| 7302 | gfx::PointF(2.f, 2.f), |
| 7303 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7304 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7305 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7306 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 7307 | root->AddChild(parent); |
| 7308 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7309 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7310 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7311 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7312 | host->SetRootLayer(root); |
| 7313 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7314 | // Now put an animating transform on child. |
| 7315 | int animation_id = AddAnimatedTransformToController( |
| 7316 | child_scale->layer_animation_controller(), 10.0, 30, 0); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7317 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7318 | { |
| 7319 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7320 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7321 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7322 | inputs.can_adjust_raster_scales = true; |
| 7323 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7324 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7325 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 7326 | // The layers with animating transforms should not compute a contents scale |
| 7327 | // other than 1 until they finish animating. |
| 7328 | EXPECT_CONTENTS_SCALE_EQ(1, child_scale); |
| 7329 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7330 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7331 | // Remove the animation, now it can save a raster scale. |
| 7332 | child_scale->layer_animation_controller()->RemoveAnimation(animation_id); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7333 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7334 | { |
| 7335 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7336 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7337 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7338 | inputs.can_adjust_raster_scales = true; |
| 7339 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7340 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7341 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 7342 | // The layers with animating transforms should not compute a contents scale |
| 7343 | // other than 1 until they finish animating. |
| 7344 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale, |
| 7345 | child_scale); |
| 7346 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7347 | } |
| 7348 | |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 7349 | TEST_F(LayerTreeHostCommonTest, |
| 7350 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 7351 | MockContentLayerClient delegate; |
| 7352 | scoped_refptr<Layer> root = Layer::Create(); |
| 7353 | scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 7354 | root->AddChild(child); |
| 7355 | |
| 7356 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7357 | host->SetRootLayer(root); |
| 7358 | |
| 7359 | gfx::Transform identity_matrix; |
| 7360 | SetLayerPropertiesForTesting(root.get(), |
| 7361 | identity_matrix, |
| 7362 | gfx::PointF(), |
| 7363 | gfx::PointF(), |
| 7364 | gfx::Size(100, 100), |
| 7365 | true, |
| 7366 | false); |
| 7367 | SetLayerPropertiesForTesting(child.get(), |
| 7368 | identity_matrix, |
| 7369 | gfx::PointF(), |
| 7370 | gfx::PointF(), |
| 7371 | gfx::Size(100, 100), |
| 7372 | true, |
| 7373 | false); |
| 7374 | |
| 7375 | root->reset_needs_push_properties_for_testing(); |
| 7376 | child->reset_needs_push_properties_for_testing(); |
| 7377 | |
| 7378 | // This will change both layers' content bounds. |
| 7379 | ExecuteCalculateDrawProperties(root.get()); |
| 7380 | EXPECT_TRUE(root->needs_push_properties()); |
| 7381 | EXPECT_TRUE(child->needs_push_properties()); |
| 7382 | |
| 7383 | root->reset_needs_push_properties_for_testing(); |
| 7384 | child->reset_needs_push_properties_for_testing(); |
| 7385 | |
| 7386 | // This will change only the child layer's contents scale and content bounds, |
| 7387 | // since the root layer is not a ContentsScalingLayer. |
| 7388 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 7389 | EXPECT_FALSE(root->needs_push_properties()); |
| 7390 | EXPECT_TRUE(child->needs_push_properties()); |
| 7391 | |
| 7392 | root->reset_needs_push_properties_for_testing(); |
| 7393 | child->reset_needs_push_properties_for_testing(); |
| 7394 | |
| 7395 | // This will not change either layer's contents scale or content bounds. |
| 7396 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 7397 | EXPECT_FALSE(root->needs_push_properties()); |
| 7398 | EXPECT_FALSE(child->needs_push_properties()); |
| 7399 | } |
| 7400 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7401 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7402 | MockContentLayerClient delegate; |
| 7403 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 7404 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7405 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7406 | SetLayerPropertiesForTesting(parent.get(), |
| 7407 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7408 | gfx::PointF(), |
| 7409 | gfx::PointF(), |
| 7410 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7411 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7412 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7413 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7414 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 7415 | SetLayerPropertiesForTesting(child.get(), |
| 7416 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7417 | gfx::PointF(), |
| 7418 | gfx::PointF(2.f, 2.f), |
| 7419 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7420 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7421 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7422 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7423 | gfx::Transform replica_transform; |
| 7424 | replica_transform.Scale(1.0, -1.0); |
| 7425 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 7426 | SetLayerPropertiesForTesting(replica.get(), |
| 7427 | replica_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7428 | gfx::PointF(), |
| 7429 | gfx::PointF(2.f, 2.f), |
| 7430 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7431 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7432 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7433 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7434 | // This layer should end up in the same surface as child, with the same draw |
| 7435 | // and screen space transforms. |
| 7436 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 7437 | CreateDrawableContentLayer(&delegate); |
| 7438 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 7439 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7440 | gfx::PointF(), |
| 7441 | gfx::PointF(), |
| 7442 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7443 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7444 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7445 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7446 | parent->AddChild(child); |
| 7447 | child->AddChild(duplicate_child_non_owner); |
| 7448 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7449 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7450 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7451 | host->SetRootLayer(parent); |
| 7452 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7453 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7454 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7455 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7456 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7457 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 7458 | inputs.device_scale_factor = device_scale_factor; |
| 7459 | inputs.can_adjust_raster_scales = true; |
| 7460 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7461 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7462 | // We should have two render surfaces. The root's render surface and child's |
| 7463 | // render surface (it needs one because it has a replica layer). |
| 7464 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7465 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7466 | gfx::Transform expected_parent_transform; |
| 7467 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 7468 | parent->screen_space_transform()); |
| 7469 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 7470 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7471 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7472 | gfx::Transform expected_draw_transform; |
| 7473 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 7474 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7475 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7476 | gfx::Transform expected_screen_space_transform; |
| 7477 | expected_screen_space_transform.Translate( |
| 7478 | device_scale_factor * child->position().x(), |
| 7479 | device_scale_factor * child->position().y()); |
| 7480 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 7481 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7482 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7483 | gfx::Transform expected_duplicate_child_draw_transform = |
| 7484 | child->draw_transform(); |
| 7485 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 7486 | duplicate_child_non_owner->draw_transform()); |
| 7487 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7488 | child->screen_space_transform(), |
| 7489 | duplicate_child_non_owner->screen_space_transform()); |
| 7490 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 7491 | duplicate_child_non_owner->drawable_content_rect()); |
| 7492 | EXPECT_EQ(child->content_bounds(), |
| 7493 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7494 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7495 | gfx::Transform expected_render_surface_draw_transform; |
| 7496 | expected_render_surface_draw_transform.Translate( |
| 7497 | device_scale_factor * child->position().x(), |
| 7498 | device_scale_factor * child->position().y()); |
| 7499 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 7500 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7501 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7502 | gfx::Transform expected_surface_draw_transform; |
| 7503 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 7504 | device_scale_factor * 2.f); |
| 7505 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 7506 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7507 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7508 | gfx::Transform expected_surface_screen_space_transform; |
| 7509 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 7510 | device_scale_factor * 2.f); |
| 7511 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7512 | expected_surface_screen_space_transform, |
| 7513 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7514 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7515 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7516 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 7517 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 7518 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7519 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7520 | expected_replica_draw_transform, |
| 7521 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7522 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7523 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7524 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 7525 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 7526 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7527 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7528 | expected_replica_screen_space_transform, |
| 7529 | child->render_surface()->replica_screen_space_transform()); |
| 7530 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7531 | expected_replica_screen_space_transform, |
| 7532 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7533 | } |
| 7534 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7535 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7536 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 7537 | MockContentLayerClient delegate; |
| 7538 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7539 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7540 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 7541 | SetLayerPropertiesForTesting(parent.get(), |
| 7542 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7543 | gfx::PointF(), |
| 7544 | gfx::PointF(), |
| 7545 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7546 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7547 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7548 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7549 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 7550 | SetLayerPropertiesForTesting(child.get(), |
| 7551 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7552 | gfx::PointF(), |
| 7553 | gfx::PointF(), |
| 7554 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7555 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7556 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7557 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7558 | gfx::Transform replica_transform; |
| 7559 | replica_transform.Scale(1.0, -1.0); |
| 7560 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 7561 | SetLayerPropertiesForTesting(replica.get(), |
| 7562 | replica_transform, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7563 | gfx::PointF(), |
| 7564 | gfx::PointF(), |
| 7565 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7566 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7567 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7568 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7569 | // This layer should end up in the same surface as child, with the same draw |
| 7570 | // and screen space transforms. |
| 7571 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 7572 | CreateDrawableContentLayer(&delegate); |
| 7573 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 7574 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7575 | gfx::PointF(), |
| 7576 | gfx::PointF(), |
| 7577 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7578 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7579 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7580 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7581 | parent->AddChild(child); |
| 7582 | child->AddChild(duplicate_child_non_owner); |
| 7583 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7584 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7585 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7586 | host->SetRootLayer(parent); |
| 7587 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 7588 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7589 | |
| 7590 | RenderSurfaceLayerList render_surface_layer_list; |
| 7591 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7592 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 7593 | inputs.device_scale_factor = device_scale_factor; |
| 7594 | inputs.can_adjust_raster_scales = true; |
| 7595 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7596 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7597 | // We should have two render surfaces. The root's render surface and child's |
| 7598 | // render surface (it needs one because it has a replica layer). |
| 7599 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7600 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7601 | gfx::Transform identity_transform; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7602 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7603 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7604 | parent->screen_space_transform()); |
| 7605 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform()); |
| 7606 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform()); |
| 7607 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7608 | child->screen_space_transform()); |
| 7609 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7610 | duplicate_child_non_owner->draw_transform()); |
| 7611 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7612 | identity_transform, duplicate_child_non_owner->screen_space_transform()); |
| 7613 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 7614 | duplicate_child_non_owner->drawable_content_rect()); |
| 7615 | EXPECT_EQ(child->content_bounds(), |
| 7616 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7617 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7618 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7619 | child->render_surface()->draw_transform()); |
| 7620 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 7621 | child->render_surface()->draw_transform()); |
| 7622 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7623 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7624 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7625 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7626 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7627 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7628 | expected_replica_draw_transform, |
| 7629 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 7630 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7631 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 7632 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7633 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7634 | expected_replica_screen_space_transform, |
| 7635 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7636 | } |
| 7637 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7638 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7639 | scoped_refptr<Layer> root = Layer::Create(); |
| 7640 | scoped_refptr<Layer> child = Layer::Create(); |
| 7641 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 7642 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 7643 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7644 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7645 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 7646 | child->AddChild(grand_child.get()); |
| 7647 | child->SetMaskLayer(mask_layer.get()); |
| 7648 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7649 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7650 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7651 | host->SetRootLayer(root); |
| 7652 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7653 | int nonexistent_id = -1; |
| 7654 | EXPECT_EQ(root, |
| 7655 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
| 7656 | EXPECT_EQ(child, |
| 7657 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 7658 | EXPECT_EQ( |
| 7659 | grand_child, |
| 7660 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 7661 | EXPECT_EQ( |
| 7662 | mask_layer, |
| 7663 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 7664 | EXPECT_EQ( |
| 7665 | replica_layer, |
| 7666 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 7667 | EXPECT_EQ( |
| 7668 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 7669 | } |
| 7670 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7671 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7672 | scoped_refptr<Layer> root = Layer::Create(); |
| 7673 | scoped_refptr<Layer> child = Layer::Create(); |
| 7674 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 7675 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7676 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7677 | const gfx::Transform identity_matrix; |
| 7678 | SetLayerPropertiesForTesting(root.get(), |
| 7679 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7680 | gfx::PointF(), |
| 7681 | gfx::PointF(), |
| 7682 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7683 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7684 | false); |
| 7685 | SetLayerPropertiesForTesting(child.get(), |
| 7686 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7687 | gfx::PointF(), |
| 7688 | gfx::PointF(), |
| 7689 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7690 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7691 | false); |
| 7692 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7693 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7694 | gfx::PointF(), |
| 7695 | gfx::PointF(), |
| 7696 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7697 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7698 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7699 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7700 | root->AddChild(child); |
| 7701 | child->AddChild(grand_child); |
| 7702 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7703 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7704 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7705 | host->SetRootLayer(root); |
| 7706 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7707 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7708 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7709 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 7710 | } |
| 7711 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7712 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7713 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7714 | TestSharedBitmapManager shared_bitmap_manager; |
| 7715 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7716 | host_impl.CreatePendingTree(); |
| 7717 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 7718 | |
| 7719 | const gfx::Transform identity_matrix; |
| 7720 | SetLayerPropertiesForTesting(root.get(), |
| 7721 | identity_matrix, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7722 | gfx::PointF(), |
| 7723 | gfx::PointF(), |
| 7724 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7725 | true, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7726 | false); |
| 7727 | root->SetDrawsContent(true); |
| 7728 | |
| 7729 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 7730 | SetLayerPropertiesForTesting(child.get(), |
| 7731 | identity_matrix, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7732 | gfx::PointF(), |
| 7733 | gfx::PointF(), |
| 7734 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7735 | true, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7736 | false); |
| 7737 | child->SetDrawsContent(true); |
| 7738 | child->SetOpacity(0.0f); |
| 7739 | |
| 7740 | // Add opacity animation. |
| 7741 | AddOpacityTransitionToController( |
| 7742 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 7743 | |
| 7744 | root->AddChild(child.Pass()); |
| 7745 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7746 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7747 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7748 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7749 | inputs.can_adjust_raster_scales = true; |
| 7750 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 7751 | |
| 7752 | // We should have one render surface and two layers. The child |
| 7753 | // layer should be included even though it is transparent. |
| 7754 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 7755 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 7756 | } |
| 7757 | |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7758 | typedef std::tr1::tuple<bool, bool> LCDTextTestParam; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7759 | class LCDTextTest |
| 7760 | : public LayerTreeHostCommonTestBase, |
| 7761 | public testing::TestWithParam<LCDTextTestParam> { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7762 | protected: |
| 7763 | virtual void SetUp() { |
| 7764 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7765 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7766 | root_ = Layer::Create(); |
| 7767 | child_ = Layer::Create(); |
| 7768 | grand_child_ = Layer::Create(); |
| 7769 | child_->AddChild(grand_child_.get()); |
| 7770 | root_->AddChild(child_.get()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7771 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7772 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7773 | SetLayerPropertiesForTesting(root_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7774 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7775 | gfx::PointF(), |
| 7776 | gfx::PointF(), |
| 7777 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7778 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7779 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7780 | SetLayerPropertiesForTesting(child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7781 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7782 | gfx::PointF(), |
| 7783 | gfx::PointF(), |
| 7784 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7785 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7786 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7787 | SetLayerPropertiesForTesting(grand_child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7788 | identity_matrix, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7789 | gfx::PointF(), |
| 7790 | gfx::PointF(), |
| 7791 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7792 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7793 | false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7794 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7795 | child_->SetForceRenderSurface(std::tr1::get<1>(GetParam())); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7796 | |
| 7797 | host_ = FakeLayerTreeHost::Create(); |
| 7798 | host_->SetRootLayer(root_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7799 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7800 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7801 | bool can_use_lcd_text_; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7802 | scoped_ptr<FakeLayerTreeHost> host_; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7803 | scoped_refptr<Layer> root_; |
| 7804 | scoped_refptr<Layer> child_; |
| 7805 | scoped_refptr<Layer> grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7806 | }; |
| 7807 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7808 | TEST_P(LCDTextTest, CanUseLCDText) { |
| 7809 | // Case 1: Identity transform. |
| 7810 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7811 | ExecuteCalculateDrawProperties( |
| 7812 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7813 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7814 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7815 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7816 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7817 | // Case 2: Integral translation. |
| 7818 | gfx::Transform integral_translation; |
| 7819 | integral_translation.Translate(1.0, 2.0); |
| 7820 | child_->SetTransform(integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7821 | ExecuteCalculateDrawProperties( |
| 7822 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7823 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7824 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7825 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7826 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7827 | // Case 3: Non-integral translation. |
| 7828 | gfx::Transform non_integral_translation; |
| 7829 | non_integral_translation.Translate(1.5, 2.5); |
| 7830 | child_->SetTransform(non_integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7831 | ExecuteCalculateDrawProperties( |
| 7832 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7833 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7834 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7835 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7836 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7837 | // Case 4: Rotation. |
| 7838 | gfx::Transform rotation; |
| 7839 | rotation.Rotate(10.0); |
| 7840 | child_->SetTransform(rotation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7841 | ExecuteCalculateDrawProperties( |
| 7842 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7843 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7844 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7845 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7846 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7847 | // Case 5: Scale. |
| 7848 | gfx::Transform scale; |
| 7849 | scale.Scale(2.0, 2.0); |
| 7850 | child_->SetTransform(scale); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7851 | ExecuteCalculateDrawProperties( |
| 7852 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7853 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7854 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7855 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7856 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7857 | // Case 6: Skew. |
| 7858 | gfx::Transform skew; |
| 7859 | skew.SkewX(10.0); |
| 7860 | child_->SetTransform(skew); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7861 | ExecuteCalculateDrawProperties( |
| 7862 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7863 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7864 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7865 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7866 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7867 | // Case 7: Translucent. |
| 7868 | child_->SetTransform(identity_matrix); |
| 7869 | child_->SetOpacity(0.5f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7870 | ExecuteCalculateDrawProperties( |
| 7871 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7872 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7873 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 7874 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7875 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7876 | // Case 8: Sanity check: restore transform and opacity. |
| 7877 | child_->SetTransform(identity_matrix); |
| 7878 | child_->SetOpacity(1.f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7879 | ExecuteCalculateDrawProperties( |
| 7880 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7881 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7882 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7883 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7884 | } |
| 7885 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 7886 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7887 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7888 | ExecuteCalculateDrawProperties( |
| 7889 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7890 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7891 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7892 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7893 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7894 | // Add opacity animation. |
| 7895 | child_->SetOpacity(0.9f); |
| 7896 | AddOpacityTransitionToController( |
| 7897 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7898 | |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 7899 | ExecuteCalculateDrawProperties( |
| 7900 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7901 | // Text AA should not be adjusted while animation is active. |
| 7902 | // Make sure LCD text AA setting remains unchanged. |
| 7903 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 7904 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 7905 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7906 | } |
| 7907 | |
| 7908 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 7909 | LCDTextTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 7910 | testing::Combine(testing::Bool(), testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 7911 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7912 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7913 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7914 | TestSharedBitmapManager shared_bitmap_manager; |
| 7915 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7916 | host_impl.CreatePendingTree(); |
| 7917 | const gfx::Transform identity_matrix; |
| 7918 | |
| 7919 | scoped_refptr<Layer> root = Layer::Create(); |
| 7920 | SetLayerPropertiesForTesting(root.get(), |
| 7921 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7922 | gfx::PointF(), |
| 7923 | gfx::PointF(), |
| 7924 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7925 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7926 | false); |
| 7927 | root->SetIsDrawable(true); |
| 7928 | |
| 7929 | scoped_refptr<Layer> child = Layer::Create(); |
| 7930 | SetLayerPropertiesForTesting(child.get(), |
| 7931 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7932 | gfx::PointF(), |
| 7933 | gfx::PointF(), |
| 7934 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7935 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7936 | false); |
| 7937 | child->SetIsDrawable(true); |
| 7938 | |
| 7939 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 7940 | SetLayerPropertiesForTesting(grand_child.get(), |
| 7941 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7942 | gfx::PointF(), |
| 7943 | gfx::PointF(), |
| 7944 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7945 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7946 | false); |
| 7947 | grand_child->SetIsDrawable(true); |
| 7948 | grand_child->SetHideLayerAndSubtree(true); |
| 7949 | |
| 7950 | child->AddChild(grand_child); |
| 7951 | root->AddChild(child); |
| 7952 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 7953 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7954 | host->SetRootLayer(root); |
| 7955 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7956 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 7957 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7958 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7959 | inputs.can_adjust_raster_scales = true; |
| 7960 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7961 | |
| 7962 | // We should have one render surface and two layers. The grand child has |
| 7963 | // hidden itself. |
| 7964 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 7965 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7966 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 7967 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7968 | } |
| 7969 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 7970 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7971 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7972 | TestSharedBitmapManager shared_bitmap_manager; |
| 7973 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7974 | host_impl.CreatePendingTree(); |
| 7975 | const gfx::Transform identity_matrix; |
| 7976 | |
| 7977 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 7978 | SetLayerPropertiesForTesting(root.get(), |
| 7979 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7980 | gfx::PointF(), |
| 7981 | gfx::PointF(), |
| 7982 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7983 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7984 | false); |
| 7985 | root->SetDrawsContent(true); |
| 7986 | |
| 7987 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 7988 | SetLayerPropertiesForTesting(child.get(), |
| 7989 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7990 | gfx::PointF(), |
| 7991 | gfx::PointF(), |
| 7992 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7993 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 7994 | false); |
| 7995 | child->SetDrawsContent(true); |
| 7996 | |
| 7997 | scoped_ptr<LayerImpl> grand_child = |
| 7998 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 7999 | SetLayerPropertiesForTesting(grand_child.get(), |
| 8000 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8001 | gfx::PointF(), |
| 8002 | gfx::PointF(), |
| 8003 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8004 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8005 | false); |
| 8006 | grand_child->SetDrawsContent(true); |
| 8007 | grand_child->SetHideLayerAndSubtree(true); |
| 8008 | |
| 8009 | child->AddChild(grand_child.Pass()); |
| 8010 | root->AddChild(child.Pass()); |
| 8011 | |
| 8012 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8013 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8014 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8015 | inputs.can_adjust_raster_scales = true; |
| 8016 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8017 | |
| 8018 | // We should have one render surface and two layers. The grand child has |
| 8019 | // hidden itself. |
| 8020 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 8021 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8022 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 8023 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8024 | } |
| 8025 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8026 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8027 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8028 | TestSharedBitmapManager shared_bitmap_manager; |
| 8029 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8030 | host_impl.CreatePendingTree(); |
| 8031 | const gfx::Transform identity_matrix; |
| 8032 | |
| 8033 | scoped_refptr<Layer> root = Layer::Create(); |
| 8034 | SetLayerPropertiesForTesting(root.get(), |
| 8035 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8036 | gfx::PointF(), |
| 8037 | gfx::PointF(), |
| 8038 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8039 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8040 | false); |
| 8041 | root->SetIsDrawable(true); |
| 8042 | |
| 8043 | scoped_refptr<Layer> child = Layer::Create(); |
| 8044 | SetLayerPropertiesForTesting(child.get(), |
| 8045 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8046 | gfx::PointF(), |
| 8047 | gfx::PointF(), |
| 8048 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8049 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8050 | false); |
| 8051 | child->SetIsDrawable(true); |
| 8052 | child->SetHideLayerAndSubtree(true); |
| 8053 | |
| 8054 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 8055 | SetLayerPropertiesForTesting(grand_child.get(), |
| 8056 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8057 | gfx::PointF(), |
| 8058 | gfx::PointF(), |
| 8059 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8060 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8061 | false); |
| 8062 | grand_child->SetIsDrawable(true); |
| 8063 | |
| 8064 | child->AddChild(grand_child); |
| 8065 | root->AddChild(child); |
| 8066 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8067 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8068 | host->SetRootLayer(root); |
| 8069 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8070 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8071 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8072 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8073 | inputs.can_adjust_raster_scales = true; |
| 8074 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8075 | |
| 8076 | // We should have one render surface and one layers. The child has |
| 8077 | // hidden itself and the grand child. |
| 8078 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 8079 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8080 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8081 | } |
| 8082 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8083 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8084 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8085 | TestSharedBitmapManager shared_bitmap_manager; |
| 8086 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8087 | host_impl.CreatePendingTree(); |
| 8088 | const gfx::Transform identity_matrix; |
| 8089 | |
| 8090 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 8091 | SetLayerPropertiesForTesting(root.get(), |
| 8092 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8093 | gfx::PointF(), |
| 8094 | gfx::PointF(), |
| 8095 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8096 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8097 | false); |
| 8098 | root->SetDrawsContent(true); |
| 8099 | |
| 8100 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 8101 | SetLayerPropertiesForTesting(child.get(), |
| 8102 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8103 | gfx::PointF(), |
| 8104 | gfx::PointF(), |
| 8105 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8106 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8107 | false); |
| 8108 | child->SetDrawsContent(true); |
| 8109 | child->SetHideLayerAndSubtree(true); |
| 8110 | |
| 8111 | scoped_ptr<LayerImpl> grand_child = |
| 8112 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 8113 | SetLayerPropertiesForTesting(grand_child.get(), |
| 8114 | identity_matrix, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8115 | gfx::PointF(), |
| 8116 | gfx::PointF(), |
| 8117 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8118 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8119 | false); |
| 8120 | grand_child->SetDrawsContent(true); |
| 8121 | |
| 8122 | child->AddChild(grand_child.Pass()); |
| 8123 | root->AddChild(child.Pass()); |
| 8124 | |
| 8125 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8126 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8127 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8128 | inputs.can_adjust_raster_scales = true; |
| 8129 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8130 | |
| 8131 | // We should have one render surface and one layers. The child has |
| 8132 | // hidden itself and the grand child. |
| 8133 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 8134 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8135 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 8136 | } |
| 8137 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8138 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 8139 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8140 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8141 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8142 | TestSharedBitmapManager shared_bitmap_manager; |
| 8143 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8144 | host_impl.CreatePendingTree(); |
| 8145 | const gfx::Transform identity_matrix; |
| 8146 | |
| 8147 | scoped_refptr<Layer> root = Layer::Create(); |
| 8148 | SetLayerPropertiesForTesting(root.get(), |
| 8149 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8150 | gfx::PointF(), |
| 8151 | gfx::PointF(), |
| 8152 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8153 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8154 | false); |
| 8155 | root->SetIsDrawable(true); |
| 8156 | |
| 8157 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(); |
| 8158 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 8159 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8160 | gfx::PointF(), |
| 8161 | gfx::PointF(), |
| 8162 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8163 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8164 | false); |
| 8165 | copy_grand_parent->SetIsDrawable(true); |
| 8166 | |
| 8167 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 8168 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 8169 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8170 | gfx::PointF(), |
| 8171 | gfx::PointF(), |
| 8172 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8173 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8174 | false); |
| 8175 | copy_parent->SetIsDrawable(true); |
| 8176 | copy_parent->SetForceRenderSurface(true); |
| 8177 | |
| 8178 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 8179 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 8180 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8181 | gfx::PointF(), |
| 8182 | gfx::PointF(), |
| 8183 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8184 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8185 | false); |
| 8186 | copy_layer->SetIsDrawable(true); |
| 8187 | |
| 8188 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 8189 | SetLayerPropertiesForTesting(copy_child.get(), |
| 8190 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8191 | gfx::PointF(), |
| 8192 | gfx::PointF(), |
| 8193 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8194 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8195 | false); |
| 8196 | copy_child->SetIsDrawable(true); |
| 8197 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8198 | scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); |
| 8199 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 8200 | identity_matrix, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8201 | gfx::PointF(), |
| 8202 | gfx::PointF(), |
| 8203 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8204 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8205 | false); |
| 8206 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 8207 | |
| 8208 | scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); |
| 8209 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 8210 | identity_matrix, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8211 | gfx::PointF(), |
| 8212 | gfx::PointF(), |
| 8213 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8214 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8215 | false); |
| 8216 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 8217 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8218 | copy_layer->AddChild(copy_child); |
| 8219 | copy_parent->AddChild(copy_layer); |
| 8220 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8221 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8222 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8223 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8224 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8225 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8226 | host->SetRootLayer(root); |
| 8227 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8228 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 8229 | // hidden subtree on copy_layer. |
| 8230 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8231 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 8232 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8233 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 8234 | base::Bind(&EmptyCopyOutputCallback))); |
| 8235 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 8236 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8237 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8238 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8239 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8240 | inputs.can_adjust_raster_scales = true; |
| 8241 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8242 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8243 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 8244 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 8245 | layer_or_descendant_has_copy_request); |
| 8246 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 8247 | layer_or_descendant_has_copy_request); |
| 8248 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 8249 | layer_or_descendant_has_copy_request); |
| 8250 | EXPECT_FALSE(copy_child->draw_properties(). |
| 8251 | layer_or_descendant_has_copy_request); |
| 8252 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 8253 | layer_or_descendant_has_copy_request); |
| 8254 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 8255 | layer_or_descendant_has_copy_request); |
| 8256 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8257 | // We should have three render surfaces, one for the root, one for the parent |
| 8258 | // since it owns a surface, and one for the copy_layer. |
| 8259 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8260 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 8261 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 8262 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8263 | |
| 8264 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 8265 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 8266 | // will appear since something in its subtree needs to be drawn for a copy |
| 8267 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8268 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8269 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 8270 | EXPECT_EQ(copy_parent->id(), |
| 8271 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8272 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 8273 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8274 | // appear in its list, since it needs to be drawn for the copy request. |
| 8275 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 8276 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8277 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8278 | |
| 8279 | // The copy_layer's render surface should have two contributing layers. |
| 8280 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 8281 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8282 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8283 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8284 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8285 | } |
| 8286 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8287 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8288 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8289 | TestSharedBitmapManager shared_bitmap_manager; |
| 8290 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8291 | host_impl.CreatePendingTree(); |
| 8292 | const gfx::Transform identity_matrix; |
| 8293 | |
| 8294 | scoped_refptr<Layer> root = Layer::Create(); |
| 8295 | SetLayerPropertiesForTesting(root.get(), |
| 8296 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8297 | gfx::PointF(), |
| 8298 | gfx::PointF(), |
| 8299 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8300 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8301 | false); |
| 8302 | root->SetIsDrawable(true); |
| 8303 | |
| 8304 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 8305 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 8306 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8307 | gfx::PointF(), |
| 8308 | gfx::PointF(), |
| 8309 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8310 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8311 | false); |
| 8312 | copy_parent->SetIsDrawable(true); |
| 8313 | copy_parent->SetMasksToBounds(true); |
| 8314 | |
| 8315 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 8316 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 8317 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8318 | gfx::PointF(), |
| 8319 | gfx::PointF(), |
| 8320 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8321 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8322 | false); |
| 8323 | copy_layer->SetIsDrawable(true); |
| 8324 | |
| 8325 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 8326 | SetLayerPropertiesForTesting(copy_child.get(), |
| 8327 | identity_matrix, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8328 | gfx::PointF(), |
| 8329 | gfx::PointF(), |
| 8330 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8331 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8332 | false); |
| 8333 | copy_child->SetIsDrawable(true); |
| 8334 | |
| 8335 | copy_layer->AddChild(copy_child); |
| 8336 | copy_parent->AddChild(copy_layer); |
| 8337 | root->AddChild(copy_parent); |
| 8338 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8339 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8340 | host->SetRootLayer(root); |
| 8341 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8342 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 8343 | base::Bind(&EmptyCopyOutputCallback))); |
| 8344 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 8345 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8346 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8347 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8348 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8349 | inputs.can_adjust_raster_scales = true; |
| 8350 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8351 | |
| 8352 | // We should have one render surface, as the others are clipped out. |
| 8353 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8354 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8355 | |
| 8356 | // The root render surface should only have 1 contributing layer, since the |
| 8357 | // other layers are empty/clipped away. |
| 8358 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 8359 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 8360 | } |
| 8361 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8362 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 8363 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8364 | TestSharedBitmapManager shared_bitmap_manager; |
| 8365 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8366 | host_impl.CreatePendingTree(); |
| 8367 | const gfx::Transform identity_matrix; |
| 8368 | |
| 8369 | scoped_refptr<Layer> root = Layer::Create(); |
| 8370 | SetLayerPropertiesForTesting(root.get(), |
| 8371 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8372 | gfx::PointF(), |
| 8373 | gfx::PointF(), |
| 8374 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8375 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8376 | false); |
| 8377 | root->SetIsDrawable(true); |
| 8378 | |
| 8379 | // The surface is moved slightly outside of the viewport. |
| 8380 | scoped_refptr<Layer> surface = Layer::Create(); |
| 8381 | SetLayerPropertiesForTesting(surface.get(), |
| 8382 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8383 | gfx::PointF(), |
| 8384 | gfx::PointF(-10, -20), |
| 8385 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8386 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8387 | false); |
| 8388 | surface->SetForceRenderSurface(true); |
| 8389 | |
| 8390 | scoped_refptr<Layer> surface_child = Layer::Create(); |
| 8391 | SetLayerPropertiesForTesting(surface_child.get(), |
| 8392 | identity_matrix, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8393 | gfx::PointF(), |
| 8394 | gfx::PointF(), |
| 8395 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8396 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8397 | false); |
| 8398 | surface_child->SetIsDrawable(true); |
| 8399 | |
| 8400 | surface->AddChild(surface_child); |
| 8401 | root->AddChild(surface); |
| 8402 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 8403 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8404 | host->SetRootLayer(root); |
| 8405 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8406 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 8407 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8408 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8409 | inputs.can_adjust_raster_scales = true; |
| 8410 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 8411 | |
| 8412 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 8413 | // the viewport. |
| 8414 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 8415 | surface_child->visible_content_rect().ToString()); |
| 8416 | } |
| 8417 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8418 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 8419 | // Ensure that a transform between the layer and its render surface is not a |
| 8420 | // problem. Constructs the following layer tree. |
| 8421 | // |
| 8422 | // root (a render surface) |
| 8423 | // + render_surface |
| 8424 | // + clip_parent (scaled) |
| 8425 | // + intervening_clipping_layer |
| 8426 | // + clip_child |
| 8427 | // |
| 8428 | // The render surface should be resized correctly and the clip child should |
| 8429 | // inherit the right clip rect. |
| 8430 | scoped_refptr<Layer> root = Layer::Create(); |
| 8431 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 8432 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8433 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8434 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8435 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8436 | |
| 8437 | root->AddChild(render_surface); |
| 8438 | render_surface->AddChild(clip_parent); |
| 8439 | clip_parent->AddChild(intervening); |
| 8440 | intervening->AddChild(clip_child); |
| 8441 | |
| 8442 | clip_child->SetClipParent(clip_parent.get()); |
| 8443 | |
| 8444 | intervening->SetMasksToBounds(true); |
| 8445 | clip_parent->SetMasksToBounds(true); |
| 8446 | |
| 8447 | render_surface->SetForceRenderSurface(true); |
| 8448 | |
| 8449 | gfx::Transform scale_transform; |
| 8450 | scale_transform.Scale(2, 2); |
| 8451 | |
| 8452 | gfx::Transform identity_transform; |
| 8453 | |
| 8454 | SetLayerPropertiesForTesting(root.get(), |
| 8455 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8456 | gfx::PointF(), |
| 8457 | gfx::PointF(), |
| 8458 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8459 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8460 | false); |
| 8461 | SetLayerPropertiesForTesting(render_surface.get(), |
| 8462 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8463 | gfx::PointF(), |
| 8464 | gfx::PointF(), |
| 8465 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8466 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8467 | false); |
| 8468 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8469 | scale_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8470 | gfx::PointF(), |
| 8471 | gfx::PointF(1.f, 1.f), |
| 8472 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8473 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8474 | false); |
| 8475 | SetLayerPropertiesForTesting(intervening.get(), |
| 8476 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8477 | gfx::PointF(), |
| 8478 | gfx::PointF(1.f, 1.f), |
| 8479 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8480 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8481 | false); |
| 8482 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8483 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8484 | gfx::PointF(), |
| 8485 | gfx::PointF(1.f, 1.f), |
| 8486 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8487 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8488 | false); |
| 8489 | |
| 8490 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8491 | host->SetRootLayer(root); |
| 8492 | |
| 8493 | ExecuteCalculateDrawProperties(root.get()); |
| 8494 | |
| 8495 | ASSERT_TRUE(root->render_surface()); |
| 8496 | ASSERT_TRUE(render_surface->render_surface()); |
| 8497 | |
| 8498 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 8499 | // by the intervening clip layer. |
| 8500 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 8501 | clip_parent->clip_rect().ToString()); |
| 8502 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 8503 | clip_child->clip_rect().ToString()); |
| 8504 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 8505 | intervening->clip_rect().ToString()); |
| 8506 | |
| 8507 | // Ensure that the render surface reports a content rect that has been grown |
| 8508 | // to accomodate for the clip child. |
| 8509 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 8510 | render_surface->render_surface()->content_rect().ToString()); |
| 8511 | |
| 8512 | // The above check implies the two below, but they nicely demonstrate that |
| 8513 | // we've grown, despite the intervening layer's clip. |
| 8514 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 8515 | render_surface->render_surface()->content_rect())); |
| 8516 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 8517 | render_surface->render_surface()->content_rect())); |
| 8518 | } |
| 8519 | |
| 8520 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 8521 | // Ensure that intervening render surfaces are not a problem in the basic |
| 8522 | // case. In the following tree, both render surfaces should be resized to |
| 8523 | // accomodate for the clip child, despite an intervening clip. |
| 8524 | // |
| 8525 | // root (a render surface) |
| 8526 | // + clip_parent (masks to bounds) |
| 8527 | // + render_surface1 (sets opacity) |
| 8528 | // + intervening (masks to bounds) |
| 8529 | // + render_surface2 (also sets opacity) |
| 8530 | // + clip_child |
| 8531 | // |
| 8532 | scoped_refptr<Layer> root = Layer::Create(); |
| 8533 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8534 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8535 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8536 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8537 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8538 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8539 | |
| 8540 | root->AddChild(clip_parent); |
| 8541 | clip_parent->AddChild(render_surface1); |
| 8542 | render_surface1->AddChild(intervening); |
| 8543 | intervening->AddChild(render_surface2); |
| 8544 | render_surface2->AddChild(clip_child); |
| 8545 | |
| 8546 | clip_child->SetClipParent(clip_parent.get()); |
| 8547 | |
| 8548 | intervening->SetMasksToBounds(true); |
| 8549 | clip_parent->SetMasksToBounds(true); |
| 8550 | |
| 8551 | render_surface1->SetForceRenderSurface(true); |
| 8552 | render_surface2->SetForceRenderSurface(true); |
| 8553 | |
| 8554 | gfx::Transform translation_transform; |
| 8555 | translation_transform.Translate(2, 2); |
| 8556 | |
| 8557 | gfx::Transform identity_transform; |
| 8558 | SetLayerPropertiesForTesting(root.get(), |
| 8559 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8560 | gfx::PointF(), |
| 8561 | gfx::PointF(), |
| 8562 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8563 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8564 | false); |
| 8565 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8566 | translation_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8567 | gfx::PointF(), |
| 8568 | gfx::PointF(1.f, 1.f), |
| 8569 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8570 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8571 | false); |
| 8572 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8573 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8574 | gfx::PointF(), |
| 8575 | gfx::PointF(), |
| 8576 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8577 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8578 | false); |
| 8579 | SetLayerPropertiesForTesting(intervening.get(), |
| 8580 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8581 | gfx::PointF(), |
| 8582 | gfx::PointF(1.f, 1.f), |
| 8583 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8584 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8585 | false); |
| 8586 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8587 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8588 | gfx::PointF(), |
| 8589 | gfx::PointF(), |
| 8590 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8591 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8592 | false); |
| 8593 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8594 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8595 | gfx::PointF(), |
| 8596 | gfx::PointF(-10.f, -10.f), |
| 8597 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8598 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8599 | false); |
| 8600 | |
| 8601 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8602 | host->SetRootLayer(root); |
| 8603 | |
| 8604 | ExecuteCalculateDrawProperties(root.get()); |
| 8605 | |
| 8606 | EXPECT_TRUE(root->render_surface()); |
| 8607 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8608 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8609 | |
| 8610 | // Since the render surfaces could have expanded, they should not clip (their |
| 8611 | // bounds would no longer be reliable). We should resort to layer clipping |
| 8612 | // in this case. |
| 8613 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8614 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8615 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8616 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8617 | render_surface2->render_surface()->clip_rect().ToString()); |
| 8618 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 8619 | |
| 8620 | // NB: clip rects are in target space. |
| 8621 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8622 | render_surface1->clip_rect().ToString()); |
| 8623 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8624 | |
| 8625 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 8626 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8627 | render_surface2->clip_rect().ToString()); |
| 8628 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 8629 | |
| 8630 | // The content rects of both render surfaces should both have expanded to |
| 8631 | // contain the clip child. |
| 8632 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8633 | render_surface1->render_surface()->content_rect().ToString()); |
| 8634 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 8635 | render_surface2->render_surface()->content_rect().ToString()); |
| 8636 | |
| 8637 | // The clip child should have inherited the clip parent's clip (projected to |
| 8638 | // the right space, of course), and should have the correctly sized visible |
| 8639 | // content rect. |
| 8640 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 8641 | clip_child->clip_rect().ToString()); |
| 8642 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 8643 | clip_child->visible_content_rect().ToString()); |
| 8644 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8645 | } |
| 8646 | |
| 8647 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 8648 | // Ensure that intervening render surfaces are not a problem, even if there |
| 8649 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 8650 | // of transform. |
| 8651 | // |
| 8652 | // root (a render surface) |
| 8653 | // + clip_parent (masks to bounds) |
| 8654 | // + render_surface1 (sets opacity) |
| 8655 | // + intervening (masks to bounds AND scrolls) |
| 8656 | // + render_surface2 (also sets opacity) |
| 8657 | // + clip_child |
| 8658 | // |
| 8659 | scoped_refptr<Layer> root = Layer::Create(); |
| 8660 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8661 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8662 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8663 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8664 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8665 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8666 | |
| 8667 | root->AddChild(clip_parent); |
| 8668 | clip_parent->AddChild(render_surface1); |
| 8669 | render_surface1->AddChild(intervening); |
| 8670 | intervening->AddChild(render_surface2); |
| 8671 | render_surface2->AddChild(clip_child); |
| 8672 | |
| 8673 | clip_child->SetClipParent(clip_parent.get()); |
| 8674 | |
| 8675 | intervening->SetMasksToBounds(true); |
| 8676 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 8677 | intervening->SetScrollClipLayerId(clip_parent->id()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8678 | intervening->SetScrollOffset(gfx::Vector2d(3, 3)); |
| 8679 | |
| 8680 | render_surface1->SetForceRenderSurface(true); |
| 8681 | render_surface2->SetForceRenderSurface(true); |
| 8682 | |
| 8683 | gfx::Transform translation_transform; |
| 8684 | translation_transform.Translate(2, 2); |
| 8685 | |
| 8686 | gfx::Transform identity_transform; |
| 8687 | SetLayerPropertiesForTesting(root.get(), |
| 8688 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8689 | gfx::PointF(), |
| 8690 | gfx::PointF(), |
| 8691 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8692 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8693 | false); |
| 8694 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8695 | translation_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8696 | gfx::PointF(), |
| 8697 | gfx::PointF(1.f, 1.f), |
| 8698 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8699 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8700 | false); |
| 8701 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8702 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8703 | gfx::PointF(), |
| 8704 | gfx::PointF(), |
| 8705 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8706 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8707 | false); |
| 8708 | SetLayerPropertiesForTesting(intervening.get(), |
| 8709 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8710 | gfx::PointF(), |
| 8711 | gfx::PointF(1.f, 1.f), |
| 8712 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8713 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8714 | false); |
| 8715 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8716 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8717 | gfx::PointF(), |
| 8718 | gfx::PointF(), |
| 8719 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8720 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8721 | false); |
| 8722 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8723 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8724 | gfx::PointF(), |
| 8725 | gfx::PointF(-10.f, -10.f), |
| 8726 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8727 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8728 | false); |
| 8729 | |
| 8730 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8731 | host->SetRootLayer(root); |
| 8732 | |
| 8733 | ExecuteCalculateDrawProperties(root.get()); |
| 8734 | |
| 8735 | EXPECT_TRUE(root->render_surface()); |
| 8736 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8737 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8738 | |
| 8739 | // Since the render surfaces could have expanded, they should not clip (their |
| 8740 | // bounds would no longer be reliable). We should resort to layer clipping |
| 8741 | // in this case. |
| 8742 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8743 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8744 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8745 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8746 | render_surface2->render_surface()->clip_rect().ToString()); |
| 8747 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 8748 | |
| 8749 | // NB: clip rects are in target space. |
| 8750 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8751 | render_surface1->clip_rect().ToString()); |
| 8752 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8753 | |
| 8754 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 8755 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 8756 | render_surface2->clip_rect().ToString()); |
| 8757 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 8758 | |
| 8759 | // The content rects of both render surfaces should both have expanded to |
| 8760 | // contain the clip child. |
| 8761 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8762 | render_surface1->render_surface()->content_rect().ToString()); |
| 8763 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 8764 | render_surface2->render_surface()->content_rect().ToString()); |
| 8765 | |
| 8766 | // The clip child should have inherited the clip parent's clip (projected to |
| 8767 | // the right space, of course), and should have the correctly sized visible |
| 8768 | // content rect. |
| 8769 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 8770 | clip_child->clip_rect().ToString()); |
| 8771 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 8772 | clip_child->visible_content_rect().ToString()); |
| 8773 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8774 | } |
| 8775 | |
| 8776 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 8777 | // Ensures that descendants of the clip child inherit the correct clip. |
| 8778 | // |
| 8779 | // root (a render surface) |
| 8780 | // + clip_parent (masks to bounds) |
| 8781 | // + intervening (masks to bounds) |
| 8782 | // + clip_child |
| 8783 | // + child |
| 8784 | // |
| 8785 | scoped_refptr<Layer> root = Layer::Create(); |
| 8786 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8787 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 8788 | scoped_refptr<Layer> clip_child = Layer::Create(); |
| 8789 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 8790 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8791 | |
| 8792 | root->AddChild(clip_parent); |
| 8793 | clip_parent->AddChild(intervening); |
| 8794 | intervening->AddChild(clip_child); |
| 8795 | clip_child->AddChild(child); |
| 8796 | |
| 8797 | clip_child->SetClipParent(clip_parent.get()); |
| 8798 | |
| 8799 | intervening->SetMasksToBounds(true); |
| 8800 | clip_parent->SetMasksToBounds(true); |
| 8801 | |
| 8802 | gfx::Transform identity_transform; |
| 8803 | SetLayerPropertiesForTesting(root.get(), |
| 8804 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8805 | gfx::PointF(), |
| 8806 | gfx::PointF(), |
| 8807 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8808 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8809 | false); |
| 8810 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8811 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8812 | gfx::PointF(), |
| 8813 | gfx::PointF(), |
| 8814 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8815 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8816 | false); |
| 8817 | SetLayerPropertiesForTesting(intervening.get(), |
| 8818 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8819 | gfx::PointF(), |
| 8820 | gfx::PointF(), |
| 8821 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8822 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8823 | false); |
| 8824 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8825 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8826 | gfx::PointF(), |
| 8827 | gfx::PointF(), |
| 8828 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8829 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8830 | false); |
| 8831 | SetLayerPropertiesForTesting(child.get(), |
| 8832 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8833 | gfx::PointF(), |
| 8834 | gfx::PointF(), |
| 8835 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8836 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8837 | false); |
| 8838 | |
| 8839 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8840 | host->SetRootLayer(root); |
| 8841 | |
| 8842 | ExecuteCalculateDrawProperties(root.get()); |
| 8843 | |
| 8844 | EXPECT_TRUE(root->render_surface()); |
| 8845 | |
| 8846 | // Neither the clip child nor its descendant should have inherited the clip |
| 8847 | // from |intervening|. |
| 8848 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8849 | clip_child->clip_rect().ToString()); |
| 8850 | EXPECT_TRUE(clip_child->is_clipped()); |
| 8851 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 8852 | child->visible_content_rect().ToString()); |
| 8853 | EXPECT_TRUE(child->is_clipped()); |
| 8854 | } |
| 8855 | |
| 8856 | TEST_F(LayerTreeHostCommonTest, |
| 8857 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 8858 | // Ensures that non-descendant clip children in the tree do not affect |
| 8859 | // render surfaces. |
| 8860 | // |
| 8861 | // root (a render surface) |
| 8862 | // + clip_parent (masks to bounds) |
| 8863 | // + render_surface1 |
| 8864 | // + clip_child |
| 8865 | // + render_surface2 |
| 8866 | // + non_clip_child |
| 8867 | // |
| 8868 | // In this example render_surface2 should be unaffected by clip_child. |
| 8869 | scoped_refptr<Layer> root = Layer::Create(); |
| 8870 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 8871 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 8872 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 8873 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8874 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 8875 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
| 8876 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 8877 | |
| 8878 | root->AddChild(clip_parent); |
| 8879 | clip_parent->AddChild(render_surface1); |
| 8880 | render_surface1->AddChild(clip_child); |
| 8881 | clip_parent->AddChild(render_surface2); |
| 8882 | render_surface2->AddChild(non_clip_child); |
| 8883 | |
| 8884 | clip_child->SetClipParent(clip_parent.get()); |
| 8885 | |
| 8886 | clip_parent->SetMasksToBounds(true); |
| 8887 | render_surface1->SetMasksToBounds(true); |
| 8888 | |
| 8889 | gfx::Transform identity_transform; |
| 8890 | SetLayerPropertiesForTesting(root.get(), |
| 8891 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8892 | gfx::PointF(), |
| 8893 | gfx::PointF(), |
| 8894 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8895 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8896 | false); |
| 8897 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 8898 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8899 | gfx::PointF(), |
| 8900 | gfx::PointF(), |
| 8901 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8902 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8903 | false); |
| 8904 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 8905 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8906 | gfx::PointF(), |
| 8907 | gfx::PointF(5, 5), |
| 8908 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8909 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8910 | false); |
| 8911 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 8912 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8913 | gfx::PointF(), |
| 8914 | gfx::PointF(), |
| 8915 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8916 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8917 | false); |
| 8918 | SetLayerPropertiesForTesting(clip_child.get(), |
| 8919 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8920 | gfx::PointF(), |
| 8921 | gfx::PointF(-1, 1), |
| 8922 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8923 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8924 | false); |
| 8925 | SetLayerPropertiesForTesting(non_clip_child.get(), |
| 8926 | identity_transform, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8927 | gfx::PointF(), |
| 8928 | gfx::PointF(), |
| 8929 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8930 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 8931 | false); |
| 8932 | |
| 8933 | render_surface1->SetForceRenderSurface(true); |
| 8934 | render_surface2->SetForceRenderSurface(true); |
| 8935 | |
| 8936 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 8937 | host->SetRootLayer(root); |
| 8938 | |
| 8939 | ExecuteCalculateDrawProperties(root.get()); |
| 8940 | |
| 8941 | EXPECT_TRUE(root->render_surface()); |
| 8942 | EXPECT_TRUE(render_surface1->render_surface()); |
| 8943 | EXPECT_TRUE(render_surface2->render_surface()); |
| 8944 | |
| 8945 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8946 | render_surface1->clip_rect().ToString()); |
| 8947 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 8948 | |
| 8949 | // The render surface should not clip (it has unclipped descendants), instead |
| 8950 | // it should rely on layer clipping. |
| 8951 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 8952 | render_surface1->render_surface()->clip_rect().ToString()); |
| 8953 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 8954 | |
| 8955 | // That said, it should have grown to accomodate the unclipped descendant. |
| 8956 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 8957 | render_surface1->render_surface()->content_rect().ToString()); |
| 8958 | |
| 8959 | // This render surface should clip. It has no unclipped descendants. |
| 8960 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8961 | render_surface2->clip_rect().ToString()); |
| 8962 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 8963 | |
| 8964 | // It also shouldn't have grown to accomodate the clip child. |
| 8965 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 8966 | render_surface2->render_surface()->content_rect().ToString()); |
| 8967 | |
| 8968 | // Sanity check our num_unclipped_descendants values. |
| 8969 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 8970 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 8971 | } |
| 8972 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8973 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 8974 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 8975 | TestSharedBitmapManager shared_bitmap_manager; |
| 8976 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8977 | scoped_ptr<LayerImpl> root = |
| 8978 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 8979 | scoped_ptr<LayerImpl> child1 = |
| 8980 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 8981 | scoped_ptr<LayerImpl> child2 = |
| 8982 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 8983 | scoped_ptr<LayerImpl> child3 = |
| 8984 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 8985 | |
| 8986 | gfx::Transform identity_matrix; |
| 8987 | gfx::PointF anchor; |
| 8988 | gfx::PointF position; |
| 8989 | gfx::Size bounds(100, 100); |
| 8990 | SetLayerPropertiesForTesting(root.get(), |
| 8991 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8992 | anchor, |
| 8993 | position, |
| 8994 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 8995 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 8996 | false); |
| 8997 | root->SetDrawsContent(true); |
| 8998 | |
| 8999 | // This layer structure normally forces render surface due to preserves3d |
| 9000 | // behavior. |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9001 | SetLayerPropertiesForTesting(child1.get(), |
| 9002 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9003 | anchor, |
| 9004 | position, |
| 9005 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9006 | false, |
| 9007 | true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9008 | child1->SetDrawsContent(true); |
| 9009 | SetLayerPropertiesForTesting(child2.get(), |
| 9010 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9011 | anchor, |
| 9012 | position, |
| 9013 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9014 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9015 | false); |
| 9016 | child2->SetDrawsContent(true); |
| 9017 | SetLayerPropertiesForTesting(child3.get(), |
| 9018 | identity_matrix, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9019 | anchor, |
| 9020 | position, |
| 9021 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9022 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9023 | false); |
| 9024 | child3->SetDrawsContent(true); |
| 9025 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9026 | child2->SetIs3dSorted(true); |
| 9027 | child3->SetIs3dSorted(true); |
| 9028 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 9029 | child2->AddChild(child3.Pass()); |
| 9030 | child1->AddChild(child2.Pass()); |
| 9031 | root->AddChild(child1.Pass()); |
| 9032 | |
| 9033 | { |
| 9034 | LayerImplList render_surface_layer_list; |
| 9035 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9036 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9037 | inputs.can_render_to_separate_surface = true; |
| 9038 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9039 | |
| 9040 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 9041 | } |
| 9042 | |
| 9043 | { |
| 9044 | LayerImplList render_surface_layer_list; |
| 9045 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9046 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9047 | inputs.can_render_to_separate_surface = false; |
| 9048 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9049 | |
| 9050 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
| 9051 | } |
| 9052 | } |
| 9053 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9054 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 9055 | scoped_refptr<Layer> root = Layer::Create(); |
| 9056 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 9057 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9058 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9059 | |
| 9060 | root->AddChild(render_surface); |
| 9061 | render_surface->AddChild(child); |
| 9062 | |
| 9063 | gfx::Transform identity_transform; |
| 9064 | SetLayerPropertiesForTesting(root.get(), |
| 9065 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9066 | gfx::PointF(), |
| 9067 | gfx::PointF(), |
| 9068 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9069 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9070 | false); |
| 9071 | SetLayerPropertiesForTesting(render_surface.get(), |
| 9072 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9073 | gfx::PointF(), |
| 9074 | gfx::PointF(), |
| 9075 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9076 | false, |
| 9077 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9078 | SetLayerPropertiesForTesting(child.get(), |
| 9079 | identity_transform, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9080 | gfx::PointF(), |
| 9081 | gfx::PointF(), |
| 9082 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9083 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9084 | false); |
| 9085 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9086 | root->SetShouldFlattenTransform(false); |
| 9087 | root->SetIs3dSorted(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 9088 | render_surface->SetDoubleSided(false); |
| 9089 | render_surface->SetForceRenderSurface(true); |
| 9090 | |
| 9091 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9092 | host->SetRootLayer(root); |
| 9093 | |
| 9094 | ExecuteCalculateDrawProperties(root.get()); |
| 9095 | |
| 9096 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 9097 | EXPECT_EQ(1u, |
| 9098 | render_surface_layer_list()->at(0) |
| 9099 | ->render_surface()->layer_list().size()); |
| 9100 | EXPECT_EQ(1u, |
| 9101 | render_surface_layer_list()->at(1) |
| 9102 | ->render_surface()->layer_list().size()); |
| 9103 | |
| 9104 | gfx::Transform rotation_transform = identity_transform; |
| 9105 | rotation_transform.RotateAboutXAxis(180.0); |
| 9106 | |
| 9107 | render_surface->SetTransform(rotation_transform); |
| 9108 | |
| 9109 | ExecuteCalculateDrawProperties(root.get()); |
| 9110 | |
| 9111 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 9112 | EXPECT_EQ(0u, |
| 9113 | render_surface_layer_list()->at(0) |
| 9114 | ->render_surface()->layer_list().size()); |
| 9115 | } |
| 9116 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9117 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 9118 | // Checks that the simple case (being clipped by a scroll parent that would |
| 9119 | // have been processed before you anyhow) results in the right clips. |
| 9120 | // |
| 9121 | // + root |
| 9122 | // + scroll_parent_border |
| 9123 | // | + scroll_parent_clip |
| 9124 | // | + scroll_parent |
| 9125 | // + scroll_child |
| 9126 | // |
| 9127 | scoped_refptr<Layer> root = Layer::Create(); |
| 9128 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9129 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9130 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9131 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9132 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9133 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9134 | |
| 9135 | root->AddChild(scroll_child); |
| 9136 | |
| 9137 | root->AddChild(scroll_parent_border); |
| 9138 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9139 | scroll_parent_clip->AddChild(scroll_parent); |
| 9140 | |
| 9141 | scroll_parent_clip->SetMasksToBounds(true); |
| 9142 | |
| 9143 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9144 | |
| 9145 | gfx::Transform identity_transform; |
| 9146 | SetLayerPropertiesForTesting(root.get(), |
| 9147 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9148 | gfx::PointF(), |
| 9149 | gfx::PointF(), |
| 9150 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9151 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9152 | false); |
| 9153 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9154 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9155 | gfx::PointF(), |
| 9156 | gfx::PointF(), |
| 9157 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9158 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9159 | false); |
| 9160 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9161 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9162 | gfx::PointF(), |
| 9163 | gfx::PointF(), |
| 9164 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9165 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9166 | false); |
| 9167 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9168 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9169 | gfx::PointF(), |
| 9170 | gfx::PointF(), |
| 9171 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9172 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9173 | false); |
| 9174 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9175 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9176 | gfx::PointF(), |
| 9177 | gfx::PointF(), |
| 9178 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9179 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9180 | false); |
| 9181 | |
| 9182 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9183 | host->SetRootLayer(root); |
| 9184 | |
| 9185 | ExecuteCalculateDrawProperties(root.get()); |
| 9186 | |
| 9187 | EXPECT_TRUE(root->render_surface()); |
| 9188 | |
| 9189 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 9190 | scroll_child->clip_rect().ToString()); |
| 9191 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9192 | } |
| 9193 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 9194 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 9195 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 9196 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9197 | scoped_refptr<LayerWithForcedDrawsContent> parent = |
| 9198 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9199 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 9200 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9201 | |
| 9202 | root->AddChild(parent); |
| 9203 | parent->AddChild(child); |
| 9204 | |
| 9205 | gfx::Transform identity_transform; |
| 9206 | SetLayerPropertiesForTesting(root.get(), |
| 9207 | identity_transform, |
| 9208 | gfx::PointF(), |
| 9209 | gfx::PointF(), |
| 9210 | gfx::Size(50, 50), |
| 9211 | true, |
| 9212 | true); |
| 9213 | root->SetForceRenderSurface(true); |
| 9214 | SetLayerPropertiesForTesting(parent.get(), |
| 9215 | identity_transform, |
| 9216 | gfx::PointF(), |
| 9217 | gfx::PointF(), |
| 9218 | gfx::Size(30, 30), |
| 9219 | true, |
| 9220 | true); |
| 9221 | parent->SetForceRenderSurface(true); |
| 9222 | SetLayerPropertiesForTesting(child.get(), |
| 9223 | identity_transform, |
| 9224 | gfx::PointF(), |
| 9225 | gfx::PointF(), |
| 9226 | gfx::Size(20, 20), |
| 9227 | true, |
| 9228 | true); |
| 9229 | child->SetForceRenderSurface(true); |
| 9230 | |
| 9231 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9232 | host->SetRootLayer(root); |
| 9233 | |
| 9234 | ExecuteCalculateDrawProperties(root.get()); |
| 9235 | |
| 9236 | EXPECT_EQ(3u, render_surface_layer_list()->size()); |
| 9237 | |
| 9238 | gfx::Transform singular_transform; |
| 9239 | singular_transform.Scale3d( |
| 9240 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 9241 | |
| 9242 | child->SetTransform(singular_transform); |
| 9243 | |
| 9244 | ExecuteCalculateDrawProperties(root.get()); |
| 9245 | |
| 9246 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 9247 | |
| 9248 | // Ensure that the entire subtree under a layer with singular transform does |
| 9249 | // not get rendered. |
| 9250 | parent->SetTransform(singular_transform); |
| 9251 | child->SetTransform(identity_transform); |
| 9252 | |
| 9253 | ExecuteCalculateDrawProperties(root.get()); |
| 9254 | |
| 9255 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 9256 | } |
| 9257 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9258 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 9259 | // Checks that clipping by a scroll parent that follows you in paint order |
| 9260 | // still results in correct clipping. |
| 9261 | // |
| 9262 | // + root |
| 9263 | // + scroll_child |
| 9264 | // + scroll_parent_border |
| 9265 | // + scroll_parent_clip |
| 9266 | // + scroll_parent |
| 9267 | // |
| 9268 | scoped_refptr<Layer> root = Layer::Create(); |
| 9269 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9270 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9271 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9272 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9273 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9274 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9275 | |
| 9276 | root->AddChild(scroll_parent_border); |
| 9277 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9278 | scroll_parent_clip->AddChild(scroll_parent); |
| 9279 | |
| 9280 | root->AddChild(scroll_child); |
| 9281 | |
| 9282 | scroll_parent_clip->SetMasksToBounds(true); |
| 9283 | |
| 9284 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9285 | |
| 9286 | gfx::Transform identity_transform; |
| 9287 | SetLayerPropertiesForTesting(root.get(), |
| 9288 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9289 | gfx::PointF(), |
| 9290 | gfx::PointF(), |
| 9291 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9292 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9293 | false); |
| 9294 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9295 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9296 | gfx::PointF(), |
| 9297 | gfx::PointF(), |
| 9298 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9299 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9300 | false); |
| 9301 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9302 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9303 | gfx::PointF(), |
| 9304 | gfx::PointF(), |
| 9305 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9306 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9307 | false); |
| 9308 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9309 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9310 | gfx::PointF(), |
| 9311 | gfx::PointF(), |
| 9312 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9313 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9314 | false); |
| 9315 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9316 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9317 | gfx::PointF(), |
| 9318 | gfx::PointF(), |
| 9319 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9320 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9321 | false); |
| 9322 | |
| 9323 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9324 | host->SetRootLayer(root); |
| 9325 | |
| 9326 | ExecuteCalculateDrawProperties(root.get()); |
| 9327 | |
| 9328 | EXPECT_TRUE(root->render_surface()); |
| 9329 | |
| 9330 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 9331 | scroll_child->clip_rect().ToString()); |
| 9332 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9333 | } |
| 9334 | |
| 9335 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 9336 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 9337 | // you in paint order still results in correct clipping. |
| 9338 | // |
| 9339 | // + root |
| 9340 | // + scroll_child |
| 9341 | // + scroll_parent_border |
| 9342 | // | + scroll_parent_clip |
| 9343 | // | + scroll_parent |
| 9344 | // + scroll_grandparent_border |
| 9345 | // + scroll_grandparent_clip |
| 9346 | // + scroll_grandparent |
| 9347 | // |
| 9348 | scoped_refptr<Layer> root = Layer::Create(); |
| 9349 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9350 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9351 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9352 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9353 | |
| 9354 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 9355 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 9356 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 9357 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9358 | |
| 9359 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9360 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9361 | |
| 9362 | root->AddChild(scroll_child); |
| 9363 | |
| 9364 | root->AddChild(scroll_parent_border); |
| 9365 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9366 | scroll_parent_clip->AddChild(scroll_parent); |
| 9367 | |
| 9368 | root->AddChild(scroll_grandparent_border); |
| 9369 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 9370 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 9371 | |
| 9372 | scroll_parent_clip->SetMasksToBounds(true); |
| 9373 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 9374 | |
| 9375 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9376 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 9377 | |
| 9378 | gfx::Transform identity_transform; |
| 9379 | SetLayerPropertiesForTesting(root.get(), |
| 9380 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9381 | gfx::PointF(), |
| 9382 | gfx::PointF(), |
| 9383 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9384 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9385 | false); |
| 9386 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 9387 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9388 | gfx::PointF(), |
| 9389 | gfx::PointF(), |
| 9390 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9391 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9392 | false); |
| 9393 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 9394 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9395 | gfx::PointF(), |
| 9396 | gfx::PointF(), |
| 9397 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9398 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9399 | false); |
| 9400 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 9401 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9402 | gfx::PointF(), |
| 9403 | gfx::PointF(), |
| 9404 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9405 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9406 | false); |
| 9407 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9408 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9409 | gfx::PointF(), |
| 9410 | gfx::PointF(), |
| 9411 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9412 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9413 | false); |
| 9414 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9415 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9416 | gfx::PointF(), |
| 9417 | gfx::PointF(), |
| 9418 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9419 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9420 | false); |
| 9421 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9422 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9423 | gfx::PointF(), |
| 9424 | gfx::PointF(), |
| 9425 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9426 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9427 | false); |
| 9428 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9429 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9430 | gfx::PointF(), |
| 9431 | gfx::PointF(), |
| 9432 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9433 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9434 | false); |
| 9435 | |
| 9436 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9437 | host->SetRootLayer(root); |
| 9438 | |
| 9439 | ExecuteCalculateDrawProperties(root.get()); |
| 9440 | |
| 9441 | EXPECT_TRUE(root->render_surface()); |
| 9442 | |
| 9443 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 9444 | scroll_child->clip_rect().ToString()); |
| 9445 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9446 | |
| 9447 | // Despite the fact that we visited the above layers out of order to get the |
| 9448 | // correct clip, the layer lists should be unaffected. |
| 9449 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 9450 | EXPECT_EQ(scroll_child.get(), |
| 9451 | root->render_surface()->layer_list().at(0)); |
| 9452 | EXPECT_EQ(scroll_parent.get(), |
| 9453 | root->render_surface()->layer_list().at(1)); |
| 9454 | EXPECT_EQ(scroll_grandparent.get(), |
| 9455 | root->render_surface()->layer_list().at(2)); |
| 9456 | } |
| 9457 | |
| 9458 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 9459 | // 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] | 9460 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9461 | // + root |
| 9462 | // + scroll_child |
| 9463 | // + scroll_parent_border |
| 9464 | // + scroll_parent_clip |
| 9465 | // + scroll_parent |
| 9466 | // + render_surface1 |
| 9467 | // + scroll_grandparent_border |
| 9468 | // + scroll_grandparent_clip |
| 9469 | // + scroll_grandparent |
| 9470 | // + render_surface2 |
| 9471 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 9472 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 9473 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9474 | |
| 9475 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 9476 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 9477 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 9478 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9479 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
| 9480 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9481 | |
| 9482 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 9483 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 9484 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 9485 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9486 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
| 9487 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9488 | |
| 9489 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 9490 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 9491 | |
| 9492 | root->AddChild(scroll_child); |
| 9493 | |
| 9494 | root->AddChild(scroll_parent_border); |
| 9495 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 9496 | scroll_parent_clip->AddChild(scroll_parent); |
| 9497 | scroll_parent->AddChild(render_surface2); |
| 9498 | |
| 9499 | root->AddChild(scroll_grandparent_border); |
| 9500 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 9501 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 9502 | scroll_grandparent->AddChild(render_surface1); |
| 9503 | |
| 9504 | scroll_parent_clip->SetMasksToBounds(true); |
| 9505 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 9506 | |
| 9507 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9508 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 9509 | |
| 9510 | render_surface1->SetForceRenderSurface(true); |
| 9511 | render_surface2->SetForceRenderSurface(true); |
| 9512 | |
| 9513 | gfx::Transform identity_transform; |
| 9514 | SetLayerPropertiesForTesting(root.get(), |
| 9515 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9516 | gfx::PointF(), |
| 9517 | gfx::PointF(), |
| 9518 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9519 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9520 | false); |
| 9521 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 9522 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9523 | gfx::PointF(), |
| 9524 | gfx::PointF(), |
| 9525 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9526 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9527 | false); |
| 9528 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 9529 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9530 | gfx::PointF(), |
| 9531 | gfx::PointF(), |
| 9532 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9533 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9534 | false); |
| 9535 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 9536 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9537 | gfx::PointF(), |
| 9538 | gfx::PointF(), |
| 9539 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9540 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9541 | false); |
| 9542 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 9543 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9544 | gfx::PointF(), |
| 9545 | gfx::PointF(), |
| 9546 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9547 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9548 | false); |
| 9549 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9550 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9551 | gfx::PointF(), |
| 9552 | gfx::PointF(), |
| 9553 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9554 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9555 | false); |
| 9556 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9557 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9558 | gfx::PointF(), |
| 9559 | gfx::PointF(), |
| 9560 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9561 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9562 | false); |
| 9563 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9564 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9565 | gfx::PointF(), |
| 9566 | gfx::PointF(), |
| 9567 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9568 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9569 | false); |
| 9570 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 9571 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9572 | gfx::PointF(), |
| 9573 | gfx::PointF(), |
| 9574 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9575 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9576 | false); |
| 9577 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9578 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9579 | gfx::PointF(), |
| 9580 | gfx::PointF(), |
| 9581 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9582 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9583 | false); |
| 9584 | |
| 9585 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9586 | host->SetRootLayer(root); |
| 9587 | |
| 9588 | RenderSurfaceLayerList render_surface_layer_list; |
| 9589 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 9590 | root.get(), |
| 9591 | root->bounds(), |
| 9592 | identity_transform, |
| 9593 | &render_surface_layer_list); |
| 9594 | |
| 9595 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9596 | |
| 9597 | EXPECT_TRUE(root->render_surface()); |
| 9598 | |
| 9599 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 9600 | scroll_child->clip_rect().ToString()); |
| 9601 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 9602 | |
| 9603 | // Despite the fact that we had to process the layers out of order to get the |
| 9604 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 9605 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 9606 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 9607 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 9608 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 9609 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 9610 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 9611 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9612 | } |
| 9613 | |
| 9614 | TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { |
| 9615 | // We rearrange layer list contributions if we have to visit children out of |
| 9616 | // order, but it should be a 'stable' rearrangement. That is, the layer list |
| 9617 | // additions for a single layer should not be reordered, though their position |
| 9618 | // wrt to the contributions due to a sibling may vary. |
| 9619 | // |
| 9620 | // + root |
| 9621 | // + scroll_child |
| 9622 | // + top_content |
| 9623 | // + bottom_content |
| 9624 | // + scroll_parent_border |
| 9625 | // + scroll_parent_clip |
| 9626 | // + scroll_parent |
| 9627 | // |
| 9628 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 9629 | TestSharedBitmapManager shared_bitmap_manager; |
| 9630 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9631 | host_impl.CreatePendingTree(); |
| 9632 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 9633 | scoped_ptr<LayerImpl> scroll_parent_border = |
| 9634 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9635 | scoped_ptr<LayerImpl> scroll_parent_clip = |
| 9636 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9637 | scoped_ptr<LayerImpl> scroll_parent = |
| 9638 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 9639 | scoped_ptr<LayerImpl> scroll_child = |
| 9640 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 9641 | scoped_ptr<LayerImpl> bottom_content = |
| 9642 | LayerImpl::Create(host_impl.active_tree(), 6); |
| 9643 | scoped_ptr<LayerImpl> top_content = |
| 9644 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 9645 | |
| 9646 | scroll_parent_clip->SetMasksToBounds(true); |
| 9647 | |
| 9648 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9649 | scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>); |
| 9650 | scroll_children->insert(scroll_child.get()); |
| 9651 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 9652 | |
| 9653 | scroll_child->SetDrawsContent(true); |
| 9654 | scroll_parent->SetDrawsContent(true); |
| 9655 | top_content->SetDrawsContent(true); |
| 9656 | bottom_content->SetDrawsContent(true); |
| 9657 | |
| 9658 | gfx::Transform identity_transform; |
| 9659 | gfx::Transform top_transform; |
| 9660 | top_transform.Translate3d(0.0, 0.0, 5.0); |
| 9661 | gfx::Transform bottom_transform; |
| 9662 | bottom_transform.Translate3d(0.0, 0.0, 3.0); |
| 9663 | |
| 9664 | SetLayerPropertiesForTesting(root.get(), |
| 9665 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9666 | gfx::PointF(), |
| 9667 | gfx::PointF(), |
| 9668 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9669 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9670 | false); |
| 9671 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 9672 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9673 | gfx::PointF(), |
| 9674 | gfx::PointF(), |
| 9675 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9676 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9677 | false); |
| 9678 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 9679 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9680 | gfx::PointF(), |
| 9681 | gfx::PointF(), |
| 9682 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9683 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9684 | false); |
| 9685 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 9686 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9687 | gfx::PointF(), |
| 9688 | gfx::PointF(), |
| 9689 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9690 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9691 | false); |
| 9692 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 9693 | identity_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9694 | gfx::PointF(), |
| 9695 | gfx::PointF(), |
| 9696 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9697 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9698 | false); |
| 9699 | SetLayerPropertiesForTesting(top_content.get(), |
| 9700 | top_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9701 | gfx::PointF(), |
| 9702 | gfx::PointF(), |
| 9703 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9704 | false, |
| 9705 | true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9706 | SetLayerPropertiesForTesting(bottom_content.get(), |
| 9707 | bottom_transform, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9708 | gfx::PointF(), |
| 9709 | gfx::PointF(), |
| 9710 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9711 | false, |
| 9712 | true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9713 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9714 | scroll_child->SetShouldFlattenTransform(false); |
| 9715 | scroll_child->SetIs3dSorted(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 9716 | |
| 9717 | scroll_child->AddChild(top_content.Pass()); |
| 9718 | scroll_child->AddChild(bottom_content.Pass()); |
| 9719 | root->AddChild(scroll_child.Pass()); |
| 9720 | |
| 9721 | scroll_parent_clip->AddChild(scroll_parent.Pass()); |
| 9722 | scroll_parent_border->AddChild(scroll_parent_clip.Pass()); |
| 9723 | root->AddChild(scroll_parent_border.Pass()); |
| 9724 | |
| 9725 | LayerImplList render_surface_layer_list; |
| 9726 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9727 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9728 | |
| 9729 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9730 | |
| 9731 | EXPECT_TRUE(root->render_surface()); |
| 9732 | |
| 9733 | // If we don't sort by depth and let the layers get added in the order they |
| 9734 | // would normally be visited in, then layers 6 and 7 will be out of order. In |
| 9735 | // other words, although we've had to shift 5, 6, and 7 to appear before 4 |
| 9736 | // in the list (because of the scroll parent relationship), this should not |
| 9737 | // have an effect on the the order of 5, 6, and 7 (which had been reordered |
| 9738 | // due to layer sorting). |
| 9739 | EXPECT_EQ(4u, root->render_surface()->layer_list().size()); |
| 9740 | EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id()); |
| 9741 | EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id()); |
| 9742 | EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id()); |
| 9743 | EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id()); |
| 9744 | } |
| 9745 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9746 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 9747 | // This test verifies that a scrolling layer that gets snapped to |
| 9748 | // integer coordinates doesn't move a fixed position child. |
| 9749 | // |
| 9750 | // + root |
| 9751 | // + container |
| 9752 | // + scroller |
| 9753 | // + fixed |
| 9754 | // |
| 9755 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 9756 | TestSharedBitmapManager shared_bitmap_manager; |
| 9757 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9758 | host_impl.CreatePendingTree(); |
| 9759 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 9760 | scoped_ptr<LayerImpl> container = |
| 9761 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 9762 | LayerImpl* container_layer = container.get(); |
| 9763 | scoped_ptr<LayerImpl> scroller = |
| 9764 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9765 | LayerImpl* scroll_layer = scroller.get(); |
| 9766 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 9767 | LayerImpl* fixed_layer = fixed.get(); |
| 9768 | |
| 9769 | container->SetIsContainerForFixedPositionLayers(true); |
| 9770 | |
| 9771 | LayerPositionConstraint constraint; |
| 9772 | constraint.set_is_fixed_position(true); |
| 9773 | fixed->SetPositionConstraint(constraint); |
| 9774 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 9775 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9776 | |
| 9777 | gfx::Transform identity_transform; |
| 9778 | gfx::Transform container_transform; |
| 9779 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 9780 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 9781 | |
| 9782 | SetLayerPropertiesForTesting(root.get(), |
| 9783 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9784 | gfx::PointF(), |
| 9785 | gfx::PointF(), |
| 9786 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9787 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9788 | false); |
| 9789 | SetLayerPropertiesForTesting(container.get(), |
| 9790 | container_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9791 | gfx::PointF(), |
| 9792 | gfx::PointF(), |
| 9793 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9794 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9795 | false); |
| 9796 | SetLayerPropertiesForTesting(scroller.get(), |
| 9797 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9798 | gfx::PointF(), |
| 9799 | gfx::PointF(), |
| 9800 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9801 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9802 | false); |
| 9803 | SetLayerPropertiesForTesting(fixed.get(), |
| 9804 | identity_transform, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9805 | gfx::PointF(), |
| 9806 | gfx::PointF(), |
| 9807 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 9808 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9809 | false); |
| 9810 | |
| 9811 | scroller->AddChild(fixed.Pass()); |
| 9812 | container->AddChild(scroller.Pass()); |
| 9813 | root->AddChild(container.Pass()); |
| 9814 | |
| 9815 | // Rounded to integers already. |
| 9816 | { |
| 9817 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 9818 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9819 | |
| 9820 | LayerImplList render_surface_layer_list; |
| 9821 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9822 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9823 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9824 | |
| 9825 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9826 | container_layer->draw_properties().screen_space_transform, |
| 9827 | fixed_layer->draw_properties().screen_space_transform); |
| 9828 | EXPECT_VECTOR_EQ( |
| 9829 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9830 | container_offset); |
| 9831 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 9832 | .screen_space_transform.To2dTranslation(), |
| 9833 | container_offset - scroll_delta); |
| 9834 | } |
| 9835 | |
| 9836 | // Scroll delta requiring rounding. |
| 9837 | { |
| 9838 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 9839 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9840 | |
| 9841 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 9842 | |
| 9843 | LayerImplList render_surface_layer_list; |
| 9844 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9845 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9846 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9847 | |
| 9848 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9849 | container_layer->draw_properties().screen_space_transform, |
| 9850 | fixed_layer->draw_properties().screen_space_transform); |
| 9851 | EXPECT_VECTOR_EQ( |
| 9852 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9853 | container_offset); |
| 9854 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 9855 | .screen_space_transform.To2dTranslation(), |
| 9856 | container_offset - rounded_scroll_delta); |
| 9857 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 9858 | |
| 9859 | // Scale is applied earlier in the tree. |
| 9860 | { |
| 9861 | gfx::Transform scaled_container_transform = container_transform; |
| 9862 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 9863 | container_layer->SetTransform(scaled_container_transform); |
| 9864 | |
| 9865 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 9866 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9867 | |
| 9868 | LayerImplList render_surface_layer_list; |
| 9869 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9870 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9871 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9872 | |
| 9873 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 9874 | container_layer->draw_properties().screen_space_transform, |
| 9875 | fixed_layer->draw_properties().screen_space_transform); |
| 9876 | EXPECT_VECTOR_EQ( |
| 9877 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9878 | container_offset); |
| 9879 | |
| 9880 | container_layer->SetTransform(container_transform); |
| 9881 | } |
| 9882 | |
| 9883 | // Scale is applied on the scroll layer itself. |
| 9884 | { |
| 9885 | gfx::Transform scale_transform; |
| 9886 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 9887 | scroll_layer->SetTransform(scale_transform); |
| 9888 | |
| 9889 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 9890 | scroll_layer->SetScrollDelta(scroll_delta); |
| 9891 | |
| 9892 | LayerImplList render_surface_layer_list; |
| 9893 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 9894 | root.get(), root->bounds(), &render_surface_layer_list); |
| 9895 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 9896 | |
| 9897 | EXPECT_VECTOR_EQ( |
| 9898 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 9899 | container_offset); |
| 9900 | |
| 9901 | scroll_layer->SetTransform(identity_transform); |
| 9902 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 9903 | } |
| 9904 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 9905 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 9906 | public: |
| 9907 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 9908 | LayerTreeImpl* tree_impl, |
| 9909 | int id) { |
| 9910 | return make_scoped_ptr( |
| 9911 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 9912 | } |
| 9913 | |
| 9914 | virtual ~AnimationScaleFactorTrackingLayerImpl() {} |
| 9915 | |
| 9916 | virtual void CalculateContentsScale(float ideal_contents_scale, |
| 9917 | float device_scale_factor, |
| 9918 | float page_scale_factor, |
| 9919 | float maximum_animation_contents_scale, |
| 9920 | bool animating_transform_to_screen, |
| 9921 | float* contents_scale_x, |
| 9922 | float* contents_scale_y, |
| 9923 | gfx::Size* content_bounds) OVERRIDE { |
| 9924 | last_maximum_animation_contents_scale_ = maximum_animation_contents_scale; |
| 9925 | LayerImpl::CalculateContentsScale(ideal_contents_scale, |
| 9926 | device_scale_factor, |
| 9927 | page_scale_factor, |
| 9928 | maximum_animation_contents_scale, |
| 9929 | animating_transform_to_screen, |
| 9930 | contents_scale_x, |
| 9931 | contents_scale_y, |
| 9932 | content_bounds); |
| 9933 | } |
| 9934 | |
| 9935 | float last_maximum_animation_contents_scale() { |
| 9936 | return last_maximum_animation_contents_scale_; |
| 9937 | } |
| 9938 | |
| 9939 | private: |
| 9940 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 9941 | int id) |
| 9942 | : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) { |
| 9943 | SetDrawsContent(true); |
| 9944 | } |
| 9945 | |
| 9946 | float last_maximum_animation_contents_scale_; |
| 9947 | }; |
| 9948 | |
| 9949 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 9950 | FakeImplProxy proxy; |
| 9951 | TestSharedBitmapManager shared_bitmap_manager; |
| 9952 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 9953 | gfx::Transform identity_matrix; |
| 9954 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 9955 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 9956 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 9957 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 9958 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 9959 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 9960 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 9961 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 9962 | |
| 9963 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 9964 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 9965 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 9966 | |
| 9967 | child->AddChild(grand_child.PassAs<LayerImpl>()); |
| 9968 | parent->AddChild(child.PassAs<LayerImpl>()); |
| 9969 | grand_parent->AddChild(parent.PassAs<LayerImpl>()); |
| 9970 | |
| 9971 | SetLayerPropertiesForTesting(grand_parent.get(), |
| 9972 | identity_matrix, |
| 9973 | gfx::PointF(), |
| 9974 | gfx::PointF(), |
| 9975 | gfx::Size(1, 2), |
| 9976 | true, |
| 9977 | false); |
| 9978 | SetLayerPropertiesForTesting(parent_raw, |
| 9979 | identity_matrix, |
| 9980 | gfx::PointF(), |
| 9981 | gfx::PointF(), |
| 9982 | gfx::Size(1, 2), |
| 9983 | true, |
| 9984 | false); |
| 9985 | SetLayerPropertiesForTesting(child_raw, |
| 9986 | identity_matrix, |
| 9987 | gfx::PointF(), |
| 9988 | gfx::PointF(), |
| 9989 | gfx::Size(1, 2), |
| 9990 | true, |
| 9991 | false); |
| 9992 | SetLayerPropertiesForTesting(grand_child_raw, |
| 9993 | identity_matrix, |
| 9994 | gfx::PointF(), |
| 9995 | gfx::PointF(), |
| 9996 | gfx::Size(1, 2), |
| 9997 | true, |
| 9998 | false); |
| 9999 | |
| 10000 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10001 | |
| 10002 | // No layers have animations. |
| 10003 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10004 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10005 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10006 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10007 | |
| 10008 | TransformOperations translation; |
| 10009 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 10010 | |
| 10011 | AddAnimatedTransformToLayer( |
| 10012 | parent_raw, 1.0, TransformOperations(), translation); |
| 10013 | |
| 10014 | // No layers have scale-affecting animations. |
| 10015 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10016 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10017 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10018 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10019 | |
| 10020 | TransformOperations scale; |
| 10021 | scale.AppendScale(5.f, 4.f, 3.f); |
| 10022 | |
| 10023 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 10024 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10025 | |
| 10026 | // Only |child| has a scale-affecting animation. |
| 10027 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10028 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10029 | EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale()); |
| 10030 | EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10031 | |
| 10032 | AddAnimatedTransformToLayer( |
| 10033 | grand_parent.get(), 1.0, TransformOperations(), scale); |
| 10034 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10035 | |
| 10036 | // |grand_parent| and |child| have scale-affecting animations. |
| 10037 | EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10038 | EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10039 | // We don't support combining animated scales from two nodes; 0.f means |
| 10040 | // that the maximum scale could not be computed. |
| 10041 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10042 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10043 | |
| 10044 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 10045 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10046 | |
| 10047 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
| 10048 | EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10049 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10050 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10051 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10052 | |
| 10053 | grand_parent->layer_animation_controller()->AbortAnimations( |
| 10054 | Animation::Transform); |
| 10055 | parent_raw->layer_animation_controller()->AbortAnimations( |
| 10056 | Animation::Transform); |
| 10057 | child_raw->layer_animation_controller()->AbortAnimations( |
| 10058 | Animation::Transform); |
| 10059 | |
| 10060 | TransformOperations perspective; |
| 10061 | perspective.AppendPerspective(10.f); |
| 10062 | |
| 10063 | AddAnimatedTransformToLayer( |
| 10064 | child_raw, 1.0, TransformOperations(), perspective); |
| 10065 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10066 | |
| 10067 | // |child| has a scale-affecting animation but computing the maximum of this |
| 10068 | // animation is not supported. |
| 10069 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10070 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10071 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10072 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10073 | |
| 10074 | child_raw->layer_animation_controller()->AbortAnimations( |
| 10075 | Animation::Transform); |
| 10076 | |
| 10077 | gfx::Transform scale_matrix; |
| 10078 | scale_matrix.Scale(1.f, 2.f); |
| 10079 | grand_parent->SetTransform(scale_matrix); |
| 10080 | parent_raw->SetTransform(scale_matrix); |
| 10081 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 10082 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10083 | |
| 10084 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 10085 | // animation with maximum scale 5.f. |
| 10086 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10087 | EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10088 | EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale()); |
| 10089 | EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10090 | |
| 10091 | gfx::Transform perspective_matrix; |
| 10092 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 10093 | child_raw->SetTransform(perspective_matrix); |
| 10094 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10095 | |
| 10096 | // |child| has a transform that's neither a translation nor a scale. |
| 10097 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10098 | EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10099 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10100 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10101 | |
| 10102 | parent_raw->SetTransform(perspective_matrix); |
| 10103 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10104 | |
| 10105 | // |parent| and |child| have transforms that are neither translations nor |
| 10106 | // scales. |
| 10107 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10108 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10109 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10110 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10111 | |
| 10112 | parent_raw->SetTransform(identity_matrix); |
| 10113 | child_raw->SetTransform(identity_matrix); |
| 10114 | grand_parent->SetTransform(perspective_matrix); |
| 10115 | |
| 10116 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10117 | |
| 10118 | // |grand_parent| has a transform that's neither a translation nor a scale. |
| 10119 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10120 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10121 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10122 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10123 | } |
| 10124 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 10125 | } // namespace |
| 10126 | } // namespace cc |