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 |
11 #include <deque> | 11 #include <deque> |
12 #include <memory> | 12 #include <memory> |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 #include <unordered_map> | 15 #include <unordered_map> |
16 #include <unordered_set> | 16 #include <unordered_set> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "base/callback.h" | 20 #include "base/callback.h" |
| 21 #include "base/containers/small_map.h" |
21 #include "base/macros.h" | 22 #include "base/macros.h" |
22 #include "base/memory/linked_ptr.h" | 23 #include "base/memory/linked_ptr.h" |
23 #include "base/threading/thread_checker.h" | 24 #include "base/threading/thread_checker.h" |
24 #include "base/trace_event/memory_allocator_dump.h" | 25 #include "base/trace_event/memory_allocator_dump.h" |
25 #include "base/trace_event/memory_dump_provider.h" | 26 #include "base/trace_event/memory_dump_provider.h" |
26 #include "cc/base/resource_id.h" | 27 #include "cc/base/resource_id.h" |
27 #include "cc/cc_export.h" | 28 #include "cc/cc_export.h" |
28 #include "cc/output/context_provider.h" | 29 #include "cc/output/context_provider.h" |
29 #include "cc/output/output_surface.h" | 30 #include "cc/output/output_surface.h" |
30 #include "cc/output/renderer_settings.h" | 31 #include "cc/output/renderer_settings.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 ResourceFormat format_; | 442 ResourceFormat format_; |
442 gfx::BufferUsage usage_; | 443 gfx::BufferUsage usage_; |
443 gfx::Size size_; | 444 gfx::Size size_; |
444 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; | 445 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; |
445 gfx::ColorSpace color_space_; | 446 gfx::ColorSpace color_space_; |
446 base::ThreadChecker thread_checker_; | 447 base::ThreadChecker thread_checker_; |
447 | 448 |
448 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); | 449 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); |
449 }; | 450 }; |
450 | 451 |
| 452 // All resources that are returned to children while an instance of this |
| 453 // class exists will be stored and returned when the instance is destroyed. |
| 454 class CC_EXPORT ScopedBatchReturnResources { |
| 455 public: |
| 456 explicit ScopedBatchReturnResources(ResourceProvider* resource_provider); |
| 457 ~ScopedBatchReturnResources(); |
| 458 |
| 459 private: |
| 460 ResourceProvider* resource_provider_; |
| 461 |
| 462 DISALLOW_COPY_AND_ASSIGN(ScopedBatchReturnResources); |
| 463 }; |
| 464 |
451 class Fence : public base::RefCounted<Fence> { | 465 class Fence : public base::RefCounted<Fence> { |
452 public: | 466 public: |
453 Fence() {} | 467 Fence() {} |
454 | 468 |
455 virtual void Set() = 0; | 469 virtual void Set() = 0; |
456 virtual bool HasPassed() = 0; | 470 virtual bool HasPassed() = 0; |
457 virtual void Wait() = 0; | 471 virtual void Wait() = 0; |
458 | 472 |
459 protected: | 473 protected: |
460 friend class base::RefCounted<Fence>; | 474 friend class base::RefCounted<Fence>; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 542 |
529 GLenum GetImageTextureTarget(gfx::BufferUsage usage, ResourceFormat format); | 543 GLenum GetImageTextureTarget(gfx::BufferUsage usage, ResourceFormat format); |
530 | 544 |
531 // base::trace_event::MemoryDumpProvider implementation. | 545 // base::trace_event::MemoryDumpProvider implementation. |
532 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 546 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
533 base::trace_event::ProcessMemoryDump* pmd) override; | 547 base::trace_event::ProcessMemoryDump* pmd) override; |
534 | 548 |
535 int tracing_id() const { return tracing_id_; } | 549 int tracing_id() const { return tracing_id_; } |
536 | 550 |
537 private: | 551 private: |
| 552 friend class ScopedBatchReturnResources; |
| 553 |
538 struct Resource { | 554 struct Resource { |
539 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; | 555 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; |
540 enum SynchronizationState { | 556 enum SynchronizationState { |
541 // The LOCALLY_USED state is the state each resource defaults to when | 557 // The LOCALLY_USED state is the state each resource defaults to when |
542 // constructed or modified or read. This state indicates that the | 558 // constructed or modified or read. This state indicates that the |
543 // resource has not been properly synchronized and it would be an error | 559 // resource has not been properly synchronized and it would be an error |
544 // to send this resource to a parent, child, or client. | 560 // to send this resource to a parent, child, or client. |
545 LOCALLY_USED, | 561 LOCALLY_USED, |
546 | 562 |
547 // The NEEDS_WAIT state is the state that indicates a resource has been | 563 // The NEEDS_WAIT state is the state that indicates a resource has been |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 | 753 |
738 // Returns null if we do not have a ContextProvider. | 754 // Returns null if we do not have a ContextProvider. |
739 gpu::gles2::GLES2Interface* ContextGL() const; | 755 gpu::gles2::GLES2Interface* ContextGL() const; |
740 bool IsGLContextLost() const; | 756 bool IsGLContextLost() const; |
741 | 757 |
742 // Will return the invalid color space unless | 758 // Will return the invalid color space unless |
743 // |enable_color_correct_rasterization| is true. | 759 // |enable_color_correct_rasterization| is true. |
744 gfx::ColorSpace GetResourceColorSpaceForRaster( | 760 gfx::ColorSpace GetResourceColorSpaceForRaster( |
745 const Resource* resource) const; | 761 const Resource* resource) const; |
746 | 762 |
| 763 void SetBatchReturnResources(bool aggregate); |
| 764 |
747 // Holds const settings for the ResourceProvider. Never changed after init. | 765 // Holds const settings for the ResourceProvider. Never changed after init. |
748 struct Settings { | 766 struct Settings { |
749 Settings(ContextProvider* compositor_context_provider, | 767 Settings(ContextProvider* compositor_context_provider, |
750 bool delegated_sync_points_required, | 768 bool delegated_sync_points_required, |
751 bool use_gpu_memory_buffer_resources, | 769 bool use_gpu_memory_buffer_resources, |
752 bool enable_color_correct_rasterization); | 770 bool enable_color_correct_rasterization); |
753 | 771 |
754 int max_texture_size = 0; | 772 int max_texture_size = 0; |
755 bool use_texture_storage_ext = false; | 773 bool use_texture_storage_ext = false; |
756 bool use_texture_format_bgra = false; | 774 bool use_texture_format_bgra = false; |
(...skipping 14 matching lines...) Expand all Loading... |
771 BlockingTaskRunner* blocking_main_thread_task_runner_; | 789 BlockingTaskRunner* blocking_main_thread_task_runner_; |
772 bool lost_context_provider_; | 790 bool lost_context_provider_; |
773 ResourceId next_id_; | 791 ResourceId next_id_; |
774 ResourceMap resources_; | 792 ResourceMap resources_; |
775 int next_child_; | 793 int next_child_; |
776 ChildMap children_; | 794 ChildMap children_; |
777 scoped_refptr<Fence> current_read_lock_fence_; | 795 scoped_refptr<Fence> current_read_lock_fence_; |
778 std::unique_ptr<TextureIdAllocator> texture_id_allocator_; | 796 std::unique_ptr<TextureIdAllocator> texture_id_allocator_; |
779 BufferToTextureTargetMap buffer_to_texture_target_map_; | 797 BufferToTextureTargetMap buffer_to_texture_target_map_; |
780 | 798 |
| 799 // Keep track of whether deleted resources should be batched up or returned |
| 800 // immediately. |
| 801 bool batch_return_resources_ = false; |
| 802 // Maps from a child id to the set of resources to be returned to it. |
| 803 base::SmallMap<std::map<int, ResourceIdArray>> batched_returning_resources_; |
| 804 |
781 base::ThreadChecker thread_checker_; | 805 base::ThreadChecker thread_checker_; |
782 | 806 |
783 // A process-unique ID used for disambiguating memory dumps from different | 807 // A process-unique ID used for disambiguating memory dumps from different |
784 // resource providers. | 808 // resource providers. |
785 int tracing_id_; | 809 int tracing_id_; |
786 | 810 |
787 #if defined(OS_ANDROID) | 811 #if defined(OS_ANDROID) |
788 // Set of resource Ids that would like to be notified about promotion hints. | 812 // Set of resource Ids that would like to be notified about promotion hints. |
789 ResourceIdSet wants_promotion_hints_set_; | 813 ResourceIdSet wants_promotion_hints_set_; |
790 #endif | 814 #endif |
791 | 815 |
792 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 816 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
793 }; | 817 }; |
794 | 818 |
795 } // namespace cc | 819 } // namespace cc |
796 | 820 |
797 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 821 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |