| 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/raster_source.h" | 15 #include "cc/playback/raster_source.h" |
| 16 #include "cc/raster/raster_buffer.h" | 16 #include "cc/raster/raster_buffer.h" |
| 17 #include "cc/raster/scoped_gpu_raster.h" | 17 #include "cc/raster/scoped_gpu_raster.h" |
| 18 #include "cc/resources/resource.h" | 18 #include "cc/resources/resource.h" |
| 19 #include "cc/resources/resource_provider.h" | |
| 20 #include "cc/tiles/tile_manager.h" | 19 #include "cc/tiles/tile_manager.h" |
| 21 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
| 22 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | 21 #include "third_party/skia/include/core/SkMultiPictureDraw.h" |
| 23 #include "third_party/skia/include/core/SkPictureRecorder.h" | 22 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 24 #include "third_party/skia/include/core/SkSurface.h" | 23 #include "third_party/skia/include/core/SkSurface.h" |
| 25 #include "third_party/skia/include/gpu/GrContext.h" | 24 #include "third_party/skia/include/gpu/GrContext.h" |
| 26 | 25 |
| 27 namespace cc { | 26 namespace cc { |
| 28 | 27 |
| 29 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, | 28 GpuRasterizer::GpuRasterizer(ContextProvider* worker_context_provider, |
| 30 ResourceProvider* resource_provider, | 29 ResourceProvider* resource_provider, |
| 31 bool use_distance_field_text, | 30 bool use_distance_field_text, |
| 32 int msaa_sample_count) | 31 int msaa_sample_count) |
| 33 : resource_provider_(resource_provider), | 32 : worker_context_provider_(worker_context_provider), |
| 33 resource_provider_(resource_provider), |
| 34 use_distance_field_text_(use_distance_field_text), | 34 use_distance_field_text_(use_distance_field_text), |
| 35 msaa_sample_count_(msaa_sample_count) { | 35 msaa_sample_count_(msaa_sample_count) { |
| 36 DCHECK(worker_context_provider_); |
| 36 } | 37 } |
| 37 | 38 |
| 38 GpuRasterizer::~GpuRasterizer() { | 39 GpuRasterizer::~GpuRasterizer() { |
| 39 } | 40 } |
| 40 | 41 |
| 41 void GpuRasterizer::RasterizeSource( | 42 void GpuRasterizer::RasterizeSource( |
| 42 ResourceProvider::ScopedWriteLockGr* write_lock, | 43 ResourceProvider::ScopedWriteLockGr* write_lock, |
| 43 const RasterSource* raster_source, | 44 const RasterSource* raster_source, |
| 44 const gfx::Rect& raster_full_rect, | 45 const gfx::Rect& raster_full_rect, |
| 45 const gfx::Rect& playback_rect, | 46 const gfx::Rect& playback_rect, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 57 canvas->restore(); | 58 canvas->restore(); |
| 58 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 59 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
| 59 | 60 |
| 60 // Turn on distance fields for layers that have ever animated. | 61 // Turn on distance fields for layers that have ever animated. |
| 61 bool use_distance_field_text = | 62 bool use_distance_field_text = |
| 62 use_distance_field_text_ || | 63 use_distance_field_text_ || |
| 63 raster_source->ShouldAttemptToUseDistanceFieldText(); | 64 raster_source->ShouldAttemptToUseDistanceFieldText(); |
| 64 | 65 |
| 65 // Playback picture into resource. | 66 // Playback picture into resource. |
| 66 { | 67 { |
| 67 ScopedGpuRaster gpu_raster( | 68 ScopedGpuRaster gpu_raster(worker_context_provider_); |
| 68 resource_provider_->output_surface()->worker_context_provider()); | 69 write_lock->InitSkSurface( |
| 69 write_lock->InitSkSurface(use_distance_field_text, | 70 worker_context_provider_->GrContext(), use_distance_field_text, |
| 70 raster_source->CanUseLCDText(), | 71 raster_source->CanUseLCDText(), msaa_sample_count_); |
| 71 msaa_sample_count_); | |
| 72 | 72 |
| 73 SkSurface* sk_surface = write_lock->sk_surface(); | 73 SkSurface* sk_surface = write_lock->sk_surface(); |
| 74 | 74 |
| 75 // Allocating an SkSurface will fail after a lost context. Pretend we | 75 // Allocating an SkSurface will fail after a lost context. Pretend we |
| 76 // rasterized, as the contents of the resource don't matter anymore. | 76 // rasterized, as the contents of the resource don't matter anymore. |
| 77 if (!sk_surface) | 77 if (!sk_surface) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 SkMultiPictureDraw multi_picture_draw; | 80 SkMultiPictureDraw multi_picture_draw; |
| 81 multi_picture_draw.add(sk_surface->getCanvas(), picture.get()); | 81 multi_picture_draw.add(sk_surface->getCanvas(), picture.get()); |
| 82 multi_picture_draw.draw(false); | 82 multi_picture_draw.draw(false); |
| 83 write_lock->ReleaseSkSurface(); | 83 write_lock->ReleaseSkSurface(); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace cc | 87 } // namespace cc |
| OLD | NEW |