summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/ggl
diff options
context:
space:
mode:
authorkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-26 20:16:18 +0000
committerkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-26 20:16:18 +0000
commit33da8041706bbe87ec9ff8d95854bf7075ab2d7a (patch)
tree518fd9b01ac6355816acd64bfb7f9ce037274598 /chrome/renderer/ggl
parent76d20290e1a84f5a18c63c0f905062b986f01f55 (diff)
downloadchromium_src-33da8041706bbe87ec9ff8d95854bf7075ab2d7a.zip
chromium_src-33da8041706bbe87ec9ff8d95854bf7075ab2d7a.tar.gz
chromium_src-33da8041706bbe87ec9ff8d95854bf7075ab2d7a.tar.bz2
Add flow control between renderer and GPU processes, and, on Mac OS X,
between GPU process and browser process. Thanks to Al Patrick for the renderer<->GPU flow control mechanism. This CL prevents the renderer from issuing more OpenGL work than the GPU process can execute, and, on the Mac, prevents the combination of the renderer and GPU processes from transmitting more frames via IOSurfaces from the GPU to the browser process than can be handled by the GPU. This fix causes the renderer to block inside ggl::SwapBuffers() when it gets too far ahead. Different strategies can be considered going forward, including measuring frame rates in the GPU and renderer processes and trying to match them via techniques such as delaying the execution of some timers. However, despite the general undesirability of blocking the render thread, this fix results in a significant performance improvement. With this fix integrated, a fill-limited test case from Chris Rogers displays at 60 FPS instead of 15 FPS on a Mac Pro. Gregg Tavares' aquarium from webglsamples.googlecode.com displays at 30 FPS instead of 4 or 5 FPS on a MacBook Pro. The frame rates measured at the JavaScript level now match the actual frame rate of the browser, where previously they were much higher since they were issuing more work than the browser could render. A few other minor OpenGL bugs potentially impacting the correctness of the Mac compositor are being fixed as well in this CL. Verified that WebGL, CSS 3D and YouTube (Core Animation plugin) content all work. BUG=63539 TEST=none Review URL: http://codereview.chromium.org/5317007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67470 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/ggl')
-rw-r--r--chrome/renderer/ggl/ggl.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/chrome/renderer/ggl/ggl.cc b/chrome/renderer/ggl/ggl.cc
index b983514..6cd9a33 100644
--- a/chrome/renderer/ggl/ggl.cc
+++ b/chrome/renderer/ggl/ggl.cc
@@ -34,6 +34,12 @@ const int32 kCommandBufferSize = 1024 * 1024;
// creation attributes.
const int32 kTransferBufferSize = 1024 * 1024;
+// TODO(kbr) / TODO(apatrick): determine the best number of pending frames
+// in the general case. On Mac OS X it seems we really want this to be 1,
+// because otherwise the renderer process produces frames that do not
+// actually reach the screen.
+const int kMaxFramesPending = 1;
+
// Singleton used to initialize and terminate the gles2 library.
class GLES2Initializer {
public:
@@ -132,6 +138,8 @@ class Context : public base::SupportsWeakPtr<Context> {
gpu::gles2::GLES2Implementation* gles2_implementation_;
gfx::Size size_;
+ int32 swap_buffer_tokens_[kMaxFramesPending];
+
Error last_error_;
DISALLOW_COPY_AND_ASSIGN(Context);
@@ -147,6 +155,8 @@ Context::Context(GpuChannelHost* channel, Context* parent)
gles2_implementation_(NULL),
last_error_(SUCCESS) {
DCHECK(channel);
+ for (int i = 0; i < kMaxFramesPending; ++i)
+ swap_buffer_tokens_[i] = -1;
}
Context::~Context() {
@@ -376,7 +386,18 @@ bool Context::SwapBuffers() {
if (command_buffer_->GetLastState().error != gpu::error::kNoError)
return false;
+ // Throttle until there are not too many frames pending.
+ if (swap_buffer_tokens_[0] != -1) {
+ gles2_helper_->WaitForToken(swap_buffer_tokens_[0]);
+ }
+
gles2_implementation_->SwapBuffers();
+
+ // Insert a new token to throttle against for this frame.
+ for (int i = 0; i < kMaxFramesPending - 1; ++i)
+ swap_buffer_tokens_[i] = swap_buffer_tokens_[i + 1];
+ swap_buffer_tokens_[kMaxFramesPending - 1] = gles2_helper_->InsertToken();
+
return true;
}