OLD | NEW |
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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace cc { | 28 namespace cc { |
29 namespace { | 29 namespace { |
30 | 30 |
31 static void RasterizeSource( | 31 static void RasterizeSource( |
32 const RasterSource* raster_source, | 32 const RasterSource* raster_source, |
33 bool resource_has_previous_content, | 33 bool resource_has_previous_content, |
34 const gfx::Size& resource_size, | 34 const gfx::Size& resource_size, |
35 const gfx::Rect& raster_full_rect, | 35 const gfx::Rect& raster_full_rect, |
36 const gfx::Rect& raster_dirty_rect, | 36 const gfx::Rect& raster_dirty_rect, |
37 float scale, | 37 const ScaleTranslate2d& transform, |
38 const RasterSource::PlaybackSettings& playback_settings, | 38 const RasterSource::PlaybackSettings& playback_settings, |
39 ContextProvider* context_provider, | 39 ContextProvider* context_provider, |
40 ResourceProvider::ScopedWriteLockGL* resource_lock, | 40 ResourceProvider::ScopedWriteLockGL* resource_lock, |
41 bool async_worker_context_enabled, | 41 bool async_worker_context_enabled, |
42 bool use_distance_field_text, | 42 bool use_distance_field_text, |
43 int msaa_sample_count) { | 43 int msaa_sample_count) { |
44 ScopedGpuRaster gpu_raster(context_provider); | 44 ScopedGpuRaster gpu_raster(context_provider); |
45 | 45 |
46 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( | 46 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( |
47 context_provider, resource_lock, async_worker_context_enabled, | 47 context_provider, resource_lock, async_worker_context_enabled, |
(...skipping 24 matching lines...) Expand all Loading... |
72 static_cast<float>(playback_rect.size().GetArea()) / full_rect_size; | 72 static_cast<float>(playback_rect.size().GetArea()) / full_rect_size; |
73 float fraction_saved = 1.0f - fraction_partial_rastered; | 73 float fraction_saved = 1.0f - fraction_partial_rastered; |
74 UMA_HISTOGRAM_PERCENTAGE( | 74 UMA_HISTOGRAM_PERCENTAGE( |
75 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", | 75 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", |
76 client_name), | 76 client_name), |
77 100.0f * fraction_saved); | 77 100.0f * fraction_saved); |
78 } | 78 } |
79 | 79 |
80 raster_source->PlaybackToCanvas( | 80 raster_source->PlaybackToCanvas( |
81 sk_surface->getCanvas(), resource_lock->color_space_for_raster(), | 81 sk_surface->getCanvas(), resource_lock->color_space_for_raster(), |
82 raster_full_rect, playback_rect, scale, playback_settings); | 82 raster_full_rect, playback_rect, transform, playback_settings); |
83 } | 83 } |
84 | 84 |
85 } // namespace | 85 } // namespace |
86 | 86 |
87 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( | 87 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( |
88 GpuRasterBufferProvider* client, | 88 GpuRasterBufferProvider* client, |
89 ResourceProvider* resource_provider, | 89 ResourceProvider* resource_provider, |
90 ResourceId resource_id, | 90 ResourceId resource_id, |
91 bool async_worker_context_enabled, | 91 bool async_worker_context_enabled, |
92 bool resource_has_previous_content) | 92 bool resource_has_previous_content) |
93 : client_(client), | 93 : client_(client), |
94 lock_(resource_provider, resource_id, async_worker_context_enabled), | 94 lock_(resource_provider, resource_id, async_worker_context_enabled), |
95 resource_has_previous_content_(resource_has_previous_content) { | 95 resource_has_previous_content_(resource_has_previous_content) { |
96 client_->pending_raster_buffers_.insert(this); | 96 client_->pending_raster_buffers_.insert(this); |
97 } | 97 } |
98 | 98 |
99 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { | 99 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { |
100 client_->pending_raster_buffers_.erase(this); | 100 client_->pending_raster_buffers_.erase(this); |
101 } | 101 } |
102 | 102 |
103 void GpuRasterBufferProvider::RasterBufferImpl::Playback( | 103 void GpuRasterBufferProvider::RasterBufferImpl::Playback( |
104 const RasterSource* raster_source, | 104 const RasterSource* raster_source, |
105 const gfx::Rect& raster_full_rect, | 105 const gfx::Rect& raster_full_rect, |
106 const gfx::Rect& raster_dirty_rect, | 106 const gfx::Rect& raster_dirty_rect, |
107 uint64_t new_content_id, | 107 uint64_t new_content_id, |
108 float scale, | 108 const ScaleTranslate2d& transform, |
109 const RasterSource::PlaybackSettings& playback_settings) { | 109 const RasterSource::PlaybackSettings& playback_settings) { |
110 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); | 110 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); |
111 client_->PlaybackOnWorkerThread(&lock_, sync_token_, | 111 client_->PlaybackOnWorkerThread(&lock_, sync_token_, |
112 resource_has_previous_content_, raster_source, | 112 resource_has_previous_content_, raster_source, |
113 raster_full_rect, raster_dirty_rect, | 113 raster_full_rect, raster_dirty_rect, |
114 new_content_id, scale, playback_settings); | 114 new_content_id, transform, playback_settings); |
115 } | 115 } |
116 | 116 |
117 GpuRasterBufferProvider::GpuRasterBufferProvider( | 117 GpuRasterBufferProvider::GpuRasterBufferProvider( |
118 ContextProvider* compositor_context_provider, | 118 ContextProvider* compositor_context_provider, |
119 ContextProvider* worker_context_provider, | 119 ContextProvider* worker_context_provider, |
120 ResourceProvider* resource_provider, | 120 ResourceProvider* resource_provider, |
121 bool use_distance_field_text, | 121 bool use_distance_field_text, |
122 int gpu_rasterization_msaa_sample_count, | 122 int gpu_rasterization_msaa_sample_count, |
123 ResourceFormat preferred_tile_format, | 123 ResourceFormat preferred_tile_format, |
124 bool async_worker_context_enabled) | 124 bool async_worker_context_enabled) |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 245 } |
246 | 246 |
247 void GpuRasterBufferProvider::PlaybackOnWorkerThread( | 247 void GpuRasterBufferProvider::PlaybackOnWorkerThread( |
248 ResourceProvider::ScopedWriteLockGL* resource_lock, | 248 ResourceProvider::ScopedWriteLockGL* resource_lock, |
249 const gpu::SyncToken& sync_token, | 249 const gpu::SyncToken& sync_token, |
250 bool resource_has_previous_content, | 250 bool resource_has_previous_content, |
251 const RasterSource* raster_source, | 251 const RasterSource* raster_source, |
252 const gfx::Rect& raster_full_rect, | 252 const gfx::Rect& raster_full_rect, |
253 const gfx::Rect& raster_dirty_rect, | 253 const gfx::Rect& raster_dirty_rect, |
254 uint64_t new_content_id, | 254 uint64_t new_content_id, |
255 float scale, | 255 const ScaleTranslate2d& transform, |
256 const RasterSource::PlaybackSettings& playback_settings) { | 256 const RasterSource::PlaybackSettings& playback_settings) { |
257 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); | 257 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
258 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 258 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
259 DCHECK(gl); | 259 DCHECK(gl); |
260 | 260 |
261 if (async_worker_context_enabled_) { | 261 if (async_worker_context_enabled_) { |
262 // Early out if sync token is invalid. This happens if the compositor | 262 // Early out if sync token is invalid. This happens if the compositor |
263 // context was lost before ScheduleTasks was called. | 263 // context was lost before ScheduleTasks was called. |
264 if (!sync_token.HasData()) | 264 if (!sync_token.HasData()) |
265 return; | 265 return; |
266 // Synchronize with compositor. | 266 // Synchronize with compositor. |
267 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 267 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
268 } | 268 } |
269 | 269 |
270 RasterizeSource(raster_source, resource_has_previous_content, | 270 RasterizeSource(raster_source, resource_has_previous_content, |
271 resource_lock->size(), raster_full_rect, raster_dirty_rect, | 271 resource_lock->size(), raster_full_rect, raster_dirty_rect, |
272 scale, playback_settings, worker_context_provider_, | 272 transform, playback_settings, worker_context_provider_, |
273 resource_lock, async_worker_context_enabled_, | 273 resource_lock, async_worker_context_enabled_, |
274 use_distance_field_text_, msaa_sample_count_); | 274 use_distance_field_text_, msaa_sample_count_); |
275 | 275 |
276 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 276 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
277 | 277 |
278 // Barrier to sync worker context output to cc context. | 278 // Barrier to sync worker context output to cc context. |
279 gl->OrderingBarrierCHROMIUM(); | 279 gl->OrderingBarrierCHROMIUM(); |
280 | 280 |
281 // Generate sync token after the barrier for cross context synchronization. | 281 // Generate sync token after the barrier for cross context synchronization. |
282 gpu::SyncToken resource_sync_token; | 282 gpu::SyncToken resource_sync_token; |
283 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); | 283 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); |
284 resource_lock->set_sync_token(resource_sync_token); | 284 resource_lock->set_sync_token(resource_sync_token); |
285 resource_lock->set_synchronized(!async_worker_context_enabled_); | 285 resource_lock->set_synchronized(!async_worker_context_enabled_); |
286 } | 286 } |
287 | 287 |
288 } // namespace cc | 288 } // namespace cc |
OLD | NEW |