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

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

Issue 2175553002: Raster PictureLayerTiling with fractional translation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up Created 4 years, 3 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/base/scale_translate2d.h"
16 #include "cc/playback/image_hijack_canvas.h" 17 #include "cc/playback/image_hijack_canvas.h"
17 #include "cc/playback/raster_source.h" 18 #include "cc/playback/raster_source.h"
18 #include "cc/raster/scoped_gpu_raster.h" 19 #include "cc/raster/scoped_gpu_raster.h"
19 #include "cc/resources/resource.h" 20 #include "cc/resources/resource.h"
20 #include "gpu/command_buffer/client/gles2_interface.h" 21 #include "gpu/command_buffer/client/gles2_interface.h"
21 #include "third_party/skia/include/core/SkMultiPictureDraw.h" 22 #include "third_party/skia/include/core/SkMultiPictureDraw.h"
22 #include "third_party/skia/include/core/SkPictureRecorder.h" 23 #include "third_party/skia/include/core/SkPictureRecorder.h"
23 #include "third_party/skia/include/core/SkSurface.h" 24 #include "third_party/skia/include/core/SkSurface.h"
24 #include "third_party/skia/include/gpu/GrContext.h" 25 #include "third_party/skia/include/gpu/GrContext.h"
25 26
26 namespace cc { 27 namespace cc {
27 namespace { 28 namespace {
28 29
29 static sk_sp<SkPicture> PlaybackToPicture( 30 static sk_sp<SkPicture> PlaybackToPicture(
30 const RasterSource* raster_source, 31 const RasterSource* raster_source,
31 bool resource_has_previous_content, 32 bool resource_has_previous_content,
32 const gfx::Size& resource_size, 33 const gfx::Size& resource_size,
33 const gfx::Rect& raster_full_rect, 34 const gfx::Rect& raster_full_rect,
34 const gfx::Rect& raster_dirty_rect, 35 const gfx::Rect& raster_dirty_rect,
35 float scale, 36 const ScaleTranslate2d& transform,
36 const RasterSource::PlaybackSettings& playback_settings) { 37 const RasterSource::PlaybackSettings& playback_settings) {
37 // GPU raster doesn't do low res tiles, so should always include images. 38 // GPU raster doesn't do low res tiles, so should always include images.
38 DCHECK(!playback_settings.skip_images); 39 DCHECK(!playback_settings.skip_images);
39 40
40 gfx::Rect playback_rect = raster_full_rect; 41 gfx::Rect playback_rect = raster_full_rect;
41 if (resource_has_previous_content) { 42 if (resource_has_previous_content) {
42 playback_rect.Intersect(raster_dirty_rect); 43 playback_rect.Intersect(raster_dirty_rect);
43 } 44 }
44 DCHECK(!playback_rect.IsEmpty()) 45 DCHECK(!playback_rect.IsEmpty())
45 << "Why are we rastering a tile that's not dirty?"; 46 << "Why are we rastering a tile that's not dirty?";
(...skipping 10 matching lines...) Expand all
56 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", 57 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu",
57 client_name), 58 client_name),
58 100.0f * fraction_saved); 59 100.0f * fraction_saved);
59 } 60 }
60 61
61 // Play back raster_source into temp SkPicture. 62 // Play back raster_source into temp SkPicture.
62 SkPictureRecorder recorder; 63 SkPictureRecorder recorder;
63 sk_sp<SkCanvas> canvas = sk_ref_sp( 64 sk_sp<SkCanvas> canvas = sk_ref_sp(
64 recorder.beginRecording(resource_size.width(), resource_size.height())); 65 recorder.beginRecording(resource_size.width(), resource_size.height()));
65 canvas->save(); 66 canvas->save();
67 canvas->translate(-raster_full_rect.x(), -raster_full_rect.y());
68 canvas->clipRect(gfx::RectToSkRect(playback_rect));
69 transform.ApplyToCanvas(canvas.get());
66 70
67 // The GPU image decode controller assumes that Skia is done with an image 71 // The GPU image decode controller assumes that Skia is done with an image
68 // when playback is complete. However, in this case, where we play back to a 72 // when playback is complete. However, in this case, where we play back to a
69 // picture, we don't actually finish with the images until the picture is 73 // picture, we don't actually finish with the images until the picture is
70 // rasterized later. This can cause lifetime issues in the GPU image decode 74 // rasterized later. This can cause lifetime issues in the GPU image decode
71 // controller. To avoid this, we disable the image hijack canvas (and image 75 // controller. To avoid this, we disable the image hijack canvas (and image
72 // decode controller) for this playback step, instead enabling it for the 76 // decode controller) for this playback step, instead enabling it for the
73 // later picture rasterization. 77 // later picture rasterization.
74 RasterSource::PlaybackSettings settings = playback_settings; 78 RasterSource::PlaybackSettings settings = playback_settings;
75 settings.use_image_hijack_canvas = false; 79 settings.use_image_hijack_canvas = false;
76 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect, 80 raster_source->PlaybackToCanvas(canvas.get(), raster_full_rect, playback_rect,
77 scale, settings); 81 transform, settings);
78 canvas->restore(); 82 canvas->restore();
79 return recorder.finishRecordingAsPicture(); 83 return recorder.finishRecordingAsPicture();
80 } 84 }
81 85
82 static void RasterizePicture(SkPicture* picture, 86 static void RasterizePicture(SkPicture* picture,
83 ContextProvider* context_provider, 87 ContextProvider* context_provider,
84 ResourceProvider::ScopedWriteLockGL* resource_lock, 88 ResourceProvider::ScopedWriteLockGL* resource_lock,
85 bool async_worker_context_enabled, 89 bool async_worker_context_enabled,
86 bool use_distance_field_text, 90 bool use_distance_field_text,
87 bool can_use_lcd_text, 91 bool can_use_lcd_text,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 143
140 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { 144 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() {
141 client_->pending_raster_buffers_.erase(this); 145 client_->pending_raster_buffers_.erase(this);
142 } 146 }
143 147
144 void GpuRasterBufferProvider::RasterBufferImpl::Playback( 148 void GpuRasterBufferProvider::RasterBufferImpl::Playback(
145 const RasterSource* raster_source, 149 const RasterSource* raster_source,
146 const gfx::Rect& raster_full_rect, 150 const gfx::Rect& raster_full_rect,
147 const gfx::Rect& raster_dirty_rect, 151 const gfx::Rect& raster_dirty_rect,
148 uint64_t new_content_id, 152 uint64_t new_content_id,
149 float scale, 153 const ScaleTranslate2d& transform,
150 const RasterSource::PlaybackSettings& playback_settings) { 154 const RasterSource::PlaybackSettings& playback_settings) {
151 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); 155 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback");
152 client_->PlaybackOnWorkerThread(&lock_, sync_token_, 156 client_->PlaybackOnWorkerThread(&lock_, sync_token_,
153 resource_has_previous_content_, raster_source, 157 resource_has_previous_content_, raster_source,
154 raster_full_rect, raster_dirty_rect, 158 raster_full_rect, raster_dirty_rect,
155 new_content_id, scale, playback_settings); 159 new_content_id, transform, playback_settings);
156 } 160 }
157 161
158 GpuRasterBufferProvider::GpuRasterBufferProvider( 162 GpuRasterBufferProvider::GpuRasterBufferProvider(
159 ContextProvider* compositor_context_provider, 163 ContextProvider* compositor_context_provider,
160 ContextProvider* worker_context_provider, 164 ContextProvider* worker_context_provider,
161 ResourceProvider* resource_provider, 165 ResourceProvider* resource_provider,
162 bool use_distance_field_text, 166 bool use_distance_field_text,
163 int gpu_rasterization_msaa_sample_count, 167 int gpu_rasterization_msaa_sample_count,
164 bool async_worker_context_enabled) 168 bool async_worker_context_enabled)
165 : compositor_context_provider_(compositor_context_provider), 169 : compositor_context_provider_(compositor_context_provider),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 241 }
238 242
239 void GpuRasterBufferProvider::PlaybackOnWorkerThread( 243 void GpuRasterBufferProvider::PlaybackOnWorkerThread(
240 ResourceProvider::ScopedWriteLockGL* resource_lock, 244 ResourceProvider::ScopedWriteLockGL* resource_lock,
241 const gpu::SyncToken& sync_token, 245 const gpu::SyncToken& sync_token,
242 bool resource_has_previous_content, 246 bool resource_has_previous_content,
243 const RasterSource* raster_source, 247 const RasterSource* raster_source,
244 const gfx::Rect& raster_full_rect, 248 const gfx::Rect& raster_full_rect,
245 const gfx::Rect& raster_dirty_rect, 249 const gfx::Rect& raster_dirty_rect,
246 uint64_t new_content_id, 250 uint64_t new_content_id,
247 float scale, 251 const ScaleTranslate2d& transform,
248 const RasterSource::PlaybackSettings& playback_settings) { 252 const RasterSource::PlaybackSettings& playback_settings) {
249 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); 253 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_);
250 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); 254 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
251 DCHECK(gl); 255 DCHECK(gl);
252 256
253 if (async_worker_context_enabled_) { 257 if (async_worker_context_enabled_) {
254 // Early out if sync token is invalid. This happens if the compositor 258 // Early out if sync token is invalid. This happens if the compositor
255 // context was lost before ScheduleTasks was called. 259 // context was lost before ScheduleTasks was called.
256 if (!sync_token.HasData()) 260 if (!sync_token.HasData())
257 return; 261 return;
258 // Synchronize with compositor. 262 // Synchronize with compositor.
259 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); 263 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
260 } 264 }
261 265
262 sk_sp<SkPicture> picture = PlaybackToPicture( 266 sk_sp<SkPicture> picture = PlaybackToPicture(
263 raster_source, resource_has_previous_content, resource_lock->size(), 267 raster_source, resource_has_previous_content, resource_lock->size(),
264 raster_full_rect, raster_dirty_rect, scale, playback_settings); 268 raster_full_rect, raster_dirty_rect, transform, playback_settings);
265 269
266 // Turn on distance fields for layers that have ever animated. 270 // Turn on distance fields for layers that have ever animated.
267 bool use_distance_field_text = 271 bool use_distance_field_text =
268 use_distance_field_text_ || 272 use_distance_field_text_ ||
269 raster_source->ShouldAttemptToUseDistanceFieldText(); 273 raster_source->ShouldAttemptToUseDistanceFieldText();
270 274
271 RasterizePicture(picture.get(), worker_context_provider_, resource_lock, 275 RasterizePicture(picture.get(), worker_context_provider_, resource_lock,
272 async_worker_context_enabled_, use_distance_field_text, 276 async_worker_context_enabled_, use_distance_field_text,
273 raster_source->CanUseLCDText(), msaa_sample_count_, 277 raster_source->CanUseLCDText(), msaa_sample_count_,
274 raster_source->image_decode_controller(), 278 raster_source->image_decode_controller(),
275 playback_settings.use_image_hijack_canvas); 279 playback_settings.use_image_hijack_canvas);
276 280
277 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 281 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
278 282
279 // Barrier to sync worker context output to cc context. 283 // Barrier to sync worker context output to cc context.
280 gl->OrderingBarrierCHROMIUM(); 284 gl->OrderingBarrierCHROMIUM();
281 285
282 // Generate sync token after the barrier for cross context synchronization. 286 // Generate sync token after the barrier for cross context synchronization.
283 gpu::SyncToken resource_sync_token; 287 gpu::SyncToken resource_sync_token;
284 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); 288 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData());
285 resource_lock->set_sync_token(resource_sync_token); 289 resource_lock->set_sync_token(resource_sync_token);
286 resource_lock->set_synchronized(!async_worker_context_enabled_); 290 resource_lock->set_synchronized(!async_worker_context_enabled_);
287 } 291 }
288 292
289 } // namespace cc 293 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698