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 #include "gpu/command_buffer/service/gpu_scheduler.h" | 5 #include "gpu/command_buffer/service/gpu_scheduler.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/callback.h" | 8 #include "base/callback.h" |
8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
10 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "ui/gfx/gl/gl_context.h" | 14 #include "ui/gfx/gl/gl_context.h" |
14 #include "ui/gfx/gl/gl_bindings.h" | 15 #include "ui/gfx/gl/gl_bindings.h" |
15 #include "ui/gfx/gl/gl_surface.h" | 16 #include "ui/gfx/gl/gl_surface.h" |
16 #include "ui/gfx/gl/gl_switches.h" | 17 #include "ui/gfx/gl/gl_switches.h" |
17 | 18 |
18 using ::base::SharedMemory; | 19 using ::base::SharedMemory; |
19 | 20 |
20 namespace gpu { | 21 namespace gpu { |
| 22 namespace { |
| 23 const uint64 kPollFencePeriod = 4; |
| 24 } |
21 | 25 |
22 GpuScheduler::GpuScheduler(CommandBuffer* command_buffer, | 26 GpuScheduler::GpuScheduler(CommandBuffer* command_buffer, |
23 gles2::GLES2Decoder* decoder, | 27 gles2::GLES2Decoder* decoder, |
24 CommandParser* parser) | 28 CommandParser* parser) |
25 : command_buffer_(command_buffer), | 29 : command_buffer_(command_buffer), |
26 decoder_(decoder), | 30 decoder_(decoder), |
27 parser_(parser), | 31 parser_(parser), |
28 unscheduled_count_(0) { | 32 unscheduled_count_(0) { |
29 // Map the ring buffer and create the parser. | 33 // Map the ring buffer and create the parser. |
30 if (!parser) { | 34 if (!parser) { |
(...skipping 18 matching lines...) Expand all Loading... |
49 void GpuScheduler::PutChanged() { | 53 void GpuScheduler::PutChanged() { |
50 TRACE_EVENT1("gpu", "GpuScheduler:PutChanged", "this", this); | 54 TRACE_EVENT1("gpu", "GpuScheduler:PutChanged", "this", this); |
51 | 55 |
52 DCHECK(IsScheduled()); | 56 DCHECK(IsScheduled()); |
53 | 57 |
54 CommandBuffer::State state = command_buffer_->GetState(); | 58 CommandBuffer::State state = command_buffer_->GetState(); |
55 parser_->set_put(state.put_offset); | 59 parser_->set_put(state.put_offset); |
56 if (state.error != error::kNoError) | 60 if (state.error != error::kNoError) |
57 return; | 61 return; |
58 | 62 |
| 63 // Check that the GPU has passed all fences. |
| 64 while (!unschedule_fences_.empty()) { |
| 65 if (glTestFenceNV(unschedule_fences_.front().fence)) { |
| 66 glDeleteFencesNV(1, &unschedule_fences_.front().fence); |
| 67 unschedule_fences_.front().task.Run(); |
| 68 unschedule_fences_.pop(); |
| 69 } else { |
| 70 SetScheduled(false); |
| 71 MessageLoop::current()->PostDelayedTask( |
| 72 FROM_HERE, |
| 73 base::Bind(&GpuScheduler::SetScheduled, AsWeakPtr(), true), |
| 74 kPollFencePeriod); |
| 75 return; |
| 76 } |
| 77 } |
| 78 |
| 79 // One of the unschedule fence tasks might have unscheduled us. |
| 80 if (!IsScheduled()) |
| 81 return; |
| 82 |
59 error::Error error = error::kNoError; | 83 error::Error error = error::kNoError; |
60 while (!parser_->IsEmpty()) { | 84 while (!parser_->IsEmpty()) { |
| 85 DCHECK(IsScheduled()); |
| 86 DCHECK(unschedule_fences_.empty()); |
| 87 |
61 error = parser_->ProcessCommand(); | 88 error = parser_->ProcessCommand(); |
62 | 89 |
63 // TODO(piman): various classes duplicate various pieces of state, leading | 90 // TODO(piman): various classes duplicate various pieces of state, leading |
64 // to needlessly complex update logic. It should be possible to simply | 91 // to needlessly complex update logic. It should be possible to simply |
65 // share the state across all of them. | 92 // share the state across all of them. |
66 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); | 93 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); |
67 | 94 |
68 if (error::IsError(error)) { | 95 if (error::IsError(error)) { |
69 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 96 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
70 command_buffer_->SetParseError(error); | 97 command_buffer_->SetParseError(error); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 147 |
121 int32 GpuScheduler::GetGetOffset() { | 148 int32 GpuScheduler::GetGetOffset() { |
122 return parser_->get(); | 149 return parser_->get(); |
123 } | 150 } |
124 | 151 |
125 void GpuScheduler::SetCommandProcessedCallback( | 152 void GpuScheduler::SetCommandProcessedCallback( |
126 Callback0::Type* callback) { | 153 Callback0::Type* callback) { |
127 command_processed_callback_.reset(callback); | 154 command_processed_callback_.reset(callback); |
128 } | 155 } |
129 | 156 |
| 157 void GpuScheduler::DeferToFence(base::Closure task) { |
| 158 UnscheduleFence fence; |
| 159 |
| 160 glGenFencesNV(1, &fence.fence); |
| 161 glSetFenceNV(fence.fence, GL_ALL_COMPLETED_NV); |
| 162 |
| 163 fence.task = task; |
| 164 |
| 165 unschedule_fences_.push(fence); |
| 166 } |
| 167 |
| 168 GpuScheduler::UnscheduleFence::UnscheduleFence() : fence(0) { |
| 169 } |
| 170 |
| 171 GpuScheduler::UnscheduleFence::~UnscheduleFence() { |
| 172 } |
| 173 |
130 } // namespace gpu | 174 } // namespace gpu |
OLD | NEW |