| 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> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 11 #include "base/shared_memory.h" | 14 #include "base/shared_memory.h" |
| 12 #include "gpu/command_buffer/common/command_buffer.h" | 15 #include "gpu/command_buffer/common/command_buffer.h" |
| 13 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 16 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 14 #include "gpu/command_buffer/service/cmd_parser.h" | 17 #include "gpu/command_buffer/service/cmd_parser.h" |
| 15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 16 | 19 |
| 17 namespace gpu { | 20 namespace gpu { |
| 18 | 21 |
| 19 // 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 |
| 20 // 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 |
| 21 // 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 |
| 22 // on it. | 25 // on it. |
| 23 class GpuScheduler : public CommandBufferEngine { | 26 class GpuScheduler |
| 27 : public CommandBufferEngine, |
| 28 public base::SupportsWeakPtr<GpuScheduler> { |
| 24 public: | 29 public: |
| 25 GpuScheduler(CommandBuffer* command_buffer, | 30 GpuScheduler(CommandBuffer* command_buffer, |
| 26 gles2::GLES2Decoder* decoder, | 31 gles2::GLES2Decoder* decoder, |
| 27 CommandParser* parser); | 32 CommandParser* parser); |
| 28 | 33 |
| 29 virtual ~GpuScheduler(); | 34 virtual ~GpuScheduler(); |
| 30 | 35 |
| 31 void PutChanged(); | 36 void PutChanged(); |
| 32 | 37 |
| 33 // Sets whether commands should be processed by this scheduler. Setting to | 38 // Sets whether commands should be processed by this scheduler. Setting to |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 void SetScheduledCallback(Callback0::Type* scheduled_callback); | 49 void SetScheduledCallback(Callback0::Type* scheduled_callback); |
| 45 | 50 |
| 46 // Implementation of CommandBufferEngine. | 51 // Implementation of CommandBufferEngine. |
| 47 virtual Buffer GetSharedMemoryBuffer(int32 shm_id); | 52 virtual Buffer GetSharedMemoryBuffer(int32 shm_id); |
| 48 virtual void set_token(int32 token); | 53 virtual void set_token(int32 token); |
| 49 virtual bool SetGetOffset(int32 offset); | 54 virtual bool SetGetOffset(int32 offset); |
| 50 virtual int32 GetGetOffset(); | 55 virtual int32 GetGetOffset(); |
| 51 | 56 |
| 52 void SetCommandProcessedCallback(Callback0::Type* callback); | 57 void SetCommandProcessedCallback(Callback0::Type* callback); |
| 53 | 58 |
| 59 void DeferToFence(base::Closure task); |
| 60 |
| 54 private: | 61 private: |
| 55 | 62 |
| 56 // The GpuScheduler holds a weak reference to the CommandBuffer. The | 63 // The GpuScheduler holds a weak reference to the CommandBuffer. The |
| 57 // CommandBuffer owns the GpuScheduler and holds a strong reference to it | 64 // CommandBuffer owns the GpuScheduler and holds a strong reference to it |
| 58 // through the ProcessCommands callback. | 65 // through the ProcessCommands callback. |
| 59 CommandBuffer* command_buffer_; | 66 CommandBuffer* command_buffer_; |
| 60 | 67 |
| 61 // Does not own decoder. TODO(apatrick): The GpuScheduler shouldn't need a | 68 // Does not own decoder. TODO(apatrick): The GpuScheduler shouldn't need a |
| 62 // pointer to the decoder, it is only used to initialize the CommandParser, | 69 // pointer to the decoder, it is only used to initialize the CommandParser, |
| 63 // which could be an argument to the constructor, and to determine the | 70 // which could be an argument to the constructor, and to determine the |
| 64 // reason for context lost. | 71 // reason for context lost. |
| 65 gles2::GLES2Decoder* decoder_; | 72 gles2::GLES2Decoder* decoder_; |
| 66 | 73 |
| 67 // TODO(apatrick): The GpuScheduler currently creates and owns the parser. | 74 // TODO(apatrick): The GpuScheduler currently creates and owns the parser. |
| 68 // This should be an argument to the constructor. | 75 // This should be an argument to the constructor. |
| 69 scoped_ptr<CommandParser> parser_; | 76 scoped_ptr<CommandParser> parser_; |
| 70 | 77 |
| 71 // Greater than zero if this is waiting to be rescheduled before continuing. | 78 // Greater than zero if this is waiting to be rescheduled before continuing. |
| 72 int unscheduled_count_; | 79 int unscheduled_count_; |
| 73 | 80 |
| 81 // The GpuScheduler will unschedule itself in the event that further GL calls |
| 82 // are issued to it before all these fences have been crossed by the GPU. |
| 83 struct UnscheduleFence { |
| 84 UnscheduleFence(); |
| 85 ~UnscheduleFence(); |
| 86 |
| 87 uint32 fence; |
| 88 base::Closure task; |
| 89 }; |
| 90 std::queue<UnscheduleFence> unschedule_fences_; |
| 91 |
| 74 scoped_ptr<Callback0::Type> scheduled_callback_; | 92 scoped_ptr<Callback0::Type> scheduled_callback_; |
| 75 scoped_ptr<Callback0::Type> command_processed_callback_; | 93 scoped_ptr<Callback0::Type> command_processed_callback_; |
| 76 }; | 94 }; |
| 77 | 95 |
| 78 } // namespace gpu | 96 } // namespace gpu |
| 79 | 97 |
| 80 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ | 98 #endif // GPU_COMMAND_BUFFER_SERVICE_GPU_SCHEDULER_H_ |
| OLD | NEW |