OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
8 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" |
9 #include "gpu/command_buffer/common/command_buffer.h" | 13 #include "gpu/command_buffer/common/command_buffer.h" |
10 #include "gpu/command_buffer/common/command_buffer_shared.h" | 14 #include "gpu/command_buffer/common/command_buffer_shared.h" |
11 | 15 |
12 namespace gpu { | 16 namespace gpu { |
13 | 17 |
14 class TransferBufferManagerInterface; | 18 class TransferBufferManagerInterface; |
15 | 19 |
16 class GPU_EXPORT CommandBufferServiceBase : public CommandBuffer { | 20 class GPU_EXPORT CommandBufferServiceBase : public CommandBuffer { |
17 public: | 21 public: |
18 // Sets the current get offset. This can be called from any thread. | 22 // Sets the current get offset. This can be called from any thread. |
19 virtual void SetGetOffset(int32 get_offset) = 0; | 23 virtual void SetGetOffset(int32_t get_offset) = 0; |
20 | 24 |
21 // Get the transfer buffer associated with an ID. Returns a null buffer for | 25 // Get the transfer buffer associated with an ID. Returns a null buffer for |
22 // ID 0. | 26 // ID 0. |
23 virtual scoped_refptr<gpu::Buffer> GetTransferBuffer(int32 id) = 0; | 27 virtual scoped_refptr<gpu::Buffer> GetTransferBuffer(int32_t id) = 0; |
24 | 28 |
25 // Allows the reader to update the current token value. | 29 // Allows the reader to update the current token value. |
26 virtual void SetToken(int32 token) = 0; | 30 virtual void SetToken(int32_t token) = 0; |
27 | 31 |
28 // Allows the reader to set the current parse error. | 32 // Allows the reader to set the current parse error. |
29 virtual void SetParseError(error::Error) = 0; | 33 virtual void SetParseError(error::Error) = 0; |
30 | 34 |
31 // Allows the reader to set the current context lost reason. | 35 // Allows the reader to set the current context lost reason. |
32 // NOTE: if calling this in conjunction with SetParseError, | 36 // NOTE: if calling this in conjunction with SetParseError, |
33 // call this first. | 37 // call this first. |
34 virtual void SetContextLostReason(error::ContextLostReason) = 0; | 38 virtual void SetContextLostReason(error::ContextLostReason) = 0; |
35 | 39 |
36 // Allows the reader to obtain the current put offset. | 40 // Allows the reader to obtain the current put offset. |
37 virtual int32 GetPutOffset() = 0; | 41 virtual int32_t GetPutOffset() = 0; |
38 }; | 42 }; |
39 | 43 |
40 // An object that implements a shared memory command buffer and a synchronous | 44 // An object that implements a shared memory command buffer and a synchronous |
41 // API to manage the put and get pointers. | 45 // API to manage the put and get pointers. |
42 class GPU_EXPORT CommandBufferService : public CommandBufferServiceBase { | 46 class GPU_EXPORT CommandBufferService : public CommandBufferServiceBase { |
43 public: | 47 public: |
44 typedef base::Callback<bool(int32)> GetBufferChangedCallback; | 48 typedef base::Callback<bool(int32_t)> GetBufferChangedCallback; |
45 explicit CommandBufferService( | 49 explicit CommandBufferService( |
46 TransferBufferManagerInterface* transfer_buffer_manager); | 50 TransferBufferManagerInterface* transfer_buffer_manager); |
47 ~CommandBufferService() override; | 51 ~CommandBufferService() override; |
48 | 52 |
49 // CommandBuffer implementation: | 53 // CommandBuffer implementation: |
50 bool Initialize() override; | 54 bool Initialize() override; |
51 State GetLastState() override; | 55 State GetLastState() override; |
52 int32 GetLastToken() override; | 56 int32_t GetLastToken() override; |
53 void Flush(int32 put_offset) override; | 57 void Flush(int32_t put_offset) override; |
54 void OrderingBarrier(int32 put_offset) override; | 58 void OrderingBarrier(int32_t put_offset) override; |
55 void WaitForTokenInRange(int32 start, int32 end) override; | 59 void WaitForTokenInRange(int32_t start, int32_t end) override; |
56 void WaitForGetOffsetInRange(int32 start, int32 end) override; | 60 void WaitForGetOffsetInRange(int32_t start, int32_t end) override; |
57 void SetGetBuffer(int32 transfer_buffer_id) override; | 61 void SetGetBuffer(int32_t transfer_buffer_id) override; |
58 scoped_refptr<Buffer> CreateTransferBuffer(size_t size, int32* id) override; | 62 scoped_refptr<Buffer> CreateTransferBuffer(size_t size, int32_t* id) override; |
59 void DestroyTransferBuffer(int32 id) override; | 63 void DestroyTransferBuffer(int32_t id) override; |
60 | 64 |
61 // CommandBufferServiceBase implementation: | 65 // CommandBufferServiceBase implementation: |
62 void SetGetOffset(int32 get_offset) override; | 66 void SetGetOffset(int32_t get_offset) override; |
63 scoped_refptr<Buffer> GetTransferBuffer(int32 id) override; | 67 scoped_refptr<Buffer> GetTransferBuffer(int32_t id) override; |
64 void SetToken(int32 token) override; | 68 void SetToken(int32_t token) override; |
65 void SetParseError(error::Error error) override; | 69 void SetParseError(error::Error error) override; |
66 void SetContextLostReason(error::ContextLostReason) override; | 70 void SetContextLostReason(error::ContextLostReason) override; |
67 int32 GetPutOffset() override; | 71 int32_t GetPutOffset() override; |
68 | 72 |
69 // Sets a callback that is called whenever the put offset is changed. When | 73 // Sets a callback that is called whenever the put offset is changed. When |
70 // called with sync==true, the callback must not return until some progress | 74 // called with sync==true, the callback must not return until some progress |
71 // has been made (unless the command buffer is empty), i.e. the get offset | 75 // has been made (unless the command buffer is empty), i.e. the get offset |
72 // must have changed. It need not process the entire command buffer though. | 76 // must have changed. It need not process the entire command buffer though. |
73 // This allows concurrency between the writer and the reader while giving the | 77 // This allows concurrency between the writer and the reader while giving the |
74 // writer a means of waiting for the reader to make some progress before | 78 // writer a means of waiting for the reader to make some progress before |
75 // attempting to write more to the command buffer. Takes ownership of | 79 // attempting to write more to the command buffer. Takes ownership of |
76 // callback. | 80 // callback. |
77 virtual void SetPutOffsetChangeCallback(const base::Closure& callback); | 81 virtual void SetPutOffsetChangeCallback(const base::Closure& callback); |
78 // Sets a callback that is called whenever the get buffer is changed. | 82 // Sets a callback that is called whenever the get buffer is changed. |
79 virtual void SetGetBufferChangeCallback( | 83 virtual void SetGetBufferChangeCallback( |
80 const GetBufferChangedCallback& callback); | 84 const GetBufferChangedCallback& callback); |
81 virtual void SetParseErrorCallback(const base::Closure& callback); | 85 virtual void SetParseErrorCallback(const base::Closure& callback); |
82 | 86 |
83 // Setup the shared memory that shared state should be copied into. | 87 // Setup the shared memory that shared state should be copied into. |
84 void SetSharedStateBuffer(scoped_ptr<BufferBacking> shared_state_buffer); | 88 void SetSharedStateBuffer(scoped_ptr<BufferBacking> shared_state_buffer); |
85 | 89 |
86 // Copy the current state into the shared state transfer buffer. | 90 // Copy the current state into the shared state transfer buffer. |
87 void UpdateState(); | 91 void UpdateState(); |
88 | 92 |
89 // Registers an existing shared memory object and get an ID that can be used | 93 // Registers an existing shared memory object and get an ID that can be used |
90 // to identify it in the command buffer. | 94 // to identify it in the command buffer. |
91 bool RegisterTransferBuffer(int32 id, scoped_ptr<BufferBacking> buffer); | 95 bool RegisterTransferBuffer(int32_t id, scoped_ptr<BufferBacking> buffer); |
92 | 96 |
93 private: | 97 private: |
94 int32 ring_buffer_id_; | 98 int32_t ring_buffer_id_; |
95 scoped_refptr<Buffer> ring_buffer_; | 99 scoped_refptr<Buffer> ring_buffer_; |
96 scoped_ptr<BufferBacking> shared_state_buffer_; | 100 scoped_ptr<BufferBacking> shared_state_buffer_; |
97 CommandBufferSharedState* shared_state_; | 101 CommandBufferSharedState* shared_state_; |
98 int32 num_entries_; | 102 int32_t num_entries_; |
99 int32 get_offset_; | 103 int32_t get_offset_; |
100 int32 put_offset_; | 104 int32_t put_offset_; |
101 base::Closure put_offset_change_callback_; | 105 base::Closure put_offset_change_callback_; |
102 GetBufferChangedCallback get_buffer_change_callback_; | 106 GetBufferChangedCallback get_buffer_change_callback_; |
103 base::Closure parse_error_callback_; | 107 base::Closure parse_error_callback_; |
104 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 108 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
105 int32 token_; | 109 int32_t token_; |
106 uint32 generation_; | 110 uint32_t generation_; |
107 error::Error error_; | 111 error::Error error_; |
108 error::ContextLostReason context_lost_reason_; | 112 error::ContextLostReason context_lost_reason_; |
109 | 113 |
110 DISALLOW_COPY_AND_ASSIGN(CommandBufferService); | 114 DISALLOW_COPY_AND_ASSIGN(CommandBufferService); |
111 }; | 115 }; |
112 | 116 |
113 } // namespace gpu | 117 } // namespace gpu |
114 | 118 |
115 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 119 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
OLD | NEW |