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

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

Issue 2885533002: cc: Allocate resources on worker context.
Patch Set: rebase Created 3 years, 6 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
« no previous file with comments | « no previous file | cc/raster/one_copy_raster_buffer_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_raster_buffer_provider.h" 5 #include "cc/raster/gpu_raster_buffer_provider.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "cc/base/histograms.h" 15 #include "cc/base/histograms.h"
16 #include "cc/paint/paint_canvas.h" 16 #include "cc/paint/paint_canvas.h"
17 #include "cc/raster/image_hijack_canvas.h" 17 #include "cc/raster/image_hijack_canvas.h"
18 #include "cc/raster/raster_source.h" 18 #include "cc/raster/raster_source.h"
19 #include "cc/raster/scoped_gpu_raster.h" 19 #include "cc/raster/scoped_gpu_raster.h"
20 #include "cc/resources/resource.h" 20 #include "cc/resources/resource.h"
21 #include "gpu/command_buffer/client/context_support.h" 21 #include "gpu/command_buffer/client/context_support.h"
22 #include "gpu/command_buffer/client/gles2_interface.h" 22 #include "gpu/command_buffer/client/gles2_interface.h"
23 #include "skia/ext/texture_handle.h"
24 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkMultiPictureDraw.h" 25 #include "third_party/skia/include/core/SkMultiPictureDraw.h"
24 #include "third_party/skia/include/core/SkPictureRecorder.h" 26 #include "third_party/skia/include/core/SkPictureRecorder.h"
25 #include "third_party/skia/include/core/SkSurface.h" 27 #include "third_party/skia/include/core/SkSurface.h"
26 #include "third_party/skia/include/gpu/GrContext.h" 28 #include "third_party/skia/include/gpu/GrContext.h"
29 #include "third_party/skia/include/gpu/gl/GrGLTypes.h"
27 30
28 namespace cc { 31 namespace cc {
29 namespace { 32 namespace {
30 33
34 static sk_sp<SkSurface> CreateSkSurface(GrContext* gr_context,
35 unsigned texture_id,
36 GLenum target,
37 const gfx::Size& size,
38 ResourceFormat format,
39 bool use_distance_field_text,
40 bool can_use_lcd_text,
41 int msaa_sample_count) {
42 GrGLTextureInfo texture_info;
43 texture_info.fID = texture_id;
44 texture_info.fTarget = target;
45 GrBackendTextureDesc desc;
46 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
47 desc.fWidth = size.width();
48 desc.fHeight = size.height();
49 desc.fConfig = ToGrPixelConfig(format);
50 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
51 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info);
52 desc.fSampleCnt = msaa_sample_count;
53
54 uint32_t flags =
55 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
56 // Use unknown pixel geometry to disable LCD text.
57 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry);
58 if (can_use_lcd_text) {
59 // LegacyFontHost will get LCD text and skia figures out what type to use.
60 surface_props =
61 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType);
62 }
63 return SkSurface::MakeFromBackendTextureAsRenderTarget(
64 gr_context, desc, nullptr, &surface_props);
65 }
66
31 static void RasterizeSource( 67 static void RasterizeSource(
32 const RasterSource* raster_source, 68 const RasterSource* raster_source,
33 bool resource_has_previous_content, 69 bool resource_has_previous_content,
34 const gfx::Size& resource_size, 70 const gfx::Size& resource_size,
35 const gfx::Rect& raster_full_rect, 71 const gfx::Rect& raster_full_rect,
36 const gfx::Rect& raster_dirty_rect, 72 const gfx::Rect& raster_dirty_rect,
37 const gfx::AxisTransform2d& transform, 73 const gfx::AxisTransform2d& transform,
38 const RasterSource::PlaybackSettings& playback_settings, 74 const RasterSource::PlaybackSettings& playback_settings,
39 ContextProvider* context_provider, 75 ContextProvider* context_provider,
40 ResourceProvider::ScopedWriteLockGL* resource_lock, 76 ResourceProvider::ScopedWriteLockGL* resource_lock,
41 bool async_worker_context_enabled, 77 bool async_worker_context_enabled,
42 bool use_distance_field_text, 78 bool use_distance_field_text,
43 int msaa_sample_count) { 79 int msaa_sample_count) {
44 ScopedGpuRaster gpu_raster(context_provider); 80 ScopedGpuRaster gpu_raster(context_provider);
45 81
46 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( 82 gpu::gles2::GLES2Interface* gl = context_provider->ContextGL();
47 context_provider, resource_lock, async_worker_context_enabled, 83
48 use_distance_field_text, raster_source->CanUseLCDText(), 84 unsigned texture_id = resource_lock->texture_id();
49 msaa_sample_count); 85 if (async_worker_context_enabled)
50 SkSurface* sk_surface = scoped_surface.sk_surface(); 86 texture_id = resource_lock->ConsumeTexture(gl);
87
88 sk_sp<SkSurface> sk_surface = CreateSkSurface(
89 context_provider->GrContext(), texture_id, resource_lock->target(),
90 resource_lock->size(), resource_lock->format(), use_distance_field_text,
91 raster_source->CanUseLCDText(), msaa_sample_count);
92
51 // Allocating an SkSurface will fail after a lost context. Pretend we 93 // Allocating an SkSurface will fail after a lost context. Pretend we
52 // rasterized, as the contents of the resource don't matter anymore. 94 // rasterized, as the contents of the resource don't matter anymore.
53 if (!sk_surface) { 95 if (!sk_surface) {
54 DLOG(ERROR) << "Failed to allocate raster surface"; 96 DLOG(ERROR) << "Failed to allocate raster surface";
55 return; 97 return;
56 } 98 }
57 99
58 // Playback 100 // Playback
59 gfx::Rect playback_rect = raster_full_rect; 101 gfx::Rect playback_rect = raster_full_rect;
60 if (resource_has_previous_content) { 102 if (resource_has_previous_content) {
(...skipping 12 matching lines...) Expand all
73 float fraction_saved = 1.0f - fraction_partial_rastered; 115 float fraction_saved = 1.0f - fraction_partial_rastered;
74 UMA_HISTOGRAM_PERCENTAGE( 116 UMA_HISTOGRAM_PERCENTAGE(
75 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", 117 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu",
76 client_name), 118 client_name),
77 100.0f * fraction_saved); 119 100.0f * fraction_saved);
78 } 120 }
79 121
80 raster_source->PlaybackToCanvas( 122 raster_source->PlaybackToCanvas(
81 sk_surface->getCanvas(), resource_lock->color_space_for_raster(), 123 sk_surface->getCanvas(), resource_lock->color_space_for_raster(),
82 raster_full_rect, playback_rect, transform, playback_settings); 124 raster_full_rect, playback_rect, transform, playback_settings);
125
126 sk_surface->prepareForExternalIO();
127
128 if (async_worker_context_enabled)
129 gl->DeleteTextures(1, &texture_id);
83 } 130 }
84 131
85 } // namespace 132 } // namespace
86 133
87 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( 134 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl(
88 GpuRasterBufferProvider* client, 135 GpuRasterBufferProvider* client,
89 ResourceProvider* resource_provider, 136 ResourceProvider* resource_provider,
90 ResourceId resource_id, 137 ResourceId resource_id,
91 bool async_worker_context_enabled, 138 bool async_worker_context_enabled,
92 bool resource_has_previous_content) 139 bool resource_has_previous_content)
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 ResourceProvider::ScopedWriteLockGL* resource_lock, 305 ResourceProvider::ScopedWriteLockGL* resource_lock,
259 const gpu::SyncToken& sync_token, 306 const gpu::SyncToken& sync_token,
260 bool resource_has_previous_content, 307 bool resource_has_previous_content,
261 const RasterSource* raster_source, 308 const RasterSource* raster_source,
262 const gfx::Rect& raster_full_rect, 309 const gfx::Rect& raster_full_rect,
263 const gfx::Rect& raster_dirty_rect, 310 const gfx::Rect& raster_dirty_rect,
264 uint64_t new_content_id, 311 uint64_t new_content_id,
265 const gfx::AxisTransform2d& transform, 312 const gfx::AxisTransform2d& transform,
266 const RasterSource::PlaybackSettings& playback_settings) { 313 const RasterSource::PlaybackSettings& playback_settings) {
267 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); 314 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_);
315
268 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); 316 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
269 DCHECK(gl); 317 DCHECK(gl);
270 318
271 if (async_worker_context_enabled_) { 319 if (async_worker_context_enabled_) {
272 // Early out if sync token is invalid. This happens if the compositor 320 // Early out if sync token is invalid. This happens if the compositor
273 // context was lost before ScheduleTasks was called. 321 // context was lost before ScheduleTasks was called.
274 if (!sync_token.HasData()) 322 if (!sync_token.HasData()) {
323 DLOG(ERROR) << "Context destroyed while scheduling raster tasks";
275 return; 324 return;
325 }
276 // Synchronize with compositor. 326 // Synchronize with compositor.
277 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); 327 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
278 } 328 }
279 329
280 RasterizeSource(raster_source, resource_has_previous_content, 330 RasterizeSource(raster_source, resource_has_previous_content,
281 resource_lock->size(), raster_full_rect, raster_dirty_rect, 331 resource_lock->size(), raster_full_rect, raster_dirty_rect,
282 transform, playback_settings, worker_context_provider_, 332 transform, playback_settings, worker_context_provider_,
283 resource_lock, async_worker_context_enabled_, 333 resource_lock, async_worker_context_enabled_,
284 use_distance_field_text_, msaa_sample_count_); 334 use_distance_field_text_, msaa_sample_count_);
285 335
286 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 336 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
287 337
288 // Barrier to sync worker context output to cc context. 338 // Barrier to sync worker context output to cc context.
289 gl->OrderingBarrierCHROMIUM(); 339 gl->OrderingBarrierCHROMIUM();
290 340
291 // Generate sync token after the barrier for cross context synchronization. 341 // Generate sync token after the barrier for cross context synchronization.
292 gpu::SyncToken resource_sync_token; 342 gpu::SyncToken resource_sync_token;
293 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); 343 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData());
294 resource_lock->set_sync_token(resource_sync_token); 344 resource_lock->set_sync_token(resource_sync_token);
295 resource_lock->set_synchronized(!async_worker_context_enabled_);
296 } 345 }
297 346
298 } // namespace cc 347 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/raster/one_copy_raster_buffer_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698