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 "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/synchronization/lock.h" | |
10 #include "gpu/command_buffer/common/command_buffer.h" | 11 #include "gpu/command_buffer/common/command_buffer.h" |
11 #include "gpu/command_buffer/common/command_buffer_shared.h" | 12 #include "gpu/command_buffer/common/command_buffer_shared.h" |
12 | 13 |
13 namespace gpu { | 14 namespace gpu { |
14 | 15 |
15 class TransferBufferManagerInterface; | 16 class TransferBufferManagerInterface; |
16 | 17 |
17 // An object that implements a shared memory command buffer and a synchronous | 18 // An object that implements a shared memory command buffer and a synchronous |
18 // API to manage the put and get pointers. | 19 // API to manage the put and get pointers. |
19 class GPU_EXPORT CommandBufferService : public CommandBuffer { | 20 class GPU_EXPORT CommandBufferService : public CommandBuffer { |
20 public: | 21 public: |
21 typedef base::Callback<bool(int32)> GetBufferChangedCallback; | 22 typedef base::Callback<bool(int32)> GetBufferChangedCallback; |
22 explicit CommandBufferService( | 23 explicit CommandBufferService( |
23 TransferBufferManagerInterface* transfer_buffer_manager); | 24 TransferBufferManagerInterface* transfer_buffer_manager); |
24 virtual ~CommandBufferService(); | 25 virtual ~CommandBufferService(); |
25 | 26 |
26 // CommandBuffer implementation: | 27 // CommandBuffer implementation: |
27 virtual bool Initialize() OVERRIDE; | 28 virtual bool Initialize() OVERRIDE; |
28 virtual State GetState() OVERRIDE; | 29 virtual State GetState() OVERRIDE; |
29 virtual State GetLastState() OVERRIDE; | 30 virtual State GetLastState() OVERRIDE; |
30 virtual int32 GetLastToken() OVERRIDE; | 31 virtual int32 GetLastToken() OVERRIDE; |
31 virtual void Flush(int32 put_offset) OVERRIDE; | 32 virtual void Flush(int32 put_offset) OVERRIDE; |
32 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; | 33 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; |
33 virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE; | 34 virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE; |
34 virtual void SetGetOffset(int32 get_offset) OVERRIDE; | 35 virtual void SetGetOffset(int32 get_offset) OVERRIDE; |
35 virtual Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; | 36 virtual Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; |
36 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; | 37 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; |
37 virtual Buffer GetTransferBuffer(int32 id) OVERRIDE; | 38 virtual Buffer GetTransferBuffer(int32 id) OVERRIDE; |
38 virtual void SetToken(int32 token) OVERRIDE; | 39 virtual void SetToken(int32 token) OVERRIDE; |
40 virtual void SetAsyncToken(uint32 token) OVERRIDE; | |
39 virtual void SetParseError(error::Error error) OVERRIDE; | 41 virtual void SetParseError(error::Error error) OVERRIDE; |
40 virtual void SetContextLostReason(error::ContextLostReason) OVERRIDE; | 42 virtual void SetContextLostReason(error::ContextLostReason) OVERRIDE; |
41 | 43 |
42 // Sets a callback that is called whenever the put offset is changed. When | 44 // Sets a callback that is called whenever the put offset is changed. When |
43 // called with sync==true, the callback must not return until some progress | 45 // called with sync==true, the callback must not return until some progress |
44 // has been made (unless the command buffer is empty), i.e. the get offset | 46 // has been made (unless the command buffer is empty), i.e. the get offset |
45 // must have changed. It need not process the entire command buffer though. | 47 // must have changed. It need not process the entire command buffer though. |
46 // This allows concurrency between the writer and the reader while giving the | 48 // This allows concurrency between the writer and the reader while giving the |
47 // writer a means of waiting for the reader to make some progress before | 49 // writer a means of waiting for the reader to make some progress before |
48 // attempting to write more to the command buffer. Takes ownership of | 50 // attempting to write more to the command buffer. Takes ownership of |
(...skipping 11 matching lines...) Expand all Loading... | |
60 void UpdateState(); | 62 void UpdateState(); |
61 | 63 |
62 // Register an existing shared memory object and get an ID that can be used | 64 // Register an existing shared memory object and get an ID that can be used |
63 // to identify it in the command buffer. Callee dups the handle until | 65 // to identify it in the command buffer. Callee dups the handle until |
64 // DestroyTransferBuffer is called. | 66 // DestroyTransferBuffer is called. |
65 bool RegisterTransferBuffer(int32 id, | 67 bool RegisterTransferBuffer(int32 id, |
66 base::SharedMemory* shared_memory, | 68 base::SharedMemory* shared_memory, |
67 size_t size); | 69 size_t size); |
68 | 70 |
69 private: | 71 private: |
72 State GetStateImpl(); | |
reveman
2014/01/22 17:30:04
Can you adjust the name of this so it's clear |loc
| |
73 | |
70 int32 ring_buffer_id_; | 74 int32 ring_buffer_id_; |
71 Buffer ring_buffer_; | 75 Buffer ring_buffer_; |
72 scoped_ptr<base::SharedMemory> shared_state_shm_; | 76 scoped_ptr<base::SharedMemory> shared_state_shm_; |
73 CommandBufferSharedState* shared_state_; | 77 CommandBufferSharedState* shared_state_; |
74 int32 num_entries_; | 78 int32 num_entries_; |
75 int32 get_offset_; | 79 int32 get_offset_; |
76 int32 put_offset_; | 80 int32 put_offset_; |
77 base::Closure put_offset_change_callback_; | 81 base::Closure put_offset_change_callback_; |
78 GetBufferChangedCallback get_buffer_change_callback_; | 82 GetBufferChangedCallback get_buffer_change_callback_; |
79 base::Closure parse_error_callback_; | 83 base::Closure parse_error_callback_; |
80 TransferBufferManagerInterface* transfer_buffer_manager_; | 84 TransferBufferManagerInterface* transfer_buffer_manager_; |
81 int32 token_; | 85 int32 token_; |
86 uint32 async_token_; | |
82 uint32 generation_; | 87 uint32 generation_; |
83 error::Error error_; | 88 error::Error error_; |
84 error::ContextLostReason context_lost_reason_; | 89 error::ContextLostReason context_lost_reason_; |
90 base::Lock lock_; | |
reveman
2014/01/22 17:30:04
Would be nice with a comment here describing what
epenner
2014/01/23 02:52:44
I'm agreeing with Piman that a lock_ doesn't seem
| |
85 | 91 |
86 DISALLOW_COPY_AND_ASSIGN(CommandBufferService); | 92 DISALLOW_COPY_AND_ASSIGN(CommandBufferService); |
87 }; | 93 }; |
88 | 94 |
89 } // namespace gpu | 95 } // namespace gpu |
90 | 96 |
91 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ | 97 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_BUFFER_SERVICE_H_ |
OLD | NEW |