Chromium Code Reviews| 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 ResourceFormat format_; | 438 ResourceFormat format_; |
| 438 gfx::BufferUsage usage_; | 439 gfx::BufferUsage usage_; |
| 439 gfx::Size size_; | 440 gfx::Size size_; |
| 440 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; | 441 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; |
| 441 gfx::ColorSpace color_space_; | 442 gfx::ColorSpace color_space_; |
| 442 base::ThreadChecker thread_checker_; | 443 base::ThreadChecker thread_checker_; |
| 443 | 444 |
| 444 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); | 445 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); |
| 445 }; | 446 }; |
| 446 | 447 |
| 448 // All resources that are returned to children while an instance of this | |
| 449 // class exists will be stored and returned when the instance is destroyed. | |
| 450 class CC_EXPORT ScopedBatchReturnResources { | |
| 451 public: | |
| 452 explicit ScopedBatchReturnResources(ResourceProvider* resource_provider); | |
| 453 ~ScopedBatchReturnResources(); | |
| 454 | |
| 455 private: | |
| 456 ResourceProvider* resource_provider_; | |
| 457 | |
| 458 DISALLOW_COPY_AND_ASSIGN(ScopedBatchReturnResources); | |
| 459 }; | |
| 460 | |
| 447 class Fence : public base::RefCounted<Fence> { | 461 class Fence : public base::RefCounted<Fence> { |
| 448 public: | 462 public: |
| 449 Fence() {} | 463 Fence() {} |
| 450 | 464 |
| 451 virtual void Set() = 0; | 465 virtual void Set() = 0; |
| 452 virtual bool HasPassed() = 0; | 466 virtual bool HasPassed() = 0; |
| 453 virtual void Wait() = 0; | 467 virtual void Wait() = 0; |
| 454 | 468 |
| 455 protected: | 469 protected: |
| 456 friend class base::RefCounted<Fence>; | 470 friend class base::RefCounted<Fence>; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 #endif | 531 #endif |
| 518 | 532 |
| 519 void WaitSyncTokenIfNeeded(ResourceId id); | 533 void WaitSyncTokenIfNeeded(ResourceId id); |
| 520 | 534 |
| 521 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); | 535 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); |
| 522 | 536 |
| 523 void ValidateResource(ResourceId id) const; | 537 void ValidateResource(ResourceId id) const; |
| 524 | 538 |
| 525 GLenum GetImageTextureTarget(gfx::BufferUsage usage, ResourceFormat format); | 539 GLenum GetImageTextureTarget(gfx::BufferUsage usage, ResourceFormat format); |
| 526 | 540 |
| 541 void SetBatchReturnResources(bool aggregate); | |
|
Daniele Castagna
2017/03/27 13:38:11
nit: Can this be moved away from the public Resour
| |
| 542 | |
| 527 // base::trace_event::MemoryDumpProvider implementation. | 543 // base::trace_event::MemoryDumpProvider implementation. |
| 528 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 544 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 529 base::trace_event::ProcessMemoryDump* pmd) override; | 545 base::trace_event::ProcessMemoryDump* pmd) override; |
| 530 | 546 |
| 531 int tracing_id() const { return tracing_id_; } | 547 int tracing_id() const { return tracing_id_; } |
| 532 | 548 |
| 533 private: | 549 private: |
| 534 struct Resource { | 550 struct Resource { |
| 535 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; | 551 enum Origin { INTERNAL, EXTERNAL, DELEGATED }; |
| 536 enum SynchronizationState { | 552 enum SynchronizationState { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 BlockingTaskRunner* blocking_main_thread_task_runner_; | 783 BlockingTaskRunner* blocking_main_thread_task_runner_; |
| 768 bool lost_context_provider_; | 784 bool lost_context_provider_; |
| 769 ResourceId next_id_; | 785 ResourceId next_id_; |
| 770 ResourceMap resources_; | 786 ResourceMap resources_; |
| 771 int next_child_; | 787 int next_child_; |
| 772 ChildMap children_; | 788 ChildMap children_; |
| 773 scoped_refptr<Fence> current_read_lock_fence_; | 789 scoped_refptr<Fence> current_read_lock_fence_; |
| 774 std::unique_ptr<TextureIdAllocator> texture_id_allocator_; | 790 std::unique_ptr<TextureIdAllocator> texture_id_allocator_; |
| 775 BufferToTextureTargetMap buffer_to_texture_target_map_; | 791 BufferToTextureTargetMap buffer_to_texture_target_map_; |
| 776 | 792 |
| 793 // Keep track of whether deleted resources should be batched up or returned | |
| 794 // immediately. | |
| 795 bool batch_return_resources_ = false; | |
| 796 // Maps from a child id to the set of resources to be returned to it. | |
| 797 base::SmallMap<std::map<int, ResourceIdArray>> batched_returning_resources_; | |
| 798 | |
| 777 base::ThreadChecker thread_checker_; | 799 base::ThreadChecker thread_checker_; |
| 778 | 800 |
| 779 // A process-unique ID used for disambiguating memory dumps from different | 801 // A process-unique ID used for disambiguating memory dumps from different |
| 780 // resource providers. | 802 // resource providers. |
| 781 int tracing_id_; | 803 int tracing_id_; |
| 782 | 804 |
| 783 #if defined(OS_ANDROID) | 805 #if defined(OS_ANDROID) |
| 784 // Set of resource Ids that would like to be notified about promotion hints. | 806 // Set of resource Ids that would like to be notified about promotion hints. |
| 785 ResourceIdSet wants_promotion_hints_set_; | 807 ResourceIdSet wants_promotion_hints_set_; |
| 786 #endif | 808 #endif |
| 787 | 809 |
| 788 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 810 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 789 }; | 811 }; |
| 790 | 812 |
| 791 } // namespace cc | 813 } // namespace cc |
| 792 | 814 |
| 793 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 815 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |