OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/html_viewer/global_state.h" | 5 #include "components/html_viewer/global_state.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "cc/blink/web_layer_impl.h" | 15 #include "cc/blink/web_layer_impl.h" |
16 #include "cc/layers/layer_settings.h" | 16 #include "cc/layers/layer_settings.h" |
17 #include "components/html_viewer/blink_platform_impl.h" | 17 #include "components/html_viewer/blink_platform_impl.h" |
18 #include "components/html_viewer/blink_settings_impl.h" | 18 #include "components/html_viewer/blink_settings_impl.h" |
19 #include "components/html_viewer/media_factory.h" | 19 #include "components/html_viewer/media_factory.h" |
20 #include "components/scheduler/renderer/renderer_scheduler.h" | 20 #include "components/scheduler/renderer/renderer_scheduler.h" |
21 #include "gin/v8_initializer.h" | 21 #include "gin/v8_initializer.h" |
22 #include "mojo/logging/init_logging.h" | 22 #include "mojo/logging/init_logging.h" |
23 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 23 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
24 #include "mojo/shell/public/cpp/application_impl.h" | 24 #include "mojo/shell/public/cpp/shell.h" |
25 #include "third_party/WebKit/public/web/WebKit.h" | 25 #include "third_party/WebKit/public/web/WebKit.h" |
26 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 26 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/base/ui_base_paths.h" | 28 #include "ui/base/ui_base_paths.h" |
29 #include "ui/gfx/display.h" | 29 #include "ui/gfx/display.h" |
30 #include "ui/mojo/init/ui_init.h" | 30 #include "ui/mojo/init/ui_init.h" |
31 #include "v8/include/v8.h" | 31 #include "v8/include/v8.h" |
32 | 32 |
33 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 33 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
34 #include "components/font_service/public/cpp/font_loader.h" | 34 #include "components/font_service/public/cpp/font_loader.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 float device_pixel_ratio) { | 69 float device_pixel_ratio) { |
70 std::vector<gfx::Display> displays(1); | 70 std::vector<gfx::Display> displays(1); |
71 displays[0].set_id(2000); | 71 displays[0].set_id(2000); |
72 displays[0].SetScaleAndBounds(device_pixel_ratio, | 72 displays[0].SetScaleAndBounds(device_pixel_ratio, |
73 gfx::Rect(screen_size_in_pixels)); | 73 gfx::Rect(screen_size_in_pixels)); |
74 return displays; | 74 return displays; |
75 } | 75 } |
76 | 76 |
77 } // namespace | 77 } // namespace |
78 | 78 |
79 GlobalState::GlobalState(mojo::ApplicationImpl* app) | 79 GlobalState::GlobalState(mojo::Shell* shell, const std::string& url) |
80 : app_(app), | 80 : shell_(shell), |
81 resource_loader_(app, GetResourcePaths()), | 81 resource_loader_(shell, GetResourcePaths()), |
82 did_init_(false), | 82 did_init_(false), |
83 device_pixel_ratio_(1.f), | 83 device_pixel_ratio_(1.f), |
84 discardable_memory_allocator_(kDesiredMaxMemory), | 84 discardable_memory_allocator_(kDesiredMaxMemory), |
85 compositor_thread_("compositor thread"), | 85 compositor_thread_("compositor thread"), |
86 blink_settings_(new BlinkSettingsImpl()) { | 86 blink_settings_(new BlinkSettingsImpl()) { |
87 tracing_.Initialize(app); | 87 tracing_.Initialize(shell, url); |
88 } | 88 } |
89 | 89 |
90 GlobalState::~GlobalState() { | 90 GlobalState::~GlobalState() { |
91 if (blink_platform_) { | 91 if (blink_platform_) { |
92 renderer_scheduler_->Shutdown(); | 92 renderer_scheduler_->Shutdown(); |
93 blink::shutdown(); | 93 blink::shutdown(); |
94 } | 94 } |
95 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 95 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
96 if (font_loader_.get()) { | 96 if (font_loader_.get()) { |
97 SkFontConfigInterface::SetGlobal(nullptr); | 97 SkFontConfigInterface::SetGlobal(nullptr); |
(...skipping 11 matching lines...) Expand all Loading... |
109 return; | 109 return; |
110 | 110 |
111 DCHECK_NE(0.f, device_pixel_ratio); | 111 DCHECK_NE(0.f, device_pixel_ratio); |
112 | 112 |
113 did_init_ = true; | 113 did_init_ = true; |
114 device_pixel_ratio_ = device_pixel_ratio; | 114 device_pixel_ratio_ = device_pixel_ratio; |
115 screen_size_in_pixels_ = screen_size_in_pixels; | 115 screen_size_in_pixels_ = screen_size_in_pixels; |
116 | 116 |
117 if (!resource_loader_.BlockUntilLoaded()) { | 117 if (!resource_loader_.BlockUntilLoaded()) { |
118 // Assume on error we're being shut down. | 118 // Assume on error we're being shut down. |
119 app_->Quit(); | 119 shell_->Quit(); |
120 return; | 120 return; |
121 } | 121 } |
122 | 122 |
123 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 123 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
124 font_loader_ = skia::AdoptRef(new font_service::FontLoader(app_)); | 124 font_loader_ = skia::AdoptRef(new font_service::FontLoader(shell_)); |
125 SkFontConfigInterface::SetGlobal(font_loader_.get()); | 125 SkFontConfigInterface::SetGlobal(font_loader_.get()); |
126 #endif | 126 #endif |
127 | 127 |
128 ui_init_.reset(new ui::mojo::UIInit( | 128 ui_init_.reset(new ui::mojo::UIInit( |
129 DisplaysFromSizeAndScale(screen_size_in_pixels_, device_pixel_ratio_))); | 129 DisplaysFromSizeAndScale(screen_size_in_pixels_, device_pixel_ratio_))); |
130 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); | 130 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); |
131 | 131 |
132 app_->ConnectToService("mojo:mus", &gpu_service_); | 132 shell_->ConnectToService("mojo:mus", &gpu_service_); |
133 gpu_service_->GetGpuInfo(base::Bind(&GlobalState::GetGpuInfoCallback, | 133 gpu_service_->GetGpuInfo(base::Bind(&GlobalState::GetGpuInfoCallback, |
134 base::Unretained(this))); | 134 base::Unretained(this))); |
135 | 135 |
136 // Use new animation system (cc::AnimationHost). | 136 // Use new animation system (cc::AnimationHost). |
137 cc::LayerSettings layer_settings; | 137 cc::LayerSettings layer_settings; |
138 layer_settings.use_compositor_animation_timelines = true; | 138 layer_settings.use_compositor_animation_timelines = true; |
139 cc_blink::WebLayerImpl::SetLayerSettings(layer_settings); | 139 cc_blink::WebLayerImpl::SetLayerSettings(layer_settings); |
140 blink::WebRuntimeFeatures::enableCompositorAnimationTimelines(true); | 140 blink::WebRuntimeFeatures::enableCompositorAnimationTimelines(true); |
141 | 141 |
142 renderer_scheduler_ = scheduler::RendererScheduler::Create(); | 142 renderer_scheduler_ = scheduler::RendererScheduler::Create(); |
143 blink_platform_.reset( | 143 blink_platform_.reset( |
144 new BlinkPlatformImpl(this, app_, renderer_scheduler_.get())); | 144 new BlinkPlatformImpl(this, shell_, renderer_scheduler_.get())); |
145 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 145 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
146 gin::V8Initializer::LoadV8SnapshotFromFD( | 146 gin::V8Initializer::LoadV8SnapshotFromFD( |
147 resource_loader_.ReleaseFile(kResourceSnapshotBlob).TakePlatformFile(), | 147 resource_loader_.ReleaseFile(kResourceSnapshotBlob).TakePlatformFile(), |
148 0u, 0u); | 148 0u, 0u); |
149 gin::V8Initializer::LoadV8NativesFromFD( | 149 gin::V8Initializer::LoadV8NativesFromFD( |
150 resource_loader_.ReleaseFile(kResourceNativesBlob).TakePlatformFile(), 0u, | 150 resource_loader_.ReleaseFile(kResourceNativesBlob).TakePlatformFile(), 0u, |
151 0u); | 151 0u); |
152 #endif | 152 #endif |
153 blink::initialize(blink_platform_.get()); | 153 blink::initialize(blink_platform_.get()); |
154 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 154 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
(...skipping 18 matching lines...) Expand all Loading... |
173 | 173 |
174 blink_settings_->Init(); | 174 blink_settings_->Init(); |
175 | 175 |
176 // TODO(sky): why is this always using 100? | 176 // TODO(sky): why is this always using 100? |
177 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 177 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
178 std::move(pak_file), ui::SCALE_FACTOR_100P); | 178 std::move(pak_file), ui::SCALE_FACTOR_100P); |
179 | 179 |
180 compositor_thread_.Start(); | 180 compositor_thread_.Start(); |
181 | 181 |
182 media_factory_.reset( | 182 media_factory_.reset( |
183 new MediaFactory(compositor_thread_.task_runner(), app_->shell())); | 183 new MediaFactory(compositor_thread_.task_runner(), shell_)); |
184 | 184 |
185 if (command_line->HasSwitch(kJavaScriptFlags)) { | 185 if (command_line->HasSwitch(kJavaScriptFlags)) { |
186 std::string flags(command_line->GetSwitchValueASCII(kJavaScriptFlags)); | 186 std::string flags(command_line->GetSwitchValueASCII(kJavaScriptFlags)); |
187 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); | 187 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 // TODO(rjkroege): These two functions probably do not interoperate correctly | 191 // TODO(rjkroege): These two functions probably do not interoperate correctly |
192 // with MUS. | 192 // with MUS. |
193 const mus::mojom::GpuInfo* GlobalState::GetGpuInfo() { | 193 const mus::mojom::GpuInfo* GlobalState::GetGpuInfo() { |
194 if (gpu_service_) | 194 if (gpu_service_) |
195 CHECK(gpu_service_.WaitForIncomingResponse()) <<"Get GPU info failed!"; | 195 CHECK(gpu_service_.WaitForIncomingResponse()) <<"Get GPU info failed!"; |
196 return gpu_info_.get(); | 196 return gpu_info_.get(); |
197 } | 197 } |
198 | 198 |
199 void GlobalState::GetGpuInfoCallback(mus::mojom::GpuInfoPtr gpu_info) { | 199 void GlobalState::GetGpuInfoCallback(mus::mojom::GpuInfoPtr gpu_info) { |
200 CHECK(gpu_info); | 200 CHECK(gpu_info); |
201 gpu_info_ = std::move(gpu_info); | 201 gpu_info_ = std::move(gpu_info); |
202 gpu_service_.reset(); | 202 gpu_service_.reset(); |
203 } | 203 } |
204 | 204 |
205 } // namespace html_viewer | 205 } // namespace html_viewer |
OLD | NEW |