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

Side by Side Diff: cc/resources/resource_provider.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: Address nits 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/atomic_sequence_num.h" 10 #include "base/atomic_sequence_num.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 itr != resources_.end(); ++itr) { 361 itr != resources_.end(); ++itr) {
362 DCHECK(!IsGpuResourceType(itr->second.type)); 362 DCHECK(!IsGpuResourceType(itr->second.type));
363 } 363 }
364 #endif // DCHECK_IS_ON() 364 #endif // DCHECK_IS_ON()
365 365
366 texture_id_allocator_ = nullptr; 366 texture_id_allocator_ = nullptr;
367 buffer_id_allocator_ = nullptr; 367 buffer_id_allocator_ = nullptr;
368 gl->Finish(); 368 gl->Finish();
369 } 369 }
370 370
371 bool ResourceProvider::IsResourceFormatSupported(ResourceFormat format) const {
372 const ContextProvider::Capabilities& caps =
373 output_surface_->context_provider()->ContextCapabilities();
374
375 switch (format) {
376 case ALPHA_8:
377 case RGBA_4444:
378 case RGBA_8888:
379 case RGB_565:
380 case LUMINANCE_8:
381 return true;
382 case BGRA_8888:
383 return caps.gpu.texture_format_bgra8888;
384 case ETC1:
385 return caps.gpu.texture_format_etc1;
386 case RED_8:
387 return caps.gpu.texture_rg;
388 }
389
390 NOTREACHED();
391 return false;
392 }
393
371 bool ResourceProvider::InUseByConsumer(ResourceId id) { 394 bool ResourceProvider::InUseByConsumer(ResourceId id) {
372 Resource* resource = GetResource(id); 395 Resource* resource = GetResource(id);
373 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || 396 return resource->lock_for_read_count > 0 || resource->exported_count > 0 ||
374 resource->lost; 397 resource->lost;
375 } 398 }
376 399
377 bool ResourceProvider::IsLost(ResourceId id) { 400 bool ResourceProvider::IsLost(ResourceId id) {
378 Resource* resource = GetResource(id); 401 Resource* resource = GetResource(id);
379 return resource->lost; 402 return resource->lost;
380 } 403 }
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 } 844 }
822 845
823 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() { 846 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() {
824 } 847 }
825 848
826 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( 849 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(
827 ResourceProvider* resource_provider, 850 ResourceProvider* resource_provider,
828 ResourceId resource_id) 851 ResourceId resource_id)
829 : resource_provider_(resource_provider), 852 : resource_provider_(resource_provider),
830 resource_(resource_provider->LockForWrite(resource_id)) { 853 resource_(resource_provider->LockForWrite(resource_id)) {
831 resource_provider_->LazyAllocate(resource_); 854 resource_provider_->LazyAllocate(resource_);
piman 2015/12/03 23:01:50 What happens now if this is ETC1? Or are we guara
christiank 2015/12/04 10:20:40 It should be fine. As far as I understand we still
piman 2015/12/04 21:30:48 So, if I understand correctly, you expect the call
christiank 2015/12/07 08:38:11 Oh, now I see what you mean. I experimented with u
832 texture_id_ = resource_->gl_id; 855 texture_id_ = resource_->gl_id;
833 DCHECK(texture_id_); 856 DCHECK(texture_id_);
834 if (resource_->dirty_image) 857 if (resource_->dirty_image)
835 resource_provider_->BindImageForSampling(resource_); 858 resource_provider_->BindImageForSampling(resource_);
836 } 859 }
837 860
838 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { 861 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
839 resource_provider_->UnlockForWrite(resource_); 862 resource_provider_->UnlockForWrite(resource_);
840 } 863 }
841 864
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 } 937 }
915 return gpu_memory_buffer_.get(); 938 return gpu_memory_buffer_.get();
916 } 939 }
917 940
918 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( 941 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr(
919 ResourceProvider* resource_provider, 942 ResourceProvider* resource_provider,
920 ResourceId resource_id) 943 ResourceId resource_id)
921 : resource_provider_(resource_provider), 944 : resource_provider_(resource_provider),
922 resource_(resource_provider->LockForWrite(resource_id)) { 945 resource_(resource_provider->LockForWrite(resource_id)) {
923 DCHECK(thread_checker_.CalledOnValidThread()); 946 DCHECK(thread_checker_.CalledOnValidThread());
924 resource_provider_->LazyAllocate(resource_); 947 resource_provider_->LazyAllocate(resource_);
piman 2015/12/03 23:01:50 Same here
925 } 948 }
926 949
927 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { 950 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() {
928 DCHECK(thread_checker_.CalledOnValidThread()); 951 DCHECK(thread_checker_.CalledOnValidThread());
929 DCHECK(resource_->locked_for_write); 952 DCHECK(resource_->locked_for_write);
930 resource_provider_->UnlockForWrite(resource_); 953 resource_provider_->UnlockForWrite(resource_);
931 } 954 }
932 955
933 void ResourceProvider::ScopedWriteLockGr::InitSkSurface( 956 void ResourceProvider::ScopedWriteLockGr::InitSkSurface(
934 bool use_distance_field_text, 957 bool use_distance_field_text,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 use_texture_storage_ext_ = caps.gpu.texture_storage; 1083 use_texture_storage_ext_ = caps.gpu.texture_storage;
1061 use_texture_format_bgra_ = caps.gpu.texture_format_bgra8888; 1084 use_texture_format_bgra_ = caps.gpu.texture_format_bgra8888;
1062 use_texture_usage_hint_ = caps.gpu.texture_usage; 1085 use_texture_usage_hint_ = caps.gpu.texture_usage;
1063 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1; 1086 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1;
1064 yuv_resource_format_ = caps.gpu.texture_rg ? RED_8 : LUMINANCE_8; 1087 yuv_resource_format_ = caps.gpu.texture_rg ? RED_8 : LUMINANCE_8;
1065 use_sync_query_ = caps.gpu.sync_query; 1088 use_sync_query_ = caps.gpu.sync_query;
1066 1089
1067 max_texture_size_ = 0; // Context expects cleared value. 1090 max_texture_size_ = 0; // Context expects cleared value.
1068 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); 1091 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_);
1069 best_texture_format_ = 1092 best_texture_format_ =
1070 PlatformColor::BestTextureFormat(use_texture_format_bgra_); 1093 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_);
1071 1094
1072 best_render_buffer_format_ = 1095 best_render_buffer_format_ = PlatformColor::BestSupportedTextureFormat(
1073 PlatformColor::BestTextureFormat(caps.gpu.render_buffer_format_bgra8888); 1096 caps.gpu.render_buffer_format_bgra8888);
1074 1097
1075 texture_id_allocator_.reset( 1098 texture_id_allocator_.reset(
1076 new TextureIdAllocator(gl, id_allocation_chunk_size_)); 1099 new TextureIdAllocator(gl, id_allocation_chunk_size_));
1077 buffer_id_allocator_.reset( 1100 buffer_id_allocator_.reset(
1078 new BufferIdAllocator(gl, id_allocation_chunk_size_)); 1101 new BufferIdAllocator(gl, id_allocation_chunk_size_));
1079 } 1102 }
1080 1103
1081 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { 1104 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) {
1082 DCHECK(thread_checker_.CalledOnValidThread()); 1105 DCHECK(thread_checker_.CalledOnValidThread());
1083 1106
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 LazyAllocate(GetResource(id)); 1519 LazyAllocate(GetResource(id));
1497 } 1520 }
1498 1521
1499 void ResourceProvider::LazyAllocate(Resource* resource) { 1522 void ResourceProvider::LazyAllocate(Resource* resource) {
1500 DCHECK(resource); 1523 DCHECK(resource);
1501 if (resource->allocated) 1524 if (resource->allocated)
1502 return; 1525 return;
1503 LazyCreate(resource); 1526 LazyCreate(resource);
1504 if (!resource->gl_id) 1527 if (!resource->gl_id)
1505 return; 1528 return;
1506 resource->allocated = true;
1507 GLES2Interface* gl = ContextGL(); 1529 GLES2Interface* gl = ContextGL();
1508 gfx::Size& size = resource->size; 1530 gfx::Size& size = resource->size;
1509 ResourceFormat format = resource->format; 1531 ResourceFormat format = resource->format;
1510 gl->BindTexture(resource->target, resource->gl_id); 1532 gl->BindTexture(resource->target, resource->gl_id);
1511 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { 1533 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) {
1512 resource->gpu_memory_buffer = 1534 resource->gpu_memory_buffer =
1513 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( 1535 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer(
1514 size, BufferFormat(format), 1536 size, BufferFormat(format),
1515 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE) 1537 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE)
1516 .release(); 1538 .release();
piman 2015/12/03 23:01:50 Doesn't resource->allocated need to be true here t
christiank 2015/12/04 10:20:40 You're absolutely right, my bad.
1517 LazyCreateImage(resource); 1539 LazyCreateImage(resource);
1518 resource->dirty_image = true; 1540 resource->dirty_image = true;
1519 resource->is_overlay_candidate = true; 1541 resource->is_overlay_candidate = true;
1520 } else if (use_texture_storage_ext_ && 1542 } else if (use_texture_storage_ext_ &&
1521 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && 1543 IsFormatSupportedForStorage(format, use_texture_format_bgra_) &&
1522 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { 1544 (resource->hint & TEXTURE_HINT_IMMUTABLE)) {
1523 GLenum storage_format = TextureToStorageFormat(format); 1545 GLenum storage_format = TextureToStorageFormat(format);
1524 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), 1546 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(),
1525 size.height()); 1547 size.height());
1548 resource->allocated = true;
1526 } else { 1549 } else {
1527 // ETC1 does not support preallocation. 1550 // ETC1 does not support preallocation.
1528 if (format != ETC1) { 1551 if (format != ETC1) {
1529 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), 1552 gl->TexImage2D(resource->target, 0, GLInternalFormat(format),
1530 size.width(), size.height(), 0, GLDataFormat(format), 1553 size.width(), size.height(), 0, GLDataFormat(format),
1531 GLDataType(format), NULL); 1554 GLDataType(format), NULL);
1555 resource->allocated = true;
1532 } 1556 }
1533 } 1557 }
1534 } 1558 }
1535 1559
1536 void ResourceProvider::LazyCreateImage(Resource* resource) { 1560 void ResourceProvider::LazyCreateImage(Resource* resource) {
1537 DCHECK(resource->gpu_memory_buffer); 1561 DCHECK(resource->gpu_memory_buffer);
1538 DCHECK(resource->gl_id); 1562 DCHECK(resource->gl_id);
1539 DCHECK(resource->allocated); 1563 DCHECK(resource->allocated);
1540 if (!resource->image_id) { 1564 if (!resource->image_id) {
1541 GLES2Interface* gl = ContextGL(); 1565 GLES2Interface* gl = ContextGL();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 const int kImportance = 2; 1685 const int kImportance = 2;
1662 pmd->CreateSharedGlobalAllocatorDump(guid); 1686 pmd->CreateSharedGlobalAllocatorDump(guid);
1663 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 1687 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
1664 } 1688 }
1665 } 1689 }
1666 1690
1667 return true; 1691 return true;
1668 } 1692 }
1669 1693
1670 } // namespace cc 1694 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698