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
3 // found in the LICENSE file.
5 #include "mandoline/ui/aura/aura_init.h"
7 #include "base/i18n/icu_util.h"
8 #include "base/lazy_instance.h"
9 #include "base/path_service.h"
10 #include "components/mus/public/cpp/view.h"
11 #include "components/resource_provider/public/cpp/resource_loader.h"
12 #include "mojo/converters/geometry/geometry_type_converters.h"
13 #include "ui/aura/env.h"
14 #include "ui/base/ime/input_method_initializer.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/ui_base_paths.h"
18 #if defined(OS_LINUX) && !defined(OS_ANDROID)
19 #include "components/font_service/public/cpp/font_loader.h"
26 // Paths resources are loaded from.
27 const char kResourceUIPak
[] = "mandoline_ui.pak";
29 std::set
<std::string
> GetResourcePaths() {
30 std::set
<std::string
> paths
;
31 paths
.insert(kResourceUIPak
);
37 // TODO(sky): the 1.f should be view->viewport_metrics().device_scale_factor,
38 // but that causes clipping problems. No doubt we're not scaling a size
40 AuraInit::AuraInit(mus::View
* view
, mojo::Shell
* shell
)
41 : ui_init_(view
->viewport_metrics().size_in_pixels
.To
<gfx::Size
>(), 1.f
) {
42 aura::Env::CreateInstance(false);
44 InitializeResources(shell
);
46 ui::InitializeInputMethodForTesting();
49 AuraInit::~AuraInit() {
50 #if defined(OS_LINUX) && !defined(OS_ANDROID)
51 if (font_loader_
.get()) {
52 SkFontConfigInterface::SetGlobal(nullptr);
53 // FontLoader is ref counted. We need to explicitly shutdown the background
54 // thread, otherwise the background thread may be shutdown after the app is
55 // torn down, when we're in a bad state.
56 font_loader_
->Shutdown();
61 void AuraInit::InitializeResources(mojo::Shell
* shell
) {
62 if (ui::ResourceBundle::HasSharedInstance())
64 resource_provider::ResourceLoader
resource_loader(shell
, GetResourcePaths());
65 if (!resource_loader
.BlockUntilLoaded())
67 CHECK(resource_loader
.loaded());
68 base::i18n::InitializeICUWithFileDescriptor(
69 resource_loader
.GetICUFile().TakePlatformFile(),
70 base::MemoryMappedFile::Region::kWholeFile
);
71 ui::RegisterPathProvider();
72 ui::ResourceBundle::InitSharedInstanceWithPakPath(base::FilePath());
73 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
74 resource_loader
.ReleaseFile(kResourceUIPak
),
75 ui::SCALE_FACTOR_100P
);
77 // Initialize the skia font code to go ask fontconfig underneath.
78 #if defined(OS_LINUX) && !defined(OS_ANDROID)
79 font_loader_
= skia::AdoptRef(new font_service::FontLoader(shell
));
80 SkFontConfigInterface::SetGlobal(font_loader_
.get());
83 // There is a bunch of static state in gfx::Font, by running this now,
84 // before any other apps load, we ensure all the state is set up.
88 } // namespace mandoline