| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/gpu_tile_task_worker_pool.h" | 5 #include "cc/raster/gpu_raster_buffer_provider.h" | 
| 6 | 6 | 
| 7 #include <stdint.h> | 7 #include <stdint.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 | 10 | 
| 11 #include "base/macros.h" | 11 #include "base/macros.h" | 
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" | 
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" | 
| 14 #include "cc/playback/raster_source.h" | 14 #include "cc/playback/raster_source.h" | 
| 15 #include "cc/raster/gpu_rasterizer.h" | 15 #include "cc/raster/gpu_rasterizer.h" | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 82   GpuRasterizer* rasterizer_; | 82   GpuRasterizer* rasterizer_; | 
| 83   ResourceProvider::ScopedWriteLockGr lock_; | 83   ResourceProvider::ScopedWriteLockGr lock_; | 
| 84   bool resource_has_previous_content_; | 84   bool resource_has_previous_content_; | 
| 85 | 85 | 
| 86   DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 86   DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 
| 87 }; | 87 }; | 
| 88 | 88 | 
| 89 }  // namespace | 89 }  // namespace | 
| 90 | 90 | 
| 91 // static | 91 // static | 
| 92 std::unique_ptr<TileTaskWorkerPool> GpuTileTaskWorkerPool::Create( | 92 std::unique_ptr<RasterBufferProvider> GpuRasterBufferProvider::Create( | 
| 93     base::SequencedTaskRunner* task_runner, |  | 
| 94     TaskGraphRunner* task_graph_runner, |  | 
| 95     ContextProvider* context_provider, | 93     ContextProvider* context_provider, | 
| 96     ResourceProvider* resource_provider, | 94     ResourceProvider* resource_provider, | 
| 97     bool use_distance_field_text, | 95     bool use_distance_field_text, | 
| 98     int gpu_rasterization_msaa_sample_count) { | 96     int gpu_rasterization_msaa_sample_count) { | 
| 99   return base::WrapUnique<TileTaskWorkerPool>(new GpuTileTaskWorkerPool( | 97   return base::WrapUnique<RasterBufferProvider>(new GpuRasterBufferProvider( | 
| 100       task_runner, task_graph_runner, context_provider, resource_provider, | 98       context_provider, resource_provider, use_distance_field_text, | 
| 101       use_distance_field_text, gpu_rasterization_msaa_sample_count)); | 99       gpu_rasterization_msaa_sample_count)); | 
| 102 } | 100 } | 
| 103 | 101 | 
| 104 GpuTileTaskWorkerPool::GpuTileTaskWorkerPool( | 102 GpuRasterBufferProvider::GpuRasterBufferProvider( | 
| 105     base::SequencedTaskRunner* task_runner, |  | 
| 106     TaskGraphRunner* task_graph_runner, |  | 
| 107     ContextProvider* context_provider, | 103     ContextProvider* context_provider, | 
| 108     ResourceProvider* resource_provider, | 104     ResourceProvider* resource_provider, | 
| 109     bool use_distance_field_text, | 105     bool use_distance_field_text, | 
| 110     int gpu_rasterization_msaa_sample_count) | 106     int gpu_rasterization_msaa_sample_count) | 
| 111     : task_runner_(task_runner), | 107     : rasterizer_(new GpuRasterizer(context_provider, | 
| 112       task_graph_runner_(task_graph_runner), |  | 
| 113       namespace_token_(task_graph_runner_->GetNamespaceToken()), |  | 
| 114       rasterizer_(new GpuRasterizer(context_provider, |  | 
| 115                                     resource_provider, | 108                                     resource_provider, | 
| 116                                     use_distance_field_text, | 109                                     use_distance_field_text, | 
| 117                                     gpu_rasterization_msaa_sample_count)) {} | 110                                     gpu_rasterization_msaa_sample_count)) {} | 
| 118 | 111 | 
| 119 GpuTileTaskWorkerPool::~GpuTileTaskWorkerPool() { | 112 GpuRasterBufferProvider::~GpuRasterBufferProvider() {} | 
| 120   DCHECK_EQ(0u, completed_tasks_.size()); |  | 
| 121 } |  | 
| 122 | 113 | 
| 123 void GpuTileTaskWorkerPool::Shutdown() { | 114 std::unique_ptr<RasterBuffer> GpuRasterBufferProvider::AcquireBufferForRaster( | 
| 124   TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::Shutdown"); |  | 
| 125 |  | 
| 126   TaskGraph empty; |  | 
| 127   task_graph_runner_->ScheduleTasks(namespace_token_, &empty); |  | 
| 128   task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); |  | 
| 129 } |  | 
| 130 |  | 
| 131 void GpuTileTaskWorkerPool::ScheduleTasks(TaskGraph* graph) { |  | 
| 132   TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::ScheduleTasks"); |  | 
| 133 |  | 
| 134   ScheduleTasksOnOriginThread(this, graph); |  | 
| 135 |  | 
| 136   // Barrier to sync any new resources to the worker context. |  | 
| 137   rasterizer_->resource_provider() |  | 
| 138       ->output_surface() |  | 
| 139       ->context_provider() |  | 
| 140       ->ContextGL() |  | 
| 141       ->OrderingBarrierCHROMIUM(); |  | 
| 142 |  | 
| 143   task_graph_runner_->ScheduleTasks(namespace_token_, graph); |  | 
| 144 } |  | 
| 145 |  | 
| 146 void GpuTileTaskWorkerPool::CheckForCompletedTasks() { |  | 
| 147   TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::CheckForCompletedTasks"); |  | 
| 148 |  | 
| 149   task_graph_runner_->CollectCompletedTasks(namespace_token_, |  | 
| 150                                             &completed_tasks_); |  | 
| 151   CompleteTasks(completed_tasks_); |  | 
| 152   completed_tasks_.clear(); |  | 
| 153 } |  | 
| 154 |  | 
| 155 ResourceFormat GpuTileTaskWorkerPool::GetResourceFormat( |  | 
| 156     bool must_support_alpha) const { |  | 
| 157   return rasterizer_->resource_provider()->best_render_buffer_format(); |  | 
| 158 } |  | 
| 159 |  | 
| 160 bool GpuTileTaskWorkerPool::GetResourceRequiresSwizzle( |  | 
| 161     bool must_support_alpha) const { |  | 
| 162   // This doesn't require a swizzle because we rasterize to the correct format. |  | 
| 163   return false; |  | 
| 164 } |  | 
| 165 |  | 
| 166 RasterBufferProvider* GpuTileTaskWorkerPool::AsRasterBufferProvider() { |  | 
| 167   return this; |  | 
| 168 } |  | 
| 169 |  | 
| 170 void GpuTileTaskWorkerPool::CompleteTasks(const Task::Vector& tasks) { |  | 
| 171   for (auto& task : tasks) { |  | 
| 172     TileTask* tile_task = static_cast<TileTask*>(task.get()); |  | 
| 173 |  | 
| 174     tile_task->WillComplete(); |  | 
| 175     tile_task->CompleteOnOriginThread(this); |  | 
| 176     tile_task->DidComplete(); |  | 
| 177   } |  | 
| 178   completed_tasks_.clear(); |  | 
| 179 } |  | 
| 180 |  | 
| 181 std::unique_ptr<RasterBuffer> GpuTileTaskWorkerPool::AcquireBufferForRaster( |  | 
| 182     const Resource* resource, | 115     const Resource* resource, | 
| 183     uint64_t resource_content_id, | 116     uint64_t resource_content_id, | 
| 184     uint64_t previous_content_id) { | 117     uint64_t previous_content_id) { | 
| 185   return std::unique_ptr<RasterBuffer>(new RasterBufferImpl( | 118   return std::unique_ptr<RasterBuffer>(new RasterBufferImpl( | 
| 186       rasterizer_.get(), resource, resource_content_id, previous_content_id)); | 119       rasterizer_.get(), resource, resource_content_id, previous_content_id)); | 
| 187 } | 120 } | 
| 188 | 121 | 
| 189 void GpuTileTaskWorkerPool::ReleaseBufferForRaster( | 122 void GpuRasterBufferProvider::ReleaseBufferForRaster( | 
| 190     std::unique_ptr<RasterBuffer> buffer) { | 123     std::unique_ptr<RasterBuffer> buffer) { | 
| 191   // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 124   // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 
| 192 } | 125 } | 
| 193 | 126 | 
|  | 127 void GpuRasterBufferProvider::BarrierToSyncResources() { | 
|  | 128   TRACE_EVENT0("cc", "GpuRasterBufferProvider::BarrierToSyncResources"); | 
|  | 129 | 
|  | 130   rasterizer_->resource_provider() | 
|  | 131       ->output_surface() | 
|  | 132       ->context_provider() | 
|  | 133       ->ContextGL() | 
|  | 134       ->OrderingBarrierCHROMIUM(); | 
|  | 135 } | 
|  | 136 | 
|  | 137 ResourceFormat GpuRasterBufferProvider::GetResourceFormat( | 
|  | 138     bool must_support_alpha) const { | 
|  | 139   return rasterizer_->resource_provider()->best_render_buffer_format(); | 
|  | 140 } | 
|  | 141 | 
|  | 142 bool GpuRasterBufferProvider::GetResourceRequiresSwizzle( | 
|  | 143     bool must_support_alpha) const { | 
|  | 144   // This doesn't require a swizzle because we rasterize to the correct format. | 
|  | 145   return false; | 
|  | 146 } | 
|  | 147 | 
| 194 }  // namespace cc | 148 }  // namespace cc | 
| OLD | NEW | 
|---|