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

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

Powered by Google App Engine
This is Rietveld 408576698