Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: cc/raster/gpu_rasterizer.cc

Issue 1876363005: cc: GPU rasterize to an auxiliary surface when using MSAA renderbuffers Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 19 #include "cc/resources/resource_provider.h"
20 #include "cc/tiles/tile_manager.h" 20 #include "cc/tiles/tile_manager.h"
21 #include "gpu/command_buffer/client/gles2_interface.h" 21 #include "gpu/command_buffer/client/gles2_interface.h"
22 #include "third_party/skia/include/core/SkMultiPictureDraw.h" 22 #include "third_party/skia/include/core/SkMultiPictureDraw.h"
23 #include "third_party/skia/include/core/SkPictureRecorder.h" 23 #include "third_party/skia/include/core/SkPictureRecorder.h"
24 #include "third_party/skia/include/core/SkSurface.h" 24 #include "third_party/skia/include/core/SkSurface.h"
25 #include "third_party/skia/include/gpu/GrContext.h" 25 #include "third_party/skia/include/gpu/GrContext.h"
26 26
27 namespace cc { 27 namespace cc {
28 28
29 namespace {
30 SkColorType ToSkColorType(ResourceFormat format) {
31 switch (format) {
32 case RGBA_8888:
33 return kRGBA_8888_SkColorType;
34 case BGRA_8888:
35 return kBGRA_8888_SkColorType;
36 case RGBA_4444:
37 return kARGB_4444_SkColorType;
38 default:
39 break;
40 }
41 DCHECK(false) << "Unsupported resource format.";
42 return kN32_SkColorType;
43 }
44 } // namespace
45
29 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, 46 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider,
30 ResourceProvider* resource_provider, 47 ResourceProvider* resource_provider,
31 bool use_distance_field_text, 48 bool use_device_independent_fonts,
32 int msaa_sample_count) 49 int msaa_sample_count)
33 : resource_provider_(resource_provider), 50 : resource_provider_(resource_provider),
34 use_distance_field_text_(use_distance_field_text), 51 use_device_independent_fonts_(use_device_independent_fonts),
35 msaa_sample_count_(msaa_sample_count) { 52 msaa_sample_count_(msaa_sample_count),
36 } 53 msaa_surface_use_device_independent_fonts_(false),
54 msaa_surface_can_use_lcd_text_(false) {}
37 55
38 GpuRasterizer::~GpuRasterizer() { 56 GpuRasterizer::~GpuRasterizer() {
39 } 57 }
40 58
41 void GpuRasterizer::RasterizeSource( 59 void GpuRasterizer::RasterizeSource(
42 ResourceProvider::ScopedWriteLockGr* write_lock, 60 ResourceProvider::ScopedWriteLockGr* write_lock,
43 const RasterSource* raster_source, 61 const RasterSource* raster_source,
44 const gfx::Rect& raster_full_rect, 62 const gfx::Rect& raster_full_rect,
45 const gfx::Rect& playback_rect, 63 const gfx::Rect& playback_rect,
46 float scale, 64 float scale,
47 const RasterSource::PlaybackSettings& playback_settings) { 65 const RasterSource::PlaybackSettings& playback_settings) {
48 // Play back raster_source into temp SkPicture. 66 // Play back raster_source into temp SkPicture.
49 SkPictureRecorder recorder; 67 SkPictureRecorder recorder;
50 const gfx::Size size = write_lock->GetResourceSize(); 68 const gfx::Size size = write_lock->GetResourceSize();
51 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; 69 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
52 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( 70 skia::RefPtr<SkCanvas> canvas = skia::SharePtr(
53 recorder.beginRecording(size.width(), size.height(), NULL, flags)); 71 recorder.beginRecording(size.width(), size.height(), NULL, flags));
54 canvas->save(); 72 canvas->save();
55 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, 73 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect,
56 scale, playback_settings); 74 scale, playback_settings);
57 canvas->restore(); 75 canvas->restore();
58 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 76 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
59 77
60 // Turn on distance fields for layers that have ever animated. 78 // Turn on device independent fonts for layers that have ever animated.
61 bool use_distance_field_text = 79 bool use_device_independent_fonts =
62 use_distance_field_text_ || 80 use_device_independent_fonts_ ||
63 raster_source->ShouldAttemptToUseDistanceFieldText(); 81 raster_source->ShouldAttemptToUseDistanceFieldText();
64 82
65 // Playback picture into resource. 83 // Playback picture into resource.
66 { 84 {
67 ScopedGpuRaster gpu_raster( 85 ContextProvider* context_provider =
68 resource_provider_->output_surface()->worker_context_provider()); 86 resource_provider_->output_surface()->worker_context_provider();
69 write_lock->InitSkSurface(use_distance_field_text, 87 ScopedGpuRaster gpu_raster(context_provider);
70 raster_source->CanUseLCDText(), 88 SkSurface* sk_surface = AcquireSurface(
71 msaa_sample_count_); 89 gpu_raster, context_provider, write_lock, use_device_independent_fonts,
72 90 raster_source->CanUseLCDText());
73 SkSurface* sk_surface = write_lock->sk_surface();
74 91
75 // Allocating an SkSurface will fail after a lost context. Pretend we 92 // Allocating an SkSurface will fail after a lost context. Pretend we
76 // rasterized, as the contents of the resource don't matter anymore. 93 // rasterized, as the contents of the resource don't matter anymore.
77 if (!sk_surface) 94 if (!sk_surface)
78 return; 95 return;
79 96
80 SkMultiPictureDraw multi_picture_draw; 97 SkMultiPictureDraw multi_picture_draw;
81 multi_picture_draw.add(sk_surface->getCanvas(), picture.get()); 98 multi_picture_draw.add(sk_surface->getCanvas(), picture.get());
82 multi_picture_draw.draw(false); 99 multi_picture_draw.draw(false);
83 write_lock->ReleaseSkSurface(); 100 ReleaseSurface(gpu_raster, write_lock);
84 } 101 }
85 } 102 }
86 103
104 // ScopedGpuRaster is an argument so that we know caller holds it, proves
105 // that Skia context has been reset.
106 SkSurface* GpuRasterizer::AcquireSurface(
107 const ScopedGpuRaster&,
108 ContextProvider* context_provider,
109 ResourceProvider::ScopedWriteLockGr* write_lock,
110 bool use_device_independent_fonts,
111 bool can_use_lcd_text) {
112 bool uses_separate_msaa_backing_store =
113 msaa_sample_count_ > 0 &&
114 !context_provider->ContextCapabilities()
115 .gpu.multisampled_render_to_texture &&
Stephen White 2016/04/15 14:10:54 Rather than checking for the absence of multisampl
116 !context_provider->ContextCapabilities()
117 .gpu.chromium_framebuffer_mixed_samples;
Stephen White 2016/04/15 14:10:54 Out of curiosity, why do we not keep a persistent
118 if (uses_separate_msaa_backing_store) {
119 // Creating SkSurface, rendering to it and then destroying the surface is
120 // slow due to need to allocate the backing store, e.g. GL renderbuffers.
121 // Use intermediate longlived MSAA surface for rendering and then copy this
122 // to the actual tile.
123 gfx::Size size = write_lock->GetResourceSize();
124 SkColorType color_type = ToSkColorType(write_lock->GetResourceFormat());
125 SkImageInfo surface_image_info = SkImageInfo::Make(
126 size.width(), size.height(), color_type, kPremul_SkAlphaType);
127 AllocateMSAASurfaceIfNeeded(surface_image_info,
128 use_device_independent_fonts, can_use_lcd_text);
129 if (msaa_surface_)
130 return msaa_surface_.get();
131 }
132
133 msaa_surface_.reset();
134
135 write_lock->InitSkSurface(use_device_independent_fonts, can_use_lcd_text,
136 msaa_sample_count_);
137
138 return write_lock->sk_surface();
139 }
140 void GpuRasterizer::ReleaseSurface(
141 const ScopedGpuRaster&,
142 ResourceProvider::ScopedWriteLockGr* write_lock) {
143 if (msaa_sample_count_ > 0 && msaa_surface_) {
144 write_lock->InitSkSurface(false, false, 0);
145 SkSurface* target_surface = write_lock->sk_surface();
146 if (!target_surface)
147 return;
148 msaa_surface_->draw(target_surface->getCanvas(), 0, 0, nullptr);
Stephen White 2016/04/15 14:10:53 Is this the extra blit you're talking about? So w
149 }
150 write_lock->ReleaseSkSurface();
151 }
152
153 void GpuRasterizer::AllocateMSAASurfaceIfNeeded(
154 const SkImageInfo& image_info,
155 bool use_device_independent_fonts,
156 bool can_use_lcd_text) {
157 if (msaa_surface_ && msaa_surface_image_info_ == image_info &&
158 msaa_surface_use_device_independent_fonts_ ==
159 use_device_independent_fonts &&
160 msaa_surface_can_use_lcd_text_ == can_use_lcd_text)
161 return;
162
163 msaa_surface_.reset();
164
165 uint32_t flags = use_device_independent_fonts
166 ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag
167 : 0;
168 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry);
169 if (can_use_lcd_text)
170 surface_props =
171 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType);
172
173 bool use_worker_context = true;
174 class GrContext* gr_context =
175 resource_provider_->GrContext(use_worker_context);
176
177 msaa_surface_ =
178 SkSurface::MakeRenderTarget(gr_context, SkBudgeted::kYes, image_info,
179 msaa_sample_count_, &surface_props);
180 msaa_surface_image_info_ = image_info;
181 msaa_surface_use_device_independent_fonts_ = use_device_independent_fonts;
182 msaa_surface_can_use_lcd_text_ = can_use_lcd_text;
183 }
184
87 } // namespace cc 185 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698