| 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/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "cc/base/histograms.h" | 16 #include "cc/base/histograms.h" |
| 17 #include "cc/base/math_util.h" | 17 #include "cc/base/math_util.h" |
| 18 #include "cc/resources/platform_color.h" | 18 #include "cc/resources/platform_color.h" |
| 19 #include "cc/resources/resource_format.h" | 19 #include "cc/resources/resource_format.h" |
| 20 #include "cc/resources/resource_util.h" | 20 #include "cc/resources/resource_util.h" |
| 21 #include "cc/resources/scoped_resource.h" | 21 #include "cc/resources/scoped_resource.h" |
| 22 #include "gpu/GLES2/gl2extchromium.h" | 22 #include "gpu/GLES2/gl2extchromium.h" |
| 23 #include "gpu/command_buffer/client/context_support.h" |
| 23 #include "gpu/command_buffer/client/gles2_interface.h" | 24 #include "gpu/command_buffer/client/gles2_interface.h" |
| 24 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 25 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 25 #include "ui/gfx/buffer_format_util.h" | 26 #include "ui/gfx/buffer_format_util.h" |
| 26 | 27 |
| 27 namespace cc { | 28 namespace cc { |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good | 31 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good |
| 31 // default batch size for copy operations. | 32 // default batch size for copy operations. |
| 32 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; | 33 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; |
| 33 | 34 |
| 34 } // namespace | 35 } // namespace |
| 35 | 36 |
| 36 OneCopyRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( | 37 OneCopyRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( |
| 37 OneCopyRasterBufferProvider* client, | 38 OneCopyRasterBufferProvider* client, |
| 38 ResourceProvider* resource_provider, | 39 ResourceProvider* resource_provider, |
| 39 const Resource* resource, | 40 const Resource* resource, |
| 40 uint64_t previous_content_id, | 41 uint64_t previous_content_id) |
| 41 bool async_worker_context_enabled) | |
| 42 : client_(client), | 42 : client_(client), |
| 43 resource_(resource), | 43 resource_(resource), |
| 44 lock_(resource_provider, resource->id(), async_worker_context_enabled), | 44 lock_(resource_provider, resource->id(), true), |
| 45 previous_content_id_(previous_content_id) { | 45 previous_content_id_(previous_content_id) { |
| 46 client_->pending_raster_buffers_.insert(this); | 46 client_->pending_raster_buffers_.insert(this); |
| 47 } | 47 } |
| 48 | 48 |
| 49 OneCopyRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { | 49 OneCopyRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { |
| 50 client_->pending_raster_buffers_.erase(this); | 50 client_->pending_raster_buffers_.erase(this); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void OneCopyRasterBufferProvider::RasterBufferImpl::Playback( | 53 void OneCopyRasterBufferProvider::RasterBufferImpl::Playback( |
| 54 const RasterSource* raster_source, | 54 const RasterSource* raster_source, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 100 } |
| 101 | 101 |
| 102 std::unique_ptr<RasterBuffer> | 102 std::unique_ptr<RasterBuffer> |
| 103 OneCopyRasterBufferProvider::AcquireBufferForRaster( | 103 OneCopyRasterBufferProvider::AcquireBufferForRaster( |
| 104 const Resource* resource, | 104 const Resource* resource, |
| 105 uint64_t resource_content_id, | 105 uint64_t resource_content_id, |
| 106 uint64_t previous_content_id) { | 106 uint64_t previous_content_id) { |
| 107 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload | 107 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload |
| 108 // the dirty rect. | 108 // the dirty rect. |
| 109 return base::MakeUnique<RasterBufferImpl>(this, resource_provider_, resource, | 109 return base::MakeUnique<RasterBufferImpl>(this, resource_provider_, resource, |
| 110 previous_content_id, | 110 previous_content_id); |
| 111 async_worker_context_enabled_); | |
| 112 } | 111 } |
| 113 | 112 |
| 114 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( | 113 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( |
| 115 std::unique_ptr<RasterBuffer> buffer) { | 114 std::unique_ptr<RasterBuffer> buffer) { |
| 116 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 115 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 117 } | 116 } |
| 118 | 117 |
| 119 void OneCopyRasterBufferProvider::OrderingBarrier() { | 118 void OneCopyRasterBufferProvider::OrderingBarrier() { |
| 120 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); | 119 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); |
| 121 | 120 |
| 122 gpu::gles2::GLES2Interface* gl = compositor_context_provider_->ContextGL(); | 121 gpu::gles2::GLES2Interface* gl = compositor_context_provider_->ContextGL(); |
| 123 if (async_worker_context_enabled_) { | 122 if (async_worker_context_enabled_) { |
| 124 GLuint64 fence = gl->InsertFenceSyncCHROMIUM(); | 123 GLuint64 fence = gl->InsertFenceSyncCHROMIUM(); |
| 125 gl->OrderingBarrierCHROMIUM(); | 124 gl->OrderingBarrierCHROMIUM(); |
| 126 | 125 |
| 127 gpu::SyncToken sync_token; | 126 gpu::SyncToken sync_token; |
| 128 gl->GenUnverifiedSyncTokenCHROMIUM(fence, sync_token.GetData()); | 127 gl->GenUnverifiedSyncTokenCHROMIUM(fence, sync_token.GetData()); |
| 129 | 128 |
| 130 DCHECK(sync_token.HasData() || | 129 DCHECK(sync_token.HasData() || |
| 131 gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR); | 130 gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR); |
| 132 | 131 |
| 133 for (RasterBufferImpl* buffer : pending_raster_buffers_) | 132 for (RasterBufferImpl* buffer : pending_raster_buffers_) |
| 134 buffer->set_sync_token(sync_token); | 133 buffer->set_sync_token(sync_token); |
| 135 } else { | 134 } else { |
| 136 gl->OrderingBarrierCHROMIUM(); | 135 gl->OrderingBarrierCHROMIUM(); |
| 137 } | 136 } |
| 138 pending_raster_buffers_.clear(); | 137 pending_raster_buffers_.clear(); |
| 139 } | 138 } |
| 140 | 139 |
| 140 bool OneCopyRasterBufferProvider::IsResourceReadyToDraw( |
| 141 const Resource* resource) { |
| 142 if (async_worker_context_enabled_) { |
| 143 gpu::SyncToken sync_token = |
| 144 resource_provider_->GetSyncTokenForResource(resource->id()); |
| 145 if (sync_token.HasData()) { |
| 146 return worker_context_provider_->ContextSupport()->IsFenceSyncReleased( |
| 147 sync_token.release_count()); |
| 148 } |
| 149 } |
| 150 return true; |
| 151 } |
| 152 |
| 153 void OneCopyRasterBufferProvider::SignalResourcesReadyToDraw( |
| 154 const std::vector<const Resource*>& resources, |
| 155 const base::Closure& callback) { |
| 156 if (async_worker_context_enabled_) { |
| 157 ResourceProvider::ResourceIdArray resource_ids; |
| 158 for (const Resource* resource : resources) |
| 159 resource_ids.push_back(resource->id()); |
| 160 |
| 161 gpu::SyncToken sync_token = |
| 162 resource_provider_->GetSyncTokenForResources(resource_ids); |
| 163 compositor_context_provider_->ContextSupport()->SignalSyncToken(sync_token, |
| 164 callback); |
| 165 } else if (!callback.is_null()) { |
| 166 callback.Run(); |
| 167 } |
| 168 } |
| 169 |
| 141 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( | 170 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( |
| 142 bool must_support_alpha) const { | 171 bool must_support_alpha) const { |
| 143 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && | 172 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && |
| 144 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || | 173 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || |
| 145 !must_support_alpha)) { | 174 !must_support_alpha)) { |
| 146 return preferred_tile_format_; | 175 return preferred_tile_format_; |
| 147 } | 176 } |
| 148 | 177 |
| 149 return resource_provider_->best_texture_format(); | 178 return resource_provider_->best_texture_format(); |
| 150 } | 179 } |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 resource_lock->set_synchronized(!async_worker_context_enabled_); | 414 resource_lock->set_synchronized(!async_worker_context_enabled_); |
| 386 } | 415 } |
| 387 | 416 |
| 388 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { | 417 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { |
| 389 return use_partial_raster_ | 418 return use_partial_raster_ |
| 390 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT | 419 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT |
| 391 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; | 420 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; |
| 392 } | 421 } |
| 393 | 422 |
| 394 } // namespace cc | 423 } // namespace cc |
| OLD | NEW |