context_factories_for_test.cc revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
1// Copyright 2013 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/context_factories_for_test.h" 6 7#include "base/command_line.h" 8#include "base/sys_info.h" 9#include "cc/test/test_shared_bitmap_manager.h" 10#include "ui/compositor/compositor.h" 11#include "ui/compositor/compositor_switches.h" 12#include "ui/compositor/test/in_process_context_factory.h" 13#include "ui/gl/gl_implementation.h" 14 15namespace { 16 17static ui::ContextFactory* g_implicit_factory = NULL; 18static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL; 19static cc::TestSharedBitmapManager* g_shared_bitmap_manager = NULL; 20 21} // namespace 22 23namespace ui { 24 25// static 26void InitializeContextFactoryForTests(bool enable_pixel_output) { 27 DCHECK(!g_implicit_factory) << 28 "ContextFactory for tests already initialized."; 29 CommandLine* command_line = CommandLine::ForCurrentProcess(); 30 if (command_line->HasSwitch(switches::kEnablePixelOutputInTests)) 31 enable_pixel_output = true; 32 if (enable_pixel_output) 33 g_disable_null_draw = new gfx::DisableNullDrawGLBindings; 34 g_implicit_factory = new InProcessContextFactory(); 35 ContextFactory::SetInstance(g_implicit_factory); 36 g_shared_bitmap_manager = new cc::TestSharedBitmapManager(); 37 Compositor::SetSharedBitmapManager(g_shared_bitmap_manager); 38} 39 40void TerminateContextFactoryForTests() { 41 ContextFactory::SetInstance(NULL); 42 delete g_implicit_factory; 43 g_implicit_factory = NULL; 44 Compositor::SetSharedBitmapManager(NULL); 45 delete g_shared_bitmap_manager; 46 g_shared_bitmap_manager = NULL; 47 delete g_disable_null_draw; 48 g_disable_null_draw = NULL; 49} 50 51} // namespace ui 52