| OLD | NEW |
| (Empty) |
| 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 "base/command_line.h" | |
| 8 #include "base/threading/thread.h" | |
| 9 #include "cc/surfaces/surface_id_allocator.h" | |
| 10 #include "cc/test/pixel_test_output_surface.h" | |
| 11 #include "cc/test/test_shared_bitmap_manager.h" | |
| 12 #include "ui/compositor/compositor_switches.h" | |
| 13 #include "ui/compositor/reflector.h" | |
| 14 #include "ui/gl/gl_implementation.h" | |
| 15 #include "ui/gl/gl_surface.h" | |
| 16 #include "webkit/common/gpu/context_provider_in_process.h" | |
| 17 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" | |
| 18 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.
h" | |
| 19 | |
| 20 namespace ui { | |
| 21 | |
| 22 InProcessContextFactory::InProcessContextFactory() | |
| 23 : next_surface_id_namespace_(1u) { | |
| 24 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone) | |
| 25 << "If running tests, ensure that main() is calling " | |
| 26 << "gfx::GLSurface::InitializeOneOffForTests()"; | |
| 27 | |
| 28 #if defined(OS_CHROMEOS) | |
| 29 bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 30 switches::kUIDisableThreadedCompositing); | |
| 31 #else | |
| 32 bool use_thread = false; | |
| 33 #endif | |
| 34 if (use_thread) { | |
| 35 compositor_thread_.reset(new base::Thread("Browser Compositor")); | |
| 36 compositor_thread_->Start(); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 InProcessContextFactory::~InProcessContextFactory() {} | |
| 41 | |
| 42 scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface( | |
| 43 Compositor* compositor, | |
| 44 bool software_fallback) { | |
| 45 DCHECK(!software_fallback); | |
| 46 blink::WebGraphicsContext3D::Attributes attrs; | |
| 47 attrs.depth = false; | |
| 48 attrs.stencil = false; | |
| 49 attrs.antialias = false; | |
| 50 attrs.shareResources = true; | |
| 51 bool lose_context_when_out_of_memory = true; | |
| 52 | |
| 53 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; | |
| 54 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( | |
| 55 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( | |
| 56 attrs, lose_context_when_out_of_memory, compositor->widget())); | |
| 57 CHECK(context3d); | |
| 58 | |
| 59 using webkit::gpu::ContextProviderInProcess; | |
| 60 scoped_refptr<ContextProviderInProcess> context_provider = | |
| 61 ContextProviderInProcess::Create(context3d.Pass(), "UICompositor"); | |
| 62 | |
| 63 return make_scoped_ptr(new cc::PixelTestOutputSurface(context_provider)); | |
| 64 } | |
| 65 | |
| 66 scoped_refptr<Reflector> InProcessContextFactory::CreateReflector( | |
| 67 Compositor* mirroed_compositor, | |
| 68 Layer* mirroring_layer) { | |
| 69 return new Reflector(); | |
| 70 } | |
| 71 | |
| 72 void InProcessContextFactory::RemoveReflector( | |
| 73 scoped_refptr<Reflector> reflector) {} | |
| 74 | |
| 75 scoped_refptr<cc::ContextProvider> | |
| 76 InProcessContextFactory::SharedMainThreadContextProvider() { | |
| 77 if (shared_main_thread_contexts_.get() && | |
| 78 !shared_main_thread_contexts_->DestroyedOnMainThread()) | |
| 79 return shared_main_thread_contexts_; | |
| 80 | |
| 81 bool lose_context_when_out_of_memory = false; | |
| 82 shared_main_thread_contexts_ = | |
| 83 webkit::gpu::ContextProviderInProcess::CreateOffscreen( | |
| 84 lose_context_when_out_of_memory); | |
| 85 if (shared_main_thread_contexts_.get() && | |
| 86 !shared_main_thread_contexts_->BindToCurrentThread()) | |
| 87 shared_main_thread_contexts_ = NULL; | |
| 88 | |
| 89 return shared_main_thread_contexts_; | |
| 90 } | |
| 91 | |
| 92 void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {} | |
| 93 | |
| 94 bool InProcessContextFactory::DoesCreateTestContexts() { return false; } | |
| 95 | |
| 96 cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() { | |
| 97 return &shared_bitmap_manager_; | |
| 98 } | |
| 99 | |
| 100 cc::GpuMemoryBufferManager* | |
| 101 InProcessContextFactory::GetGpuMemoryBufferManager() { | |
| 102 return &gpu_memory_buffer_manager_; | |
| 103 } | |
| 104 | |
| 105 base::MessageLoopProxy* InProcessContextFactory::GetCompositorMessageLoop() { | |
| 106 if (!compositor_thread_) | |
| 107 return NULL; | |
| 108 return compositor_thread_->message_loop_proxy().get(); | |
| 109 } | |
| 110 | |
| 111 scoped_ptr<cc::SurfaceIdAllocator> | |
| 112 InProcessContextFactory::CreateSurfaceIdAllocator() { | |
| 113 return make_scoped_ptr( | |
| 114 new cc::SurfaceIdAllocator(next_surface_id_namespace_++)); | |
| 115 } | |
| 116 | |
| 117 } // namespace ui | |
| OLD | NEW |