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

Side by Side Diff: ui/compositor/compositor.cc

Issue 11195011: Send vsync timebase updates to the browser compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased again. Created 8 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
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/gl/generate_bindings.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/compositor.h" 5 #include "ui/compositor/compositor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 26 matching lines...) Expand all
37 const double kTestRefreshRate = 100.0; 37 const double kTestRefreshRate = 100.0;
38 38
39 webkit_glue::WebThreadImpl* g_compositor_thread = NULL; 39 webkit_glue::WebThreadImpl* g_compositor_thread = NULL;
40 40
41 bool test_compositor_enabled = false; 41 bool test_compositor_enabled = false;
42 42
43 ui::ContextFactory* g_context_factory = NULL; 43 ui::ContextFactory* g_context_factory = NULL;
44 44
45 const int kCompositorLockTimeoutMs = 67; 45 const int kCompositorLockTimeoutMs = 67;
46 46
47 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface.
48 class WebGraphicsContextToOutputSurfaceAdapter :
49 public WebKit::WebCompositorOutputSurface {
50 public:
51 explicit WebGraphicsContextToOutputSurfaceAdapter(
52 WebKit::WebGraphicsContext3D* context)
53 : context3D_(context),
54 client_(NULL) {
55 }
56
57 virtual bool bindToClient(
58 WebKit::WebCompositorOutputSurfaceClient* client) OVERRIDE {
59 DCHECK(client);
60 if (!context3D_->makeContextCurrent())
61 return false;
62 client_ = client;
63 return true;
64 }
65
66 virtual const Capabilities& capabilities() const OVERRIDE {
67 return capabilities_;
68 }
69
70 virtual WebKit::WebGraphicsContext3D* context3D() const OVERRIDE {
71 return context3D_.get();
72 }
73
74 virtual void sendFrameToParentCompositor(
75 const WebKit::WebCompositorFrame&) OVERRIDE {
76 }
77
78 private:
79 scoped_ptr<WebKit::WebGraphicsContext3D> context3D_;
80 Capabilities capabilities_;
81 WebKit::WebCompositorOutputSurfaceClient* client_;
82 };
83
47 } // namespace 84 } // namespace
48 85
49 namespace ui { 86 namespace ui {
50 87
51 // static 88 // static
52 ContextFactory* ContextFactory::GetInstance() { 89 ContextFactory* ContextFactory::GetInstance() {
53 // We leak the shared resources so that we don't race with 90 // We leak the shared resources so that we don't race with
54 // the tear down of the gl_bindings. 91 // the tear down of the gl_bindings.
55 if (!g_context_factory) { 92 if (!g_context_factory) {
56 DVLOG(1) << "Using DefaultSharedResource"; 93 DVLOG(1) << "Using DefaultSharedResource";
(...skipping 22 matching lines...) Expand all
79 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. 116 // TODO(wjmaclean) Remove this when GL initialisation cleaned up.
80 base::ThreadRestrictions::ScopedAllowIO allow_io; 117 base::ThreadRestrictions::ScopedAllowIO allow_io;
81 if (!gfx::GLSurface::InitializeOneOff() || 118 if (!gfx::GLSurface::InitializeOneOff() ||
82 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { 119 gfx::GetGLImplementation() == gfx::kGLImplementationNone) {
83 LOG(ERROR) << "Could not load the GL bindings"; 120 LOG(ERROR) << "Could not load the GL bindings";
84 return false; 121 return false;
85 } 122 }
86 return true; 123 return true;
87 } 124 }
88 125
89 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContext( 126 WebKit::WebCompositorOutputSurface* DefaultContextFactory::CreateOutputSurface(
90 Compositor* compositor) { 127 Compositor* compositor) {
91 return CreateContextCommon(compositor, false); 128 return new WebGraphicsContextToOutputSurfaceAdapter(
129 CreateContextCommon(compositor, false));
92 } 130 }
93 131
94 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { 132 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() {
95 return CreateContextCommon(NULL, true); 133 return CreateContextCommon(NULL, true);
96 } 134 }
97 135
98 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { 136 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) {
99 } 137 }
100 138
101 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( 139 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon(
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 disable_schedule_composite_ = true; 379 disable_schedule_composite_ = true;
342 if (root_layer_) 380 if (root_layer_)
343 root_layer_->SendDamagedRects(); 381 root_layer_->SendDamagedRects();
344 disable_schedule_composite_ = false; 382 disable_schedule_composite_ = false;
345 } 383 }
346 384
347 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, 385 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta,
348 float scaleFactor) { 386 float scaleFactor) {
349 } 387 }
350 388
351 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface.
352 class WebGraphicsContextToOutputSurfaceAdapter :
353 public WebKit::WebCompositorOutputSurface {
354 public:
355 explicit WebGraphicsContextToOutputSurfaceAdapter(
356 WebKit::WebGraphicsContext3D* context)
357 : m_context3D(context)
358 , m_client(0)
359 {
360 }
361
362 virtual bool bindToClient(
363 WebKit::WebCompositorOutputSurfaceClient* client) OVERRIDE
364 {
365 DCHECK(client);
366 if (!m_context3D->makeContextCurrent())
367 return false;
368 m_client = client;
369 return true;
370 }
371
372 virtual const Capabilities& capabilities() const OVERRIDE
373 {
374 return m_capabilities;
375 }
376
377 virtual WebKit::WebGraphicsContext3D* context3D() const OVERRIDE
378 {
379 return m_context3D.get();
380 }
381
382 virtual void sendFrameToParentCompositor(
383 const WebKit::WebCompositorFrame&) OVERRIDE
384 {
385 }
386
387 private:
388 scoped_ptr<WebKit::WebGraphicsContext3D> m_context3D;
389 Capabilities m_capabilities;
390 WebKit::WebCompositorOutputSurfaceClient* m_client;
391 };
392
393 WebKit::WebCompositorOutputSurface* Compositor::createOutputSurface() { 389 WebKit::WebCompositorOutputSurface* Compositor::createOutputSurface() {
394 if (test_compositor_enabled) { 390 if (test_compositor_enabled) {
395 ui::TestWebGraphicsContext3D* test_context = 391 ui::TestWebGraphicsContext3D* test_context =
396 new ui::TestWebGraphicsContext3D(); 392 new ui::TestWebGraphicsContext3D();
397 test_context->Initialize(); 393 test_context->Initialize();
398 return new WebGraphicsContextToOutputSurfaceAdapter(test_context); 394 return new WebGraphicsContextToOutputSurfaceAdapter(test_context);
399 } else { 395 } else {
400 return new WebGraphicsContextToOutputSurfaceAdapter( 396 return ContextFactory::GetInstance()->CreateOutputSurface(this);
401 ContextFactory::GetInstance()->CreateContext(this));
402 } 397 }
403 } 398 }
404 399
405 void Compositor::didRecreateOutputSurface(bool success) { 400 void Compositor::didRecreateOutputSurface(bool success) {
406 } 401 }
407 402
408 void Compositor::didCommit() { 403 void Compositor::didCommit() {
409 DCHECK(!IsLocked()); 404 DCHECK(!IsLocked());
410 FOR_EACH_OBSERVER(CompositorObserver, 405 FOR_EACH_OBSERVER(CompositorObserver,
411 observer_list_, 406 observer_list_,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 471
477 COMPOSITOR_EXPORT void DisableTestCompositor() { 472 COMPOSITOR_EXPORT void DisableTestCompositor() {
478 test_compositor_enabled = false; 473 test_compositor_enabled = false;
479 } 474 }
480 475
481 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { 476 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() {
482 return test_compositor_enabled; 477 return test_compositor_enabled;
483 } 478 }
484 479
485 } // namespace ui 480 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/gl/generate_bindings.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698