Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/renderer/ggl/ggl.cc

Issue 5317007: Add flow control between renderer and GPU processes, and, on Mac OS X,... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "base/weak_ptr.h" 9 #include "base/weak_ptr.h"
10 #include "chrome/renderer/command_buffer_proxy.h" 10 #include "chrome/renderer/command_buffer_proxy.h"
(...skipping 16 matching lines...) Expand all
27 27
28 #if defined(ENABLE_GPU) 28 #if defined(ENABLE_GPU)
29 29
30 namespace { 30 namespace {
31 31
32 const int32 kCommandBufferSize = 1024 * 1024; 32 const int32 kCommandBufferSize = 1024 * 1024;
33 // TODO(kbr): make the transfer buffer size configurable via context 33 // TODO(kbr): make the transfer buffer size configurable via context
34 // creation attributes. 34 // creation attributes.
35 const int32 kTransferBufferSize = 1024 * 1024; 35 const int32 kTransferBufferSize = 1024 * 1024;
36 36
37 // TODO(kbr) / TODO(apatrick): determine the best number of pending frames
38 // in the general case. On Mac OS X it seems we really want this to be 1,
39 // because otherwise the renderer process produces frames that do not
40 // actually reach the screen.
Nico 2010/11/24 23:43:29 True, but the browser process would show the lates
Ken Russell (switch to Gerrit) 2010/11/25 01:02:08 Correct.
41 const int kMaxFramesPending = 1;
42
37 // Singleton used to initialize and terminate the gles2 library. 43 // Singleton used to initialize and terminate the gles2 library.
38 class GLES2Initializer { 44 class GLES2Initializer {
39 public: 45 public:
40 GLES2Initializer() { 46 GLES2Initializer() {
41 gles2::Initialize(); 47 gles2::Initialize();
42 } 48 }
43 49
44 ~GLES2Initializer() { 50 ~GLES2Initializer() {
45 gles2::Terminate(); 51 gles2::Terminate();
46 } 52 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 scoped_refptr<GpuChannelHost> channel_; 131 scoped_refptr<GpuChannelHost> channel_;
126 base::WeakPtr<Context> parent_; 132 base::WeakPtr<Context> parent_;
127 scoped_ptr<Callback0::Type> swap_buffers_callback_; 133 scoped_ptr<Callback0::Type> swap_buffers_callback_;
128 uint32 parent_texture_id_; 134 uint32 parent_texture_id_;
129 CommandBufferProxy* command_buffer_; 135 CommandBufferProxy* command_buffer_;
130 gpu::gles2::GLES2CmdHelper* gles2_helper_; 136 gpu::gles2::GLES2CmdHelper* gles2_helper_;
131 int32 transfer_buffer_id_; 137 int32 transfer_buffer_id_;
132 gpu::gles2::GLES2Implementation* gles2_implementation_; 138 gpu::gles2::GLES2Implementation* gles2_implementation_;
133 gfx::Size size_; 139 gfx::Size size_;
134 140
141 int32 swap_buffer_tokens_[kMaxFramesPending];
142
135 Error last_error_; 143 Error last_error_;
136 144
137 DISALLOW_COPY_AND_ASSIGN(Context); 145 DISALLOW_COPY_AND_ASSIGN(Context);
138 }; 146 };
139 147
140 Context::Context(GpuChannelHost* channel, Context* parent) 148 Context::Context(GpuChannelHost* channel, Context* parent)
141 : channel_(channel), 149 : channel_(channel),
142 parent_(parent ? parent->AsWeakPtr() : base::WeakPtr<Context>()), 150 parent_(parent ? parent->AsWeakPtr() : base::WeakPtr<Context>()),
143 parent_texture_id_(0), 151 parent_texture_id_(0),
144 command_buffer_(NULL), 152 command_buffer_(NULL),
145 gles2_helper_(NULL), 153 gles2_helper_(NULL),
146 transfer_buffer_id_(0), 154 transfer_buffer_id_(0),
147 gles2_implementation_(NULL), 155 gles2_implementation_(NULL),
148 last_error_(SUCCESS) { 156 last_error_(SUCCESS) {
149 DCHECK(channel); 157 DCHECK(channel);
158 for (int i = 0; i < kMaxFramesPending; ++i)
159 swap_buffer_tokens_[i] = -1;
150 } 160 }
151 161
152 Context::~Context() { 162 Context::~Context() {
153 Destroy(); 163 Destroy();
154 } 164 }
155 165
156 bool Context::Initialize(gfx::NativeViewId view, 166 bool Context::Initialize(gfx::NativeViewId view,
157 int render_view_id, 167 int render_view_id,
158 const gfx::Size& size, 168 const gfx::Size& size,
159 const char* allowed_extensions, 169 const char* allowed_extensions,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 379
370 return true; 380 return true;
371 } 381 }
372 382
373 bool Context::SwapBuffers() { 383 bool Context::SwapBuffers() {
374 // Don't request latest error status from service. Just use the locally cached 384 // Don't request latest error status from service. Just use the locally cached
375 // information from the last flush. 385 // information from the last flush.
376 if (command_buffer_->GetLastState().error != gpu::error::kNoError) 386 if (command_buffer_->GetLastState().error != gpu::error::kNoError)
377 return false; 387 return false;
378 388
389 // Throttle until there are not too many frames pending.
390 if (swap_buffer_tokens_[0] != -1) {
391 gles2_helper_->WaitForToken(swap_buffer_tokens_[0]);
392 }
393
379 gles2_implementation_->SwapBuffers(); 394 gles2_implementation_->SwapBuffers();
395
396 // Insert a new token to throttle against for this frame.
397 for (int i = 0; i < kMaxFramesPending - 1; ++i)
398 swap_buffer_tokens_[i] = swap_buffer_tokens_[i + 1];
399 swap_buffer_tokens_[kMaxFramesPending - 1] = gles2_helper_->InsertToken();
400
380 return true; 401 return true;
381 } 402 }
382 403
383 media::VideoDecodeEngine* Context::CreateVideoDecodeEngine() { 404 media::VideoDecodeEngine* Context::CreateVideoDecodeEngine() {
384 return channel_->gpu_video_service_host()->CreateVideoDecoder( 405 return channel_->gpu_video_service_host()->CreateVideoDecoder(
385 command_buffer_->route_id()); 406 command_buffer_->route_id());
386 } 407 }
387 408
388 media::VideoDecodeContext* Context::CreateVideoDecodeContext( 409 media::VideoDecodeContext* Context::CreateVideoDecodeContext(
389 MessageLoop* message_loop, bool hardware_decoder) { 410 MessageLoop* message_loop, bool hardware_decoder) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } 584 }
564 585
565 gpu::gles2::GLES2Implementation* GetImplementation(Context* context) { 586 gpu::gles2::GLES2Implementation* GetImplementation(Context* context) {
566 if (!context) 587 if (!context)
567 return NULL; 588 return NULL;
568 589
569 return context->gles2_implementation(); 590 return context->gles2_implementation();
570 } 591 }
571 592
572 } // namespace ggl 593 } // namespace ggl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698