| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 protected: | 166 protected: |
| 167 explicit ContextProviderFromContextFactory(ContextFactory* factory) | 167 explicit ContextProviderFromContextFactory(ContextFactory* factory) |
| 168 : factory_(factory), | 168 : factory_(factory), |
| 169 destroyed_(false) {} | 169 destroyed_(false) {} |
| 170 virtual ~ContextProviderFromContextFactory() {} | 170 virtual ~ContextProviderFromContextFactory() {} |
| 171 | 171 |
| 172 bool InitializeOnMainThread() { | 172 bool InitializeOnMainThread() { |
| 173 if (context3d_) | 173 if (context3d_) |
| 174 return true; | 174 return true; |
| 175 context3d_.reset(factory_->CreateOffscreenContext()); | 175 context3d_ = factory_->CreateOffscreenContext(); |
| 176 return !!context3d_; | 176 return !!context3d_; |
| 177 } | 177 } |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 ContextFactory* factory_; | 180 ContextFactory* factory_; |
| 181 base::Lock destroyed_lock_; | 181 base::Lock destroyed_lock_; |
| 182 bool destroyed_; | 182 bool destroyed_; |
| 183 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; | 183 scoped_ptr<WebKit::WebGraphicsContext3D> context3d_; |
| 184 scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_; | 184 scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_; |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 DefaultContextFactory::DefaultContextFactory() { | 187 DefaultContextFactory::DefaultContextFactory() { |
| 188 } | 188 } |
| 189 | 189 |
| 190 DefaultContextFactory::~DefaultContextFactory() { | 190 DefaultContextFactory::~DefaultContextFactory() { |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool DefaultContextFactory::Initialize() { | 193 bool DefaultContextFactory::Initialize() { |
| 194 if (!gfx::GLSurface::InitializeOneOff() || | 194 if (!gfx::GLSurface::InitializeOneOff() || |
| 195 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { | 195 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
| 196 LOG(ERROR) << "Could not load the GL bindings"; | 196 LOG(ERROR) << "Could not load the GL bindings"; |
| 197 return false; | 197 return false; |
| 198 } | 198 } |
| 199 return true; | 199 return true; |
| 200 } | 200 } |
| 201 | 201 |
| 202 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( | 202 cc::OutputSurface* DefaultContextFactory::CreateOutputSurface( |
| 203 Compositor* compositor) { | 203 Compositor* compositor) { |
| 204 return new cc::OutputSurface( | 204 return new cc::OutputSurface(CreateContextCommon(compositor, false).Pass()); |
| 205 make_scoped_ptr(CreateContextCommon(compositor, false))); | |
| 206 } | 205 } |
| 207 | 206 |
| 208 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext() { | 207 scoped_ptr<WebKit::WebGraphicsContext3D> |
| 208 DefaultContextFactory::CreateOffscreenContext() { |
| 209 return CreateContextCommon(NULL, true); | 209 return CreateContextCommon(NULL, true); |
| 210 } | 210 } |
| 211 | 211 |
| 212 scoped_refptr<Reflector> DefaultContextFactory::CreateReflector( | 212 scoped_refptr<Reflector> DefaultContextFactory::CreateReflector( |
| 213 Compositor* mirroed_compositor, | 213 Compositor* mirroed_compositor, |
| 214 Layer* mirroring_layer) { | 214 Layer* mirroring_layer) { |
| 215 return NULL; | 215 return NULL; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void DefaultContextFactory::RemoveReflector( | 218 void DefaultContextFactory::RemoveReflector( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 238 !offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) { | 238 !offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) { |
| 239 offscreen_contexts_compositor_thread_ = | 239 offscreen_contexts_compositor_thread_ = |
| 240 ContextProviderFromContextFactory::Create(this); | 240 ContextProviderFromContextFactory::Create(this); |
| 241 } | 241 } |
| 242 return offscreen_contexts_compositor_thread_; | 242 return offscreen_contexts_compositor_thread_; |
| 243 } | 243 } |
| 244 | 244 |
| 245 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { | 245 void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
| 246 } | 246 } |
| 247 | 247 |
| 248 WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( | 248 scoped_ptr<WebKit::WebGraphicsContext3D> |
| 249 Compositor* compositor, | 249 DefaultContextFactory::CreateContextCommon(Compositor* compositor, |
| 250 bool offscreen) { | 250 bool offscreen) { |
| 251 DCHECK(offscreen || compositor); | 251 DCHECK(offscreen || compositor); |
| 252 WebKit::WebGraphicsContext3D::Attributes attrs; | 252 WebKit::WebGraphicsContext3D::Attributes attrs; |
| 253 attrs.depth = false; | 253 attrs.depth = false; |
| 254 attrs.stencil = false; | 254 attrs.stencil = false; |
| 255 attrs.antialias = false; | 255 attrs.antialias = false; |
| 256 attrs.shareResources = true; | 256 attrs.shareResources = true; |
| 257 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | 257 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; |
| 258 WebKit::WebGraphicsContext3D* context = | 258 scoped_ptr<WebKit::WebGraphicsContext3D> context( |
| 259 offscreen ? | 259 offscreen |
| 260 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( | 260 ? WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 261 attrs) : | 261 CreateOffscreenContext(attrs) |
| 262 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | 262 : WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( |
| 263 attrs, compositor->widget()); | 263 attrs, compositor->widget())); |
| 264 if (!context) | 264 if (!context) |
| 265 return NULL; | 265 return context.Pass(); |
| 266 | 266 |
| 267 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 267 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 268 if (!offscreen) { | 268 if (!offscreen) { |
| 269 context->makeContextCurrent(); | 269 context->makeContextCurrent(); |
| 270 gfx::GLContext* gl_context = gfx::GLContext::GetCurrent(); | 270 gfx::GLContext* gl_context = gfx::GLContext::GetCurrent(); |
| 271 bool vsync = !command_line->HasSwitch(switches::kDisableGpuVsync); | 271 bool vsync = !command_line->HasSwitch(switches::kDisableGpuVsync); |
| 272 gl_context->SetSwapInterval(vsync ? 1 : 0); | 272 gl_context->SetSwapInterval(vsync ? 1 : 0); |
| 273 gl_context->ReleaseCurrent(NULL); | 273 gl_context->ReleaseCurrent(NULL); |
| 274 } | 274 } |
| 275 return context; | 275 return context.Pass(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TestContextFactory::TestContextFactory() {} | 278 TestContextFactory::TestContextFactory() {} |
| 279 | 279 |
| 280 TestContextFactory::~TestContextFactory() {} | 280 TestContextFactory::~TestContextFactory() {} |
| 281 | 281 |
| 282 cc::OutputSurface* TestContextFactory::CreateOutputSurface( | 282 cc::OutputSurface* TestContextFactory::CreateOutputSurface( |
| 283 Compositor* compositor) { | 283 Compositor* compositor) { |
| 284 return new cc::OutputSurface(make_scoped_ptr(CreateOffscreenContext())); | 284 return new cc::OutputSurface(CreateOffscreenContext()); |
| 285 } | 285 } |
| 286 | 286 |
| 287 WebKit::WebGraphicsContext3D* TestContextFactory::CreateOffscreenContext() { | 287 scoped_ptr<WebKit::WebGraphicsContext3D> |
| 288 ui::TestWebGraphicsContext3D* context = new ui::TestWebGraphicsContext3D; | 288 TestContextFactory::CreateOffscreenContext() { |
| 289 scoped_ptr<ui::TestWebGraphicsContext3D> context( |
| 290 new ui::TestWebGraphicsContext3D); |
| 289 context->Initialize(); | 291 context->Initialize(); |
| 290 return context; | 292 return context.PassAs<WebKit::WebGraphicsContext3D>(); |
| 291 } | 293 } |
| 292 | 294 |
| 293 scoped_refptr<Reflector> TestContextFactory::CreateReflector( | 295 scoped_refptr<Reflector> TestContextFactory::CreateReflector( |
| 294 Compositor* mirrored_compositor, | 296 Compositor* mirrored_compositor, |
| 295 Layer* mirroring_layer) { | 297 Layer* mirroring_layer) { |
| 296 return new Reflector(); | 298 return new Reflector(); |
| 297 } | 299 } |
| 298 | 300 |
| 299 void TestContextFactory::RemoveReflector(scoped_refptr<Reflector> reflector) { | 301 void TestContextFactory::RemoveReflector(scoped_refptr<Reflector> reflector) { |
| 300 } | 302 } |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 COMPOSITOR_EXPORT void DisableTestCompositor() { | 848 COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 847 ResetImplicitFactory(); | 849 ResetImplicitFactory(); |
| 848 g_test_compositor_enabled = false; | 850 g_test_compositor_enabled = false; |
| 849 } | 851 } |
| 850 | 852 |
| 851 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { | 853 COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 852 return g_test_compositor_enabled; | 854 return g_test_compositor_enabled; |
| 853 } | 855 } |
| 854 | 856 |
| 855 } // namespace ui | 857 } // namespace ui |
| OLD | NEW |