OLD | NEW |
---|---|
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/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 } | 114 } |
115 | 115 |
116 gfx::GpuMemoryBuffer::Format ToGpuMemoryBufferFormat(ResourceFormat format) { | 116 gfx::GpuMemoryBuffer::Format ToGpuMemoryBufferFormat(ResourceFormat format) { |
117 switch (format) { | 117 switch (format) { |
118 case RGBA_8888: | 118 case RGBA_8888: |
119 return gfx::GpuMemoryBuffer::RGBA_8888; | 119 return gfx::GpuMemoryBuffer::RGBA_8888; |
120 case BGRA_8888: | 120 case BGRA_8888: |
121 return gfx::GpuMemoryBuffer::BGRA_8888; | 121 return gfx::GpuMemoryBuffer::BGRA_8888; |
122 case RGBA_4444: | 122 case RGBA_4444: |
123 return gfx::GpuMemoryBuffer::RGBA_4444; | 123 return gfx::GpuMemoryBuffer::RGBA_4444; |
124 case ETC1: | |
125 return gfx::GpuMemoryBuffer::ETC1; | |
124 case ALPHA_8: | 126 case ALPHA_8: |
125 case LUMINANCE_8: | 127 case LUMINANCE_8: |
126 case RGB_565: | 128 case RGB_565: |
127 case ETC1: | |
128 case RED_8: | 129 case RED_8: |
129 break; | 130 break; |
130 } | 131 } |
131 NOTREACHED(); | 132 NOTREACHED(); |
132 return gfx::GpuMemoryBuffer::RGBA_8888; | 133 return gfx::GpuMemoryBuffer::RGBA_8888; |
133 } | 134 } |
134 | 135 |
135 class ScopedSetActiveTexture { | 136 class ScopedSetActiveTexture { |
136 public: | 137 public: |
137 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) | 138 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 | 386 |
386 ResourceProvider::Child::~Child() {} | 387 ResourceProvider::Child::~Child() {} |
387 | 388 |
388 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 389 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
389 OutputSurface* output_surface, | 390 OutputSurface* output_surface, |
390 SharedBitmapManager* shared_bitmap_manager, | 391 SharedBitmapManager* shared_bitmap_manager, |
391 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 392 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
392 BlockingTaskRunner* blocking_main_thread_task_runner, | 393 BlockingTaskRunner* blocking_main_thread_task_runner, |
393 int highp_threshold_min, | 394 int highp_threshold_min, |
394 bool use_rgba_4444_texture_format, | 395 bool use_rgba_4444_texture_format, |
396 bool use_tile_compression, | |
395 size_t id_allocation_chunk_size, | 397 size_t id_allocation_chunk_size, |
396 bool use_persistent_map_for_gpu_memory_buffers) { | 398 bool use_persistent_map_for_gpu_memory_buffers) { |
397 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( | 399 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( |
398 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, | 400 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, |
399 blocking_main_thread_task_runner, highp_threshold_min, | 401 blocking_main_thread_task_runner, highp_threshold_min, |
400 use_rgba_4444_texture_format, id_allocation_chunk_size, | 402 use_rgba_4444_texture_format, use_tile_compression, |
401 use_persistent_map_for_gpu_memory_buffers)); | 403 id_allocation_chunk_size, use_persistent_map_for_gpu_memory_buffers)); |
402 resource_provider->Initialize(); | 404 resource_provider->Initialize(); |
403 return resource_provider; | 405 return resource_provider; |
404 } | 406 } |
405 | 407 |
406 ResourceProvider::~ResourceProvider() { | 408 ResourceProvider::~ResourceProvider() { |
407 while (!children_.empty()) | 409 while (!children_.empty()) |
408 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); | 410 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); |
409 while (!resources_.empty()) | 411 while (!resources_.empty()) |
410 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); | 412 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); |
411 | 413 |
(...skipping 11 matching lines...) Expand all Loading... | |
423 itr != resources_.end(); ++itr) { | 425 itr != resources_.end(); ++itr) { |
424 DCHECK_NE(RESOURCE_TYPE_GL_TEXTURE, itr->second.type); | 426 DCHECK_NE(RESOURCE_TYPE_GL_TEXTURE, itr->second.type); |
425 } | 427 } |
426 #endif // DCHECK_IS_ON() | 428 #endif // DCHECK_IS_ON() |
427 | 429 |
428 texture_id_allocator_ = nullptr; | 430 texture_id_allocator_ = nullptr; |
429 buffer_id_allocator_ = nullptr; | 431 buffer_id_allocator_ = nullptr; |
430 gl->Finish(); | 432 gl->Finish(); |
431 } | 433 } |
432 | 434 |
435 ResourceFormat ResourceProvider::memory_efficient_texture_format( | |
436 bool must_be_noncompressed, | |
437 bool must_support_alpha) const { | |
438 if (use_tile_compression_ && !must_be_noncompressed && !must_support_alpha) | |
439 return ETC1; | |
440 | |
441 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; | |
442 } | |
443 | |
433 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 444 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
434 Resource* resource = GetResource(id); | 445 Resource* resource = GetResource(id); |
435 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 446 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
436 resource->lost; | 447 resource->lost; |
437 } | 448 } |
438 | 449 |
439 bool ResourceProvider::IsLost(ResourceId id) { | 450 bool ResourceProvider::IsLost(ResourceId id) { |
440 Resource* resource = GetResource(id); | 451 Resource* resource = GetResource(id); |
441 return resource->lost; | 452 return resource->lost; |
442 } | 453 } |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 gl_->Finish(); | 1084 gl_->Finish(); |
1074 } | 1085 } |
1075 | 1086 |
1076 ResourceProvider::ResourceProvider( | 1087 ResourceProvider::ResourceProvider( |
1077 OutputSurface* output_surface, | 1088 OutputSurface* output_surface, |
1078 SharedBitmapManager* shared_bitmap_manager, | 1089 SharedBitmapManager* shared_bitmap_manager, |
1079 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 1090 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
1080 BlockingTaskRunner* blocking_main_thread_task_runner, | 1091 BlockingTaskRunner* blocking_main_thread_task_runner, |
1081 int highp_threshold_min, | 1092 int highp_threshold_min, |
1082 bool use_rgba_4444_texture_format, | 1093 bool use_rgba_4444_texture_format, |
1094 bool use_tile_compression, | |
1083 size_t id_allocation_chunk_size, | 1095 size_t id_allocation_chunk_size, |
1084 bool use_persistent_map_for_gpu_memory_buffers) | 1096 bool use_persistent_map_for_gpu_memory_buffers) |
1085 : output_surface_(output_surface), | 1097 : output_surface_(output_surface), |
1086 shared_bitmap_manager_(shared_bitmap_manager), | 1098 shared_bitmap_manager_(shared_bitmap_manager), |
1087 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 1099 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
1088 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), | 1100 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), |
1089 lost_output_surface_(false), | 1101 lost_output_surface_(false), |
1090 highp_threshold_min_(highp_threshold_min), | 1102 highp_threshold_min_(highp_threshold_min), |
1091 next_id_(1), | 1103 next_id_(1), |
1092 next_child_(1), | 1104 next_child_(1), |
1093 default_resource_type_(RESOURCE_TYPE_BITMAP), | 1105 default_resource_type_(RESOURCE_TYPE_BITMAP), |
1094 use_texture_storage_ext_(false), | 1106 use_texture_storage_ext_(false), |
1095 use_texture_format_bgra_(false), | 1107 use_texture_format_bgra_(false), |
1096 use_texture_usage_hint_(false), | 1108 use_texture_usage_hint_(false), |
1097 use_compressed_texture_etc1_(false), | 1109 use_compressed_texture_etc1_(false), |
1098 yuv_resource_format_(LUMINANCE_8), | 1110 yuv_resource_format_(LUMINANCE_8), |
1099 max_texture_size_(0), | 1111 max_texture_size_(0), |
1100 best_texture_format_(RGBA_8888), | 1112 best_texture_format_(RGBA_8888), |
1101 best_render_buffer_format_(RGBA_8888), | 1113 best_render_buffer_format_(RGBA_8888), |
1102 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), | 1114 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), |
1115 use_tile_compression_(use_tile_compression), | |
1103 id_allocation_chunk_size_(id_allocation_chunk_size), | 1116 id_allocation_chunk_size_(id_allocation_chunk_size), |
1104 use_sync_query_(false), | 1117 use_sync_query_(false), |
1105 use_persistent_map_for_gpu_memory_buffers_( | 1118 use_persistent_map_for_gpu_memory_buffers_( |
1106 use_persistent_map_for_gpu_memory_buffers) { | 1119 use_persistent_map_for_gpu_memory_buffers) { |
1107 DCHECK(output_surface_->HasClient()); | 1120 DCHECK(output_surface_->HasClient()); |
1108 DCHECK(id_allocation_chunk_size_); | 1121 DCHECK(id_allocation_chunk_size_); |
1109 } | 1122 } |
1110 | 1123 |
1111 void ResourceProvider::Initialize() { | 1124 void ResourceProvider::Initialize() { |
1112 DCHECK(thread_checker_.CalledOnValidThread()); | 1125 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1870 // implementations. crbug.com/436314 | 1883 // implementations. crbug.com/436314 |
1871 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, | 1884 gl->BeginQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM, |
1872 source_resource->gl_read_lock_query_id); | 1885 source_resource->gl_read_lock_query_id); |
1873 #else | 1886 #else |
1874 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, | 1887 gl->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, |
1875 source_resource->gl_read_lock_query_id); | 1888 source_resource->gl_read_lock_query_id); |
1876 #endif | 1889 #endif |
1877 } | 1890 } |
1878 DCHECK(!dest_resource->image_id); | 1891 DCHECK(!dest_resource->image_id); |
1879 dest_resource->allocated = true; | 1892 dest_resource->allocated = true; |
1880 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, | 1893 if (IsResourceFormatCompressed(source_resource->format)) { |
1881 dest_resource->gl_id, rect.x(), rect.y(), rect.x(), | 1894 // TODO(christiank): Should use CompressedCopySubTextureCHROMIUM. |
reveman
2015/07/21 04:26:33
Let's fix this TODO before landing this patch.
| |
1882 rect.y(), rect.width(), rect.height()); | 1895 gl->CompressedCopyTextureCHROMIUM( |
1896 dest_resource->target, source_resource->gl_id, dest_resource->gl_id); | |
1897 } else { | |
1898 gl->CopySubTextureCHROMIUM(dest_resource->target, source_resource->gl_id, | |
1899 dest_resource->gl_id, rect.x(), rect.y(), | |
1900 rect.x(), rect.y(), rect.width(), rect.height()); | |
1901 } | |
1883 if (source_resource->gl_read_lock_query_id) { | 1902 if (source_resource->gl_read_lock_query_id) { |
1884 // End query and create a read lock fence that will prevent access to | 1903 // End query and create a read lock fence that will prevent access to |
1885 // source resource until CopySubTextureCHROMIUM command has completed. | 1904 // source resource until CopySubTextureCHROMIUM command has completed. |
1886 #if defined(OS_CHROMEOS) | 1905 #if defined(OS_CHROMEOS) |
1887 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); | 1906 gl->EndQueryEXT(GL_COMMANDS_ISSUED_CHROMIUM); |
1888 #else | 1907 #else |
1889 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); | 1908 gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM); |
1890 #endif | 1909 #endif |
1891 source_resource->read_lock_fence = make_scoped_refptr( | 1910 source_resource->read_lock_fence = make_scoped_refptr( |
1892 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); | 1911 new CopyTextureFence(gl, source_resource->gl_read_lock_query_id)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1944 } | 1963 } |
1945 | 1964 |
1946 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 1965 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
1947 ContextProvider* context_provider = | 1966 ContextProvider* context_provider = |
1948 worker_context ? output_surface_->worker_context_provider() | 1967 worker_context ? output_surface_->worker_context_provider() |
1949 : output_surface_->context_provider(); | 1968 : output_surface_->context_provider(); |
1950 return context_provider ? context_provider->GrContext() : NULL; | 1969 return context_provider ? context_provider->GrContext() : NULL; |
1951 } | 1970 } |
1952 | 1971 |
1953 } // namespace cc | 1972 } // namespace cc |
OLD | NEW |