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

Side by Side Diff: ui/compositor/layer_unittest.cc

Issue 638653003: Make ui::Compositor use ui::Scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mv DCHECK from DidCommit to BeginFrame Created 6 years, 2 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 unified diff | Download patch
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { 123 Layer* CreateNoTextureLayer(const gfx::Rect& bounds) {
124 Layer* layer = CreateLayer(LAYER_NOT_DRAWN); 124 Layer* layer = CreateLayer(LAYER_NOT_DRAWN);
125 layer->SetBounds(bounds); 125 layer->SetBounds(bounds);
126 return layer; 126 return layer;
127 } 127 }
128 128
129 void DrawTree(Layer* root) { 129 void DrawTree(Layer* root) {
130 GetCompositor()->SetRootLayer(root); 130 GetCompositor()->SetRootLayer(root);
131 GetCompositor()->ScheduleDraw(); 131 GetCompositor()->ScheduleDraw();
132 WaitForDraw(); 132 WaitForSwap();
133 } 133 }
134 134
135 void ReadPixels(SkBitmap* bitmap) { 135 void ReadPixels(SkBitmap* bitmap) {
136 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); 136 ReadPixels(bitmap, gfx::Rect(GetCompositor()->size()));
137 } 137 }
138 138
139 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { 139 void ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) {
140 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder); 140 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder);
141 scoped_ptr<cc::CopyOutputRequest> request = 141 scoped_ptr<cc::CopyOutputRequest> request =
142 cc::CopyOutputRequest::CreateBitmapRequest( 142 cc::CopyOutputRequest::CreateBitmapRequest(
143 base::Bind(&ReadbackHolder::OutputRequestCallback, holder)); 143 base::Bind(&ReadbackHolder::OutputRequestCallback, holder));
144 request->set_area(source_rect); 144 request->set_area(source_rect);
145 145
146 GetCompositor()->root_layer()->RequestCopyOfOutput(request.Pass()); 146 GetCompositor()->root_layer()->RequestCopyOfOutput(request.Pass());
147 147
148 // Wait for copy response. This needs to wait as the compositor could 148 // Wait for copy response. This needs to wait as the compositor could
149 // be in the middle of a draw right now, and the commit with the 149 // be in the middle of a draw right now, and the commit with the
150 // copy output request may not be done on the first draw. 150 // copy output request may not be done on the first draw.
151 for (int i = 0; i < 2; i++) { 151 for (int i = 0; i < 2; i++) {
152 GetCompositor()->ScheduleDraw(); 152 GetCompositor()->ScheduleFullRedraw();
153 WaitForDraw(); 153 WaitForDraw();
154 } 154 }
155 155
156 // Waits for the callback to finish run and return result. 156 // Waits for the callback to finish run and return result.
157 holder->WaitForReadback(); 157 holder->WaitForReadback();
158 158
159 *bitmap = holder->result(); 159 *bitmap = holder->result();
160 } 160 }
161 161
162 void WaitForDraw() { ui::DrawWaiterForTest::Wait(GetCompositor()); } 162 void WaitForDraw() {
163 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor());
164 }
165
166 void WaitForSwap() {
167 DrawWaiterForTest::WaitForCompositingEnded(GetCompositor());
168 }
163 169
164 void WaitForCommit() { 170 void WaitForCommit() {
165 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); 171 ui::DrawWaiterForTest::WaitForCommit(GetCompositor());
166 } 172 }
167 173
168 // Invalidates the entire contents of the layer. 174 // Invalidates the entire contents of the layer.
169 void SchedulePaintForLayer(Layer* layer) { 175 void SchedulePaintForLayer(Layer* layer) {
170 layer->SchedulePaint( 176 layer->SchedulePaint(
171 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 177 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
172 } 178 }
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 layer->SchedulePaint( 450 layer->SchedulePaint(
445 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 451 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
446 } 452 }
447 453
448 // Invokes DrawTree on the compositor. 454 // Invokes DrawTree on the compositor.
449 void Draw() { 455 void Draw() {
450 compositor()->ScheduleDraw(); 456 compositor()->ScheduleDraw();
451 WaitForDraw(); 457 WaitForDraw();
452 } 458 }
453 459
454 void WaitForDraw() { DrawWaiterForTest::Wait(compositor()); } 460 void WaitForDraw() {
461 DrawWaiterForTest::WaitForCompositingStarted(compositor());
462 }
455 463
456 void WaitForCommit() { 464 void WaitForCommit() {
457 DrawWaiterForTest::WaitForCommit(compositor()); 465 DrawWaiterForTest::WaitForCommit(compositor());
458 } 466 }
459 467
460 private: 468 private:
461 scoped_ptr<TestCompositorHost> compositor_host_; 469 scoped_ptr<TestCompositorHost> compositor_host_;
462 470
463 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 471 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
464 }; 472 };
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 1028
1021 // ScheduleDraw without any visible change should cause a commit. 1029 // ScheduleDraw without any visible change should cause a commit.
1022 observer.Reset(); 1030 observer.Reset();
1023 l1->ScheduleDraw(); 1031 l1->ScheduleDraw();
1024 WaitForCommit(); 1032 WaitForCommit();
1025 EXPECT_TRUE(observer.committed()); 1033 EXPECT_TRUE(observer.committed());
1026 1034
1027 // Moving, but not resizing, a layer should alert the observers. 1035 // Moving, but not resizing, a layer should alert the observers.
1028 observer.Reset(); 1036 observer.Reset();
1029 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); 1037 l2->SetBounds(gfx::Rect(0, 0, 350, 350));
1030 WaitForDraw(); 1038 WaitForSwap();
1031 EXPECT_TRUE(observer.notified()); 1039 EXPECT_TRUE(observer.notified());
1032 1040
1033 // So should resizing a layer. 1041 // So should resizing a layer.
1034 observer.Reset(); 1042 observer.Reset();
1035 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); 1043 l2->SetBounds(gfx::Rect(0, 0, 400, 400));
1036 WaitForDraw(); 1044 WaitForSwap();
1037 EXPECT_TRUE(observer.notified()); 1045 EXPECT_TRUE(observer.notified());
1038 1046
1039 // Opacity changes should alert the observers. 1047 // Opacity changes should alert the observers.
1040 observer.Reset(); 1048 observer.Reset();
1041 l2->SetOpacity(0.5f); 1049 l2->SetOpacity(0.5f);
1042 WaitForDraw(); 1050 WaitForSwap();
1043 EXPECT_TRUE(observer.notified()); 1051 EXPECT_TRUE(observer.notified());
1044 1052
1045 // So should setting the opacity back. 1053 // So should setting the opacity back.
1046 observer.Reset(); 1054 observer.Reset();
1047 l2->SetOpacity(1.0f); 1055 l2->SetOpacity(1.0f);
1048 WaitForDraw(); 1056 WaitForSwap();
1049 EXPECT_TRUE(observer.notified()); 1057 EXPECT_TRUE(observer.notified());
1050 1058
1051 // Setting the transform of a layer should alert the observers. 1059 // Setting the transform of a layer should alert the observers.
1052 observer.Reset(); 1060 observer.Reset();
1053 gfx::Transform transform; 1061 gfx::Transform transform;
1054 transform.Translate(200.0, 200.0); 1062 transform.Translate(200.0, 200.0);
1055 transform.Rotate(90.0); 1063 transform.Rotate(90.0);
1056 transform.Translate(-200.0, -200.0); 1064 transform.Translate(-200.0, -200.0);
1057 l2->SetTransform(transform); 1065 l2->SetTransform(transform);
1058 WaitForDraw(); 1066 WaitForSwap();
1059 EXPECT_TRUE(observer.notified()); 1067 EXPECT_TRUE(observer.notified());
1060 1068
1061 // A change resulting in an aborted swap buffer should alert the observer 1069 // A change resulting in an aborted swap buffer should alert the observer
1062 // and also signal an abort. 1070 // and also signal an abort.
1063 observer.Reset(); 1071 observer.Reset();
1064 l2->SetOpacity(0.1f); 1072 l2->SetOpacity(0.1f);
1065 GetCompositor()->DidAbortSwapBuffers(); 1073 GetCompositor()->DidAbortSwapBuffers();
1066 WaitForDraw(); 1074 WaitForSwap();
1067 EXPECT_TRUE(observer.notified()); 1075 EXPECT_TRUE(observer.notified());
1068 EXPECT_TRUE(observer.aborted()); 1076 EXPECT_TRUE(observer.aborted());
1069 1077
1070 GetCompositor()->RemoveObserver(&observer); 1078 GetCompositor()->RemoveObserver(&observer);
1071 1079
1072 // Opacity changes should no longer alert the removed observer. 1080 // Opacity changes should no longer alert the removed observer.
1073 observer.Reset(); 1081 observer.Reset();
1074 l2->SetOpacity(0.5f); 1082 l2->SetOpacity(0.5f);
1075 WaitForDraw(); 1083 WaitForSwap();
1076 1084
1077 EXPECT_FALSE(observer.notified()); 1085 EXPECT_FALSE(observer.notified());
1078 } 1086 }
1079 1087
1080 // Checks that modifying the hierarchy correctly affects final composite. 1088 // Checks that modifying the hierarchy correctly affects final composite.
1081 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { 1089 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) {
1082 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); 1090 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
1083 1091
1084 // l0 1092 // l0
1085 // +-l11 1093 // +-l11
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 MakeFrameData(gfx::Size(10, 10)))); 1753 MakeFrameData(gfx::Size(10, 10))));
1746 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); 1754 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10));
1747 1755
1748 EXPECT_FALSE(delegate.delegated_frame_damage_called()); 1756 EXPECT_FALSE(delegate.delegated_frame_damage_called());
1749 layer->OnDelegatedFrameDamage(damage_rect); 1757 layer->OnDelegatedFrameDamage(damage_rect);
1750 EXPECT_TRUE(delegate.delegated_frame_damage_called()); 1758 EXPECT_TRUE(delegate.delegated_frame_damage_called());
1751 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); 1759 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect());
1752 } 1760 }
1753 1761
1754 } // namespace ui 1762 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698