| 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 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ | 5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ | 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 RESOURCE_TYPE_GPU_MEMORY_BUFFER, | 76 RESOURCE_TYPE_GPU_MEMORY_BUFFER, |
| 77 RESOURCE_TYPE_GL_TEXTURE, | 77 RESOURCE_TYPE_GL_TEXTURE, |
| 78 RESOURCE_TYPE_BITMAP, | 78 RESOURCE_TYPE_BITMAP, |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 ResourceProvider( | 81 ResourceProvider( |
| 82 ContextProvider* compositor_context_provider, | 82 ContextProvider* compositor_context_provider, |
| 83 SharedBitmapManager* shared_bitmap_manager, | 83 SharedBitmapManager* shared_bitmap_manager, |
| 84 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 84 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 85 BlockingTaskRunner* blocking_main_thread_task_runner, | 85 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 86 int highp_threshold_min, | |
| 87 size_t id_allocation_chunk_size, | 86 size_t id_allocation_chunk_size, |
| 88 bool delegated_sync_points_required, | 87 bool delegated_sync_points_required, |
| 89 bool use_gpu_memory_buffer_resources, | 88 bool use_gpu_memory_buffer_resources, |
| 90 bool enable_color_correct_rendering, | 89 bool enable_color_correct_rendering, |
| 91 const BufferToTextureTargetMap& buffer_to_texture_target_map); | 90 const BufferToTextureTargetMap& buffer_to_texture_target_map); |
| 92 ~ResourceProvider() override; | 91 ~ResourceProvider() override; |
| 93 | 92 |
| 94 void Initialize(); | 93 void Initialize(); |
| 95 | 94 |
| 96 void DidLoseContextProvider() { lost_context_provider_ = true; } | 95 void DidLoseContextProvider() { lost_context_provider_ = true; } |
| 97 | 96 |
| 98 int max_texture_size() const { return max_texture_size_; } | 97 int max_texture_size() const { return settings_.max_texture_size; } |
| 99 ResourceFormat best_texture_format() const { return best_texture_format_; } | 98 ResourceFormat best_texture_format() const { |
| 99 return settings_.best_texture_format; |
| 100 } |
| 100 ResourceFormat best_render_buffer_format() const { | 101 ResourceFormat best_render_buffer_format() const { |
| 101 return best_render_buffer_format_; | 102 return settings_.best_render_buffer_format; |
| 102 } | 103 } |
| 103 ResourceFormat YuvResourceFormat(int bits) const; | 104 ResourceFormat YuvResourceFormat(int bits) const; |
| 104 bool use_sync_query() const { return use_sync_query_; } | 105 bool use_sync_query() const { return settings_.use_sync_query; } |
| 105 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() { | 106 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() { |
| 106 return gpu_memory_buffer_manager_; | 107 return gpu_memory_buffer_manager_; |
| 107 } | 108 } |
| 108 size_t num_resources() const { return resources_.size(); } | 109 size_t num_resources() const { return resources_.size(); } |
| 109 | 110 |
| 110 bool IsResourceFormatSupported(ResourceFormat format) const; | 111 bool IsResourceFormatSupported(ResourceFormat format) const; |
| 111 | 112 |
| 112 // Checks whether a resource is in use by a consumer. | 113 // Checks whether a resource is in use by a consumer. |
| 113 bool InUseByConsumer(ResourceId id); | 114 bool InUseByConsumer(ResourceId id); |
| 114 | 115 |
| 115 bool IsLost(ResourceId id); | 116 bool IsLost(ResourceId id); |
| 116 | 117 |
| 117 void LoseResourceForTesting(ResourceId id); | 118 void LoseResourceForTesting(ResourceId id); |
| 118 void EnableReadLockFencesForTesting(ResourceId id); | 119 void EnableReadLockFencesForTesting(ResourceId id); |
| 119 | 120 |
| 120 // Producer interface. | 121 // Producer interface. |
| 121 | 122 |
| 122 ResourceType default_resource_type() const { return default_resource_type_; } | 123 ResourceType default_resource_type() const { |
| 124 return settings_.default_resource_type; |
| 125 } |
| 123 ResourceType GetResourceType(ResourceId id); | 126 ResourceType GetResourceType(ResourceId id); |
| 124 GLenum GetResourceTextureTarget(ResourceId id); | 127 GLenum GetResourceTextureTarget(ResourceId id); |
| 125 bool IsImmutable(ResourceId id); | 128 bool IsImmutable(ResourceId id); |
| 126 TextureHint GetTextureHint(ResourceId id); | 129 TextureHint GetTextureHint(ResourceId id); |
| 127 | 130 |
| 128 // Creates a resource of the default resource type. | 131 // Creates a resource of the default resource type. |
| 129 ResourceId CreateResource(const gfx::Size& size, | 132 ResourceId CreateResource(const gfx::Size& size, |
| 130 TextureHint hint, | 133 TextureHint hint, |
| 131 ResourceFormat format, | 134 ResourceFormat format, |
| 132 const gfx::ColorSpace& color_space); | 135 const gfx::ColorSpace& color_space); |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 void BindImageForSampling(Resource* resource); | 706 void BindImageForSampling(Resource* resource); |
| 704 // Binds the given GL resource to a texture target for sampling using the | 707 // Binds the given GL resource to a texture target for sampling using the |
| 705 // specified filter for both minification and magnification. Returns the | 708 // specified filter for both minification and magnification. Returns the |
| 706 // texture target used. The resource must be locked for reading. | 709 // texture target used. The resource must be locked for reading. |
| 707 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); | 710 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); |
| 708 | 711 |
| 709 // Returns null if we do not have a ContextProvider. | 712 // Returns null if we do not have a ContextProvider. |
| 710 gpu::gles2::GLES2Interface* ContextGL() const; | 713 gpu::gles2::GLES2Interface* ContextGL() const; |
| 711 bool IsGLContextLost() const; | 714 bool IsGLContextLost() const; |
| 712 | 715 |
| 713 // Returns null if |enable_color_correct_rendering_| is false. | 716 // Returns null if |settings_.enable_color_correct_rendering| is false. |
| 714 sk_sp<SkColorSpace> GetResourceSkColorSpace(const Resource* resource) const; | 717 sk_sp<SkColorSpace> GetResourceSkColorSpace(const Resource* resource) const; |
| 715 | 718 |
| 719 // Holds const settings for the ResourceProvider. Never changed after init. |
| 720 struct Settings { |
| 721 Settings(ContextProvider* compositor_context_provider, |
| 722 bool delegated_sync_points_required, |
| 723 bool use_gpu_memory_buffer_resources, |
| 724 bool enable_color_correct_rendering); |
| 725 |
| 726 int max_texture_size = 0; |
| 727 bool use_texture_storage_ext = false; |
| 728 bool use_texture_format_bgra = false; |
| 729 bool use_texture_usage_hint = false; |
| 730 bool use_sync_query = false; |
| 731 ResourceType default_resource_type = RESOURCE_TYPE_GL_TEXTURE; |
| 732 ResourceFormat yuv_resource_format = LUMINANCE_8; |
| 733 ResourceFormat yuv_highbit_resource_format = LUMINANCE_8; |
| 734 ResourceFormat best_texture_format = RGBA_8888; |
| 735 ResourceFormat best_render_buffer_format = RGBA_8888; |
| 736 bool enable_color_correct_rendering = false; |
| 737 bool delegated_sync_points_required = false; |
| 738 } const settings_; |
| 739 |
| 716 ContextProvider* compositor_context_provider_; | 740 ContextProvider* compositor_context_provider_; |
| 717 SharedBitmapManager* shared_bitmap_manager_; | 741 SharedBitmapManager* shared_bitmap_manager_; |
| 718 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; | 742 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
| 719 BlockingTaskRunner* blocking_main_thread_task_runner_; | 743 BlockingTaskRunner* blocking_main_thread_task_runner_; |
| 720 bool lost_context_provider_; | 744 bool lost_context_provider_; |
| 721 int highp_threshold_min_; | |
| 722 ResourceId next_id_; | 745 ResourceId next_id_; |
| 723 ResourceMap resources_; | 746 ResourceMap resources_; |
| 724 int next_child_; | 747 int next_child_; |
| 725 ChildMap children_; | 748 ChildMap children_; |
| 726 | 749 scoped_refptr<Fence> current_read_lock_fence_; |
| 727 const bool delegated_sync_points_required_; | 750 std::unique_ptr<IdAllocator> texture_id_allocator_; |
| 728 | 751 std::unique_ptr<IdAllocator> buffer_id_allocator_; |
| 729 ResourceType default_resource_type_; | 752 BufferToTextureTargetMap buffer_to_texture_target_map_; |
| 730 bool use_texture_storage_ext_; | |
| 731 bool use_texture_format_bgra_; | |
| 732 bool use_texture_usage_hint_; | |
| 733 bool use_compressed_texture_etc1_; | |
| 734 ResourceFormat yuv_resource_format_; | |
| 735 ResourceFormat yuv_highbit_resource_format_; | |
| 736 int max_texture_size_; | |
| 737 ResourceFormat best_texture_format_; | |
| 738 ResourceFormat best_render_buffer_format_; | |
| 739 const bool enable_color_correct_rendering_ = false; | |
| 740 | 753 |
| 741 base::ThreadChecker thread_checker_; | 754 base::ThreadChecker thread_checker_; |
| 742 | 755 |
| 743 scoped_refptr<Fence> current_read_lock_fence_; | |
| 744 | |
| 745 const size_t id_allocation_chunk_size_; | |
| 746 std::unique_ptr<IdAllocator> texture_id_allocator_; | |
| 747 std::unique_ptr<IdAllocator> buffer_id_allocator_; | |
| 748 | |
| 749 bool use_sync_query_; | |
| 750 BufferToTextureTargetMap buffer_to_texture_target_map_; | |
| 751 | |
| 752 // A process-unique ID used for disambiguating memory dumps from different | 756 // A process-unique ID used for disambiguating memory dumps from different |
| 753 // resource providers. | 757 // resource providers. |
| 754 int tracing_id_; | 758 int tracing_id_; |
| 759 |
| 755 #if defined(OS_ANDROID) | 760 #if defined(OS_ANDROID) |
| 756 // Set of resource Ids that would like to be notified about promotion hints. | 761 // Set of resource Ids that would like to be notified about promotion hints. |
| 757 ResourceIdSet wants_promotion_hints_set_; | 762 ResourceIdSet wants_promotion_hints_set_; |
| 758 #endif | 763 #endif |
| 759 | 764 |
| 760 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 765 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 761 }; | 766 }; |
| 762 | 767 |
| 763 } // namespace cc | 768 } // namespace cc |
| 764 | 769 |
| 765 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 770 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |