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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 OneCopyRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { | 51 OneCopyRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { |
52 client_->pending_raster_buffers_.erase(this); | 52 client_->pending_raster_buffers_.erase(this); |
53 } | 53 } |
54 | 54 |
55 void OneCopyRasterBufferProvider::RasterBufferImpl::Playback( | 55 void OneCopyRasterBufferProvider::RasterBufferImpl::Playback( |
56 const RasterSource* raster_source, | 56 const RasterSource* raster_source, |
57 const gfx::Rect& raster_full_rect, | 57 const gfx::Rect& raster_full_rect, |
58 const gfx::Rect& raster_dirty_rect, | 58 const gfx::Rect& raster_dirty_rect, |
59 uint64_t new_content_id, | 59 uint64_t new_content_id, |
60 float scale, | 60 const ScaleTranslate2d& transform, |
61 const RasterSource::PlaybackSettings& playback_settings) { | 61 const RasterSource::PlaybackSettings& playback_settings) { |
62 TRACE_EVENT0("cc", "OneCopyRasterBuffer::Playback"); | 62 TRACE_EVENT0("cc", "OneCopyRasterBuffer::Playback"); |
63 client_->PlaybackAndCopyOnWorkerThread( | 63 client_->PlaybackAndCopyOnWorkerThread( |
64 resource_, &lock_, sync_token_, raster_source, raster_full_rect, | 64 resource_, &lock_, sync_token_, raster_source, raster_full_rect, |
65 raster_dirty_rect, scale, playback_settings, previous_content_id_, | 65 raster_dirty_rect, transform, playback_settings, previous_content_id_, |
66 new_content_id); | 66 new_content_id); |
67 } | 67 } |
68 | 68 |
69 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( | 69 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( |
70 base::SequencedTaskRunner* task_runner, | 70 base::SequencedTaskRunner* task_runner, |
71 ContextProvider* compositor_context_provider, | 71 ContextProvider* compositor_context_provider, |
72 ContextProvider* worker_context_provider, | 72 ContextProvider* worker_context_provider, |
73 ResourceProvider* resource_provider, | 73 ResourceProvider* resource_provider, |
74 int max_copy_texture_chromium_size, | 74 int max_copy_texture_chromium_size, |
75 bool use_partial_raster, | 75 bool use_partial_raster, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 pending_raster_buffers_.clear(); | 208 pending_raster_buffers_.clear(); |
209 } | 209 } |
210 | 210 |
211 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( | 211 void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( |
212 const Resource* resource, | 212 const Resource* resource, |
213 ResourceProvider::ScopedWriteLockGL* resource_lock, | 213 ResourceProvider::ScopedWriteLockGL* resource_lock, |
214 const gpu::SyncToken& sync_token, | 214 const gpu::SyncToken& sync_token, |
215 const RasterSource* raster_source, | 215 const RasterSource* raster_source, |
216 const gfx::Rect& raster_full_rect, | 216 const gfx::Rect& raster_full_rect, |
217 const gfx::Rect& raster_dirty_rect, | 217 const gfx::Rect& raster_dirty_rect, |
218 float scale, | 218 const ScaleTranslate2d& transform, |
219 const RasterSource::PlaybackSettings& playback_settings, | 219 const RasterSource::PlaybackSettings& playback_settings, |
220 uint64_t previous_content_id, | 220 uint64_t previous_content_id, |
221 uint64_t new_content_id) { | 221 uint64_t new_content_id) { |
222 if (async_worker_context_enabled_) { | 222 if (async_worker_context_enabled_) { |
223 // Early out if sync token is invalid. This happens if the compositor | 223 // Early out if sync token is invalid. This happens if the compositor |
224 // context was lost before ScheduleTasks was called. | 224 // context was lost before ScheduleTasks was called. |
225 if (!sync_token.HasData()) | 225 if (!sync_token.HasData()) |
226 return; | 226 return; |
227 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); | 227 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
228 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 228 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
229 DCHECK(gl); | 229 DCHECK(gl); |
230 // Synchronize with compositor. | 230 // Synchronize with compositor. |
231 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 231 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
232 } | 232 } |
233 | 233 |
234 std::unique_ptr<StagingBuffer> staging_buffer = | 234 std::unique_ptr<StagingBuffer> staging_buffer = |
235 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); | 235 staging_pool_.AcquireStagingBuffer(resource, previous_content_id); |
236 | 236 |
237 PlaybackToStagingBuffer( | 237 PlaybackToStagingBuffer( |
238 staging_buffer.get(), resource, raster_source, raster_full_rect, | 238 staging_buffer.get(), resource, raster_source, raster_full_rect, |
239 raster_dirty_rect, scale, resource_lock->color_space_for_raster(), | 239 raster_dirty_rect, transform, resource_lock->color_space_for_raster(), |
240 playback_settings, previous_content_id, new_content_id); | 240 playback_settings, previous_content_id, new_content_id); |
241 | 241 |
242 CopyOnWorkerThread(staging_buffer.get(), resource_lock, sync_token, | 242 CopyOnWorkerThread(staging_buffer.get(), resource_lock, sync_token, |
243 raster_source, previous_content_id, new_content_id); | 243 raster_source, previous_content_id, new_content_id); |
244 | 244 |
245 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); | 245 staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); |
246 } | 246 } |
247 | 247 |
248 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( | 248 void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( |
249 StagingBuffer* staging_buffer, | 249 StagingBuffer* staging_buffer, |
250 const Resource* resource, | 250 const Resource* resource, |
251 const RasterSource* raster_source, | 251 const RasterSource* raster_source, |
252 const gfx::Rect& raster_full_rect, | 252 const gfx::Rect& raster_full_rect, |
253 const gfx::Rect& raster_dirty_rect, | 253 const gfx::Rect& raster_dirty_rect, |
254 float scale, | 254 const ScaleTranslate2d& transform, |
255 const gfx::ColorSpace& dst_color_space, | 255 const gfx::ColorSpace& dst_color_space, |
256 const RasterSource::PlaybackSettings& playback_settings, | 256 const RasterSource::PlaybackSettings& playback_settings, |
257 uint64_t previous_content_id, | 257 uint64_t previous_content_id, |
258 uint64_t new_content_id) { | 258 uint64_t new_content_id) { |
259 // Allocate GpuMemoryBuffer if necessary. If using partial raster, we | 259 // Allocate GpuMemoryBuffer if necessary. If using partial raster, we |
260 // must allocate a buffer with BufferUsage CPU_READ_WRITE_PERSISTENT. | 260 // must allocate a buffer with BufferUsage CPU_READ_WRITE_PERSISTENT. |
261 if (!staging_buffer->gpu_memory_buffer) { | 261 if (!staging_buffer->gpu_memory_buffer) { |
262 staging_buffer->gpu_memory_buffer = | 262 staging_buffer->gpu_memory_buffer = |
263 resource_provider_->gpu_memory_buffer_manager()->CreateGpuMemoryBuffer( | 263 resource_provider_->gpu_memory_buffer_manager()->CreateGpuMemoryBuffer( |
264 staging_buffer->size, BufferFormat(resource->format()), | 264 staging_buffer->size, BufferFormat(resource->format()), |
(...skipping 29 matching lines...) Expand all Loading... |
294 DCHECK(rv); | 294 DCHECK(rv); |
295 DCHECK(buffer->memory(0)); | 295 DCHECK(buffer->memory(0)); |
296 // RasterBufferProvider::PlaybackToMemory only supports unsigned strides. | 296 // RasterBufferProvider::PlaybackToMemory only supports unsigned strides. |
297 DCHECK_GE(buffer->stride(0), 0); | 297 DCHECK_GE(buffer->stride(0), 0); |
298 | 298 |
299 DCHECK(!playback_rect.IsEmpty()) | 299 DCHECK(!playback_rect.IsEmpty()) |
300 << "Why are we rastering a tile that's not dirty?"; | 300 << "Why are we rastering a tile that's not dirty?"; |
301 RasterBufferProvider::PlaybackToMemory( | 301 RasterBufferProvider::PlaybackToMemory( |
302 buffer->memory(0), resource->format(), staging_buffer->size, | 302 buffer->memory(0), resource->format(), staging_buffer->size, |
303 buffer->stride(0), raster_source, raster_full_rect, playback_rect, | 303 buffer->stride(0), raster_source, raster_full_rect, playback_rect, |
304 scale, dst_color_space, playback_settings); | 304 transform, dst_color_space, playback_settings); |
305 buffer->Unmap(); | 305 buffer->Unmap(); |
306 staging_buffer->content_id = new_content_id; | 306 staging_buffer->content_id = new_content_id; |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 void OneCopyRasterBufferProvider::CopyOnWorkerThread( | 310 void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
311 StagingBuffer* staging_buffer, | 311 StagingBuffer* staging_buffer, |
312 ResourceProvider::ScopedWriteLockGL* resource_lock, | 312 ResourceProvider::ScopedWriteLockGL* resource_lock, |
313 const gpu::SyncToken& sync_token, | 313 const gpu::SyncToken& sync_token, |
314 const RasterSource* raster_source, | 314 const RasterSource* raster_source, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 resource_lock->set_synchronized(!async_worker_context_enabled_); | 424 resource_lock->set_synchronized(!async_worker_context_enabled_); |
425 } | 425 } |
426 | 426 |
427 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { | 427 gfx::BufferUsage OneCopyRasterBufferProvider::StagingBufferUsage() const { |
428 return use_partial_raster_ | 428 return use_partial_raster_ |
429 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT | 429 ? gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT |
430 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; | 430 : gfx::BufferUsage::GPU_READ_CPU_READ_WRITE; |
431 } | 431 } |
432 | 432 |
433 } // namespace cc | 433 } // namespace cc |
OLD | NEW |