OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "cc/layers/delegated_frame_provider.h" | 17 #include "cc/layers/delegated_frame_provider.h" |
18 #include "cc/layers/delegated_frame_resource_collection.h" | 18 #include "cc/layers/delegated_frame_resource_collection.h" |
19 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" |
20 #include "cc/output/copy_output_request.h" | 20 #include "cc/output/copy_output_request.h" |
21 #include "cc/output/copy_output_result.h" | 21 #include "cc/output/copy_output_result.h" |
22 #include "cc/output/delegated_frame_data.h" | 22 #include "cc/output/delegated_frame_data.h" |
23 #include "cc/test/pixel_test_utils.h" | 23 #include "cc/test/pixel_test_utils.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "ui/compositor/compositor_observer.h" | 25 #include "ui/compositor/compositor_observer.h" |
26 #include "ui/compositor/dip_util.h" | |
26 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
27 #include "ui/compositor/layer_animation_sequence.h" | 28 #include "ui/compositor/layer_animation_sequence.h" |
28 #include "ui/compositor/layer_animator.h" | 29 #include "ui/compositor/layer_animator.h" |
29 #include "ui/compositor/test/context_factories_for_test.h" | 30 #include "ui/compositor/test/context_factories_for_test.h" |
30 #include "ui/compositor/test/draw_waiter_for_test.h" | 31 #include "ui/compositor/test/draw_waiter_for_test.h" |
31 #include "ui/compositor/test/test_compositor_host.h" | 32 #include "ui/compositor/test/test_compositor_host.h" |
32 #include "ui/compositor/test/test_layers.h" | 33 #include "ui/compositor/test/test_layers.h" |
33 #include "ui/gfx/canvas.h" | 34 #include "ui/gfx/canvas.h" |
34 #include "ui/gfx/codec/png_codec.h" | 35 #include "ui/gfx/codec/png_codec.h" |
35 #include "ui/gfx/gfx_paths.h" | 36 #include "ui/gfx/gfx_paths.h" |
(...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1547 compositor()->SetRootLayer(root.get()); | 1548 compositor()->SetRootLayer(root.get()); |
1548 | 1549 |
1549 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); | 1550 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); |
1550 child->SetOpacity(0.5f); | 1551 child->SetOpacity(0.5f); |
1551 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1552 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1552 | 1553 |
1553 child.reset(); | 1554 child.reset(); |
1554 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); | 1555 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); |
1555 } | 1556 } |
1556 | 1557 |
1558 namespace { | |
1559 | |
1560 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.
| |
1561 return base::StringPrintf("%.2f %0.2f", vector.x(), vector.y()); | |
1562 } | |
1563 | |
1564 } // namespace | |
1565 | |
1566 TEST_F(LayerWithRealCompositorTest, SnapLayerToPixels) { | |
1567 scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); | |
1568 scoped_ptr<Layer> c1(CreateLayer(LAYER_TEXTURED)); | |
1569 scoped_ptr<Layer> c11(CreateLayer(LAYER_TEXTURED)); | |
1570 | |
1571 GetCompositor()->SetScaleAndSize(1.25f, gfx::Size(100, 100)); | |
1572 GetCompositor()->SetRootLayer(root.get()); | |
1573 root->Add(c1.get()); | |
1574 c1->Add(c11.get()); | |
1575 | |
1576 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | |
1577 c1->SetBounds(gfx::Rect(1, 1, 10, 10)); | |
1578 c11->SetBounds(gfx::Rect(1, 1, 10, 10)); | |
1579 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); | |
1580 // 0.5 at 1.25 scale : (0.25 + 0.25) / 1.25 = 0.4 | |
1581 EXPECT_EQ("0.40 0.40", ToString(c11->subpixel_position_offset())); | |
1582 | |
1583 GetCompositor()->SetScaleAndSize(1.5f, gfx::Size(100, 100)); | |
1584 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); | |
1585 // 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.
| |
1586 EXPECT_EQ("0.00 0.00", ToString(c11->subpixel_position_offset())); | |
1587 | |
1588 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); | |
1589 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); | |
1590 // c11 is now off the pixel. | |
1591 // 0.5 / 1.5 = 0.333... | |
1592 EXPECT_EQ("0.33 0.33", ToString(c11->subpixel_position_offset())); | |
1593 } | |
1594 | |
1557 } // namespace ui | 1595 } // namespace ui |
OLD | NEW |