| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_rasterizer.h" | 5 #include "cc/raster/gpu_rasterizer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "cc/debug/devtools_instrumentation.h" | 12 #include "cc/debug/devtools_instrumentation.h" |
| 13 #include "cc/debug/frame_viewer_instrumentation.h" | 13 #include "cc/debug/frame_viewer_instrumentation.h" |
| 14 #include "cc/output/context_provider.h" | 14 #include "cc/output/context_provider.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/raster_buffer.h" | 17 #include "cc/raster/raster_buffer.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 "cc/resources/resource_provider.h" | 20 #include "cc/resources/resource_provider.h" |
| 20 #include "cc/tiles/tile_manager.h" | 21 #include "cc/tiles/tile_manager.h" |
| 21 #include "gpu/command_buffer/client/gles2_interface.h" | 22 #include "gpu/command_buffer/client/gles2_interface.h" |
| 22 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | 23 #include "third_party/skia/include/core/SkMultiPictureDraw.h" |
| 23 #include "third_party/skia/include/core/SkPictureRecorder.h" | 24 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 24 #include "third_party/skia/include/core/SkSurface.h" | 25 #include "third_party/skia/include/core/SkSurface.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 45 const gfx::Rect& playback_rect, | 46 const gfx::Rect& playback_rect, |
| 46 float scale, | 47 float scale, |
| 47 const RasterSource::PlaybackSettings& playback_settings) { | 48 const RasterSource::PlaybackSettings& playback_settings) { |
| 48 // Play back raster_source into temp SkPicture. | 49 // Play back raster_source into temp SkPicture. |
| 49 SkPictureRecorder recorder; | 50 SkPictureRecorder recorder; |
| 50 const gfx::Size size = write_lock->GetResourceSize(); | 51 const gfx::Size size = write_lock->GetResourceSize(); |
| 51 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; | 52 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; |
| 52 sk_sp<SkCanvas> canvas = sk_ref_sp( | 53 sk_sp<SkCanvas> canvas = sk_ref_sp( |
| 53 recorder.beginRecording(size.width(), size.height(), NULL, flags)); | 54 recorder.beginRecording(size.width(), size.height(), NULL, flags)); |
| 54 canvas->save(); | 55 canvas->save(); |
| 56 // The GPU image decode controller assumes that Skia is done with an image |
| 57 // when playback is complete. However, in this case, where we play back to a |
| 58 // picture, we don't actually finish with the images until the picture is |
| 59 // rasterized later. This can cause lifetime issues in the GPU image decode |
| 60 // controller. To avoid this, we disable the image hijack canvas (and image |
| 61 // decode controller) for this playback step, instead enabling it for the |
| 62 // later picture rasterization. |
| 63 RasterSource::PlaybackSettings settings = playback_settings; |
| 64 settings.use_image_hijack_canvas = false; |
| 55 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, | 65 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, |
| 56 scale, playback_settings); | 66 scale, settings); |
| 57 canvas->restore(); | 67 canvas->restore(); |
| 58 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 68 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
| 59 | 69 |
| 60 // Turn on distance fields for layers that have ever animated. | 70 // Turn on distance fields for layers that have ever animated. |
| 61 bool use_distance_field_text = | 71 bool use_distance_field_text = |
| 62 use_distance_field_text_ || | 72 use_distance_field_text_ || |
| 63 raster_source->ShouldAttemptToUseDistanceFieldText(); | 73 raster_source->ShouldAttemptToUseDistanceFieldText(); |
| 64 | 74 |
| 65 // Playback picture into resource. | 75 // Playback picture into resource. |
| 66 { | 76 { |
| 67 ScopedGpuRaster gpu_raster( | 77 ScopedGpuRaster gpu_raster( |
| 68 resource_provider_->output_surface()->worker_context_provider()); | 78 resource_provider_->output_surface()->worker_context_provider()); |
| 69 write_lock->InitSkSurface(use_distance_field_text, | 79 write_lock->InitSkSurface(use_distance_field_text, |
| 70 raster_source->CanUseLCDText(), | 80 raster_source->CanUseLCDText(), |
| 71 msaa_sample_count_); | 81 msaa_sample_count_); |
| 72 | 82 |
| 73 SkSurface* sk_surface = write_lock->sk_surface(); | 83 SkSurface* sk_surface = write_lock->sk_surface(); |
| 74 | 84 |
| 75 // Allocating an SkSurface will fail after a lost context. Pretend we | 85 // Allocating an SkSurface will fail after a lost context. Pretend we |
| 76 // rasterized, as the contents of the resource don't matter anymore. | 86 // rasterized, as the contents of the resource don't matter anymore. |
| 77 if (!sk_surface) | 87 if (!sk_surface) |
| 78 return; | 88 return; |
| 79 | 89 |
| 90 // As we did not use the image hijack canvas during the initial playback to |
| 91 // |picture| (see PlaybackToPicture), we must enable it here if requested. |
| 92 SkCanvas* canvas = sk_surface->getCanvas(); |
| 93 std::unique_ptr<ImageHijackCanvas> hijack_canvas; |
| 94 if (playback_settings.use_image_hijack_canvas) { |
| 95 const SkImageInfo& info = canvas->imageInfo(); |
| 96 hijack_canvas.reset( |
| 97 new ImageHijackCanvas(info.width(), info.height(), |
| 98 raster_source->image_decode_controller())); |
| 99 SkIRect raster_bounds; |
| 100 canvas->getClipDeviceBounds(&raster_bounds); |
| 101 hijack_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds)); |
| 102 hijack_canvas->setMatrix(canvas->getTotalMatrix()); |
| 103 hijack_canvas->addCanvas(canvas); |
| 104 |
| 105 // Replace canvas with our ImageHijackCanvas which is wrapping it. |
| 106 canvas = hijack_canvas.get(); |
| 107 } |
| 108 |
| 80 SkMultiPictureDraw multi_picture_draw; | 109 SkMultiPictureDraw multi_picture_draw; |
| 81 multi_picture_draw.add(sk_surface->getCanvas(), picture.get()); | 110 multi_picture_draw.add(canvas, picture.get()); |
| 82 multi_picture_draw.draw(false); | 111 multi_picture_draw.draw(false); |
| 83 write_lock->ReleaseSkSurface(); | 112 write_lock->ReleaseSkSurface(); |
| 84 } | 113 } |
| 85 } | 114 } |
| 86 | 115 |
| 87 } // namespace cc | 116 } // namespace cc |
| OLD | NEW |