| 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/one_copy_raster_buffer_provider.h" | 5 #include "cc/raster/one_copy_raster_buffer_provider.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "cc/base/histograms.h" | 17 #include "cc/base/histograms.h" |
| 18 #include "cc/base/math_util.h" | 18 #include "cc/base/math_util.h" |
| 19 #include "cc/resources/platform_color.h" | 19 #include "cc/resources/platform_color.h" |
| 20 #include "cc/resources/resource_format.h" | 20 #include "cc/resources/resource_format.h" |
| 21 #include "cc/resources/resource_util.h" | 21 #include "cc/resources/resource_util.h" |
| 22 #include "cc/resources/scoped_resource.h" | 22 #include "cc/resources/scoped_resource.h" |
| 23 #include "gpu/GLES2/gl2extchromium.h" | 23 #include "gpu/GLES2/gl2extchromium.h" |
| 24 #include "gpu/command_buffer/client/context_support.h" |
| 24 #include "gpu/command_buffer/client/gles2_interface.h" | 25 #include "gpu/command_buffer/client/gles2_interface.h" |
| 25 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 26 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 26 #include "ui/gfx/buffer_format_util.h" | 27 #include "ui/gfx/buffer_format_util.h" |
| 27 | 28 |
| 28 namespace cc { | 29 namespace cc { |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good | 32 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good |
| 32 // default batch size for copy operations. | 33 // default batch size for copy operations. |
| 33 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; | 34 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); | 156 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 bool OneCopyRasterBufferProvider::CanPartialRasterIntoProvidedResource() const { | 159 bool OneCopyRasterBufferProvider::CanPartialRasterIntoProvidedResource() const { |
| 159 // While OneCopyRasterBufferProvider has an internal partial raster | 160 // While OneCopyRasterBufferProvider has an internal partial raster |
| 160 // implementation, it cannot directly partial raster into the externally | 161 // implementation, it cannot directly partial raster into the externally |
| 161 // owned resource provided in AcquireBufferForRaster. | 162 // owned resource provided in AcquireBufferForRaster. |
| 162 return false; | 163 return false; |
| 163 } | 164 } |
| 164 | 165 |
| 166 bool OneCopyRasterBufferProvider::IsResourceReadyToDraw( |
| 167 ResourceId resource_id) const { |
| 168 if (!async_worker_context_enabled_) |
| 169 return true; |
| 170 |
| 171 ResourceProvider::ResourceIdArray resources; |
| 172 resources.push_back(resource_id); |
| 173 gpu::SyncToken sync_token = |
| 174 resource_provider_->GetSyncTokenForResources(resources); |
| 175 if (!sync_token.HasData()) |
| 176 return true; |
| 177 |
| 178 // IsSyncTokenSignalled is threadsafe, no need for worker context lock. |
| 179 return worker_context_provider_->ContextSupport()->IsSyncTokenSignalled( |
| 180 sync_token); |
| 181 } |
| 182 |
| 183 uint64_t OneCopyRasterBufferProvider::SetReadyToDrawCallback( |
| 184 const ResourceProvider::ResourceIdArray& resource_ids, |
| 185 const base::Closure& callback, |
| 186 uint64_t pending_callback_id) const { |
| 187 if (!async_worker_context_enabled_) |
| 188 return 0; |
| 189 |
| 190 gpu::SyncToken sync_token = |
| 191 resource_provider_->GetSyncTokenForResources(resource_ids); |
| 192 uint64_t callback_id = sync_token.release_count(); |
| 193 DCHECK_NE(callback_id, 0u); |
| 194 |
| 195 // If the callback is different from the one the caller is already waiting on, |
| 196 // pass the callback through to SignalSinkToken. Otherwise the request is |
| 197 // redundant. |
| 198 if (callback_id != pending_callback_id) { |
| 199 // SignalSyncToken is threadsafe, no need for worker context lock. |
| 200 worker_context_provider_->ContextSupport()->SignalSyncToken(sync_token, |
| 201 callback); |
| 202 } |
| 203 |
| 204 return callback_id; |
| 205 } |
| 206 |
| 165 void OneCopyRasterBufferProvider::Shutdown() { | 207 void OneCopyRasterBufferProvider::Shutdown() { |
| 166 staging_pool_.Shutdown(); | 208 staging_pool_.Shutdown(); |
| 167 pending_raster_buffers_.clear(); | 209 pending_raster_buffers_.clear(); |
| 168 } | 210 } |
| 169 | 211 |
| 170 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( | 212 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( |
| 171 const Resource* resource, | 213 const Resource* resource, |
| 172 ResourceProvider::ScopedWriteLockGL* resource_lock, | 214 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 173 const gpu::SyncToken& sync_token, | 215 const gpu::SyncToken& sync_token, |
| 174 const RasterSource* raster_source, | 216 const RasterSource* raster_source, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 resource_lock->set_synchronized(!async_worker_context_enabled_); | 429 resource_lock->set_synchronized(!async_worker_context_enabled_); |
| 388 } | 430 } |
| 389 | 431 |
| 390 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { | 432 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { |
| 391 return use_partial_raster_ | 433 return use_partial_raster_ |
| 392 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT | 434 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT |
| 393 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; | 435 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; |
| 394 } | 436 } |
| 395 | 437 |
| 396 } // namespace cc | 438 } // namespace cc |
| OLD | NEW |