in_process_context_factory.cc revision 010d83a9304c5a91596085d917d248abff47903a
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "ui/compositor/test/in_process_context_factory.h" 6 7#include "cc/output/output_surface.h" 8#include "cc/test/test_shared_bitmap_manager.h" 9#include "ui/compositor/reflector.h" 10#include "ui/gl/gl_implementation.h" 11#include "ui/gl/gl_surface.h" 12#include "webkit/common/gpu/context_provider_in_process.h" 13#include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" 14#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 15 16namespace ui { 17 18InProcessContextFactory::InProcessContextFactory() 19 : shared_bitmap_manager_(new cc::TestSharedBitmapManager()) { 20 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone); 21} 22 23InProcessContextFactory::~InProcessContextFactory() {} 24 25scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface( 26 Compositor* compositor, 27 bool software_fallback) { 28 DCHECK(!software_fallback); 29 blink::WebGraphicsContext3D::Attributes attrs; 30 attrs.depth = false; 31 attrs.stencil = false; 32 attrs.antialias = false; 33 attrs.shareResources = true; 34 bool lose_context_when_out_of_memory = true; 35 36 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; 37 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( 38 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( 39 attrs, lose_context_when_out_of_memory, compositor->widget())); 40 CHECK(context3d); 41 42 using webkit::gpu::ContextProviderInProcess; 43 scoped_refptr<ContextProviderInProcess> context_provider = 44 ContextProviderInProcess::Create(context3d.Pass(), "UICompositor"); 45 46 return make_scoped_ptr(new cc::OutputSurface(context_provider)); 47} 48 49scoped_refptr<Reflector> InProcessContextFactory::CreateReflector( 50 Compositor* mirroed_compositor, 51 Layer* mirroring_layer) { 52 return new Reflector(); 53} 54 55void InProcessContextFactory::RemoveReflector( 56 scoped_refptr<Reflector> reflector) {} 57 58scoped_refptr<cc::ContextProvider> 59InProcessContextFactory::SharedMainThreadContextProvider() { 60 if (shared_main_thread_contexts_ && 61 !shared_main_thread_contexts_->DestroyedOnMainThread()) 62 return shared_main_thread_contexts_; 63 64 bool lose_context_when_out_of_memory = false; 65 shared_main_thread_contexts_ = 66 webkit::gpu::ContextProviderInProcess::CreateOffscreen( 67 lose_context_when_out_of_memory); 68 if (shared_main_thread_contexts_ && 69 !shared_main_thread_contexts_->BindToCurrentThread()) 70 shared_main_thread_contexts_ = NULL; 71 72 return shared_main_thread_contexts_; 73} 74 75void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {} 76 77bool InProcessContextFactory::DoesCreateTestContexts() { return false; } 78 79cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() { 80 return shared_bitmap_manager_.get(); 81} 82 83} // namespace ui 84