| Index: cc/raster/one_copy_tile_task_worker_pool.cc
|
| diff --git a/cc/raster/one_copy_tile_task_worker_pool.cc b/cc/raster/one_copy_tile_task_worker_pool.cc
|
| index c5518e3cd88d5a1e348f22dbce8d6c5cfb70d304..6166059d396659b20b72dfa0e66f6f6117929e96 100644
|
| --- a/cc/raster/one_copy_tile_task_worker_pool.cc
|
| +++ b/cc/raster/one_copy_tile_task_worker_pool.cc
|
| @@ -112,15 +112,18 @@ OneCopyTileTaskWorkerPool::StagingBuffer::~StagingBuffer() {
|
| void OneCopyTileTaskWorkerPool::StagingBuffer::DestroyGLResources(
|
| gpu::gles2::GLES2Interface* gl) {
|
| if (query_id) {
|
| - gl->DeleteQueriesEXT(1, &query_id);
|
| + if (gl)
|
| + gl->DeleteQueriesEXT(1, &query_id);
|
| query_id = 0;
|
| }
|
| if (image_id) {
|
| - gl->DestroyImageCHROMIUM(image_id);
|
| + if (gl)
|
| + gl->DestroyImageCHROMIUM(image_id);
|
| image_id = 0;
|
| }
|
| if (texture_id) {
|
| - gl->DeleteTextures(1, &texture_id);
|
| + if (gl)
|
| + gl->DeleteTextures(1, &texture_id);
|
| texture_id = 0;
|
| }
|
| }
|
| @@ -424,97 +427,99 @@ void OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread(
|
| ContextProvider::ScopedContextLock scoped_context(context_provider);
|
|
|
| gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
|
| - DCHECK(gl);
|
| -
|
| - unsigned image_target = resource_provider_->GetImageTextureTarget(
|
| - resource_provider_->memory_efficient_texture_format());
|
| -
|
| - // Create and bind staging texture.
|
| - if (!staging_buffer->texture_id) {
|
| - gl->GenTextures(1, &staging_buffer->texture_id);
|
| - gl->BindTexture(image_target, staging_buffer->texture_id);
|
| - gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
| - gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
| - gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
| - gl->TexParameteri(image_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
| - } else {
|
| - gl->BindTexture(image_target, staging_buffer->texture_id);
|
| - }
|
| + if (gl) {
|
| + unsigned image_target = resource_provider_->GetImageTextureTarget(
|
| + resource_provider_->memory_efficient_texture_format());
|
| +
|
| + // Create and bind staging texture.
|
| + if (!staging_buffer->texture_id) {
|
| + gl->GenTextures(1, &staging_buffer->texture_id);
|
| + gl->BindTexture(image_target, staging_buffer->texture_id);
|
| + gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
| + gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
| + gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
| + gl->TexParameteri(image_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
| + } else {
|
| + gl->BindTexture(image_target, staging_buffer->texture_id);
|
| + }
|
|
|
| - // Create and bind image.
|
| - if (!staging_buffer->image_id) {
|
| - if (staging_buffer->gpu_memory_buffer) {
|
| - staging_buffer->image_id = gl->CreateImageCHROMIUM(
|
| - staging_buffer->gpu_memory_buffer->AsClientBuffer(),
|
| - staging_buffer->size.width(), staging_buffer->size.height(),
|
| - GLInternalFormat(
|
| - resource_provider_->memory_efficient_texture_format()));
|
| + // Create and bind image.
|
| + if (!staging_buffer->image_id) {
|
| + if (staging_buffer->gpu_memory_buffer) {
|
| + staging_buffer->image_id = gl->CreateImageCHROMIUM(
|
| + staging_buffer->gpu_memory_buffer->AsClientBuffer(),
|
| + staging_buffer->size.width(), staging_buffer->size.height(),
|
| + GLInternalFormat(
|
| + resource_provider_->memory_efficient_texture_format()));
|
| + gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id);
|
| + }
|
| + } else {
|
| + gl->ReleaseTexImage2DCHROMIUM(image_target, staging_buffer->image_id);
|
| gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id);
|
| }
|
| - } else {
|
| - gl->ReleaseTexImage2DCHROMIUM(image_target, staging_buffer->image_id);
|
| - gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id);
|
| - }
|
|
|
| - // Unbind staging texture.
|
| - gl->BindTexture(image_target, 0);
|
| + // Unbind staging texture.
|
| + gl->BindTexture(image_target, 0);
|
|
|
| - if (resource_provider_->use_sync_query()) {
|
| - if (!staging_buffer->query_id)
|
| - gl->GenQueriesEXT(1, &staging_buffer->query_id);
|
| + if (resource_provider_->use_sync_query()) {
|
| + if (!staging_buffer->query_id)
|
| + gl->GenQueriesEXT(1, &staging_buffer->query_id);
|
|
|
| #if defined(OS_CHROMEOS)
|
| - // TODO(reveman): This avoids a performance problem on some ChromeOS
|
| - // devices. This needs to be removed to support native GpuMemoryBuffer
|
| - // implementations. crbug.com/436314
|
| - gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id);
|
| + // TODO(reveman): This avoids a performance problem on some ChromeOS
|
| + // devices. This needs to be removed to support native GpuMemoryBuffer
|
| + // implementations. crbug.com/436314
|
| + gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM,
|
| + staging_buffer->query_id);
|
| #else
|
| - gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM,
|
| - staging_buffer->query_id);
|
| + gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM,
|
| + staging_buffer->query_id);
|
| #endif
|
| - }
|
| + }
|
|
|
| - int bytes_per_row =
|
| - (BitsPerPixel(resource_provider_->memory_efficient_texture_format()) *
|
| - resource->size().width()) /
|
| - 8;
|
| - 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();
|
| - 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(GL_TEXTURE_2D, staging_buffer->texture_id,
|
| - resource_lock->texture_id(), 0, y, 0, y,
|
| - resource->size().width(), rows_to_copy, false,
|
| - false, false);
|
| - y += rows_to_copy;
|
| -
|
| - // Increment |bytes_scheduled_since_last_flush_| by the amount of memory
|
| - // used for this copy operation.
|
| - bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row;
|
| -
|
| - if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) {
|
| - gl->ShallowFlushCHROMIUM();
|
| - bytes_scheduled_since_last_flush_ = 0;
|
| + int bytes_per_row =
|
| + (BitsPerPixel(resource_provider_->memory_efficient_texture_format()) *
|
| + resource->size().width()) /
|
| + 8;
|
| + 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();
|
| + 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(GL_TEXTURE_2D, staging_buffer->texture_id,
|
| + resource_lock->texture_id(), 0, y, 0, y,
|
| + resource->size().width(), rows_to_copy,
|
| + false, false, false);
|
| + y += rows_to_copy;
|
| +
|
| + // Increment |bytes_scheduled_since_last_flush_| by the amount of memory
|
| + // used for this copy operation.
|
| + bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row;
|
| +
|
| + if (bytes_scheduled_since_last_flush_ >=
|
| + max_bytes_per_copy_operation_) {
|
| + gl->ShallowFlushCHROMIUM();
|
| + bytes_scheduled_since_last_flush_ = 0;
|
| + }
|
| }
|
| - }
|
|
|
| - if (resource_provider_->use_sync_query()) {
|
| + if (resource_provider_->use_sync_query()) {
|
| #if defined(OS_CHROMEOS)
|
| - gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
|
| + gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
|
| #else
|
| - gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
|
| + gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
|
| #endif
|
| - }
|
| + }
|
|
|
| - // Barrier to sync worker context output to cc context.
|
| - gl->OrderingBarrierCHROMIUM();
|
| + // Barrier to sync worker context output to cc context.
|
| + gl->OrderingBarrierCHROMIUM();
|
| + }
|
| }
|
|
|
| staging_buffer->last_usage = base::TimeTicks::Now();
|
| @@ -598,37 +603,37 @@ OneCopyTileTaskWorkerPool::AcquireStagingBuffer(const Resource* resource,
|
| ContextProvider::ScopedContextLock scoped_context(context_provider);
|
|
|
| gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
|
| - DCHECK(gl);
|
| -
|
| - // Check if any busy buffers have become available.
|
| - if (resource_provider_->use_sync_query()) {
|
| - while (!busy_buffers_.empty()) {
|
| - if (!CheckForQueryResult(gl, busy_buffers_.front()->query_id))
|
| - break;
|
| + if (gl) {
|
| + // Check if any busy buffers have become available.
|
| + if (resource_provider_->use_sync_query()) {
|
| + while (!busy_buffers_.empty()) {
|
| + if (!CheckForQueryResult(gl, busy_buffers_.front()->query_id))
|
| + break;
|
|
|
| - MarkStagingBufferAsFree(busy_buffers_.front());
|
| - free_buffers_.push_back(busy_buffers_.take_front());
|
| + MarkStagingBufferAsFree(busy_buffers_.front());
|
| + free_buffers_.push_back(busy_buffers_.take_front());
|
| + }
|
| }
|
| - }
|
|
|
| - // Wait for memory usage of non-free buffers to become less than the limit.
|
| - while (
|
| - (staging_buffer_usage_in_bytes_ - free_staging_buffer_usage_in_bytes_) >=
|
| - max_staging_buffer_usage_in_bytes_) {
|
| - // Stop when there are no more busy buffers to wait for.
|
| - if (busy_buffers_.empty())
|
| - break;
|
| + // Wait for memory usage of non-free buffers to become less than the limit.
|
| + while ((staging_buffer_usage_in_bytes_ -
|
| + free_staging_buffer_usage_in_bytes_) >=
|
| + max_staging_buffer_usage_in_bytes_) {
|
| + // Stop when there are no more busy buffers to wait for.
|
| + if (busy_buffers_.empty())
|
| + break;
|
|
|
| - if (resource_provider_->use_sync_query()) {
|
| - WaitForQueryResult(gl, busy_buffers_.front()->query_id);
|
| - MarkStagingBufferAsFree(busy_buffers_.front());
|
| - free_buffers_.push_back(busy_buffers_.take_front());
|
| - } else {
|
| - // Fall-back to glFinish if CHROMIUM_sync_query is not available.
|
| - gl->Finish();
|
| - while (!busy_buffers_.empty()) {
|
| + if (resource_provider_->use_sync_query()) {
|
| + WaitForQueryResult(gl, busy_buffers_.front()->query_id);
|
| MarkStagingBufferAsFree(busy_buffers_.front());
|
| free_buffers_.push_back(busy_buffers_.take_front());
|
| + } else {
|
| + // Fall-back to glFinish if CHROMIUM_sync_query is not available.
|
| + gl->Finish();
|
| + while (!busy_buffers_.empty()) {
|
| + MarkStagingBufferAsFree(busy_buffers_.front());
|
| + free_buffers_.push_back(busy_buffers_.take_front());
|
| + }
|
| }
|
| }
|
| }
|
| @@ -745,7 +750,6 @@ void OneCopyTileTaskWorkerPool::ReleaseBuffersNotUsedSince(
|
| ContextProvider::ScopedContextLock scoped_context(context_provider);
|
|
|
| gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
|
| - DCHECK(gl);
|
|
|
| // Note: Front buffer is guaranteed to be LRU so we can stop releasing
|
| // buffers as soon as we find a buffer that has been used since |time|.
|
|
|