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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/i18n/icu_util.h" | 11 #include "base/i18n/icu_util.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "components/html_viewer/blink_platform_impl.h" | 13 #include "components/html_viewer/blink_platform_impl.h" |
14 #include "components/html_viewer/media_factory.h" | 14 #include "components/html_viewer/media_factory.h" |
15 #include "components/scheduler/renderer/renderer_scheduler.h" | 15 #include "components/scheduler/renderer/renderer_scheduler.h" |
16 #include "gin/v8_initializer.h" | 16 #include "gin/v8_initializer.h" |
17 #include "mojo/application/public/cpp/application_impl.h" | 17 #include "mojo/application/public/cpp/application_impl.h" |
18 #include "mojo/logging/init_logging.h" | 18 #include "mojo/logging/init_logging.h" |
19 #include "third_party/WebKit/public/web/WebKit.h" | 19 #include "third_party/WebKit/public/web/WebKit.h" |
20 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 20 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/base/ui_base_paths.h" | 22 #include "ui/base/ui_base_paths.h" |
| 23 #include "ui/gfx/display.h" |
23 #include "ui/mojo/init/ui_init.h" | 24 #include "ui/mojo/init/ui_init.h" |
24 #include "v8/include/v8.h" | 25 #include "v8/include/v8.h" |
25 | 26 |
26 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 27 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
27 #include "components/font_service/public/cpp/font_loader.h" | 28 #include "components/font_service/public/cpp/font_loader.h" |
28 #endif | 29 #endif |
29 | 30 |
30 namespace html_viewer { | 31 namespace html_viewer { |
31 | 32 |
32 namespace { | 33 namespace { |
(...skipping 16 matching lines...) Expand all Loading... |
49 std::set<std::string> GetResourcePaths() { | 50 std::set<std::string> GetResourcePaths() { |
50 std::set<std::string> paths; | 51 std::set<std::string> paths; |
51 paths.insert(kResourceResourcesPak); | 52 paths.insert(kResourceResourcesPak); |
52 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 53 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
53 paths.insert(kResourceNativesBlob); | 54 paths.insert(kResourceNativesBlob); |
54 paths.insert(kResourceSnapshotBlob); | 55 paths.insert(kResourceSnapshotBlob); |
55 #endif | 56 #endif |
56 return paths; | 57 return paths; |
57 } | 58 } |
58 | 59 |
| 60 // TODO(sky): convert to using DisplayService. |
| 61 std::vector<gfx::Display> DisplaysFromSizeAndScale( |
| 62 const gfx::Size& screen_size_in_pixels, |
| 63 float device_pixel_ratio) { |
| 64 std::vector<gfx::Display> displays(1); |
| 65 displays[0].set_id(2000); |
| 66 displays[0].SetScaleAndBounds(device_pixel_ratio, |
| 67 gfx::Rect(screen_size_in_pixels)); |
| 68 return displays; |
| 69 } |
| 70 |
59 } // namespace | 71 } // namespace |
60 | 72 |
61 GlobalState::GlobalState(mojo::ApplicationImpl* app) | 73 GlobalState::GlobalState(mojo::ApplicationImpl* app) |
62 : app_(app), | 74 : app_(app), |
63 resource_loader_(app->shell(), GetResourcePaths()), | 75 resource_loader_(app, GetResourcePaths()), |
64 did_init_(false), | 76 did_init_(false), |
65 device_pixel_ratio_(1.f), | 77 device_pixel_ratio_(1.f), |
66 discardable_memory_allocator_(kDesiredMaxMemory), | 78 discardable_memory_allocator_(kDesiredMaxMemory), |
67 compositor_thread_("compositor thread") { | 79 compositor_thread_("compositor thread") {} |
68 } | |
69 | 80 |
70 GlobalState::~GlobalState() { | 81 GlobalState::~GlobalState() { |
71 if (blink_platform_) { | 82 if (blink_platform_) { |
72 renderer_scheduler_->Shutdown(); | 83 renderer_scheduler_->Shutdown(); |
73 blink::shutdown(); | 84 blink::shutdown(); |
74 } | 85 } |
75 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 86 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
76 if (font_loader_.get()) { | 87 if (font_loader_.get()) { |
77 SkFontConfigInterface::SetGlobal(nullptr); | 88 SkFontConfigInterface::SetGlobal(nullptr); |
78 // FontLoader is ref counted. We need to explicitly shutdown the background | 89 // FontLoader is ref counted. We need to explicitly shutdown the background |
(...skipping 19 matching lines...) Expand all Loading... |
98 // Assume on error we're being shut down. | 109 // Assume on error we're being shut down. |
99 app_->Quit(); | 110 app_->Quit(); |
100 return; | 111 return; |
101 } | 112 } |
102 | 113 |
103 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 114 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
104 font_loader_ = skia::AdoptRef(new font_service::FontLoader(app_)); | 115 font_loader_ = skia::AdoptRef(new font_service::FontLoader(app_)); |
105 SkFontConfigInterface::SetGlobal(font_loader_.get()); | 116 SkFontConfigInterface::SetGlobal(font_loader_.get()); |
106 #endif | 117 #endif |
107 | 118 |
108 ui_init_.reset( | 119 ui_init_.reset(new ui::mojo::UIInit( |
109 new ui::mojo::UIInit(screen_size_in_pixels, device_pixel_ratio)); | 120 DisplaysFromSizeAndScale(screen_size_in_pixels_, device_pixel_ratio_))); |
110 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); | 121 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); |
111 | 122 |
112 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 123 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
113 request->url = mojo::String::From("mojo:mus"); | 124 request->url = mojo::String::From("mojo:mus"); |
114 app_->ConnectToService(request.Pass(), &gpu_service_); | 125 app_->ConnectToService(request.Pass(), &gpu_service_); |
115 gpu_service_->GetGpuInfo(base::Bind(&GlobalState::GetGpuInfoCallback, | 126 gpu_service_->GetGpuInfo(base::Bind(&GlobalState::GetGpuInfoCallback, |
116 base::Unretained(this))); | 127 base::Unretained(this))); |
117 | 128 |
118 renderer_scheduler_ = scheduler::RendererScheduler::Create(); | 129 renderer_scheduler_ = scheduler::RendererScheduler::Create(); |
119 blink_platform_.reset( | 130 blink_platform_.reset( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return gpu_info_.get(); | 176 return gpu_info_.get(); |
166 } | 177 } |
167 | 178 |
168 void GlobalState::GetGpuInfoCallback(mojo::GpuInfoPtr gpu_info) { | 179 void GlobalState::GetGpuInfoCallback(mojo::GpuInfoPtr gpu_info) { |
169 CHECK(gpu_info); | 180 CHECK(gpu_info); |
170 gpu_info_ = gpu_info.Pass(); | 181 gpu_info_ = gpu_info.Pass(); |
171 gpu_service_.reset(); | 182 gpu_service_.reset(); |
172 } | 183 } |
173 | 184 |
174 } // namespace html_viewer | 185 } // namespace html_viewer |
OLD | NEW |