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

Side by Side Diff: components/html_viewer/setup.cc

Issue 1136743003: Plumbs through screen size and scale factor to html_viewer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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 | « components/html_viewer/setup.h ('k') | components/html_viewer/ui_setup.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "components/html_viewer/setup.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/i18n/icu_util.h"
10 #include "base/logging.h"
11 #include "components/html_viewer/blink_platform_impl.h"
12 #include "components/html_viewer/web_media_player_factory.h"
13 #include "components/scheduler/renderer/renderer_scheduler.h"
14 #include "gin/v8_initializer.h"
15 #include "third_party/WebKit/public/web/WebKit.h"
16 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
17 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/base/ui_base_paths.h"
20
21 #if defined(OS_ANDROID)
22 #include "components/html_viewer/ui_setup_android.h"
23 #else
24 #include "components/html_viewer/ui_setup.h"
25 #endif
26
27 namespace html_viewer {
28
29 namespace {
30
31 // Enable MediaRenderer in media pipeline instead of using the internal
32 // media::Renderer implementation.
33 const char kEnableMojoMediaRenderer[] = "enable-mojo-media-renderer";
34
35 // Disables support for (unprefixed) Encrypted Media Extensions.
36 const char kDisableEncryptedMedia[] = "disable-encrypted-media";
37
38 // Prevents creation of any output surface.
39 const char kIsHeadless[] = "is-headless";
40
41 size_t kDesiredMaxMemory = 20 * 1024 * 1024;
42
43 // Paths resources are loaded from.
44 const char kResourceIcudtl[] = "icudtl.dat";
45 const char kResourceResourcesPak[] = "html_viewer_resources.pak";
46 const char kResourceUIPak[] = "ui_test.pak";
47 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
48 const char kResourceNativesBlob[] = "natives_blob.bin";
49 const char kResourceSnapshotBlob[] = "snapshot_blob.bin";
50 #endif
51
52 std::set<std::string> GetResourcePaths() {
53 std::set<std::string> paths;
54 paths.insert(kResourceResourcesPak);
55 paths.insert(kResourceIcudtl);
56 paths.insert(kResourceUIPak);
57 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
58 paths.insert(kResourceNativesBlob);
59 paths.insert(kResourceSnapshotBlob);
60 #endif
61 return paths;
62 }
63
64 } // namespace
65
66 Setup::Setup(mojo::ApplicationImpl* app)
67 : app_(app),
68 resource_loader_(app->shell(), GetResourcePaths()),
69 is_headless_(
70 base::CommandLine::ForCurrentProcess()->HasSwitch(kIsHeadless)),
71 did_init_(false),
72 device_pixel_ratio_(1.f),
73 discardable_memory_allocator_(kDesiredMaxMemory),
74 compositor_thread_("compositor thread") {
75 if (is_headless_)
76 InitHeadless();
77 }
78
79 Setup::~Setup() {
80 }
81
82 void Setup::InitHeadless() {
83 DCHECK(!did_init_);
84 is_headless_ = true;
85 InitIfNecessary(gfx::Size(1024, 1024), 1.f);
86 }
87
88 void Setup::InitIfNecessary(const gfx::Size& screen_size_in_pixels,
89 float device_pixel_ratio) {
90 if (did_init_)
91 return;
92
93 DCHECK_NE(0.f, device_pixel_ratio);
94
95 did_init_ = true;
96 device_pixel_ratio_ = device_pixel_ratio;
97 screen_size_in_pixels_ = screen_size_in_pixels;
98
99 if (!resource_loader_.BlockUntilLoaded()) {
100 // Assume on error we're being shut down.
101 mojo::ApplicationImpl::Terminate();
102 return;
103 }
104
105 ui_setup_.reset(new UISetup(screen_size_in_pixels, device_pixel_ratio));
106 base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_);
107
108 renderer_scheduler_ = scheduler::RendererScheduler::Create();
109 blink_platform_.reset(new BlinkPlatformImpl(app_, renderer_scheduler_.get()));
110 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
111 CHECK(gin::V8Initializer::LoadV8SnapshotFromFD(
112 resource_loader_.ReleaseFile(kResourceNativesBlob).TakePlatformFile(), 0u,
113 0u,
114 resource_loader_.ReleaseFile(kResourceSnapshotBlob).TakePlatformFile(),
115 0u, 0u));
116 #endif
117 blink::initialize(blink_platform_.get());
118 base::i18n::InitializeICUWithFileDescriptor(
119 resource_loader_.ReleaseFile(kResourceIcudtl).TakePlatformFile(),
120 base::MemoryMappedFile::Region::kWholeFile);
121
122 ui::RegisterPathProvider();
123
124 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
125
126 logging::LoggingSettings settings;
127 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
128 logging::InitLogging(settings);
129 // Display process ID, thread ID and timestamp in logs.
130 logging::SetLogItems(true, true, true, false);
131
132 if (command_line->HasSwitch(kDisableEncryptedMedia))
133 blink::WebRuntimeFeatures::enableEncryptedMedia(false);
134
135 if (!is_headless_) {
136 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
137 resource_loader_.ReleaseFile(kResourceResourcesPak),
138 base::MemoryMappedFile::Region::kWholeFile);
139 // TODO(sky): why is this always using 100?
140 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
141 resource_loader_.ReleaseFile(kResourceUIPak), ui::SCALE_FACTOR_100P);
142 }
143
144 compositor_thread_.Start();
145 #if defined(OS_ANDROID)
146 // TODO(sky): Get WebMediaPlayerFactory working on android.
147 NOTIMPLEMENTED();
148 #else
149 bool enable_mojo_media_renderer =
150 command_line->HasSwitch(kEnableMojoMediaRenderer);
151
152 web_media_player_factory_.reset(new WebMediaPlayerFactory(
153 compositor_thread_.message_loop_proxy(), enable_mojo_media_renderer));
154 #endif
155 }
156
157 } // namespace html_viewer
OLDNEW
« no previous file with comments | « components/html_viewer/setup.h ('k') | components/html_viewer/ui_setup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698