| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura/env.h" | 5 #include "ui/aura/env.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "ui/aura/env_observer.h" | 10 #include "ui/aura/env_observer.h" |
| 11 #include "ui/aura/input_state_lookup.h" | 11 #include "ui/aura/input_state_lookup.h" |
| 12 #include "ui/events/event_target_iterator.h" | 12 #include "ui/events/event_target_iterator.h" |
| 13 #include "ui/events/platform/platform_event_source.h" | 13 #include "ui/events/platform/platform_event_source.h" |
| 14 | 14 |
| 15 #if defined(USE_OZONE) | 15 #if defined(USE_OZONE) |
| 16 #include "ui/ozone/public/ozone_platform.h" | 16 #include "ui/ozone/public/ozone_platform.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace aura { | 19 namespace aura { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Env is thread local so that aura may be used on multiple threads. | 23 // Env is thread local so that aura may be used on multiple threads. |
| 24 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = | 24 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = |
| 25 LAZY_INSTANCE_INITIALIZER; | 25 LAZY_INSTANCE_INITIALIZER; |
| 26 | 26 |
| 27 // Returns true if running inside of mus. Checks for mojo specific flag. | |
| 28 bool RunningInsideMus() { | |
| 29 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 30 "primordial-pipe-token"); | |
| 31 } | |
| 32 | |
| 33 } // namespace | 27 } // namespace |
| 34 | 28 |
| 35 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 36 // Env, public: | 30 // Env, public: |
| 37 | 31 |
| 38 Env::~Env() { | 32 Env::~Env() { |
| 39 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWillDestroyEnv()); | 33 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWillDestroyEnv()); |
| 40 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); | 34 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); |
| 41 lazy_tls_ptr.Pointer()->Set(NULL); | 35 lazy_tls_ptr.Pointer()->Set(NULL); |
| 42 } | 36 } |
| 43 | 37 |
| 44 // static | 38 // static |
| 45 std::unique_ptr<Env> Env::CreateInstance() { | 39 std::unique_ptr<Env> Env::CreateInstance(bool running_inside_mus, |
| 40 bool in_process_gpu) { |
| 46 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 41 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
| 47 std::unique_ptr<Env> env(new Env()); | 42 std::unique_ptr<Env> env(new Env()); |
| 48 env->Init(); | 43 env->Init(running_inside_mus, in_process_gpu); |
| 49 return env; | 44 return env; |
| 50 } | 45 } |
| 51 | 46 |
| 52 // static | 47 // static |
| 53 Env* Env::GetInstance() { | 48 Env* Env::GetInstance() { |
| 54 Env* env = lazy_tls_ptr.Pointer()->Get(); | 49 Env* env = lazy_tls_ptr.Pointer()->Get(); |
| 55 DCHECK(env) << "Env::CreateInstance must be called before getting the " | 50 DCHECK(env) << "Env::CreateInstance must be called before getting the " |
| 56 "instance of Env."; | 51 "instance of Env."; |
| 57 return env; | 52 return env; |
| 58 } | 53 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 80 | 75 |
| 81 Env::Env() | 76 Env::Env() |
| 82 : mouse_button_flags_(0), | 77 : mouse_button_flags_(0), |
| 83 is_touch_down_(false), | 78 is_touch_down_(false), |
| 84 input_state_lookup_(InputStateLookup::Create()), | 79 input_state_lookup_(InputStateLookup::Create()), |
| 85 context_factory_(NULL) { | 80 context_factory_(NULL) { |
| 86 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); | 81 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); |
| 87 lazy_tls_ptr.Pointer()->Set(this); | 82 lazy_tls_ptr.Pointer()->Set(this); |
| 88 } | 83 } |
| 89 | 84 |
| 90 void Env::Init() { | 85 void Env::Init(bool running_inside_mus, bool in_process_gpu) { |
| 91 if (RunningInsideMus()) | 86 if (running_inside_mus) |
| 92 return; | 87 return; |
| 93 #if defined(USE_OZONE) | 88 #if defined(USE_OZONE) |
| 94 // The ozone platform can provide its own event source. So initialize the | 89 // The ozone platform can provide its own event source. So initialize the |
| 95 // platform before creating the default event source. If running inside mus | 90 // platform before creating the default event source. If running inside mus |
| 96 // let the mus process initialize ozone instead. | 91 // let the mus process initialize ozone instead. |
| 97 ui::OzonePlatform::InitializeForUI(); | 92 ui::OzonePlatform::InitParams ozoneInitParams; |
| 93 ozoneInitParams.single_process = in_process_gpu; |
| 94 ui::OzonePlatform::InitializeForUI(ozoneInitParams); |
| 98 #endif | 95 #endif |
| 99 if (!ui::PlatformEventSource::GetInstance()) | 96 if (!ui::PlatformEventSource::GetInstance()) |
| 100 event_source_ = ui::PlatformEventSource::CreateDefault(); | 97 event_source_ = ui::PlatformEventSource::CreateDefault(); |
| 101 } | 98 } |
| 102 | 99 |
| 103 void Env::NotifyWindowInitialized(Window* window) { | 100 void Env::NotifyWindowInitialized(Window* window) { |
| 104 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWindowInitialized(window)); | 101 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWindowInitialized(window)); |
| 105 } | 102 } |
| 106 | 103 |
| 107 void Env::NotifyHostInitialized(WindowTreeHost* host) { | 104 void Env::NotifyHostInitialized(WindowTreeHost* host) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 126 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { | 123 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { |
| 127 return nullptr; | 124 return nullptr; |
| 128 } | 125 } |
| 129 | 126 |
| 130 ui::EventTargeter* Env::GetEventTargeter() { | 127 ui::EventTargeter* Env::GetEventTargeter() { |
| 131 NOTREACHED(); | 128 NOTREACHED(); |
| 132 return NULL; | 129 return NULL; |
| 133 } | 130 } |
| 134 | 131 |
| 135 } // namespace aura | 132 } // namespace aura |
| OLD | NEW |