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

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

Issue 2149843003: Fix MultiPictureDraw issues with GpuImageDecodeController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 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/playback/image_hijack_canvas.h"
16 #include "cc/playback/raster_source.h" 17 #include "cc/playback/raster_source.h"
17 #include "cc/raster/scoped_gpu_raster.h" 18 #include "cc/raster/scoped_gpu_raster.h"
18 #include "cc/resources/resource.h" 19 #include "cc/resources/resource.h"
19 #include "gpu/command_buffer/client/gles2_interface.h" 20 #include "gpu/command_buffer/client/gles2_interface.h"
20 #include "third_party/skia/include/core/SkMultiPictureDraw.h" 21 #include "third_party/skia/include/core/SkMultiPictureDraw.h"
21 #include "third_party/skia/include/core/SkPictureRecorder.h" 22 #include "third_party/skia/include/core/SkPictureRecorder.h"
22 #include "third_party/skia/include/core/SkSurface.h" 23 #include "third_party/skia/include/core/SkSurface.h"
23 #include "third_party/skia/include/gpu/GrContext.h" 24 #include "third_party/skia/include/gpu/GrContext.h"
24 25
25 namespace cc { 26 namespace cc {
(...skipping 30 matching lines...) Expand all
56 client_name), 57 client_name),
57 100.0f * fraction_saved); 58 100.0f * fraction_saved);
58 } 59 }
59 60
60 // Play back raster_source into temp SkPicture. 61 // Play back raster_source into temp SkPicture.
61 SkPictureRecorder recorder; 62 SkPictureRecorder recorder;
62 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; 63 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag;
63 sk_sp<SkCanvas> canvas = sk_ref_sp(recorder.beginRecording( 64 sk_sp<SkCanvas> canvas = sk_ref_sp(recorder.beginRecording(
64 resource_size.width(), resource_size.height(), NULL, flags)); 65 resource_size.width(), resource_size.height(), NULL, flags));
65 canvas->save(); 66 canvas->save();
67
68 // The GPU image decode controller assumes that Skia is done with an image
69 // when playback is complete. However, in this case, where we play back to a
70 // picture, we don't actually finish with the images until the picture is
71 // rasterized later. This can cause lifetime issues in the GPU image decode
72 // controller. To avoid this, we disable the image hijack canvas (and image
73 // decode controller) for this playback step, instead enabling it for the
74 // later picture rasterization.
75 RasterSource::PlaybackSettings settings = playback_settings;
76 settings.use_image_hijack_canvas = false;
66 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, 77 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect,
67 scale, playback_settings); 78 scale, settings);
68 canvas->restore(); 79 canvas->restore();
69 return recorder.finishRecordingAsPicture(); 80 return recorder.finishRecordingAsPicture();
70 } 81 }
71 82
72 static void RasterizePicture(SkPicture* picture, 83 static void RasterizePicture(
73 ContextProvider* context_provider, 84 SkPicture* picture,
74 ResourceProvider::ScopedWriteLockGL* resource_lock, 85 ContextProvider* context_provider,
75 bool async_worker_context_enabled, 86 ResourceProvider::ScopedWriteLockGL* resource_lock,
76 bool use_distance_field_text, 87 bool async_worker_context_enabled,
77 bool can_use_lcd_text, 88 bool use_distance_field_text,
78 int msaa_sample_count) { 89 bool can_use_lcd_text,
90 int msaa_sample_count,
91 const RasterSource* raster_source,
vmpstr 2016/07/14 21:41:54 Can you just pass IDC here? and just "use_hijack_c
ericrk 2016/07/14 22:04:20 yup, makes sense.
92 const RasterSource::PlaybackSettings& playback_settings) {
79 ScopedGpuRaster gpu_raster(context_provider); 93 ScopedGpuRaster gpu_raster(context_provider);
80 94
81 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( 95 ResourceProvider::ScopedSkSurfaceProvider scoped_surface(
82 context_provider, resource_lock, async_worker_context_enabled, 96 context_provider, resource_lock, async_worker_context_enabled,
83 use_distance_field_text, can_use_lcd_text, msaa_sample_count); 97 use_distance_field_text, can_use_lcd_text, msaa_sample_count);
84 SkSurface* sk_surface = scoped_surface.sk_surface(); 98 SkSurface* sk_surface = scoped_surface.sk_surface();
85 // Allocating an SkSurface will fail after a lost context. Pretend we 99 // Allocating an SkSurface will fail after a lost context. Pretend we
86 // rasterized, as the contents of the resource don't matter anymore. 100 // rasterized, as the contents of the resource don't matter anymore.
87 if (!sk_surface) 101 if (!sk_surface)
88 return; 102 return;
89 103
104 // As we did not use the image hijack canvas during the initial playback to
105 // |picture| (see PlaybackToPicture), we must enable it here if requested.
106 SkCanvas* canvas = sk_surface->getCanvas();
107 std::unique_ptr<ImageHijackCanvas> hijack_canvas;
108 if (playback_settings.use_image_hijack_canvas) {
109 const SkImageInfo& info = canvas->imageInfo();
110 hijack_canvas.reset(
111 new ImageHijackCanvas(info.width(), info.height(),
112 raster_source->GetImageDecodeController()));
113 SkIRect raster_bounds;
114 canvas->getClipDeviceBounds(&raster_bounds);
115 hijack_canvas->clipRect(SkRect::MakeFromIRect(raster_bounds));
116 hijack_canvas->setMatrix(canvas->getTotalMatrix());
117 hijack_canvas->addCanvas(canvas);
118
119 // Replace canvas with our ImageHijackCanvas which is wrapping it.
120 canvas = hijack_canvas.get();
121 }
122
90 SkMultiPictureDraw multi_picture_draw; 123 SkMultiPictureDraw multi_picture_draw;
91 multi_picture_draw.add(sk_surface->getCanvas(), picture); 124 multi_picture_draw.add(canvas, picture);
92 multi_picture_draw.draw(false); 125 multi_picture_draw.draw(false);
93 } 126 }
94 127
95 } // namespace 128 } // namespace
96 129
97 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( 130 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl(
98 GpuRasterBufferProvider* client, 131 GpuRasterBufferProvider* client,
99 ResourceProvider* resource_provider, 132 ResourceProvider* resource_provider,
100 ResourceId resource_id, 133 ResourceId resource_id,
101 bool async_worker_context_enabled, 134 bool async_worker_context_enabled,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 raster_source, resource_has_previous_content, resource_lock->size(), 262 raster_source, resource_has_previous_content, resource_lock->size(),
230 raster_full_rect, raster_dirty_rect, scale, playback_settings); 263 raster_full_rect, raster_dirty_rect, scale, playback_settings);
231 264
232 // Turn on distance fields for layers that have ever animated. 265 // Turn on distance fields for layers that have ever animated.
233 bool use_distance_field_text = 266 bool use_distance_field_text =
234 use_distance_field_text_ || 267 use_distance_field_text_ ||
235 raster_source->ShouldAttemptToUseDistanceFieldText(); 268 raster_source->ShouldAttemptToUseDistanceFieldText();
236 269
237 RasterizePicture(picture.get(), worker_context_provider_, resource_lock, 270 RasterizePicture(picture.get(), worker_context_provider_, resource_lock,
238 async_worker_context_enabled_, use_distance_field_text, 271 async_worker_context_enabled_, use_distance_field_text,
239 raster_source->CanUseLCDText(), msaa_sample_count_); 272 raster_source->CanUseLCDText(), msaa_sample_count_,
273 raster_source, playback_settings);
240 274
241 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 275 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
242 276
243 // Barrier to sync worker context output to cc context. 277 // Barrier to sync worker context output to cc context.
244 gl->OrderingBarrierCHROMIUM(); 278 gl->OrderingBarrierCHROMIUM();
245 279
246 // Generate sync token after the barrier for cross context synchronization. 280 // Generate sync token after the barrier for cross context synchronization.
247 gpu::SyncToken resource_sync_token; 281 gpu::SyncToken resource_sync_token;
248 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); 282 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData());
249 resource_lock->set_sync_token(resource_sync_token); 283 resource_lock->set_sync_token(resource_sync_token);
250 resource_lock->set_synchronized(!async_worker_context_enabled_); 284 resource_lock->set_synchronized(!async_worker_context_enabled_);
251 } 285 }
252 286
253 } // namespace cc 287 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698