| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "cc/output/begin_frame_args.h" | 10 #include "cc/output/begin_frame_args.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST_F(CompositorTest, ReleaseWidgetWithOutputSurfaceNeverCreated) { | 124 TEST_F(CompositorTest, ReleaseWidgetWithOutputSurfaceNeverCreated) { |
| 125 compositor()->SetVisible(false); | 125 compositor()->SetVisible(false); |
| 126 EXPECT_EQ(gfx::kNullAcceleratedWidget, | 126 EXPECT_EQ(gfx::kNullAcceleratedWidget, |
| 127 compositor()->ReleaseAcceleratedWidget()); | 127 compositor()->ReleaseAcceleratedWidget()); |
| 128 compositor()->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 128 compositor()->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 129 compositor()->SetVisible(true); | 129 compositor()->SetVisible(true); |
| 130 } | 130 } |
| 131 | 131 |
| 132 TEST_F(CompositorTest, SurfaceClients) { | |
| 133 const uint32_t kClientId1 = | |
| 134 compositor()->surface_id_allocator()->client_id() + 1; | |
| 135 const uint32_t kClientId2 = | |
| 136 compositor()->surface_id_allocator()->client_id() + 2; | |
| 137 const uint32_t kClientId3 = | |
| 138 compositor()->surface_id_allocator()->client_id() + 3; | |
| 139 cc::SurfaceManager* manager = | |
| 140 compositor()->context_factory()->GetSurfaceManager(); | |
| 141 FakeCompositorFrameSink client1(kClientId1, manager); | |
| 142 FakeCompositorFrameSink client2(kClientId2, manager); | |
| 143 FakeCompositorFrameSink client3(kClientId3, manager); | |
| 144 const uint32_t kNoClient = 0; | |
| 145 | |
| 146 compositor()->AddSurfaceClient(kClientId1); | |
| 147 compositor()->AddSurfaceClient(kClientId2); | |
| 148 compositor()->AddSurfaceClient(kClientId3); | |
| 149 | |
| 150 const std::unordered_map<uint32_t, uint32_t>& surface_clients = | |
| 151 compositor()->SurfaceClientsForTesting(); | |
| 152 EXPECT_EQ(3u, surface_clients.size()); | |
| 153 EXPECT_NE(surface_clients.end(), surface_clients.find(kClientId1)); | |
| 154 EXPECT_NE(surface_clients.end(), surface_clients.find(kClientId2)); | |
| 155 EXPECT_NE(surface_clients.end(), surface_clients.find(kClientId3)); | |
| 156 | |
| 157 // Verify that the clients haven't been assigned a parent compositor yet. | |
| 158 EXPECT_EQ(kNoClient, surface_clients.find(kClientId1)->second); | |
| 159 EXPECT_EQ(kNoClient, surface_clients.find(kClientId2)->second); | |
| 160 EXPECT_EQ(kNoClient, surface_clients.find(kClientId3)->second); | |
| 161 | |
| 162 // This will trigger the creation of an OutputSurface and then | |
| 163 // assignment of a surface hierarchy. | |
| 164 std::unique_ptr<Layer> root_layer(new Layer(ui::LAYER_SOLID_COLOR)); | |
| 165 root_layer->SetBounds(gfx::Rect(10, 10)); | |
| 166 compositor()->SetRootLayer(root_layer.get()); | |
| 167 compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10)); | |
| 168 compositor()->SetVisible(true); | |
| 169 compositor()->ScheduleDraw(); | |
| 170 DrawWaiterForTest::WaitForCompositingEnded(compositor()); | |
| 171 | |
| 172 // Verify that the clients have been assigned a parent compositor. | |
| 173 EXPECT_EQ(compositor()->surface_id_allocator()->client_id(), | |
| 174 surface_clients.find(kClientId1)->second); | |
| 175 EXPECT_EQ(compositor()->surface_id_allocator()->client_id(), | |
| 176 surface_clients.find(kClientId2)->second); | |
| 177 EXPECT_EQ(compositor()->surface_id_allocator()->client_id(), | |
| 178 surface_clients.find(kClientId3)->second); | |
| 179 | |
| 180 // Remove a client while the parent compositor has an OutputSurface. | |
| 181 compositor()->RemoveSurfaceClient(kClientId3); | |
| 182 EXPECT_EQ(surface_clients.end(), surface_clients.find(kClientId3)); | |
| 183 | |
| 184 // This will remove parent compositor from the surface hierarchy. | |
| 185 compositor()->SetVisible(false); | |
| 186 compositor()->ReleaseAcceleratedWidget(); | |
| 187 EXPECT_EQ(kNoClient, surface_clients.find(kClientId1)->second); | |
| 188 EXPECT_EQ(kNoClient, surface_clients.find(kClientId2)->second); | |
| 189 | |
| 190 // Remove a client after the OutputSurface has been dropped. | |
| 191 compositor()->RemoveSurfaceClient(kClientId2); | |
| 192 EXPECT_EQ(surface_clients.end(), surface_clients.find(kClientId2)); | |
| 193 | |
| 194 // The remaining client will be cleared during destruction. | |
| 195 } | |
| 196 | |
| 197 #if defined(OS_WIN) | 132 #if defined(OS_WIN) |
| 198 // TODO(crbug.com/608436): Flaky on windows trybots | 133 // TODO(crbug.com/608436): Flaky on windows trybots |
| 199 #define MAYBE_CreateAndReleaseOutputSurface \ | 134 #define MAYBE_CreateAndReleaseOutputSurface \ |
| 200 DISABLED_CreateAndReleaseOutputSurface | 135 DISABLED_CreateAndReleaseOutputSurface |
| 201 #else | 136 #else |
| 202 #define MAYBE_CreateAndReleaseOutputSurface CreateAndReleaseOutputSurface | 137 #define MAYBE_CreateAndReleaseOutputSurface CreateAndReleaseOutputSurface |
| 203 #endif | 138 #endif |
| 204 TEST_F(CompositorTest, MAYBE_CreateAndReleaseOutputSurface) { | 139 TEST_F(CompositorTest, MAYBE_CreateAndReleaseOutputSurface) { |
| 205 std::unique_ptr<Layer> root_layer(new Layer(ui::LAYER_SOLID_COLOR)); | 140 std::unique_ptr<Layer> root_layer(new Layer(ui::LAYER_SOLID_COLOR)); |
| 206 root_layer->SetBounds(gfx::Rect(10, 10)); | 141 root_layer->SetBounds(gfx::Rect(10, 10)); |
| 207 compositor()->SetRootLayer(root_layer.get()); | 142 compositor()->SetRootLayer(root_layer.get()); |
| 208 compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10)); | 143 compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10)); |
| 209 DCHECK(compositor()->IsVisible()); | 144 DCHECK(compositor()->IsVisible()); |
| 210 compositor()->ScheduleDraw(); | 145 compositor()->ScheduleDraw(); |
| 211 DrawWaiterForTest::WaitForCompositingEnded(compositor()); | 146 DrawWaiterForTest::WaitForCompositingEnded(compositor()); |
| 212 compositor()->SetVisible(false); | 147 compositor()->SetVisible(false); |
| 213 EXPECT_EQ(gfx::kNullAcceleratedWidget, | 148 EXPECT_EQ(gfx::kNullAcceleratedWidget, |
| 214 compositor()->ReleaseAcceleratedWidget()); | 149 compositor()->ReleaseAcceleratedWidget()); |
| 215 compositor()->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 150 compositor()->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 216 compositor()->SetVisible(true); | 151 compositor()->SetVisible(true); |
| 217 compositor()->ScheduleDraw(); | 152 compositor()->ScheduleDraw(); |
| 218 DrawWaiterForTest::WaitForCompositingEnded(compositor()); | 153 DrawWaiterForTest::WaitForCompositingEnded(compositor()); |
| 219 compositor()->SetRootLayer(nullptr); | 154 compositor()->SetRootLayer(nullptr); |
| 220 } | 155 } |
| 221 | 156 |
| 222 } // namespace ui | 157 } // namespace ui |
| OLD | NEW |