OLD | NEW |
---|---|
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 #include <vector> | |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
12 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
13 #include "ui/gfx/native_widget_types.h" | 15 #include "ui/gfx/native_widget_types.h" |
14 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
15 | 17 |
18 class GpuSurfaceReader; | |
19 | |
16 // This class is responsible for managing rendering surfaces exposed to the | 20 // This class is responsible for managing rendering surfaces exposed to the |
17 // GPU process. Every surface gets registered to this class, and gets an ID. | 21 // GPU process. Every surface gets registered to this class, and gets an ID. |
18 // All calls to and from the GPU process, with the exception of | 22 // All calls to and from the GPU process, with the exception of |
19 // CreateViewCommandBuffer, refer to the rendering surface by its ID. | 23 // CreateViewCommandBuffer, refer to the rendering surface by its ID. |
20 // This class is thread safe. | 24 // This class is thread safe. |
21 // | 25 // |
22 // Note: The ID can exist before the actual native handle for the surface is | 26 // Note: The ID can exist before the actual native handle for the surface is |
23 // created, for example to allow giving a reference to it to a renderer, so that | 27 // created, for example to allow giving a reference to it to a renderer, so that |
24 // it is unamibiguously identified. | 28 // it is unamibiguously identified. |
25 class GpuSurfaceTracker { | 29 class GpuSurfaceTracker { |
26 public: | 30 public: |
31 struct SurfaceInfo { | |
apatrick_chromium
2012/03/07 20:39:37
If it weren't for GpuSurfaceReader, this could rem
mazda
2012/03/08 13:14:28
Done.
| |
32 int renderer_id; | |
33 int render_widget_id; | |
34 gfx::AcceleratedWidget native_widget; | |
35 gfx::GLSurfaceHandle handle; | |
36 }; | |
37 | |
27 // Gets the global instance of the surface tracker. | 38 // Gets the global instance of the surface tracker. |
28 static GpuSurfaceTracker* Get() { return GetInstance(); } | 39 static GpuSurfaceTracker* Get() { return GetInstance(); } |
29 | 40 |
30 // Adds a surface for a given RenderWidgetHost. |renderer_id| is the renderer | 41 // Adds a surface for a given RenderWidgetHost. |renderer_id| is the renderer |
31 // process ID, |render_widget_id| is the RenderWidgetHost route id within that | 42 // process ID, |render_widget_id| is the RenderWidgetHost route id within that |
32 // renderer. Returns the surface ID. | 43 // renderer. Returns the surface ID. |
33 int AddSurfaceForRenderer(int renderer_id, int render_widget_id); | 44 int AddSurfaceForRenderer(int renderer_id, int render_widget_id); |
34 | 45 |
35 // Looks up a surface for a given RenderWidgetHost. Returns the surface | 46 // Looks up a surface for a given RenderWidgetHost. Returns the surface |
36 // ID, or 0 if not found. | 47 // ID, or 0 if not found. |
(...skipping 14 matching lines...) Expand all Loading... | |
51 int* render_widget_id); | 62 int* render_widget_id); |
52 | 63 |
53 // Sets the native handle for the given surface. | 64 // Sets the native handle for the given surface. |
54 // Note: This is an O(log N) lookup. | 65 // Note: This is an O(log N) lookup. |
55 void SetSurfaceHandle(int surface_id, const gfx::GLSurfaceHandle& handle); | 66 void SetSurfaceHandle(int surface_id, const gfx::GLSurfaceHandle& handle); |
56 | 67 |
57 // Gets the native handle for the given surface. | 68 // Gets the native handle for the given surface. |
58 // Note: This is an O(log N) lookup. | 69 // Note: This is an O(log N) lookup. |
59 gfx::GLSurfaceHandle GetSurfaceHandle(int surface_id); | 70 gfx::GLSurfaceHandle GetSurfaceHandle(int surface_id); |
60 | 71 |
72 // Copies the image data of the the given surface to |out|. The image data | |
73 // is transformed so that it fits in |size|. | |
74 bool CopySurface(int surface_id, | |
75 const gfx::Size& size, | |
76 std::vector<unsigned char>* out); | |
77 | |
61 #if defined(OS_WIN) && !defined(USE_AURA) | 78 #if defined(OS_WIN) && !defined(USE_AURA) |
62 // This is a member of GpuSurfaceTracker because it holds the lock for its | 79 // This is a member of GpuSurfaceTracker because it holds the lock for its |
63 // duration. This prevents the AcceleratedSurface that it posts to from being | 80 // duration. This prevents the AcceleratedSurface that it posts to from being |
64 // destroyed by the main thread during that time. This function is only called | 81 // destroyed by the main thread during that time. This function is only called |
65 // on the IO thread. This function only posts tasks asynchronously. If it | 82 // on the IO thread. This function only posts tasks asynchronously. If it |
66 // were to synchronously call the UI thread, there would be a possiblity of | 83 // were to synchronously call the UI thread, there would be a possiblity of |
67 // deadlock. | 84 // deadlock. |
68 void AsyncPresentAndAcknowledge(int surface_id, | 85 void AsyncPresentAndAcknowledge(int surface_id, |
69 const gfx::Size& size, | 86 const gfx::Size& size, |
70 int64 surface_handle, | 87 int64 surface_handle, |
71 const base::Closure& completion_task); | 88 const base::Closure& completion_task); |
72 #endif | 89 #endif |
73 | 90 |
74 // Gets the global instance of the surface tracker. Identical to Get(), but | 91 // Gets the global instance of the surface tracker. Identical to Get(), but |
75 // named that way for the implementation of Singleton. | 92 // named that way for the implementation of Singleton. |
76 static GpuSurfaceTracker* GetInstance(); | 93 static GpuSurfaceTracker* GetInstance(); |
77 | 94 |
78 private: | 95 private: |
79 struct SurfaceInfo { | |
80 int renderer_id; | |
81 int render_widget_id; | |
82 gfx::AcceleratedWidget native_widget; | |
83 gfx::GLSurfaceHandle handle; | |
84 }; | |
85 typedef std::map<int, SurfaceInfo> SurfaceMap; | 96 typedef std::map<int, SurfaceInfo> SurfaceMap; |
86 | 97 |
87 friend struct DefaultSingletonTraits<GpuSurfaceTracker>; | 98 friend struct DefaultSingletonTraits<GpuSurfaceTracker>; |
88 | 99 |
89 GpuSurfaceTracker(); | 100 GpuSurfaceTracker(); |
90 ~GpuSurfaceTracker(); | 101 ~GpuSurfaceTracker(); |
91 | 102 |
92 base::Lock lock_; | 103 base::Lock lock_; |
93 SurfaceMap surface_map_; | 104 SurfaceMap surface_map_; |
94 int next_surface_id_; | 105 int next_surface_id_; |
106 scoped_ptr<GpuSurfaceReader> reader_; | |
95 | 107 |
96 DISALLOW_COPY_AND_ASSIGN(GpuSurfaceTracker); | 108 DISALLOW_COPY_AND_ASSIGN(GpuSurfaceTracker); |
97 }; | 109 }; |
98 | 110 |
99 #endif // CONTENT_BROWSER_GPU_GPU_SURFACE_TRACKER_H_ | 111 #endif // CONTENT_BROWSER_GPU_GPU_SURFACE_TRACKER_H_ |
OLD | NEW |