| 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 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "cc/base/histograms.h" | 15 #include "cc/base/histograms.h" |
| 16 #include "cc/playback/image_hijack_canvas.h" |
| 16 #include "cc/playback/raster_source.h" | 17 #include "cc/playback/raster_source.h" |
| 17 #include "cc/raster/scoped_gpu_raster.h" | 18 #include "cc/raster/scoped_gpu_raster.h" |
| 18 #include "cc/resources/resource.h" | 19 #include "cc/resources/resource.h" |
| 19 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
| 20 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | 21 #include "third_party/skia/include/core/SkMultiPictureDraw.h" |
| 21 #include "third_party/skia/include/core/SkPictureRecorder.h" | 22 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 22 #include "third_party/skia/include/core/SkSurface.h" | 23 #include "third_party/skia/include/core/SkSurface.h" |
| 23 #include "third_party/skia/include/gpu/GrContext.h" | 24 #include "third_party/skia/include/gpu/GrContext.h" |
| 24 | 25 |
| 25 namespace cc { | 26 namespace cc { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 55 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", | 56 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", |
| 56 client_name), | 57 client_name), |
| 57 100.0f * fraction_saved); | 58 100.0f * fraction_saved); |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Play back raster_source into temp SkPicture. | 61 // Play back raster_source into temp SkPicture. |
| 61 SkPictureRecorder recorder; | 62 SkPictureRecorder recorder; |
| 62 sk_sp<SkCanvas> canvas = sk_ref_sp( | 63 sk_sp<SkCanvas> canvas = sk_ref_sp( |
| 63 recorder.beginRecording(resource_size.width(), resource_size.height())); | 64 recorder.beginRecording(resource_size.width(), resource_size.height())); |
| 64 canvas->save(); | 65 canvas->save(); |
| 66 |
| 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 |
| 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 |
| 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 |
| 73 // later picture rasterization. |
| 74 RasterSource::PlaybackSettings settings = playback_settings; |
| 75 settings.use_image_hijack_canvas = false; |
| 65 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, | 76 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, |
| 66 scale, playback_settings); | 77 scale, settings); |
| 67 canvas->restore(); | 78 canvas->restore(); |
| 68 return recorder.finishRecordingAsPicture(); | 79 return recorder.finishRecordingAsPicture(); |
| 69 } | 80 } |
| 70 | 81 |
| 71 static void RasterizePicture(SkPicture* picture, | 82 static void RasterizePicture(SkPicture* picture, |
| 72 ContextProvider* context_provider, | 83 ContextProvider* context_provider, |
| 73 ResourceProvider::ScopedWriteLockGL* resource_lock, | 84 ResourceProvider::ScopedWriteLockGL* resource_lock, |
| 74 bool async_worker_context_enabled, | 85 bool async_worker_context_enabled, |
| 75 bool use_distance_field_text, | 86 bool use_distance_field_text, |
| 76 bool can_use_lcd_text, | 87 bool can_use_lcd_text, |
| 77 int msaa_sample_count) { | 88 int msaa_sample_count, |
| 89 ImageDecodeController* image_decode_controller, |
| 90 bool use_image_hijack_canvas) { |
| 78 ScopedGpuRaster gpu_raster(context_provider); | 91 ScopedGpuRaster gpu_raster(context_provider); |
| 79 | 92 |
| 80 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( | 93 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( |
| 81 context_provider, resource_lock, async_worker_context_enabled, | 94 context_provider, resource_lock, async_worker_context_enabled, |
| 82 use_distance_field_text, can_use_lcd_text, msaa_sample_count); | 95 use_distance_field_text, can_use_lcd_text, msaa_sample_count); |
| 83 SkSurface* sk_surface = scoped_surface.sk_surface(); | 96 SkSurface* sk_surface = scoped_surface.sk_surface(); |
| 84 // Allocating an SkSurface will fail after a lost context. Pretend we | 97 // Allocating an SkSurface will fail after a lost context. Pretend we |
| 85 // rasterized, as the contents of the resource don't matter anymore. | 98 // rasterized, as the contents of the resource don't matter anymore. |
| 86 if (!sk_surface) | 99 if (!sk_surface) |
| 87 return; | 100 return; |
| 88 | 101 |
| 102 // As we did not use the image hijack canvas during the initial playback to |
| 103 // |picture| (see PlaybackToPicture), we must enable it here if requested. |
| 104 SkCanvas* canvas = sk_surface->getCanvas(); |
| 105 std::unique_ptr<ImageHijackCanvas> hijack_canvas; |
| 106 if (use_image_hijack_canvas) { |
| 107 DCHECK(image_decode_controller); |
| 108 const SkImageInfo& info = canvas->imageInfo(); |
| 109 hijack_canvas.reset(new ImageHijackCanvas(info.width(), info.height(), |
| 110 image_decode_controller)); |
| 111 SkIRect raster_bounds; |
| 112 canvas->getClipDeviceBounds(&raster_bounds); |
| 113 hijack_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); |
| 114 hijack_canvas->setMatrix(canvas->getTotalMatrix()); |
| 115 hijack_canvas->addCanvas(canvas); |
| 116 |
| 117 // Replace canvas with our ImageHijackCanvas which is wrapping it. |
| 118 canvas = hijack_canvas.get(); |
| 119 } |
| 120 |
| 89 SkMultiPictureDraw multi_picture_draw; | 121 SkMultiPictureDraw multi_picture_draw; |
| 90 multi_picture_draw.add(sk_surface->getCanvas(), picture); | 122 multi_picture_draw.add(canvas, picture); |
| 91 multi_picture_draw.draw(false); | 123 multi_picture_draw.draw(false); |
| 92 } | 124 } |
| 93 | 125 |
| 94 } // namespace | 126 } // namespace |
| 95 | 127 |
| 96 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( | 128 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( |
| 97 GpuRasterBufferProvider* client, | 129 GpuRasterBufferProvider* client, |
| 98 ResourceProvider* resource_provider, | 130 ResourceProvider* resource_provider, |
| 99 ResourceId resource_id, | 131 ResourceId resource_id, |
| 100 bool async_worker_context_enabled, | 132 bool async_worker_context_enabled, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 raster_source, resource_has_previous_content, resource_lock->size(), | 260 raster_source, resource_has_previous_content, resource_lock->size(), |
| 229 raster_full_rect, raster_dirty_rect, scale, playback_settings); | 261 raster_full_rect, raster_dirty_rect, scale, playback_settings); |
| 230 | 262 |
| 231 // Turn on distance fields for layers that have ever animated. | 263 // Turn on distance fields for layers that have ever animated. |
| 232 bool use_distance_field_text = | 264 bool use_distance_field_text = |
| 233 use_distance_field_text_ || | 265 use_distance_field_text_ || |
| 234 raster_source->ShouldAttemptToUseDistanceFieldText(); | 266 raster_source->ShouldAttemptToUseDistanceFieldText(); |
| 235 | 267 |
| 236 RasterizePicture(picture.get(), worker_context_provider_, resource_lock, | 268 RasterizePicture(picture.get(), worker_context_provider_, resource_lock, |
| 237 async_worker_context_enabled_, use_distance_field_text, | 269 async_worker_context_enabled_, use_distance_field_text, |
| 238 raster_source->CanUseLCDText(), msaa_sample_count_); | 270 raster_source->CanUseLCDText(), msaa_sample_count_, |
| 271 raster_source->image_decode_controller(), |
| 272 playback_settings.use_image_hijack_canvas); |
| 239 | 273 |
| 240 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 274 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 241 | 275 |
| 242 // Barrier to sync worker context output to cc context. | 276 // Barrier to sync worker context output to cc context. |
| 243 gl->OrderingBarrierCHROMIUM(); | 277 gl->OrderingBarrierCHROMIUM(); |
| 244 | 278 |
| 245 // Generate sync token after the barrier for cross context synchronization. | 279 // Generate sync token after the barrier for cross context synchronization. |
| 246 gpu::SyncToken resource_sync_token; | 280 gpu::SyncToken resource_sync_token; |
| 247 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); | 281 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); |
| 248 resource_lock->set_sync_token(resource_sync_token); | 282 resource_lock->set_sync_token(resource_sync_token); |
| 249 resource_lock->set_synchronized(!async_worker_context_enabled_); | 283 resource_lock->set_synchronized(!async_worker_context_enabled_); |
| 250 } | 284 } |
| 251 | 285 |
| 252 } // namespace cc | 286 } // namespace cc |
| OLD | NEW |