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

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

Issue 134623005: Make SingleThreadProxy a SchedulerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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 unified diff | Download patch | Annotate | Revision Log
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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 virtual ~LayerWithRealCompositorTest() {} 88 virtual ~LayerWithRealCompositorTest() {}
89 89
90 // Overridden from testing::Test: 90 // Overridden from testing::Test:
91 virtual void SetUp() OVERRIDE { 91 virtual void SetUp() OVERRIDE {
92 bool enable_pixel_output = true; 92 bool enable_pixel_output = true;
93 ui::ContextFactory* context_factory = 93 ui::ContextFactory* context_factory =
94 InitializeContextFactoryForTests(enable_pixel_output); 94 InitializeContextFactoryForTests(enable_pixel_output);
95 95
96 const gfx::Rect host_bounds(10, 10, 500, 500); 96 const gfx::Rect host_bounds(10, 10, 500, 500);
97 compositor_host_.reset(TestCompositorHost::Create( 97 compositor_host_.reset(
98 host_bounds, context_factory)); 98 TestCompositorHost::Create(host_bounds, context_factory));
99 compositor_host_->Show(); 99 compositor_host_->Show();
100 } 100 }
101 101
102 virtual void TearDown() OVERRIDE { 102 virtual void TearDown() OVERRIDE {
103 compositor_host_.reset(); 103 compositor_host_.reset();
104 TerminateContextFactoryForTests(); 104 TerminateContextFactoryForTests();
105 } 105 }
106 106
107 Compositor* GetCompositor() { return compositor_host_->GetCompositor(); } 107 Compositor* GetCompositor() { return compositor_host_->GetCompositor(); }
108 108
109 Layer* CreateLayer(LayerType type) { 109 Layer* CreateLayer(LayerType type) {
110 return new Layer(type); 110 return new Layer(type);
111 } 111 }
112 112
113 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 113 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
114 Layer* layer = new ColoredLayer(color); 114 Layer* layer = new ColoredLayer(color);
115 layer->SetBounds(bounds); 115 layer->SetBounds(bounds);
116 return layer; 116 return layer;
117 } 117 }
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 bool ReadPixels(SkBitmap* bitmap) { 131 bool ReadPixels(SkBitmap* bitmap) {
132 return ReadPixels(bitmap, gfx::Rect(GetCompositor()->size())); 132 return ReadPixels(bitmap, gfx::Rect(GetCompositor()->size()));
133 } 133 }
134 134
135 bool ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) { 135 bool 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. The copy output request will get committed
145 // be in the middle of a draw right now, and the commit with the 145 // before the first draw, but may not be part of the first draw's frame.
146 // copy output request may not be done on the first draw. 146 // The second draw will perform the async copy request, post the callback.
147 for (int i = 0; i < 2; i++) { 147 // The second loop finishes before the callback is run, so a third
148 GetCompositor()->ScheduleDraw(); 148 // loop is needed.
149 for (int i = 0; i < 3; i++) {
150 GetCompositor()->ScheduleFullRedraw();
149 WaitForDraw(); 151 WaitForDraw();
150 } 152 }
151 153
152 if (holder->completed()) { 154 if (holder->completed()) {
153 *bitmap = holder->result(); 155 *bitmap = holder->result();
154 return true; 156 return true;
155 } 157 }
156 158
157 // Callback never called. 159 // Callback never called.
158 NOTREACHED(); 160 NOTREACHED();
159 return false; 161 return false;
160 } 162 }
161 163
162 void WaitForDraw() { 164 void WaitForDraw() {
163 ui::DrawWaiterForTest::Wait(GetCompositor()); 165 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor());
166 }
167
168 void WaitForSwap() {
169 DrawWaiterForTest::WaitForCompositingEnded(GetCompositor());
164 } 170 }
165 171
166 void WaitForCommit() { 172 void WaitForCommit() {
167 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); 173 ui::DrawWaiterForTest::WaitForCommit(GetCompositor());
168 } 174 }
169 175
170 // Invalidates the entire contents of the layer. 176 // Invalidates the entire contents of the layer.
171 void SchedulePaintForLayer(Layer* layer) { 177 void SchedulePaintForLayer(Layer* layer) {
172 layer->SchedulePaint( 178 layer->SchedulePaint(
173 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 179 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 448 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
443 } 449 }
444 450
445 // Invokes DrawTree on the compositor. 451 // Invokes DrawTree on the compositor.
446 void Draw() { 452 void Draw() {
447 compositor()->ScheduleDraw(); 453 compositor()->ScheduleDraw();
448 WaitForDraw(); 454 WaitForDraw();
449 } 455 }
450 456
451 void WaitForDraw() { 457 void WaitForDraw() {
452 DrawWaiterForTest::Wait(compositor()); 458 DrawWaiterForTest::WaitForCompositingStarted(compositor());
453 } 459 }
454 460
455 void WaitForCommit() { 461 void WaitForCommit() {
456 DrawWaiterForTest::WaitForCommit(compositor()); 462 DrawWaiterForTest::WaitForCommit(compositor());
457 } 463 }
458 464
459 private: 465 private:
460 scoped_ptr<TestCompositorHost> compositor_host_; 466 scoped_ptr<TestCompositorHost> compositor_host_;
461 467
462 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 468 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 943
938 // ScheduleDraw without any visible change should cause a commit. 944 // ScheduleDraw without any visible change should cause a commit.
939 observer.Reset(); 945 observer.Reset();
940 l1->ScheduleDraw(); 946 l1->ScheduleDraw();
941 WaitForCommit(); 947 WaitForCommit();
942 EXPECT_TRUE(observer.committed()); 948 EXPECT_TRUE(observer.committed());
943 949
944 // Moving, but not resizing, a layer should alert the observers. 950 // Moving, but not resizing, a layer should alert the observers.
945 observer.Reset(); 951 observer.Reset();
946 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); 952 l2->SetBounds(gfx::Rect(0, 0, 350, 350));
947 WaitForDraw(); 953 WaitForSwap();
948 EXPECT_TRUE(observer.notified()); 954 EXPECT_TRUE(observer.notified());
949 955
950 // So should resizing a layer. 956 // So should resizing a layer.
951 observer.Reset(); 957 observer.Reset();
952 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); 958 l2->SetBounds(gfx::Rect(0, 0, 400, 400));
953 WaitForDraw(); 959 WaitForSwap();
954 EXPECT_TRUE(observer.notified()); 960 EXPECT_TRUE(observer.notified());
955 961
956 // Opacity changes should alert the observers. 962 // Opacity changes should alert the observers.
957 observer.Reset(); 963 observer.Reset();
958 l2->SetOpacity(0.5f); 964 l2->SetOpacity(0.5f);
959 WaitForDraw(); 965 WaitForSwap();
960 EXPECT_TRUE(observer.notified()); 966 EXPECT_TRUE(observer.notified());
961 967
962 // So should setting the opacity back. 968 // So should setting the opacity back.
963 observer.Reset(); 969 observer.Reset();
964 l2->SetOpacity(1.0f); 970 l2->SetOpacity(1.0f);
965 WaitForDraw(); 971 WaitForSwap();
966 EXPECT_TRUE(observer.notified()); 972 EXPECT_TRUE(observer.notified());
967 973
968 // Setting the transform of a layer should alert the observers. 974 // Setting the transform of a layer should alert the observers.
969 observer.Reset(); 975 observer.Reset();
970 gfx::Transform transform; 976 gfx::Transform transform;
971 transform.Translate(200.0, 200.0); 977 transform.Translate(200.0, 200.0);
972 transform.Rotate(90.0); 978 transform.Rotate(90.0);
973 transform.Translate(-200.0, -200.0); 979 transform.Translate(-200.0, -200.0);
974 l2->SetTransform(transform); 980 l2->SetTransform(transform);
975 WaitForDraw(); 981 WaitForSwap();
976 EXPECT_TRUE(observer.notified()); 982 EXPECT_TRUE(observer.notified());
977 983
978 // A change resulting in an aborted swap buffer should alert the observer 984 // A change resulting in an aborted swap buffer should alert the observer
979 // and also signal an abort. 985 // and also signal an abort.
980 observer.Reset(); 986 observer.Reset();
981 l2->SetOpacity(0.1f); 987 l2->SetOpacity(0.1f);
982 GetCompositor()->DidAbortSwapBuffers(); 988 GetCompositor()->DidAbortSwapBuffers();
983 WaitForDraw(); 989 WaitForSwap();
984 EXPECT_TRUE(observer.notified()); 990 EXPECT_TRUE(observer.notified());
985 EXPECT_TRUE(observer.aborted()); 991 EXPECT_TRUE(observer.aborted());
986 992
987 GetCompositor()->RemoveObserver(&observer); 993 GetCompositor()->RemoveObserver(&observer);
988 994
989 // Opacity changes should no longer alert the removed observer. 995 // Opacity changes should no longer alert the removed observer.
990 observer.Reset(); 996 observer.Reset();
991 l2->SetOpacity(0.5f); 997 l2->SetOpacity(0.5f);
992 WaitForDraw(); 998 WaitForSwap();
993 999
994 EXPECT_FALSE(observer.notified()); 1000 EXPECT_FALSE(observer.notified());
995 } 1001 }
996 1002
997 // Checks that modifying the hierarchy correctly affects final composite. 1003 // Checks that modifying the hierarchy correctly affects final composite.
998 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { 1004 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) {
999 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); 1005 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
1000 1006
1001 // l0 1007 // l0
1002 // +-l11 1008 // +-l11
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 1554
1549 child->SetAnimator(LayerAnimator::CreateImplicitAnimator()); 1555 child->SetAnimator(LayerAnimator::CreateImplicitAnimator());
1550 child->SetOpacity(0.5f); 1556 child->SetOpacity(0.5f);
1551 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators()); 1557 EXPECT_TRUE(compositor()->layer_animator_collection()->HasActiveAnimators());
1552 1558
1553 child.reset(); 1559 child.reset();
1554 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators()); 1560 EXPECT_FALSE(compositor()->layer_animator_collection()->HasActiveAnimators());
1555 } 1561 }
1556 1562
1557 } // namespace ui 1563 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698