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 |
25 explicit CommandBuffer(NPP npp); | 33 explicit CommandBuffer(NPP npp); |
26 virtual ~CommandBuffer(); | 34 virtual ~CommandBuffer(); |
27 | 35 |
28 // Create a shared memory buffer of the given size. | 36 // Create a shared memory buffer of the given size. |
29 virtual bool Initialize(int32 size); | 37 virtual bool Initialize(int32 size); |
30 | 38 |
31 // Gets the shared memory ring buffer object for the command buffer. | 39 // Gets the shared memory ring buffer object for the command buffer. |
32 virtual NPObjectPointer<CHRSharedMemory> GetRingBuffer(); | 40 virtual NPObjectPointer<CHRSharedMemory> GetRingBuffer(); |
33 | 41 |
34 virtual int32 GetSize(); | 42 virtual int32 GetSize(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // multiple times and have multiple associated handles. Each handle for a | 74 // multiple times and have multiple associated handles. Each handle for a |
67 // distinct object must be separately unregistered. | 75 // distinct object must be separately unregistered. |
68 virtual int32 RegisterObject(NPObjectPointer<NPObject> object); | 76 virtual int32 RegisterObject(NPObjectPointer<NPObject> object); |
69 | 77 |
70 // Unregister a previously registered NPObject. It is safe to unregister the | 78 // Unregister a previously registered NPObject. It is safe to unregister the |
71 // zero handle. | 79 // zero handle. |
72 virtual void UnregisterObject(NPObjectPointer<NPObject> object, int32 handle); | 80 virtual void UnregisterObject(NPObjectPointer<NPObject> object, int32 handle); |
73 | 81 |
74 virtual NPObjectPointer<NPObject> GetRegisteredObject(int32 handle); | 82 virtual NPObjectPointer<NPObject> GetRegisteredObject(int32 handle); |
75 | 83 |
| 84 // Get the current token value. This is used for by the writer to defer |
| 85 // changes to shared memory objects until the reader has reached a certain |
| 86 // point in the command buffer. The reader is responsible for updating the |
| 87 // token value, for example in response to an asynchronous set token command |
| 88 // embedded in the command buffer. The default token value is zero. |
| 89 int32 GetToken() { |
| 90 return token_; |
| 91 } |
| 92 |
| 93 // Allows the reader to update the current token value. |
| 94 void SetToken(int32 token) { |
| 95 token_ = token; |
| 96 } |
| 97 |
| 98 // Get the current error status and reset it to ERROR_NO_ERROR. |
| 99 // The default error status is ERROR_NO_ERROR. |
| 100 int32 ResetError(); |
| 101 |
| 102 // Allows the reader to set the current error status. |
| 103 void SetError(int32 error) { |
| 104 error_ = error; |
| 105 } |
| 106 |
76 NP_UTILS_BEGIN_DISPATCHER_CHAIN(CommandBuffer, DefaultNPObject<NPObject>) | 107 NP_UTILS_BEGIN_DISPATCHER_CHAIN(CommandBuffer, DefaultNPObject<NPObject>) |
77 NP_UTILS_DISPATCHER(Initialize, bool(int32)) | 108 NP_UTILS_DISPATCHER(Initialize, bool(int32)) |
78 NP_UTILS_DISPATCHER(GetRingBuffer, NPObjectPointer<CHRSharedMemory>()) | 109 NP_UTILS_DISPATCHER(GetRingBuffer, NPObjectPointer<CHRSharedMemory>()) |
79 NP_UTILS_DISPATCHER(GetSize, int32()) | 110 NP_UTILS_DISPATCHER(GetSize, int32()) |
80 NP_UTILS_DISPATCHER(SyncOffsets, int32(int32)) | 111 NP_UTILS_DISPATCHER(SyncOffsets, int32(int32)) |
81 NP_UTILS_DISPATCHER(GetGetOffset, int32()); | 112 NP_UTILS_DISPATCHER(GetGetOffset, int32()); |
82 NP_UTILS_DISPATCHER(GetPutOffset, int32()); | 113 NP_UTILS_DISPATCHER(GetPutOffset, int32()); |
83 NP_UTILS_DISPATCHER(RegisterObject, int32(NPObjectPointer<NPObject>)); | 114 NP_UTILS_DISPATCHER(RegisterObject, int32(NPObjectPointer<NPObject>)); |
84 NP_UTILS_DISPATCHER(UnregisterObject, | 115 NP_UTILS_DISPATCHER(UnregisterObject, |
85 void(NPObjectPointer<NPObject>, int32)); | 116 void(NPObjectPointer<NPObject>, int32)); |
| 117 NP_UTILS_DISPATCHER(GetToken, int32()); |
| 118 NP_UTILS_DISPATCHER(ResetError, int32()); |
86 NP_UTILS_END_DISPATCHER_CHAIN | 119 NP_UTILS_END_DISPATCHER_CHAIN |
87 | 120 |
88 private: | 121 private: |
89 NPP npp_; | 122 NPP npp_; |
90 NPObjectPointer<CHRSharedMemory> shared_memory_; | 123 NPObjectPointer<CHRSharedMemory> shared_memory_; |
91 int32 size_; | 124 int32 size_; |
92 int32 get_offset_; | 125 int32 get_offset_; |
93 int32 put_offset_; | 126 int32 put_offset_; |
94 scoped_ptr<Callback0::Type> put_offset_change_callback_; | 127 scoped_ptr<Callback0::Type> put_offset_change_callback_; |
95 std::vector<NPObjectPointer<NPObject> > registered_objects_; | 128 std::vector<NPObjectPointer<NPObject> > registered_objects_; |
96 std::set<int32> unused_registered_object_elements_; | 129 std::set<int32> unused_registered_object_elements_; |
| 130 int32 token_; |
| 131 int32 error_; |
97 }; | 132 }; |
98 | 133 |
99 } // namespace gpu_plugin | 134 } // namespace gpu_plugin |
100 } // namespace o3d | 135 } // namespace o3d |
101 | 136 |
102 #endif // O3D_GPU_PLUGIN_COMMAND_BUFFER_H_ | 137 #endif // O3D_GPU_PLUGIN_COMMAND_BUFFER_H_ |
OLD | NEW |