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.
5 #include "ui/compositor/test/in_process_context_factory.h"
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"
18 InProcessContextFactory::InProcessContextFactory()
19 : shared_bitmap_manager_(new cc::TestSharedBitmapManager()) {
20 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone);
23 InProcessContextFactory::~InProcessContextFactory() {}
25 scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface(
26 Compositor* compositor,
27 bool software_fallback) {
28 DCHECK(!software_fallback);
29 blink::WebGraphicsContext3D::Attributes attrs;
31 attrs.stencil = false;
32 attrs.antialias = false;
33 attrs.shareResources = true;
34 bool lose_context_when_out_of_memory = true;
36 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
37 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
38 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
39 attrs, lose_context_when_out_of_memory, compositor->widget()));
42 using webkit::gpu::ContextProviderInProcess;
43 scoped_refptr<ContextProviderInProcess> context_provider =
44 ContextProviderInProcess::Create(context3d.Pass(), "UICompositor");
46 return make_scoped_ptr(new cc::OutputSurface(context_provider));
49 scoped_refptr<Reflector> InProcessContextFactory::CreateReflector(
50 Compositor* mirroed_compositor,
51 Layer* mirroring_layer) {
52 return new Reflector();
55 void InProcessContextFactory::RemoveReflector(
56 scoped_refptr<Reflector> reflector) {}
58 scoped_refptr<cc::ContextProvider>
59 InProcessContextFactory::SharedMainThreadContextProvider() {
60 if (shared_main_thread_contexts_ &&
61 !shared_main_thread_contexts_->DestroyedOnMainThread())
62 return shared_main_thread_contexts_;
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;
72 return shared_main_thread_contexts_;
75 void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {}
77 bool InProcessContextFactory::DoesCreateTestContexts() { return false; }
79 cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() {
80 return shared_bitmap_manager_.get();