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

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

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

Powered by Google App Engine
This is Rietveld 408576698