Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: cc/raster/one_copy_tile_task_worker_pool.cc

Issue 1379783002: Allow one-copy task tile worker pool to use compressed textures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use memory_efficient_format* settings and revert allocation modifications Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_tile_task_worker_pool.h" 5 #include "cc/raster/one_copy_tile_task_worker_pool.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 // static 175 // static
176 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( 176 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create(
177 base::SequencedTaskRunner* task_runner, 177 base::SequencedTaskRunner* task_runner,
178 TaskGraphRunner* task_graph_runner, 178 TaskGraphRunner* task_graph_runner,
179 ContextProvider* context_provider, 179 ContextProvider* context_provider,
180 ResourceProvider* resource_provider, 180 ResourceProvider* resource_provider,
181 int max_copy_texture_chromium_size, 181 int max_copy_texture_chromium_size,
182 bool use_partial_raster, 182 bool use_partial_raster,
183 int max_staging_buffer_usage_in_bytes, 183 int max_staging_buffer_usage_in_bytes,
184 bool use_rgba_4444_texture_format) { 184 ResourceFormat memory_efficient_format,
185 ResourceFormat memory_efficient_format_with_alpha) {
185 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( 186 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool(
186 task_runner, task_graph_runner, resource_provider, 187 task_runner, task_graph_runner, resource_provider,
187 max_copy_texture_chromium_size, use_partial_raster, 188 max_copy_texture_chromium_size, use_partial_raster,
188 max_staging_buffer_usage_in_bytes, use_rgba_4444_texture_format)); 189 max_staging_buffer_usage_in_bytes, memory_efficient_format,
190 memory_efficient_format_with_alpha));
189 } 191 }
190 192
191 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( 193 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool(
192 base::SequencedTaskRunner* task_runner, 194 base::SequencedTaskRunner* task_runner,
193 TaskGraphRunner* task_graph_runner, 195 TaskGraphRunner* task_graph_runner,
194 ResourceProvider* resource_provider, 196 ResourceProvider* resource_provider,
195 int max_copy_texture_chromium_size, 197 int max_copy_texture_chromium_size,
196 bool use_partial_raster, 198 bool use_partial_raster,
197 int max_staging_buffer_usage_in_bytes, 199 int max_staging_buffer_usage_in_bytes,
198 bool use_rgba_4444_texture_format) 200 ResourceFormat memory_efficient_format,
201 ResourceFormat memory_efficient_format_with_alpha)
199 : task_runner_(task_runner), 202 : task_runner_(task_runner),
200 task_graph_runner_(task_graph_runner), 203 task_graph_runner_(task_graph_runner),
201 namespace_token_(task_graph_runner->GetNamespaceToken()), 204 namespace_token_(task_graph_runner->GetNamespaceToken()),
202 resource_provider_(resource_provider), 205 resource_provider_(resource_provider),
203 max_bytes_per_copy_operation_( 206 max_bytes_per_copy_operation_(
204 max_copy_texture_chromium_size 207 max_copy_texture_chromium_size
205 ? std::min(kMaxBytesPerCopyOperation, 208 ? std::min(kMaxBytesPerCopyOperation,
206 max_copy_texture_chromium_size) 209 max_copy_texture_chromium_size)
207 : kMaxBytesPerCopyOperation), 210 : kMaxBytesPerCopyOperation),
208 use_partial_raster_(use_partial_raster), 211 use_partial_raster_(use_partial_raster),
209 bytes_scheduled_since_last_flush_(0), 212 bytes_scheduled_since_last_flush_(0),
210 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes), 213 max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes),
211 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), 214 memory_efficient_format_(memory_efficient_format),
215 memory_efficient_format_with_alpha_(memory_efficient_format_with_alpha),
212 staging_buffer_usage_in_bytes_(0), 216 staging_buffer_usage_in_bytes_(0),
213 free_staging_buffer_usage_in_bytes_(0), 217 free_staging_buffer_usage_in_bytes_(0),
214 staging_buffer_expiration_delay_( 218 staging_buffer_expiration_delay_(
215 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)), 219 base::TimeDelta::FromMilliseconds(kStagingBufferExpirationDelayMs)),
216 reduce_memory_usage_pending_(false), 220 reduce_memory_usage_pending_(false),
217 weak_ptr_factory_(this), 221 weak_ptr_factory_(this),
218 task_set_finished_weak_ptr_factory_(this) { 222 task_set_finished_weak_ptr_factory_(this) {
219 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 223 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
220 this, "OneCopyTileTaskWorkerPool", base::ThreadTaskRunnerHandle::Get()); 224 this, "OneCopyTileTaskWorkerPool", base::ThreadTaskRunnerHandle::Get());
221 reduce_memory_usage_callback_ = 225 reduce_memory_usage_callback_ =
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 TileTask* task = static_cast<TileTask*>(it->get()); 338 TileTask* task = static_cast<TileTask*>(it->get());
335 339
336 task->WillComplete(); 340 task->WillComplete();
337 task->CompleteOnOriginThread(this); 341 task->CompleteOnOriginThread(this);
338 task->DidComplete(); 342 task->DidComplete();
339 } 343 }
340 completed_tasks_.clear(); 344 completed_tasks_.clear();
341 } 345 }
342 346
343 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat( 347 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat(
344 bool must_support_alpha) const { 348 bool must_support_alpha) const {
reveman 2015/11/30 16:41:45 Can we adjust this interface to match RendererSett
christiank 2015/12/01 15:01:07 Sure! That will leave it to TileManager::Determine
345 return use_rgba_4444_texture_format_ 349 if (memory_efficient_format_with_alpha_ != RGBA_8888 && must_support_alpha)
reveman 2015/11/30 16:41:45 I think these RGBA_8888 checks will be confusing f
christiank 2015/12/01 15:01:07 I agree that it's a bit confusing. I don't quite f
reveman 2015/12/01 17:27:24 I think it would be much cleaner and easier to und
christiank 2015/12/02 16:18:14 Now I see what you mean. Sounds good to me, defini
346 ? RGBA_4444 350 return memory_efficient_format_with_alpha_;
347 : resource_provider_->best_texture_format(); 351
352 if (memory_efficient_format_ != RGBA_8888 && !must_support_alpha)
353 return memory_efficient_format_;
354
355 return resource_provider_->best_texture_format();
348 } 356 }
349 357
350 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle( 358 bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle(
351 bool must_support_alpha) const { 359 bool must_support_alpha) const {
352 return !PlatformColor::SameComponentOrder( 360 return !PlatformColor::SameComponentOrder(
353 GetResourceFormat(must_support_alpha)); 361 GetResourceFormat(must_support_alpha));
354 } 362 }
355 363
356 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( 364 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster(
357 const Resource* resource, 365 const Resource* resource,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 // TODO(reveman): This avoids a performance problem on some ChromeOS 489 // TODO(reveman): This avoids a performance problem on some ChromeOS
482 // devices. This needs to be removed to support native GpuMemoryBuffer 490 // devices. This needs to be removed to support native GpuMemoryBuffer
483 // implementations. crbug.com/436314 491 // implementations. crbug.com/436314
484 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); 492 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id);
485 #else 493 #else
486 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, 494 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM,
487 staging_buffer->query_id); 495 staging_buffer->query_id);
488 #endif 496 #endif
489 } 497 }
490 498
491 int bytes_per_row = 499 // Since compressed texture's cannot be pre-allocated we might have an
492 (BitsPerPixel(resource->format()) * resource->size().width()) / 8; 500 // unallocated resource in which case we need to perform a full size copy.
493 int chunk_size_in_rows = 501 if (IsResourceFormatCompressed(resource->format())) {
494 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); 502 gl->CompressedCopyTextureCHROMIUM(GL_TEXTURE_2D,
495 // Align chunk size to 4. Required to support compressed texture formats. 503 staging_buffer->texture_id,
496 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); 504 resource_lock->texture_id());
497 int y = 0; 505 } else {
498 int height = resource->size().height(); 506 int bytes_per_row =
499 while (y < height) { 507 (BitsPerPixel(resource->format()) * resource->size().width()) / 8;
500 // Copy at most |chunk_size_in_rows|. 508 int chunk_size_in_rows =
501 int rows_to_copy = std::min(chunk_size_in_rows, height - y); 509 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row);
502 DCHECK_GT(rows_to_copy, 0); 510 // Align chunk size to 4. Required to support compressed texture formats.
511 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4);
512 int y = 0;
513 int height = resource->size().height();
514 while (y < height) {
515 // Copy at most |chunk_size_in_rows|.
516 int rows_to_copy = std::min(chunk_size_in_rows, height - y);
517 DCHECK_GT(rows_to_copy, 0);
503 518
504 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, staging_buffer->texture_id, 519 if (IsResourceFormatCompressed(resource->format())) {
reveman 2015/11/30 16:41:45 This is never going to be true thanks to the check
christiank 2015/12/01 15:01:07 Oh, that's sloppy of me. You're absolutely right.
505 resource_lock->texture_id(), 0, y, 0, y, 520 gl->CompressedCopySubTextureCHROMIUM(
506 resource->size().width(), rows_to_copy, false, 521 GL_TEXTURE_2D, staging_buffer->texture_id,
507 false, false); 522 resource_lock->texture_id(), 0, y, 0, y, resource->size().width(),
508 y += rows_to_copy; 523 rows_to_copy);
524 } else {
525 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, staging_buffer->texture_id,
526 resource_lock->texture_id(), 0, y, 0, y,
527 resource->size().width(), rows_to_copy,
528 false, false, false);
529 }
530 y += rows_to_copy;
509 531
510 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory 532 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory
511 // used for this copy operation. 533 // used for this copy operation.
512 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; 534 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row;
513 535
514 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { 536 if (bytes_scheduled_since_last_flush_ >=
515 gl->ShallowFlushCHROMIUM(); 537 max_bytes_per_copy_operation_) {
516 bytes_scheduled_since_last_flush_ = 0; 538 gl->ShallowFlushCHROMIUM();
539 bytes_scheduled_since_last_flush_ = 0;
540 }
517 } 541 }
518 } 542 }
519 543
520 if (resource_provider_->use_sync_query()) { 544 if (resource_provider_->use_sync_query()) {
521 #if defined(OS_CHROMEOS) 545 #if defined(OS_CHROMEOS)
522 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); 546 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM);
523 #else 547 #else
524 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); 548 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
525 #endif 549 #endif
526 } 550 }
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 847
824 staging_state->SetInteger("staging_buffer_count", 848 staging_state->SetInteger("staging_buffer_count",
825 static_cast<int>(buffers_.size())); 849 static_cast<int>(buffers_.size()));
826 staging_state->SetInteger("busy_count", 850 staging_state->SetInteger("busy_count",
827 static_cast<int>(busy_buffers_.size())); 851 static_cast<int>(busy_buffers_.size()));
828 staging_state->SetInteger("free_count", 852 staging_state->SetInteger("free_count",
829 static_cast<int>(free_buffers_.size())); 853 static_cast<int>(free_buffers_.size()));
830 } 854 }
831 855
832 } // namespace cc 856 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698