Index: cc/raster/one_copy_raster_buffer_provider.cc |
diff --git a/cc/raster/one_copy_raster_buffer_provider.cc b/cc/raster/one_copy_raster_buffer_provider.cc |
index 87f8f026a1eb9fc7f6efeb027e9e3c3f3e9abaa4..3d4d1e45e0a5bce0c88d24872b8f812ddf4a814d 100644 |
--- a/cc/raster/one_copy_raster_buffer_provider.cc |
+++ b/cc/raster/one_copy_raster_buffer_provider.cc |
@@ -26,14 +26,14 @@ namespace { |
class RasterBufferImpl : public RasterBuffer { |
public: |
- RasterBufferImpl(OneCopyRasterBufferProvider* worker_pool, |
+ RasterBufferImpl(OneCopyRasterBufferProvider* client, |
ResourceProvider* resource_provider, |
- ResourceFormat resource_format, |
const Resource* resource, |
- uint64_t previous_content_id) |
- : worker_pool_(worker_pool), |
+ uint64_t previous_content_id, |
+ bool async_worker_context_enabled) |
+ : client_(client), |
resource_(resource), |
- lock_(resource_provider, resource->id()), |
+ lock_(resource_provider, resource->id(), async_worker_context_enabled), |
previous_content_id_(previous_content_id) {} |
~RasterBufferImpl() override {} |
@@ -46,13 +46,13 @@ class RasterBufferImpl : public RasterBuffer { |
uint64_t new_content_id, |
float scale, |
const RasterSource::PlaybackSettings& playback_settings) override { |
- worker_pool_->PlaybackAndCopyOnWorkerThread( |
+ client_->PlaybackAndCopyOnWorkerThread( |
resource_, &lock_, raster_source, raster_full_rect, raster_dirty_rect, |
scale, playback_settings, previous_content_id_, new_content_id); |
} |
private: |
- OneCopyRasterBufferProvider* worker_pool_; |
+ OneCopyRasterBufferProvider* client_; |
const Resource* resource_; |
ResourceProvider::ScopedWriteLockGL lock_; |
uint64_t previous_content_id_; |
@@ -74,7 +74,8 @@ OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( |
int max_copy_texture_chromium_size, |
bool use_partial_raster, |
int max_staging_buffer_usage_in_bytes, |
- ResourceFormat preferred_tile_format) |
+ ResourceFormat preferred_tile_format, |
+ bool async_worker_context_enabled) |
: compositor_context_provider_(compositor_context_provider), |
worker_context_provider_(worker_context_provider), |
resource_provider_(resource_provider), |
@@ -90,8 +91,9 @@ OneCopyRasterBufferProvider::OneCopyRasterBufferProvider( |
worker_context_provider, |
resource_provider, |
use_partial_raster, |
- max_staging_buffer_usage_in_bytes) { |
- DCHECK(compositor_context_provider_); |
+ max_staging_buffer_usage_in_bytes), |
+ async_worker_context_enabled_(async_worker_context_enabled) { |
+ DCHECK(compositor_context_provider); |
DCHECK(worker_context_provider); |
} |
@@ -105,8 +107,8 @@ OneCopyRasterBufferProvider::AcquireBufferForRaster( |
// TODO(danakj): If resource_content_id != 0, we only need to copy/upload |
// the dirty rect. |
return base::WrapUnique<RasterBuffer>( |
- new RasterBufferImpl(this, resource_provider_, resource->format(), |
- resource, previous_content_id)); |
+ new RasterBufferImpl(this, resource_provider_, resource, |
+ previous_content_id, async_worker_context_enabled_)); |
} |
void OneCopyRasterBufferProvider::ReleaseBufferForRaster( |
@@ -116,7 +118,10 @@ void OneCopyRasterBufferProvider::ReleaseBufferForRaster( |
void OneCopyRasterBufferProvider::OrderingBarrier() { |
TRACE_EVENT0("cc", "OneCopyRasterBufferProvider::OrderingBarrier"); |
- compositor_context_provider_->ContextGL()->OrderingBarrierCHROMIUM(); |
+ gpu::gles2::GLES2Interface* gl = compositor_context_provider_->ContextGL(); |
+ GLuint64 fence = gl->InsertFenceSyncCHROMIUM(); |
+ gl->OrderingBarrierCHROMIUM(); |
+ gl->GenUnverifiedSyncTokenCHROMIUM(fence, sync_token_.GetData()); |
} |
ResourceFormat OneCopyRasterBufferProvider::GetResourceFormat( |
@@ -157,8 +162,8 @@ void OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread( |
playback_settings, previous_content_id, |
new_content_id); |
- CopyOnWorkerThread(staging_buffer.get(), resource, resource_lock, |
- raster_source, previous_content_id, new_content_id); |
+ CopyOnWorkerThread(staging_buffer.get(), resource_lock, raster_source, |
+ previous_content_id, new_content_id); |
staging_pool_.ReleaseStagingBuffer(std::move(staging_buffer)); |
} |
@@ -216,7 +221,6 @@ void OneCopyRasterBufferProvider::PlaybackToStagingBuffer( |
void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
StagingBuffer* staging_buffer, |
- const Resource* resource, |
ResourceProvider::ScopedWriteLockGL* resource_lock, |
const RasterSource* raster_source, |
uint64_t previous_content_id, |
@@ -227,8 +231,16 @@ void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
DCHECK(gl); |
+ ResourceProvider::ScopedTextureProvider scoped_texture( |
+ gl, resource_lock, async_worker_context_enabled_); |
+ |
+ // Synchronize with compositor. |
+ DCHECK(sync_token_.HasData()); |
+ gl->WaitSyncTokenCHROMIUM(sync_token_.GetConstData()); |
+ |
+ unsigned resource_texture_id = scoped_texture.texture_id(); |
unsigned image_target = |
- resource_provider_->GetImageTextureTarget(resource->format()); |
+ resource_provider_->GetImageTextureTarget(resource_lock->format()); |
// Create and bind staging texture. |
if (!staging_buffer->texture_id) { |
@@ -248,7 +260,7 @@ void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
staging_buffer->image_id = gl->CreateImageCHROMIUM( |
staging_buffer->gpu_memory_buffer->AsClientBuffer(), |
staging_buffer->size.width(), staging_buffer->size.height(), |
- GLInternalFormat(resource->format())); |
+ GLInternalFormat(resource_lock->format())); |
gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); |
} |
} else { |
@@ -275,26 +287,26 @@ void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
// Since compressed texture's cannot be pre-allocated we might have an |
// unallocated resource in which case we need to perform a full size copy. |
- if (IsResourceFormatCompressed(resource->format())) { |
+ if (IsResourceFormatCompressed(resource_lock->format())) { |
gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id, |
- resource_lock->texture_id()); |
+ resource_texture_id); |
} else { |
int bytes_per_row = ResourceUtil::UncheckedWidthInBytes<int>( |
- resource->size().width(), resource->format()); |
+ resource_lock->size().width(), resource_lock->format()); |
int chunk_size_in_rows = |
std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
// Align chunk size to 4. Required to support compressed texture formats. |
chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); |
int y = 0; |
- int height = resource->size().height(); |
+ int height = resource_lock->size().height(); |
while (y < height) { |
// Copy at most |chunk_size_in_rows|. |
int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
DCHECK_GT(rows_to_copy, 0); |
gl->CopySubTextureCHROMIUM( |
- staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y, |
- resource->size().width(), rows_to_copy, false, false, false); |
+ staging_buffer->texture_id, resource_texture_id, 0, y, 0, y, |
+ resource_lock->size().width(), rows_to_copy, false, false, false); |
y += rows_to_copy; |
// Increment |bytes_scheduled_since_last_flush_| by the amount of memory |
@@ -325,7 +337,7 @@ void OneCopyRasterBufferProvider::CopyOnWorkerThread( |
// Generate sync token after the barrier for cross context synchronization. |
gpu::SyncToken sync_token; |
gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
- resource_lock->UpdateResourceSyncToken(sync_token); |
+ resource_lock->set_sync_token(sync_token); |
} |
} |