| 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/gpu_raster_buffer_provider.h" | 5 #include "cc/raster/gpu_raster_buffer_provider.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace cc { | 26 namespace cc { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 static sk_sp<SkPicture> PlaybackToPicture( | 29 static sk_sp<SkPicture> PlaybackToPicture( |
| 30 const RasterSource* raster_source, | 30 const RasterSource* raster_source, |
| 31 bool resource_has_previous_content, | 31 bool resource_has_previous_content, |
| 32 const gfx::Size& resource_size, | 32 const gfx::Size& resource_size, |
| 33 const gfx::Rect& raster_full_rect, | 33 const gfx::Rect& raster_full_rect, |
| 34 const gfx::Rect& raster_dirty_rect, | 34 const gfx::Rect& raster_dirty_rect, |
| 35 const gfx::SizeF& scales, | 35 const ScaleTranslate2d& transform, |
| 36 const RasterSource::PlaybackSettings& playback_settings) { | 36 const RasterSource::PlaybackSettings& playback_settings) { |
| 37 // GPU raster doesn't do low res tiles, so should always include images. | 37 // GPU raster doesn't do low res tiles, so should always include images. |
| 38 DCHECK(!playback_settings.skip_images); | 38 DCHECK(!playback_settings.skip_images); |
| 39 | 39 |
| 40 gfx::Rect playback_rect = raster_full_rect; | 40 gfx::Rect playback_rect = raster_full_rect; |
| 41 if (resource_has_previous_content) { | 41 if (resource_has_previous_content) { |
| 42 playback_rect.Intersect(raster_dirty_rect); | 42 playback_rect.Intersect(raster_dirty_rect); |
| 43 } | 43 } |
| 44 DCHECK(!playback_rect.IsEmpty()) | 44 DCHECK(!playback_rect.IsEmpty()) |
| 45 << "Why are we rastering a tile that's not dirty?"; | 45 << "Why are we rastering a tile that's not dirty?"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 // The GPU image decode controller assumes that Skia is done with an image | 67 // The GPU image decode controller assumes that Skia is done with an image |
| 68 // when playback is complete. However, in this case, where we play back to a | 68 // when playback is complete. However, in this case, where we play back to a |
| 69 // picture, we don't actually finish with the images until the picture is | 69 // picture, we don't actually finish with the images until the picture is |
| 70 // rasterized later. This can cause lifetime issues in the GPU image decode | 70 // rasterized later. This can cause lifetime issues in the GPU image decode |
| 71 // controller. To avoid this, we disable the image hijack canvas (and image | 71 // controller. To avoid this, we disable the image hijack canvas (and image |
| 72 // decode controller) for this playback step, instead enabling it for the | 72 // decode controller) for this playback step, instead enabling it for the |
| 73 // later picture rasterization. | 73 // later picture rasterization. |
| 74 RasterSource::PlaybackSettings settings = playback_settings; | 74 RasterSource::PlaybackSettings settings = playback_settings; |
| 75 settings.use_image_hijack_canvas = false; | 75 settings.use_image_hijack_canvas = false; |
| 76 raster_source->PlaybackToCanvas(canvas, raster_full_rect, playback_rect, | 76 raster_source->PlaybackToCanvas(canvas, raster_full_rect, playback_rect, |
| 77 scales, settings); | 77 transform, settings); |
| 78 canvas->restore(); | 78 canvas->restore(); |
| 79 return recorder.finishRecordingAsPicture(); | 79 return recorder.finishRecordingAsPicture(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 static void RasterizePicture(SkPicture* picture, | 82 static void RasterizePicture(SkPicture* picture, |
| 83 ContextProvider* context_provider, | 83 ContextProvider* context_provider, |
| 84 ResourceProvider::ScopedWriteLockGL* resource_lock, | 84 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 85 bool async_worker_context_enabled, | 85 bool async_worker_context_enabled, |
| 86 bool use_distance_field_text, | 86 bool use_distance_field_text, |
| 87 bool can_use_lcd_text, | 87 bool can_use_lcd_text, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { | 142 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { |
| 143 client_->pending_raster_buffers_.erase(this); | 143 client_->pending_raster_buffers_.erase(this); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void GpuRasterBufferProvider::RasterBufferImpl::Playback( | 146 void GpuRasterBufferProvider::RasterBufferImpl::Playback( |
| 147 const RasterSource* raster_source, | 147 const RasterSource* raster_source, |
| 148 const gfx::Rect& raster_full_rect, | 148 const gfx::Rect& raster_full_rect, |
| 149 const gfx::Rect& raster_dirty_rect, | 149 const gfx::Rect& raster_dirty_rect, |
| 150 uint64_t new_content_id, | 150 uint64_t new_content_id, |
| 151 const gfx::SizeF& scales, | 151 const ScaleTranslate2d& transform, |
| 152 const RasterSource::PlaybackSettings& playback_settings) { | 152 const RasterSource::PlaybackSettings& playback_settings) { |
| 153 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); | 153 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); |
| 154 client_->PlaybackOnWorkerThread(&lock_, sync_token_, | 154 client_->PlaybackOnWorkerThread(&lock_, sync_token_, |
| 155 resource_has_previous_content_, raster_source, | 155 resource_has_previous_content_, raster_source, |
| 156 raster_full_rect, raster_dirty_rect, | 156 raster_full_rect, raster_dirty_rect, |
| 157 new_content_id, scales, playback_settings); | 157 new_content_id, transform, playback_settings); |
| 158 } | 158 } |
| 159 | 159 |
| 160 GpuRasterBufferProvider::GpuRasterBufferProvider( | 160 GpuRasterBufferProvider::GpuRasterBufferProvider( |
| 161 ContextProvider* compositor_context_provider, | 161 ContextProvider* compositor_context_provider, |
| 162 ContextProvider* worker_context_provider, | 162 ContextProvider* worker_context_provider, |
| 163 ResourceProvider* resource_provider, | 163 ResourceProvider* resource_provider, |
| 164 bool use_distance_field_text, | 164 bool use_distance_field_text, |
| 165 int gpu_rasterization_msaa_sample_count, | 165 int gpu_rasterization_msaa_sample_count, |
| 166 bool async_worker_context_enabled) | 166 bool async_worker_context_enabled) |
| 167 : compositor_context_provider_(compositor_context_provider), | 167 : compositor_context_provider_(compositor_context_provider), |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 239 } |
| 240 | 240 |
| 241 void GpuRasterBufferProvider::PlaybackOnWorkerThread( | 241 void GpuRasterBufferProvider::PlaybackOnWorkerThread( |
| 242 ResourceProvider::ScopedWriteLockGL* resource_lock, | 242 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 243 const gpu::SyncToken& sync_token, | 243 const gpu::SyncToken& sync_token, |
| 244 bool resource_has_previous_content, | 244 bool resource_has_previous_content, |
| 245 const RasterSource* raster_source, | 245 const RasterSource* raster_source, |
| 246 const gfx::Rect& raster_full_rect, | 246 const gfx::Rect& raster_full_rect, |
| 247 const gfx::Rect& raster_dirty_rect, | 247 const gfx::Rect& raster_dirty_rect, |
| 248 uint64_t new_content_id, | 248 uint64_t new_content_id, |
| 249 const gfx::SizeF& scales, | 249 const ScaleTranslate2d& transform, |
| 250 const RasterSource::PlaybackSettings& playback_settings) { | 250 const RasterSource::PlaybackSettings& playback_settings) { |
| 251 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); | 251 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
| 252 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 252 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 253 DCHECK(gl); | 253 DCHECK(gl); |
| 254 | 254 |
| 255 if (async_worker_context_enabled_) { | 255 if (async_worker_context_enabled_) { |
| 256 // Early out if sync token is invalid. This happens if the compositor | 256 // Early out if sync token is invalid. This happens if the compositor |
| 257 // context was lost before ScheduleTasks was called. | 257 // context was lost before ScheduleTasks was called. |
| 258 if (!sync_token.HasData()) | 258 if (!sync_token.HasData()) |
| 259 return; | 259 return; |
| 260 // Synchronize with compositor. | 260 // Synchronize with compositor. |
| 261 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 261 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 262 } | 262 } |
| 263 | 263 |
| 264 sk_sp<SkPicture> picture = PlaybackToPicture( | 264 sk_sp<SkPicture> picture = PlaybackToPicture( |
| 265 raster_source, resource_has_previous_content, resource_lock->size(), | 265 raster_source, resource_has_previous_content, resource_lock->size(), |
| 266 raster_full_rect, raster_dirty_rect, scales, playback_settings); | 266 raster_full_rect, raster_dirty_rect, transform, playback_settings); |
| 267 | 267 |
| 268 // Turn on distance fields for layers that have ever animated. | 268 // Turn on distance fields for layers that have ever animated. |
| 269 bool use_distance_field_text = | 269 bool use_distance_field_text = |
| 270 use_distance_field_text_ || | 270 use_distance_field_text_ || |
| 271 raster_source->ShouldAttemptToUseDistanceFieldText(); | 271 raster_source->ShouldAttemptToUseDistanceFieldText(); |
| 272 | 272 |
| 273 RasterizePicture(picture.get(), worker_context_provider_, resource_lock, | 273 RasterizePicture(picture.get(), worker_context_provider_, resource_lock, |
| 274 async_worker_context_enabled_, use_distance_field_text, | 274 async_worker_context_enabled_, use_distance_field_text, |
| 275 raster_source->CanUseLCDText(), | 275 raster_source->CanUseLCDText(), |
| 276 raster_source->HasImpliedColorSpace(), msaa_sample_count_, | 276 raster_source->HasImpliedColorSpace(), msaa_sample_count_, |
| 277 raster_source->image_decode_cache(), | 277 raster_source->image_decode_cache(), |
| 278 playback_settings.use_image_hijack_canvas); | 278 playback_settings.use_image_hijack_canvas); |
| 279 | 279 |
| 280 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 280 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 281 | 281 |
| 282 // Barrier to sync worker context output to cc context. | 282 // Barrier to sync worker context output to cc context. |
| 283 gl->OrderingBarrierCHROMIUM(); | 283 gl->OrderingBarrierCHROMIUM(); |
| 284 | 284 |
| 285 // Generate sync token after the barrier for cross context synchronization. | 285 // Generate sync token after the barrier for cross context synchronization. |
| 286 gpu::SyncToken resource_sync_token; | 286 gpu::SyncToken resource_sync_token; |
| 287 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); | 287 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); |
| 288 resource_lock->set_sync_token(resource_sync_token); | 288 resource_lock->set_sync_token(resource_sync_token); |
| 289 resource_lock->set_synchronized(!async_worker_context_enabled_); | 289 resource_lock->set_synchronized(!async_worker_context_enabled_); |
| 290 } | 290 } |
| 291 | 291 |
| 292 } // namespace cc | 292 } // namespace cc |
| OLD | NEW |