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

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

Issue 1308533003: cc: Fix support for RGBA4444 texture format and one-copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 { 370 {
371 base::AutoUnlock unlock(lock_); 371 base::AutoUnlock unlock(lock_);
372 372
373 // Allocate GpuMemoryBuffer if necessary. 373 // Allocate GpuMemoryBuffer if necessary.
374 if (!staging_buffer->gpu_memory_buffer) { 374 if (!staging_buffer->gpu_memory_buffer) {
375 staging_buffer->gpu_memory_buffer = 375 staging_buffer->gpu_memory_buffer =
376 resource_provider_->gpu_memory_buffer_manager() 376 resource_provider_->gpu_memory_buffer_manager()
377 ->AllocateGpuMemoryBuffer( 377 ->AllocateGpuMemoryBuffer(
378 staging_buffer->size, 378 staging_buffer->size,
379 BufferFormat(resource_provider_->best_texture_format()), 379 BufferFormat(
380 resource_provider_->memory_efficient_texture_format()),
380 use_persistent_gpu_memory_buffers_ 381 use_persistent_gpu_memory_buffers_
381 ? gfx::BufferUsage::PERSISTENT_MAP 382 ? gfx::BufferUsage::PERSISTENT_MAP
382 : gfx::BufferUsage::MAP); 383 : gfx::BufferUsage::MAP);
383 DCHECK_EQ(gfx::NumberOfPlanesForBufferFormat( 384 DCHECK_EQ(gfx::NumberOfPlanesForBufferFormat(
384 staging_buffer->gpu_memory_buffer->GetFormat()), 385 staging_buffer->gpu_memory_buffer->GetFormat()),
385 1u); 386 1u);
386 } 387 }
387 388
388 gfx::Rect playback_rect = raster_full_rect; 389 gfx::Rect playback_rect = raster_full_rect;
389 if (use_persistent_gpu_memory_buffers_ && previous_content_id) { 390 if (use_persistent_gpu_memory_buffers_ && previous_content_id) {
390 // Reduce playback rect to dirty region if the content id of the staging 391 // Reduce playback rect to dirty region if the content id of the staging
391 // buffer matches the prevous content id. 392 // buffer matches the prevous content id.
392 if (previous_content_id == staging_buffer->content_id) 393 if (previous_content_id == staging_buffer->content_id)
393 playback_rect.Intersect(raster_dirty_rect); 394 playback_rect.Intersect(raster_dirty_rect);
394 } 395 }
395 396
396 if (staging_buffer->gpu_memory_buffer) { 397 if (staging_buffer->gpu_memory_buffer) {
397 void* data = nullptr; 398 void* data = nullptr;
398 bool rv = staging_buffer->gpu_memory_buffer->Map(&data); 399 bool rv = staging_buffer->gpu_memory_buffer->Map(&data);
399 DCHECK(rv); 400 DCHECK(rv);
400 int stride; 401 int stride;
401 staging_buffer->gpu_memory_buffer->GetStride(&stride); 402 staging_buffer->gpu_memory_buffer->GetStride(&stride);
402 // TileTaskWorkerPool::PlaybackToMemory only supports unsigned strides. 403 // TileTaskWorkerPool::PlaybackToMemory only supports unsigned strides.
403 DCHECK_GE(stride, 0); 404 DCHECK_GE(stride, 0);
404 405
405 DCHECK(!playback_rect.IsEmpty()) 406 DCHECK(!playback_rect.IsEmpty())
406 << "Why are we rastering a tile that's not dirty?"; 407 << "Why are we rastering a tile that's not dirty?";
407 TileTaskWorkerPool::PlaybackToMemory( 408 TileTaskWorkerPool::PlaybackToMemory(
408 data, resource_provider_->best_texture_format(), staging_buffer->size, 409 data, resource_provider_->memory_efficient_texture_format(),
409 static_cast<size_t>(stride), raster_source, raster_full_rect, 410 staging_buffer->size, static_cast<size_t>(stride), raster_source,
410 playback_rect, scale, include_images); 411 raster_full_rect, playback_rect, scale, include_images);
411 staging_buffer->gpu_memory_buffer->Unmap(); 412 staging_buffer->gpu_memory_buffer->Unmap();
412 staging_buffer->content_id = new_content_id; 413 staging_buffer->content_id = new_content_id;
413 } 414 }
414 } 415 }
415 416
416 ContextProvider* context_provider = 417 ContextProvider* context_provider =
417 resource_provider_->output_surface()->worker_context_provider(); 418 resource_provider_->output_surface()->worker_context_provider();
418 DCHECK(context_provider); 419 DCHECK(context_provider);
419 420
420 { 421 {
421 ContextProvider::ScopedContextLock scoped_context(context_provider); 422 ContextProvider::ScopedContextLock scoped_context(context_provider);
422 423
423 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); 424 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
424 DCHECK(gl); 425 DCHECK(gl);
425 426
426 unsigned image_target = resource_provider_->GetImageTextureTarget( 427 unsigned image_target = resource_provider_->GetImageTextureTarget(
427 resource_provider_->best_texture_format()); 428 resource_provider_->memory_efficient_texture_format());
428 429
429 // Create and bind staging texture. 430 // Create and bind staging texture.
430 if (!staging_buffer->texture_id) { 431 if (!staging_buffer->texture_id) {
431 gl->GenTextures(1, &staging_buffer->texture_id); 432 gl->GenTextures(1, &staging_buffer->texture_id);
432 gl->BindTexture(image_target, staging_buffer->texture_id); 433 gl->BindTexture(image_target, staging_buffer->texture_id);
433 gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 434 gl->TexParameteri(image_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
434 gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 435 gl->TexParameteri(image_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
435 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 436 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
436 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 437 gl->TexParameteri(image_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
437 } else { 438 } else {
438 gl->BindTexture(image_target, staging_buffer->texture_id); 439 gl->BindTexture(image_target, staging_buffer->texture_id);
439 } 440 }
440 441
441 // Create and bind image. 442 // Create and bind image.
442 if (!staging_buffer->image_id) { 443 if (!staging_buffer->image_id) {
443 if (staging_buffer->gpu_memory_buffer) { 444 if (staging_buffer->gpu_memory_buffer) {
444 staging_buffer->image_id = gl->CreateImageCHROMIUM( 445 staging_buffer->image_id = gl->CreateImageCHROMIUM(
445 staging_buffer->gpu_memory_buffer->AsClientBuffer(), 446 staging_buffer->gpu_memory_buffer->AsClientBuffer(),
446 staging_buffer->size.width(), staging_buffer->size.height(), 447 staging_buffer->size.width(), staging_buffer->size.height(),
447 GLInternalFormat(resource_provider_->best_texture_format())); 448 GLInternalFormat(
449 resource_provider_->memory_efficient_texture_format()));
448 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); 450 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id);
449 } 451 }
450 } else { 452 } else {
451 gl->ReleaseTexImage2DCHROMIUM(image_target, staging_buffer->image_id); 453 gl->ReleaseTexImage2DCHROMIUM(image_target, staging_buffer->image_id);
452 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id); 454 gl->BindTexImage2DCHROMIUM(image_target, staging_buffer->image_id);
453 } 455 }
454 456
455 // Unbind staging texture. 457 // Unbind staging texture.
456 gl->BindTexture(image_target, 0); 458 gl->BindTexture(image_target, 0);
457 459
458 if (resource_provider_->use_sync_query()) { 460 if (resource_provider_->use_sync_query()) {
459 if (!staging_buffer->query_id) 461 if (!staging_buffer->query_id)
460 gl->GenQueriesEXT(1, &staging_buffer->query_id); 462 gl->GenQueriesEXT(1, &staging_buffer->query_id);
461 463
462 #if defined(OS_CHROMEOS) 464 #if defined(OS_CHROMEOS)
463 // TODO(reveman): This avoids a performance problem on some ChromeOS 465 // TODO(reveman): This avoids a performance problem on some ChromeOS
464 // devices. This needs to be removed to support native GpuMemoryBuffer 466 // devices. This needs to be removed to support native GpuMemoryBuffer
465 // implementations. crbug.com/436314 467 // implementations. crbug.com/436314
466 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id); 468 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, staging_buffer->query_id);
467 #else 469 #else
468 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, 470 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM,
469 staging_buffer->query_id); 471 staging_buffer->query_id);
470 #endif 472 #endif
471 } 473 }
472 474
473 int bytes_per_row = 475 int bytes_per_row =
474 (BitsPerPixel(resource_provider_->best_texture_format()) * 476 (BitsPerPixel(resource_provider_->memory_efficient_texture_format()) *
475 resource->size().width()) / 477 resource->size().width()) /
476 8; 478 8;
477 int chunk_size_in_rows = 479 int chunk_size_in_rows =
478 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); 480 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row);
479 // Align chunk size to 4. Required to support compressed texture formats. 481 // Align chunk size to 4. Required to support compressed texture formats.
480 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4); 482 chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4);
481 int y = 0; 483 int y = 0;
482 int height = resource->size().height(); 484 int height = resource->size().height();
483 while (y < height) { 485 while (y < height) {
484 // Copy at most |chunk_size_in_rows|. 486 // Copy at most |chunk_size_in_rows|.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 520
519 ScheduleReduceMemoryUsage(); 521 ScheduleReduceMemoryUsage();
520 } 522 }
521 523
522 bool OneCopyTileTaskWorkerPool::OnMemoryDump( 524 bool OneCopyTileTaskWorkerPool::OnMemoryDump(
523 const base::trace_event::MemoryDumpArgs& args, 525 const base::trace_event::MemoryDumpArgs& args,
524 base::trace_event::ProcessMemoryDump* pmd) { 526 base::trace_event::ProcessMemoryDump* pmd) {
525 base::AutoLock lock(lock_); 527 base::AutoLock lock(lock_);
526 528
527 for (const auto& buffer : buffers_) { 529 for (const auto& buffer : buffers_) {
528 buffer->OnMemoryDump(pmd, resource_provider_->best_texture_format(), 530 buffer->OnMemoryDump(pmd,
531 resource_provider_->memory_efficient_texture_format(),
529 std::find(free_buffers_.begin(), free_buffers_.end(), 532 std::find(free_buffers_.begin(), free_buffers_.end(),
530 buffer) != free_buffers_.end()); 533 buffer) != free_buffers_.end());
531 } 534 }
532 535
533 return true; 536 return true;
534 } 537 }
535 538
536 scoped_ptr<OneCopyTileTaskWorkerPool::StagingBuffer> 539 scoped_ptr<OneCopyTileTaskWorkerPool::StagingBuffer>
537 OneCopyTileTaskWorkerPool::AcquireStagingBuffer(const Resource* resource, 540 OneCopyTileTaskWorkerPool::AcquireStagingBuffer(const Resource* resource,
538 uint64_t previous_content_id) { 541 uint64_t previous_content_id) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 747
745 staging_state->SetInteger("staging_buffer_count", 748 staging_state->SetInteger("staging_buffer_count",
746 static_cast<int>(buffers_.size())); 749 static_cast<int>(buffers_.size()));
747 staging_state->SetInteger("busy_count", 750 staging_state->SetInteger("busy_count",
748 static_cast<int>(busy_buffers_.size())); 751 static_cast<int>(busy_buffers_.size()));
749 staging_state->SetInteger("free_count", 752 staging_state->SetInteger("free_count",
750 static_cast<int>(free_buffers_.size())); 753 static_cast<int>(free_buffers_.size()));
751 } 754 }
752 755
753 } // namespace cc 756 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698