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