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" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { | 120 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { |
121 Layer* layer = CreateLayer(LAYER_NOT_DRAWN); | 121 Layer* layer = CreateLayer(LAYER_NOT_DRAWN); |
122 layer->SetBounds(bounds); | 122 layer->SetBounds(bounds); |
123 return layer; | 123 return layer; |
124 } | 124 } |
125 | 125 |
126 void DrawTree(Layer* root) { | 126 void DrawTree(Layer* root) { |
127 GetCompositor()->SetRootLayer(root); | 127 GetCompositor()->SetRootLayer(root); |
128 GetCompositor()->ScheduleDraw(); | 128 GetCompositor()->ScheduleDraw(); |
129 WaitForSwap(); | 129 WaitForDraw(); |
130 } | 130 } |
131 | 131 |
132 bool ReadPixels(SkBitmap* bitmap) { | 132 bool ReadPixels(SkBitmap* bitmap) { |
133 return ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); | 133 return ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); |
134 } | 134 } |
135 | 135 |
136 bool ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { | 136 bool ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { |
137 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); | 137 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); |
138 scoped_ptr<cc::CopyOutputRequest> request = | 138 scoped_ptr<cc::CopyOutputRequest> request = |
139 cc::CopyOutputRequest::CreateBitmapRequest( | 139 cc::CopyOutputRequest::CreateBitmapRequest( |
140 base::Bind(&ReadbackHolder::OutputRequestCallback, holder)); | 140 base::Bind(&ReadbackHolder::OutputRequestCallback, holder)); |
141 request->set_area(source_rect); | 141 request->set_area(source_rect); |
142 | 142 |
143 GetCompositor()->root_layer()->RequestCopyOfOutput(request.Pass()); | 143 GetCompositor()->root_layer()->RequestCopyOfOutput(request.Pass()); |
144 | 144 |
145 // Wait for copy response. The copy output request will get committed | 145 // Wait for copy response. This needs to wait as the compositor could |
146 // before the first draw, but may not be part of the first draw's frame. | 146 // be in the middle of a draw right now, and the commit with the |
147 // The second draw will perform the async copy request, post the callback. | 147 // copy output request may not be done on the first draw. |
148 // The second loop finishes before the callback is run, so a third | 148 for (int i = 0; i < 2; i++) { |
149 // loop is needed. | 149 GetCompositor()->ScheduleDraw(); |
150 for (int i = 0; i < 3; i++) { | |
151 GetCompositor()->ScheduleFullRedraw(); | |
152 WaitForDraw(); | 150 WaitForDraw(); |
153 } | 151 } |
154 | 152 |
155 if (holder->completed()) { | 153 if (holder->completed()) { |
156 *bitmap = holder->result(); | 154 *bitmap = holder->result(); |
157 return true; | 155 return true; |
158 } | 156 } |
159 | 157 |
160 // Callback never called. | 158 // Callback never called. |
161 NOTREACHED(); | 159 NOTREACHED(); |
162 return false; | 160 return false; |
163 } | 161 } |
164 | 162 |
165 void WaitForDraw() { | 163 void WaitForDraw() { ui::DrawWaiterForTest::Wait(GetCompositor()); } |
166 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor()); | |
167 } | |
168 | |
169 void WaitForSwap() { | |
170 DrawWaiterForTest::WaitForCompositingEnded(GetCompositor()); | |
171 } | |
172 | 164 |
173 void WaitForCommit() { | 165 void WaitForCommit() { |
174 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); | 166 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); |
175 } | 167 } |
176 | 168 |
177 // Invalidates the entire contents of the layer. | 169 // Invalidates the entire contents of the layer. |
178 void SchedulePaintForLayer(Layer* layer) { | 170 void SchedulePaintForLayer(Layer* layer) { |
179 layer->SchedulePaint( | 171 layer->SchedulePaint( |
180 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); | 172 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); |
181 } | 173 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 layer->SchedulePaint( | 440 layer->SchedulePaint( |
449 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); | 441 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); |
450 } | 442 } |
451 | 443 |
452 // Invokes DrawTree on the compositor. | 444 // Invokes DrawTree on the compositor. |
453 void Draw() { | 445 void Draw() { |
454 compositor()->ScheduleDraw(); | 446 compositor()->ScheduleDraw(); |
455 WaitForDraw(); | 447 WaitForDraw(); |
456 } | 448 } |
457 | 449 |
458 void WaitForDraw() { | 450 void WaitForDraw() { DrawWaiterForTest::Wait(compositor()); } |
459 DrawWaiterForTest::WaitForCompositingStarted(compositor()); | |
460 } | |
461 | 451 |
462 void WaitForCommit() { | 452 void WaitForCommit() { |
463 DrawWaiterForTest::WaitForCommit(compositor()); | 453 DrawWaiterForTest::WaitForCommit(compositor()); |
464 } | 454 } |
465 | 455 |
466 private: | 456 private: |
467 scoped_ptr<TestCompositorHost> compositor_host_; | 457 scoped_ptr<TestCompositorHost> compositor_host_; |
468 | 458 |
469 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); | 459 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); |
470 }; | 460 }; |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 | 934 |
945 // ScheduleDraw without any visible change should cause a commit. | 935 // ScheduleDraw without any visible change should cause a commit. |
946 observer.Reset(); | 936 observer.Reset(); |
947 l1->ScheduleDraw(); | 937 l1->ScheduleDraw(); |
948 WaitForCommit(); | 938 WaitForCommit(); |
949 EXPECT_TRUE(observer.committed()); | 939 EXPECT_TRUE(observer.committed()); |
950 | 940 |
951 // Moving, but not resizing, a layer should alert the observers. | 941 // Moving, but not resizing, a layer should alert the observers. |
952 observer.Reset(); | 942 observer.Reset(); |
953 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); | 943 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); |
954 WaitForSwap(); | 944 WaitForDraw(); |
955 EXPECT_TRUE(observer.notified()); | 945 EXPECT_TRUE(observer.notified()); |
956 | 946 |
957 // So should resizing a layer. | 947 // So should resizing a layer. |
958 observer.Reset(); | 948 observer.Reset(); |
959 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); | 949 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); |
960 WaitForSwap(); | 950 WaitForDraw(); |
961 EXPECT_TRUE(observer.notified()); | 951 EXPECT_TRUE(observer.notified()); |
962 | 952 |
963 // Opacity changes should alert the observers. | 953 // Opacity changes should alert the observers. |
964 observer.Reset(); | 954 observer.Reset(); |
965 l2->SetOpacity(0.5f); | 955 l2->SetOpacity(0.5f); |
966 WaitForSwap(); | 956 WaitForDraw(); |
967 EXPECT_TRUE(observer.notified()); | 957 EXPECT_TRUE(observer.notified()); |
968 | 958 |
969 // So should setting the opacity back. | 959 // So should setting the opacity back. |
970 observer.Reset(); | 960 observer.Reset(); |
971 l2->SetOpacity(1.0f); | 961 l2->SetOpacity(1.0f); |
972 WaitForSwap(); | 962 WaitForDraw(); |
973 EXPECT_TRUE(observer.notified()); | 963 EXPECT_TRUE(observer.notified()); |
974 | 964 |
975 // Setting the transform of a layer should alert the observers. | 965 // Setting the transform of a layer should alert the observers. |
976 observer.Reset(); | 966 observer.Reset(); |
977 gfx::Transform transform; | 967 gfx::Transform transform; |
978 transform.Translate(200.0, 200.0); | 968 transform.Translate(200.0, 200.0); |
979 transform.Rotate(90.0); | 969 transform.Rotate(90.0); |
980 transform.Translate(-200.0, -200.0); | 970 transform.Translate(-200.0, -200.0); |
981 l2->SetTransform(transform); | 971 l2->SetTransform(transform); |
982 WaitForSwap(); | 972 WaitForDraw(); |
983 EXPECT_TRUE(observer.notified()); | 973 EXPECT_TRUE(observer.notified()); |
984 | 974 |
985 // A change resulting in an aborted swap buffer should alert the observer | 975 // A change resulting in an aborted swap buffer should alert the observer |
986 // and also signal an abort. | 976 // and also signal an abort. |
987 observer.Reset(); | 977 observer.Reset(); |
988 l2->SetOpacity(0.1f); | 978 l2->SetOpacity(0.1f); |
989 GetCompositor()->DidAbortSwapBuffers(); | 979 GetCompositor()->DidAbortSwapBuffers(); |
990 WaitForSwap(); | 980 WaitForDraw(); |
991 EXPECT_TRUE(observer.notified()); | 981 EXPECT_TRUE(observer.notified()); |
992 EXPECT_TRUE(observer.aborted()); | 982 EXPECT_TRUE(observer.aborted()); |
993 | 983 |
994 GetCompositor()->RemoveObserver(&observer); | 984 GetCompositor()->RemoveObserver(&observer); |
995 | 985 |
996 // Opacity changes should no longer alert the removed observer. | 986 // Opacity changes should no longer alert the removed observer. |
997 observer.Reset(); | 987 observer.Reset(); |
998 l2->SetOpacity(0.5f); | 988 l2->SetOpacity(0.5f); |
999 WaitForSwap(); | 989 WaitForDraw(); |
1000 | 990 |
1001 EXPECT_FALSE(observer.notified()); | 991 EXPECT_FALSE(observer.notified()); |
1002 } | 992 } |
1003 | 993 |
1004 // Checks that modifying the hierarchy correctly affects final composite. | 994 // Checks that modifying the hierarchy correctly affects final composite. |
1005 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { | 995 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { |
1006 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); | 996 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); |
1007 | 997 |
1008 // l0 | 998 // l0 |
1009 // +-l11 | 999 // +-l11 |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 | 1585 |
1596 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); | 1586 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); |
1597 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); | 1587 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); |
1598 // c11 is now off the pixel. | 1588 // c11 is now off the pixel. |
1599 // 0.5 / 1.5 = 0.333... | 1589 // 0.5 / 1.5 = 0.333... |
1600 EXPECT_EQ("0.33 0.33", | 1590 EXPECT_EQ("0.33 0.33", |
1601 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); | 1591 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); |
1602 } | 1592 } |
1603 | 1593 |
1604 } // namespace ui | 1594 } // namespace ui |
OLD | NEW |