Commit fa69f2b6 authored by sky@chromium.org's avatar sky@chromium.org

Makes Env contain a ContextFactory

This way when creating the Compositor we can supply the ContextFactory
from the thread local Env to it. This is part of making aura thread
safe.

BUG=none
TEST=none
R=ben@chromium.org

Review URL: https://codereview.chromium.org/296053009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272332 0039d316-1c4b-4281-b951-d872f2087c98
parent 15b4290d
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "apps/shell/browser/shell_desktop_controller.h" #include "apps/shell/browser/shell_desktop_controller.h"
#include "apps/shell/browser/shell_app_window.h" #include "apps/shell/browser/shell_app_window.h"
#include "content/public/browser/context_factory.h"
#include "ui/aura/client/cursor_client.h" #include "ui/aura/client/cursor_client.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/layout_manager.h" #include "ui/aura/layout_manager.h"
...@@ -226,7 +227,8 @@ void ShellDesktopController::CreateRootWindow() { ...@@ -226,7 +227,8 @@ void ShellDesktopController::CreateRootWindow() {
gfx::Size size = GetPrimaryDisplaySize(); gfx::Size size = GetPrimaryDisplaySize();
if (size.IsEmpty()) if (size.IsEmpty())
size = gfx::Size(800, 600); size = gfx::Size(800, 600);
wm_test_helper_.reset(new wm::WMTestHelper(size)); wm_test_helper_.reset(
new wm::WMTestHelper(size, content::GetContextFactory()));
// Ensure new windows fill the display. // Ensure new windows fill the display.
aura::WindowTreeHost* host = wm_test_helper_->host(); aura::WindowTreeHost* host = wm_test_helper_->host();
......
...@@ -843,10 +843,8 @@ void Shell::Init(const ShellInitParams& init_params) { ...@@ -843,10 +843,8 @@ void Shell::Init(const ShellInitParams& init_params) {
// Shelf, and WallPaper could be created by the factory. // Shelf, and WallPaper could be created by the factory.
views::FocusManagerFactory::Install(new AshFocusManagerFactory); views::FocusManagerFactory::Install(new AshFocusManagerFactory);
// Env creates the compositor. Historically it seems to have been implicitly
// initialized first by the ActivationController, but now that FocusController
// no longer does this we need to do it explicitly.
aura::Env::CreateInstance(true); aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
// The WindowModalityController needs to be at the front of the input event // The WindowModalityController needs to be at the front of the input event
// pretarget handler list to ensure that it processes input events when modal // pretarget handler list to ensure that it processes input events when modal
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "content/public/browser/context_factory.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/shell/browser/shell_browser_context.h" #include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_net_log.h" #include "content/shell/browser/shell_net_log.h"
...@@ -124,6 +125,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { ...@@ -124,6 +125,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
ash::ShellInitParams init_params; ash::ShellInitParams init_params;
init_params.delegate = delegate_; init_params.delegate = delegate_;
init_params.context_factory = content::GetContextFactory();
ash::Shell::CreateInstance(init_params); ash::Shell::CreateInstance(init_params);
delegate_->set_browser_context(browser_context_.get()); delegate_->set_browser_context(browser_context_.get());
ash::Shell::GetInstance()->CreateShelf(); ash::Shell::GetInstance()->CreateShelf();
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/shell_init_params.h" #include "ash/shell_init_params.h"
#include "ash/system/user/login_status.h" #include "ash/system/user/login_status.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
namespace ash { namespace ash {
...@@ -25,6 +26,7 @@ TEST_F(WindowWatcherTest, ShellDeleteInstance) { ...@@ -25,6 +26,7 @@ TEST_F(WindowWatcherTest, ShellDeleteInstance) {
shell::ShellDelegateImpl* delegate = new ash::shell::ShellDelegateImpl; shell::ShellDelegateImpl* delegate = new ash::shell::ShellDelegateImpl;
ash::ShellInitParams init_params; ash::ShellInitParams init_params;
init_params.context_factory = aura::Env::GetInstance()->context_factory();
init_params.delegate = delegate; init_params.delegate = delegate;
Shell::CreateInstance(init_params); Shell::CreateInstance(init_params);
Shell::GetPrimaryRootWindow()->GetHost()->Show(); Shell::GetPrimaryRootWindow()->GetHost()->Show();
......
...@@ -8,11 +8,13 @@ ...@@ -8,11 +8,13 @@
namespace ash { namespace ash {
ShellInitParams::ShellInitParams()
: delegate(NULL),
context_factory(NULL)
#if defined(OS_WIN) #if defined(OS_WIN)
ShellInitParams::ShellInitParams() : delegate(NULL), remote_hwnd(NULL) {} , remote_hwnd(NULL)
#else
ShellInitParams::ShellInitParams() : delegate(NULL) {}
#endif #endif
{}
ShellInitParams::~ShellInitParams() {} ShellInitParams::~ShellInitParams() {}
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
namespace ui {
class ContextFactory;
}
namespace ash { namespace ash {
class ShellDelegate; class ShellDelegate;
...@@ -23,6 +27,8 @@ struct ASH_EXPORT ShellInitParams { ...@@ -23,6 +27,8 @@ struct ASH_EXPORT ShellInitParams {
ShellDelegate* delegate; ShellDelegate* delegate;
ui::ContextFactory* context_factory;
#if defined(OS_WIN) #if defined(OS_WIN)
HWND remote_hwnd; HWND remote_hwnd;
#endif #endif
......
...@@ -65,6 +65,7 @@ void AshTestHelper::SetUp(bool start_session) { ...@@ -65,6 +65,7 @@ void AshTestHelper::SetUp(bool start_session) {
ui::InitializeInputMethodForTesting(); ui::InitializeInputMethodForTesting();
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
// Creates Shell and hook with Desktop. // Creates Shell and hook with Desktop.
...@@ -87,6 +88,7 @@ void AshTestHelper::SetUp(bool start_session) { ...@@ -87,6 +88,7 @@ void AshTestHelper::SetUp(bool start_session) {
#endif #endif
ShellInitParams init_params; ShellInitParams init_params;
init_params.delegate = test_shell_delegate_; init_params.delegate = test_shell_delegate_;
init_params.context_factory = context_factory;
ash::Shell::CreateInstance(init_params); ash::Shell::CreateInstance(init_params);
aura::test::EnvTestHelper(aura::Env::GetInstance()).SetInputStateLookup( aura::test::EnvTestHelper(aura::Env::GetInstance()).SetInputStateLookup(
scoped_ptr<aura::InputStateLookup>()); scoped_ptr<aura::InputStateLookup>());
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/ui/ash/screenshot_taker.h" #include "chrome/browser/ui/ash/screenshot_taker.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/context_factory.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
...@@ -62,6 +63,7 @@ void OpenAsh(gfx::AcceleratedWidget remote_window) { ...@@ -62,6 +63,7 @@ void OpenAsh(gfx::AcceleratedWidget remote_window) {
ash::ShellInitParams shell_init_params; ash::ShellInitParams shell_init_params;
// Shell takes ownership of ChromeShellDelegate. // Shell takes ownership of ChromeShellDelegate.
shell_init_params.delegate = new ChromeShellDelegate; shell_init_params.delegate = new ChromeShellDelegate;
shell_init_params.context_factory = content::GetContextFactory();
#if defined(OS_WIN) #if defined(OS_WIN)
shell_init_params.remote_hwnd = remote_window; shell_init_params.remote_hwnd = remote_window;
#endif #endif
......
...@@ -52,6 +52,7 @@ class AccessibilityViewsDelegate : public views::TestViewsDelegate { ...@@ -52,6 +52,7 @@ class AccessibilityViewsDelegate : public views::TestViewsDelegate {
view, event_type); view, event_type);
} }
private:
DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate); DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate);
}; };
...@@ -110,10 +111,11 @@ class AccessibilityEventRouterViewsTest ...@@ -110,10 +111,11 @@ class AccessibilityEventRouterViewsTest
#if defined(USE_AURA) #if defined(USE_AURA)
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp(); aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window()); new wm::DefaultActivationClient(aura_test_helper_->root_window());
#endif // USE_AURA #endif // USE_AURA
EnableAccessibilityAndListenToFocusNotifications(); EnableAccessibilityAndListenToFocusNotifications();
...@@ -126,7 +128,6 @@ class AccessibilityEventRouterViewsTest ...@@ -126,7 +128,6 @@ class AccessibilityEventRouterViewsTest
ui::TerminateContextFactoryForTests(); ui::TerminateContextFactoryForTests();
#endif #endif
delete views::ViewsDelegate::views_delegate; delete views::ViewsDelegate::views_delegate;
views::ViewsDelegate::views_delegate = NULL;
// The Widget's FocusManager is deleted using DeleteSoon - this // The Widget's FocusManager is deleted using DeleteSoon - this
// forces it to be deleted now, so we don't have any memory leaks // forces it to be deleted now, so we don't have any memory leaks
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#if defined(USE_AURA) #if defined(USE_AURA)
#include "ui/aura/test/aura_test_helper.h" #include "ui/aura/test/aura_test_helper.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/test/context_factories_for_test.h" #include "ui/compositor/test/context_factories_for_test.h"
#include "ui/wm/core/default_activation_client.h" #include "ui/wm/core/default_activation_client.h"
#endif #endif
...@@ -68,11 +69,12 @@ void BrowserWithTestWindowTest::SetUp() { ...@@ -68,11 +69,12 @@ void BrowserWithTestWindowTest::SetUp() {
#elif defined(USE_AURA) #elif defined(USE_AURA)
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(new aura::test::AuraTestHelper( aura_test_helper_.reset(new aura::test::AuraTestHelper(
base::MessageLoopForUI::current())); base::MessageLoopForUI::current()));
aura_test_helper_->SetUp(); aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window()); new wm::DefaultActivationClient(aura_test_helper_->root_window());
#endif // USE_AURA #endif // USE_AURA
#if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS) #if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS)
......
...@@ -109,6 +109,7 @@ void ViewEventTestBase::SetUp() { ...@@ -109,6 +109,7 @@ void ViewEventTestBase::SetUp() {
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -122,6 +123,7 @@ void ViewEventTestBase::SetUp() { ...@@ -122,6 +123,7 @@ void ViewEventTestBase::SetUp() {
new ash::test::TestShellDelegate(); new ash::test::TestShellDelegate();
ash::ShellInitParams init_params; ash::ShellInitParams init_params;
init_params.delegate = shell_delegate; init_params.delegate = shell_delegate;
init_params.context_factory = context_factory;
ash::Shell::CreateInstance(init_params); ash::Shell::CreateInstance(init_params);
shell_delegate->test_session_state_delegate() shell_delegate->test_session_state_delegate()
->SetActiveUserSessionStarted(true); ->SetActiveUserSessionStarted(true);
...@@ -133,12 +135,13 @@ void ViewEventTestBase::SetUp() { ...@@ -133,12 +135,13 @@ void ViewEventTestBase::SetUp() {
gfx::Screen::SetScreenInstance( gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen());
aura::Env::CreateInstance(true); aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory);
#elif defined(USE_AURA) #elif defined(USE_AURA)
// Instead of using the ash shell, use an AuraTestHelper to create and manage // Instead of using the ash shell, use an AuraTestHelper to create and manage
// the test screen. // the test screen.
aura_test_helper_.reset( aura_test_helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
aura_test_helper_->SetUp(); aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window()); new wm::DefaultActivationClient(aura_test_helper_->root_window());
context = aura_test_helper_->root_window(); context = aura_test_helper_->root_window();
#endif #endif
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#endif #endif
#if defined(USE_AURA) #if defined(USE_AURA)
#include "content/public/browser/context_factory.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#endif #endif
...@@ -942,6 +943,12 @@ int BrowserMainLoop::BrowserThreadsStarted() { ...@@ -942,6 +943,12 @@ int BrowserMainLoop::BrowserThreadsStarted() {
} }
BrowserGpuChannelHostFactory::Initialize(established_gpu_channel); BrowserGpuChannelHostFactory::Initialize(established_gpu_channel);
ImageTransportFactory::Initialize(); ImageTransportFactory::Initialize();
#if defined(USE_AURA)
if (aura::Env::GetInstance()) {
aura::Env::GetInstance()->set_context_factory(
content::GetContextFactory());
}
#endif
} }
#elif defined(OS_ANDROID) #elif defined(OS_ANDROID)
established_gpu_channel = true; established_gpu_channel = true;
......
...@@ -90,9 +90,11 @@ SoftwareBrowserCompositorOutputSurfaceTest:: ...@@ -90,9 +90,11 @@ SoftwareBrowserCompositorOutputSurfaceTest::
void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() { void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() {
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget)); compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
context_factory));
surface_proxy_ = surface_proxy_ =
new content::BrowserCompositorOutputSurfaceProxy(&surface_map_); new content::BrowserCompositorOutputSurfaceProxy(&surface_map_);
} }
......
...@@ -99,13 +99,15 @@ SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() { ...@@ -99,13 +99,15 @@ SoftwareOutputDeviceOzoneTest::~SoftwareOutputDeviceOzoneTest() {
} }
void SoftwareOutputDeviceOzoneTest::SetUp() { void SoftwareOutputDeviceOzoneTest::SetUp() {
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output_); ui::InitializeContextFactoryForTests(enable_pixel_output_);
surface_factory_.reset(new MockSurfaceFactoryOzone()); surface_factory_.reset(new MockSurfaceFactoryOzone());
const gfx::Size size(500, 400); const gfx::Size size(500, 400);
compositor_.reset(new ui::Compositor( compositor_.reset(new ui::Compositor(
gfx::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget())); gfx::SurfaceFactoryOzone::GetInstance()->GetAcceleratedWidget(),
context_factory));
compositor_->SetScaleAndSize(1.0f, size); compositor_->SetScaleAndSize(1.0f, size);
output_device_.reset(new content::SoftwareOutputDeviceOzone( output_device_.reset(new content::SoftwareOutputDeviceOzone(
......
...@@ -63,9 +63,10 @@ class DesktopCaptureDeviceAuraTest : public testing::Test { ...@@ -63,9 +63,10 @@ class DesktopCaptureDeviceAuraTest : public testing::Test {
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
helper_->SetUp(); helper_->SetUp(context_factory);
new wm::DefaultActivationClient(helper_->root_window()); new wm::DefaultActivationClient(helper_->root_window());
// We need a window to cover desktop area so that DesktopCaptureDeviceAura // We need a window to cover desktop area so that DesktopCaptureDeviceAura
......
...@@ -209,10 +209,11 @@ class RenderWidgetHostViewAuraTest : public testing::Test { ...@@ -209,10 +209,11 @@ class RenderWidgetHostViewAuraTest : public testing::Test {
: browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
void SetUpEnvironment() { void SetUpEnvironment() {
ui::ContextFactory* context_factory = new ui::InProcessContextFactory;
ImageTransportFactory::InitializeForUnitTests( ImageTransportFactory::InitializeForUnitTests(
scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory)); scoped_ptr<ui::ContextFactory>(context_factory));
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp(); aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window()); new wm::DefaultActivationClient(aura_test_helper_->root_window());
browser_context_.reset(new TestBrowserContext); browser_context_.reset(new TestBrowserContext);
......
...@@ -170,11 +170,12 @@ void RenderViewHostTestHarness::SetUp() { ...@@ -170,11 +170,12 @@ void RenderViewHostTestHarness::SetUp() {
#if defined(USE_AURA) #if defined(USE_AURA)
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset( aura_test_helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
aura_test_helper_->SetUp(); aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window()); new wm::DefaultActivationClient(aura_test_helper_->root_window());
#endif #endif
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/browser/context_factory.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/context_menu_params.h" #include "content/public/common/context_menu_params.h"
...@@ -424,7 +425,8 @@ void Shell::PlatformInitialize(const gfx::Size& default_window_size) { ...@@ -424,7 +425,8 @@ void Shell::PlatformInitialize(const gfx::Size& default_window_size) {
chromeos::DBusThreadManager::Initialize(); chromeos::DBusThreadManager::Initialize();
gfx::Screen::SetScreenInstance( gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create()); gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create());
wm_test_helper_ = new wm::WMTestHelper(default_window_size); wm_test_helper_ = new wm::WMTestHelper(default_window_size,
GetContextFactory());
#else #else
gfx::Screen::SetScreenInstance( gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen());
......
...@@ -48,6 +48,7 @@ WindowTreeHostMojo::WindowTreeHostMojo( ...@@ -48,6 +48,7 @@ WindowTreeHostMojo::WindowTreeHostMojo(
} }
context_factory_ = new ContextFactoryMojo(gles2_handle.Pass()); context_factory_ = new ContextFactoryMojo(gles2_handle.Pass());
ui::ContextFactory::SetInstance(context_factory_); ui::ContextFactory::SetInstance(context_factory_);
aura::Env::GetInstance()->set_context_factory(context_factory_);
CHECK(context_factory_) << "No GL bindings."; CHECK(context_factory_) << "No GL bindings.";
native_viewport_->CreateGLES2Context(gles2_client_handle.Pass()); native_viewport_->CreateGLES2Context(gles2_client_handle.Pass());
......
...@@ -305,6 +305,7 @@ int main(int argc, char** argv) { ...@@ -305,6 +305,7 @@ int main(int argc, char** argv) {
base::MessageLoopForUI message_loop; base::MessageLoopForUI message_loop;
aura::Env::CreateInstance(true); aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory.get());
scoped_ptr<aura::TestScreen> test_screen( scoped_ptr<aura::TestScreen> test_screen(
aura::TestScreen::CreateFullscreen()); aura::TestScreen::CreateFullscreen());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
......
...@@ -129,6 +129,7 @@ int DemoMain() { ...@@ -129,6 +129,7 @@ int DemoMain() {
base::MessageLoopForUI message_loop; base::MessageLoopForUI message_loop;
aura::Env::CreateInstance(true); aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory.get());
scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create()); scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get());
scoped_ptr<aura::WindowTreeHost> host( scoped_ptr<aura::WindowTreeHost> host(
......
...@@ -66,7 +66,8 @@ bool Env::IsMouseButtonDown() const { ...@@ -66,7 +66,8 @@ bool Env::IsMouseButtonDown() const {
Env::Env() Env::Env()
: mouse_button_flags_(0), : mouse_button_flags_(0),
is_touch_down_(false), is_touch_down_(false),
input_state_lookup_(InputStateLookup::Create().Pass()) { input_state_lookup_(InputStateLookup::Create().Pass()),
context_factory_(NULL) {
DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL);
lazy_tls_ptr.Pointer()->Set(this); lazy_tls_ptr.Pointer()->Set(this);
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
namespace ui { namespace ui {
class ContextFactory;
class PlatformEventSource; class PlatformEventSource;
} }
namespace aura { namespace aura {
...@@ -59,6 +60,11 @@ class AURA_EXPORT Env : public ui::EventTarget { ...@@ -59,6 +60,11 @@ class AURA_EXPORT Env : public ui::EventTarget {
bool is_touch_down() const { return is_touch_down_; } bool is_touch_down() const { return is_touch_down_; }
void set_touch_down(bool value) { is_touch_down_ = value; } void set_touch_down(bool value) { is_touch_down_ = value; }
void set_context_factory(ui::ContextFactory* context_factory) {
context_factory_ = context_factory;
}
ui::ContextFactory* context_factory() { return context_factory_; }
private: private:
friend class test::EnvTestHelper; friend class test::EnvTestHelper;
friend class Window; friend class Window;
...@@ -95,6 +101,8 @@ class AURA_EXPORT Env : public ui::EventTarget { ...@@ -95,6 +101,8 @@ class AURA_EXPORT Env : public ui::EventTarget {
scoped_ptr<InputStateLookup> input_state_lookup_; scoped_ptr<InputStateLookup> input_state_lookup_;
scoped_ptr<ui::PlatformEventSource> event_source_; scoped_ptr<ui::PlatformEventSource> event_source_;
ui::ContextFactory* context_factory_;
DISALLOW_COPY_AND_ASSIGN(Env); DISALLOW_COPY_AND_ASSIGN(Env);
}; };
......
...@@ -73,10 +73,11 @@ void AuraTestBase::SetUp() { ...@@ -73,10 +73,11 @@ void AuraTestBase::SetUp() {
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
helper_.reset(new AuraTestHelper(&message_loop_)); helper_.reset(new AuraTestHelper(&message_loop_));
helper_->SetUp(); helper_->SetUp(context_factory);
} }
void AuraTestBase::TearDown() { void AuraTestBase::TearDown() {
......
...@@ -52,10 +52,11 @@ AuraTestHelper::~AuraTestHelper() { ...@@ -52,10 +52,11 @@ AuraTestHelper::~AuraTestHelper() {
<< "AuraTestHelper::TearDown() never called."; << "AuraTestHelper::TearDown() never called.";
} }
void AuraTestHelper::SetUp() { void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) {
setup_called_ = true; setup_called_ = true;
Env::CreateInstance(true); Env::CreateInstance(true);
Env::GetInstance()->set_context_factory(context_factory);
// Unit tests generally don't want to query the system, rather use the state // Unit tests generally don't want to query the system, rather use the state
// from RootWindow. // from RootWindow.
EnvTestHelper(Env::GetInstance()).SetInputStateLookup( EnvTestHelper(Env::GetInstance()).SetInputStateLookup(
......
...@@ -15,6 +15,7 @@ class MessageLoopForUI; ...@@ -15,6 +15,7 @@ class MessageLoopForUI;
} }
namespace ui { namespace ui {
class ContextFactory;
class InputMethod; class InputMethod;
class ScopedAnimationDurationScaleMode; class ScopedAnimationDurationScaleMode;
} }
...@@ -37,7 +38,7 @@ class AuraTestHelper { ...@@ -37,7 +38,7 @@ class AuraTestHelper {
~AuraTestHelper(); ~AuraTestHelper();
// Creates and initializes (shows and sizes) the RootWindow for use in tests. // Creates and initializes (shows and sizes) the RootWindow for use in tests.
void SetUp(); void SetUp(ui::ContextFactory* context_factory);
// Clean up objects that are created for tests. This also deletes the Env // Clean up objects that are created for tests. This also deletes the Env
// object. // object.
......
...@@ -198,8 +198,11 @@ void WindowTreeHost::DestroyDispatcher() { ...@@ -198,8 +198,11 @@ void WindowTreeHost::DestroyDispatcher() {
void WindowTreeHost::CreateCompositor( void WindowTreeHost::CreateCompositor(
gfx::AcceleratedWidget accelerated_widget) { gfx::AcceleratedWidget accelerated_widget) {
compositor_.reset(new ui::Compositor(GetAcceleratedWidget())); DCHECK(Env::GetInstance());
DCHECK(compositor_.get()); ui::ContextFactory* context_factory = Env::GetInstance()->context_factory();
DCHECK(context_factory);
compositor_.reset(
new ui::Compositor(GetAcceleratedWidget(), context_factory));
// TODO(beng): I think this setup should probably all move to a "accelerated // TODO(beng): I think this setup should probably all move to a "accelerated
// widget available" function. // widget available" function.
if (!dispatcher()) { if (!dispatcher()) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h" #include "ui/base/ime/input_method_factory.h"
#include "ui/base/ime/text_input_client.h" #include "ui/base/ime/text_input_client.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer_type.h" #include "ui/compositor/layer_type.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/context_factories_for_test.h" #include "ui/compositor/test/context_factories_for_test.h"
...@@ -165,10 +166,11 @@ class KeyboardControllerTest : public testing::Test { ...@@ -165,10 +166,11 @@ class KeyboardControllerTest : public testing::Test {
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp(); aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window()); new wm::DefaultActivationClient(aura_test_helper_->root_window());
ui::SetUpInputMethodFactoryForTesting(); ui::SetUpInputMethodFactoryForTesting();
focus_controller_.reset(new TestFocusController(root_window())); focus_controller_.reset(new TestFocusController(root_window()));
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/aura/test/test_windows.h" #include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/test/context_factories_for_test.h" #include "ui/compositor/test/context_factories_for_test.h"
#include "ui/compositor/test/draw_waiter_for_test.h" #include "ui/compositor/test/draw_waiter_for_test.h"
...@@ -89,11 +90,12 @@ class SnapshotAuraTest : public testing::Test { ...@@ -89,11 +90,12 @@ class SnapshotAuraTest : public testing::Test {
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
// Snapshot test tests real drawing and readback, so needs pixel output. // Snapshot test tests real drawing and readback, so needs pixel output.
bool enable_pixel_output = true; bool enable_pixel_output = true;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
helper_.reset( helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
helper_->SetUp(); helper_->SetUp(context_factory);
new ::wm::DefaultActivationClient(helper_->root_window()); new ::wm::DefaultActivationClient(helper_->root_window());
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "content/public/browser/context_factory.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/shell/browser/shell_browser_context.h" #include "content/shell/browser/shell_browser_context.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
...@@ -54,7 +55,8 @@ void ExamplesBrowserMainParts::PreMainMessageLoopRun() { ...@@ -54,7 +55,8 @@ void ExamplesBrowserMainParts::PreMainMessageLoopRun() {
gfx::Screen::SetScreenInstance( gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create()); gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create());
// Set up basic pieces of views::corewm. // Set up basic pieces of views::corewm.
wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600))); wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600),
content::GetContextFactory()));
// Ensure the X window gets mapped. // Ensure the X window gets mapped.
wm_test_helper_->host()->Show(); wm_test_helper_->host()->Show();
// Ensure Aura knows where to open new windows. // Ensure Aura knows where to open new windows.
......
...@@ -15,11 +15,7 @@ namespace views { ...@@ -15,11 +15,7 @@ namespace views {
TestViewsDelegate::TestViewsDelegate() TestViewsDelegate::TestViewsDelegate()
: use_desktop_native_widgets_(false), : use_desktop_native_widgets_(false),
use_transparent_windows_(false) use_transparent_windows_(false) {
#if defined(USE_AURA)
, context_factory_(NULL)
#endif
{
DCHECK(!ViewsDelegate::views_delegate); DCHECK(!ViewsDelegate::views_delegate);
ViewsDelegate::views_delegate = this; ViewsDelegate::views_delegate = this;
#if defined(USE_AURA) #if defined(USE_AURA)
...@@ -46,10 +42,4 @@ void TestViewsDelegate::OnBeforeWidgetInit( ...@@ -46,10 +42,4 @@ void TestViewsDelegate::OnBeforeWidgetInit(
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
} }
#if defined(USE_AURA)
ui::ContextFactory* TestViewsDelegate::GetContextFactory() {
return context_factory_;
}
#endif
} // namespace views } // namespace views
...@@ -30,19 +30,10 @@ class TestViewsDelegate : public ViewsDelegate { ...@@ -30,19 +30,10 @@ class TestViewsDelegate : public ViewsDelegate {
use_transparent_windows_ = transparent; use_transparent_windows_ = transparent;
} }
#if defined(USE_AURA)
void set_context_factory(ui::ContextFactory* context_factory) {
context_factory_ = context_factory;
}
#endif
// ViewsDelegate: // ViewsDelegate:
virtual void OnBeforeWidgetInit( virtual void OnBeforeWidgetInit(
Widget::InitParams* params, Widget::InitParams* params,
internal::NativeWidgetDelegate* delegate) OVERRIDE; internal::NativeWidgetDelegate* delegate) OVERRIDE;
#if defined(USE_AURA)
virtual ui::ContextFactory* GetContextFactory() OVERRIDE;
#endif
private: private:
bool use_desktop_native_widgets_; bool use_desktop_native_widgets_;
......
...@@ -31,9 +31,10 @@ void ViewsTestBase::SetUp() { ...@@ -31,9 +31,10 @@ void ViewsTestBase::SetUp() {
views_delegate_.reset(new TestViewsDelegate()); views_delegate_.reset(new TestViewsDelegate());
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
test_helper_.reset(ViewsTestHelper::Create(&message_loop_)); test_helper_.reset(ViewsTestHelper::Create(&message_loop_, context_factory));
test_helper_->SetUp(); test_helper_->SetUp();
ui::InitializeInputMethodForTesting(); ui::InitializeInputMethodForTesting();
} }
......
...@@ -8,7 +8,8 @@ namespace views { ...@@ -8,7 +8,8 @@ namespace views {
#if !defined(USE_AURA) #if !defined(USE_AURA)
// static // static
ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop) { ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory) {
return new ViewsTestHelper; return new ViewsTestHelper;
} }
#endif #endif
......
...@@ -11,6 +11,10 @@ namespace base { ...@@ -11,6 +11,10 @@ namespace base {
class MessageLoopForUI; class MessageLoopForUI;
} }
namespace ui {
class ContextFactory;
}
namespace views { namespace views {
// A helper class owned by tests that performs platform specific initialization // A helper class owned by tests that performs platform specific initialization
...@@ -21,7 +25,8 @@ class ViewsTestHelper { ...@@ -21,7 +25,8 @@ class ViewsTestHelper {
virtual ~ViewsTestHelper(); virtual ~ViewsTestHelper();
// Create a platform specific instance. // Create a platform specific instance.
static ViewsTestHelper* Create(base::MessageLoopForUI* message_loop); static ViewsTestHelper* Create(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory);
// Creates objects that are needed for tests. // Creates objects that are needed for tests.
virtual void SetUp(); virtual void SetUp();
......
...@@ -12,11 +12,14 @@ ...@@ -12,11 +12,14 @@
namespace views { namespace views {
// static // static
ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop) { ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop,
return new ViewsTestHelperAura(message_loop); ui::ContextFactory* context_factory) {
return new ViewsTestHelperAura(message_loop, context_factory);
} }
ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI* message_loop) { ViewsTestHelperAura::ViewsTestHelperAura(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory)
: context_factory_(context_factory) {
aura_test_helper_.reset(new aura::test::AuraTestHelper(message_loop)); aura_test_helper_.reset(new aura::test::AuraTestHelper(message_loop));
} }
...@@ -24,7 +27,7 @@ ViewsTestHelperAura::~ViewsTestHelperAura() { ...@@ -24,7 +27,7 @@ ViewsTestHelperAura::~ViewsTestHelperAura() {
} }
void ViewsTestHelperAura::SetUp() { void ViewsTestHelperAura::SetUp() {
aura_test_helper_->SetUp(); aura_test_helper_->SetUp(context_factory_);
new wm::DefaultActivationClient(aura_test_helper_->root_window()); new wm::DefaultActivationClient(aura_test_helper_->root_window());
wm_state_.reset(new wm::WMState); wm_state_.reset(new wm::WMState);
} }
......
...@@ -28,7 +28,8 @@ namespace views { ...@@ -28,7 +28,8 @@ namespace views {
class ViewsTestHelperAura : public ViewsTestHelper { class ViewsTestHelperAura : public ViewsTestHelper {
public: public:
explicit ViewsTestHelperAura(base::MessageLoopForUI* message_loop); ViewsTestHelperAura(base::MessageLoopForUI* message_loop,
ui::ContextFactory* context_factory);
virtual ~ViewsTestHelperAura(); virtual ~ViewsTestHelperAura();
// Overridden from ViewsTestHelper: // Overridden from ViewsTestHelper:
...@@ -37,6 +38,7 @@ class ViewsTestHelperAura : public ViewsTestHelper { ...@@ -37,6 +38,7 @@ class ViewsTestHelperAura : public ViewsTestHelper {
virtual gfx::NativeView GetContext() OVERRIDE; virtual gfx::NativeView GetContext() OVERRIDE;
private: private:
ui::ContextFactory* context_factory_;
scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
scoped_ptr<wm::WMState> wm_state_; scoped_ptr<wm::WMState> wm_state_;
......
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
namespace wm { namespace wm {
WMTestHelper::WMTestHelper(const gfx::Size& default_window_size) { WMTestHelper::WMTestHelper(const gfx::Size& default_window_size,
ui::ContextFactory* context_factory) {
aura::Env::CreateInstance(true); aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory);
host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size))); host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size)));
host_->InitHost(); host_->InitHost();
aura::client::SetWindowTreeClient(host_->window(), this); aura::client::SetWindowTreeClient(host_->window(), this);
......
...@@ -24,6 +24,10 @@ class Rect; ...@@ -24,6 +24,10 @@ class Rect;
class Size; class Size;
} }
namespace ui {
class ContextFactory;
}
namespace wm { namespace wm {
class CompoundEventFilter; class CompoundEventFilter;
...@@ -34,7 +38,8 @@ class InputMethodEventFilter; ...@@ -34,7 +38,8 @@ class InputMethodEventFilter;
// the ash parts of the code. // the ash parts of the code.
class WMTestHelper : public aura::client::WindowTreeClient { class WMTestHelper : public aura::client::WindowTreeClient {
public: public:
explicit WMTestHelper(const gfx::Size& default_window_size); WMTestHelper(const gfx::Size& default_window_size,
ui::ContextFactory* context_factory);
virtual ~WMTestHelper(); virtual ~WMTestHelper();
aura::WindowTreeHost* host() { return host_.get(); } aura::WindowTreeHost* host() { return host_.get(); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment