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

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: rebase Created 5 years, 10 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
« no previous file with comments | « ui/compositor/compositor.cc ('k') | ui/compositor/test/context_factories_for_test.cc » ('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/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 layer->SchedulePaint( 441 layer->SchedulePaint(
436 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 442 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
437 } 443 }
438 444
439 // Invokes DrawTree on the compositor. 445 // Invokes DrawTree on the compositor.
440 void Draw() { 446 void Draw() {
441 compositor()->ScheduleDraw(); 447 compositor()->ScheduleDraw();
442 WaitForDraw(); 448 WaitForDraw();
443 } 449 }
444 450
445 void WaitForDraw() { DrawWaiterForTest::Wait(compositor()); } 451 void WaitForDraw() {
452 DrawWaiterForTest::WaitForCompositingStarted(compositor());
453 }
446 454
447 void WaitForCommit() { 455 void WaitForCommit() {
448 DrawWaiterForTest::WaitForCommit(compositor()); 456 DrawWaiterForTest::WaitForCommit(compositor());
449 } 457 }
450 458
451 private: 459 private:
452 scoped_ptr<TestCompositorHost> compositor_host_; 460 scoped_ptr<TestCompositorHost> compositor_host_;
453 461
454 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest); 462 DISALLOW_COPY_AND_ASSIGN(LayerWithDelegateTest);
455 }; 463 };
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 1019
1012 // ScheduleDraw without any visible change should cause a commit. 1020 // ScheduleDraw without any visible change should cause a commit.
1013 observer.Reset(); 1021 observer.Reset();
1014 l1->ScheduleDraw(); 1022 l1->ScheduleDraw();
1015 WaitForCommit(); 1023 WaitForCommit();
1016 EXPECT_TRUE(observer.committed()); 1024 EXPECT_TRUE(observer.committed());
1017 1025
1018 // Moving, but not resizing, a layer should alert the observers. 1026 // Moving, but not resizing, a layer should alert the observers.
1019 observer.Reset(); 1027 observer.Reset();
1020 l2->SetBounds(gfx::Rect(0, 0, 350, 350)); 1028 l2->SetBounds(gfx::Rect(0, 0, 350, 350));
1021 WaitForDraw(); 1029 WaitForSwap();
1022 EXPECT_TRUE(observer.notified()); 1030 EXPECT_TRUE(observer.notified());
1023 1031
1024 // So should resizing a layer. 1032 // So should resizing a layer.
1025 observer.Reset(); 1033 observer.Reset();
1026 l2->SetBounds(gfx::Rect(0, 0, 400, 400)); 1034 l2->SetBounds(gfx::Rect(0, 0, 400, 400));
1027 WaitForDraw(); 1035 WaitForSwap();
1028 EXPECT_TRUE(observer.notified()); 1036 EXPECT_TRUE(observer.notified());
1029 1037
1030 // Opacity changes should alert the observers. 1038 // Opacity changes should alert the observers.
1031 observer.Reset(); 1039 observer.Reset();
1032 l2->SetOpacity(0.5f); 1040 l2->SetOpacity(0.5f);
1033 WaitForDraw(); 1041 WaitForSwap();
1034 EXPECT_TRUE(observer.notified()); 1042 EXPECT_TRUE(observer.notified());
1035 1043
1036 // So should setting the opacity back. 1044 // So should setting the opacity back.
1037 observer.Reset(); 1045 observer.Reset();
1038 l2->SetOpacity(1.0f); 1046 l2->SetOpacity(1.0f);
1039 WaitForDraw(); 1047 WaitForSwap();
1040 EXPECT_TRUE(observer.notified()); 1048 EXPECT_TRUE(observer.notified());
1041 1049
1042 // Setting the transform of a layer should alert the observers. 1050 // Setting the transform of a layer should alert the observers.
1043 observer.Reset(); 1051 observer.Reset();
1044 gfx::Transform transform; 1052 gfx::Transform transform;
1045 transform.Translate(200.0, 200.0); 1053 transform.Translate(200.0, 200.0);
1046 transform.Rotate(90.0); 1054 transform.Rotate(90.0);
1047 transform.Translate(-200.0, -200.0); 1055 transform.Translate(-200.0, -200.0);
1048 l2->SetTransform(transform); 1056 l2->SetTransform(transform);
1049 WaitForDraw(); 1057 WaitForSwap();
1050 EXPECT_TRUE(observer.notified()); 1058 EXPECT_TRUE(observer.notified());
1051 1059
1052 // A change resulting in an aborted swap buffer should alert the observer 1060 // A change resulting in an aborted swap buffer should alert the observer
1053 // and also signal an abort. 1061 // and also signal an abort.
1054 observer.Reset(); 1062 observer.Reset();
1055 l2->SetOpacity(0.1f); 1063 l2->SetOpacity(0.1f);
1056 GetCompositor()->DidAbortSwapBuffers(); 1064 GetCompositor()->DidAbortSwapBuffers();
1057 WaitForDraw(); 1065 WaitForSwap();
1058 EXPECT_TRUE(observer.notified()); 1066 EXPECT_TRUE(observer.notified());
1059 EXPECT_TRUE(observer.aborted()); 1067 EXPECT_TRUE(observer.aborted());
1060 1068
1061 GetCompositor()->RemoveObserver(&observer); 1069 GetCompositor()->RemoveObserver(&observer);
1062 1070
1063 // Opacity changes should no longer alert the removed observer. 1071 // Opacity changes should no longer alert the removed observer.
1064 observer.Reset(); 1072 observer.Reset();
1065 l2->SetOpacity(0.5f); 1073 l2->SetOpacity(0.5f);
1066 WaitForDraw(); 1074 WaitForSwap();
1067 1075
1068 EXPECT_FALSE(observer.notified()); 1076 EXPECT_FALSE(observer.notified());
1069 } 1077 }
1070 1078
1071 // Checks that modifying the hierarchy correctly affects final composite. 1079 // Checks that modifying the hierarchy correctly affects final composite.
1072 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { 1080 TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) {
1073 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); 1081 GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50));
1074 1082
1075 // l0 1083 // l0
1076 // +-l11 1084 // +-l11
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 MakeFrameData(gfx::Size(10, 10)))); 1741 MakeFrameData(gfx::Size(10, 10))));
1734 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10)); 1742 layer->SetShowDelegatedContent(frame_provider.get(), gfx::Size(10, 10));
1735 1743
1736 EXPECT_FALSE(delegate.delegated_frame_damage_called()); 1744 EXPECT_FALSE(delegate.delegated_frame_damage_called());
1737 layer->OnDelegatedFrameDamage(damage_rect); 1745 layer->OnDelegatedFrameDamage(damage_rect);
1738 EXPECT_TRUE(delegate.delegated_frame_damage_called()); 1746 EXPECT_TRUE(delegate.delegated_frame_damage_called());
1739 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect()); 1747 EXPECT_EQ(damage_rect, delegate.delegated_frame_damage_rect());
1740 } 1748 }
1741 1749
1742 } // namespace ui 1750 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor.cc ('k') | ui/compositor/test/context_factories_for_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698