| 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> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 OneCopyRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { | 48 OneCopyRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { |
| 49 client_->pending_raster_buffers_.erase(this); | 49 client_->pending_raster_buffers_.erase(this); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void OneCopyRasterBufferProvider::RasterBufferImpl::Playback( | 52 void OneCopyRasterBufferProvider::RasterBufferImpl::Playback( |
| 53 const RasterSource* raster_source, | 53 const RasterSource* raster_source, |
| 54 const gfx::Rect& raster_full_rect, | 54 const gfx::Rect& raster_full_rect, |
| 55 const gfx::Rect& raster_dirty_rect, | 55 const gfx::Rect& raster_dirty_rect, |
| 56 uint64_t new_content_id, | 56 uint64_t new_content_id, |
| 57 float scale, | 57 const ScaleTranslate2d& transform, |
| 58 const RasterSource::PlaybackSettings& playback_settings) { | 58 const RasterSource::PlaybackSettings& playback_settings) { |
| 59 TRACE_EVENT0("cc", "OneCopyRasterBuffer::Playback"); | 59 TRACE_EVENT0("cc", "OneCopyRasterBuffer::Playback"); |
| 60 client_->PlaybackAndCopyOnWorkerThread( | 60 client_->PlaybackAndCopyOnWorkerThread( |
| 61 resource_, &lock_, sync_token_, raster_source, raster_full_rect, | 61 resource_, &lock_, sync_token_, raster_source, raster_full_rect, |
| 62 raster_dirty_rect, scale, playback_settings, previous_content_id_, | 62 raster_dirty_rect, transform, playback_settings, previous_content_id_, |
| 63 new_content_id); | 63 new_content_id); |
| 64 } | 64 } |
| 65 | 65 |
| 66 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( | 66 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( |
| 67 base::SequencedTaskRunner* task_runner, | 67 base::SequencedTaskRunner* task_runner, |
| 68 ContextProvider* compositor_context_provider, | 68 ContextProvider* compositor_context_provider, |
| 69 ContextProvider* worker_context_provider, | 69 ContextProvider* worker_context_provider, |
| 70 ResourceProvider* resource_provider, | 70 ResourceProvider* resource_provider, |
| 71 int max_copy_texture_chromium_size, | 71 int max_copy_texture_chromium_size, |
| 72 bool use_partial_raster, | 72 bool use_partial_raster, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 pending_raster_buffers_.clear(); | 165 pending_raster_buffers_.clear(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( | 168 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( |
| 169 const Resource* resource, | 169 const Resource* resource, |
| 170 ResourceProvider::ScopedWriteLockGL* resource_lock, | 170 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 171 const gpu::SyncToken& sync_token, | 171 const gpu::SyncToken& sync_token, |
| 172 const RasterSource* raster_source, | 172 const RasterSource* raster_source, |
| 173 const gfx::Rect& raster_full_rect, | 173 const gfx::Rect& raster_full_rect, |
| 174 const gfx::Rect& raster_dirty_rect, | 174 const gfx::Rect& raster_dirty_rect, |
| 175 float scale, | 175 const ScaleTranslate2d& transform, |
| 176 const RasterSource::PlaybackSettings& playback_settings, | 176 const RasterSource::PlaybackSettings& playback_settings, |
| 177 uint64_t previous_content_id, | 177 uint64_t previous_content_id, |
| 178 uint64_t new_content_id) { | 178 uint64_t new_content_id) { |
| 179 if (async_worker_context_enabled_) { | 179 if (async_worker_context_enabled_) { |
| 180 // Early out if sync token is invalid. This happens if the compositor | 180 // Early out if sync token is invalid. This happens if the compositor |
| 181 // context was lost before ScheduleTasks was called. | 181 // context was lost before ScheduleTasks was called. |
| 182 if (!sync_token.HasData()) | 182 if (!sync_token.HasData()) |
| 183 return; | 183 return; |
| 184 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); | 184 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
| 185 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 185 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 186 DCHECK(gl); | 186 DCHECK(gl); |
| 187 // Synchronize with compositor. | 187 // Synchronize with compositor. |
| 188 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 188 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 std::unique_ptr<StagingBuffer> staging_buffer = | 191 std::unique_ptr<StagingBuffer> staging_buffer = |
| 192 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); | 192 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); |
| 193 | 193 |
| 194 PlaybackToStagingBuffer(staging_buffer.get(), resource, raster_source, | 194 PlaybackToStagingBuffer(staging_buffer.get(), resource, raster_source, |
| 195 raster_full_rect, raster_dirty_rect, scale, | 195 raster_full_rect, raster_dirty_rect, transform, |
| 196 playback_settings, previous_content_id, | 196 playback_settings, previous_content_id, |
| 197 new_content_id); | 197 new_content_id); |
| 198 | 198 |
| 199 CopyOnWorkerThread(staging_buffer.get(), resource_lock, sync_token, | 199 CopyOnWorkerThread(staging_buffer.get(), resource_lock, sync_token, |
| 200 raster_source, previous_content_id, new_content_id); | 200 raster_source, previous_content_id, new_content_id); |
| 201 | 201 |
| 202 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); | 202 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( | 205 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( |
| 206 StagingBuffer* staging_buffer, | 206 StagingBuffer* staging_buffer, |
| 207 const Resource* resource, | 207 const Resource* resource, |
| 208 const RasterSource* raster_source, | 208 const RasterSource* raster_source, |
| 209 const gfx::Rect& raster_full_rect, | 209 const gfx::Rect& raster_full_rect, |
| 210 const gfx::Rect& raster_dirty_rect, | 210 const gfx::Rect& raster_dirty_rect, |
| 211 float scale, | 211 const ScaleTranslate2d& transform, |
| 212 const RasterSource::PlaybackSettings& playback_settings, | 212 const RasterSource::PlaybackSettings& playback_settings, |
| 213 uint64_t previous_content_id, | 213 uint64_t previous_content_id, |
| 214 uint64_t new_content_id) { | 214 uint64_t new_content_id) { |
| 215 // Allocate GpuMemoryBuffer if necessary. If using partial raster, we | 215 // Allocate GpuMemoryBuffer if necessary. If using partial raster, we |
| 216 // must allocate a buffer with BufferUsage CPU_READ_WRITE_PERSISTENT. | 216 // must allocate a buffer with BufferUsage CPU_READ_WRITE_PERSISTENT. |
| 217 if (!staging_buffer->gpu_memory_buffer) { | 217 if (!staging_buffer->gpu_memory_buffer) { |
| 218 staging_buffer->gpu_memory_buffer = | 218 staging_buffer->gpu_memory_buffer = |
| 219 resource_provider_->gpu_memory_buffer_manager() | 219 resource_provider_->gpu_memory_buffer_manager() |
| 220 ->AllocateGpuMemoryBuffer( | 220 ->AllocateGpuMemoryBuffer( |
| 221 staging_buffer->size, BufferFormat(resource->format()), | 221 staging_buffer->size, BufferFormat(resource->format()), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 251 DCHECK(rv); | 251 DCHECK(rv); |
| 252 DCHECK(buffer->memory(0)); | 252 DCHECK(buffer->memory(0)); |
| 253 // RasterBufferProvider::PlaybackToMemory only supports unsigned strides. | 253 // RasterBufferProvider::PlaybackToMemory only supports unsigned strides. |
| 254 DCHECK_GE(buffer->stride(0), 0); | 254 DCHECK_GE(buffer->stride(0), 0); |
| 255 | 255 |
| 256 DCHECK(!playback_rect.IsEmpty()) | 256 DCHECK(!playback_rect.IsEmpty()) |
| 257 << "Why are we rastering a tile that's not dirty?"; | 257 << "Why are we rastering a tile that's not dirty?"; |
| 258 RasterBufferProvider::PlaybackToMemory( | 258 RasterBufferProvider::PlaybackToMemory( |
| 259 buffer->memory(0), resource->format(), staging_buffer->size, | 259 buffer->memory(0), resource->format(), staging_buffer->size, |
| 260 buffer->stride(0), raster_source, raster_full_rect, playback_rect, | 260 buffer->stride(0), raster_source, raster_full_rect, playback_rect, |
| 261 scale, playback_settings); | 261 transform, playback_settings); |
| 262 buffer->Unmap(); | 262 buffer->Unmap(); |
| 263 staging_buffer->content_id = new_content_id; | 263 staging_buffer->content_id = new_content_id; |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 void OneCopyRasterBufferProvider::CopyOnWorkerThread( | 267 void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
| 268 StagingBuffer* staging_buffer, | 268 StagingBuffer* staging_buffer, |
| 269 ResourceProvider::ScopedWriteLockGL* resource_lock, | 269 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 270 const gpu::SyncToken& sync_token, | 270 const gpu::SyncToken& sync_token, |
| 271 const RasterSource* raster_source, | 271 const RasterSource* raster_source, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 resource_lock->set_synchronized(!async_worker_context_enabled_); | 380 resource_lock->set_synchronized(!async_worker_context_enabled_); |
| 381 } | 381 } |
| 382 | 382 |
| 383 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { | 383 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { |
| 384 return use_partial_raster_ | 384 return use_partial_raster_ |
| 385 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT | 385 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT |
| 386 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; | 386 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; |
| 387 } | 387 } |
| 388 | 388 |
| 389 } // namespace cc | 389 } // namespace cc |
| OLD | NEW |