Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 g_context_factory = instance.release(); | 56 g_context_factory = instance.release(); |
| 57 } | 57 } |
| 58 return g_context_factory; | 58 return g_context_factory; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // static | 61 // static |
| 62 void ContextFactory::SetInstance(ContextFactory* instance) { | 62 void ContextFactory::SetInstance(ContextFactory* instance) { |
| 63 g_context_factory = instance; | 63 g_context_factory = instance; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. | |
|
jonathan.backer
2012/10/26 20:31:03
Feels like this should have been in an anon namesp
ajuma
2012/10/29 17:02:26
Done.
| |
| 67 class WebGraphicsContextToOutputSurfaceAdapter : | |
| 68 public WebKit::WebCompositorOutputSurface { | |
| 69 public: | |
| 70 explicit WebGraphicsContextToOutputSurfaceAdapter( | |
| 71 WebKit::WebGraphicsContext3D* context) | |
| 72 : context3D_(context) | |
| 73 , client_(NULL) { | |
| 74 } | |
| 75 | |
| 76 virtual bool bindToClient( | |
| 77 WebKit::WebCompositorOutputSurfaceClient* client) OVERRIDE { | |
| 78 DCHECK(client); | |
| 79 if (!context3D_->makeContextCurrent()) | |
| 80 return false; | |
| 81 client_ = client; | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 virtual const Capabilities& capabilities() const OVERRIDE { | |
| 86 return capabilities_; | |
| 87 } | |
| 88 | |
| 89 virtual WebKit::WebGraphicsContext3D* context3D() const OVERRIDE { | |
| 90 return context3D_.get(); | |
| 91 } | |
| 92 | |
| 93 virtual void sendFrameToParentCompositor( | |
| 94 const WebKit::WebCompositorFrame&) OVERRIDE { | |
| 95 } | |
| 96 | |
| 97 private: | |
| 98 scoped_ptr<WebKit::WebGraphicsContext3D> context3D_; | |
| 99 Capabilities capabilities_; | |
| 100 WebKit::WebCompositorOutputSurfaceClient* client_; | |
| 101 }; | |
| 102 | |
| 66 DefaultContextFactory::DefaultContextFactory() { | 103 DefaultContextFactory::DefaultContextFactory() { |
| 67 } | 104 } |
| 68 | 105 |
| 69 DefaultContextFactory::~DefaultContextFactory() { | 106 DefaultContextFactory::~DefaultContextFactory() { |
| 70 } | 107 } |
| 71 | 108 |
| 72 bool DefaultContextFactory::Initialize() { | 109 bool DefaultContextFactory::Initialize() { |
| 73 // The following line of code exists soley to disable IO restrictions | 110 // The following line of code exists soley to disable IO restrictions |
| 74 // on this thread long enough to perform the GL bindings. | 111 // on this thread long enough to perform the GL bindings. |
| 75 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. | 112 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. |
| 76 base::ThreadRestrictions::ScopedAllowIO allow_io; | 113 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 77 if (!gfx::GLSurface::InitializeOneOff() || | 114 if (!gfx::GLSurface::InitializeOneOff() || |
| 78 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { | 115 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
| 79 LOG(ERROR) << "Could not load the GL bindings"; | 116 LOG(ERROR) << "Could not load the GL bindings"; |
| 80 return false; | 117 return false; |
| 81 } | 118 } |
| 82 return true; | 119 return true; |
| 83 } | 120 } |
| 84 | 121 |
| 85 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContext( | 122 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContext( |
| 86 Compositor* compositor) { | 123 Compositor* compositor) { |
| 87 return CreateContextCommon(compositor, false); | 124 return CreateContextCommon(compositor, false); |
| 88 } | 125 } |
| 89 | 126 |
| 127 WebKit::WebCompositorOutputSurface* DefaultContextFactory::CreateOutputSurface( | |
| 128 Compositor* compositor) { | |
| 129 return new WebGraphicsContextToOutputSurfaceAdapter( | |
| 130 CreateContext(compositor)); | |
| 131 } | |
| 132 | |
| 90 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { | 133 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { |
| 91 return CreateContextCommon(NULL, true); | 134 return CreateContextCommon(NULL, true); |
| 92 } | 135 } |
| 93 | 136 |
| 94 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 137 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
| 95 } | 138 } |
| 96 | 139 |
| 97 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( | 140 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( |
| 98 Compositor* compositor, | 141 Compositor* compositor, |
| 99 bool offscreen) { | 142 bool offscreen) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 disable_schedule_composite_ = true; | 363 disable_schedule_composite_ = true; |
| 321 if (root_layer_) | 364 if (root_layer_) |
| 322 root_layer_->SendDamagedRects(); | 365 root_layer_->SendDamagedRects(); |
| 323 disable_schedule_composite_ = false; | 366 disable_schedule_composite_ = false; |
| 324 } | 367 } |
| 325 | 368 |
| 326 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 369 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
| 327 float scaleFactor) { | 370 float scaleFactor) { |
| 328 } | 371 } |
| 329 | 372 |
| 330 // Adapts a pure WebGraphicsContext3D into a WebCompositorOutputSurface. | |
| 331 class WebGraphicsContextToOutputSurfaceAdapter : | |
| 332 public WebKit::WebCompositorOutputSurface { | |
| 333 public: | |
| 334 explicit WebGraphicsContextToOutputSurfaceAdapter( | |
| 335 WebKit::WebGraphicsContext3D* context) | |
| 336 : m_context3D(context) | |
| 337 , m_client(0) | |
| 338 { | |
| 339 } | |
| 340 | |
| 341 virtual bool bindToClient( | |
| 342 WebKit::WebCompositorOutputSurfaceClient* client) OVERRIDE | |
| 343 { | |
| 344 DCHECK(client); | |
| 345 if (!m_context3D->makeContextCurrent()) | |
| 346 return false; | |
| 347 m_client = client; | |
| 348 return true; | |
| 349 } | |
| 350 | |
| 351 virtual const Capabilities& capabilities() const OVERRIDE | |
| 352 { | |
| 353 return m_capabilities; | |
| 354 } | |
| 355 | |
| 356 virtual WebKit::WebGraphicsContext3D* context3D() const OVERRIDE | |
| 357 { | |
| 358 return m_context3D.get(); | |
| 359 } | |
| 360 | |
| 361 virtual void sendFrameToParentCompositor( | |
| 362 const WebKit::WebCompositorFrame&) OVERRIDE | |
| 363 { | |
| 364 } | |
| 365 | |
| 366 private: | |
| 367 scoped_ptr<WebKit::WebGraphicsContext3D> m_context3D; | |
| 368 Capabilities m_capabilities; | |
| 369 WebKit::WebCompositorOutputSurfaceClient* m_client; | |
| 370 }; | |
| 371 | |
| 372 WebKit::WebCompositorOutputSurface* Compositor::createOutputSurface() { | 373 WebKit::WebCompositorOutputSurface* Compositor::createOutputSurface() { |
| 373 if (test_compositor_enabled) { | 374 if (test_compositor_enabled) { |
| 374 ui::TestWebGraphicsContext3D* test_context = | 375 ui::TestWebGraphicsContext3D* test_context = |
| 375 new ui::TestWebGraphicsContext3D(); | 376 new ui::TestWebGraphicsContext3D(); |
| 376 test_context->Initialize(); | 377 test_context->Initialize(); |
| 377 return new WebGraphicsContextToOutputSurfaceAdapter(test_context); | 378 return new WebGraphicsContextToOutputSurfaceAdapter(test_context); |
| 378 } else { | 379 } else { |
| 379 return new WebGraphicsContextToOutputSurfaceAdapter( | 380 return ContextFactory::GetInstance()->CreateOutputSurface(this); |
| 380 ContextFactory::GetInstance()->CreateContext(this)); | |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 | 383 |
| 384 void Compositor::didRecreateOutputSurface(bool success) { | 384 void Compositor::didRecreateOutputSurface(bool success) { |
| 385 } | 385 } |
| 386 | 386 |
| 387 // Called once per draw in single-threaded compositor mode and potentially | 387 // Called once per draw in single-threaded compositor mode and potentially |
| 388 // many times between draws in the multi-threaded compositor mode. | 388 // many times between draws in the multi-threaded compositor mode. |
| 389 void Compositor::didCommit() { | 389 void Compositor::didCommit() { |
| 390 FOR_EACH_OBSERVER(CompositorObserver, | 390 FOR_EACH_OBSERVER(CompositorObserver, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 | 435 |
| 436 COMPOSITOR_EXPORT void DisableTestCompositor() { | 436 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 437 test_compositor_enabled = false; | 437 test_compositor_enabled = false; |
| 438 } | 438 } |
| 439 | 439 |
| 440 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 440 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 441 return test_compositor_enabled; | 441 return test_compositor_enabled; |
| 442 } | 442 } |
| 443 | 443 |
| 444 } // namespace ui | 444 } // namespace ui |
| OLD | NEW |