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

Unified Diff: webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc

Issue 12326022: Efficiently handle image layer scaling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add black-box tests Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc
diff --git a/webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc b/webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e607c5ebcfc3599f484f4232171b3b9713a8aeaf
--- /dev/null
+++ b/webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc
@@ -0,0 +1,169 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/layer_tree_host_common.h"
+#include "cc/picture_image_layer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMatrix.h"
+#include "third_party/skia/include/utils/SkMatrix44.h"
+#include "ui/gfx/point3_f.h"
+#include "webkit/compositor_bindings/web_layer_impl_fixed_bounds.h"
+
+using namespace WebKit;
+
+TEST(WebLayerImplFixedBoundsTest, IdentityBounds)
+{
+ scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds());
+ layer->setAnchorPoint(WebFloatPoint(0, 0));
+ layer->setFixedBounds(gfx::Size(100, 100));
+ layer->setBounds(WebSize(100, 100));
+ EXPECT_EQ(WebSize(100, 100), layer->bounds());
+ EXPECT_EQ(gfx::Size(100, 100), layer->layer()->bounds());
+ EXPECT_EQ(gfx::Transform(), layer->layer()->transform());
+}
+
+#define EXPECT_POINT3F_EQ(p1, p2) \
enne (OOO) 2013/02/22 23:53:32 Can you put these in geometry_test_utils.h?
Xianzhu 2013/02/23 00:56:19 Done.
+ EXPECT_FLOAT_EQ((p1).x(), (p2).x()); \
+ EXPECT_FLOAT_EQ((p1).y(), (p2).y()); \
+ EXPECT_FLOAT_EQ((p1).z(), (p2).z());
+
+#define EXPECT_RECTF_EQ(r1, r2) \
+ EXPECT_FLOAT_EQ((r1).x(), (r2).x()); \
+ EXPECT_FLOAT_EQ((r1).y(), (r2).y()); \
+ EXPECT_FLOAT_EQ((r1).width(), (r2).width()); \
+ EXPECT_FLOAT_EQ((r1).height(), (r2).height());
+
+gfx::Point3F transformPoint(const gfx::Transform& transform, const gfx::Point3F& point)
enne (OOO) 2013/02/22 23:53:32 style nits: 80 columns everywhere in this file, p
Xianzhu 2013/02/23 00:05:20 I thought all files under the directory should fol
Xianzhu 2013/02/23 00:56:19 Converted this file into Chromium style. Still ke
enne (OOO) 2013/02/23 01:10:55 As jamesr says, new code should be Chromium style,
+{
+ gfx::Point3F result = point;
+ transform.TransformPoint(result);
+ return result;
+}
+
+void checkBoundsScaleSimple(WebLayerImplFixedBounds* layer,
+ const WebSize& bounds,
+ const gfx::Size& fixedBounds)
+{
+ layer->setBounds(bounds);
+ layer->setFixedBounds(fixedBounds);
+
+ EXPECT_EQ(bounds, layer->bounds());
+ EXPECT_EQ(fixedBounds, layer->layer()->bounds());
+ EXPECT_TRUE(layer->transform().isIdentity());
+ EXPECT_TRUE(layer->sublayerTransform().isIdentity());
+
+ // An arbitrary point to check the scale and transforms.
+ gfx::Point3F originalPoint(10, 20, 1);
+ gfx::Point3F scaledPoint(originalPoint.x() * bounds.width / fixedBounds.width(),
+ originalPoint.y() * bounds.height / fixedBounds.height(),
+ originalPoint.z());
+ // Test if the bounds scale is correctly applied in transform and sublayerTransform.
+ EXPECT_POINT3F_EQ(scaledPoint, transformPoint(layer->layer()->transform(), originalPoint));
+ EXPECT_POINT3F_EQ(originalPoint, transformPoint(layer->layer()->sublayerTransform(), scaledPoint));
+}
+
+TEST(WebLayerImplFixedBoundsTest, BoundsScaleSimple)
+{
+ scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds());
+ layer->setAnchorPoint(WebFloatPoint(0, 0));
+ // All numbers below are arbitrary values that should not affect the results.
+ checkBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(150, 250));
+ // Change fixedBounds.
+ checkBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(75, 100));
+ // Change bounds.
+ checkBoundsScaleSimple(layer.get(), WebSize(300, 100), gfx::Size(75, 100));
+}
+
+void compareToWebLayerImpl(const WebFloatPoint& anchorPoint,
enne (OOO) 2013/02/22 23:53:32 This function is great. That's exactly what I was
+ const gfx::Transform& transform,
+ const gfx::Transform& sublayerTransform)
+{
+ const gfx::Size deviceViewportSize(800, 600);
+ const float deviceScaleFactor = 1.f; // 2.f;
+ const float pageScaleFactor = 1.f; // 1.5f;
+ const int maxTextureSize = 512;
+
+ WebSize bounds(100, 100); // (150, 200);
+ WebFloatPoint position(20, 30);
+ WebSize sublayerBounds(88, 99);
+ WebFloatPoint sublayerPosition(50, 60);
+ gfx::Size fixedBounds(200, 200); // (160, 70);
enne (OOO) 2013/02/22 23:53:32 Are these debug comments that should be removed?
Xianzhu 2013/02/23 00:56:19 Done.
+
+ scoped_ptr<WebLayerImplFixedBounds> rootLayer(new WebLayerImplFixedBounds());
+
+ WebLayerImplFixedBounds* fixedBoundsLayer = new WebLayerImplFixedBounds(cc::PictureImageLayer::create());
+ WebLayerImpl* sublayerUnderFixedBoundsLayer = new WebLayerImpl();
+ sublayerUnderFixedBoundsLayer->setBounds(sublayerBounds);
+ sublayerUnderFixedBoundsLayer->setPosition(sublayerPosition);
+ sublayerUnderFixedBoundsLayer->setDebugName("sublayerUnderFixedBoundsLayer");
+ fixedBoundsLayer->setDebugName("fixedBoundsLayer");
+ fixedBoundsLayer->addChild(sublayerUnderFixedBoundsLayer);
+ fixedBoundsLayer->setBounds(bounds);
+ fixedBoundsLayer->setFixedBounds(fixedBounds);
+ fixedBoundsLayer->setAnchorPoint(anchorPoint);
+ fixedBoundsLayer->setTransform(transform.matrix());
+ fixedBoundsLayer->setSublayerTransform(sublayerTransform.matrix());
+ fixedBoundsLayer->setPosition(position);
+ rootLayer->addChild(fixedBoundsLayer);
+
+ WebLayerImpl* normalLayer(new WebLayerImpl(cc::PictureImageLayer::create()));
+ WebLayerImpl* sublayerUnderNormalLayer = new WebLayerImpl();
+ sublayerUnderNormalLayer->setBounds(sublayerBounds);
+ sublayerUnderNormalLayer->setPosition(sublayerPosition);
+ sublayerUnderNormalLayer->setDebugName("sublayerUnderNormalLayer");
+ normalLayer->setDebugName("normalLayer");
+ normalLayer->addChild(sublayerUnderNormalLayer);
+ normalLayer->setBounds(bounds);
+ normalLayer->setAnchorPoint(anchorPoint);
+ normalLayer->setTransform(transform.matrix());
+ normalLayer->setSublayerTransform(sublayerTransform.matrix());
+ normalLayer->setPosition(position);
+ rootLayer->addChild(normalLayer);
+
+ std::vector<scoped_refptr<cc::Layer> > renderSurfaceLayerList;
+ cc::LayerTreeHostCommon::calculateDrawProperties(rootLayer->layer(), deviceViewportSize, deviceScaleFactor, pageScaleFactor, maxTextureSize, false, renderSurfaceLayerList);
+
+ gfx::RectF fixedBoundsLayerContentRect(fixedBoundsLayer->layer()->contentBounds());
enne (OOO) 2013/02/22 23:53:32 Content rects are not guaranteed to be the same.
+ fixedBoundsLayer->layer()->drawTransform().TransformRect(&fixedBoundsLayerContentRect);
+ gfx::RectF normalLayerContentRect(normalLayer->layer()->contentBounds());
+ normalLayer->layer()->drawTransform().TransformRect(&normalLayerContentRect);
enne (OOO) 2013/02/22 23:55:44 Oh, scratch my previous comment. Can you not name
Xianzhu 2013/02/23 00:56:19 Done.
+ EXPECT_RECTF_EQ(fixedBoundsLayerContentRect, normalLayerContentRect);
+
+ gfx::RectF subLayerUnderFixedBoundsLayerContentRect(sublayerUnderFixedBoundsLayer->layer()->contentBounds());
+ sublayerUnderFixedBoundsLayer->layer()->drawTransform().TransformRect(&subLayerUnderFixedBoundsLayerContentRect);
+ gfx::RectF subLayerUnderNormalLayerContentRect(sublayerUnderNormalLayer->layer()->contentBounds());
+ sublayerUnderNormalLayer->layer()->drawTransform().TransformRect(&subLayerUnderNormalLayerContentRect);
+ EXPECT_RECTF_EQ(subLayerUnderFixedBoundsLayerContentRect, subLayerUnderNormalLayerContentRect);
+}
+
+// A black box test that ensures WebLayerImplFixedBounds won't change final layer geometries.
+// Simple case: identity transforms and zero anchor point.
+TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplSimple)
+{
+ compareToWebLayerImpl(WebFloatPoint(0, 0), gfx::Transform(), gfx::Transform());
+}
+
+// A black box test that ensures WebLayerImplFixedBounds won't change final layer geometries.
+// Complex case: complex transforms and non-zero anchor point.
+TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplComplex)
+{
+ gfx::Transform transform;
+ // These are arbitrary values that should not affect the results.
+ transform.Translate3d(50, 60, 70);
+ transform.Scale3d(1, 1, 1);
+ transform.RotateAbout(gfx::Vector3dF(33, 44, 55), 99);
+
+ gfx::Transform sublayerTransform;
+ // These are arbitrary values that should not affect the results.
+ sublayerTransform.Scale3d(1, 2, 1);// (1.1, 2.2, 3.3);
+ sublayerTransform.Translate3d(11, 22, 33);
+ sublayerTransform.RotateAbout(gfx::Vector3dF(10, 30, 20), 88);
+
+ compareToWebLayerImpl(WebFloatPoint(0, 0), transform, sublayerTransform);
+
+ // With non-zero anchor point, WebLayerImplFixedBounds will fall back to WebLayerImpl.
+ compareToWebLayerImpl(WebFloatPoint(0.4, 0.6), transform, sublayerTransform);
+}

Powered by Google App Engine
This is Rietveld 408576698