Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: components/display_compositor/renderer_frame_manager.h

Issue 2811083002: Move frame eviction into components (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_DISPLAY_COMPOSITOR_RENDERER_FRAME_MANAGER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_ 6 #define COMPONENTS_DISPLAY_COMPOSITOR_RENDERER_FRAME_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/display_compositor/display_compositor_export.h"
18 18
19 namespace content { 19 namespace display_compositor {
20 20
21 class RenderWidgetHostViewAuraTest; 21 class DISPLAY_COMPOSITOR_EXPORT RendererFrameManagerClient {
22
23 class CONTENT_EXPORT RendererFrameManagerClient {
24 public: 22 public:
25 virtual ~RendererFrameManagerClient() {} 23 virtual ~RendererFrameManagerClient() {}
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 DISPLAY_COMPOSITOR_EXPORT RendererFrameManager
Saman Sami 2017/04/11 14:58:24 I think this class should have a more general name
xing.xu 2017/04/14 03:01:29 Done.
36 public base::MemoryCoordinatorClient { 34 : public base::MemoryCoordinatorClient {
37 public: 35 public:
38 static RendererFrameManager* GetInstance(); 36 static RendererFrameManager* GetInstance();
39 37
40 void AddFrame(RendererFrameManagerClient*, bool locked); 38 void AddFrame(RendererFrameManagerClient*, bool locked);
41 void RemoveFrame(RendererFrameManagerClient*); 39 void RemoveFrame(RendererFrameManagerClient*);
42 void LockFrame(RendererFrameManagerClient*); 40 void LockFrame(RendererFrameManagerClient*);
43 void UnlockFrame(RendererFrameManagerClient*); 41 void UnlockFrame(RendererFrameManagerClient*);
44 42
45 size_t GetMaxNumberOfSavedFrames() const; 43 size_t GetMaxNumberOfSavedFrames() const;
46 44
47 // For testing only 45 // For testing only
48 void set_max_number_of_saved_frames(size_t max_number_of_saved_frames) { 46 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; 47 max_number_of_saved_frames_ = max_number_of_saved_frames;
50 } 48 }
51 void set_max_handles(float max_handles) { max_handles_ = max_handles; } 49 void set_max_handles(float max_handles) { max_handles_ = max_handles; }
52 50
51 // React on memory pressure events to adjust the number of cached frames.
52 // Please remove when crbug.com/443824 has been fixed.
53 void OnMemoryPressure(
54 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
55
53 private: 56 private:
54 // Please remove when crbug.com/443824 has been fixed.
55 friend class RenderWidgetHostViewAuraTest;
56
57 RendererFrameManager(); 57 RendererFrameManager();
58 ~RendererFrameManager() override; 58 ~RendererFrameManager() override;
59 59
60 // base::MemoryCoordinatorClient implementation: 60 // base::MemoryCoordinatorClient implementation:
61 void OnPurgeMemory() override; 61 void OnPurgeMemory() override;
62 62
63 void CullUnlockedFrames(size_t saved_frame_limit); 63 void CullUnlockedFrames(size_t saved_frame_limit);
64 64
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); 65 void PurgeMemory(int percentage);
70 66
71 friend struct base::DefaultSingletonTraits<RendererFrameManager>; 67 friend struct base::DefaultSingletonTraits<RendererFrameManager>;
72 68
73 // Listens for system under pressure notifications and adjusts number of 69 // Listens for system under pressure notifications and adjusts number of
74 // cached frames accordingly. 70 // cached frames accordingly.
75 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; 71 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
76 72
77 std::map<RendererFrameManagerClient*, size_t> locked_frames_; 73 std::map<RendererFrameManagerClient*, size_t> locked_frames_;
78 std::list<RendererFrameManagerClient*> unlocked_frames_; 74 std::list<RendererFrameManagerClient*> unlocked_frames_;
79 size_t max_number_of_saved_frames_; 75 size_t max_number_of_saved_frames_;
80 float max_handles_; 76 float max_handles_;
81 77
82 DISALLOW_COPY_AND_ASSIGN(RendererFrameManager); 78 DISALLOW_COPY_AND_ASSIGN(RendererFrameManager);
83 }; 79 };
84 80
85 } // namespace content 81 } // namespace display_compositor
86 82
87 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDERER_FRAME_MANAGER_H_ 83 #endif // COMPONENTS_DISPLAY_COMPOSITOR_RENDERER_FRAME_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698