Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: cc/CCLayerTreeHostCommonTest.cpp

Issue 10964002: Add high DPI unit test for verifying visible and drawable content rects in compositor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed unit test Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "config.h" 5 #include "config.h"
6 6
7 #include "CCLayerTreeHostCommon.h" 7 #include "CCLayerTreeHostCommon.h"
8 8
9 #include "CCAnimationTestCommon.h" 9 #include "CCAnimationTestCommon.h"
10 #include "CCGeometryTestUtils.h" 10 #include "CCGeometryTestUtils.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 { 44 {
45 setLayerPropertiesForTesting<LayerChromium>(layer, transform, sublayerTransf orm, anchor, position, bounds, preserves3D); 45 setLayerPropertiesForTesting<LayerChromium>(layer, transform, sublayerTransf orm, anchor, position, bounds, preserves3D);
46 } 46 }
47 47
48 void setLayerPropertiesForTesting(CCLayerImpl* layer, const WebTransformationMat rix& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoi nt& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D) 48 void setLayerPropertiesForTesting(CCLayerImpl* layer, const WebTransformationMat rix& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoi nt& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D)
49 { 49 {
50 setLayerPropertiesForTesting<CCLayerImpl>(layer, transform, sublayerTransfor m, anchor, position, bounds, preserves3D); 50 setLayerPropertiesForTesting<CCLayerImpl>(layer, transform, sublayerTransfor m, anchor, position, bounds, preserves3D);
51 layer->setContentBounds(bounds); 51 layer->setContentBounds(bounds);
52 } 52 }
53 53
54 void executeCalculateDrawTransformsAndVisibility(LayerChromium* rootLayer) 54 void executeCalculateDrawTransformsAndVisibility(LayerChromium* rootLayer, float deviceScaleFactor = 1)
55 { 55 {
56 WebTransformationMatrix identityMatrix; 56 WebTransformationMatrix identityMatrix;
57 Vector<RefPtr<LayerChromium> > dummyRenderSurfaceLayerList; 57 Vector<RefPtr<LayerChromium> > dummyRenderSurfaceLayerList;
58 int dummyMaxTextureSize = 512; 58 int dummyMaxTextureSize = 512;
59 IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceSca leFactor, rootLayer->bounds().height() * deviceScaleFactor);
59 60
60 // We are probably not testing what is intended if the rootLayer bounds are empty. 61 // We are probably not testing what is intended if the rootLayer bounds are empty.
61 ASSERT(!rootLayer->bounds().isEmpty()); 62 ASSERT(!rootLayer->bounds().isEmpty());
62 CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, rootLayer->bounds( ), 1, dummyMaxTextureSize, dummyRenderSurfaceLayerList); 63 CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize , deviceScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
63 CCLayerTreeHostCommon::calculateVisibleRects(dummyRenderSurfaceLayerList); 64 CCLayerTreeHostCommon::calculateVisibleRects(dummyRenderSurfaceLayerList);
64 } 65 }
65 66
66 void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer) 67 void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer, float d eviceScaleFactor = 1)
67 { 68 {
68 // Note: this version skips layer sorting. 69 // Note: this version skips layer sorting.
69 70
70 WebTransformationMatrix identityMatrix; 71 WebTransformationMatrix identityMatrix;
71 Vector<CCLayerImpl*> dummyRenderSurfaceLayerList; 72 Vector<CCLayerImpl*> dummyRenderSurfaceLayerList;
72 int dummyMaxTextureSize = 512; 73 int dummyMaxTextureSize = 512;
74 IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceSca leFactor, rootLayer->bounds().height() * deviceScaleFactor);
73 75
74 // We are probably not testing what is intended if the rootLayer bounds are empty. 76 // We are probably not testing what is intended if the rootLayer bounds are empty.
75 ASSERT(!rootLayer->bounds().isEmpty()); 77 ASSERT(!rootLayer->bounds().isEmpty());
76 CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, rootLayer->bounds( ), 1, 0, dummyMaxTextureSize, dummyRenderSurfaceLayerList); 78 CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize , deviceScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
77 CCLayerTreeHostCommon::calculateVisibleRects(dummyRenderSurfaceLayerList); 79 CCLayerTreeHostCommon::calculateVisibleRects(dummyRenderSurfaceLayerList);
78 } 80 }
79 81
80 WebTransformationMatrix remove3DComponentOfMatrix(const WebTransformationMatrix& mat) 82 WebTransformationMatrix remove3DComponentOfMatrix(const WebTransformationMatrix& mat)
81 { 83 {
82 WebTransformationMatrix ret = mat; 84 WebTransformationMatrix ret = mat;
83 ret.setM13(0); 85 ret.setM13(0);
84 ret.setM23(0); 86 ret.setM23(0);
85 ret.setM31(0); 87 ret.setM31(0);
86 ret.setM32(0); 88 ret.setM32(0);
(...skipping 29 matching lines...) Expand all
116 class LayerChromiumWithForcedDrawsContent : public LayerChromium { 118 class LayerChromiumWithForcedDrawsContent : public LayerChromium {
117 public: 119 public:
118 LayerChromiumWithForcedDrawsContent() 120 LayerChromiumWithForcedDrawsContent()
119 : LayerChromium() 121 : LayerChromium()
120 { 122 {
121 } 123 }
122 124
123 virtual bool drawsContent() const OVERRIDE { return true; } 125 virtual bool drawsContent() const OVERRIDE { return true; }
124 }; 126 };
125 127
128 class MockContentLayerChromiumClient : public ContentLayerChromiumClient {
129 public:
130 MockContentLayerChromiumClient() { }
131 virtual ~MockContentLayerChromiumClient() { }
132 virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque ) OVERRIDE { }
133 };
134
135 PassRefPtr<ContentLayerChromium> createDrawableContentLayerChromium(ContentLayer ChromiumClient* delegate)
136 {
137 RefPtr<ContentLayerChromium> toReturn = ContentLayerChromium::create(delegat e);
138 toReturn->setIsDrawable(true);
139 return toReturn.release();
140 }
141
126 TEST(CCLayerTreeHostCommonTest, verifyTransformsForNoOpLayer) 142 TEST(CCLayerTreeHostCommonTest, verifyTransformsForNoOpLayer)
127 { 143 {
128 // Sanity check: For layers positioned at zero, with zero size, 144 // Sanity check: For layers positioned at zero, with zero size,
129 // and with identity transforms, then the drawTransform, 145 // and with identity transforms, then the drawTransform,
130 // screenSpaceTransform, and the hierarchy passed on to children 146 // screenSpaceTransform, and the hierarchy passed on to children
131 // layers should also be identity transforms. 147 // layers should also be identity transforms.
132 148
133 RefPtr<LayerChromium> parent = LayerChromium::create(); 149 RefPtr<LayerChromium> parent = LayerChromium::create();
134 RefPtr<LayerChromium> child = LayerChromium::create(); 150 RefPtr<LayerChromium> child = LayerChromium::create();
135 RefPtr<LayerChromium> grandChild = LayerChromium::create(); 151 RefPtr<LayerChromium> grandChild = LayerChromium::create();
(...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 2229
2214 // On the clipped surface, only a quarter of the child1 is visible, but whe n rotating 2230 // On the clipped surface, only a quarter of the child1 is visible, but whe n rotating
2215 // it back to child1's content space, the actual enclosing rect ends up cov ering the 2231 // it back to child1's content space, the actual enclosing rect ends up cov ering the
2216 // full left half of child1. 2232 // full left half of child1.
2217 EXPECT_RECT_EQ(IntRect(0, 0, 26, 50), child1->visibleContentRect()); 2233 EXPECT_RECT_EQ(IntRect(0, 0, 26, 50), child1->visibleContentRect());
2218 2234
2219 // The child's drawableContentRect is unclipped. 2235 // The child's drawableContentRect is unclipped.
2220 EXPECT_RECT_EQ(unclippedSurfaceContent, child1->drawableContentRect()); 2236 EXPECT_RECT_EQ(unclippedSurfaceContent, child1->drawableContentRect());
2221 } 2237 }
2222 2238
2239 TEST(CCLayerTreeHostCommonTest, verifyDrawableAndVisibleContentRectsInHighDPI)
2240 {
2241 MockContentLayerChromiumClient client;
2242
2243 RefPtr<LayerChromium> root = LayerChromium::create();
2244 RefPtr<ContentLayerChromium> renderSurface1 = createDrawableContentLayerChro mium(&client);
2245 RefPtr<ContentLayerChromium> renderSurface2 = createDrawableContentLayerChro mium(&client);
2246 RefPtr<ContentLayerChromium> child1 = createDrawableContentLayerChromium(&cl ient);
2247 RefPtr<ContentLayerChromium> child2 = createDrawableContentLayerChromium(&cl ient);
2248 RefPtr<ContentLayerChromium> child3 = createDrawableContentLayerChromium(&cl ient);
2249 root->addChild(renderSurface1);
2250 renderSurface1->addChild(renderSurface2);
2251 renderSurface2->addChild(child1);
2252 renderSurface2->addChild(child2);
2253 renderSurface2->addChild(child3);
2254
2255 WebTransformationMatrix identityMatrix;
2256 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, Flo atPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
2257 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(3, 4), false);
2258 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(7, 13), false);
2259 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(5, 5), IntSize(50, 50), false);
2260 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(75, 75), IntSize(50, 50), false);
2261 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(125, 125), IntSize(50, 50), false);
2262
2263 const double deviceScaleFactor = 2;
2264 root->setContentsScale(deviceScaleFactor);
2265 renderSurface1->setContentsScale(deviceScaleFactor);
2266 renderSurface2->setContentsScale(deviceScaleFactor);
2267 child1->setContentsScale(deviceScaleFactor);
2268 child2->setContentsScale(deviceScaleFactor);
2269 child3->setContentsScale(deviceScaleFactor);
2270
2271 root->setMasksToBounds(true);
2272 renderSurface1->setForceRenderSurface(true);
2273 renderSurface2->setForceRenderSurface(true);
2274 executeCalculateDrawTransformsAndVisibility(root.get(), deviceScaleFactor);
2275
2276 ASSERT_TRUE(renderSurface1->renderSurface());
2277 ASSERT_TRUE(renderSurface2->renderSurface());
2278
2279 // DrawableContentRects for all layers and surfaces are scaled by deviceScal eFactor.
2280 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), root->renderSurface()->drawableConte ntRect());
2281 EXPECT_RECT_EQ(IntRect(0, 0, 200, 200), root->drawableContentRect());
2282 EXPECT_RECT_EQ(IntRect(10, 10, 190, 190), renderSurface1->renderSurface()->d rawableContentRect());
2283
2284 // renderSurface2 lives in the "unclipped universe" of renderSurface1, and
2285 // is only implicitly clipped by renderSurface1.
2286 EXPECT_RECT_EQ(IntRect(10, 10, 350, 350), renderSurface2->renderSurface()->d rawableContentRect());
2287
2288 EXPECT_RECT_EQ(IntRect(10, 10, 100, 100), child1->drawableContentRect());
2289 EXPECT_RECT_EQ(IntRect(150, 150, 100, 100), child2->drawableContentRect());
2290 EXPECT_RECT_EQ(IntRect(250, 250, 100, 100), child3->drawableContentRect());
2291
2292 // The root layer does not actually draw content of its own.
2293 EXPECT_RECT_EQ(IntRect(0, 0, 0, 0), root->visibleContentRect());
2294
2295 // All layer visibleContentRects are expressed in content space of each
2296 // layer, so they are also scaled by the deviceScaleFactor.
2297 EXPECT_RECT_EQ(IntRect(0, 0, 6, 8), renderSurface1->visibleContentRect());
2298 EXPECT_RECT_EQ(IntRect(0, 0, 14, 26), renderSurface2->visibleContentRect());
2299 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child1->visibleContentRect());
2300 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child2->visibleContentRect());
2301 EXPECT_RECT_EQ(IntRect(0, 0, 100, 100), child3->visibleContentRect());
2302 }
2303
2223 TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d) 2304 TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d)
2224 { 2305 {
2225 // Verify the behavior of back-face culling when there are no preserve-3d la yers. Note 2306 // Verify the behavior of back-face culling when there are no preserve-3d la yers. Note
2226 // that 3d transforms still apply in this case, but they are "flattened" to each 2307 // that 3d transforms still apply in this case, but they are "flattened" to each
2227 // parent layer according to current W3C spec. 2308 // parent layer according to current W3C spec.
2228 2309
2229 const WebTransformationMatrix identityMatrix; 2310 const WebTransformationMatrix identityMatrix;
2230 RefPtr<LayerChromium> parent = LayerChromium::create(); 2311 RefPtr<LayerChromium> parent = LayerChromium::create();
2231 RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingChild = adoptRef(new LayerChromiumWithForcedDrawsContent()); 2312 RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingChild = adoptRef(new LayerChromiumWithForcedDrawsContent());
2232 RefPtr<LayerChromiumWithForcedDrawsContent> backFacingChild = adoptRef(new L ayerChromiumWithForcedDrawsContent()); 2313 RefPtr<LayerChromiumWithForcedDrawsContent> backFacingChild = adoptRef(new L ayerChromiumWithForcedDrawsContent());
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3333 ASSERT_TRUE(resultLayer); 3414 ASSERT_TRUE(resultLayer);
3334 EXPECT_EQ(3, resultLayer->id()); 3415 EXPECT_EQ(3, resultLayer->id());
3335 3416
3336 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top. 3417 // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to b e on top.
3337 testPoint = IntPoint(20, 51); 3418 testPoint = IntPoint(20, 51);
3338 resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, re nderSurfaceLayerList); 3419 resultLayer = CCLayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, re nderSurfaceLayerList);
3339 ASSERT_TRUE(resultLayer); 3420 ASSERT_TRUE(resultLayer);
3340 EXPECT_EQ(4, resultLayer->id()); 3421 EXPECT_EQ(4, resultLayer->id());
3341 } 3422 }
3342 3423
3343 class MockContentLayerChromiumClient : public ContentLayerChromiumClient {
3344 public:
3345 MockContentLayerChromiumClient() { }
3346 virtual ~MockContentLayerChromiumClient() { }
3347 virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque ) OVERRIDE { }
3348 };
3349
3350 PassRefPtr<ContentLayerChromium> createDrawableContentLayerChromium(ContentLayer ChromiumClient* delegate)
3351 {
3352 RefPtr<ContentLayerChromium> toReturn = ContentLayerChromium::create(delegat e);
3353 toReturn->setIsDrawable(true);
3354 return toReturn.release();
3355 }
3356
3357 TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI) 3424 TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
3358 { 3425 {
3359 // Verify draw and screen space transforms of layers not in a surface. 3426 // Verify draw and screen space transforms of layers not in a surface.
3360 MockContentLayerChromiumClient delegate; 3427 MockContentLayerChromiumClient delegate;
3361 WebTransformationMatrix identityMatrix; 3428 WebTransformationMatrix identityMatrix;
3362 3429
3363 RefPtr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&de legate); 3430 RefPtr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&de legate);
3364 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 3431 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
3365 3432
3366 RefPtr<ContentLayerChromium> child = createDrawableContentLayerChromium(&del egate); 3433 RefPtr<ContentLayerChromium> child = createDrawableContentLayerChromium(&del egate);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
3525 int nonexistentId = -1; 3592 int nonexistentId = -1;
3526 EXPECT_EQ(root, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), root-> id())); 3593 EXPECT_EQ(root, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), root-> id()));
3527 EXPECT_EQ(child, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), child ->id())); 3594 EXPECT_EQ(child, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), child ->id()));
3528 EXPECT_EQ(grandChild, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), grandChild->id())); 3595 EXPECT_EQ(grandChild, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), grandChild->id()));
3529 EXPECT_EQ(maskLayer, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), m askLayer->id())); 3596 EXPECT_EQ(maskLayer, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), m askLayer->id()));
3530 EXPECT_EQ(replicaLayer, CCLayerTreeHostCommon::findLayerInSubtree(root.get() , replicaLayer->id())); 3597 EXPECT_EQ(replicaLayer, CCLayerTreeHostCommon::findLayerInSubtree(root.get() , replicaLayer->id()));
3531 EXPECT_EQ(0, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), nonexiste ntId)); 3598 EXPECT_EQ(0, CCLayerTreeHostCommon::findLayerInSubtree(root.get(), nonexiste ntId));
3532 } 3599 }
3533 3600
3534 } // namespace 3601 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698