| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layer_tree_host_common.h" | 5 #include "cc/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include "cc/content_layer.h" | 7 #include "cc/content_layer.h" |
| 8 #include "cc/content_layer_client.h" | 8 #include "cc/content_layer_client.h" |
| 9 #include "cc/layer.h" | 9 #include "cc/layer.h" |
| 10 #include "cc/layer_animation_controller.h" | 10 #include "cc/layer_animation_controller.h" |
| (...skipping 2888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2899 // Verify root surface's layerList. | 2899 // Verify root surface's layerList. |
| 2900 ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size()
); | 2900 ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size()
); |
| 2901 EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[0]->renderSurface
()->layerList()[0]->id()); | 2901 EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[0]->renderSurface
()->layerList()[0]->id()); |
| 2902 | 2902 |
| 2903 // Verify frontFacingSurface's layerList. | 2903 // Verify frontFacingSurface's layerList. |
| 2904 ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size()
); | 2904 ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size()
); |
| 2905 EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->renderSurface
()->layerList()[0]->id()); | 2905 EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->renderSurface
()->layerList()[0]->id()); |
| 2906 EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerLis
t()[1]->id()); | 2906 EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerLis
t()[1]->id()); |
| 2907 } | 2907 } |
| 2908 | 2908 |
| 2909 TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList) | |
| 2910 { | |
| 2911 // Hit testing on an empty renderSurfaceLayerList should return a null point
er. | |
| 2912 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 2913 | |
| 2914 gfx::Point testPoint(0, 0); | |
| 2915 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 2916 EXPECT_FALSE(resultLayer); | |
| 2917 | |
| 2918 testPoint = gfx::Point(10, 20); | |
| 2919 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 2920 EXPECT_FALSE(resultLayer); | |
| 2921 } | |
| 2922 | |
| 2923 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer) | |
| 2924 { | |
| 2925 FakeImplProxy proxy; | |
| 2926 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 2927 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; | |
| 2928 | |
| 2929 gfx::Transform identityMatrix; | |
| 2930 gfx::PointF anchor(0, 0); | |
| 2931 gfx::PointF position(0, 0); | |
| 2932 gfx::Size bounds(100, 100); | |
| 2933 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, position, bounds, false); | |
| 2934 root->setDrawsContent(true); | |
| 2935 | |
| 2936 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 2937 int dummyMaxTextureSize = 512; | |
| 2938 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 2939 | |
| 2940 // Sanity check the scenario we just created. | |
| 2941 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 2942 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 2943 | |
| 2944 // Hit testing for a point outside the layer should return a null pointer. | |
| 2945 gfx::Point testPoint(101, 101); | |
| 2946 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 2947 EXPECT_FALSE(resultLayer); | |
| 2948 | |
| 2949 testPoint = gfx::Point(-1, -1); | |
| 2950 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 2951 EXPECT_FALSE(resultLayer); | |
| 2952 | |
| 2953 // Hit testing for a point inside should return the root layer. | |
| 2954 testPoint = gfx::Point(1, 1); | |
| 2955 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 2956 ASSERT_TRUE(resultLayer); | |
| 2957 EXPECT_EQ(12345, resultLayer->id()); | |
| 2958 | |
| 2959 testPoint = gfx::Point(99, 99); | |
| 2960 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 2961 ASSERT_TRUE(resultLayer); | |
| 2962 EXPECT_EQ(12345, resultLayer->id()); | |
| 2963 } | |
| 2964 | |
| 2965 TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform) | |
| 2966 { | |
| 2967 FakeImplProxy proxy; | |
| 2968 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 2969 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; | |
| 2970 | |
| 2971 gfx::Transform uninvertibleTransform; | |
| 2972 uninvertibleTransform.matrix().setDouble(0, 0, 0); | |
| 2973 uninvertibleTransform.matrix().setDouble(1, 1, 0); | |
| 2974 uninvertibleTransform.matrix().setDouble(2, 2, 0); | |
| 2975 uninvertibleTransform.matrix().setDouble(3, 3, 0); | |
| 2976 ASSERT_FALSE(uninvertibleTransform.IsInvertible()); | |
| 2977 | |
| 2978 gfx::Transform identityMatrix; | |
| 2979 gfx::PointF anchor(0, 0); | |
| 2980 gfx::PointF position(0, 0); | |
| 2981 gfx::Size bounds(100, 100); | |
| 2982 setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatr
ix, anchor, position, bounds, false); | |
| 2983 root->setDrawsContent(true); | |
| 2984 | |
| 2985 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 2986 int dummyMaxTextureSize = 512; | |
| 2987 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 2988 | |
| 2989 // Sanity check the scenario we just created. | |
| 2990 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 2991 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 2992 ASSERT_FALSE(root->screenSpaceTransform().IsInvertible()); | |
| 2993 | |
| 2994 // Hit testing any point should not hit the layer. If the invertible matrix
is | |
| 2995 // accidentally ignored and treated like an identity, then the hit testing w
ill | |
| 2996 // incorrectly hit the layer when it shouldn't. | |
| 2997 gfx::Point testPoint(1, 1); | |
| 2998 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 2999 EXPECT_FALSE(resultLayer); | |
| 3000 | |
| 3001 testPoint = gfx::Point(10, 10); | |
| 3002 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3003 EXPECT_FALSE(resultLayer); | |
| 3004 | |
| 3005 testPoint = gfx::Point(10, 30); | |
| 3006 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3007 EXPECT_FALSE(resultLayer); | |
| 3008 | |
| 3009 testPoint = gfx::Point(50, 50); | |
| 3010 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3011 EXPECT_FALSE(resultLayer); | |
| 3012 | |
| 3013 testPoint = gfx::Point(67, 48); | |
| 3014 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3015 EXPECT_FALSE(resultLayer); | |
| 3016 | |
| 3017 testPoint = gfx::Point(99, 99); | |
| 3018 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3019 EXPECT_FALSE(resultLayer); | |
| 3020 | |
| 3021 testPoint = gfx::Point(-1, -1); | |
| 3022 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3023 EXPECT_FALSE(resultLayer); | |
| 3024 } | |
| 3025 | |
| 3026 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer) | |
| 3027 { | |
| 3028 FakeImplProxy proxy; | |
| 3029 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3030 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; | |
| 3031 | |
| 3032 gfx::Transform identityMatrix; | |
| 3033 gfx::PointF anchor(0, 0); | |
| 3034 gfx::PointF position(50, 50); // this layer is positioned, and hit testing s
hould correctly know where the layer is located. | |
| 3035 gfx::Size bounds(100, 100); | |
| 3036 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, position, bounds, false); | |
| 3037 root->setDrawsContent(true); | |
| 3038 | |
| 3039 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3040 int dummyMaxTextureSize = 512; | |
| 3041 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3042 | |
| 3043 // Sanity check the scenario we just created. | |
| 3044 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3045 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3046 | |
| 3047 // Hit testing for a point outside the layer should return a null pointer. | |
| 3048 gfx::Point testPoint(49, 49); | |
| 3049 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3050 EXPECT_FALSE(resultLayer); | |
| 3051 | |
| 3052 // Even though the layer exists at (101, 101), it should not be visible ther
e since the root renderSurface would clamp it. | |
| 3053 testPoint = gfx::Point(101, 101); | |
| 3054 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3055 EXPECT_FALSE(resultLayer); | |
| 3056 | |
| 3057 // Hit testing for a point inside should return the root layer. | |
| 3058 testPoint = gfx::Point(51, 51); | |
| 3059 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3060 ASSERT_TRUE(resultLayer); | |
| 3061 EXPECT_EQ(12345, resultLayer->id()); | |
| 3062 | |
| 3063 testPoint = gfx::Point(99, 99); | |
| 3064 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3065 ASSERT_TRUE(resultLayer); | |
| 3066 EXPECT_EQ(12345, resultLayer->id()); | |
| 3067 } | |
| 3068 | |
| 3069 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) | |
| 3070 { | |
| 3071 FakeImplProxy proxy; | |
| 3072 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3073 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; | |
| 3074 | |
| 3075 gfx::Transform identityMatrix; | |
| 3076 gfx::Transform rotation45DegreesAboutCenter; | |
| 3077 rotation45DegreesAboutCenter.Translate(50, 50); | |
| 3078 rotation45DegreesAboutCenter.RotateAboutZAxis(45); | |
| 3079 rotation45DegreesAboutCenter.Translate(-50, -50); | |
| 3080 gfx::PointF anchor(0, 0); | |
| 3081 gfx::PointF position(0, 0); | |
| 3082 gfx::Size bounds(100, 100); | |
| 3083 setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, ident
ityMatrix, anchor, position, bounds, false); | |
| 3084 root->setDrawsContent(true); | |
| 3085 | |
| 3086 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3087 int dummyMaxTextureSize = 512; | |
| 3088 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3089 | |
| 3090 // Sanity check the scenario we just created. | |
| 3091 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3092 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3093 | |
| 3094 // Hit testing for points outside the layer. | |
| 3095 // These corners would have been inside the un-transformed layer, but they s
hould not hit the correctly transformed layer. | |
| 3096 gfx::Point testPoint(99, 99); | |
| 3097 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3098 EXPECT_FALSE(resultLayer); | |
| 3099 | |
| 3100 testPoint = gfx::Point(1, 1); | |
| 3101 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3102 EXPECT_FALSE(resultLayer); | |
| 3103 | |
| 3104 // Hit testing for a point inside should return the root layer. | |
| 3105 testPoint = gfx::Point(1, 50); | |
| 3106 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3107 ASSERT_TRUE(resultLayer); | |
| 3108 EXPECT_EQ(12345, resultLayer->id()); | |
| 3109 | |
| 3110 // Hit testing the corners that would overlap the unclipped layer, but are o
utside the clipped region. | |
| 3111 testPoint = gfx::Point(50, -1); | |
| 3112 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3113 ASSERT_FALSE(resultLayer); | |
| 3114 | |
| 3115 testPoint = gfx::Point(-1, 50); | |
| 3116 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3117 ASSERT_FALSE(resultLayer); | |
| 3118 } | |
| 3119 | |
| 3120 TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer) | |
| 3121 { | |
| 3122 FakeImplProxy proxy; | |
| 3123 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3124 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345)
; | |
| 3125 | |
| 3126 gfx::Transform identityMatrix; | |
| 3127 | |
| 3128 // perspectiveProjectionAboutCenter * translationByZ is designed so that the
100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). | |
| 3129 gfx::Transform perspectiveProjectionAboutCenter; | |
| 3130 perspectiveProjectionAboutCenter.Translate(50, 50); | |
| 3131 perspectiveProjectionAboutCenter.ApplyPerspectiveDepth(1); | |
| 3132 perspectiveProjectionAboutCenter.Translate(-50, -50); | |
| 3133 gfx::Transform translationByZ; | |
| 3134 translationByZ.Translate3d(0, 0, -1); | |
| 3135 | |
| 3136 gfx::PointF anchor(0, 0); | |
| 3137 gfx::PointF position(0, 0); | |
| 3138 gfx::Size bounds(100, 100); | |
| 3139 setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter *
translationByZ, identityMatrix, anchor, position, bounds, false); | |
| 3140 root->setDrawsContent(true); | |
| 3141 | |
| 3142 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3143 int dummyMaxTextureSize = 512; | |
| 3144 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3145 | |
| 3146 // Sanity check the scenario we just created. | |
| 3147 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3148 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3149 | |
| 3150 // Hit testing for points outside the layer. | |
| 3151 // These corners would have been inside the un-transformed layer, but they s
hould not hit the correctly transformed layer. | |
| 3152 gfx::Point testPoint(24, 24); | |
| 3153 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3154 EXPECT_FALSE(resultLayer); | |
| 3155 | |
| 3156 testPoint = gfx::Point(76, 76); | |
| 3157 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3158 EXPECT_FALSE(resultLayer); | |
| 3159 | |
| 3160 // Hit testing for a point inside should return the root layer. | |
| 3161 testPoint = gfx::Point(26, 26); | |
| 3162 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3163 ASSERT_TRUE(resultLayer); | |
| 3164 EXPECT_EQ(12345, resultLayer->id()); | |
| 3165 | |
| 3166 testPoint = gfx::Point(74, 74); | |
| 3167 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3168 ASSERT_TRUE(resultLayer); | |
| 3169 EXPECT_EQ(12345, resultLayer->id()); | |
| 3170 } | |
| 3171 | |
| 3172 TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents) | |
| 3173 { | |
| 3174 // A layer's visibleContentRect is actually in the layer's content space. Th
e | |
| 3175 // screenSpaceTransform converts from the layer's origin space to screen spa
ce. This | |
| 3176 // test makes sure that hit testing works correctly accounts for the content
s scale. | |
| 3177 // A contentsScale that is not 1 effectively forces a non-identity transform
between | |
| 3178 // layer's content space and layer's origin space. The hit testing code must
take this into account. | |
| 3179 // | |
| 3180 // To test this, the layer is positioned at (25, 25), and is size (50, 50).
If | |
| 3181 // contentsScale is ignored, then hit testing will mis-interpret the visible
ContentRect | |
| 3182 // as being larger than the actual bounds of the layer. | |
| 3183 // | |
| 3184 FakeImplProxy proxy; | |
| 3185 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3186 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1); | |
| 3187 | |
| 3188 gfx::Transform identityMatrix; | |
| 3189 gfx::PointF anchor(0, 0); | |
| 3190 | |
| 3191 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); | |
| 3192 | |
| 3193 { | |
| 3194 gfx::PointF position(25, 25); | |
| 3195 gfx::Size bounds(50, 50); | |
| 3196 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(hostImpl.activeTree(
), 12345); | |
| 3197 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa
trix, anchor, position, bounds, false); | |
| 3198 | |
| 3199 // override contentBounds and contentsScale | |
| 3200 testLayer->setContentBounds(gfx::Size(100, 100)); | |
| 3201 testLayer->setContentsScale(2, 2); | |
| 3202 | |
| 3203 testLayer->setDrawsContent(true); | |
| 3204 root->addChild(testLayer.Pass()); | |
| 3205 } | |
| 3206 | |
| 3207 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3208 int dummyMaxTextureSize = 512; | |
| 3209 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3210 | |
| 3211 // Sanity check the scenario we just created. | |
| 3212 // The visibleContentRect for testLayer is actually 100x100, even though its
layout size is 50x50, positioned at 25x25. | |
| 3213 LayerImpl* testLayer = root->children()[0]; | |
| 3214 EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), testLayer->visi
bleContentRect()); | |
| 3215 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3216 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3217 | |
| 3218 // Hit testing for a point outside the layer should return a null pointer (t
he root layer does not draw content, so it will not be hit tested either). | |
| 3219 gfx::Point testPoint(101, 101); | |
| 3220 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3221 EXPECT_FALSE(resultLayer); | |
| 3222 | |
| 3223 testPoint = gfx::Point(24, 24); | |
| 3224 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3225 EXPECT_FALSE(resultLayer); | |
| 3226 | |
| 3227 testPoint = gfx::Point(76, 76); | |
| 3228 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3229 EXPECT_FALSE(resultLayer); | |
| 3230 | |
| 3231 // Hit testing for a point inside should return the test layer. | |
| 3232 testPoint = gfx::Point(26, 26); | |
| 3233 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3234 ASSERT_TRUE(resultLayer); | |
| 3235 EXPECT_EQ(12345, resultLayer->id()); | |
| 3236 | |
| 3237 testPoint = gfx::Point(74, 74); | |
| 3238 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3239 ASSERT_TRUE(resultLayer); | |
| 3240 EXPECT_EQ(12345, resultLayer->id()); | |
| 3241 } | |
| 3242 | |
| 3243 TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer) | |
| 3244 { | |
| 3245 // Test that hit-testing will only work for the visible portion of a layer,
and not | |
| 3246 // the entire layer bounds. Here we just test the simple axis-aligned case. | |
| 3247 gfx::Transform identityMatrix; | |
| 3248 gfx::PointF anchor(0, 0); | |
| 3249 | |
| 3250 FakeImplProxy proxy; | |
| 3251 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3252 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1); | |
| 3253 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); | |
| 3254 | |
| 3255 { | |
| 3256 scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(hostImpl.activeT
ree(), 123); | |
| 3257 gfx::PointF position(25, 25); // this layer is positioned, and hit testi
ng should correctly know where the layer is located. | |
| 3258 gfx::Size bounds(50, 50); | |
| 3259 setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identi
tyMatrix, anchor, position, bounds, false); | |
| 3260 clippingLayer->setMasksToBounds(true); | |
| 3261 | |
| 3262 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4
56); | |
| 3263 position = gfx::PointF(-50, -50); | |
| 3264 bounds = gfx::Size(300, 300); | |
| 3265 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix
, anchor, position, bounds, false); | |
| 3266 child->setDrawsContent(true); | |
| 3267 clippingLayer->addChild(child.Pass()); | |
| 3268 root->addChild(clippingLayer.Pass()); | |
| 3269 } | |
| 3270 | |
| 3271 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3272 int dummyMaxTextureSize = 512; | |
| 3273 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3274 | |
| 3275 // Sanity check the scenario we just created. | |
| 3276 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3277 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3278 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id()); | |
| 3279 | |
| 3280 // Hit testing for a point outside the layer should return a null pointer. | |
| 3281 // Despite the child layer being very large, it should be clipped to the roo
t layer's bounds. | |
| 3282 gfx::Point testPoint(24, 24); | |
| 3283 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3284 EXPECT_FALSE(resultLayer); | |
| 3285 | |
| 3286 // Even though the layer exists at (101, 101), it should not be visible ther
e since the clippingLayer would clamp it. | |
| 3287 testPoint = gfx::Point(76, 76); | |
| 3288 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3289 EXPECT_FALSE(resultLayer); | |
| 3290 | |
| 3291 // Hit testing for a point inside should return the child layer. | |
| 3292 testPoint = gfx::Point(26, 26); | |
| 3293 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3294 ASSERT_TRUE(resultLayer); | |
| 3295 EXPECT_EQ(456, resultLayer->id()); | |
| 3296 | |
| 3297 testPoint = gfx::Point(74, 74); | |
| 3298 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3299 ASSERT_TRUE(resultLayer); | |
| 3300 EXPECT_EQ(456, resultLayer->id()); | |
| 3301 } | |
| 3302 | |
| 3303 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer) | |
| 3304 { | |
| 3305 // This test checks whether hit testing correctly avoids hit testing with mu
ltiple | |
| 3306 // ancestors that clip in non axis-aligned ways. To pass this test, the hit
testing | |
| 3307 // algorithm needs to recognize that multiple parent layers may clip the lay
er, and | |
| 3308 // should not actually hit those clipped areas. | |
| 3309 // | |
| 3310 // The child and grandChild layers are both initialized to clip the rotatedL
eaf. The | |
| 3311 // child layer is rotated about the top-left corner, so that the root + chil
d clips | |
| 3312 // combined create a triangle. The rotatedLeaf will only be visible where it
overlaps | |
| 3313 // this triangle. | |
| 3314 // | |
| 3315 FakeImplProxy proxy; | |
| 3316 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3317 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 123); | |
| 3318 | |
| 3319 gfx::Transform identityMatrix; | |
| 3320 gfx::PointF anchor(0, 0); | |
| 3321 gfx::PointF position(0, 0); | |
| 3322 gfx::Size bounds(100, 100); | |
| 3323 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, position, bounds, false); | |
| 3324 root->setMasksToBounds(true); | |
| 3325 | |
| 3326 { | |
| 3327 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4
56); | |
| 3328 scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl.activeTree
(), 789); | |
| 3329 scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(hostImpl.activeTre
e(), 2468); | |
| 3330 | |
| 3331 position = gfx::PointF(10, 10); | |
| 3332 bounds = gfx::Size(80, 80); | |
| 3333 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix
, anchor, position, bounds, false); | |
| 3334 child->setMasksToBounds(true); | |
| 3335 | |
| 3336 gfx::Transform rotation45DegreesAboutCorner; | |
| 3337 rotation45DegreesAboutCorner.RotateAboutZAxis(45); | |
| 3338 | |
| 3339 position = gfx::PointF(0, 0); // remember, positioned with respect to it
s parent which is already at 10, 10 | |
| 3340 bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) *
100. | |
| 3341 setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCor
ner, identityMatrix, anchor, position, bounds, false); | |
| 3342 grandChild->setMasksToBounds(true); | |
| 3343 | |
| 3344 // Rotates about the center of the layer | |
| 3345 gfx::Transform rotatedLeafTransform; | |
| 3346 rotatedLeafTransform.Translate(-10, -10); // cancel out the grandParent'
s position | |
| 3347 rotatedLeafTransform.RotateAboutZAxis(-45); // cancel out the corner 45-
degree rotation of the parent. | |
| 3348 rotatedLeafTransform.Translate(50, 50); | |
| 3349 rotatedLeafTransform.RotateAboutZAxis(45); | |
| 3350 rotatedLeafTransform.Translate(-50, -50); | |
| 3351 position = gfx::PointF(0, 0); | |
| 3352 bounds = gfx::Size(100, 100); | |
| 3353 setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, id
entityMatrix, anchor, position, bounds, false); | |
| 3354 rotatedLeaf->setDrawsContent(true); | |
| 3355 | |
| 3356 grandChild->addChild(rotatedLeaf.Pass()); | |
| 3357 child->addChild(grandChild.Pass()); | |
| 3358 root->addChild(child.Pass()); | |
| 3359 } | |
| 3360 | |
| 3361 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3362 int dummyMaxTextureSize = 512; | |
| 3363 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3364 | |
| 3365 // Sanity check the scenario we just created. | |
| 3366 // The grandChild is expected to create a renderSurface because it masksToBo
unds and is not axis aligned. | |
| 3367 ASSERT_EQ(2u, renderSurfaceLayerList.size()); | |
| 3368 ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size()
); | |
| 3369 ASSERT_EQ(789, renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->i
d()); // grandChild's surface. | |
| 3370 ASSERT_EQ(1u, renderSurfaceLayerList[1]->renderSurface()->layerList().size()
); | |
| 3371 ASSERT_EQ(2468, renderSurfaceLayerList[1]->renderSurface()->layerList()[0]->
id()); | |
| 3372 | |
| 3373 // (11, 89) is close to the the bottom left corner within the clip, but it i
s not inside the layer. | |
| 3374 gfx::Point testPoint(11, 89); | |
| 3375 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3376 EXPECT_FALSE(resultLayer); | |
| 3377 | |
| 3378 // Closer inwards from the bottom left will overlap the layer. | |
| 3379 testPoint = gfx::Point(25, 75); | |
| 3380 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3381 ASSERT_TRUE(resultLayer); | |
| 3382 EXPECT_EQ(2468, resultLayer->id()); | |
| 3383 | |
| 3384 // (4, 50) is inside the unclipped layer, but that corner of the layer shoul
d be | |
| 3385 // clipped away by the grandParent and should not get hit. If hit testing bl
indly uses | |
| 3386 // visibleContentRect without considering how parent may clip the layer, the
n hit | |
| 3387 // testing would accidentally think that the point successfully hits the lay
er. | |
| 3388 testPoint = gfx::Point(4, 50); | |
| 3389 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3390 EXPECT_FALSE(resultLayer); | |
| 3391 | |
| 3392 // (11, 50) is inside the layer and within the clipped area. | |
| 3393 testPoint = gfx::Point(11, 50); | |
| 3394 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3395 ASSERT_TRUE(resultLayer); | |
| 3396 EXPECT_EQ(2468, resultLayer->id()); | |
| 3397 | |
| 3398 // Around the middle, just to the right and up, would have hit the layer exc
ept that | |
| 3399 // that area should be clipped away by the parent. | |
| 3400 testPoint = gfx::Point(51, 51); | |
| 3401 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3402 EXPECT_FALSE(resultLayer); | |
| 3403 | |
| 3404 // Around the middle, just to the left and down, should successfully hit the
layer. | |
| 3405 testPoint = gfx::Point(49, 51); | |
| 3406 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3407 ASSERT_TRUE(resultLayer); | |
| 3408 EXPECT_EQ(2468, resultLayer->id()); | |
| 3409 } | |
| 3410 | |
| 3411 TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) | |
| 3412 { | |
| 3413 // This test checks that hit testing code does not accidentally clip to laye
r | |
| 3414 // bounds for a layer that actually does not clip. | |
| 3415 gfx::Transform identityMatrix; | |
| 3416 gfx::PointF anchor(0, 0); | |
| 3417 | |
| 3418 FakeImplProxy proxy; | |
| 3419 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3420 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1); | |
| 3421 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, gfx::PointF(0, 0), gfx::Size(100, 100), false); | |
| 3422 | |
| 3423 { | |
| 3424 scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(hostImpl.act
iveTree(), 123); | |
| 3425 gfx::PointF position(10, 10); // this layer is positioned, and hit testi
ng should correctly know where the layer is located. | |
| 3426 gfx::Size bounds(50, 50); | |
| 3427 setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, id
entityMatrix, anchor, position, bounds, false); | |
| 3428 // Sanity check the intermediate layer should not clip. | |
| 3429 ASSERT_FALSE(intermediateLayer->masksToBounds()); | |
| 3430 ASSERT_FALSE(intermediateLayer->maskLayer()); | |
| 3431 | |
| 3432 // The child of the intermediateLayer is translated so that it does not
overlap intermediateLayer at all. | |
| 3433 // If child is incorrectly clipped, we would not be able to hit it succe
ssfully. | |
| 3434 scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 4
56); | |
| 3435 position = gfx::PointF(60, 60); // 70, 70 in screen space | |
| 3436 bounds = gfx::Size(20, 20); | |
| 3437 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix
, anchor, position, bounds, false); | |
| 3438 child->setDrawsContent(true); | |
| 3439 intermediateLayer->addChild(child.Pass()); | |
| 3440 root->addChild(intermediateLayer.Pass()); | |
| 3441 } | |
| 3442 | |
| 3443 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3444 int dummyMaxTextureSize = 512; | |
| 3445 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3446 | |
| 3447 // Sanity check the scenario we just created. | |
| 3448 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3449 ASSERT_EQ(1u, root->renderSurface()->layerList().size()); | |
| 3450 ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id()); | |
| 3451 | |
| 3452 // Hit testing for a point outside the layer should return a null pointer. | |
| 3453 gfx::Point testPoint(69, 69); | |
| 3454 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3455 EXPECT_FALSE(resultLayer); | |
| 3456 | |
| 3457 testPoint = gfx::Point(91, 91); | |
| 3458 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3459 EXPECT_FALSE(resultLayer); | |
| 3460 | |
| 3461 // Hit testing for a point inside should return the child layer. | |
| 3462 testPoint = gfx::Point(71, 71); | |
| 3463 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3464 ASSERT_TRUE(resultLayer); | |
| 3465 EXPECT_EQ(456, resultLayer->id()); | |
| 3466 | |
| 3467 testPoint = gfx::Point(89, 89); | |
| 3468 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3469 ASSERT_TRUE(resultLayer); | |
| 3470 EXPECT_EQ(456, resultLayer->id()); | |
| 3471 } | |
| 3472 | |
| 3473 | |
| 3474 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers) | |
| 3475 { | |
| 3476 FakeImplProxy proxy; | |
| 3477 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3478 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1); | |
| 3479 | |
| 3480 gfx::Transform identityMatrix; | |
| 3481 gfx::PointF anchor(0, 0); | |
| 3482 gfx::PointF position(0, 0); | |
| 3483 gfx::Size bounds(100, 100); | |
| 3484 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, position, bounds, false); | |
| 3485 root->setDrawsContent(true); | |
| 3486 | |
| 3487 { | |
| 3488 // child 1 and child2 are initialized to overlap between x=50 and x=60. | |
| 3489 // grandChild is set to overlap both child1 and child2 between y=50 and
y=60. | |
| 3490 // The expected stacking order is: | |
| 3491 // (front) child2, (second) grandChild, (third) child1, and (back) the
root layer behind all other layers. | |
| 3492 | |
| 3493 scoped_ptr<LayerImpl> child1 = LayerImpl::create(hostImpl.activeTree(),
2); | |
| 3494 scoped_ptr<LayerImpl> child2 = LayerImpl::create(hostImpl.activeTree(),
3); | |
| 3495 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(hostImpl.activeTre
e(), 4); | |
| 3496 | |
| 3497 position = gfx::PointF(10, 10); | |
| 3498 bounds = gfx::Size(50, 50); | |
| 3499 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri
x, anchor, position, bounds, false); | |
| 3500 child1->setDrawsContent(true); | |
| 3501 | |
| 3502 position = gfx::PointF(50, 10); | |
| 3503 bounds = gfx::Size(50, 50); | |
| 3504 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri
x, anchor, position, bounds, false); | |
| 3505 child2->setDrawsContent(true); | |
| 3506 | |
| 3507 // Remember that grandChild is positioned with respect to its parent (i.
e. child1). | |
| 3508 // In screen space, the intended position is (10, 50), with size 100 x 5
0. | |
| 3509 position = gfx::PointF(0, 40); | |
| 3510 bounds = gfx::Size(100, 50); | |
| 3511 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity
Matrix, anchor, position, bounds, false); | |
| 3512 grandChild1->setDrawsContent(true); | |
| 3513 | |
| 3514 child1->addChild(grandChild1.Pass()); | |
| 3515 root->addChild(child1.Pass()); | |
| 3516 root->addChild(child2.Pass()); | |
| 3517 } | |
| 3518 | |
| 3519 LayerImpl* child1 = root->children()[0]; | |
| 3520 LayerImpl* child2 = root->children()[1]; | |
| 3521 LayerImpl* grandChild1 = child1->children()[0]; | |
| 3522 | |
| 3523 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3524 int dummyMaxTextureSize = 512; | |
| 3525 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3526 | |
| 3527 // Sanity check the scenario we just created. | |
| 3528 ASSERT_TRUE(child1); | |
| 3529 ASSERT_TRUE(child2); | |
| 3530 ASSERT_TRUE(grandChild1); | |
| 3531 ASSERT_EQ(1u, renderSurfaceLayerList.size()); | |
| 3532 ASSERT_EQ(4u, root->renderSurface()->layerList().size()); | |
| 3533 ASSERT_EQ(1, root->renderSurface()->layerList()[0]->id()); // root layer | |
| 3534 ASSERT_EQ(2, root->renderSurface()->layerList()[1]->id()); // child1 | |
| 3535 ASSERT_EQ(4, root->renderSurface()->layerList()[2]->id()); // grandChild1 | |
| 3536 ASSERT_EQ(3, root->renderSurface()->layerList()[3]->id()); // child2 | |
| 3537 | |
| 3538 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin
d the root layer. | |
| 3539 gfx::Point testPoint = gfx::Point(1, 1); | |
| 3540 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3541 ASSERT_TRUE(resultLayer); | |
| 3542 EXPECT_EQ(1, resultLayer->id()); | |
| 3543 | |
| 3544 // At (15, 15), child1 and root are the only layers. child1 is expected to b
e on top. | |
| 3545 testPoint = gfx::Point(15, 15); | |
| 3546 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3547 ASSERT_TRUE(resultLayer); | |
| 3548 EXPECT_EQ(2, resultLayer->id()); | |
| 3549 | |
| 3550 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. | |
| 3551 testPoint = gfx::Point(51, 20); | |
| 3552 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3553 ASSERT_TRUE(resultLayer); | |
| 3554 EXPECT_EQ(3, resultLayer->id()); | |
| 3555 | |
| 3556 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on
top. | |
| 3557 testPoint = gfx::Point(80, 51); | |
| 3558 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3559 ASSERT_TRUE(resultLayer); | |
| 3560 EXPECT_EQ(3, resultLayer->id()); | |
| 3561 | |
| 3562 // At (51, 51), all layers overlap each other. child2 is expected to be on t
op of all other layers. | |
| 3563 testPoint = gfx::Point(51, 51); | |
| 3564 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3565 ASSERT_TRUE(resultLayer); | |
| 3566 EXPECT_EQ(3, resultLayer->id()); | |
| 3567 | |
| 3568 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b
e on top. | |
| 3569 testPoint = gfx::Point(20, 51); | |
| 3570 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3571 ASSERT_TRUE(resultLayer); | |
| 3572 EXPECT_EQ(4, resultLayer->id()); | |
| 3573 } | |
| 3574 | |
| 3575 TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists) | |
| 3576 { | |
| 3577 // | |
| 3578 // The geometry is set up similarly to the previous case, but | |
| 3579 // all layers are forced to be renderSurfaces now. | |
| 3580 // | |
| 3581 FakeImplProxy proxy; | |
| 3582 FakeLayerTreeHostImpl hostImpl(&proxy); | |
| 3583 scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1); | |
| 3584 | |
| 3585 gfx::Transform identityMatrix; | |
| 3586 gfx::PointF anchor(0, 0); | |
| 3587 gfx::PointF position(0, 0); | |
| 3588 gfx::Size bounds(100, 100); | |
| 3589 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, position, bounds, false); | |
| 3590 root->setDrawsContent(true); | |
| 3591 | |
| 3592 { | |
| 3593 // child 1 and child2 are initialized to overlap between x=50 and x=60. | |
| 3594 // grandChild is set to overlap both child1 and child2 between y=50 and
y=60. | |
| 3595 // The expected stacking order is: | |
| 3596 // (front) child2, (second) grandChild, (third) child1, and (back) the
root layer behind all other layers. | |
| 3597 | |
| 3598 scoped_ptr<LayerImpl> child1 = LayerImpl::create(hostImpl.activeTree(),
2); | |
| 3599 scoped_ptr<LayerImpl> child2 = LayerImpl::create(hostImpl.activeTree(),
3); | |
| 3600 scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(hostImpl.activeTre
e(), 4); | |
| 3601 | |
| 3602 position = gfx::PointF(10, 10); | |
| 3603 bounds = gfx::Size(50, 50); | |
| 3604 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatri
x, anchor, position, bounds, false); | |
| 3605 child1->setDrawsContent(true); | |
| 3606 child1->setForceRenderSurface(true); | |
| 3607 | |
| 3608 position = gfx::PointF(50, 10); | |
| 3609 bounds = gfx::Size(50, 50); | |
| 3610 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatri
x, anchor, position, bounds, false); | |
| 3611 child2->setDrawsContent(true); | |
| 3612 child2->setForceRenderSurface(true); | |
| 3613 | |
| 3614 // Remember that grandChild is positioned with respect to its parent (i.
e. child1). | |
| 3615 // In screen space, the intended position is (10, 50), with size 100 x 5
0. | |
| 3616 position = gfx::PointF(0, 40); | |
| 3617 bounds = gfx::Size(100, 50); | |
| 3618 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identity
Matrix, anchor, position, bounds, false); | |
| 3619 grandChild1->setDrawsContent(true); | |
| 3620 grandChild1->setForceRenderSurface(true); | |
| 3621 | |
| 3622 child1->addChild(grandChild1.Pass()); | |
| 3623 root->addChild(child1.Pass()); | |
| 3624 root->addChild(child2.Pass()); | |
| 3625 } | |
| 3626 | |
| 3627 LayerImpl* child1 = root->children()[0]; | |
| 3628 LayerImpl* child2 = root->children()[1]; | |
| 3629 LayerImpl* grandChild1 = child1->children()[0]; | |
| 3630 | |
| 3631 std::vector<LayerImpl*> renderSurfaceLayerList; | |
| 3632 int dummyMaxTextureSize = 512; | |
| 3633 LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1,
1, dummyMaxTextureSize, false, renderSurfaceLayerList, false); | |
| 3634 | |
| 3635 // Sanity check the scenario we just created. | |
| 3636 ASSERT_TRUE(child1); | |
| 3637 ASSERT_TRUE(child2); | |
| 3638 ASSERT_TRUE(grandChild1); | |
| 3639 ASSERT_TRUE(child1->renderSurface()); | |
| 3640 ASSERT_TRUE(child2->renderSurface()); | |
| 3641 ASSERT_TRUE(grandChild1->renderSurface()); | |
| 3642 ASSERT_EQ(4u, renderSurfaceLayerList.size()); | |
| 3643 ASSERT_EQ(3u, root->renderSurface()->layerList().size()); // The root surfac
e has the root layer, and child1's and child2's renderSurfaces. | |
| 3644 ASSERT_EQ(2u, child1->renderSurface()->layerList().size()); // The child1 su
rface has the child1 layer and grandChild1's renderSurface. | |
| 3645 ASSERT_EQ(1u, child2->renderSurface()->layerList().size()); | |
| 3646 ASSERT_EQ(1u, grandChild1->renderSurface()->layerList().size()); | |
| 3647 ASSERT_EQ(1, renderSurfaceLayerList[0]->id()); // root layer | |
| 3648 ASSERT_EQ(2, renderSurfaceLayerList[1]->id()); // child1 | |
| 3649 ASSERT_EQ(4, renderSurfaceLayerList[2]->id()); // grandChild1 | |
| 3650 ASSERT_EQ(3, renderSurfaceLayerList[3]->id()); // child2 | |
| 3651 | |
| 3652 // Nothing overlaps the rootLayer at (1, 1), so hit testing there should fin
d the root layer. | |
| 3653 gfx::Point testPoint = gfx::Point(1, 1); | |
| 3654 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(test
Point, renderSurfaceLayerList); | |
| 3655 ASSERT_TRUE(resultLayer); | |
| 3656 EXPECT_EQ(1, resultLayer->id()); | |
| 3657 | |
| 3658 // At (15, 15), child1 and root are the only layers. child1 is expected to b
e on top. | |
| 3659 testPoint = gfx::Point(15, 15); | |
| 3660 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3661 ASSERT_TRUE(resultLayer); | |
| 3662 EXPECT_EQ(2, resultLayer->id()); | |
| 3663 | |
| 3664 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top. | |
| 3665 testPoint = gfx::Point(51, 20); | |
| 3666 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3667 ASSERT_TRUE(resultLayer); | |
| 3668 EXPECT_EQ(3, resultLayer->id()); | |
| 3669 | |
| 3670 // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on
top. | |
| 3671 testPoint = gfx::Point(80, 51); | |
| 3672 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3673 ASSERT_TRUE(resultLayer); | |
| 3674 EXPECT_EQ(3, resultLayer->id()); | |
| 3675 | |
| 3676 // At (51, 51), all layers overlap each other. child2 is expected to be on t
op of all other layers. | |
| 3677 testPoint = gfx::Point(51, 51); | |
| 3678 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3679 ASSERT_TRUE(resultLayer); | |
| 3680 EXPECT_EQ(3, resultLayer->id()); | |
| 3681 | |
| 3682 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b
e on top. | |
| 3683 testPoint = gfx::Point(20, 51); | |
| 3684 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | |
| 3685 ASSERT_TRUE(resultLayer); | |
| 3686 EXPECT_EQ(4, resultLayer->id()); | |
| 3687 } | |
| 3688 | |
| 3689 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForEmptyLayerL
ist) | 2909 TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForEmptyLayerL
ist) |
| 3690 { | 2910 { |
| 3691 // Hit checking on an empty renderSurfaceLayerList should return a null poin
ter. | 2911 // Hit checking on an empty renderSurfaceLayerList should return a null poin
ter. |
| 3692 std::vector<LayerImpl*> renderSurfaceLayerList; | 2912 std::vector<LayerImpl*> renderSurfaceLayerList; |
| 3693 | 2913 |
| 3694 gfx::Point testPoint(0, 0); | 2914 gfx::Point testPoint(0, 0); |
| 3695 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou
chHandlerRegion(testPoint, renderSurfaceLayerList); | 2915 LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTou
chHandlerRegion(testPoint, renderSurfaceLayerList); |
| 3696 EXPECT_FALSE(resultLayer); | 2916 EXPECT_FALSE(resultLayer); |
| 3697 | 2917 |
| 3698 testPoint = gfx::Point(10, 20); | 2918 testPoint = gfx::Point(10, 20); |
| (...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5037 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); | 4257 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); |
| 5038 } | 4258 } |
| 5039 | 4259 |
| 5040 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 4260 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5041 LCDTextTest, | 4261 LCDTextTest, |
| 5042 testing::Combine(testing::Bool(), | 4262 testing::Combine(testing::Bool(), |
| 5043 testing::Bool())); | 4263 testing::Bool())); |
| 5044 | 4264 |
| 5045 } // namespace | 4265 } // namespace |
| 5046 } // namespace cc | 4266 } // namespace cc |
| OLD | NEW |