Commit 13de50d7 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

exo: pass in Envs when creating aura::Windows

As part of the mash work we're going to have multiple aura::Envs at the same
time. Code that may run in Ash now gets the Env from aura::Window, rather than
using Env's static GetInstance(). This patch converts exo to remember the
Env so that it can get the right one.

BUG=847992
TEST=covered by tests

Change-Id: I5fd1c6120868b3847ccd68a063039eec5b54a3b6
Reviewed-on: https://chromium-review.googlesource.com/1169590
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582303}
parent 1ef0a41a
......@@ -8,6 +8,7 @@
#include "components/exo/input_method_surface.h"
#include "components/exo/surface.h"
#include "components/exo/wm_helper.h"
#include "ui/aura/env.h"
namespace ash {
......@@ -18,7 +19,7 @@ class ArcInputMethodSurfaceManagerTest : public AshTestBase {
void SetUp() override {
AshTestBase::SetUp();
wm_helper_ = std::make_unique<exo::WMHelper>();
wm_helper_ = std::make_unique<exo::WMHelper>(aura::Env::GetInstance());
exo::WMHelper::SetInstance(wm_helper_.get());
}
......
......@@ -36,6 +36,7 @@
#include "components/exo/test/exo_test_helper.h"
#include "components/exo/wm_helper.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/events/keycodes/dom/dom_code.h"
......@@ -116,7 +117,7 @@ class ArcNotificationContentViewTest : public AshTestBase {
MessageCenterView::disable_animation_for_testing = true;
wm_helper_ = std::make_unique<exo::WMHelper>();
wm_helper_ = std::make_unique<exo::WMHelper>(aura::Env::GetInstance());
exo::WMHelper::SetInstance(wm_helper_.get());
DCHECK(exo::WMHelper::HasInstance());
......
......@@ -17,6 +17,7 @@
#include "components/exo/file_helper.h"
#include "components/exo/wayland/server.h"
#include "components/exo/wm_helper.h"
#include "ui/aura/env.h"
namespace ash {
......@@ -71,7 +72,7 @@ WaylandServerController::WaylandServerController(
std::make_unique<ArcNotificationSurfaceManagerImpl>();
arc_input_method_surface_manager_ =
std::make_unique<ArcInputMethodSurfaceManager>();
wm_helper_ = std::make_unique<exo::WMHelper>();
wm_helper_ = std::make_unique<exo::WMHelper>(aura::Env::GetInstance());
exo::WMHelper::SetInstance(wm_helper_.get());
display_ = std::make_unique<exo::Display>(
arc_notification_surface_manager_.get(),
......
......@@ -21,6 +21,7 @@
#include "components/exo/wm_helper.h"
#include "components/viz/common/features.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/public/activation_client.h"
......@@ -44,7 +45,7 @@ class ArcAccessibilityHelperBridgeBrowserTest : public InProcessBrowserTest {
chromeos::AccessibilityManager::Get()->SetProfileForTest(
browser()->profile());
wm_helper_ = std::make_unique<exo::WMHelper>();
wm_helper_ = std::make_unique<exo::WMHelper>(aura::Env::GetInstance());
exo::WMHelper::SetInstance(wm_helper_.get());
}
......
......@@ -21,6 +21,7 @@
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_argument.h"
#include "components/exo/layer_tree_frame_sink_holder.h"
#include "components/exo/wm_helper.h"
#include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/resources/resource_format.h"
#include "components/viz/common/resources/resource_format_utils.h"
......@@ -423,7 +424,7 @@ bool Buffer::ProduceTransferableResource(
texture_.reset();
ui::ContextFactory* context_factory =
aura::Env::GetInstance()->context_factory();
WMHelper::GetInstance()->env()->context_factory();
// Note: This can fail if GPU acceleration has been disabled.
scoped_refptr<viz::ContextProvider> context_provider =
context_factory->SharedMainThreadContextProvider();
......
......@@ -270,7 +270,7 @@ void ShellSurface::AttemptToStartDrag(int component) {
target, location, component,
base::BindOnce(end_drag, base::Unretained(this)));
} else {
gfx::Point location = aura::Env::GetInstance()->last_mouse_location();
gfx::Point location = WMHelper::GetInstance()->env()->last_mouse_location();
::wm::ConvertPointFromScreen(widget_->GetNativeWindow()->GetRootWindow(),
&location);
toplevel_handler->AttemptToStartDrag(
......
......@@ -192,8 +192,10 @@ class CustomWindowTargeter : public aura::WindowTargeter {
////////////////////////////////////////////////////////////////////////////////
// Surface, public:
Surface::Surface() : window_(new aura::Window(new CustomWindowDelegate(this))) {
window_->SetType(aura::client::WINDOW_TYPE_CONTROL);
Surface::Surface()
: window_(std::make_unique<aura::Window>(new CustomWindowDelegate(this),
aura::client::WINDOW_TYPE_CONTROL,
WMHelper::GetInstance()->env())) {
window_->SetName("ExoSurface");
window_->SetProperty(kSurfaceKey, this);
window_->Init(ui::LAYER_NOT_DRAWN);
......
......@@ -80,8 +80,10 @@ class CustomWindowTargeter : public aura::WindowTargeter {
// SurfaceTreeHost, public:
SurfaceTreeHost::SurfaceTreeHost(const std::string& window_name)
: host_window_(std::make_unique<aura::Window>(nullptr)) {
host_window_->SetType(aura::client::WINDOW_TYPE_CONTROL);
: host_window_(
std::make_unique<aura::Window>(nullptr,
aura::client::WINDOW_TYPE_CONTROL,
WMHelper::GetInstance()->env())) {
host_window_->SetName(window_name);
host_window_->Init(ui::LAYER_SOLID_COLOR);
host_window_->set_owned_by_parent(false);
......@@ -92,11 +94,11 @@ SurfaceTreeHost::SurfaceTreeHost(const std::string& window_name)
host_window_->SetEventTargeter(std::make_unique<CustomWindowTargeter>(this));
layer_tree_frame_sink_holder_ = std::make_unique<LayerTreeFrameSinkHolder>(
this, host_window_->CreateLayerTreeFrameSink());
aura::Env::GetInstance()->context_factory()->AddObserver(this);
WMHelper::GetInstance()->env()->context_factory()->AddObserver(this);
}
SurfaceTreeHost::~SurfaceTreeHost() {
aura::Env::GetInstance()->context_factory()->RemoveObserver(this);
WMHelper::GetInstance()->env()->context_factory()->RemoveObserver(this);
SetRootSurface(nullptr);
LayerTreeFrameSinkHolder::DeleteWhenLastResourceHasBeenReclaimed(
std::move(layer_tree_frame_sink_holder_));
......@@ -252,7 +254,7 @@ void SurfaceTreeHost::SubmitCompositorFrame() {
for (auto& resource : frame.resource_list)
sync_tokens.push_back(resource.mailbox_holder.sync_token.GetData());
ui::ContextFactory* context_factory =
aura::Env::GetInstance()->context_factory();
WMHelper::GetInstance()->env()->context_factory();
gpu::gles2::GLES2Interface* gles2 =
context_factory->SharedMainThreadContextProvider()->ContextGL();
gles2->VerifySyncTokensCHROMIUM(sync_tokens.data(), sync_tokens.size());
......
......@@ -12,6 +12,7 @@
#include "components/exo/sub_surface.h"
#include "components/exo/test/exo_test_base.h"
#include "components/exo/test/exo_test_helper.h"
#include "components/exo/wm_helper.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
......@@ -102,7 +103,8 @@ TEST_P(SurfaceTest, Attach) {
const viz::CompositorFrame& GetFrameFromSurface(ShellSurface* shell_surface) {
viz::SurfaceId surface_id = shell_surface->host_window()->GetSurfaceId();
viz::SurfaceManager* surface_manager = aura::Env::GetInstance()
viz::SurfaceManager* surface_manager = WMHelper::GetInstance()
->env()
->context_factory_private()
->GetFrameSinkManager()
->surface_manager();
......
......@@ -4,10 +4,12 @@
#include "components/exo/test/exo_test_base.h"
#include "ash/shell.h"
#include "base/command_line.h"
#include "components/exo/test/exo_test_helper.h"
#include "components/exo/test/test_client_controlled_state_delegate.h"
#include "components/exo/wm_helper.h"
#include "ui/aura/env.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/wm/core/wm_core_switches.h"
......@@ -27,7 +29,7 @@ void ExoTestBase::SetUp() {
command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled);
ui::SetUpInputMethodFactoryForTesting();
AshTestBase::SetUp();
wm_helper_ = std::make_unique<WMHelper>();
wm_helper_ = std::make_unique<WMHelper>(aura::Env::GetInstance());
WMHelper::SetInstance(wm_helper_.get());
test::TestClientControlledStateDelegate::InstallFactory();
}
......
......@@ -65,7 +65,8 @@ ExoTestHelper::~ExoTestHelper() {}
std::unique_ptr<gfx::GpuMemoryBuffer> ExoTestHelper::CreateGpuMemoryBuffer(
const gfx::Size& size,
gfx::BufferFormat format) {
return aura::Env::GetInstance()
return WMHelper::GetInstance()
->env()
->context_factory()
->GetGpuMemoryBufferManager()
->CreateGpuMemoryBuffer(size, format, gfx::BufferUsage::GPU_READ,
......
......@@ -23,6 +23,7 @@
#include "components/exo/file_helper.h"
#include "components/exo/wayland/server.h"
#include "components/exo/wm_helper.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/wm/core/cursor_manager.h"
......@@ -144,7 +145,7 @@ void WaylandClientTest::SetUpOnUIThread(base::WaitableEvent* event) {
gesture_config->set_long_press_time_in_ms(1000);
gesture_config->set_max_touch_move_in_pixels_for_click(5);
wm_helper_ = std::make_unique<WMHelper>();
wm_helper_ = std::make_unique<WMHelper>(aura::Env::GetInstance());
WMHelper::SetInstance(wm_helper_.get());
display_ = std::make_unique<Display>(nullptr, nullptr, nullptr);
wayland_server_ = exo::wayland::Server::Create(display_.get());
......
......@@ -27,9 +27,10 @@ aura::Window* GetPrimaryRoot() {
////////////////////////////////////////////////////////////////////////////////
// WMHelper, public:
WMHelper::WMHelper()
WMHelper::WMHelper(aura::Env* env)
: vsync_manager_(
GetPrimaryRoot()->layer()->GetCompositor()->vsync_manager()) {}
GetPrimaryRoot()->layer()->GetCompositor()->vsync_manager()),
env_(env) {}
WMHelper::~WMHelper() {}
......
......@@ -17,6 +17,7 @@ class TabletModeObserver;
}
namespace aura {
class env;
class Window;
namespace client {
class CursorClient;
......@@ -58,13 +59,15 @@ class WMHelper : public aura::client::DragDropDelegate {
virtual ~DragDropObserver() {}
};
WMHelper();
explicit WMHelper(aura::Env* env);
~WMHelper() override;
static void SetInstance(WMHelper* helper);
static WMHelper* GetInstance();
static bool HasInstance();
aura::Env* env() { return env_; }
void AddActivationObserver(wm::ActivationChangeObserver* observer);
void RemoveActivationObserver(wm::ActivationChangeObserver* observer);
void AddFocusObserver(aura::client::FocusChangeObserver* observer);
......@@ -111,6 +114,7 @@ class WMHelper : public aura::client::DragDropDelegate {
base::TimeTicks vsync_timebase_;
base::TimeDelta vsync_interval_;
scoped_refptr<ui::CompositorVSyncManager> vsync_manager_;
aura::Env* const env_;
DISALLOW_COPY_AND_ASSIGN(WMHelper);
};
......
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