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