OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "app/gfx/gl/gl_context.h" | 8 #include "app/gfx/gl/gl_context.h" |
9 #include "gpu/command_buffer/service/gpu_processor.h" | 9 #include "gpu/command_buffer/service/gpu_processor.h" |
10 | 10 |
11 using ::base::SharedMemory; | 11 using ::base::SharedMemory; |
12 | 12 |
13 namespace gpu { | 13 namespace gpu { |
14 | 14 |
15 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, | 15 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, |
16 gles2::ContextGroup* group) | 16 gles2::ContextGroup* group) |
17 : command_buffer_(command_buffer), | 17 : command_buffer_(command_buffer), |
18 commands_per_update_(100), | 18 commands_per_update_(100), |
19 #if defined(OS_MACOSX) | |
20 swap_buffers_count_(0), | |
21 acknowledged_swap_buffers_count_(0), | |
22 #endif | |
19 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 23 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
20 DCHECK(command_buffer); | 24 DCHECK(command_buffer); |
21 decoder_.reset(gles2::GLES2Decoder::Create(group)); | 25 decoder_.reset(gles2::GLES2Decoder::Create(group)); |
22 decoder_->set_engine(this); | 26 decoder_->set_engine(this); |
23 } | 27 } |
24 | 28 |
25 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, | 29 GPUProcessor::GPUProcessor(CommandBuffer* command_buffer, |
26 gles2::GLES2Decoder* decoder, | 30 gles2::GLES2Decoder* decoder, |
27 CommandParser* parser, | 31 CommandParser* parser, |
28 int commands_per_update) | 32 int commands_per_update) |
29 : command_buffer_(command_buffer), | 33 : command_buffer_(command_buffer), |
30 commands_per_update_(commands_per_update), | 34 commands_per_update_(commands_per_update), |
35 #if defined(OS_MACOSX) | |
36 swap_buffers_count_(0), | |
37 acknowledged_swap_buffers_count_(0), | |
38 #endif | |
31 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 39 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
32 DCHECK(command_buffer); | 40 DCHECK(command_buffer); |
33 decoder_.reset(decoder); | 41 decoder_.reset(decoder); |
34 parser_.reset(parser); | 42 parser_.reset(parser); |
35 } | 43 } |
36 | 44 |
37 GPUProcessor::~GPUProcessor() { | 45 GPUProcessor::~GPUProcessor() { |
38 Destroy(); | 46 Destroy(); |
39 } | 47 } |
40 | 48 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 bool have_context = false; | 88 bool have_context = false; |
81 if (decoder_.get()) { | 89 if (decoder_.get()) { |
82 have_context = decoder_->MakeCurrent(); | 90 have_context = decoder_->MakeCurrent(); |
83 decoder_->Destroy(); | 91 decoder_->Destroy(); |
84 decoder_.reset(); | 92 decoder_.reset(); |
85 } | 93 } |
86 | 94 |
87 parser_.reset(); | 95 parser_.reset(); |
88 } | 96 } |
89 | 97 |
98 #if defined(OS_MACOSX) | |
99 namespace { | |
100 const unsigned int kMaxOutstandingSwapBuffersCallsPerOnscreenContext = 1; | |
101 const int64 kWaitingTimeForSwapBuffers = 1; // ms | |
102 } | |
103 #endif | |
104 | |
90 void GPUProcessor::ProcessCommands() { | 105 void GPUProcessor::ProcessCommands() { |
91 CommandBuffer::State state = command_buffer_->GetState(); | 106 CommandBuffer::State state = command_buffer_->GetState(); |
92 if (state.error != error::kNoError) | 107 if (state.error != error::kNoError) |
93 return; | 108 return; |
94 | 109 |
95 if (decoder_.get()) { | 110 if (decoder_.get()) { |
96 if (!decoder_->MakeCurrent()) { | 111 if (!decoder_->MakeCurrent()) { |
97 LOG(ERROR) << "Context lost because MakeCurrent failed."; | 112 LOG(ERROR) << "Context lost because MakeCurrent failed."; |
98 command_buffer_->SetParseError(error::kLostContext); | 113 command_buffer_->SetParseError(error::kLostContext); |
99 return; | 114 return; |
100 } | 115 } |
101 } | 116 } |
102 | 117 |
103 parser_->set_put(state.put_offset); | 118 parser_->set_put(state.put_offset); |
104 | 119 |
120 #if defined(OS_MACOSX) | |
121 bool do_rate_limiting = surface_.get() != NULL; | |
122 // Don't swamp the browser process with SwapBuffers calls it can't handle. | |
123 if (do_rate_limiting && | |
124 swap_buffers_count_ - acknowledged_swap_buffers_count_ >= | |
125 kMaxOutstandingSwapBuffersCallsPerOnscreenContext) { | |
126 // Defer the processing of more commands. | |
127 MessageLoop::current()->PostDelayedTask( | |
apatrick_chromium
2010/11/24 23:56:09
Rather than repeatedly poll for progress every 1ms
Ken Russell (switch to Gerrit)
2010/11/25 01:02:08
Thanks, this is an excellent suggestion and cleans
| |
128 FROM_HERE, | |
129 method_factory_.NewRunnableMethod(&GPUProcessor::ProcessCommands), | |
130 kWaitingTimeForSwapBuffers); | |
131 return; | |
132 } | |
133 #endif | |
134 | |
105 int commands_processed = 0; | 135 int commands_processed = 0; |
106 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { | 136 while (commands_processed < commands_per_update_ && !parser_->IsEmpty()) { |
107 error::Error error = parser_->ProcessCommand(); | 137 error::Error error = parser_->ProcessCommand(); |
108 if (error != error::kNoError) { | 138 if (error != error::kNoError) { |
109 command_buffer_->SetParseError(error); | 139 command_buffer_->SetParseError(error); |
110 return; | 140 return; |
111 } | 141 } |
112 ++commands_processed; | 142 ++commands_processed; |
113 } | 143 } |
114 | 144 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 | 177 |
148 void GPUProcessor::SetSwapBuffersCallback( | 178 void GPUProcessor::SetSwapBuffersCallback( |
149 Callback0::Type* callback) { | 179 Callback0::Type* callback) { |
150 wrapped_swap_buffers_callback_.reset(callback); | 180 wrapped_swap_buffers_callback_.reset(callback); |
151 decoder_->SetSwapBuffersCallback( | 181 decoder_->SetSwapBuffersCallback( |
152 NewCallback(this, | 182 NewCallback(this, |
153 &GPUProcessor::WillSwapBuffers)); | 183 &GPUProcessor::WillSwapBuffers)); |
154 } | 184 } |
155 | 185 |
156 } // namespace gpu | 186 } // namespace gpu |
OLD | NEW |