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 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 g_context_factory = instance.release(); | 127 g_context_factory = instance.release(); |
128 } | 128 } |
129 return g_context_factory; | 129 return g_context_factory; |
130 } | 130 } |
131 | 131 |
132 // static | 132 // static |
133 void ContextFactory::SetInstance(ContextFactory* instance) { | 133 void ContextFactory::SetInstance(ContextFactory* instance) { |
134 g_context_factory = instance; | 134 g_context_factory = instance; |
135 } | 135 } |
136 | 136 |
137 DefaultContextFactory::DefaultContextFactory() { | 137 DefaultContextFactory::DefaultContextFactory() |
| 138 : main_thread_offscreen_context_(this, this), |
| 139 compositor_thread_offscreen_context_(this, this) { |
138 } | 140 } |
139 | 141 |
140 DefaultContextFactory::~DefaultContextFactory() { | 142 DefaultContextFactory::~DefaultContextFactory() { |
141 } | 143 } |
142 | 144 |
143 bool DefaultContextFactory::Initialize() { | 145 bool DefaultContextFactory::Initialize() { |
144 // The following line of code exists soley to disable IO restrictions | 146 // The following line of code exists soley to disable IO restrictions |
145 // on this thread long enough to perform the GL bindings. | 147 // on this thread long enough to perform the GL bindings. |
146 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. | 148 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. |
147 base::ThreadRestrictions::ScopedAllowIO allow_io; | 149 base::ThreadRestrictions::ScopedAllowIO allow_io; |
148 if (!gfx::GLSurface::InitializeOneOff() || | 150 if (!gfx::GLSurface::InitializeOneOff() || |
149 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { | 151 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
150 LOG(ERROR) << "Could not load the GL bindings"; | 152 LOG(ERROR) << "Could not load the GL bindings"; |
151 return false; | 153 return false; |
152 } | 154 } |
153 return true; | 155 return true; |
154 } | 156 } |
155 | 157 |
156 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( | 158 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( |
157 Compositor* compositor) { | 159 Compositor* compositor) { |
158 return new WebGraphicsContextToOutputSurfaceAdapter( | 160 return new WebGraphicsContextToOutputSurfaceAdapter( |
159 CreateContextCommon(compositor, false)); | 161 CreateContextCommon(compositor, false)); |
160 } | 162 } |
161 | 163 |
162 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { | 164 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { |
163 return CreateContextCommon(NULL, true); | 165 return CreateContextCommon(NULL, true); |
164 } | 166 } |
165 | 167 |
| 168 WebKit::WebGraphicsContext3D* DefaultContextFactory:: |
| 169 OffscreenContextForMainThread() { |
| 170 return main_thread_offscreen_context_.Context3d(); |
| 171 } |
| 172 |
| 173 WebKit::WebGraphicsContext3D* DefaultContextFactory:: |
| 174 OffscreenContextForCompositorThread() { |
| 175 return compositor_thread_offscreen_context_.Context3d(); |
| 176 } |
| 177 |
| 178 GrContext* DefaultContextFactory:: |
| 179 OffscreenGrContextForMainThread() { |
| 180 return main_thread_offscreen_context_.GrContext(); |
| 181 } |
| 182 |
| 183 GrContext* DefaultContextFactory:: |
| 184 OffscreenGrContextForCompositorThread() { |
| 185 return compositor_thread_offscreen_context_.GrContext(); |
| 186 } |
| 187 |
166 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 188 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
167 } | 189 } |
168 | 190 |
169 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( | 191 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( |
170 Compositor* compositor, | 192 Compositor* compositor, |
171 bool offscreen) { | 193 bool offscreen) { |
172 DCHECK(offscreen || compositor); | 194 DCHECK(offscreen || compositor); |
173 WebKit::WebGraphicsContext3D::Attributes attrs; | 195 WebKit::WebGraphicsContext3D::Attributes attrs; |
174 attrs.depth = false; | 196 attrs.depth = false; |
175 attrs.stencil = false; | 197 attrs.stencil = false; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 new WebGraphicsContextToOutputSurfaceAdapter(test_context)); | 536 new WebGraphicsContextToOutputSurfaceAdapter(test_context)); |
515 } else { | 537 } else { |
516 return scoped_ptr<cc::OutputSurface>( | 538 return scoped_ptr<cc::OutputSurface>( |
517 ContextFactory::GetInstance()->CreateOutputSurface(this)); | 539 ContextFactory::GetInstance()->CreateOutputSurface(this)); |
518 } | 540 } |
519 } | 541 } |
520 | 542 |
521 void Compositor::didRecreateOutputSurface(bool success) { | 543 void Compositor::didRecreateOutputSurface(bool success) { |
522 } | 544 } |
523 | 545 |
| 546 WebKit::WebGraphicsContext3D* |
| 547 Compositor::offscreenContext3dForMainThread() { |
| 548 return ContextFactory::GetInstance()-> |
| 549 OffscreenContextForMainThread(); |
| 550 } |
| 551 |
| 552 WebKit::WebGraphicsContext3D* |
| 553 Compositor::offscreenContext3dForCompositorThread() { |
| 554 return ContextFactory::GetInstance()-> |
| 555 OffscreenContextForCompositorThread(); |
| 556 } |
| 557 |
| 558 GrContext* Compositor::offscreenGrContextForMainThread() { |
| 559 return ContextFactory::GetInstance()-> |
| 560 OffscreenGrContextForMainThread(); |
| 561 } |
| 562 |
| 563 GrContext* Compositor::offscreenGrContextForCompositorThread() { |
| 564 return ContextFactory::GetInstance()-> |
| 565 OffscreenGrContextForCompositorThread(); |
| 566 } |
| 567 |
524 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() { | 568 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() { |
525 return scoped_ptr<cc::InputHandler>(); | 569 return scoped_ptr<cc::InputHandler>(); |
526 } | 570 } |
527 | 571 |
528 void Compositor::willCommit() { | 572 void Compositor::willCommit() { |
529 } | 573 } |
530 | 574 |
531 void Compositor::didCommit() { | 575 void Compositor::didCommit() { |
532 DCHECK(!IsLocked()); | 576 DCHECK(!IsLocked()); |
533 FOR_EACH_OBSERVER(CompositorObserver, | 577 FOR_EACH_OBSERVER(CompositorObserver, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 | 648 |
605 COMPOSITOR_EXPORT void DisableTestCompositor() { | 649 COMPOSITOR_EXPORT void DisableTestCompositor() { |
606 g_test_compositor_enabled = false; | 650 g_test_compositor_enabled = false; |
607 } | 651 } |
608 | 652 |
609 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 653 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
610 return g_test_compositor_enabled; | 654 return g_test_compositor_enabled; |
611 } | 655 } |
612 | 656 |
613 } // namespace ui | 657 } // namespace ui |
OLD | NEW |