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/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 Loading... |
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 27 matching lines...) Expand all Loading... |
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::WebGraphicsContext3D* DefaultContextFactory::CreateContext( |
90 Compositor* compositor) { | 127 Compositor* compositor) { |
91 return CreateContextCommon(compositor, false); | 128 return CreateContextCommon(compositor, false); |
92 } | 129 } |
93 | 130 |
| 131 WebKit::WebCompositorOutputSurface* DefaultContextFactory::CreateOutputSurface( |
| 132 Compositor* compositor) { |
| 133 return new WebGraphicsContextToOutputSurfaceAdapter( |
| 134 CreateContext(compositor)); |
| 135 } |
| 136 |
94 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { | 137 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { |
95 return CreateContextCommon(NULL, true); | 138 return CreateContextCommon(NULL, true); |
96 } | 139 } |
97 | 140 |
98 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 141 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
99 } | 142 } |
100 | 143 |
101 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( | 144 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( |
102 Compositor* compositor, | 145 Compositor* compositor, |
103 bool offscreen) { | 146 bool offscreen) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 disable_schedule_composite_ = true; | 384 disable_schedule_composite_ = true; |
342 if (root_layer_) | 385 if (root_layer_) |
343 root_layer_->SendDamagedRects(); | 386 root_layer_->SendDamagedRects(); |
344 disable_schedule_composite_ = false; | 387 disable_schedule_composite_ = false; |
345 } | 388 } |
346 | 389 |
347 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, | 390 void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
348 float scaleFactor) { | 391 float scaleFactor) { |
349 } | 392 } |
350 | 393 |
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() { | 394 WebKit::WebCompositorOutputSurface* Compositor::createOutputSurface() { |
394 if (test_compositor_enabled) { | 395 if (test_compositor_enabled) { |
395 ui::TestWebGraphicsContext3D* test_context = | 396 ui::TestWebGraphicsContext3D* test_context = |
396 new ui::TestWebGraphicsContext3D(); | 397 new ui::TestWebGraphicsContext3D(); |
397 test_context->Initialize(); | 398 test_context->Initialize(); |
398 return new WebGraphicsContextToOutputSurfaceAdapter(test_context); | 399 return new WebGraphicsContextToOutputSurfaceAdapter(test_context); |
399 } else { | 400 } else { |
400 return new WebGraphicsContextToOutputSurfaceAdapter( | 401 return ContextFactory::GetInstance()->CreateOutputSurface(this); |
401 ContextFactory::GetInstance()->CreateContext(this)); | |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 void Compositor::didRecreateOutputSurface(bool success) { | 405 void Compositor::didRecreateOutputSurface(bool success) { |
406 } | 406 } |
407 | 407 |
408 void Compositor::didCommit() { | 408 void Compositor::didCommit() { |
409 DCHECK(!IsLocked()); | 409 DCHECK(!IsLocked()); |
410 FOR_EACH_OBSERVER(CompositorObserver, | 410 FOR_EACH_OBSERVER(CompositorObserver, |
411 observer_list_, | 411 observer_list_, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 476 |
477 COMPOSITOR_EXPORT void DisableTestCompositor() { | 477 COMPOSITOR_EXPORT void DisableTestCompositor() { |
478 test_compositor_enabled = false; | 478 test_compositor_enabled = false; |
479 } | 479 } |
480 | 480 |
481 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 481 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
482 return test_compositor_enabled; | 482 return test_compositor_enabled; |
483 } | 483 } |
484 | 484 |
485 } // namespace ui | 485 } // namespace ui |
OLD | NEW |