| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| 11 #include "ui/aura/client/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/env_observer.h" | 12 #include "ui/aura/env_observer.h" |
| 13 #include "ui/aura/input_state_lookup.h" | 13 #include "ui/aura/input_state_lookup.h" |
| 14 #include "ui/aura/mus/mus_types.h" | 14 #include "ui/aura/mus/mus_types.h" |
| 15 #include "ui/aura/mus/os_exchange_data_provider_mus.h" | 15 #include "ui/aura/mus/os_exchange_data_provider_mus.h" |
| 16 #include "ui/aura/mus/window_port_mus.h" | 16 #include "ui/aura/mus/window_port_mus.h" |
| 17 #include "ui/aura/mus/window_tree_client.h" | 17 #include "ui/aura/mus/window_tree_client.h" |
| 18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 19 #include "ui/aura/window_port_local.h" | 19 #include "ui/aura/window_port_local.h" |
| 20 #include "ui/events/event_target_iterator.h" | 20 #include "ui/events/event_target_iterator.h" |
| 21 #include "ui/events/platform/platform_event_source.h" | 21 #include "ui/events/platform/platform_event_source.h" |
| 22 | 22 |
| 23 #if defined(USE_OZONE) | 23 #if defined(USE_OZONE) |
| 24 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h" |
| 24 #include "ui/ozone/public/ozone_platform.h" | 25 #include "ui/ozone/public/ozone_platform.h" |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 namespace aura { | 28 namespace aura { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // Env is thread local so that aura may be used on multiple threads. | 32 // Env is thread local so that aura may be used on multiple threads. |
| 32 base::LazyInstance<base::ThreadLocalPointer<Env>>::Leaky lazy_tls_ptr = | 33 base::LazyInstance<base::ThreadLocalPointer<Env>>::Leaky lazy_tls_ptr = |
| 33 LAZY_INSTANCE_INITIALIZER; | 34 LAZY_INSTANCE_INITIALIZER; |
| 34 | 35 |
| 35 } // namespace | 36 } // namespace |
| 36 | 37 |
| 37 //////////////////////////////////////////////////////////////////////////////// | 38 //////////////////////////////////////////////////////////////////////////////// |
| 38 // Env, public: | 39 // Env, public: |
| 39 | 40 |
| 40 Env::~Env() { | 41 Env::~Env() { |
| 41 if (is_os_exchange_data_provider_factory_) | 42 if (is_os_exchange_data_provider_factory_) |
| 42 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); | 43 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); |
| 43 | 44 |
| 45 #if defined(USE_OZONE) |
| 46 gfx::ClientNativePixmapFactory::ResetInstance(); |
| 47 #endif |
| 48 |
| 44 for (EnvObserver& observer : observers_) | 49 for (EnvObserver& observer : observers_) |
| 45 observer.OnWillDestroyEnv(); | 50 observer.OnWillDestroyEnv(); |
| 46 | 51 |
| 47 #if defined(USE_OZONE) | 52 #if defined(USE_OZONE) |
| 48 ui::OzonePlatform::Shutdown(); | 53 ui::OzonePlatform::Shutdown(); |
| 49 #endif | 54 #endif |
| 50 | 55 |
| 51 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); | 56 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); |
| 52 lazy_tls_ptr.Pointer()->Set(NULL); | 57 lazy_tls_ptr.Pointer()->Set(NULL); |
| 53 } | 58 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 136 |
| 132 //////////////////////////////////////////////////////////////////////////////// | 137 //////////////////////////////////////////////////////////////////////////////// |
| 133 // Env, private: | 138 // Env, private: |
| 134 | 139 |
| 135 Env::Env(Mode mode) | 140 Env::Env(Mode mode) |
| 136 : mode_(mode), | 141 : mode_(mode), |
| 137 mouse_button_flags_(0), | 142 mouse_button_flags_(0), |
| 138 is_touch_down_(false), | 143 is_touch_down_(false), |
| 139 get_last_mouse_location_from_mus_(mode_ == Mode::MUS), | 144 get_last_mouse_location_from_mus_(mode_ == Mode::MUS), |
| 140 input_state_lookup_(InputStateLookup::Create()), | 145 input_state_lookup_(InputStateLookup::Create()), |
| 146 #if defined(USE_OZONE) |
| 147 native_pixmap_factory_(ui::CreateClientNativePixmapFactoryOzone()), |
| 148 #endif |
| 141 context_factory_(nullptr), | 149 context_factory_(nullptr), |
| 142 context_factory_private_(nullptr) { | 150 context_factory_private_(nullptr) { |
| 143 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); | 151 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); |
| 144 lazy_tls_ptr.Pointer()->Set(this); | 152 lazy_tls_ptr.Pointer()->Set(this); |
| 145 } | 153 } |
| 146 | 154 |
| 147 void Env::Init() { | 155 void Env::Init() { |
| 148 if (mode_ == Mode::MUS) { | 156 if (mode_ == Mode::MUS) { |
| 149 EnableMusOSExchangeDataProvider(); | 157 EnableMusOSExchangeDataProvider(); |
| 158 #if defined(USE_OZONE) |
| 159 // Required by all Aura-using clients of services/ui |
| 160 gfx::ClientNativePixmapFactory::SetInstance(native_pixmap_factory_.get()); |
| 161 #endif |
| 150 return; | 162 return; |
| 151 } | 163 } |
| 152 | 164 |
| 153 #if defined(USE_OZONE) | 165 #if defined(USE_OZONE) |
| 154 // The ozone platform can provide its own event source. So initialize the | 166 // The ozone platform can provide its own event source. So initialize the |
| 155 // platform before creating the default event source. If running inside mus | 167 // platform before creating the default event source. If running inside mus |
| 156 // let the mus process initialize ozone instead. | 168 // let the mus process initialize ozone instead. |
| 157 ui::OzonePlatform::InitializeForUI(); | 169 ui::OzonePlatform::InitializeForUI(); |
| 170 gfx::ClientNativePixmapFactory::SetInstance(native_pixmap_factory_.get()); |
| 158 #endif | 171 #endif |
| 159 if (!ui::PlatformEventSource::GetInstance()) | 172 if (!ui::PlatformEventSource::GetInstance()) |
| 160 event_source_ = ui::PlatformEventSource::CreateDefault(); | 173 event_source_ = ui::PlatformEventSource::CreateDefault(); |
| 161 } | 174 } |
| 162 | 175 |
| 163 void Env::EnableMusOSExchangeDataProvider() { | 176 void Env::EnableMusOSExchangeDataProvider() { |
| 164 if (!is_os_exchange_data_provider_factory_) { | 177 if (!is_os_exchange_data_provider_factory_) { |
| 165 ui::OSExchangeDataProviderFactory::SetFactory(this); | 178 ui::OSExchangeDataProviderFactory::SetFactory(this); |
| 166 is_os_exchange_data_provider_factory_ = true; | 179 is_os_exchange_data_provider_factory_ = true; |
| 167 } | 180 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 ui::EventTargeter* Env::GetEventTargeter() { | 213 ui::EventTargeter* Env::GetEventTargeter() { |
| 201 NOTREACHED(); | 214 NOTREACHED(); |
| 202 return NULL; | 215 return NULL; |
| 203 } | 216 } |
| 204 | 217 |
| 205 std::unique_ptr<ui::OSExchangeData::Provider> Env::BuildProvider() { | 218 std::unique_ptr<ui::OSExchangeData::Provider> Env::BuildProvider() { |
| 206 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); | 219 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); |
| 207 } | 220 } |
| 208 | 221 |
| 209 } // namespace aura | 222 } // namespace aura |
| OLD | NEW |