OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 O3D_GPU_PLUGIN_COMMAND_BUFFER_H_ | 5 #ifndef O3D_GPU_PLUGIN_COMMAND_BUFFER_H_ |
6 #define O3D_GPU_PLUGIN_COMMAND_BUFFER_H_ | 6 #define O3D_GPU_PLUGIN_COMMAND_BUFFER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "o3d/gpu_plugin/np_utils/default_np_object.h" | 14 #include "o3d/gpu_plugin/np_utils/default_np_object.h" |
15 #include "o3d/gpu_plugin/np_utils/np_dispatcher.h" | 15 #include "o3d/gpu_plugin/np_utils/np_dispatcher.h" |
16 #include "o3d/gpu_plugin/system_services/shared_memory_public.h" | 16 #include "o3d/gpu_plugin/system_services/shared_memory_public.h" |
17 | 17 |
18 namespace o3d { | 18 namespace o3d { |
19 namespace gpu_plugin { | 19 namespace gpu_plugin { |
20 | 20 |
21 // An NPObject that implements a shared memory command buffer and a synchronous | 21 // An NPObject that implements a shared memory command buffer and a synchronous |
22 // API to manage the put and get pointers. | 22 // API to manage the put and get pointers. |
23 class CommandBuffer : public DefaultNPObject<NPObject> { | 23 class CommandBuffer : public DefaultNPObject<NPObject> { |
24 public: | 24 public: |
25 enum { | |
26 ERROR_NO_ERROR, | |
27 ERROR_INVALID_SIZE, | |
28 ERROR_OUT_OF_BOUNDS, | |
29 ERROR_UNKNOWN_COMMAND, | |
30 ERROR_INVALID_ARGUMENTS, | |
31 }; | |
32 | |
33 explicit CommandBuffer(NPP npp); | 25 explicit CommandBuffer(NPP npp); |
34 virtual ~CommandBuffer(); | 26 virtual ~CommandBuffer(); |
35 | 27 |
36 // Create a shared memory buffer of the given size. | 28 // Create a shared memory buffer of the given size. |
37 virtual bool Initialize(int32 size); | 29 virtual bool Initialize(int32 size); |
38 | 30 |
39 // Gets the shared memory ring buffer object for the command buffer. | 31 // Gets the shared memory ring buffer object for the command buffer. |
40 virtual NPObjectPointer<CHRSharedMemory> GetRingBuffer(); | 32 virtual NPObjectPointer<CHRSharedMemory> GetRingBuffer(); |
41 | 33 |
42 virtual int32 GetSize(); | 34 virtual int32 GetSize(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // embedded in the command buffer. The default token value is zero. | 80 // embedded in the command buffer. The default token value is zero. |
89 int32 GetToken() { | 81 int32 GetToken() { |
90 return token_; | 82 return token_; |
91 } | 83 } |
92 | 84 |
93 // Allows the reader to update the current token value. | 85 // Allows the reader to update the current token value. |
94 void SetToken(int32 token) { | 86 void SetToken(int32 token) { |
95 token_ = token; | 87 token_ = token; |
96 } | 88 } |
97 | 89 |
98 // Get the current error status and reset it to ERROR_NO_ERROR. | 90 // Get the current parse error and reset it to zero. Zero means no error. Non- |
99 // The default error status is ERROR_NO_ERROR. | 91 // zero means error. The default error status is zero. |
100 int32 ResetError(); | 92 int32 ResetParseError(); |
101 | 93 |
102 // Allows the reader to set the current error status. | 94 // Allows the reader to set the current parse error. |
103 void SetError(int32 error) { | 95 void SetParseError(int32 parse_error) { |
104 error_ = error; | 96 parse_error_ = parse_error; |
| 97 } |
| 98 |
| 99 // Returns whether the command buffer is in the error state. |
| 100 bool GetErrorStatus() { |
| 101 return error_status_; |
| 102 } |
| 103 |
| 104 // Allows the reader to set the error status. Once in an error state, the |
| 105 // command buffer cannot recover and ceases to process commands. |
| 106 void RaiseErrorStatus() { |
| 107 error_status_ = true; |
105 } | 108 } |
106 | 109 |
107 NP_UTILS_BEGIN_DISPATCHER_CHAIN(CommandBuffer, DefaultNPObject<NPObject>) | 110 NP_UTILS_BEGIN_DISPATCHER_CHAIN(CommandBuffer, DefaultNPObject<NPObject>) |
108 NP_UTILS_DISPATCHER(Initialize, bool(int32)) | 111 NP_UTILS_DISPATCHER(Initialize, bool(int32 size)) |
109 NP_UTILS_DISPATCHER(GetRingBuffer, NPObjectPointer<CHRSharedMemory>()) | 112 NP_UTILS_DISPATCHER(GetRingBuffer, NPObjectPointer<CHRSharedMemory>()) |
110 NP_UTILS_DISPATCHER(GetSize, int32()) | 113 NP_UTILS_DISPATCHER(GetSize, int32()) |
111 NP_UTILS_DISPATCHER(SyncOffsets, int32(int32)) | 114 NP_UTILS_DISPATCHER(SyncOffsets, int32(int32 get_offset)) |
112 NP_UTILS_DISPATCHER(GetGetOffset, int32()); | 115 NP_UTILS_DISPATCHER(GetGetOffset, int32()); |
113 NP_UTILS_DISPATCHER(GetPutOffset, int32()); | 116 NP_UTILS_DISPATCHER(GetPutOffset, int32()); |
114 NP_UTILS_DISPATCHER(RegisterObject, int32(NPObjectPointer<NPObject>)); | 117 NP_UTILS_DISPATCHER(RegisterObject, |
| 118 int32(NPObjectPointer<NPObject> object)); |
115 NP_UTILS_DISPATCHER(UnregisterObject, | 119 NP_UTILS_DISPATCHER(UnregisterObject, |
116 void(NPObjectPointer<NPObject>, int32)); | 120 void(NPObjectPointer<NPObject> object, int32 handle)); |
117 NP_UTILS_DISPATCHER(GetToken, int32()); | 121 NP_UTILS_DISPATCHER(GetToken, int32()); |
118 NP_UTILS_DISPATCHER(ResetError, int32()); | 122 NP_UTILS_DISPATCHER(ResetParseError, int32()); |
| 123 NP_UTILS_DISPATCHER(GetErrorStatus, bool()); |
119 NP_UTILS_END_DISPATCHER_CHAIN | 124 NP_UTILS_END_DISPATCHER_CHAIN |
120 | 125 |
121 private: | 126 private: |
122 NPP npp_; | 127 NPP npp_; |
123 NPObjectPointer<CHRSharedMemory> shared_memory_; | 128 NPObjectPointer<CHRSharedMemory> shared_memory_; |
124 int32 size_; | 129 int32 size_; |
125 int32 get_offset_; | 130 int32 get_offset_; |
126 int32 put_offset_; | 131 int32 put_offset_; |
127 scoped_ptr<Callback0::Type> put_offset_change_callback_; | 132 scoped_ptr<Callback0::Type> put_offset_change_callback_; |
128 std::vector<NPObjectPointer<NPObject> > registered_objects_; | 133 std::vector<NPObjectPointer<NPObject> > registered_objects_; |
129 std::set<int32> unused_registered_object_elements_; | 134 std::set<int32> unused_registered_object_elements_; |
130 int32 token_; | 135 int32 token_; |
131 int32 error_; | 136 int32 parse_error_; |
| 137 bool error_status_; |
132 }; | 138 }; |
133 | 139 |
134 } // namespace gpu_plugin | 140 } // namespace gpu_plugin |
135 } // namespace o3d | 141 } // namespace o3d |
136 | 142 |
137 #endif // O3D_GPU_PLUGIN_COMMAND_BUFFER_H_ | 143 #endif // O3D_GPU_PLUGIN_COMMAND_BUFFER_H_ |
OLD | NEW |