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. | |
67 class WebGraphicsContextToOutputSurfaceAdapter : | |
68 public WebKit::WebCompositorOutputSurface { | |
69 public: | |
piman
2012/10/24 16:56:54
nit: Chrome style please for all of this class.
ajuma
2012/10/26 20:12:39
Done.
| |
70 explicit WebGraphicsContextToOutputSurfaceAdapter( | |
71 WebKit::WebGraphicsContext3D* context) | |
72 : m_context3D(context) | |
73 , m_client(0) | |
74 { | |
75 } | |
76 | |
77 virtual bool bindToClient( | |
78 WebKit::WebCompositorOutputSurfaceClient* client) OVERRIDE | |
79 { | |
80 DCHECK(client); | |
81 if (!m_context3D->makeContextCurrent()) | |
82 return false; | |
83 m_client = client; | |
84 return true; | |
85 } | |
86 | |
87 virtual const Capabilities& capabilities() const OVERRIDE | |
88 { | |
89 return m_capabilities; | |
90 } | |
91 | |
92 virtual WebKit::WebGraphicsContext3D* context3D() const OVERRIDE | |
93 { | |
94 return m_context3D.get(); | |
95 } | |
96 | |
97 virtual void sendFrameToParentCompositor( | |
98 const WebKit::WebCompositorFrame&) OVERRIDE | |
99 { | |
100 } | |
101 | |
102 private: | |
103 scoped_ptr<WebKit::WebGraphicsContext3D> m_context3D; | |
104 Capabilities m_capabilities; | |
105 WebKit::WebCompositorOutputSurfaceClient* m_client; | |
106 }; | |
107 | |
66 DefaultContextFactory::DefaultContextFactory() { | 108 DefaultContextFactory::DefaultContextFactory() { |
67 } | 109 } |
68 | 110 |
69 DefaultContextFactory::~DefaultContextFactory() { | 111 DefaultContextFactory::~DefaultContextFactory() { |
70 } | 112 } |
71 | 113 |
72 bool DefaultContextFactory::Initialize() { | 114 bool DefaultContextFactory::Initialize() { |
73 // The following line of code exists soley to disable IO restrictions | 115 // The following line of code exists soley to disable IO restrictions |
74 // on this thread long enough to perform the GL bindings. | 116 // on this thread long enough to perform the GL bindings. |
75 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. | 117 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. |
76 base::ThreadRestrictions::ScopedAllowIO allow_io; | 118 base::ThreadRestrictions::ScopedAllowIO allow_io; |
77 if (!gfx::GLSurface::InitializeOneOff() || | 119 if (!gfx::GLSurface::InitializeOneOff() || |
78 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { | 120 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
79 LOG(ERROR) << "Could not load the GL bindings"; | 121 LOG(ERROR) << "Could not load the GL bindings"; |
80 return false; | 122 return false; |
81 } | 123 } |
82 return true; | 124 return true; |
83 } | 125 } |
84 | 126 |
85 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContext( | 127 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContext( |
86 Compositor* compositor) { | 128 Compositor* compositor) { |
87 return CreateContextCommon(compositor, false); | 129 return CreateContextCommon(compositor, false); |
88 } | 130 } |
89 | 131 |
132 WebKit::WebCompositorOutputSurface* DefaultContextFactory::CreateOutputSurface( | |
133 Compositor* compositor) { | |
134 return new WebGraphicsContextToOutputSurfaceAdapter( | |
135 CreateContext(compositor)); | |
136 } | |
137 | |
90 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { | 138 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { |
91 return CreateContextCommon(NULL, true); | 139 return CreateContextCommon(NULL, true); |
92 } | 140 } |
93 | 141 |
94 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 142 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
95 } | 143 } |
96 | 144 |
97 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( | 145 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( |
98 Compositor* compositor, | 146 Compositor* compositor, |
99 bool offscreen) { | 147 bool offscreen) { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 disable_schedule_composite_ = true; | 368 disable_schedule_composite_ = true; |
321 if (root_layer_) | 369 if (root_layer_) |
322 root_layer_->SendDamagedRects(); | 370 root_layer_->SendDamagedRects(); |
323 disable_schedule_composite_ = false; | 371 disable_schedule_composite_ = false; |
324 } | 372 } |
325 | 373 |
326 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 374 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
327 float scaleFactor) { | 375 float scaleFactor) { |
328 } | 376 } |
329 | 377 |
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() { | 378 WebKit::WebCompositorOutputSurface* Compositor::createOutputSurface() { |
373 if (test_compositor_enabled) { | 379 if (test_compositor_enabled) { |
374 ui::TestWebGraphicsContext3D* test_context = | 380 ui::TestWebGraphicsContext3D* test_context = |
375 new ui::TestWebGraphicsContext3D(); | 381 new ui::TestWebGraphicsContext3D(); |
376 test_context->Initialize(); | 382 test_context->Initialize(); |
377 return new WebGraphicsContextToOutputSurfaceAdapter(test_context); | 383 return new WebGraphicsContextToOutputSurfaceAdapter(test_context); |
378 } else { | 384 } else { |
379 return new WebGraphicsContextToOutputSurfaceAdapter( | 385 return ContextFactory::GetInstance()->CreateOutputSurface(this); |
380 ContextFactory::GetInstance()->CreateContext(this)); | |
381 } | 386 } |
382 } | 387 } |
383 | 388 |
384 void Compositor::didRecreateOutputSurface(bool success) { | 389 void Compositor::didRecreateOutputSurface(bool success) { |
385 } | 390 } |
386 | 391 |
387 // Called once per draw in single-threaded compositor mode and potentially | 392 // Called once per draw in single-threaded compositor mode and potentially |
388 // many times between draws in the multi-threaded compositor mode. | 393 // many times between draws in the multi-threaded compositor mode. |
389 void Compositor::didCommit() { | 394 void Compositor::didCommit() { |
390 FOR_EACH_OBSERVER(CompositorObserver, | 395 FOR_EACH_OBSERVER(CompositorObserver, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 | 440 |
436 COMPOSITOR_EXPORT void DisableTestCompositor() { | 441 COMPOSITOR_EXPORT void DisableTestCompositor() { |
437 test_compositor_enabled = false; | 442 test_compositor_enabled = false; |
438 } | 443 } |
439 | 444 |
440 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 445 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
441 return test_compositor_enabled; | 446 return test_compositor_enabled; |
442 } | 447 } |
443 | 448 |
444 } // namespace ui | 449 } // namespace ui |
OLD | NEW |