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

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

Issue 448713002: Revert of Make SingleThreadProxy a SchedulerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« no previous file with comments | « ui/compositor/compositor.cc ('k') | ui/compositor/test/draw_waiter_for_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 88 }
89 virtual ~LayerWithRealCompositorTest() {} 89 virtual ~LayerWithRealCompositorTest() {}
90 90
91 // Overridden from testing::Test: 91 // Overridden from testing::Test:
92 virtual void SetUp() OVERRIDE { 92 virtual void SetUp() OVERRIDE {
93 bool enable_pixel_output = true; 93 bool enable_pixel_output = true;
94 ui::ContextFactory* context_factory = 94 ui::ContextFactory* context_factory =
95 InitializeContextFactoryForTests(enable_pixel_output); 95 InitializeContextFactoryForTests(enable_pixel_output);
96 96
97 const gfx::Rect host_bounds(10, 10, 500, 500); 97 const gfx::Rect host_bounds(10, 10, 500, 500);
98 compositor_host_.reset( 98 compositor_host_.reset(TestCompositorHost::Create(
99 TestCompositorHost::Create(host_bounds, context_factory)); 99 host_bounds, context_factory));
100 compositor_host_->Show(); 100 compositor_host_->Show();
101 } 101 }
102 102
103 virtual void TearDown() OVERRIDE { 103 virtual void TearDown() OVERRIDE {
104 compositor_host_.reset(); 104 compositor_host_.reset();
105 TerminateContextFactoryForTests(); 105 TerminateContextFactoryForTests();
106 } 106 }
107 107
108 Compositor* GetCompositor() { return compositor_host_->GetCompositor(); } 108 Compositor* GetCompositor() { return compositor_host_->GetCompositor(); }
109 109
110 Layer* CreateLayer(LayerType type) { 110 Layer* CreateLayer(LayerType type) {
111 return new Layer(type); 111 return new Layer(type);
112 } 112 }
113 113
114 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) { 114 Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
115 Layer* layer = new ColoredLayer(color); 115 Layer* layer = new ColoredLayer(color);
116 layer->SetBounds(bounds); 116 layer->SetBounds(bounds);
117 return layer; 117 return layer;
118 } 118 }
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() {
166 ui::DrawWaiterForTest::WaitForCompositingStarted(GetCompositor()); 164 ui::DrawWaiterForTest::Wait(GetCompositor());
167 }
168
169 void WaitForSwap() {
170 DrawWaiterForTest::WaitForCompositingEnded(GetCompositor());
171 } 165 }
172 166
173 void WaitForCommit() { 167 void WaitForCommit() {
174 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); 168 ui::DrawWaiterForTest::WaitForCommit(GetCompositor());
175 } 169 }
176 170
177 // Invalidates the entire contents of the layer. 171 // Invalidates the entire contents of the layer.
178 void SchedulePaintForLayer(Layer* layer) { 172 void SchedulePaintForLayer(Layer* layer) {
179 layer->SchedulePaint( 173 layer->SchedulePaint(
180 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 174 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 443 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
450 } 444 }
451 445
452 // Invokes DrawTree on the compositor. 446 // Invokes DrawTree on the compositor.
453 void Draw() { 447 void Draw() {
454 compositor()->ScheduleDraw(); 448 compositor()->ScheduleDraw();
455 WaitForDraw(); 449 WaitForDraw();
456 } 450 }
457 451
458 void WaitForDraw() { 452 void WaitForDraw() {
459 DrawWaiterForTest::WaitForCompositingStarted(compositor()); 453 DrawWaiterForTest::Wait(compositor());
460 } 454 }
461 455
462 void WaitForCommit() { 456 void WaitForCommit() {
463 DrawWaiterForTest::WaitForCommit(compositor()); 457 DrawWaiterForTest::WaitForCommit(compositor());
464 } 458 }
465 459
466 private: 460 private:
467 scoped_ptr<TestCompositorHost> compositor_host_; 461 scoped_ptr<TestCompositorHost> compositor_host_;
468 462
469 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 463 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 938
945 // ScheduleDraw without any visible change should cause a commit. 939 // ScheduleDraw without any visible change should cause a commit.
946 observer.Reset(); 940 observer.Reset();
947 l1->ScheduleDraw(); 941 l1->ScheduleDraw();
948 WaitForCommit(); 942 WaitForCommit();
949 EXPECT_TRUE(observer.committed()); 943 EXPECT_TRUE(observer.committed());
950 944
951 // Moving, but not resizing, a layer should alert the observers. 945 // Moving, but not resizing, a layer should alert the observers.
952 observer.Reset(); 946 observer.Reset();
953 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); 947 l2->SetBounds(gfx::Rect(0, 0, 350, 350));
954 WaitForSwap(); 948 WaitForDraw();
955 EXPECT_TRUE(observer.notified()); 949 EXPECT_TRUE(observer.notified());
956 950
957 // So should resizing a layer. 951 // So should resizing a layer.
958 observer.Reset(); 952 observer.Reset();
959 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); 953 l2->SetBounds(gfx::Rect(0, 0, 400, 400));
960 WaitForSwap(); 954 WaitForDraw();
961 EXPECT_TRUE(observer.notified()); 955 EXPECT_TRUE(observer.notified());
962 956
963 // Opacity changes should alert the observers. 957 // Opacity changes should alert the observers.
964 observer.Reset(); 958 observer.Reset();
965 l2->SetOpacity(0.5f); 959 l2->SetOpacity(0.5f);
966 WaitForSwap(); 960 WaitForDraw();
967 EXPECT_TRUE(observer.notified()); 961 EXPECT_TRUE(observer.notified());
968 962
969 // So should setting the opacity back. 963 // So should setting the opacity back.
970 observer.Reset(); 964 observer.Reset();
971 l2->SetOpacity(1.0f); 965 l2->SetOpacity(1.0f);
972 WaitForSwap(); 966 WaitForDraw();
973 EXPECT_TRUE(observer.notified()); 967 EXPECT_TRUE(observer.notified());
974 968
975 // Setting the transform of a layer should alert the observers. 969 // Setting the transform of a layer should alert the observers.
976 observer.Reset(); 970 observer.Reset();
977 gfx::Transform transform; 971 gfx::Transform transform;
978 transform.Translate(200.0, 200.0); 972 transform.Translate(200.0, 200.0);
979 transform.Rotate(90.0); 973 transform.Rotate(90.0);
980 transform.Translate(-200.0, -200.0); 974 transform.Translate(-200.0, -200.0);
981 l2->SetTransform(transform); 975 l2->SetTransform(transform);
982 WaitForSwap(); 976 WaitForDraw();
983 EXPECT_TRUE(observer.notified()); 977 EXPECT_TRUE(observer.notified());
984 978
985 // A change resulting in an aborted swap buffer should alert the observer 979 // A change resulting in an aborted swap buffer should alert the observer
986 // and also signal an abort. 980 // and also signal an abort.
987 observer.Reset(); 981 observer.Reset();
988 l2->SetOpacity(0.1f); 982 l2->SetOpacity(0.1f);
989 GetCompositor()->DidAbortSwapBuffers(); 983 GetCompositor()->DidAbortSwapBuffers();
990 WaitForSwap(); 984 WaitForDraw();
991 EXPECT_TRUE(observer.notified()); 985 EXPECT_TRUE(observer.notified());
992 EXPECT_TRUE(observer.aborted()); 986 EXPECT_TRUE(observer.aborted());
993 987
994 GetCompositor()->RemoveObserver(&observer); 988 GetCompositor()->RemoveObserver(&observer);
995 989
996 // Opacity changes should no longer alert the removed observer. 990 // Opacity changes should no longer alert the removed observer.
997 observer.Reset(); 991 observer.Reset();
998 l2->SetOpacity(0.5f); 992 l2->SetOpacity(0.5f);
999 WaitForSwap(); 993 WaitForDraw();
1000 994
1001 EXPECT_FALSE(observer.notified()); 995 EXPECT_FALSE(observer.notified());
1002 } 996 }
1003 997
1004 // Checks that modifying the hierarchy correctly affects final composite. 998 // Checks that modifying the hierarchy correctly affects final composite.
1005 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { 999 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) {
1006 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); 1000 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
1007 1001
1008 // l0 1002 // l0
1009 // +-l11 1003 // +-l11
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 1589
1596 c11->SetBounds(gfx::Rect(2, 2, 10, 10)); 1590 c11->SetBounds(gfx::Rect(2, 2, 10, 10));
1597 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get()); 1591 SnapLayerToPhysicalPixelBoundary(root.get(), c11.get());
1598 // c11 is now off the pixel. 1592 // c11 is now off the pixel.
1599 // 0.5 / 1.5 = 0.333... 1593 // 0.5 / 1.5 = 0.333...
1600 EXPECT_EQ("0.33 0.33", 1594 EXPECT_EQ("0.33 0.33",
1601 Vector2dFTo100thPercisionString(c11->subpixel_position_offset())); 1595 Vector2dFTo100thPercisionString(c11->subpixel_position_offset()));
1602 } 1596 }
1603 1597
1604 } // namespace ui 1598 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor.cc ('k') | ui/compositor/test/draw_waiter_for_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698