Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: ui/ozone/ozone_platform.cc

Issue 291473002: ozone: Initialize a subsystem only if necessary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r270817 Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/ozone/ozone_platform.h ('k') | ui/ozone/platform/caca/ozone_platform_caca.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/base/cursor/ozone/cursor_factory_ozone.h" 8 #include "ui/base/cursor/ozone/cursor_factory_ozone.h"
9 #include "ui/events/ozone/event_factory_ozone.h" 9 #include "ui/events/ozone/event_factory_ozone.h"
10 #include "ui/gfx/ozone/surface_factory_ozone.h" 10 #include "ui/gfx/ozone/surface_factory_ozone.h"
(...skipping 22 matching lines...) Expand all
33 // The first platform is the default. 33 // The first platform is the default.
34 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) && 34 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzonePlatform) &&
35 kOzonePlatformCount > 0) 35 kOzonePlatformCount > 0)
36 return kOzonePlatforms[0].name; 36 return kOzonePlatforms[0].name;
37 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 37 return CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
38 switches::kOzonePlatform); 38 switches::kOzonePlatform);
39 } 39 }
40 40
41 } // namespace 41 } // namespace
42 42
43 OzonePlatform::OzonePlatform() {} 43 OzonePlatform::OzonePlatform() {
44 CHECK(!instance_) << "There should only be a single OzonePlatform.";
45 instance_ = this;
46 }
44 47
45 OzonePlatform::~OzonePlatform() { 48 OzonePlatform::~OzonePlatform() {
46 gfx::SurfaceFactoryOzone::SetInstance(NULL); 49 CHECK_EQ(instance_, this);
47 ui::EventFactoryOzone::SetInstance(NULL); 50 instance_ = NULL;
48 ui::CursorFactoryOzone::SetInstance(NULL);
49 } 51 }
50 52
51 // static 53 // static
52 void OzonePlatform::Initialize() { 54 void OzonePlatform::InitializeForUI() {
53 if (instance_) 55 CreateInstance();
54 return; 56 instance_->InitializeUI();
55
56 std::string platform = GetPlatformName();
57
58 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform);
59
60 instance_ = CreatePlatform(platform);
61
62 // Inject ozone interfaces.
63 gfx::SurfaceFactoryOzone::SetInstance(instance_->GetSurfaceFactoryOzone());
64 ui::EventFactoryOzone::SetInstance(instance_->GetEventFactoryOzone());
65 ui::InputMethodContextFactoryOzone::SetInstance( 57 ui::InputMethodContextFactoryOzone::SetInstance(
66 instance_->GetInputMethodContextFactoryOzone()); 58 instance_->GetInputMethodContextFactoryOzone());
67 ui::CursorFactoryOzone::SetInstance(instance_->GetCursorFactoryOzone());
68 } 59 }
69 60
70 // static 61 // static
62 void OzonePlatform::InitializeForGPU() {
63 CreateInstance();
64 instance_->InitializeGPU();
65 }
66
67 // static
71 OzonePlatform* OzonePlatform::GetInstance() { 68 OzonePlatform* OzonePlatform::GetInstance() {
72 CHECK(instance_) << "OzonePlatform is not initialized"; 69 CHECK(instance_) << "OzonePlatform is not initialized";
73 return instance_; 70 return instance_;
74 } 71 }
75 72
76 // static 73 // static
74 void OzonePlatform::CreateInstance() {
75 if (!instance_) {
76 std::string platform = GetPlatformName();
77 TRACE_EVENT1("ozone", "OzonePlatform::Initialize", "platform", platform);
78 CreatePlatform(platform);
79 }
80 }
81
82 // static
77 OzonePlatform* OzonePlatform::instance_; 83 OzonePlatform* OzonePlatform::instance_;
78 84
79 } // namespace ui 85 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/ozone_platform.h ('k') | ui/ozone/platform/caca/ozone_platform_caca.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698