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) 7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/command_line.h" 8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/threading/thread.h" 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/output/output_surface.h" 10010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "cc/test/test_shared_bitmap_manager.h" 11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ui/compositor/compositor_switches.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/compositor/reflector.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/gl/gl_implementation.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/gl/gl_surface.h" 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "webkit/common/gpu/context_provider_in_process.h" 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace ui { 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)InProcessContextFactory::InProcessContextFactory() 22010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) : shared_bitmap_manager_(new cc::TestSharedBitmapManager()) { 231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone) 241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci << "If running tests, ensure that main() is calling " 251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci << "gfx::GLSurface::InitializeOneOffForTests()"; 261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(OS_CHROMEOS) 28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch( 29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) switches::kUIDisableThreadedCompositing); 30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#else 31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool use_thread = false; 32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif 33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (use_thread) { 34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) compositor_thread_.reset(new base::Thread("Browser Compositor")); 35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) compositor_thread_->Start(); 36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)InProcessContextFactory::~InProcessContextFactory() {} 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface( 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Compositor* compositor, 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool software_fallback) { 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) DCHECK(!software_fallback); 45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) blink::WebGraphicsContext3D::Attributes attrs; 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs.depth = false; 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs.stencil = false; 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs.antialias = false; 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) attrs.shareResources = true; 50e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch bool lose_context_when_out_of_memory = true; 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( 55e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch attrs, lose_context_when_out_of_memory, compositor->widget())); 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CHECK(context3d); 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) using webkit::gpu::ContextProviderInProcess; 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) scoped_refptr<ContextProviderInProcess> context_provider = 60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) ContextProviderInProcess::Create(context3d.Pass(), "UICompositor"); 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return make_scoped_ptr(new cc::OutputSurface(context_provider)); 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)scoped_refptr<Reflector> InProcessContextFactory::CreateReflector( 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Compositor* mirroed_compositor, 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Layer* mirroring_layer) { 68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return new Reflector(); 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void InProcessContextFactory::RemoveReflector( 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_refptr<Reflector> reflector) {} 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)scoped_refptr<cc::ContextProvider> 75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)InProcessContextFactory::SharedMainThreadContextProvider() { 761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (shared_main_thread_contexts_.get() && 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) !shared_main_thread_contexts_->DestroyedOnMainThread()) 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return shared_main_thread_contexts_; 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool lose_context_when_out_of_memory = false; 815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu shared_main_thread_contexts_ = 825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu webkit::gpu::ContextProviderInProcess::CreateOffscreen( 835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu lose_context_when_out_of_memory); 841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (shared_main_thread_contexts_.get() && 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) !shared_main_thread_contexts_->BindToCurrentThread()) 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) shared_main_thread_contexts_ = NULL; 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return shared_main_thread_contexts_; 891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {} 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool InProcessContextFactory::DoesCreateTestContexts() { return false; } 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 95010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() { 96010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return shared_bitmap_manager_.get(); 97010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 98010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 99cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)base::MessageLoopProxy* InProcessContextFactory::GetCompositorMessageLoop() { 100cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!compositor_thread_) 101cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return NULL; 1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return compositor_thread_->message_loop_proxy().get(); 103cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 104cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace ui 106