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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 118 |
119 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { | 119 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { |
120 Layer* layer = CreateLayer(LAYER_NOT_DRAWN); | 120 Layer* layer = CreateLayer(LAYER_NOT_DRAWN); |
121 layer->SetBounds(bounds); | 121 layer->SetBounds(bounds); |
122 return layer; | 122 return layer; |
123 } | 123 } |
124 | 124 |
125 void DrawTree(Layer* root) { | 125 void DrawTree(Layer* root) { |
126 GetCompositor()->SetRootLayer(root); | 126 GetCompositor()->SetRootLayer(root); |
127 GetCompositor()->ScheduleDraw(); | 127 GetCompositor()->ScheduleDraw(); |
128 WaitForDraw(); | 128 WaitForSwap(); |
129 } | 129 } |
130 | 130 |
131 void ReadPixels(SkBitmap* bitmap) { | 131 void ReadPixels(SkBitmap* bitmap) { |
132 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); | 132 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); |
133 } | 133 } |
134 | 134 |
135 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { | 135 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { |
136 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); | 136 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); |
137 scoped_ptr<cc::CopyOutputRequest> request = | 137 scoped_ptr<cc::CopyOutputRequest> request = |
138 cc::CopyOutputRequest::CreateBitmapRequest( | 138 cc::CopyOutputRequest::CreateBitmapRequest( |
139 base::Bind(&ReadbackHolder::OutputRequestCallback, holder)); | 139 base::Bind(&ReadbackHolder::OutputRequestCallback, holder)); |
140 request->set_area(source_rect); | 140 request->set_area(source_rect); |
141 | 141 |
142 GetCompositor()->root_layer()->RequestCopyOfOutput(request.Pass()); | 142 GetCompositor()->root_layer()->RequestCopyOfOutput(request.Pass()); |
143 | 143 |
144 // Wait for copy response. This needs to wait as the compositor could | 144 // Wait for copy response. This needs to wait as the compositor could |
145 // be in the middle of a draw right now, and the commit with the | 145 // be in the middle of a draw right now, and the commit with the |
146 // copy output request may not be done on the first draw. | 146 // copy output request may not be done on the first draw. |
147 for (int i = 0; i < 2; i++) { | 147 for (int i = 0; i < 2; i++) { |
148 GetCompositor()->ScheduleDraw(); | 148 GetCompositor()->ScheduleFullRedraw(); |
149 WaitForDraw(); | 149 WaitForDraw(); |
150 } | 150 } |
151 | 151 |
152 // Waits for the callback to finish run and return result. | 152 // Waits for the callback to finish run and return result. |
153 holder->WaitForReadback(); | 153 holder->WaitForReadback(); |
154 | 154 |
155 *bitmap = holder->result(); | 155 *bitmap = holder->result(); |
156 } | 156 } |
157 | 157 |
158 void WaitForDraw() { ui::DrawWaiterForTest::Wait(GetCompositor()); } | 158 void WaitForDraw() { |
| 159 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor()); |
| 160 } |
| 161 |
| 162 void WaitForSwap() { |
| 163 DrawWaiterForTest::WaitForCompositingEnded(GetCompositor()); |
| 164 } |
159 | 165 |
160 void WaitForCommit() { | 166 void WaitForCommit() { |
161 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); | 167 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); |
162 } | 168 } |
163 | 169 |
164 // Invalidates the entire contents of the layer. | 170 // Invalidates the entire contents of the layer. |
165 void SchedulePaintForLayer(Layer* layer) { | 171 void SchedulePaintForLayer(Layer* layer) { |
166 layer->SchedulePaint( | 172 layer->SchedulePaint( |
167 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); | 173 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); |
168 } | 174 } |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 layer->SchedulePaint( | 439 layer->SchedulePaint( |
434 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); | 440 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); |
435 } | 441 } |
436 | 442 |
437 // Invokes DrawTree on the compositor. | 443 // Invokes DrawTree on the compositor. |
438 void Draw() { | 444 void Draw() { |
439 compositor()->ScheduleDraw(); | 445 compositor()->ScheduleDraw(); |
440 WaitForDraw(); | 446 WaitForDraw(); |
441 } | 447 } |
442 | 448 |
443 void WaitForDraw() { DrawWaiterForTest::Wait(compositor()); } | 449 void WaitForDraw() { |
| 450 DrawWaiterForTest::WaitForCompositingStarted(compositor()); |
| 451 } |
444 | 452 |
445 void WaitForCommit() { | 453 void WaitForCommit() { |
446 DrawWaiterForTest::WaitForCommit(compositor()); | 454 DrawWaiterForTest::WaitForCommit(compositor()); |
447 } | 455 } |
448 | 456 |
449 private: | 457 private: |
450 scoped_ptr<TestCompositorHost> compositor_host_; | 458 scoped_ptr<TestCompositorHost> compositor_host_; |
451 | 459 |
452 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); | 460 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); |
453 }; | 461 }; |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 | 1017 |
1010 // ScheduleDraw without any visible change should cause a commit. | 1018 // ScheduleDraw without any visible change should cause a commit. |
1011 observer.Reset(); | 1019 observer.Reset(); |
1012 l1->ScheduleDraw(); | 1020 l1->ScheduleDraw(); |
1013 WaitForCommit(); | 1021 WaitForCommit(); |
1014 EXPECT_TRUE(observer.committed()); | 1022 EXPECT_TRUE(observer.committed()); |
1015 | 1023 |
1016 // Moving, but not resizing, a layer should alert the observers. | 1024 // Moving, but not resizing, a layer should alert the observers. |
1017 observer.Reset(); | 1025 observer.Reset(); |
1018 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); | 1026 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); |
1019 WaitForDraw(); | 1027 WaitForSwap(); |
1020 EXPECT_TRUE(observer.notified()); | 1028 EXPECT_TRUE(observer.notified()); |
1021 | 1029 |
1022 // So should resizing a layer. | 1030 // So should resizing a layer. |
1023 observer.Reset(); | 1031 observer.Reset(); |
1024 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); | 1032 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); |
1025 WaitForDraw(); | 1033 WaitForSwap(); |
1026 EXPECT_TRUE(observer.notified()); | 1034 EXPECT_TRUE(observer.notified()); |
1027 | 1035 |
1028 // Opacity changes should alert the observers. | 1036 // Opacity changes should alert the observers. |
1029 observer.Reset(); | 1037 observer.Reset(); |
1030 l2->SetOpacity(0.5f); | 1038 l2->SetOpacity(0.5f); |
1031 WaitForDraw(); | 1039 WaitForSwap(); |
1032 EXPECT_TRUE(observer.notified()); | 1040 EXPECT_TRUE(observer.notified()); |
1033 | 1041 |
1034 // So should setting the opacity back. | 1042 // So should setting the opacity back. |
1035 observer.Reset(); | 1043 observer.Reset(); |
1036 l2->SetOpacity(1.0f); | 1044 l2->SetOpacity(1.0f); |
1037 WaitForDraw(); | 1045 WaitForSwap(); |
1038 EXPECT_TRUE(observer.notified()); | 1046 EXPECT_TRUE(observer.notified()); |
1039 | 1047 |
1040 // Setting the transform of a layer should alert the observers. | 1048 // Setting the transform of a layer should alert the observers. |
1041 observer.Reset(); | 1049 observer.Reset(); |
1042 gfx::Transform transform; | 1050 gfx::Transform transform; |
1043 transform.Translate(200.0, 200.0); | 1051 transform.Translate(200.0, 200.0); |
1044 transform.Rotate(90.0); | 1052 transform.Rotate(90.0); |
1045 transform.Translate(-200.0, -200.0); | 1053 transform.Translate(-200.0, -200.0); |
1046 l2->SetTransform(transform); | 1054 l2->SetTransform(transform); |
1047 WaitForDraw(); | 1055 WaitForSwap(); |
1048 EXPECT_TRUE(observer.notified()); | 1056 EXPECT_TRUE(observer.notified()); |
1049 | 1057 |
1050 // A change resulting in an aborted swap buffer should alert the observer | 1058 // A change resulting in an aborted swap buffer should alert the observer |
1051 // and also signal an abort. | 1059 // and also signal an abort. |
1052 observer.Reset(); | 1060 observer.Reset(); |
1053 l2->SetOpacity(0.1f); | 1061 l2->SetOpacity(0.1f); |
1054 GetCompositor()->DidAbortSwapBuffers(); | 1062 GetCompositor()->DidAbortSwapBuffers(); |
1055 WaitForDraw(); | 1063 WaitForSwap(); |
1056 EXPECT_TRUE(observer.notified()); | 1064 EXPECT_TRUE(observer.notified()); |
1057 EXPECT_TRUE(observer.aborted()); | 1065 EXPECT_TRUE(observer.aborted()); |
1058 | 1066 |
1059 GetCompositor()->RemoveObserver(&observer); | 1067 GetCompositor()->RemoveObserver(&observer); |
1060 | 1068 |
1061 // Opacity changes should no longer alert the removed observer. | 1069 // Opacity changes should no longer alert the removed observer. |
1062 observer.Reset(); | 1070 observer.Reset(); |
1063 l2->SetOpacity(0.5f); | 1071 l2->SetOpacity(0.5f); |
1064 WaitForDraw(); | 1072 WaitForSwap(); |
1065 | 1073 |
1066 EXPECT_FALSE(observer.notified()); | 1074 EXPECT_FALSE(observer.notified()); |
1067 } | 1075 } |
1068 | 1076 |
1069 // Checks that modifying the hierarchy correctly affects final composite. | 1077 // Checks that modifying the hierarchy correctly affects final composite. |
1070 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { | 1078 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { |
1071 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); | 1079 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); |
1072 | 1080 |
1073 // l0 | 1081 // l0 |
1074 // +-l11 | 1082 // +-l11 |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 MakeFrameData(gfx::Size(10, 10)))); | 1739 MakeFrameData(gfx::Size(10, 10)))); |
1732 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); | 1740 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); |
1733 | 1741 |
1734 EXPECT_FALSE(delegate.delegated_frame_damage_called()); | 1742 EXPECT_FALSE(delegate.delegated_frame_damage_called()); |
1735 layer->OnDelegatedFrameDamage(damage_rect); | 1743 layer->OnDelegatedFrameDamage(damage_rect); |
1736 EXPECT_TRUE(delegate.delegated_frame_damage_called()); | 1744 EXPECT_TRUE(delegate.delegated_frame_damage_called()); |
1737 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); | 1745 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); |
1738 } | 1746 } |
1739 | 1747 |
1740 } // namespace ui | 1748 } // namespace ui |
OLD | NEW |