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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 namespace cc { | 26 namespace cc { |
27 namespace { | 27 namespace { |
28 | 28 |
29 static void RasterizeSource( | 29 static void RasterizeSource( |
30 const RasterSource* raster_source, | 30 const RasterSource* raster_source, |
31 bool resource_has_previous_content, | 31 bool resource_has_previous_content, |
32 const gfx::Size& resource_size, | 32 const gfx::Size& resource_size, |
33 const gfx::Rect& raster_full_rect, | 33 const gfx::Rect& raster_full_rect, |
34 const gfx::Rect& raster_dirty_rect, | 34 const gfx::Rect& raster_dirty_rect, |
35 const gfx::SizeF& scales, | 35 float scale, |
36 const RasterSource::PlaybackSettings& playback_settings, | 36 const RasterSource::PlaybackSettings& playback_settings, |
37 ContextProvider* context_provider, | 37 ContextProvider* context_provider, |
38 ResourceProvider::ScopedWriteLockGL* resource_lock, | 38 ResourceProvider::ScopedWriteLockGL* resource_lock, |
39 bool async_worker_context_enabled, | 39 bool async_worker_context_enabled, |
40 bool use_distance_field_text, | 40 bool use_distance_field_text, |
41 int msaa_sample_count) { | 41 int msaa_sample_count) { |
42 ScopedGpuRaster gpu_raster(context_provider); | 42 ScopedGpuRaster gpu_raster(context_provider); |
43 | 43 |
44 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( | 44 ResourceProvider::ScopedSkSurfaceProvider scoped_surface( |
45 context_provider, resource_lock, async_worker_context_enabled, | 45 context_provider, resource_lock, async_worker_context_enabled, |
(...skipping 21 matching lines...) Expand all Loading... |
67 float fraction_partial_rastered = | 67 float fraction_partial_rastered = |
68 static_cast<float>(playback_rect.size().GetArea()) / full_rect_size; | 68 static_cast<float>(playback_rect.size().GetArea()) / full_rect_size; |
69 float fraction_saved = 1.0f - fraction_partial_rastered; | 69 float fraction_saved = 1.0f - fraction_partial_rastered; |
70 UMA_HISTOGRAM_PERCENTAGE( | 70 UMA_HISTOGRAM_PERCENTAGE( |
71 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", | 71 base::StringPrintf("Renderer4.%s.PartialRasterPercentageSaved.Gpu", |
72 client_name), | 72 client_name), |
73 100.0f * fraction_saved); | 73 100.0f * fraction_saved); |
74 } | 74 } |
75 | 75 |
76 raster_source->PlaybackToCanvas(sk_surface->getCanvas(), raster_full_rect, | 76 raster_source->PlaybackToCanvas(sk_surface->getCanvas(), raster_full_rect, |
77 playback_rect, scales, playback_settings); | 77 playback_rect, scale, playback_settings); |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( | 82 GpuRasterBufferProvider::RasterBufferImpl::RasterBufferImpl( |
83 GpuRasterBufferProvider* client, | 83 GpuRasterBufferProvider* client, |
84 ResourceProvider* resource_provider, | 84 ResourceProvider* resource_provider, |
85 ResourceId resource_id, | 85 ResourceId resource_id, |
86 bool async_worker_context_enabled, | 86 bool async_worker_context_enabled, |
87 bool resource_has_previous_content) | 87 bool resource_has_previous_content) |
88 : client_(client), | 88 : client_(client), |
89 lock_(resource_provider, resource_id, async_worker_context_enabled), | 89 lock_(resource_provider, resource_id, async_worker_context_enabled), |
90 resource_has_previous_content_(resource_has_previous_content) { | 90 resource_has_previous_content_(resource_has_previous_content) { |
91 client_->pending_raster_buffers_.insert(this); | 91 client_->pending_raster_buffers_.insert(this); |
92 } | 92 } |
93 | 93 |
94 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { | 94 GpuRasterBufferProvider::RasterBufferImpl::~RasterBufferImpl() { |
95 client_->pending_raster_buffers_.erase(this); | 95 client_->pending_raster_buffers_.erase(this); |
96 } | 96 } |
97 | 97 |
98 void GpuRasterBufferProvider::RasterBufferImpl::Playback( | 98 void GpuRasterBufferProvider::RasterBufferImpl::Playback( |
99 const RasterSource* raster_source, | 99 const RasterSource* raster_source, |
100 const gfx::Rect& raster_full_rect, | 100 const gfx::Rect& raster_full_rect, |
101 const gfx::Rect& raster_dirty_rect, | 101 const gfx::Rect& raster_dirty_rect, |
102 uint64_t new_content_id, | 102 uint64_t new_content_id, |
103 const gfx::SizeF& scales, | 103 float scale, |
104 const RasterSource::PlaybackSettings& playback_settings) { | 104 const RasterSource::PlaybackSettings& playback_settings) { |
105 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); | 105 TRACE_EVENT0("cc", "GpuRasterBuffer::Playback"); |
106 client_->PlaybackOnWorkerThread(&lock_, sync_token_, | 106 client_->PlaybackOnWorkerThread(&lock_, sync_token_, |
107 resource_has_previous_content_, raster_source, | 107 resource_has_previous_content_, raster_source, |
108 raster_full_rect, raster_dirty_rect, | 108 raster_full_rect, raster_dirty_rect, |
109 new_content_id, scales, playback_settings); | 109 new_content_id, scale, playback_settings); |
110 } | 110 } |
111 | 111 |
112 GpuRasterBufferProvider::GpuRasterBufferProvider( | 112 GpuRasterBufferProvider::GpuRasterBufferProvider( |
113 ContextProvider* compositor_context_provider, | 113 ContextProvider* compositor_context_provider, |
114 ContextProvider* worker_context_provider, | 114 ContextProvider* worker_context_provider, |
115 ResourceProvider* resource_provider, | 115 ResourceProvider* resource_provider, |
116 bool use_distance_field_text, | 116 bool use_distance_field_text, |
117 int gpu_rasterization_msaa_sample_count, | 117 int gpu_rasterization_msaa_sample_count, |
118 bool async_worker_context_enabled) | 118 bool async_worker_context_enabled) |
119 : compositor_context_provider_(compositor_context_provider), | 119 : compositor_context_provider_(compositor_context_provider), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 void GpuRasterBufferProvider::PlaybackOnWorkerThread( | 193 void GpuRasterBufferProvider::PlaybackOnWorkerThread( |
194 ResourceProvider::ScopedWriteLockGL* resource_lock, | 194 ResourceProvider::ScopedWriteLockGL* resource_lock, |
195 const gpu::SyncToken& sync_token, | 195 const gpu::SyncToken& sync_token, |
196 bool resource_has_previous_content, | 196 bool resource_has_previous_content, |
197 const RasterSource* raster_source, | 197 const RasterSource* raster_source, |
198 const gfx::Rect& raster_full_rect, | 198 const gfx::Rect& raster_full_rect, |
199 const gfx::Rect& raster_dirty_rect, | 199 const gfx::Rect& raster_dirty_rect, |
200 uint64_t new_content_id, | 200 uint64_t new_content_id, |
201 const gfx::SizeF& scales, | 201 float scale, |
202 const RasterSource::PlaybackSettings& playback_settings) { | 202 const RasterSource::PlaybackSettings& playback_settings) { |
203 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); | 203 ContextProvider::ScopedContextLock scoped_context(worker_context_provider_); |
204 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 204 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
205 DCHECK(gl); | 205 DCHECK(gl); |
206 | 206 |
207 if (async_worker_context_enabled_) { | 207 if (async_worker_context_enabled_) { |
208 // Early out if sync token is invalid. This happens if the compositor | 208 // Early out if sync token is invalid. This happens if the compositor |
209 // context was lost before ScheduleTasks was called. | 209 // context was lost before ScheduleTasks was called. |
210 if (!sync_token.HasData()) | 210 if (!sync_token.HasData()) |
211 return; | 211 return; |
212 // Synchronize with compositor. | 212 // Synchronize with compositor. |
213 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 213 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
214 } | 214 } |
215 | 215 |
216 RasterizeSource(raster_source, resource_has_previous_content, | 216 RasterizeSource(raster_source, resource_has_previous_content, |
217 resource_lock->size(), raster_full_rect, raster_dirty_rect, | 217 resource_lock->size(), raster_full_rect, raster_dirty_rect, |
218 scales, playback_settings, worker_context_provider_, | 218 scale, playback_settings, worker_context_provider_, |
219 resource_lock, async_worker_context_enabled_, | 219 resource_lock, async_worker_context_enabled_, |
220 use_distance_field_text_, msaa_sample_count_); | 220 use_distance_field_text_, msaa_sample_count_); |
221 | 221 |
222 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 222 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
223 | 223 |
224 // Barrier to sync worker context output to cc context. | 224 // Barrier to sync worker context output to cc context. |
225 gl->OrderingBarrierCHROMIUM(); | 225 gl->OrderingBarrierCHROMIUM(); |
226 | 226 |
227 // Generate sync token after the barrier for cross context synchronization. | 227 // Generate sync token after the barrier for cross context synchronization. |
228 gpu::SyncToken resource_sync_token; | 228 gpu::SyncToken resource_sync_token; |
229 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); | 229 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, resource_sync_token.GetData()); |
230 resource_lock->set_sync_token(resource_sync_token); | 230 resource_lock->set_sync_token(resource_sync_token); |
231 resource_lock->set_synchronized(!async_worker_context_enabled_); | 231 resource_lock->set_synchronized(!async_worker_context_enabled_); |
232 } | 232 } |
233 | 233 |
234 } // namespace cc | 234 } // namespace cc |
OLD | NEW |