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

Side by Side Diff: gpu/command_buffer/service/gpu_scheduler.h

Issue 7395020: Create new GLSurface for cross process image transport. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "" Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/shared_memory.h" 15 #include "base/shared_memory.h"
16 #include "base/task.h" 16 #include "base/task.h"
17 #include "gpu/command_buffer/common/command_buffer.h" 17 #include "gpu/command_buffer/common/command_buffer.h"
18 #include "gpu/command_buffer/service/cmd_buffer_engine.h" 18 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
19 #include "gpu/command_buffer/service/cmd_parser.h" 19 #include "gpu/command_buffer/service/cmd_parser.h"
20 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 20 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
21 #include "ui/gfx/native_widget_types.h" 21 #include "ui/gfx/native_widget_types.h"
22 #include "ui/gfx/size.h" 22 #include "ui/gfx/size.h"
23 #include "ui/gfx/surface/transport_dib.h" 23 #include "ui/gfx/surface/transport_dib.h"
24 24
25 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
26 #include "ui/gfx/surface/accelerated_surface_mac.h" 26 #include "ui/gfx/surface/accelerated_surface_mac.h"
27 #elif defined(TOUCH_UI)
28 #include "ui/gfx/surface/accelerated_surface_linux.h"
29 #endif 27 #endif
30 28
31 namespace gfx { 29 namespace gfx {
32 class GLContext; 30 class GLContext;
33 class GLShareGroup; 31 class GLShareGroup;
34 class GLSurface; 32 class GLSurface;
35 } 33 }
36 34
37 namespace gpu { 35 namespace gpu {
38 namespace gles2 { 36 namespace gles2 {
(...skipping 14 matching lines...) Expand all
53 gles2::ContextGroup* group); 51 gles2::ContextGroup* group);
54 52
55 // This constructor is for unit tests. 53 // This constructor is for unit tests.
56 GpuScheduler(CommandBuffer* command_buffer, 54 GpuScheduler(CommandBuffer* command_buffer,
57 gles2::GLES2Decoder* decoder, 55 gles2::GLES2Decoder* decoder,
58 CommandParser* parser, 56 CommandParser* parser,
59 int commands_per_update); 57 int commands_per_update);
60 58
61 virtual ~GpuScheduler(); 59 virtual ~GpuScheduler();
62 60
63 // Perform platform specific and common initialization. 61 // Platform specific code to create GLContexts and GLSurfaces that are
62 // handed off to the next function.
64 bool Initialize(gfx::PluginWindowHandle hwnd, 63 bool Initialize(gfx::PluginWindowHandle hwnd,
65 const gfx::Size& size, 64 const gfx::Size& size,
66 const gles2::DisallowedExtensions& disallowed_extensions, 65 const gles2::DisallowedExtensions& disallowed_extensions,
67 const char* allowed_extensions, 66 const char* allowed_extensions,
68 const std::vector<int32>& attribs, 67 const std::vector<int32>& attribs,
69 gfx::GLShareGroup* share_group); 68 gfx::GLShareGroup* share_group);
70 69
70 // Takes ownership of GLSurface and GLContext.
71 bool InitializeCommon(
72 const scoped_refptr<gfx::GLSurface>& surface,
73 const scoped_refptr<gfx::GLContext>& context,
74 const gfx::Size& size,
75 const gles2::DisallowedExtensions& disallowed_extensions,
76 const char* allowed_extensions,
77 const std::vector<int32>& attribs);
78
71 void Destroy(); 79 void Destroy();
72 void DestroyCommon(); 80 void DestroyCommon();
73 81
74 bool SetParent(GpuScheduler* parent_scheduler, uint32 parent_texture_id); 82 bool SetParent(GpuScheduler* parent_scheduler, uint32 parent_texture_id);
75 83
76 void PutChanged(bool sync); 84 void PutChanged(bool sync);
77 85
78 // Sets whether commands should be processed by this scheduler. Setting to 86 // Sets whether commands should be processed by this scheduler. Setting to
79 // false unschedules. Setting to true reschedules. Whether or not the 87 // false unschedules. Setting to true reschedules. Whether or not the
80 // scheduler is currently scheduled is "reference counted". Every call with 88 // scheduler is currently scheduled is "reference counted". Every call with
81 // false must eventually be paired by a call with true. 89 // false must eventually be paired by a call with true.
82 void SetScheduled(bool is_scheduled); 90 void SetScheduled(bool is_scheduled);
83 91
84 // Returns whether the scheduler is currently scheduled to process commands. 92 // Returns whether the scheduler is currently scheduled to process commands.
85 bool IsScheduled(); 93 bool IsScheduled();
86 94
87 // Sets a callback that is invoked just before scheduler is rescheduled. 95 // Sets a callback that is invoked just before scheduler is rescheduled.
88 // Takes ownership of callback object. 96 // Takes ownership of callback object.
89 void SetScheduledCallback(Callback0::Type* scheduled_callback); 97 void SetScheduledCallback(Callback0::Type* scheduled_callback);
90 98
91 // Implementation of CommandBufferEngine. 99 // Implementation of CommandBufferEngine.
92 virtual Buffer GetSharedMemoryBuffer(int32 shm_id); 100 virtual Buffer GetSharedMemoryBuffer(int32 shm_id);
93 virtual void set_token(int32 token); 101 virtual void set_token(int32 token);
94 virtual bool SetGetOffset(int32 offset); 102 virtual bool SetGetOffset(int32 offset);
95 virtual int32 GetGetOffset(); 103 virtual int32 GetGetOffset();
96 104
97 // Asynchronously resizes an offscreen frame buffer. 105 // Asynchronously resizes an offscreen frame buffer.
98 void ResizeOffscreenFrameBuffer(const gfx::Size& size); 106 void ResizeOffscreenFrameBuffer(const gfx::Size& size);
99 107
100 #if defined(OS_MACOSX) || defined(TOUCH_UI) 108 #if defined(OS_MACOSX)
101 // To prevent the GPU process from overloading the browser process, 109 // To prevent the GPU process from overloading the browser process,
102 // we need to track the number of swap buffers calls issued and 110 // we need to track the number of swap buffers calls issued and
103 // acknowledged per on-screen context, and keep the GPU from getting 111 // acknowledged per on-screen context, and keep the GPU from getting
104 // too far ahead of the browser. Note that this 112 // too far ahead of the browser. Note that this
105 // is also predicated on a flow control mechanism between the 113 // is also predicated on a flow control mechanism between the
106 // renderer and GPU processes. 114 // renderer and GPU processes.
107 uint64 swap_buffers_count() const; 115 uint64 swap_buffers_count() const;
108 uint64 acknowledged_swap_buffers_count() const; 116 uint64 acknowledged_swap_buffers_count() const;
109 void set_acknowledged_swap_buffers_count( 117 void set_acknowledged_swap_buffers_count(
110 uint64 acknowledged_swap_buffers_count); 118 uint64 acknowledged_swap_buffers_count);
111 #endif
112 119
113 #if defined(OS_MACOSX)
114 // Needed only on Mac OS X, which does not render into an on-screen 120 // Needed only on Mac OS X, which does not render into an on-screen
115 // window and therefore requires the backing store to be resized 121 // window and therefore requires the backing store to be resized
116 // manually. Returns an opaque identifier for the new backing store. 122 // manually. Returns an opaque identifier for the new backing store.
117 // There are two versions of this method: one for use with the IOSurface 123 // There are two versions of this method: one for use with the IOSurface
118 // available in Mac OS X 10.6; and, one for use with the 124 // available in Mac OS X 10.6; and, one for use with the
119 // TransportDIB-based version used on Mac OS X 10.5. 125 // TransportDIB-based version used on Mac OS X 10.5.
120 virtual uint64 SetWindowSizeForIOSurface(const gfx::Size& size); 126 virtual uint64 SetWindowSizeForIOSurface(const gfx::Size& size);
121 virtual TransportDIB::Handle SetWindowSizeForTransportDIB( 127 virtual TransportDIB::Handle SetWindowSizeForTransportDIB(
122 const gfx::Size& size); 128 const gfx::Size& size);
123 virtual void SetTransportDIBAllocAndFree( 129 virtual void SetTransportDIBAllocAndFree(
124 Callback2<size_t, TransportDIB::Handle*>::Type* allocator, 130 Callback2<size_t, TransportDIB::Handle*>::Type* allocator,
125 Callback1<TransportDIB::Id>::Type* deallocator); 131 Callback1<TransportDIB::Id>::Type* deallocator);
126 // Returns the id of the current surface that is being rendered to 132 // Returns the id of the current surface that is being rendered to
127 // (or 0 if no such surface has been created). 133 // (or 0 if no such surface has been created).
128 virtual uint64 GetSurfaceId(); 134 virtual uint64 GetSurfaceId();
129 135
130 void DidDestroySurface(); 136 void DidDestroySurface();
131 #endif 137 #endif
132 138
133 #if defined(TOUCH_UI)
134 virtual void CreateBackSurface(const gfx::Size& size);
135 // Should not be back_surface_ or front_surface_.
136 virtual void ReleaseSurface(uint64 surface_id);
137
138 // Returns the id of the surface (or 0 if no such surface has been created).
139 virtual uint64 GetBackSurfaceId();
140 virtual uint64 GetFrontSurfaceId();
141 #endif
142
143 // Sets a callback that is called when a glResizeCHROMIUM command 139 // Sets a callback that is called when a glResizeCHROMIUM command
144 // is processed. 140 // is processed.
145 void SetResizeCallback(Callback1<gfx::Size>::Type* callback); 141 void SetResizeCallback(Callback1<gfx::Size>::Type* callback);
146 142
147 // Sets a callback which is called when a SwapBuffers command is processed. 143 // Sets a callback which is called when a SwapBuffers command is processed.
148 // Must be called after Initialize(). 144 // Must be called after Initialize().
149 // It is not defined on which thread this callback is called. 145 // It is not defined on which thread this callback is called.
150 void SetSwapBuffersCallback(Callback0::Type* callback); 146 void SetSwapBuffersCallback(Callback0::Type* callback);
151 147
152 void SetCommandProcessedCallback(Callback0::Type* callback); 148 void SetCommandProcessedCallback(Callback0::Type* callback);
153 149
154 // Sets a callback which is called after a Set/WaitLatch command is processed. 150 // Sets a callback which is called after a Set/WaitLatch command is processed.
155 // The bool parameter will be true for SetLatch, and false for a WaitLatch 151 // The bool parameter will be true for SetLatch, and false for a WaitLatch
156 // that is blocked. An unblocked WaitLatch will not trigger a callback. 152 // that is blocked. An unblocked WaitLatch will not trigger a callback.
157 void SetLatchCallback(const base::Callback<void(bool)>& callback) { 153 void SetLatchCallback(const base::Callback<void(bool)>& callback) {
158 decoder_->SetLatchCallback(callback); 154 decoder_->SetLatchCallback(callback);
159 } 155 }
160 156
161 // Sets a callback which is called when set_token() is called, and passes the 157 // Sets a callback which is called when set_token() is called, and passes the
162 // just-set token to the callback. DCHECKs that no callback has previously 158 // just-set token to the callback. DCHECKs that no callback has previously
163 // been registered for this notification. 159 // been registered for this notification.
164 void SetTokenCallback(const base::Callback<void(int32)>& callback); 160 void SetTokenCallback(const base::Callback<void(int32)>& callback);
165 161
166 // Get the GLES2Decoder associated with this scheduler. 162 // Get the GLES2Decoder associated with this scheduler.
167 gles2::GLES2Decoder* decoder() const { return decoder_.get(); } 163 gles2::GLES2Decoder* decoder() const { return decoder_.get(); }
168 164
169 protected:
170 // Perform common initialization. Takes ownership of GLSurface and GLContext.
171 bool InitializeCommon(
172 const scoped_refptr<gfx::GLSurface>& surface,
173 const scoped_refptr<gfx::GLContext>& context,
174 const gfx::Size& size,
175 const gles2::DisallowedExtensions& disallowed_extensions,
176 const char* allowed_extensions,
177 const std::vector<int32>& attribs);
178
179
180 private: 165 private:
181 // Helper which causes a call to ProcessCommands to be scheduled later. 166 // Helper which causes a call to ProcessCommands to be scheduled later.
182 void ScheduleProcessCommands(); 167 void ScheduleProcessCommands();
183 168
184 // Called via a callback just before we are supposed to call the 169 // Called via a callback just before we are supposed to call the
185 // user's resize callback.
186 void WillResize(gfx::Size size);
187
188 // Called via a callback just before we are supposed to call the
189 // user's swap buffers callback. 170 // user's swap buffers callback.
190 void WillSwapBuffers(); 171 void WillSwapBuffers();
191 void ProcessCommands(); 172 void ProcessCommands();
192 173
193 // The GpuScheduler holds a weak reference to the CommandBuffer. The 174 // The GpuScheduler holds a weak reference to the CommandBuffer. The
194 // CommandBuffer owns the GpuScheduler and holds a strong reference to it 175 // CommandBuffer owns the GpuScheduler and holds a strong reference to it
195 // through the ProcessCommands callback. 176 // through the ProcessCommands callback.
196 CommandBuffer* command_buffer_; 177 CommandBuffer* command_buffer_;
197 178
198 int commands_per_update_; 179 int commands_per_update_;
199 180
200 scoped_ptr<gles2::GLES2Decoder> decoder_; 181 scoped_ptr<gles2::GLES2Decoder> decoder_;
201 scoped_ptr<CommandParser> parser_; 182 scoped_ptr<CommandParser> parser_;
202 183
203 // Greater than zero if this is waiting to be rescheduled before continuing. 184 // Greater than zero if this is waiting to be rescheduled before continuing.
204 int unscheduled_count_; 185 int unscheduled_count_;
205 186
206 scoped_ptr<Callback0::Type> scheduled_callback_; 187 scoped_ptr<Callback0::Type> scheduled_callback_;
207 188
208 #if defined(OS_MACOSX) || defined(TOUCH_UI) 189 #if defined(OS_MACOSX)
209 uint64 swap_buffers_count_; 190 uint64 swap_buffers_count_;
210 uint64 acknowledged_swap_buffers_count_; 191 uint64 acknowledged_swap_buffers_count_;
211 #endif
212
213 #if defined(OS_MACOSX)
214 scoped_ptr<AcceleratedSurface> surface_; 192 scoped_ptr<AcceleratedSurface> surface_;
215 #elif defined(TOUCH_UI)
216 std::map<uint64, scoped_refptr<AcceleratedSurface> >
217 surfaces_;
218 scoped_refptr<AcceleratedSurface> back_surface_;
219 scoped_refptr<AcceleratedSurface> front_surface_;
220 #endif 193 #endif
221 194
222 ScopedRunnableMethodFactory<GpuScheduler> method_factory_; 195 ScopedRunnableMethodFactory<GpuScheduler> method_factory_;
223 scoped_ptr<Callback1<gfx::Size>::Type> wrapped_resize_callback_;
224 scoped_ptr<Callback0::Type> wrapped_swap_buffers_callback_; 196 scoped_ptr<Callback0::Type> wrapped_swap_buffers_callback_;
225 scoped_ptr<Callback0::Type> command_processed_callback_; 197 scoped_ptr<Callback0::Type> command_processed_callback_;
226 base::Callback<void(int32)> set_token_callback_; 198 base::Callback<void(int32)> set_token_callback_;
227 }; 199 };
228 200
229 } // namespace gpu 201 } // namespace gpu
230 202
231 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ 203 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698