| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/debug/trace_event.h" | 6 #include "base/debug/trace_event.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/events/device_data_manager.h" | 8 #include "ui/events/device_data_manager.h" |
| 9 #include "ui/ozone/platform_object.h" | 9 #include "ui/ozone/platform_object.h" |
| 10 #include "ui/ozone/platform_selection.h" | 10 #include "ui/ozone/platform_selection.h" |
| 11 #include "ui/ozone/public/ozone_platform.h" | 11 #include "ui/ozone/public/ozone_platform.h" |
| 12 #include "ui/ozone/public/ozone_switches.h" | 12 #include "ui/ozone/public/ozone_switches.h" |
| 13 #include "ui/platform_window/platform_window.h" |
| 14 #include "ui/platform_window/platform_window_factory.h" |
| 13 | 15 |
| 14 namespace ui { | 16 namespace ui { |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 bool g_platform_initialized_ui = false; | 20 bool g_platform_initialized_ui = false; |
| 19 bool g_platform_initialized_gpu = false; | 21 bool g_platform_initialized_gpu = false; |
| 20 | 22 |
| 23 class OzoneWindowFactory : public PlatformWindowFactory { |
| 24 public: |
| 25 static void CreateInstance() { new OzoneWindowFactory(); } |
| 26 |
| 27 private: |
| 28 OzoneWindowFactory() {} |
| 29 virtual ~OzoneWindowFactory() {} |
| 30 |
| 31 // PlatformWindowFactory: |
| 32 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow( |
| 33 PlatformWindowDelegate* delegate, |
| 34 const gfx::Rect& bounds) OVERRIDE { |
| 35 return ui::OzonePlatform::GetInstance()->CreatePlatformWindow(delegate, |
| 36 bounds); |
| 37 } |
| 38 }; |
| 21 } | 39 } |
| 22 | 40 |
| 23 OzonePlatform::OzonePlatform() { | 41 OzonePlatform::OzonePlatform() { |
| 24 CHECK(!instance_) << "There should only be a single OzonePlatform."; | 42 CHECK(!instance_) << "There should only be a single OzonePlatform."; |
| 25 instance_ = this; | 43 instance_ = this; |
| 26 g_platform_initialized_ui = false; | 44 g_platform_initialized_ui = false; |
| 27 g_platform_initialized_gpu = false; | 45 g_platform_initialized_gpu = false; |
| 28 } | 46 } |
| 29 | 47 |
| 30 OzonePlatform::~OzonePlatform() { | 48 OzonePlatform::~OzonePlatform() { |
| 31 CHECK_EQ(instance_, this); | 49 CHECK_EQ(instance_, this); |
| 32 instance_ = NULL; | 50 instance_ = NULL; |
| 33 } | 51 } |
| 34 | 52 |
| 35 // static | 53 // static |
| 36 void OzonePlatform::InitializeForUI() { | 54 void OzonePlatform::InitializeForUI() { |
| 37 CreateInstance(); | 55 CreateInstance(); |
| 38 if (g_platform_initialized_ui) | 56 if (g_platform_initialized_ui) |
| 39 return; | 57 return; |
| 40 g_platform_initialized_ui = true; | 58 g_platform_initialized_ui = true; |
| 41 instance_->InitializeUI(); | 59 instance_->InitializeUI(); |
| 42 // This is deliberately created after initializing so that the platform can | 60 // This is deliberately created after initializing so that the platform can |
| 43 // create its own version of DDM. | 61 // create its own version of DDM. |
| 44 DeviceDataManager::CreateInstance(); | 62 DeviceDataManager::CreateInstance(); |
| 63 OzoneWindowFactory::CreateInstance(); |
| 45 } | 64 } |
| 46 | 65 |
| 47 // static | 66 // static |
| 48 void OzonePlatform::InitializeForGPU() { | 67 void OzonePlatform::InitializeForGPU() { |
| 49 CreateInstance(); | 68 CreateInstance(); |
| 50 if (g_platform_initialized_gpu) | 69 if (g_platform_initialized_gpu) |
| 51 return; | 70 return; |
| 52 g_platform_initialized_gpu = true; | 71 g_platform_initialized_gpu = true; |
| 53 instance_->InitializeGPU(); | 72 instance_->InitializeGPU(); |
| 54 } | 73 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 | 90 |
| 72 // TODO(spang): Currently need to leak this object. | 91 // TODO(spang): Currently need to leak this object. |
| 73 CHECK_EQ(instance_, platform.release()); | 92 CHECK_EQ(instance_, platform.release()); |
| 74 } | 93 } |
| 75 } | 94 } |
| 76 | 95 |
| 77 // static | 96 // static |
| 78 OzonePlatform* OzonePlatform::instance_; | 97 OzonePlatform* OzonePlatform::instance_; |
| 79 | 98 |
| 80 } // namespace ui | 99 } // namespace ui |
| OLD | NEW |