in_process_context_factory.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/compositor/test/in_process_context_factory.h" 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/output/output_surface.h" 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/compositor/reflector.h" 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/gl/gl_implementation.h" 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/gl/gl_surface.h" 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "webkit/common/gpu/context_provider_in_process.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace ui { 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)InProcessContextFactory::InProcessContextFactory() { 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)InProcessContextFactory::~InProcessContextFactory() {} 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface( 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Compositor* compositor, 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool software_fallback) { 26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DCHECK(!software_fallback); 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) blink::WebGraphicsContext3D::Attributes attrs; 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs.depth = false; 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs.stencil = false; 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs.antialias = false; 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs.shareResources = true; 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs, compositor->widget())); 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CHECK(context3d); 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) using webkit::gpu::ContextProviderInProcess; 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_refptr<ContextProviderInProcess> context_provider = 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ContextProviderInProcess::Create(context3d.Pass(), "UICompositor"); 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return make_scoped_ptr(new cc::OutputSurface(context_provider)); 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)scoped_refptr<Reflector> InProcessContextFactory::CreateReflector( 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Compositor* mirroed_compositor, 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Layer* mirroring_layer) { 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return new Reflector(); 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void InProcessContextFactory::RemoveReflector( 53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_refptr<Reflector> reflector) {} 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)scoped_refptr<cc::ContextProvider> 56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)InProcessContextFactory::OffscreenCompositorContextProvider() { 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!offscreen_compositor_contexts_.get() || 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) !offscreen_compositor_contexts_->DestroyedOnMainThread()) { 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) offscreen_compositor_contexts_ = 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) webkit::gpu::ContextProviderInProcess::CreateOffscreen(); 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return offscreen_compositor_contexts_; 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)scoped_refptr<cc::ContextProvider> 66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)InProcessContextFactory::SharedMainThreadContextProvider() { 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (shared_main_thread_contexts_ && 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) !shared_main_thread_contexts_->DestroyedOnMainThread()) 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return shared_main_thread_contexts_; 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (ui::Compositor::WasInitializedWithThread()) { 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) shared_main_thread_contexts_ = 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) webkit::gpu::ContextProviderInProcess::CreateOffscreen(); 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } else { 751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) shared_main_thread_contexts_ = 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) static_cast<webkit::gpu::ContextProviderInProcess*>( 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) OffscreenCompositorContextProvider().get()); 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (shared_main_thread_contexts_ && 801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) !shared_main_thread_contexts_->BindToCurrentThread()) 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) shared_main_thread_contexts_ = NULL; 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return shared_main_thread_contexts_; 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {} 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool InProcessContextFactory::DoesCreateTestContexts() { return false; } 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace ui 91