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