| 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 15 matching lines...) Expand all Loading... |
| 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 float scale, | 35 float scale, |
| 36 const gfx::Vector2dF& translation, |
| 36 const RasterSource::PlaybackSettings& playback_settings) { | 37 const RasterSource::PlaybackSettings& playback_settings) { |
| 37 // GPU raster doesn't do low res tiles, so should always include images. | 38 // GPU raster doesn't do low res tiles, so should always include images. |
| 38 DCHECK(!playback_settings.skip_images); | 39 DCHECK(!playback_settings.skip_images); |
| 39 | 40 |
| 40 gfx::Rect playback_rect = raster_full_rect; | 41 gfx::Rect playback_rect = raster_full_rect; |
| 41 if (resource_has_previous_content) { | 42 if (resource_has_previous_content) { |
| 42 playback_rect.Intersect(raster_dirty_rect); | 43 playback_rect.Intersect(raster_dirty_rect); |
| 43 } | 44 } |
| 44 DCHECK(!playback_rect.IsEmpty()) | 45 DCHECK(!playback_rect.IsEmpty()) |
| 45 << "Why are we rastering a tile that's not dirty?"; | 46 << "Why are we rastering a tile that's not dirty?"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 56 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", | 57 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", |
| 57 client_name), | 58 client_name), |
| 58 100.0f * fraction_saved); | 59 100.0f * fraction_saved); |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Play back raster_source into temp SkPicture. | 62 // Play back raster_source into temp SkPicture. |
| 62 SkPictureRecorder recorder; | 63 SkPictureRecorder recorder; |
| 63 sk_sp<SkCanvas> canvas = sk_ref_sp( | 64 sk_sp<SkCanvas> canvas = sk_ref_sp( |
| 64 recorder.beginRecording(resource_size.width(), resource_size.height())); | 65 recorder.beginRecording(resource_size.width(), resource_size.height())); |
| 65 canvas->save(); | 66 canvas->save(); |
| 67 canvas->translate(-raster_full_rect.x(), -raster_full_rect.y()); |
| 68 canvas->clipRect(gfx::RectToSkRect(playback_rect)); |
| 69 canvas->translate(translation.x(), translation.y()); |
| 70 canvas->scale(scale, scale); |
| 66 | 71 |
| 67 // The GPU image decode controller assumes that Skia is done with an image | 72 // 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 | 73 // 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 | 74 // 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 | 75 // 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 | 76 // controller. To avoid this, we disable the image hijack canvas (and image |
| 72 // decode controller) for this playback step, instead enabling it for the | 77 // decode controller) for this playback step, instead enabling it for the |
| 73 // later picture rasterization. | 78 // later picture rasterization. |
| 74 RasterSource::PlaybackSettings settings = playback_settings; | 79 RasterSource::PlaybackSettings settings = playback_settings; |
| 75 settings.use_image_hijack_canvas = false; | 80 settings.use_image_hijack_canvas = false; |
| 76 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, | 81 raster_source->PlaybackToCanvas(canvas.get(), settings); |
| 77 scale, settings); | |
| 78 canvas->restore(); | 82 canvas->restore(); |
| 79 return recorder.finishRecordingAsPicture(); | 83 return recorder.finishRecordingAsPicture(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 static void RasterizePicture(SkPicture* picture, | 86 static void RasterizePicture(SkPicture* picture, |
| 83 ContextProvider* context_provider, | 87 ContextProvider* context_provider, |
| 84 ResourceProvider::ScopedWriteLockGL* resource_lock, | 88 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 85 bool async_worker_context_enabled, | 89 bool async_worker_context_enabled, |
| 86 bool use_distance_field_text, | 90 bool use_distance_field_text, |
| 87 bool can_use_lcd_text, | 91 bool can_use_lcd_text, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { | 144 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { |
| 141 client_->pending_raster_buffers_.erase(this); | 145 client_->pending_raster_buffers_.erase(this); |
| 142 } | 146 } |
| 143 | 147 |
| 144 void GpuRasterBufferProvider::RasterBufferImpl::Playback( | 148 void GpuRasterBufferProvider::RasterBufferImpl::Playback( |
| 145 const RasterSource* raster_source, | 149 const RasterSource* raster_source, |
| 146 const gfx::Rect& raster_full_rect, | 150 const gfx::Rect& raster_full_rect, |
| 147 const gfx::Rect& raster_dirty_rect, | 151 const gfx::Rect& raster_dirty_rect, |
| 148 uint64_t new_content_id, | 152 uint64_t new_content_id, |
| 149 float scale, | 153 float scale, |
| 154 const gfx::Vector2dF& translation, |
| 150 const RasterSource::PlaybackSettings& playback_settings) { | 155 const RasterSource::PlaybackSettings& playback_settings) { |
| 151 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); | 156 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); |
| 152 client_->PlaybackOnWorkerThread(&lock_, sync_token_, | 157 client_->PlaybackOnWorkerThread( |
| 153 resource_has_previous_content_, raster_source, | 158 &lock_, sync_token_, resource_has_previous_content_, raster_source, |
| 154 raster_full_rect, raster_dirty_rect, | 159 raster_full_rect, raster_dirty_rect, new_content_id, scale, translation, |
| 155 new_content_id, scale, playback_settings); | 160 playback_settings); |
| 156 } | 161 } |
| 157 | 162 |
| 158 GpuRasterBufferProvider::GpuRasterBufferProvider( | 163 GpuRasterBufferProvider::GpuRasterBufferProvider( |
| 159 ContextProvider* compositor_context_provider, | 164 ContextProvider* compositor_context_provider, |
| 160 ContextProvider* worker_context_provider, | 165 ContextProvider* worker_context_provider, |
| 161 ResourceProvider* resource_provider, | 166 ResourceProvider* resource_provider, |
| 162 bool use_distance_field_text, | 167 bool use_distance_field_text, |
| 163 int gpu_rasterization_msaa_sample_count, | 168 int gpu_rasterization_msaa_sample_count, |
| 164 bool async_worker_context_enabled) | 169 bool async_worker_context_enabled) |
| 165 : compositor_context_provider_(compositor_context_provider), | 170 : compositor_context_provider_(compositor_context_provider), |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 243 |
| 239 void GpuRasterBufferProvider::PlaybackOnWorkerThread( | 244 void GpuRasterBufferProvider::PlaybackOnWorkerThread( |
| 240 ResourceProvider::ScopedWriteLockGL* resource_lock, | 245 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 241 const gpu::SyncToken& sync_token, | 246 const gpu::SyncToken& sync_token, |
| 242 bool resource_has_previous_content, | 247 bool resource_has_previous_content, |
| 243 const RasterSource* raster_source, | 248 const RasterSource* raster_source, |
| 244 const gfx::Rect& raster_full_rect, | 249 const gfx::Rect& raster_full_rect, |
| 245 const gfx::Rect& raster_dirty_rect, | 250 const gfx::Rect& raster_dirty_rect, |
| 246 uint64_t new_content_id, | 251 uint64_t new_content_id, |
| 247 float scale, | 252 float scale, |
| 253 const gfx::Vector2dF& translation, |
| 248 const RasterSource::PlaybackSettings& playback_settings) { | 254 const RasterSource::PlaybackSettings& playback_settings) { |
| 249 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); | 255 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
| 250 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 256 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 251 DCHECK(gl); | 257 DCHECK(gl); |
| 252 | 258 |
| 253 if (async_worker_context_enabled_) { | 259 if (async_worker_context_enabled_) { |
| 254 // Early out if sync token is invalid. This happens if the compositor | 260 // Early out if sync token is invalid. This happens if the compositor |
| 255 // context was lost before ScheduleTasks was called. | 261 // context was lost before ScheduleTasks was called. |
| 256 if (!sync_token.HasData()) | 262 if (!sync_token.HasData()) |
| 257 return; | 263 return; |
| 258 // Synchronize with compositor. | 264 // Synchronize with compositor. |
| 259 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 265 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 260 } | 266 } |
| 261 | 267 |
| 262 sk_sp<SkPicture> picture = PlaybackToPicture( | 268 sk_sp<SkPicture> picture = PlaybackToPicture( |
| 263 raster_source, resource_has_previous_content, resource_lock->size(), | 269 raster_source, resource_has_previous_content, resource_lock->size(), |
| 264 raster_full_rect, raster_dirty_rect, scale, playback_settings); | 270 raster_full_rect, raster_dirty_rect, scale, translation, |
| 271 playback_settings); |
| 265 | 272 |
| 266 // Turn on distance fields for layers that have ever animated. | 273 // Turn on distance fields for layers that have ever animated. |
| 267 bool use_distance_field_text = | 274 bool use_distance_field_text = |
| 268 use_distance_field_text_ || | 275 use_distance_field_text_ || |
| 269 raster_source->ShouldAttemptToUseDistanceFieldText(); | 276 raster_source->ShouldAttemptToUseDistanceFieldText(); |
| 270 | 277 |
| 271 RasterizePicture(picture.get(), worker_context_provider_, resource_lock, | 278 RasterizePicture(picture.get(), worker_context_provider_, resource_lock, |
| 272 async_worker_context_enabled_, use_distance_field_text, | 279 async_worker_context_enabled_, use_distance_field_text, |
| 273 raster_source->CanUseLCDText(), msaa_sample_count_, | 280 raster_source->CanUseLCDText(), msaa_sample_count_, |
| 274 raster_source->image_decode_controller(), | 281 raster_source->image_decode_controller(), |
| 275 playback_settings.use_image_hijack_canvas); | 282 playback_settings.use_image_hijack_canvas); |
| 276 | 283 |
| 277 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 284 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 278 | 285 |
| 279 // Barrier to sync worker context output to cc context. | 286 // Barrier to sync worker context output to cc context. |
| 280 gl->OrderingBarrierCHROMIUM(); | 287 gl->OrderingBarrierCHROMIUM(); |
| 281 | 288 |
| 282 // Generate sync token after the barrier for cross context synchronization. | 289 // Generate sync token after the barrier for cross context synchronization. |
| 283 gpu::SyncToken resource_sync_token; | 290 gpu::SyncToken resource_sync_token; |
| 284 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); | 291 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); |
| 285 resource_lock->set_sync_token(resource_sync_token); | 292 resource_lock->set_sync_token(resource_sync_token); |
| 286 resource_lock->set_synchronized(!async_worker_context_enabled_); | 293 resource_lock->set_synchronized(!async_worker_context_enabled_); |
| 287 } | 294 } |
| 288 | 295 |
| 289 } // namespace cc | 296 } // namespace cc |
| OLD | NEW |