| 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 "ui/views/mus/aura_init.h" | 5 #include "ui/views/mus/aura_init.h" | 
| 6 | 6 | 
| 7 #include "base/i18n/icu_util.h" | 7 #include "base/i18n/icu_util.h" | 
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" | 
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" | 
| 10 #include "components/mus/public/cpp/view.h" | 10 #include "components/mus/public/cpp/view.h" | 
| 11 #include "components/resource_provider/public/cpp/resource_loader.h" | 11 #include "components/resource_provider/public/cpp/resource_loader.h" | 
|  | 12 #include "mojo/application/public/cpp/application_impl.h" | 
| 12 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" | 
| 13 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" | 
| 14 #include "ui/base/ime/input_method_initializer.h" | 15 #include "ui/base/ime/input_method_initializer.h" | 
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" | 
| 16 #include "ui/base/ui_base_paths.h" | 17 #include "ui/base/ui_base_paths.h" | 
|  | 18 #include "ui/gfx/display.h" | 
| 17 | 19 | 
| 18 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 20 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 
| 19 #include "components/font_service/public/cpp/font_loader.h" | 21 #include "components/font_service/public/cpp/font_loader.h" | 
| 20 #endif | 22 #endif | 
| 21 | 23 | 
| 22 namespace views { | 24 namespace views { | 
| 23 | 25 | 
| 24 namespace { | 26 namespace { | 
| 25 | 27 | 
| 26 std::set<std::string> GetResourcePaths(const std::string& resource_file) { | 28 std::set<std::string> GetResourcePaths(const std::string& resource_file) { | 
| 27   std::set<std::string> paths; | 29   std::set<std::string> paths; | 
| 28   paths.insert(resource_file); | 30   paths.insert(resource_file); | 
| 29   return paths; | 31   return paths; | 
| 30 } | 32 } | 
| 31 | 33 | 
|  | 34 std::vector<gfx::Display> GetDisplaysFromView(mus::View* view) { | 
|  | 35   static int64 synthesized_display_id = 2000; | 
|  | 36   gfx::Display display; | 
|  | 37   display.set_id(synthesized_display_id++); | 
|  | 38   display.SetScaleAndBounds( | 
|  | 39       view->viewport_metrics().device_pixel_ratio, | 
|  | 40       gfx::Rect(view->viewport_metrics().size_in_pixels.To<gfx::Size>())); | 
|  | 41   std::vector<gfx::Display> displays; | 
|  | 42   displays.push_back(display); | 
|  | 43   return displays; | 
|  | 44 } | 
|  | 45 | 
| 32 }  // namespace | 46 }  // namespace | 
| 33 | 47 | 
| 34 // TODO(sky): the 1.f should be view->viewport_metrics().device_scale_factor, | 48 AuraInit::AuraInit(mojo::ApplicationImpl* app, | 
| 35 // but that causes clipping problems. No doubt we're not scaling a size | 49                    const std::string& resource_file, | 
| 36 // correctly. | 50                    mus::View* view) | 
| 37 AuraInit::AuraInit(mus::View* view, | 51     : AuraInit(app, resource_file, GetDisplaysFromView(view)) {} | 
| 38                    mojo::Shell* shell, | 52 | 
| 39                    const std::string& resource_file) | 53 AuraInit::AuraInit(mojo::ApplicationImpl* app, | 
| 40     : ui_init_(view->viewport_metrics().size_in_pixels.To<gfx::Size>(), 1.f), | 54                    const std::string& resource_file, | 
| 41       resource_file_(resource_file) { | 55                    const std::vector<gfx::Display>& displays) | 
|  | 56     : ui_init_(displays), resource_file_(resource_file) { | 
| 42   aura::Env::CreateInstance(false); | 57   aura::Env::CreateInstance(false); | 
| 43 | 58 | 
| 44   InitializeResources(shell); | 59   InitializeResources(app); | 
| 45 | 60 | 
| 46   ui::InitializeInputMethodForTesting(); | 61   ui::InitializeInputMethodForTesting(); | 
| 47 } | 62 } | 
| 48 | 63 | 
| 49 AuraInit::~AuraInit() { | 64 AuraInit::~AuraInit() { | 
| 50 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 65 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 
| 51   if (font_loader_.get()) { | 66   if (font_loader_.get()) { | 
| 52     SkFontConfigInterface::SetGlobal(nullptr); | 67     SkFontConfigInterface::SetGlobal(nullptr); | 
| 53     // FontLoader is ref counted. We need to explicitly shutdown the background | 68     // FontLoader is ref counted. We need to explicitly shutdown the background | 
| 54     // thread, otherwise the background thread may be shutdown after the app is | 69     // thread, otherwise the background thread may be shutdown after the app is | 
| 55     // torn down, when we're in a bad state. | 70     // torn down, when we're in a bad state. | 
| 56     font_loader_->Shutdown(); | 71     font_loader_->Shutdown(); | 
| 57   } | 72   } | 
| 58 #endif | 73 #endif | 
| 59 } | 74 } | 
| 60 | 75 | 
| 61 void AuraInit::InitializeResources(mojo::Shell* shell) { | 76 void AuraInit::InitializeResources(mojo::ApplicationImpl* app) { | 
| 62   if (ui::ResourceBundle::HasSharedInstance()) | 77   if (ui::ResourceBundle::HasSharedInstance()) | 
| 63     return; | 78     return; | 
| 64   resource_provider::ResourceLoader resource_loader( | 79   resource_provider::ResourceLoader resource_loader( | 
| 65       shell, GetResourcePaths(resource_file_)); | 80       app, GetResourcePaths(resource_file_)); | 
| 66   if (!resource_loader.BlockUntilLoaded()) | 81   if (!resource_loader.BlockUntilLoaded()) | 
| 67     return; | 82     return; | 
| 68   CHECK(resource_loader.loaded()); | 83   CHECK(resource_loader.loaded()); | 
| 69   base::i18n::InitializeICUWithFileDescriptor( | 84   base::i18n::InitializeICUWithFileDescriptor( | 
| 70       resource_loader.GetICUFile().TakePlatformFile(), | 85       resource_loader.GetICUFile().TakePlatformFile(), | 
| 71       base::MemoryMappedFile::Region::kWholeFile); | 86       base::MemoryMappedFile::Region::kWholeFile); | 
| 72   ui::RegisterPathProvider(); | 87   ui::RegisterPathProvider(); | 
| 73   base::File pak_file = resource_loader.ReleaseFile(resource_file_); | 88   base::File pak_file = resource_loader.ReleaseFile(resource_file_); | 
| 74   base::File pak_file_2 = pak_file.Duplicate(); | 89   base::File pak_file_2 = pak_file.Duplicate(); | 
| 75   ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 90   ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 
| 76       pak_file.Pass(), base::MemoryMappedFile::Region::kWholeFile); | 91       pak_file.Pass(), base::MemoryMappedFile::Region::kWholeFile); | 
| 77   ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 92   ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 
| 78       pak_file_2.Pass(), ui::SCALE_FACTOR_100P); | 93       pak_file_2.Pass(), ui::SCALE_FACTOR_100P); | 
| 79 | 94 | 
| 80 // Initialize the skia font code to go ask fontconfig underneath. | 95 // Initialize the skia font code to go ask fontconfig underneath. | 
| 81 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 96 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 
| 82   font_loader_ = skia::AdoptRef(new font_service::FontLoader(shell)); | 97   font_loader_ = skia::AdoptRef(new font_service::FontLoader(app->shell())); | 
| 83   SkFontConfigInterface::SetGlobal(font_loader_.get()); | 98   SkFontConfigInterface::SetGlobal(font_loader_.get()); | 
| 84 #endif | 99 #endif | 
| 85 | 100 | 
| 86   // There is a bunch of static state in gfx::Font, by running this now, | 101   // There is a bunch of static state in gfx::Font, by running this now, | 
| 87   // before any other apps load, we ensure all the state is set up. | 102   // before any other apps load, we ensure all the state is set up. | 
| 88   gfx::Font(); | 103   gfx::Font(); | 
| 89 } | 104 } | 
| 90 | 105 | 
| 91 }  // namespace views | 106 }  // namespace views | 
| OLD | NEW | 
|---|