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