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

Side by Side Diff: content/browser/gpu/gpu_surface_tracker.h

Issue 1365563002: Make channel preemption not require view contexts for hookup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wakeup_gpu
Patch Set: rebase Created 5 years, 3 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
« no previous file with comments | « content/browser/gpu/gpu_process_host.cc ('k') | content/browser/gpu/gpu_surface_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 CONTENT_BROWSER_GPU_GPU_SURFACE_TRACKER_H_ 5 #ifndef CONTENT_BROWSER_GPU_GPU_SURFACE_TRACKER_H_
6 #define CONTENT_BROWSER_GPU_GPU_SURFACE_TRACKER_H_ 6 #define CONTENT_BROWSER_GPU_GPU_SURFACE_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 11 matching lines...) Expand all
22 // GPU process. Every surface gets registered to this class, and gets an ID. 22 // GPU process. Every surface gets registered to this class, and gets an ID.
23 // All calls to and from the GPU process, with the exception of 23 // All calls to and from the GPU process, with the exception of
24 // CreateViewCommandBuffer, refer to the rendering surface by its ID. 24 // CreateViewCommandBuffer, refer to the rendering surface by its ID.
25 // This class is thread safe. 25 // This class is thread safe.
26 // 26 //
27 // Note: The ID can exist before the actual native handle for the surface is 27 // Note: The ID can exist before the actual native handle for the surface is
28 // created, for example to allow giving a reference to it to a renderer, so that 28 // created, for example to allow giving a reference to it to a renderer, so that
29 // it is unamibiguously identified. 29 // it is unamibiguously identified.
30 class CONTENT_EXPORT GpuSurfaceTracker : public GpuSurfaceLookup { 30 class CONTENT_EXPORT GpuSurfaceTracker : public GpuSurfaceLookup {
31 public: 31 public:
32 // Base class for reference counting surfaces. We store a
33 // reference to an instance of this class in the surface_map_
34 // and GpuProcessHost (if the GPU process is drawing to
35 // the surface with a Command Buffer). The reference count ensures that
36 // we don't destroy the object until it's released from both places.
37 //
38 // This is especially important on Android and GTK where the surface must
39 // not be destroyed when the WebContents is closed if the GPU is still
40 // drawing to it. Those platforms extend this class with the functionality
41 // they need to implement on tear down (see SurfaceRefPluginWindow for GTK and
42 // SurfaceRefAndroid for Android).
43 class SurfaceRef : public base::RefCountedThreadSafe<SurfaceRef> {
44 protected:
45 SurfaceRef() { }
46 virtual ~SurfaceRef() { }
47
48 private:
49 friend class base::RefCountedThreadSafe<SurfaceRef>;
50 DISALLOW_COPY_AND_ASSIGN(SurfaceRef);
51 };
52
53 // GpuSurfaceLookup implementation: 32 // GpuSurfaceLookup implementation:
54 // Returns the native widget associated with a given surface_id. 33 // Returns the native widget associated with a given surface_id.
55 gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override; 34 gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override;
56 35
57 // Gets the global instance of the surface tracker. 36 // Gets the global instance of the surface tracker.
58 static GpuSurfaceTracker* Get() { return GetInstance(); } 37 static GpuSurfaceTracker* Get() { return GetInstance(); }
59 38
60 // Adds a surface for a given RenderWidgetHost. |renderer_id| is the renderer 39 // Adds a surface for a given RenderWidgetHost. |renderer_id| is the renderer
61 // process ID, |render_widget_id| is the RenderWidgetHost route id within that 40 // process ID, |render_widget_id| is the RenderWidgetHost route id within that
62 // renderer. Returns the surface ID. 41 // renderer. Returns the surface ID.
63 int AddSurfaceForRenderer(int renderer_id, int render_widget_id); 42 int AddSurfaceForRenderer(int renderer_id, int render_widget_id);
64 43
65 // Looks up a surface for a given RenderWidgetHost. Returns the surface 44 // Looks up a surface for a given RenderWidgetHost. Returns the surface
66 // ID, or 0 if not found. 45 // ID, or 0 if not found.
67 // Note: This is an O(N) lookup. 46 // Note: This is an O(N) lookup.
68 int LookupSurfaceForRenderer(int renderer_id, int render_widget_id); 47 int LookupSurfaceForRenderer(int renderer_id, int render_widget_id);
69 48
70 // Adds a surface for a native widget. Returns the surface ID. 49 // Adds a surface for a native widget. Returns the surface ID.
71 int AddSurfaceForNativeWidget(gfx::AcceleratedWidget widget); 50 int AddSurfaceForNativeWidget(gfx::AcceleratedWidget widget);
72 51
73 // Removes a given existing surface. 52 // Removes a given existing surface.
74 void RemoveSurface(int surface_id); 53 void RemoveSurface(int surface_id);
75 54
76 // Gets the renderer process ID and RenderWidgetHost route id for a given
77 // surface, returning true if the surface is found (and corresponds to a
78 // RenderWidgetHost), or false if not.
79 bool GetRenderWidgetIDForSurface(int surface_id,
80 int* renderer_id,
81 int* render_widget_id);
82
83 // Sets the native handle for the given surface. 55 // Sets the native handle for the given surface.
84 // Note: This is an O(log N) lookup. 56 // Note: This is an O(log N) lookup.
85 void SetSurfaceHandle(int surface_id, const gfx::GLSurfaceHandle& handle); 57 void SetSurfaceHandle(int surface_id, const gfx::GLSurfaceHandle& handle);
86 58
87 // Sets the native widget associated with the surface_id.
88 void SetNativeWidget(
89 int surface_id,
90 gfx::AcceleratedWidget widget,
91 SurfaceRef* surface_ref);
92
93 // Gets the native handle for the given surface. 59 // Gets the native handle for the given surface.
94 // Note: This is an O(log N) lookup. 60 // Note: This is an O(log N) lookup.
95 gfx::GLSurfaceHandle GetSurfaceHandle(int surface_id); 61 gfx::GLSurfaceHandle GetSurfaceHandle(int surface_id);
96 62
97 // Returns the number of surfaces currently registered with the tracker. 63 // Returns the number of surfaces currently registered with the tracker.
98 std::size_t GetSurfaceCount(); 64 std::size_t GetSurfaceCount();
99 65
100 // Gets the global instance of the surface tracker. Identical to Get(), but 66 // Gets the global instance of the surface tracker. Identical to Get(), but
101 // named that way for the implementation of Singleton. 67 // named that way for the implementation of Singleton.
102 static GpuSurfaceTracker* GetInstance(); 68 static GpuSurfaceTracker* GetInstance();
103 69
104 scoped_refptr<SurfaceRef> GetSurfaceRefForSurface(int surface_id) {
105 return surface_map_[surface_id].surface_ref;
106 }
107
108 private: 70 private:
109 struct SurfaceInfo { 71 struct SurfaceInfo {
110 SurfaceInfo(); 72 SurfaceInfo();
111 SurfaceInfo(int renderer_id, 73 SurfaceInfo(int renderer_id,
112 int render_widget_id, 74 int render_widget_id,
113 const gfx::AcceleratedWidget& native_widget, 75 const gfx::AcceleratedWidget& native_widget,
114 const gfx::GLSurfaceHandle& handle, 76 const gfx::GLSurfaceHandle& handle);
115 const scoped_refptr<SurfaceRef>& surface_ref);
116 ~SurfaceInfo(); 77 ~SurfaceInfo();
117 int renderer_id; 78 int renderer_id;
118 int render_widget_id; 79 int render_widget_id;
119 gfx::AcceleratedWidget native_widget; 80 gfx::AcceleratedWidget native_widget;
120 gfx::GLSurfaceHandle handle; 81 gfx::GLSurfaceHandle handle;
121 scoped_refptr<SurfaceRef> surface_ref;
122 }; 82 };
123 typedef std::map<int, SurfaceInfo> SurfaceMap; 83 typedef std::map<int, SurfaceInfo> SurfaceMap;
124 84
125 friend struct base::DefaultSingletonTraits<GpuSurfaceTracker>; 85 friend struct base::DefaultSingletonTraits<GpuSurfaceTracker>;
126 86
127 GpuSurfaceTracker(); 87 GpuSurfaceTracker();
128 ~GpuSurfaceTracker() override; 88 ~GpuSurfaceTracker() override;
129 89
130 base::Lock lock_; 90 base::Lock lock_;
131 SurfaceMap surface_map_; 91 SurfaceMap surface_map_;
132 int next_surface_id_; 92 int next_surface_id_;
133 93
134 DISALLOW_COPY_AND_ASSIGN(GpuSurfaceTracker); 94 DISALLOW_COPY_AND_ASSIGN(GpuSurfaceTracker);
135 }; 95 };
136 96
137 } // namespace content 97 } // namespace content
138 98
139 #endif // CONTENT_BROWSER_GPU_GPU_SURFACE_TRACKER_H_ 99 #endif // CONTENT_BROWSER_GPU_GPU_SURFACE_TRACKER_H_
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_process_host.cc ('k') | content/browser/gpu/gpu_surface_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698