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

Unified Diff: ui/compositor/layer_unittest.cc

Issue 375693006: Snap layers in views to physical pixel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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: ui/compositor/layer_unittest.cc
diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc
index af85fcf2ca6f2733ec8b6ad7997753b1149b51ab..a7803d431918e6f23ed2e6a506e1abba913a2929 100644
--- a/ui/compositor/layer_unittest.cc
+++ b/ui/compositor/layer_unittest.cc
@@ -23,6 +23,7 @@
#include "cc/test/pixel_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/compositor_observer.h"
+#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/layer_animator.h"
@@ -1554,4 +1555,41 @@ TEST_F(LayerWithDelegateTest, DestroyingLayerRemovesTheAnimatorFromCollection) {
EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators());
}
+namespace {
+
+std::string ToString(const gfx::Vector2dF& vector) {
danakj 2014/07/15 21:11:02 Vector2dFToHundredthPrecisionString or something?
oshima 2014/07/15 22:28:42 Done.
+ return base::StringPrintf("%.2f %0.2f", vector.x(), vector.y());
+}
+
+} // namespace
+
+TEST_F(LayerWithRealCompositorTest, SnapLayerToPixels) {
+ scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED));
+ scoped_ptr<Layer> c1(CreateLayer(LAYER_TEXTURED));
+ scoped_ptr<Layer> c11(CreateLayer(LAYER_TEXTURED));
+
+ GetCompositor()->SetScaleAndSize(1.25f, gfx::Size(100, 100));
+ GetCompositor()->SetRootLayer(root.get());
+ root->Add(c1.get());
+ c1->Add(c11.get());
+
+ root->SetBounds(gfx::Rect(0, 0, 100, 100));
+ c1->SetBounds(gfx::Rect(1, 1, 10, 10));
+ c11->SetBounds(gfx::Rect(1, 1, 10, 10));
+ SnapLayerToPhysicalPixelBoundary(root.get(), c11.get());
+ // 0.5 at 1.25 scale : (0.25 + 0.25) / 1.25 = 0.4
+ EXPECT_EQ("0.40 0.40", ToString(c11->subpixel_position_offset()));
+
+ GetCompositor()->SetScaleAndSize(1.5f, gfx::Size(100, 100));
+ SnapLayerToPhysicalPixelBoundary(root.get(), c11.get());
+ // c11 msut already be alignedt at 1.5 scale.
danakj 2014/07/15 21:11:02 "must" "aligned"
oshima 2014/07/15 22:28:42 Done.
+ EXPECT_EQ("0.00 0.00", ToString(c11->subpixel_position_offset()));
+
+ c11->SetBounds(gfx::Rect(2, 2, 10, 10));
+ SnapLayerToPhysicalPixelBoundary(root.get(), c11.get());
+ // c11 is now off the pixel.
+ // 0.5 / 1.5 = 0.333...
+ EXPECT_EQ("0.33 0.33", ToString(c11->subpixel_position_offset()));
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698