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

Side by Side Diff: blimp/client/app/linux/blimp_main.cc

Issue 2503763002: Revert of Add skia extension to allow setting default fontmgr on linux. Use it to allow the linux blimp clien… (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | blimp/client/core/switches/blimp_client_switches.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <string> 5 #include <string>
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "blimp/client/app/blimp_startup.h" 12 #include "blimp/client/app/blimp_startup.h"
13 #include "blimp/client/app/linux/blimp_client_context_delegate_linux.h" 13 #include "blimp/client/app/linux/blimp_client_context_delegate_linux.h"
14 #include "blimp/client/app/linux/blimp_display_manager.h" 14 #include "blimp/client/app/linux/blimp_display_manager.h"
15 #include "blimp/client/app/linux/blimp_display_manager_delegate_main.h" 15 #include "blimp/client/app/linux/blimp_display_manager_delegate_main.h"
16 #include "blimp/client/core/settings/settings_prefs.h" 16 #include "blimp/client/core/settings/settings_prefs.h"
17 #include "blimp/client/core/switches/blimp_client_switches.h"
18 #include "blimp/client/public/blimp_client_context.h" 17 #include "blimp/client/public/blimp_client_context.h"
19 #include "blimp/client/public/contents/blimp_navigation_controller.h" 18 #include "blimp/client/public/contents/blimp_navigation_controller.h"
20 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" 19 #include "blimp/client/support/compositor/compositor_dependencies_impl.h"
21 #include "components/pref_registry/pref_registry_syncable.h" 20 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "components/prefs/command_line_pref_store.h" 21 #include "components/prefs/command_line_pref_store.h"
23 #include "components/prefs/in_memory_pref_store.h" 22 #include "components/prefs/in_memory_pref_store.h"
24 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
25 #include "components/prefs/pref_service_factory.h" 24 #include "components/prefs/pref_service_factory.h"
26 #include "skia/ext/fontmgr_default_linux.h"
27 #include "third_party/skia/include/ports/SkFontConfigInterface.h"
28 #include "third_party/skia/include/ports/SkFontMgr.h"
29 #include "third_party/skia/include/ports/SkFontMgr_android.h"
30 #include "ui/gfx/x/x11_connection.h" 25 #include "ui/gfx/x/x11_connection.h"
31 26
32 namespace { 27 namespace {
33 const char kDefaultUrl[] = "https://www.google.com"; 28 const char kDefaultUrl[] = "https://www.google.com";
34 constexpr int kWindowWidth = 800; 29 constexpr int kWindowWidth = 800;
35 constexpr int kWindowHeight = 600; 30 constexpr int kWindowHeight = 600;
36 31
37 class BlimpShellCommandLinePrefStore : public CommandLinePrefStore { 32 class BlimpShellCommandLinePrefStore : public CommandLinePrefStore {
38 public: 33 public:
39 explicit BlimpShellCommandLinePrefStore(const base::CommandLine* command_line) 34 explicit BlimpShellCommandLinePrefStore(const base::CommandLine* command_line)
40 : CommandLinePrefStore(command_line) { 35 : CommandLinePrefStore(command_line) {
41 blimp::client::BlimpClientContext::ApplyBlimpSwitches(this); 36 blimp::client::BlimpClientContext::ApplyBlimpSwitches(this);
42 } 37 }
43 38
44 protected: 39 protected:
45 ~BlimpShellCommandLinePrefStore() override = default; 40 ~BlimpShellCommandLinePrefStore() override = default;
46 }; 41 };
47
48 bool HasAndroidFontSwitch() {
49 return base::CommandLine::ForCurrentProcess()->HasSwitch(
50 blimp::switches::kAndroidFontsPath);
51 }
52
53 std::string GetAndroidFontsDirectory() {
54 std::string android_fonts_dir =
55 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
56 blimp::switches::kAndroidFontsPath);
57 if (android_fonts_dir.size() > 0 && android_fonts_dir.back() != '/') {
58 android_fonts_dir += '/';
59 }
60 return android_fonts_dir;
61 }
62
63 sk_sp<SkFontMgr> CreateAndroidFontMgr(std::string android_fonts_dir) {
64 SkFontMgr_Android_CustomFonts custom;
65 custom.fSystemFontUse =
66 SkFontMgr_Android_CustomFonts::SystemFontUse::kOnlyCustom;
67 custom.fBasePath = android_fonts_dir.c_str();
68
69 std::string font_config;
70 std::string fallback_font_config;
71 if (android_fonts_dir.find("kitkat") != std::string::npos) {
72 font_config = android_fonts_dir + "system_fonts.xml";
73 fallback_font_config = android_fonts_dir + "fallback_fonts.xml";
74 custom.fFallbackFontsXml = fallback_font_config.c_str();
75 } else {
76 font_config = android_fonts_dir + "fonts.xml";
77 custom.fFallbackFontsXml = nullptr;
78 }
79 custom.fFontsXml = font_config.c_str();
80 custom.fIsolated = true;
81
82 return sk_sp<SkFontMgr>(SkFontMgr_New_Android(&custom));
83 }
84
85 void SetupAndroidFontManager() {
86 if (HasAndroidFontSwitch()) {
87 SetDefaultSkiaFactory(CreateAndroidFontMgr(GetAndroidFontsDirectory()));
88 }
89 }
90 } // namespace 42 } // namespace
91 43
92 int main(int argc, const char**argv) { 44 int main(int argc, const char**argv) {
93 base::AtExitManager at_exit; 45 base::AtExitManager at_exit;
94 base::CommandLine::Init(argc, argv); 46 base::CommandLine::Init(argc, argv);
95 SetupAndroidFontManager();
96 47
97 CHECK(gfx::InitializeThreadedX11()); 48 CHECK(gfx::InitializeThreadedX11());
98 49
99 blimp::client::InitializeLogging(); 50 blimp::client::InitializeLogging();
100 blimp::client::InitializeMainMessageLoop(); 51 blimp::client::InitializeMainMessageLoop();
101 blimp::client::InitializeResourceBundle(); 52 blimp::client::InitializeResourceBundle();
102 53
103 base::Thread io_thread("BlimpIOThread"); 54 base::Thread io_thread("BlimpIOThread");
104 base::Thread::Options options; 55 base::Thread::Options options;
105 options.message_loop_type = base::MessageLoop::TYPE_IO; 56 options.message_loop_type = base::MessageLoop::TYPE_IO;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 std::unique_ptr<blimp::client::BlimpDisplayManagerDelegate> 103 std::unique_ptr<blimp::client::BlimpDisplayManagerDelegate>
153 display_manager_delegate = 104 display_manager_delegate =
154 base::MakeUnique<blimp::client::BlimpDisplayManagerDelegateMain>(); 105 base::MakeUnique<blimp::client::BlimpDisplayManagerDelegateMain>();
155 blimp::client::BlimpDisplayManager display_manager( 106 blimp::client::BlimpDisplayManager display_manager(
156 display_manager_delegate.get(), compositor_dependencies); 107 display_manager_delegate.get(), compositor_dependencies);
157 display_manager.SetWindowSize(gfx::Size(kWindowWidth, kWindowHeight)); 108 display_manager.SetWindowSize(gfx::Size(kWindowWidth, kWindowHeight));
158 display_manager.SetBlimpContents(std::move(contents)); 109 display_manager.SetBlimpContents(std::move(contents));
159 110
160 base::RunLoop().Run(); 111 base::RunLoop().Run();
161 } 112 }
OLDNEW
« no previous file with comments | « no previous file | blimp/client/core/switches/blimp_client_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698