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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 383 |
384 ResourceProvider::ResourceProvider( | 384 ResourceProvider::ResourceProvider( |
385 ContextProvider* compositor_context_provider, | 385 ContextProvider* compositor_context_provider, |
386 SharedBitmapManager* shared_bitmap_manager, | 386 SharedBitmapManager* shared_bitmap_manager, |
387 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 387 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
388 BlockingTaskRunner* blocking_main_thread_task_runner, | 388 BlockingTaskRunner* blocking_main_thread_task_runner, |
389 int highp_threshold_min, | 389 int highp_threshold_min, |
390 size_t id_allocation_chunk_size, | 390 size_t id_allocation_chunk_size, |
391 bool delegated_sync_points_required, | 391 bool delegated_sync_points_required, |
392 bool use_gpu_memory_buffer_resources, | 392 bool use_gpu_memory_buffer_resources, |
393 const std::vector<unsigned>& use_image_texture_targets) | 393 const BufferToTextureTargetMap& buffer_to_texture_target_map) |
394 : compositor_context_provider_(compositor_context_provider), | 394 : compositor_context_provider_(compositor_context_provider), |
395 shared_bitmap_manager_(shared_bitmap_manager), | 395 shared_bitmap_manager_(shared_bitmap_manager), |
396 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 396 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
397 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), | 397 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), |
398 lost_output_surface_(false), | 398 lost_output_surface_(false), |
399 highp_threshold_min_(highp_threshold_min), | 399 highp_threshold_min_(highp_threshold_min), |
400 next_id_(1), | 400 next_id_(1), |
401 next_child_(1), | 401 next_child_(1), |
402 delegated_sync_points_required_(delegated_sync_points_required), | 402 delegated_sync_points_required_(delegated_sync_points_required), |
403 default_resource_type_(use_gpu_memory_buffer_resources | 403 default_resource_type_(use_gpu_memory_buffer_resources |
404 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER | 404 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER |
405 : RESOURCE_TYPE_GL_TEXTURE), | 405 : RESOURCE_TYPE_GL_TEXTURE), |
406 use_texture_storage_ext_(false), | 406 use_texture_storage_ext_(false), |
407 use_texture_format_bgra_(false), | 407 use_texture_format_bgra_(false), |
408 use_texture_usage_hint_(false), | 408 use_texture_usage_hint_(false), |
409 use_compressed_texture_etc1_(false), | 409 use_compressed_texture_etc1_(false), |
410 yuv_resource_format_(LUMINANCE_8), | 410 yuv_resource_format_(LUMINANCE_8), |
411 max_texture_size_(0), | 411 max_texture_size_(0), |
412 best_texture_format_(RGBA_8888), | 412 best_texture_format_(RGBA_8888), |
413 best_render_buffer_format_(RGBA_8888), | 413 best_render_buffer_format_(RGBA_8888), |
414 id_allocation_chunk_size_(id_allocation_chunk_size), | 414 id_allocation_chunk_size_(id_allocation_chunk_size), |
415 use_sync_query_(false), | 415 use_sync_query_(false), |
416 use_image_texture_targets_(use_image_texture_targets), | 416 buffer_to_texture_target_map_(buffer_to_texture_target_map), |
417 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { | 417 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { |
418 DCHECK(id_allocation_chunk_size_); | 418 DCHECK(id_allocation_chunk_size_); |
419 DCHECK(thread_checker_.CalledOnValidThread()); | 419 DCHECK(thread_checker_.CalledOnValidThread()); |
420 | 420 |
421 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 421 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
422 // Don't register a dump provider in these cases. | 422 // Don't register a dump provider in these cases. |
423 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 | 423 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 |
424 if (base::ThreadTaskRunnerHandle::IsSet()) { | 424 if (base::ThreadTaskRunnerHandle::IsSet()) { |
425 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 425 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
426 this, "cc::ResourceProvider", base::ThreadTaskRunnerHandle::Get()); | 426 this, "cc::ResourceProvider", base::ThreadTaskRunnerHandle::Get()); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } | 592 } |
593 | 593 |
594 ResourceId ResourceProvider::CreateGLTexture(const gfx::Size& size, | 594 ResourceId ResourceProvider::CreateGLTexture(const gfx::Size& size, |
595 TextureHint hint, | 595 TextureHint hint, |
596 ResourceType type, | 596 ResourceType type, |
597 ResourceFormat format) { | 597 ResourceFormat format) { |
598 DCHECK_LE(size.width(), max_texture_size_); | 598 DCHECK_LE(size.width(), max_texture_size_); |
599 DCHECK_LE(size.height(), max_texture_size_); | 599 DCHECK_LE(size.height(), max_texture_size_); |
600 DCHECK(thread_checker_.CalledOnValidThread()); | 600 DCHECK(thread_checker_.CalledOnValidThread()); |
601 | 601 |
| 602 // TODO(crbug.com/590317): We should not assume that all resources created by |
| 603 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this |
| 604 // based on the current RasterBufferProvider's needs. |
602 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER | 605 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER |
603 ? GetImageTextureTarget(format) | 606 ? GetImageTextureTarget( |
| 607 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, format) |
604 : GL_TEXTURE_2D; | 608 : GL_TEXTURE_2D; |
605 | 609 |
606 ResourceId id = next_id_++; | 610 ResourceId id = next_id_++; |
607 Resource* resource = | 611 Resource* resource = |
608 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, | 612 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, |
609 GL_LINEAR, hint, type, format)); | 613 GL_LINEAR, hint, type, format)); |
610 resource->allocated = false; | 614 resource->allocated = false; |
611 return id; | 615 return id; |
612 } | 616 } |
613 | 617 |
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1893 resource->WaitSyncToken(gl); | 1897 resource->WaitSyncToken(gl); |
1894 } | 1898 } |
1895 } | 1899 } |
1896 | 1900 |
1897 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { | 1901 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { |
1898 GLint active_unit = 0; | 1902 GLint active_unit = 0; |
1899 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1903 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1900 return active_unit; | 1904 return active_unit; |
1901 } | 1905 } |
1902 | 1906 |
1903 GLenum ResourceProvider::GetImageTextureTarget(ResourceFormat format) { | 1907 GLenum ResourceProvider::GetImageTextureTarget(gfx::BufferUsage usage, |
| 1908 ResourceFormat format) { |
1904 gfx::BufferFormat buffer_format = BufferFormat(format); | 1909 gfx::BufferFormat buffer_format = BufferFormat(format); |
1905 DCHECK_GT(use_image_texture_targets_.size(), | 1910 auto found = buffer_to_texture_target_map_.find( |
1906 static_cast<size_t>(buffer_format)); | 1911 BufferToTextureTargetKey(usage, buffer_format)); |
1907 return use_image_texture_targets_[static_cast<size_t>(buffer_format)]; | 1912 DCHECK(found != buffer_to_texture_target_map_.end()); |
| 1913 return found->second; |
1908 } | 1914 } |
1909 | 1915 |
1910 void ResourceProvider::ValidateResource(ResourceId id) const { | 1916 void ResourceProvider::ValidateResource(ResourceId id) const { |
1911 DCHECK(thread_checker_.CalledOnValidThread()); | 1917 DCHECK(thread_checker_.CalledOnValidThread()); |
1912 DCHECK(id); | 1918 DCHECK(id); |
1913 DCHECK(resources_.find(id) != resources_.end()); | 1919 DCHECK(resources_.find(id) != resources_.end()); |
1914 } | 1920 } |
1915 | 1921 |
1916 GLES2Interface* ResourceProvider::ContextGL() const { | 1922 GLES2Interface* ResourceProvider::ContextGL() const { |
1917 ContextProvider* context_provider = compositor_context_provider_; | 1923 ContextProvider* context_provider = compositor_context_provider_; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 | 1997 |
1992 const int kImportance = 2; | 1998 const int kImportance = 2; |
1993 pmd->CreateSharedGlobalAllocatorDump(guid); | 1999 pmd->CreateSharedGlobalAllocatorDump(guid); |
1994 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2000 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
1995 } | 2001 } |
1996 | 2002 |
1997 return true; | 2003 return true; |
1998 } | 2004 } |
1999 | 2005 |
2000 } // namespace cc | 2006 } // namespace cc |
OLD | NEW |