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