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 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
| 23 #include "ui/compositor/compositor_observer.h" | 23 #include "ui/compositor/compositor_observer.h" |
| 24 #include "ui/compositor/compositor_switches.h" | 24 #include "ui/compositor/compositor_switches.h" |
| 25 #include "ui/compositor/dip_util.h" | 25 #include "ui/compositor/dip_util.h" |
| 26 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
| 27 #include "ui/compositor/test_web_graphics_context_3d.h" | 27 #include "ui/compositor/test_web_graphics_context_3d.h" |
| 28 #include "ui/gl/gl_context.h" | 28 #include "ui/gl/gl_context.h" |
| 29 #include "ui/gl/gl_implementation.h" | 29 #include "ui/gl/gl_implementation.h" |
| 30 #include "ui/gl/gl_surface.h" | 30 #include "ui/gl/gl_surface.h" |
| 31 #include "ui/gl/gl_switches.h" | 31 #include "ui/gl/gl_switches.h" |
| 32 #include "webkit/gpu/grcontext_for_webgraphicscontext3d.h" | |
| 32 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" | 33 #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
| 33 | 34 |
| 34 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 35 #include "base/chromeos/chromeos_version.h" | 36 #include "base/chromeos/chromeos_version.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 const double kDefaultRefreshRate = 60.0; | 41 const double kDefaultRefreshRate = 60.0; |
| 41 const double kTestRefreshRate = 100.0; | 42 const double kTestRefreshRate = 100.0; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 g_context_factory = instance; | 135 g_context_factory = instance; |
| 135 } | 136 } |
| 136 | 137 |
| 137 DefaultContextFactory::DefaultContextFactory() { | 138 DefaultContextFactory::DefaultContextFactory() { |
| 138 } | 139 } |
| 139 | 140 |
| 140 DefaultContextFactory::~DefaultContextFactory() { | 141 DefaultContextFactory::~DefaultContextFactory() { |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool DefaultContextFactory::Initialize() { | 144 bool DefaultContextFactory::Initialize() { |
| 145 if (g_test_compositor_enabled) | |
| 146 return true; | |
| 147 | |
| 144 // The following line of code exists soley to disable IO restrictions | 148 // The following line of code exists soley to disable IO restrictions |
| 145 // on this thread long enough to perform the GL bindings. | 149 // on this thread long enough to perform the GL bindings. |
| 146 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. | 150 // TODO(wjmaclean) Remove this when GL initialisation cleaned up. |
| 147 base::ThreadRestrictions::ScopedAllowIO allow_io; | 151 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 148 if (!gfx::GLSurface::InitializeOneOff() || | 152 if (!gfx::GLSurface::InitializeOneOff() || |
| 149 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { | 153 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
| 150 LOG(ERROR) << "Could not load the GL bindings"; | 154 LOG(ERROR) << "Could not load the GL bindings"; |
| 151 return false; | 155 return false; |
| 152 } | 156 } |
| 153 return true; | 157 return true; |
| 154 } | 158 } |
| 155 | 159 |
| 156 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( | 160 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( |
| 157 Compositor* compositor) { | 161 Compositor* compositor) { |
| 158 return new WebGraphicsContextToOutputSurfaceAdapter( | 162 return new WebGraphicsContextToOutputSurfaceAdapter( |
| 159 CreateContextCommon(compositor, false)); | 163 CreateContextCommon(compositor, false)); |
| 160 } | 164 } |
| 161 | 165 |
| 162 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { | 166 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { |
| 163 return CreateContextCommon(NULL, true); | 167 return CreateContextCommon(NULL, true); |
| 164 } | 168 } |
| 165 | 169 |
| 170 WebKit::WebGraphicsContext3D* | |
| 171 DefaultContextFactory::OffscreenContextForMainThread() { | |
| 172 if (!test_offscreen_context_main_thread_) { | |
| 173 scoped_ptr<ui::TestWebGraphicsContext3D> test_context( | |
|
piman
2013/02/13 19:13:31
Mmh, we should only be creating TestWGC3D-type con
danakj
2013/02/13 20:47:10
The downside to this is that then we need storage
piman
2013/02/14 00:16:08
Why couldn't they still be fields in DefaultContex
| |
| 174 new ui::TestWebGraphicsContext3D()); | |
| 175 test_context->Initialize(); | |
| 176 test_offscreen_context_main_thread_ = | |
| 177 test_context.PassAs<WebKit::WebGraphicsContext3D>(); | |
| 178 } | |
| 179 return test_offscreen_context_main_thread_.get(); | |
| 180 } | |
| 181 | |
| 182 WebKit::WebGraphicsContext3D* | |
| 183 DefaultContextFactory::OffscreenContextForCompositorThread() { | |
| 184 if (!test_offscreen_context_compositor_thread_) { | |
| 185 scoped_ptr<ui::TestWebGraphicsContext3D> test_context( | |
| 186 new ui::TestWebGraphicsContext3D()); | |
| 187 test_context->Initialize(); | |
| 188 test_offscreen_context_compositor_thread_ = | |
| 189 test_context.PassAs<WebKit::WebGraphicsContext3D>(); | |
| 190 } | |
| 191 return test_offscreen_context_compositor_thread_.get(); | |
| 192 } | |
| 193 | |
| 194 GrContext* DefaultContextFactory::OffscreenGrContextForMainThread() { | |
| 195 if (!grcontext_main_thread_ && test_offscreen_context_main_thread_) { | |
| 196 grcontext_main_thread_.reset( | |
| 197 new webkit::gpu::GrContextForWebGraphicsContext3D( | |
| 198 test_offscreen_context_main_thread_.get())); | |
| 199 } | |
| 200 return grcontext_main_thread_->gr_context(); | |
| 201 } | |
| 202 | |
| 203 GrContext* DefaultContextFactory::OffscreenGrContextForCompositorThread() { | |
| 204 if (!grcontext_compositor_thread_ && | |
| 205 test_offscreen_context_compositor_thread_) { | |
| 206 grcontext_compositor_thread_.reset( | |
| 207 new webkit::gpu::GrContextForWebGraphicsContext3D( | |
| 208 test_offscreen_context_compositor_thread_.get())); | |
| 209 } | |
| 210 return grcontext_compositor_thread_->gr_context(); | |
| 211 } | |
| 212 | |
| 213 void DefaultContextFactory::DestroyOffscreenContext3dForCompositorThread() { | |
| 214 test_offscreen_context_compositor_thread_.reset(); | |
| 215 } | |
| 216 | |
| 166 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 217 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
| 167 } | 218 } |
| 168 | 219 |
| 169 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( | 220 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( |
| 170 Compositor* compositor, | 221 Compositor* compositor, |
| 171 bool offscreen) { | 222 bool offscreen) { |
| 172 DCHECK(offscreen || compositor); | 223 DCHECK(offscreen || compositor); |
| 173 WebKit::WebGraphicsContext3D::Attributes attrs; | 224 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 174 attrs.depth = false; | 225 attrs.depth = false; |
| 175 attrs.stencil = false; | 226 attrs.stencil = false; |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 new WebGraphicsContextToOutputSurfaceAdapter(test_context)); | 565 new WebGraphicsContextToOutputSurfaceAdapter(test_context)); |
| 515 } else { | 566 } else { |
| 516 return scoped_ptr<cc::OutputSurface>( | 567 return scoped_ptr<cc::OutputSurface>( |
| 517 ContextFactory::GetInstance()->CreateOutputSurface(this)); | 568 ContextFactory::GetInstance()->CreateOutputSurface(this)); |
| 518 } | 569 } |
| 519 } | 570 } |
| 520 | 571 |
| 521 void Compositor::didRecreateOutputSurface(bool success) { | 572 void Compositor::didRecreateOutputSurface(bool success) { |
| 522 } | 573 } |
| 523 | 574 |
| 575 WebKit::WebGraphicsContext3D* | |
| 576 Compositor::OffscreenContext3dForMainThread() { | |
| 577 return ContextFactory::GetInstance()->OffscreenContextForMainThread(); | |
| 578 } | |
| 579 | |
| 580 WebKit::WebGraphicsContext3D* | |
| 581 Compositor::OffscreenContext3dForCompositorThread() { | |
| 582 return ContextFactory::GetInstance()->OffscreenContextForCompositorThread(); | |
| 583 } | |
| 584 | |
| 585 GrContext* Compositor::OffscreenGrContextForMainThread() { | |
| 586 return ContextFactory::GetInstance()->OffscreenGrContextForMainThread(); | |
| 587 } | |
| 588 | |
| 589 GrContext* Compositor::OffscreenGrContextForCompositorThread() { | |
| 590 return ContextFactory::GetInstance()->OffscreenGrContextForCompositorThread(); | |
| 591 } | |
| 592 | |
| 593 void Compositor::DestroyOffscreenContext3dForCompositorThread() { | |
| 594 ContextFactory::GetInstance()->DestroyOffscreenContext3dForCompositorThread(); | |
| 595 } | |
| 596 | |
| 524 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() { | 597 scoped_ptr<cc::InputHandler> Compositor::createInputHandler() { |
| 525 return scoped_ptr<cc::InputHandler>(); | 598 return scoped_ptr<cc::InputHandler>(); |
| 526 } | 599 } |
| 527 | 600 |
| 528 void Compositor::willCommit() { | 601 void Compositor::willCommit() { |
| 529 } | 602 } |
| 530 | 603 |
| 531 void Compositor::didCommit() { | 604 void Compositor::didCommit() { |
| 532 DCHECK(!IsLocked()); | 605 DCHECK(!IsLocked()); |
| 533 FOR_EACH_OBSERVER(CompositorObserver, | 606 FOR_EACH_OBSERVER(CompositorObserver, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 | 677 |
| 605 COMPOSITOR_EXPORT void DisableTestCompositor() { | 678 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 606 g_test_compositor_enabled = false; | 679 g_test_compositor_enabled = false; |
| 607 } | 680 } |
| 608 | 681 |
| 609 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 682 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 610 return g_test_compositor_enabled; | 683 return g_test_compositor_enabled; |
| 611 } | 684 } |
| 612 | 685 |
| 613 } // namespace ui | 686 } // namespace ui |
| OLD | NEW |