OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/raster/raster_buffer_provider.h" | 5 #include "cc/raster/raster_buffer_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <limits> | 11 #include <limits> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "cc/base/unique_notifier.h" | 20 #include "cc/base/unique_notifier.h" |
21 #include "cc/raster/bitmap_raster_buffer_provider.h" | 21 #include "cc/raster/bitmap_raster_buffer_provider.h" |
22 #include "cc/raster/gpu_raster_buffer_provider.h" | 22 #include "cc/raster/gpu_raster_buffer_provider.h" |
23 #include "cc/raster/gpu_rasterizer.h" | |
24 #include "cc/raster/one_copy_raster_buffer_provider.h" | 23 #include "cc/raster/one_copy_raster_buffer_provider.h" |
25 #include "cc/raster/synchronous_task_graph_runner.h" | 24 #include "cc/raster/synchronous_task_graph_runner.h" |
26 #include "cc/raster/zero_copy_raster_buffer_provider.h" | 25 #include "cc/raster/zero_copy_raster_buffer_provider.h" |
| 26 #include "cc/resources/platform_color.h" |
27 #include "cc/resources/resource_pool.h" | 27 #include "cc/resources/resource_pool.h" |
28 #include "cc/resources/resource_provider.h" | 28 #include "cc/resources/resource_provider.h" |
29 #include "cc/resources/scoped_resource.h" | 29 #include "cc/resources/scoped_resource.h" |
30 #include "cc/test/fake_output_surface.h" | 30 #include "cc/test/fake_output_surface.h" |
31 #include "cc/test/fake_output_surface_client.h" | 31 #include "cc/test/fake_output_surface_client.h" |
32 #include "cc/test/fake_raster_source.h" | 32 #include "cc/test/fake_raster_source.h" |
33 #include "cc/test/fake_resource_provider.h" | 33 #include "cc/test/fake_resource_provider.h" |
34 #include "cc/test/test_gpu_memory_buffer_manager.h" | 34 #include "cc/test/test_gpu_memory_buffer_manager.h" |
35 #include "cc/test/test_shared_bitmap_manager.h" | 35 #include "cc/test/test_shared_bitmap_manager.h" |
36 #include "cc/test/test_web_graphics_context_3d.h" | 36 #include "cc/test/test_web_graphics_context_3d.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 worker_context_provider_(TestContextProvider::CreateWorker()), | 149 worker_context_provider_(TestContextProvider::CreateWorker()), |
150 all_tile_tasks_finished_( | 150 all_tile_tasks_finished_( |
151 base::ThreadTaskRunnerHandle::Get().get(), | 151 base::ThreadTaskRunnerHandle::Get().get(), |
152 base::Bind(&RasterBufferProviderTest::AllTileTasksFinished, | 152 base::Bind(&RasterBufferProviderTest::AllTileTasksFinished, |
153 base::Unretained(this))), | 153 base::Unretained(this))), |
154 timeout_seconds_(5), | 154 timeout_seconds_(5), |
155 timed_out_(false) {} | 155 timed_out_(false) {} |
156 | 156 |
157 // Overridden from testing::Test: | 157 // Overridden from testing::Test: |
158 void SetUp() override { | 158 void SetUp() override { |
159 std::unique_ptr<RasterBufferProvider> raster_buffer_provider; | |
160 switch (GetParam()) { | 159 switch (GetParam()) { |
161 case RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY: | 160 case RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY: |
162 Create3dOutputSurfaceAndResourceProvider(); | 161 Create3dOutputSurfaceAndResourceProvider(); |
163 raster_buffer_provider = ZeroCopyRasterBufferProvider::Create( | 162 raster_buffer_provider_ = ZeroCopyRasterBufferProvider::Create( |
164 resource_provider_.get(), PlatformColor::BestTextureFormat()); | 163 resource_provider_.get(), PlatformColor::BestTextureFormat()); |
165 break; | 164 break; |
166 case RASTER_BUFFER_PROVIDER_TYPE_ONE_COPY: | 165 case RASTER_BUFFER_PROVIDER_TYPE_ONE_COPY: |
167 Create3dOutputSurfaceAndResourceProvider(); | 166 Create3dOutputSurfaceAndResourceProvider(); |
168 raster_buffer_provider = base::MakeUnique<OneCopyRasterBufferProvider>( | 167 raster_buffer_provider_ = base::MakeUnique<OneCopyRasterBufferProvider>( |
169 base::ThreadTaskRunnerHandle::Get().get(), context_provider_.get(), | 168 base::ThreadTaskRunnerHandle::Get().get(), context_provider_.get(), |
170 worker_context_provider_.get(), resource_provider_.get(), | 169 worker_context_provider_.get(), resource_provider_.get(), |
171 kMaxBytesPerCopyOperation, false, kMaxStagingBuffers, | 170 kMaxBytesPerCopyOperation, false, kMaxStagingBuffers, |
172 PlatformColor::BestTextureFormat()); | 171 PlatformColor::BestTextureFormat(), false); |
173 break; | 172 break; |
174 case RASTER_BUFFER_PROVIDER_TYPE_GPU: | 173 case RASTER_BUFFER_PROVIDER_TYPE_GPU: |
175 Create3dOutputSurfaceAndResourceProvider(); | 174 Create3dOutputSurfaceAndResourceProvider(); |
176 raster_buffer_provider = base::MakeUnique<GpuRasterBufferProvider>( | 175 raster_buffer_provider_ = base::MakeUnique<GpuRasterBufferProvider>( |
177 context_provider_.get(), worker_context_provider_.get(), | 176 context_provider_.get(), worker_context_provider_.get(), |
178 resource_provider_.get(), false, 0); | 177 resource_provider_.get(), false, 0, false); |
179 break; | 178 break; |
180 case RASTER_BUFFER_PROVIDER_TYPE_BITMAP: | 179 case RASTER_BUFFER_PROVIDER_TYPE_BITMAP: |
181 CreateSoftwareOutputSurfaceAndResourceProvider(); | 180 CreateSoftwareOutputSurfaceAndResourceProvider(); |
182 raster_buffer_provider = | 181 raster_buffer_provider_ = |
183 BitmapRasterBufferProvider::Create(resource_provider_.get()); | 182 BitmapRasterBufferProvider::Create(resource_provider_.get()); |
184 break; | 183 break; |
185 } | 184 } |
186 | 185 |
187 DCHECK(raster_buffer_provider); | 186 DCHECK(raster_buffer_provider_); |
188 | 187 |
189 tile_task_manager_ = TileTaskManagerImpl::Create( | 188 tile_task_manager_ = TileTaskManagerImpl::Create(&task_graph_runner_); |
190 std::move(raster_buffer_provider), &task_graph_runner_); | |
191 } | 189 } |
192 | 190 |
193 void TearDown() override { | 191 void TearDown() override { |
194 tile_task_manager_->Shutdown(); | 192 tile_task_manager_->Shutdown(); |
195 tile_task_manager_->CheckForCompletedTasks(); | 193 tile_task_manager_->CheckForCompletedTasks(); |
| 194 |
| 195 raster_buffer_provider_->Shutdown(); |
196 } | 196 } |
197 | 197 |
198 void AllTileTasksFinished() { | 198 void AllTileTasksFinished() { |
199 tile_task_manager_->CheckForCompletedTasks(); | 199 tile_task_manager_->CheckForCompletedTasks(); |
200 base::MessageLoop::current()->QuitWhenIdle(); | 200 base::MessageLoop::current()->QuitWhenIdle(); |
201 } | 201 } |
202 | 202 |
203 void RunMessageLoopUntilAllTasksHaveCompleted() { | 203 void RunMessageLoopUntilAllTasksHaveCompleted() { |
204 task_graph_runner_.RunUntilIdle(); | 204 task_graph_runner_.RunUntilIdle(); |
205 tile_task_manager_->CheckForCompletedTasks(); | 205 tile_task_manager_->CheckForCompletedTasks(); |
206 } | 206 } |
207 | 207 |
208 void ScheduleTasks() { | 208 void ScheduleTasks() { |
209 graph_.Reset(); | 209 graph_.Reset(); |
210 | 210 |
211 size_t priority = 0; | 211 size_t priority = 0; |
212 | 212 |
213 for (RasterTaskVector::const_iterator it = tasks_.begin(); | 213 for (RasterTaskVector::const_iterator it = tasks_.begin(); |
214 it != tasks_.end(); ++it) { | 214 it != tasks_.end(); ++it) { |
215 graph_.nodes.emplace_back(it->get(), 0 /* group */, priority++, | 215 graph_.nodes.emplace_back(it->get(), 0 /* group */, priority++, |
216 0 /* dependencies */); | 216 0 /* dependencies */); |
217 } | 217 } |
218 | 218 |
| 219 raster_buffer_provider_->OrderingBarrier(); |
219 tile_task_manager_->ScheduleTasks(&graph_); | 220 tile_task_manager_->ScheduleTasks(&graph_); |
220 } | 221 } |
221 | 222 |
222 void AppendTask(unsigned id, const gfx::Size& size) { | 223 void AppendTask(unsigned id, const gfx::Size& size) { |
223 std::unique_ptr<ScopedResource> resource( | 224 std::unique_ptr<ScopedResource> resource( |
224 ScopedResource::Create(resource_provider_.get())); | 225 ScopedResource::Create(resource_provider_.get())); |
225 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 226 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
226 RGBA_8888); | 227 RGBA_8888); |
227 | 228 |
228 // The raster buffer has no tile ids associated with it for partial update, | 229 // The raster buffer has no tile ids associated with it for partial update, |
229 // so doesn't need to provide a valid dirty rect. | 230 // so doesn't need to provide a valid dirty rect. |
230 std::unique_ptr<RasterBuffer> raster_buffer = | 231 std::unique_ptr<RasterBuffer> raster_buffer = |
231 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( | 232 raster_buffer_provider_->AcquireBufferForRaster(resource.get(), 0, 0); |
232 resource.get(), 0, 0); | |
233 TileTask::Vector empty; | 233 TileTask::Vector empty; |
234 tasks_.push_back(new TestRasterTaskImpl(this, std::move(resource), id, | 234 tasks_.push_back(new TestRasterTaskImpl(this, std::move(resource), id, |
235 std::move(raster_buffer), &empty)); | 235 std::move(raster_buffer), &empty)); |
236 } | 236 } |
237 | 237 |
238 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } | 238 void AppendTask(unsigned id) { AppendTask(id, gfx::Size(1, 1)); } |
239 | 239 |
240 void AppendBlockingTask(unsigned id, base::Lock* lock) { | 240 void AppendBlockingTask(unsigned id, base::Lock* lock) { |
241 const gfx::Size size(1, 1); | 241 const gfx::Size size(1, 1); |
242 | 242 |
243 std::unique_ptr<ScopedResource> resource( | 243 std::unique_ptr<ScopedResource> resource( |
244 ScopedResource::Create(resource_provider_.get())); | 244 ScopedResource::Create(resource_provider_.get())); |
245 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 245 resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
246 RGBA_8888); | 246 RGBA_8888); |
247 | 247 |
248 std::unique_ptr<RasterBuffer> raster_buffer = | 248 std::unique_ptr<RasterBuffer> raster_buffer = |
249 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( | 249 raster_buffer_provider_->AcquireBufferForRaster(resource.get(), 0, 0); |
250 resource.get(), 0, 0); | |
251 TileTask::Vector empty; | 250 TileTask::Vector empty; |
252 tasks_.push_back(new BlockingTestRasterTaskImpl( | 251 tasks_.push_back(new BlockingTestRasterTaskImpl( |
253 this, std::move(resource), id, std::move(raster_buffer), lock, &empty)); | 252 this, std::move(resource), id, std::move(raster_buffer), lock, &empty)); |
254 } | 253 } |
255 | 254 |
256 const std::vector<RasterTaskResult>& completed_tasks() const { | 255 const std::vector<RasterTaskResult>& completed_tasks() const { |
257 return completed_tasks_; | 256 return completed_tasks_; |
258 } | 257 } |
259 | 258 |
260 void LoseContext(ContextProvider* context_provider) { | 259 void LoseContext(ContextProvider* context_provider) { |
261 if (!context_provider) | 260 if (!context_provider) |
262 return; | 261 return; |
263 context_provider->ContextGL()->LoseContextCHROMIUM( | 262 context_provider->ContextGL()->LoseContextCHROMIUM( |
264 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | 263 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); |
265 context_provider->ContextGL()->Flush(); | 264 context_provider->ContextGL()->Flush(); |
266 } | 265 } |
267 | 266 |
268 void OnRasterTaskCompleted(std::unique_ptr<RasterBuffer> raster_buffer, | 267 void OnRasterTaskCompleted(std::unique_ptr<RasterBuffer> raster_buffer, |
269 unsigned id, | 268 unsigned id, |
270 bool was_canceled) override { | 269 bool was_canceled) override { |
271 tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( | 270 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); |
272 std::move(raster_buffer)); | |
273 RasterTaskResult result; | 271 RasterTaskResult result; |
274 result.id = id; | 272 result.id = id; |
275 result.canceled = was_canceled; | 273 result.canceled = was_canceled; |
276 completed_tasks_.push_back(result); | 274 completed_tasks_.push_back(result); |
277 } | 275 } |
278 | 276 |
279 private: | 277 private: |
280 void Create3dOutputSurfaceAndResourceProvider() { | 278 void Create3dOutputSurfaceAndResourceProvider() { |
281 output_surface_ = FakeOutputSurface::Create3d(context_provider_, | 279 output_surface_ = FakeOutputSurface::Create3d(context_provider_, |
282 worker_context_provider_); | 280 worker_context_provider_); |
(...skipping 17 matching lines...) Expand all Loading... |
300 base::MessageLoop::current()->QuitWhenIdle(); | 298 base::MessageLoop::current()->QuitWhenIdle(); |
301 } | 299 } |
302 | 300 |
303 protected: | 301 protected: |
304 scoped_refptr<TestContextProvider> context_provider_; | 302 scoped_refptr<TestContextProvider> context_provider_; |
305 scoped_refptr<TestContextProvider> worker_context_provider_; | 303 scoped_refptr<TestContextProvider> worker_context_provider_; |
306 FakeOutputSurfaceClient output_surface_client_; | 304 FakeOutputSurfaceClient output_surface_client_; |
307 std::unique_ptr<FakeOutputSurface> output_surface_; | 305 std::unique_ptr<FakeOutputSurface> output_surface_; |
308 std::unique_ptr<ResourceProvider> resource_provider_; | 306 std::unique_ptr<ResourceProvider> resource_provider_; |
309 std::unique_ptr<TileTaskManager> tile_task_manager_; | 307 std::unique_ptr<TileTaskManager> tile_task_manager_; |
| 308 std::unique_ptr<RasterBufferProvider> raster_buffer_provider_; |
310 TestGpuMemoryBufferManager gpu_memory_buffer_manager_; | 309 TestGpuMemoryBufferManager gpu_memory_buffer_manager_; |
311 TestSharedBitmapManager shared_bitmap_manager_; | 310 TestSharedBitmapManager shared_bitmap_manager_; |
312 SynchronousTaskGraphRunner task_graph_runner_; | 311 SynchronousTaskGraphRunner task_graph_runner_; |
313 base::CancelableClosure timeout_; | 312 base::CancelableClosure timeout_; |
314 UniqueNotifier all_tile_tasks_finished_; | 313 UniqueNotifier all_tile_tasks_finished_; |
315 int timeout_seconds_; | 314 int timeout_seconds_; |
316 bool timed_out_; | 315 bool timed_out_; |
317 RasterTaskVector tasks_; | 316 RasterTaskVector tasks_; |
318 std::vector<RasterTaskResult> completed_tasks_; | 317 std::vector<RasterTaskResult> completed_tasks_; |
319 TaskGraph graph_; | 318 TaskGraph graph_; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 386 |
388 INSTANTIATE_TEST_CASE_P(RasterBufferProviderTests, | 387 INSTANTIATE_TEST_CASE_P(RasterBufferProviderTests, |
389 RasterBufferProviderTest, | 388 RasterBufferProviderTest, |
390 ::testing::Values(RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY, | 389 ::testing::Values(RASTER_BUFFER_PROVIDER_TYPE_ZERO_COPY, |
391 RASTER_BUFFER_PROVIDER_TYPE_ONE_COPY, | 390 RASTER_BUFFER_PROVIDER_TYPE_ONE_COPY, |
392 RASTER_BUFFER_PROVIDER_TYPE_GPU, | 391 RASTER_BUFFER_PROVIDER_TYPE_GPU, |
393 RASTER_BUFFER_PROVIDER_TYPE_BITMAP)); | 392 RASTER_BUFFER_PROVIDER_TYPE_BITMAP)); |
394 | 393 |
395 } // namespace | 394 } // namespace |
396 } // namespace cc | 395 } // namespace cc |
OLD | NEW |