| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_ | 5 #ifndef COMPONENTS_VIZ_FRAME_SINKS_FRAME_EVICTION_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_ | 6 #define COMPONENTS_VIZ_FRAME_SINKS_FRAME_EVICTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/memory_coordinator_client.h" | 14 #include "base/memory/memory_coordinator_client.h" |
| 15 #include "base/memory/memory_pressure_listener.h" | 15 #include "base/memory/memory_pressure_listener.h" |
| 16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 17 #include "content/common/content_export.h" | 17 #include "components/viz/frame_sinks/viz_export.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace viz { |
| 20 | 20 |
| 21 class RenderWidgetHostViewAuraTest; | 21 class VIZ_EXPORT FrameEvictionManagerClient { |
| 22 | |
| 23 class CONTENT_EXPORT RendererFrameManagerClient { | |
| 24 public: | 22 public: |
| 25 virtual ~RendererFrameManagerClient() {} | 23 virtual ~FrameEvictionManagerClient() {} |
| 26 virtual void EvictCurrentFrame() = 0; | 24 virtual void EvictCurrentFrame() = 0; |
| 27 }; | 25 }; |
| 28 | 26 |
| 29 // This class is responsible for globally managing which renderers keep their | 27 // This class is responsible for globally managing which renderers keep their |
| 30 // compositor frame when offscreen. We actively discard compositor frames for | 28 // compositor frame when offscreen. We actively discard compositor frames for |
| 31 // offscreen tabs, but keep a minimum amount, as an LRU cache, to make switching | 29 // offscreen tabs, but keep a minimum amount, as an LRU cache, to make switching |
| 32 // between a small set of tabs faster. The limit is a soft limit, because | 30 // between a small set of tabs faster. The limit is a soft limit, because |
| 33 // clients can lock their frame to prevent it from being discarded, e.g. if the | 31 // clients can lock their frame to prevent it from being discarded, e.g. if the |
| 34 // tab is visible, or while capturing a screenshot. | 32 // tab is visible, or while capturing a screenshot. |
| 35 class CONTENT_EXPORT RendererFrameManager : | 33 class VIZ_EXPORT FrameEvictionManager : public base::MemoryCoordinatorClient { |
| 36 public base::MemoryCoordinatorClient { | |
| 37 public: | 34 public: |
| 38 static RendererFrameManager* GetInstance(); | 35 static FrameEvictionManager* GetInstance(); |
| 39 | 36 |
| 40 void AddFrame(RendererFrameManagerClient*, bool locked); | 37 void AddFrame(FrameEvictionManagerClient*, bool locked); |
| 41 void RemoveFrame(RendererFrameManagerClient*); | 38 void RemoveFrame(FrameEvictionManagerClient*); |
| 42 void LockFrame(RendererFrameManagerClient*); | 39 void LockFrame(FrameEvictionManagerClient*); |
| 43 void UnlockFrame(RendererFrameManagerClient*); | 40 void UnlockFrame(FrameEvictionManagerClient*); |
| 44 | 41 |
| 45 size_t GetMaxNumberOfSavedFrames() const; | 42 size_t GetMaxNumberOfSavedFrames() const; |
| 46 | 43 |
| 47 // For testing only | 44 // For testing only |
| 48 void set_max_number_of_saved_frames(size_t max_number_of_saved_frames) { | 45 void set_max_number_of_saved_frames(size_t max_number_of_saved_frames) { |
| 49 max_number_of_saved_frames_ = max_number_of_saved_frames; | 46 max_number_of_saved_frames_ = max_number_of_saved_frames; |
| 50 } | 47 } |
| 51 void set_max_handles(float max_handles) { max_handles_ = max_handles; } | 48 void set_max_handles(float max_handles) { max_handles_ = max_handles; } |
| 52 | 49 |
| 50 // React on memory pressure events to adjust the number of cached frames. |
| 51 // Please make this private when crbug.com/443824 has been fixed. |
| 52 void OnMemoryPressure( |
| 53 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
| 54 |
| 53 private: | 55 private: |
| 54 // Please remove when crbug.com/443824 has been fixed. | 56 FrameEvictionManager(); |
| 55 friend class RenderWidgetHostViewAuraTest; | 57 ~FrameEvictionManager() override; |
| 56 | |
| 57 RendererFrameManager(); | |
| 58 ~RendererFrameManager() override; | |
| 59 | 58 |
| 60 // base::MemoryCoordinatorClient implementation: | 59 // base::MemoryCoordinatorClient implementation: |
| 61 void OnPurgeMemory() override; | 60 void OnPurgeMemory() override; |
| 62 | 61 |
| 63 void CullUnlockedFrames(size_t saved_frame_limit); | 62 void CullUnlockedFrames(size_t saved_frame_limit); |
| 64 | 63 |
| 65 // React on memory pressure events to adjust the number of cached frames. | |
| 66 void OnMemoryPressure( | |
| 67 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); | |
| 68 | |
| 69 void PurgeMemory(int percentage); | 64 void PurgeMemory(int percentage); |
| 70 | 65 |
| 71 friend struct base::DefaultSingletonTraits<RendererFrameManager>; | 66 friend struct base::DefaultSingletonTraits<FrameEvictionManager>; |
| 72 | 67 |
| 73 // Listens for system under pressure notifications and adjusts number of | 68 // Listens for system under pressure notifications and adjusts number of |
| 74 // cached frames accordingly. | 69 // cached frames accordingly. |
| 75 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 70 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| 76 | 71 |
| 77 std::map<RendererFrameManagerClient*, size_t> locked_frames_; | 72 std::map<FrameEvictionManagerClient*, size_t> locked_frames_; |
| 78 std::list<RendererFrameManagerClient*> unlocked_frames_; | 73 std::list<FrameEvictionManagerClient*> unlocked_frames_; |
| 79 size_t max_number_of_saved_frames_; | 74 size_t max_number_of_saved_frames_; |
| 80 float max_handles_; | 75 float max_handles_; |
| 81 | 76 |
| 82 DISALLOW_COPY_AND_ASSIGN(RendererFrameManager); | 77 DISALLOW_COPY_AND_ASSIGN(FrameEvictionManager); |
| 83 }; | 78 }; |
| 84 | 79 |
| 85 } // namespace content | 80 } // namespace viz |
| 86 | 81 |
| 87 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_ | 82 #endif // COMPONENTS_VIZ_FRAME_SINKS_FRAME_EVICTION_MANAGER_H_ |
| OLD | NEW |