OLD | NEW |
| (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 #ifndef COMPONENTS_HTML_VIEWER_GLOBAL_STATE_H_ | |
6 #define COMPONENTS_HTML_VIEWER_GLOBAL_STATE_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/threading/thread.h" | |
11 #include "build/build_config.h" | |
12 #include "components/html_viewer/blink_settings.h" | |
13 #include "components/html_viewer/discardable_memory_allocator.h" | |
14 #include "components/mus/gles2/mojo_gpu_memory_buffer_manager.h" | |
15 #include "components/mus/gles2/raster_thread_helper.h" | |
16 #include "components/mus/public/interfaces/gpu.mojom.h" | |
17 #include "components/resource_provider/public/cpp/resource_loader.h" | |
18 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | |
19 #include "skia/ext/refptr.h" | |
20 #include "ui/gfx/geometry/size.h" | |
21 | |
22 namespace font_service { | |
23 class FontLoader; | |
24 } | |
25 | |
26 namespace mojo { | |
27 class Shell; | |
28 } | |
29 | |
30 namespace ui { | |
31 namespace mojo { | |
32 class UIInit; | |
33 } | |
34 } | |
35 | |
36 namespace scheduler { | |
37 class RendererScheduler; | |
38 } | |
39 | |
40 namespace html_viewer { | |
41 | |
42 class BlinkPlatformImpl; | |
43 class MediaFactory; | |
44 | |
45 // GlobalState encapsulates the necessary state needed by HTMLViewer. Some | |
46 // objects are created immediately in the constructor, otherwise not until | |
47 // InitIfNecessary() is invoked. | |
48 // | |
49 // GlobalState can be initialized in two distinct ways: | |
50 // . headless: this is determined by the command line, but can be forced by way | |
51 // of InitHeadless(). | |
52 // . with a ui: this is done via InitIfNecessary(). | |
53 class GlobalState { | |
54 public: | |
55 GlobalState(mojo::Shell* shell, const std::string& url); | |
56 ~GlobalState(); | |
57 | |
58 // Inits with the specified screen size and device pixel ratio. | |
59 // NOTE: we wait to complete setup until the device pixel ratio is available | |
60 // as ResourceBundle uses the device pixel ratio during initialization. | |
61 void InitIfNecessary(const gfx::Size& screen_size_in_pixels, | |
62 float device_pixel_ratio); | |
63 | |
64 bool did_init() const { return did_init_; } | |
65 | |
66 const gfx::Size& screen_size_in_pixels() const { | |
67 return screen_size_in_pixels_; | |
68 } | |
69 | |
70 float device_pixel_ratio() const { return device_pixel_ratio_; } | |
71 | |
72 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread() { | |
73 return compositor_thread_.task_runner(); | |
74 } | |
75 | |
76 gles2::RasterThreadHelper* raster_thread_helper() { | |
77 return &raster_thread_helper_; | |
78 } | |
79 | |
80 mus::MojoGpuMemoryBufferManager* gpu_memory_buffer_manager() { | |
81 return &gpu_memory_buffer_manager_; | |
82 } | |
83 | |
84 const mus::mojom::GpuInfo* GetGpuInfo(); | |
85 | |
86 MediaFactory* media_factory() { return media_factory_.get(); } | |
87 | |
88 BlinkSettings* blink_settings() { return blink_settings_.get(); } | |
89 void set_blink_settings(BlinkSettings* blink_settings) { | |
90 blink_settings_.reset(blink_settings); | |
91 } | |
92 | |
93 private: | |
94 // Callback for |gpu_service_|->GetGpuInfo(). | |
95 void GetGpuInfoCallback(mus::mojom::GpuInfoPtr gpu_info); | |
96 | |
97 // App for HTMLViewer, not the document's app. | |
98 // WARNING: do not expose this. It's too easy to use the wrong one. | |
99 // HTMLDocument should be using the application it creates, not this one. | |
100 mojo::Shell* shell_; | |
101 | |
102 resource_provider::ResourceLoader resource_loader_; | |
103 | |
104 // True once we've completed init. | |
105 bool did_init_; | |
106 | |
107 float device_pixel_ratio_; | |
108 | |
109 gfx::Size screen_size_in_pixels_; | |
110 | |
111 scoped_ptr<ui::mojo::UIInit> ui_init_; | |
112 | |
113 // Skia requires that we have one of these. Unlike the one used in chrome, | |
114 // this doesn't use purgable shared memory. Instead, it tries to free the | |
115 // oldest unlocked chunks on allocation. | |
116 // | |
117 // TODO(erg): In the long run, delete this allocator and get the real shared | |
118 // memory based purging allocator working here. | |
119 DiscardableMemoryAllocator discardable_memory_allocator_; | |
120 | |
121 mojo::TracingImpl tracing_; | |
122 | |
123 scoped_ptr<scheduler::RendererScheduler> renderer_scheduler_; | |
124 scoped_ptr<BlinkPlatformImpl> blink_platform_; | |
125 base::Thread compositor_thread_; | |
126 gles2::RasterThreadHelper raster_thread_helper_; | |
127 mus::MojoGpuMemoryBufferManager gpu_memory_buffer_manager_; | |
128 mus::mojom::GpuPtr gpu_service_; | |
129 mus::mojom::GpuInfoPtr gpu_info_; | |
130 scoped_ptr<MediaFactory> media_factory_; | |
131 | |
132 scoped_ptr<BlinkSettings> blink_settings_; | |
133 | |
134 #if defined(OS_LINUX) && !defined(OS_ANDROID) | |
135 skia::RefPtr<font_service::FontLoader> font_loader_; | |
136 #endif | |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(GlobalState); | |
139 }; | |
140 | |
141 } // namespace html_viewer | |
142 | |
143 #endif // COMPONENTS_HTML_VIEWER_GLOBAL_STATE_H_ | |
OLD | NEW |