OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | |
6 #define GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/synchronization/lock.h" | |
13 #include "base/synchronization/waitable_event.h" | |
14 #include "gpu/command_buffer/common/command_buffer.h" | |
15 #include "gpu/gpu_export.h" | |
16 #include "ui/gfx/native_widget_types.h" | |
17 #include "ui/gl/gpu_preference.h" | |
18 | |
19 namespace gfx { | |
20 class GLContext; | |
21 class GLImage; | |
22 class GLSurface; | |
23 class Size; | |
24 } | |
25 | |
26 namespace gpu { | |
27 | |
28 namespace gles2 { | |
29 class GLES2Decoder; | |
30 } | |
31 | |
32 class GpuScheduler; | |
33 class TransferBufferManagerInterface; | |
34 | |
35 // This class provides a thread-safe interface to the global GPU service (for | |
36 // example GPU thread) when being run in single process mode. | |
37 // However, the behavior for accessing one context (i.e. one instance of this | |
38 // class) from different client threads is undefined. | |
39 class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer { | |
40 public: | |
41 InProcessCommandBuffer(); | |
42 virtual ~InProcessCommandBuffer(); | |
43 | |
44 // Used to override the GPU thread with explicit scheduling. | |
45 // (By default an internal GPU thread will be spawned to handle all GL work | |
46 // and the two functions are unused.) | |
47 // The callback will be called from different client threads. After the | |
48 // callback is issued, the client is expected to eventually call | |
49 // ProcessGpuWorkOnCurrentThread(). The latter cannot be called from different | |
50 // threads. | |
piman
2013/07/30 03:51:44
note: worth documenting that this needs to be set
no sievers
2013/07/31 18:19:28
Done.
| |
51 static void SetScheduleCallback(const base::Closure& callback); | |
52 static void ProcessGpuWorkOnCurrentThread(); | |
53 | |
54 static void EnableVirtualizedContext(); | |
55 | |
56 bool Initialize(bool is_offscreen, | |
57 bool share_resources, | |
58 gfx::AcceleratedWidget window, | |
59 const gfx::Size& size, | |
60 const char* allowed_extensions, | |
61 const std::vector<int32>& attribs, | |
62 gfx::GpuPreference gpu_preference, | |
63 const base::Closure& context_lost_callback, | |
64 unsigned int share_group_id); | |
65 void Destroy(); | |
66 void SignalSyncPoint(unsigned sync_point, | |
67 const base::Closure& callback); | |
68 unsigned int CreateImageForGpuMemoryBuffer( | |
69 gfx::GpuMemoryBufferHandle buffer, | |
70 gfx::Size size); | |
71 void RemoveImage(unsigned int image_id); | |
72 | |
73 // CommandBuffer implementation: | |
74 virtual bool Initialize() OVERRIDE; | |
75 virtual State GetState() OVERRIDE; | |
76 virtual State GetLastState() OVERRIDE; | |
77 virtual int32 GetLastToken() OVERRIDE; | |
78 virtual void Flush(int32 put_offset) OVERRIDE; | |
79 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; | |
80 virtual void SetGetBuffer(int32 shm_id) OVERRIDE; | |
81 virtual void SetGetOffset(int32 get_offset) OVERRIDE; | |
82 virtual gpu::Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; | |
83 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; | |
84 virtual gpu::Buffer GetTransferBuffer(int32 id) OVERRIDE; | |
85 virtual void SetToken(int32 token) OVERRIDE; | |
86 virtual void SetParseError(gpu::error::Error error) OVERRIDE; | |
87 virtual void SetContextLostReason( | |
88 gpu::error::ContextLostReason reason) OVERRIDE; | |
89 virtual uint32 InsertSyncPoint() OVERRIDE; | |
90 virtual gpu::error::Error GetLastError() OVERRIDE; | |
91 | |
92 private: | |
93 bool InitializeOnGpuThread(bool is_offscreen, | |
94 gfx::AcceleratedWidget window, | |
95 const gfx::Size& size, | |
96 const char* allowed_extensions, | |
97 const std::vector<int32>& attribs, | |
98 gfx::GpuPreference gpu_preference); | |
99 bool DestroyOnGpuThread(); | |
100 void FlushOnGpuThread(int32 put_offset); | |
101 void CreateImageOnGpuThread(gfx::GpuMemoryBufferHandle buffer, | |
102 gfx::Size size, | |
103 unsigned int image_id); | |
104 void RemoveImageOnGpuThread(unsigned int image_id); | |
105 bool MakeCurrent(); | |
106 bool IsContextLost(); | |
107 base::Closure WrapCallback(const base::Closure& callback); | |
108 State GetStateFast(); | |
109 | |
110 // Callbacks: | |
111 void OnContextLost(); | |
112 void OnResizeView(gfx::Size size, float scale_factor); | |
113 bool GetBufferChanged(int32 transfer_buffer_id); | |
114 void PumpCommands(); | |
115 | |
116 // Members accessed on the gpu thread (possibly with the exception of | |
117 // creation): | |
118 bool context_lost_; | |
119 bool share_resources_; | |
120 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | |
121 scoped_ptr<GpuScheduler> gpu_scheduler_; | |
122 scoped_ptr<gles2::GLES2Decoder> decoder_; | |
123 scoped_refptr<gfx::GLContext> context_; | |
124 scoped_refptr<gfx::GLSurface> surface_; | |
125 base::Closure context_lost_callback_; | |
126 unsigned int share_group_id_; | |
127 | |
128 // Members accessed on the client thread: | |
129 State last_state_; | |
130 int32 last_put_offset_; | |
131 | |
132 // Accessed on both threads: | |
133 scoped_ptr<CommandBuffer> command_buffer_; | |
134 base::Lock command_buffer_lock_; | |
135 base::WaitableEvent flush_event_; | |
136 | |
137 DISALLOW_COPY_AND_ASSIGN(InProcessCommandBuffer); | |
138 }; | |
139 | |
140 } // namespace gpu | |
141 | |
142 #endif // GPU_COMMAND_BUFFER_SERVICE_IN_PROCESS_COMMAND_BUFFER_H_ | |
OLD | NEW |