| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GPU_SCHEDULER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // This class schedules commands that have been flushed. They are received via | 22 // This class schedules commands that have been flushed. They are received via |
| 23 // a command buffer and forwarded to a command parser. TODO(apatrick): This | 23 // a command buffer and forwarded to a command parser. TODO(apatrick): This |
| 24 // class should not know about the decoder. Do not add additional dependencies | 24 // class should not know about the decoder. Do not add additional dependencies |
| 25 // on it. | 25 // on it. |
| 26 class GpuScheduler | 26 class GpuScheduler |
| 27 : public CommandBufferEngine, | 27 : public CommandBufferEngine, |
| 28 public base::SupportsWeakPtr<GpuScheduler> { | 28 public base::SupportsWeakPtr<GpuScheduler> { |
| 29 public: | 29 public: |
| 30 GpuScheduler(CommandBuffer* command_buffer, | 30 GpuScheduler(CommandBuffer* command_buffer, |
| 31 gles2::GLES2Decoder* decoder, | 31 AsyncAPIInterface* handler, |
| 32 CommandParser* parser); | 32 gles2::GLES2Decoder* decoder); |
| 33 | 33 |
| 34 virtual ~GpuScheduler(); | 34 virtual ~GpuScheduler(); |
| 35 | 35 |
| 36 void PutChanged(); | 36 void PutChanged(); |
| 37 | 37 |
| 38 // Sets whether commands should be processed by this scheduler. Setting to | 38 // Sets whether commands should be processed by this scheduler. Setting to |
| 39 // false unschedules. Setting to true reschedules. Whether or not the | 39 // false unschedules. Setting to true reschedules. Whether or not the |
| 40 // scheduler is currently scheduled is "reference counted". Every call with | 40 // scheduler is currently scheduled is "reference counted". Every call with |
| 41 // false must eventually be paired by a call with true. | 41 // false must eventually be paired by a call with true. |
| 42 void SetScheduled(bool is_scheduled); | 42 void SetScheduled(bool is_scheduled); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 55 virtual Buffer GetSharedMemoryBuffer(int32 shm_id) OVERRIDE; | 55 virtual Buffer GetSharedMemoryBuffer(int32 shm_id) OVERRIDE; |
| 56 virtual void set_token(int32 token) OVERRIDE; | 56 virtual void set_token(int32 token) OVERRIDE; |
| 57 virtual bool SetGetBuffer(int32 transfer_buffer_id) OVERRIDE; | 57 virtual bool SetGetBuffer(int32 transfer_buffer_id) OVERRIDE; |
| 58 virtual bool SetGetOffset(int32 offset) OVERRIDE; | 58 virtual bool SetGetOffset(int32 offset) OVERRIDE; |
| 59 virtual int32 GetGetOffset() OVERRIDE; | 59 virtual int32 GetGetOffset() OVERRIDE; |
| 60 | 60 |
| 61 void SetCommandProcessedCallback(const base::Closure& callback); | 61 void SetCommandProcessedCallback(const base::Closure& callback); |
| 62 | 62 |
| 63 void DeferToFence(base::Closure task); | 63 void DeferToFence(base::Closure task); |
| 64 | 64 |
| 65 CommandParser* parser() const { |
| 66 return parser_.get(); |
| 67 } |
| 68 |
| 65 private: | 69 private: |
| 66 // Polls the fences, invoking callbacks that were waiting to be triggered | 70 // Polls the fences, invoking callbacks that were waiting to be triggered |
| 67 // by them and returns whether all fences were complete. | 71 // by them and returns whether all fences were complete. |
| 68 bool PollUnscheduleFences(); | 72 bool PollUnscheduleFences(); |
| 69 | 73 |
| 70 // The GpuScheduler holds a weak reference to the CommandBuffer. The | 74 // The GpuScheduler holds a weak reference to the CommandBuffer. The |
| 71 // CommandBuffer owns the GpuScheduler and holds a strong reference to it | 75 // CommandBuffer owns the GpuScheduler and holds a strong reference to it |
| 72 // through the ProcessCommands callback. | 76 // through the ProcessCommands callback. |
| 73 CommandBuffer* command_buffer_; | 77 CommandBuffer* command_buffer_; |
| 74 | 78 |
| 79 // The parser uses this to execute commands. |
| 80 AsyncAPIInterface* handler_; |
| 81 |
| 75 // Does not own decoder. TODO(apatrick): The GpuScheduler shouldn't need a | 82 // Does not own decoder. TODO(apatrick): The GpuScheduler shouldn't need a |
| 76 // pointer to the decoder, it is only used to initialize the CommandParser, | 83 // pointer to the decoder, it is only used to initialize the CommandParser, |
| 77 // which could be an argument to the constructor, and to determine the | 84 // which could be an argument to the constructor, and to determine the |
| 78 // reason for context lost. | 85 // reason for context lost. |
| 79 gles2::GLES2Decoder* decoder_; | 86 gles2::GLES2Decoder* decoder_; |
| 80 | 87 |
| 81 // TODO(apatrick): The GpuScheduler currently creates and owns the parser. | 88 // TODO(apatrick): The GpuScheduler currently creates and owns the parser. |
| 82 // This should be an argument to the constructor. | 89 // This should be an argument to the constructor. |
| 83 scoped_ptr<CommandParser> parser_; | 90 scoped_ptr<CommandParser> parser_; |
| 84 | 91 |
| 85 // Greater than zero if this is waiting to be rescheduled before continuing. | 92 // Greater than zero if this is waiting to be rescheduled before continuing. |
| 86 int unscheduled_count_; | 93 int unscheduled_count_; |
| 87 | 94 |
| 88 // The GpuScheduler will unschedule itself in the event that further GL calls | 95 // The GpuScheduler will unschedule itself in the event that further GL calls |
| 89 // are issued to it before all these fences have been crossed by the GPU. | 96 // are issued to it before all these fences have been crossed by the GPU. |
| 90 struct UnscheduleFence { | 97 struct UnscheduleFence { |
| 91 UnscheduleFence(); | 98 UnscheduleFence(); |
| 92 ~UnscheduleFence(); | 99 ~UnscheduleFence(); |
| 93 | 100 |
| 94 uint32 fence; | 101 uint32 fence; |
| 95 base::Closure task; | 102 base::Closure task; |
| 96 }; | 103 }; |
| 97 std::queue<UnscheduleFence> unschedule_fences_; | 104 std::queue<UnscheduleFence> unschedule_fences_; |
| 98 | 105 |
| 99 base::Closure scheduled_callback_; | 106 base::Closure scheduled_callback_; |
| 100 base::Closure command_processed_callback_; | 107 base::Closure command_processed_callback_; |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(GpuScheduler); |
| 101 }; | 110 }; |
| 102 | 111 |
| 103 } // namespace gpu | 112 } // namespace gpu |
| 104 | 113 |
| 105 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ | 114 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
| OLD | NEW |