| 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 "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
| 15 #include "cc/raster/staging_buffer_pool.h" | |
| 16 #include "cc/resources/platform_color.h" | 15 #include "cc/resources/platform_color.h" |
| 17 #include "cc/resources/resource_format.h" | 16 #include "cc/resources/resource_format.h" |
| 18 #include "cc/resources/resource_util.h" | 17 #include "cc/resources/resource_util.h" |
| 19 #include "cc/resources/scoped_resource.h" | 18 #include "cc/resources/scoped_resource.h" |
| 20 #include "gpu/GLES2/gl2extchromium.h" | 19 #include "gpu/GLES2/gl2extchromium.h" |
| 21 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
| 22 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 21 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 23 #include "ui/gfx/buffer_format_util.h" | 22 #include "ui/gfx/buffer_format_util.h" |
| 24 | 23 |
| 25 namespace cc { | 24 namespace cc { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 59 |
| 61 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 60 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good | 63 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good |
| 65 // default batch size for copy operations. | 64 // default batch size for copy operations. |
| 66 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; | 65 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; |
| 67 | 66 |
| 68 } // namespace | 67 } // namespace |
| 69 | 68 |
| 70 // static | |
| 71 std::unique_ptr<RasterBufferProvider> OneCopyRasterBufferProvider::Create( | |
| 72 base::SequencedTaskRunner* task_runner, | |
| 73 ContextProvider* context_provider, | |
| 74 ResourceProvider* resource_provider, | |
| 75 int max_copy_texture_chromium_size, | |
| 76 bool use_partial_raster, | |
| 77 int max_staging_buffer_usage_in_bytes, | |
| 78 ResourceFormat preferred_tile_format) { | |
| 79 return base::WrapUnique<RasterBufferProvider>(new OneCopyRasterBufferProvider( | |
| 80 task_runner, resource_provider, max_copy_texture_chromium_size, | |
| 81 use_partial_raster, max_staging_buffer_usage_in_bytes, | |
| 82 preferred_tile_format)); | |
| 83 } | |
| 84 | |
| 85 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( | 69 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( |
| 86 base::SequencedTaskRunner* task_runner, | 70 base::SequencedTaskRunner* task_runner, |
| 71 ContextProvider* compositor_context_provider, |
| 72 ContextProvider* worker_context_provider, |
| 87 ResourceProvider* resource_provider, | 73 ResourceProvider* resource_provider, |
| 88 int max_copy_texture_chromium_size, | 74 int max_copy_texture_chromium_size, |
| 89 bool use_partial_raster, | 75 bool use_partial_raster, |
| 90 int max_staging_buffer_usage_in_bytes, | 76 int max_staging_buffer_usage_in_bytes, |
| 91 ResourceFormat preferred_tile_format) | 77 ResourceFormat preferred_tile_format) |
| 92 : resource_provider_(resource_provider), | 78 : compositor_context_provider_(compositor_context_provider), |
| 79 worker_context_provider_(worker_context_provider), |
| 80 resource_provider_(resource_provider), |
| 93 max_bytes_per_copy_operation_( | 81 max_bytes_per_copy_operation_( |
| 94 max_copy_texture_chromium_size | 82 max_copy_texture_chromium_size |
| 95 ? std::min(kMaxBytesPerCopyOperation, | 83 ? std::min(kMaxBytesPerCopyOperation, |
| 96 max_copy_texture_chromium_size) | 84 max_copy_texture_chromium_size) |
| 97 : kMaxBytesPerCopyOperation), | 85 : kMaxBytesPerCopyOperation), |
| 98 use_partial_raster_(use_partial_raster), | 86 use_partial_raster_(use_partial_raster), |
| 99 bytes_scheduled_since_last_flush_(0), | 87 bytes_scheduled_since_last_flush_(0), |
| 100 preferred_tile_format_(preferred_tile_format) { | 88 preferred_tile_format_(preferred_tile_format), |
| 101 staging_pool_ = StagingBufferPool::Create(task_runner, resource_provider, | 89 staging_pool_(task_runner, |
| 102 use_partial_raster, | 90 worker_context_provider, |
| 103 max_staging_buffer_usage_in_bytes); | 91 resource_provider, |
| 92 use_partial_raster, |
| 93 max_staging_buffer_usage_in_bytes) { |
| 94 DCHECK(compositor_context_provider_); |
| 95 DCHECK(worker_context_provider); |
| 104 } | 96 } |
| 105 | 97 |
| 106 OneCopyRasterBufferProvider::~OneCopyRasterBufferProvider() {} | 98 OneCopyRasterBufferProvider::~OneCopyRasterBufferProvider() {} |
| 107 | 99 |
| 108 std::unique_ptr<RasterBuffer> | 100 std::unique_ptr<RasterBuffer> |
| 109 OneCopyRasterBufferProvider::AcquireBufferForRaster( | 101 OneCopyRasterBufferProvider::AcquireBufferForRaster( |
| 110 const Resource* resource, | 102 const Resource* resource, |
| 111 uint64_t resource_content_id, | 103 uint64_t resource_content_id, |
| 112 uint64_t previous_content_id) { | 104 uint64_t previous_content_id) { |
| 113 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload | 105 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload |
| 114 // the dirty rect. | 106 // the dirty rect. |
| 115 return base::WrapUnique<RasterBuffer>( | 107 return base::WrapUnique<RasterBuffer>( |
| 116 new RasterBufferImpl(this, resource_provider_, resource->format(), | 108 new RasterBufferImpl(this, resource_provider_, resource->format(), |
| 117 resource, previous_content_id)); | 109 resource, previous_content_id)); |
| 118 } | 110 } |
| 119 | 111 |
| 120 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( | 112 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( |
| 121 std::unique_ptr<RasterBuffer> buffer) { | 113 std::unique_ptr<RasterBuffer> buffer) { |
| 122 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 114 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 123 } | 115 } |
| 124 | 116 |
| 125 void OneCopyRasterBufferProvider::OrderingBarrier() { | 117 void OneCopyRasterBufferProvider::OrderingBarrier() { |
| 126 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); | 118 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); |
| 127 | 119 compositor_context_provider_->ContextGL()->OrderingBarrierCHROMIUM(); |
| 128 resource_provider_->output_surface() | |
| 129 ->context_provider() | |
| 130 ->ContextGL() | |
| 131 ->OrderingBarrierCHROMIUM(); | |
| 132 } | 120 } |
| 133 | 121 |
| 134 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( | 122 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( |
| 135 bool must_support_alpha) const { | 123 bool must_support_alpha) const { |
| 136 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && | 124 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && |
| 137 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || | 125 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || |
| 138 !must_support_alpha)) { | 126 !must_support_alpha)) { |
| 139 return preferred_tile_format_; | 127 return preferred_tile_format_; |
| 140 } | 128 } |
| 141 | 129 |
| 142 return resource_provider_->best_texture_format(); | 130 return resource_provider_->best_texture_format(); |
| 143 } | 131 } |
| 144 | 132 |
| 145 bool OneCopyRasterBufferProvider::GetResourceRequiresSwizzle( | 133 bool OneCopyRasterBufferProvider::GetResourceRequiresSwizzle( |
| 146 bool must_support_alpha) const { | 134 bool must_support_alpha) const { |
| 147 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); | 135 return ResourceFormatRequiresSwizzle(GetResourceFormat(must_support_alpha)); |
| 148 } | 136 } |
| 149 | 137 |
| 150 void OneCopyRasterBufferProvider::Shutdown() { | 138 void OneCopyRasterBufferProvider::Shutdown() { |
| 151 staging_pool_->Shutdown(); | 139 staging_pool_.Shutdown(); |
| 152 } | 140 } |
| 153 | 141 |
| 154 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( | 142 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( |
| 155 const Resource* resource, | 143 const Resource* resource, |
| 156 ResourceProvider::ScopedWriteLockGL* resource_lock, | 144 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 157 const RasterSource* raster_source, | 145 const RasterSource* raster_source, |
| 158 const gfx::Rect& raster_full_rect, | 146 const gfx::Rect& raster_full_rect, |
| 159 const gfx::Rect& raster_dirty_rect, | 147 const gfx::Rect& raster_dirty_rect, |
| 160 float scale, | 148 float scale, |
| 161 const RasterSource::PlaybackSettings& playback_settings, | 149 const RasterSource::PlaybackSettings& playback_settings, |
| 162 uint64_t previous_content_id, | 150 uint64_t previous_content_id, |
| 163 uint64_t new_content_id) { | 151 uint64_t new_content_id) { |
| 164 std::unique_ptr<StagingBuffer> staging_buffer = | 152 std::unique_ptr<StagingBuffer> staging_buffer = |
| 165 staging_pool_->AcquireStagingBuffer(resource, previous_content_id); | 153 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); |
| 166 | 154 |
| 167 PlaybackToStagingBuffer(staging_buffer.get(), resource, raster_source, | 155 PlaybackToStagingBuffer(staging_buffer.get(), resource, raster_source, |
| 168 raster_full_rect, raster_dirty_rect, scale, | 156 raster_full_rect, raster_dirty_rect, scale, |
| 169 playback_settings, previous_content_id, | 157 playback_settings, previous_content_id, |
| 170 new_content_id); | 158 new_content_id); |
| 171 | 159 |
| 172 CopyOnWorkerThread(staging_buffer.get(), resource, resource_lock, | 160 CopyOnWorkerThread(staging_buffer.get(), resource, resource_lock, |
| 173 raster_source, previous_content_id, new_content_id); | 161 raster_source, previous_content_id, new_content_id); |
| 174 | 162 |
| 175 staging_pool_->ReleaseStagingBuffer(std::move(staging_buffer)); | 163 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); |
| 176 } | 164 } |
| 177 | 165 |
| 178 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( | 166 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( |
| 179 StagingBuffer* staging_buffer, | 167 StagingBuffer* staging_buffer, |
| 180 const Resource* resource, | 168 const Resource* resource, |
| 181 const RasterSource* raster_source, | 169 const RasterSource* raster_source, |
| 182 const gfx::Rect& raster_full_rect, | 170 const gfx::Rect& raster_full_rect, |
| 183 const gfx::Rect& raster_dirty_rect, | 171 const gfx::Rect& raster_dirty_rect, |
| 184 float scale, | 172 float scale, |
| 185 const RasterSource::PlaybackSettings& playback_settings, | 173 const RasterSource::PlaybackSettings& playback_settings, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 214 } |
| 227 } | 215 } |
| 228 | 216 |
| 229 void OneCopyRasterBufferProvider::CopyOnWorkerThread( | 217 void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
| 230 StagingBuffer* staging_buffer, | 218 StagingBuffer* staging_buffer, |
| 231 const Resource* resource, | 219 const Resource* resource, |
| 232 ResourceProvider::ScopedWriteLockGL* resource_lock, | 220 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 233 const RasterSource* raster_source, | 221 const RasterSource* raster_source, |
| 234 uint64_t previous_content_id, | 222 uint64_t previous_content_id, |
| 235 uint64_t new_content_id) { | 223 uint64_t new_content_id) { |
| 236 ContextProvider* context_provider = | |
| 237 resource_provider_->output_surface()->worker_context_provider(); | |
| 238 DCHECK(context_provider); | |
| 239 | |
| 240 { | 224 { |
| 241 ContextProvider::ScopedContextLock scoped_context(context_provider); | 225 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
| 242 | 226 |
| 243 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 227 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 244 DCHECK(gl); | 228 DCHECK(gl); |
| 245 | 229 |
| 246 unsigned image_target = | 230 unsigned image_target = |
| 247 resource_provider_->GetImageTextureTarget(resource->format()); | 231 resource_provider_->GetImageTextureTarget(resource->format()); |
| 248 | 232 |
| 249 // Create and bind staging texture. | 233 // Create and bind staging texture. |
| 250 if (!staging_buffer->texture_id) { | 234 if (!staging_buffer->texture_id) { |
| 251 gl->GenTextures(1, &staging_buffer->texture_id); | 235 gl->GenTextures(1, &staging_buffer->texture_id); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 gl->OrderingBarrierCHROMIUM(); | 323 gl->OrderingBarrierCHROMIUM(); |
| 340 | 324 |
| 341 // Generate sync token after the barrier for cross context synchronization. | 325 // Generate sync token after the barrier for cross context synchronization. |
| 342 gpu::SyncToken sync_token; | 326 gpu::SyncToken sync_token; |
| 343 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 327 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 344 resource_lock->UpdateResourceSyncToken(sync_token); | 328 resource_lock->UpdateResourceSyncToken(sync_token); |
| 345 } | 329 } |
| 346 } | 330 } |
| 347 | 331 |
| 348 } // namespace cc | 332 } // namespace cc |
| OLD | NEW |