| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/raster/gpu_rasterizer.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/trace_event/trace_event.h" | |
| 12 #include "cc/debug/devtools_instrumentation.h" | |
| 13 #include "cc/debug/frame_viewer_instrumentation.h" | |
| 14 #include "cc/output/context_provider.h" | |
| 15 #include "cc/playback/raster_source.h" | |
| 16 #include "cc/raster/raster_buffer.h" | |
| 17 #include "cc/raster/scoped_gpu_raster.h" | |
| 18 #include "cc/resources/resource.h" | |
| 19 #include "cc/tiles/tile_manager.h" | |
| 20 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 21 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | |
| 22 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 23 #include "third_party/skia/include/core/SkSurface.h" | |
| 24 #include "third_party/skia/include/gpu/GrContext.h" | |
| 25 | |
| 26 namespace cc { | |
| 27 | |
| 28 GpuRasterizer::GpuRasterizer(ContextProvider* worker_context_provider, | |
| 29 ResourceProvider* resource_provider, | |
| 30 bool use_distance_field_text, | |
| 31 int msaa_sample_count) | |
| 32 : worker_context_provider_(worker_context_provider), | |
| 33 resource_provider_(resource_provider), | |
| 34 use_distance_field_text_(use_distance_field_text), | |
| 35 msaa_sample_count_(msaa_sample_count) { | |
| 36 DCHECK(worker_context_provider_); | |
| 37 } | |
| 38 | |
| 39 GpuRasterizer::~GpuRasterizer() {} | |
| 40 | |
| 41 void GpuRasterizer::RasterizeSource( | |
| 42 ResourceProvider::ScopedWriteLockGr* write_lock, | |
| 43 const RasterSource* raster_source, | |
| 44 const gfx::Rect& raster_full_rect, | |
| 45 const gfx::Rect& playback_rect, | |
| 46 float scale, | |
| 47 const RasterSource::PlaybackSettings& playback_settings) { | |
| 48 // Play back raster_source into temp SkPicture. | |
| 49 SkPictureRecorder recorder; | |
| 50 const gfx::Size size = write_lock->GetResourceSize(); | |
| 51 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; | |
| 52 sk_sp<SkCanvas> canvas = sk_ref_sp( | |
| 53 recorder.beginRecording(size.width(), size.height(), NULL, flags)); | |
| 54 canvas->save(); | |
| 55 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, | |
| 56 scale, playback_settings); | |
| 57 canvas->restore(); | |
| 58 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | |
| 59 | |
| 60 // Turn on distance fields for layers that have ever animated. | |
| 61 bool use_distance_field_text = | |
| 62 use_distance_field_text_ || | |
| 63 raster_source->ShouldAttemptToUseDistanceFieldText(); | |
| 64 | |
| 65 // Playback picture into resource. | |
| 66 { | |
| 67 ScopedGpuRaster gpu_raster(worker_context_provider_); | |
| 68 write_lock->InitSkSurface( | |
| 69 worker_context_provider_->GrContext(), use_distance_field_text, | |
| 70 raster_source->CanUseLCDText(), msaa_sample_count_); | |
| 71 | |
| 72 SkSurface* sk_surface = write_lock->sk_surface(); | |
| 73 | |
| 74 // Allocating an SkSurface will fail after a lost context. Pretend we | |
| 75 // rasterized, as the contents of the resource don't matter anymore. | |
| 76 if (!sk_surface) | |
| 77 return; | |
| 78 | |
| 79 SkMultiPictureDraw multi_picture_draw; | |
| 80 multi_picture_draw.add(sk_surface->getCanvas(), picture.get()); | |
| 81 multi_picture_draw.draw(false); | |
| 82 write_lock->ReleaseSkSurface(); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 } // namespace cc | |
| OLD | NEW |