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/one_copy_raster_buffer_provider.h" | 5 #include "cc/raster/one_copy_raster_buffer_provider.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace cc { | 25 namespace cc { |
26 namespace { | 26 namespace { |
27 | 27 |
28 class RasterBufferImpl : public RasterBuffer { | 28 class RasterBufferImpl : public RasterBuffer { |
29 public: | 29 public: |
30 RasterBufferImpl(OneCopyRasterBufferProvider* worker_pool, | 30 RasterBufferImpl(OneCopyRasterBufferProvider* worker_pool, |
31 ResourceProvider* resource_provider, | 31 ResourceProvider* resource_provider, |
32 ResourceFormat resource_format, | 32 ResourceFormat resource_format, |
33 const Resource* resource, | 33 const Resource* resource, |
34 uint64_t previous_content_id) | 34 uint64_t previous_content_id, |
| 35 bool use_mailbox) |
35 : worker_pool_(worker_pool), | 36 : worker_pool_(worker_pool), |
36 resource_(resource), | 37 resource_(resource), |
37 lock_(resource_provider, resource->id()), | 38 lock_(resource_provider, resource->id(), use_mailbox), |
38 previous_content_id_(previous_content_id) {} | 39 previous_content_id_(previous_content_id) {} |
39 | 40 |
40 ~RasterBufferImpl() override {} | 41 ~RasterBufferImpl() override {} |
41 | 42 |
42 // Overridden from RasterBuffer: | 43 // Overridden from RasterBuffer: |
43 void Playback( | 44 void Playback( |
44 const RasterSource* raster_source, | 45 const RasterSource* raster_source, |
45 const gfx::Rect& raster_full_rect, | 46 const gfx::Rect& raster_full_rect, |
46 const gfx::Rect& raster_dirty_rect, | 47 const gfx::Rect& raster_dirty_rect, |
47 uint64_t new_content_id, | 48 uint64_t new_content_id, |
(...skipping 20 matching lines...) Expand all Loading... |
68 } // namespace | 69 } // namespace |
69 | 70 |
70 // static | 71 // static |
71 std::unique_ptr<RasterBufferProvider> OneCopyRasterBufferProvider::Create( | 72 std::unique_ptr<RasterBufferProvider> OneCopyRasterBufferProvider::Create( |
72 base::SequencedTaskRunner* task_runner, | 73 base::SequencedTaskRunner* task_runner, |
73 ContextProvider* context_provider, | 74 ContextProvider* context_provider, |
74 ResourceProvider* resource_provider, | 75 ResourceProvider* resource_provider, |
75 int max_copy_texture_chromium_size, | 76 int max_copy_texture_chromium_size, |
76 bool use_partial_raster, | 77 bool use_partial_raster, |
77 int max_staging_buffer_usage_in_bytes, | 78 int max_staging_buffer_usage_in_bytes, |
78 ResourceFormat preferred_tile_format) { | 79 ResourceFormat preferred_tile_format, |
| 80 bool async_worker_context_enabled) { |
79 return base::WrapUnique<RasterBufferProvider>(new OneCopyRasterBufferProvider( | 81 return base::WrapUnique<RasterBufferProvider>(new OneCopyRasterBufferProvider( |
80 task_runner, resource_provider, max_copy_texture_chromium_size, | 82 task_runner, resource_provider, max_copy_texture_chromium_size, |
81 use_partial_raster, max_staging_buffer_usage_in_bytes, | 83 use_partial_raster, max_staging_buffer_usage_in_bytes, |
82 preferred_tile_format)); | 84 preferred_tile_format, async_worker_context_enabled)); |
83 } | 85 } |
84 | 86 |
85 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( | 87 OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( |
86 base::SequencedTaskRunner* task_runner, | 88 base::SequencedTaskRunner* task_runner, |
87 ResourceProvider* resource_provider, | 89 ResourceProvider* resource_provider, |
88 int max_copy_texture_chromium_size, | 90 int max_copy_texture_chromium_size, |
89 bool use_partial_raster, | 91 bool use_partial_raster, |
90 int max_staging_buffer_usage_in_bytes, | 92 int max_staging_buffer_usage_in_bytes, |
91 ResourceFormat preferred_tile_format) | 93 ResourceFormat preferred_tile_format, |
| 94 bool async_worker_context_enabled) |
92 : resource_provider_(resource_provider), | 95 : resource_provider_(resource_provider), |
93 max_bytes_per_copy_operation_( | 96 max_bytes_per_copy_operation_( |
94 max_copy_texture_chromium_size | 97 max_copy_texture_chromium_size |
95 ? std::min(kMaxBytesPerCopyOperation, | 98 ? std::min(kMaxBytesPerCopyOperation, |
96 max_copy_texture_chromium_size) | 99 max_copy_texture_chromium_size) |
97 : kMaxBytesPerCopyOperation), | 100 : kMaxBytesPerCopyOperation), |
98 use_partial_raster_(use_partial_raster), | 101 use_partial_raster_(use_partial_raster), |
99 bytes_scheduled_since_last_flush_(0), | 102 bytes_scheduled_since_last_flush_(0), |
100 preferred_tile_format_(preferred_tile_format) { | 103 preferred_tile_format_(preferred_tile_format), |
| 104 async_worker_context_enabled_(async_worker_context_enabled) { |
101 staging_pool_ = StagingBufferPool::Create(task_runner, resource_provider, | 105 staging_pool_ = StagingBufferPool::Create(task_runner, resource_provider, |
102 use_partial_raster, | 106 use_partial_raster, |
103 max_staging_buffer_usage_in_bytes); | 107 max_staging_buffer_usage_in_bytes); |
104 } | 108 } |
105 | 109 |
106 OneCopyRasterBufferProvider::~OneCopyRasterBufferProvider() {} | 110 OneCopyRasterBufferProvider::~OneCopyRasterBufferProvider() {} |
107 | 111 |
108 std::unique_ptr<RasterBuffer> | 112 std::unique_ptr<RasterBuffer> |
109 OneCopyRasterBufferProvider::AcquireBufferForRaster( | 113 OneCopyRasterBufferProvider::AcquireBufferForRaster( |
110 const Resource* resource, | 114 const Resource* resource, |
111 uint64_t resource_content_id, | 115 uint64_t resource_content_id, |
112 uint64_t previous_content_id) { | 116 uint64_t previous_content_id) { |
113 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload | 117 // TODO(danakj): If resource_content_id != 0, we only need to copy/upload |
114 // the dirty rect. | 118 // the dirty rect. |
115 return base::WrapUnique<RasterBuffer>( | 119 return base::WrapUnique<RasterBuffer>(new RasterBufferImpl( |
116 new RasterBufferImpl(this, resource_provider_, resource->format(), | 120 this, resource_provider_, resource->format(), resource, |
117 resource, previous_content_id)); | 121 previous_content_id, async_worker_context_enabled_)); |
118 } | 122 } |
119 | 123 |
120 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( | 124 void OneCopyRasterBufferProvider::ReleaseBufferForRaster( |
121 std::unique_ptr<RasterBuffer> buffer) { | 125 std::unique_ptr<RasterBuffer> buffer) { |
122 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 126 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
123 } | 127 } |
124 | 128 |
125 void OneCopyRasterBufferProvider::OrderingBarrier() { | 129 void OneCopyRasterBufferProvider::OrderingBarrier() { |
126 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); | 130 TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); |
127 | 131 |
128 resource_provider_->output_surface() | 132 gpu::gles2::GLES2Interface* gl = |
129 ->context_provider() | 133 resource_provider_->output_surface()->context_provider()->ContextGL(); |
130 ->ContextGL() | 134 |
131 ->OrderingBarrierCHROMIUM(); | 135 GLuint64 fence = gl->InsertFenceSyncCHROMIUM(); |
| 136 gl->OrderingBarrierCHROMIUM(); |
| 137 gl->GenUnverifiedSyncTokenCHROMIUM(fence, sync_token_.GetData()); |
132 } | 138 } |
133 | 139 |
134 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( | 140 ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( |
135 bool must_support_alpha) const { | 141 bool must_support_alpha) const { |
136 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && | 142 if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) && |
137 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || | 143 (DoesResourceFormatSupportAlpha(preferred_tile_format_) || |
138 !must_support_alpha)) { | 144 !must_support_alpha)) { |
139 return preferred_tile_format_; | 145 return preferred_tile_format_; |
140 } | 146 } |
141 | 147 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 ContextProvider* context_provider = | 242 ContextProvider* context_provider = |
237 resource_provider_->output_surface()->worker_context_provider(); | 243 resource_provider_->output_surface()->worker_context_provider(); |
238 DCHECK(context_provider); | 244 DCHECK(context_provider); |
239 | 245 |
240 { | 246 { |
241 ContextProvider::ScopedContextLock scoped_context(context_provider); | 247 ContextProvider::ScopedContextLock scoped_context(context_provider); |
242 | 248 |
243 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | 249 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
244 DCHECK(gl); | 250 DCHECK(gl); |
245 | 251 |
| 252 // Synchronize with compositor. |
| 253 DCHECK(sync_token_.HasData()); |
| 254 gl->WaitSyncTokenCHROMIUM(sync_token_.GetConstData()); |
| 255 |
| 256 unsigned resource_texture_id = resource_lock->ProduceTextureId(); |
246 unsigned image_target = | 257 unsigned image_target = |
247 resource_provider_->GetImageTextureTarget(resource->format()); | 258 resource_provider_->GetImageTextureTarget(resource->format()); |
248 | 259 |
249 // Create and bind staging texture. | 260 // Create and bind staging texture. |
250 if (!staging_buffer->texture_id) { | 261 if (!staging_buffer->texture_id) { |
251 gl->GenTextures(1, &staging_buffer->texture_id); | 262 gl->GenTextures(1, &staging_buffer->texture_id); |
252 gl->BindTexture(image_target, staging_buffer->texture_id); | 263 gl->BindTexture(image_target, staging_buffer->texture_id); |
253 gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 264 gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
254 gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 265 gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
255 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 266 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
(...skipping 30 matching lines...) Expand all Loading... |
286 #else | 297 #else |
287 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 298 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
288 staging_buffer->query_id); | 299 staging_buffer->query_id); |
289 #endif | 300 #endif |
290 } | 301 } |
291 | 302 |
292 // Since compressed texture's cannot be pre-allocated we might have an | 303 // Since compressed texture's cannot be pre-allocated we might have an |
293 // unallocated resource in which case we need to perform a full size copy. | 304 // unallocated resource in which case we need to perform a full size copy. |
294 if (IsResourceFormatCompressed(resource->format())) { | 305 if (IsResourceFormatCompressed(resource->format())) { |
295 gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, | 306 gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, |
296 resource_lock->texture_id()); | 307 resource_texture_id); |
297 } else { | 308 } else { |
298 int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>( | 309 int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>( |
299 resource->size().width(), resource->format()); | 310 resource->size().width(), resource->format()); |
300 int chunk_size_in_rows = | 311 int chunk_size_in_rows = |
301 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); | 312 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
302 // Align chunk size to 4. Required to support compressed texture formats. | 313 // Align chunk size to 4. Required to support compressed texture formats. |
303 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); | 314 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); |
304 int y = 0; | 315 int y = 0; |
305 int height = resource->size().height(); | 316 int height = resource->size().height(); |
306 while (y < height) { | 317 while (y < height) { |
307 // Copy at most |chunk_size_in_rows|. | 318 // Copy at most |chunk_size_in_rows|. |
308 int rows_to_copy = std::min(chunk_size_in_rows, height - y); | 319 int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
309 DCHECK_GT(rows_to_copy, 0); | 320 DCHECK_GT(rows_to_copy, 0); |
310 | 321 |
311 gl->CopySubTextureCHROMIUM( | 322 gl->CopySubTextureCHROMIUM( |
312 staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y, | 323 staging_buffer->texture_id, resource_texture_id, 0, y, 0, y, |
313 resource->size().width(), rows_to_copy, false, false, false); | 324 resource->size().width(), rows_to_copy, false, false, false); |
314 y += rows_to_copy; | 325 y += rows_to_copy; |
315 | 326 |
316 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory | 327 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
317 // used for this copy operation. | 328 // used for this copy operation. |
318 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; | 329 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; |
319 | 330 |
320 if (bytes_scheduled_since_last_flush_ >= | 331 if (bytes_scheduled_since_last_flush_ >= |
321 max_bytes_per_copy_operation_) { | 332 max_bytes_per_copy_operation_) { |
322 gl->ShallowFlushCHROMIUM(); | 333 gl->ShallowFlushCHROMIUM(); |
323 bytes_scheduled_since_last_flush_ = 0; | 334 bytes_scheduled_since_last_flush_ = 0; |
324 } | 335 } |
325 } | 336 } |
326 } | 337 } |
327 | 338 |
328 if (resource_provider_->use_sync_query()) { | 339 if (resource_provider_->use_sync_query()) { |
329 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | 340 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) |
330 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 341 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
331 #else | 342 #else |
332 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 343 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
333 #endif | 344 #endif |
334 } | 345 } |
335 | 346 |
| 347 resource_lock->ReleaseTextureId(); |
| 348 |
336 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 349 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
337 | 350 |
338 // Barrier to sync worker context output to cc context. | 351 // Barrier to sync worker context output to cc context. |
339 gl->OrderingBarrierCHROMIUM(); | 352 gl->OrderingBarrierCHROMIUM(); |
340 | 353 |
341 // Generate sync token after the barrier for cross context synchronization. | 354 // Generate sync token after the barrier for cross context synchronization. |
342 gpu::SyncToken sync_token; | 355 gpu::SyncToken sync_token; |
343 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 356 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
344 resource_lock->UpdateResourceSyncToken(sync_token); | 357 resource_lock->UpdateResourceSyncToken(sync_token); |
345 } | 358 } |
346 } | 359 } |
347 | 360 |
348 } // namespace cc | 361 } // namespace cc |
OLD | NEW |