Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / html_viewer / global_state.h
blob0d60e79d46d1e629ef5042f94c5d31e1b8334f8c
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 #ifndef COMPONENTS_HTML_VIEWER_GLOBAL_STATE_H_
6 #define COMPONENTS_HTML_VIEWER_GLOBAL_STATE_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread.h"
11 #include "components/html_viewer/discardable_memory_allocator.h"
12 #include "components/mus/gles2/mojo_gpu_memory_buffer_manager.h"
13 #include "components/mus/gles2/raster_thread_helper.h"
14 #include "components/resource_provider/public/cpp/resource_loader.h"
15 #include "skia/ext/refptr.h"
16 #include "ui/gfx/geometry/size.h"
18 namespace font_service {
19 class FontLoader;
22 namespace mojo {
23 class ApplicationImpl;
24 class Shell;
27 namespace ui {
28 namespace mojo {
29 class UIInit;
33 namespace scheduler {
34 class RendererScheduler;
37 namespace html_viewer {
39 class BlinkPlatformImpl;
40 class MediaFactory;
42 // GlobalState encapsulates the necessary state needed by HTMLViewer. Some
43 // objects are created immediately in the constructor, otherwise not until
44 // InitIfNecessary() is invoked.
46 // GlobalState can be initialized in two distinct ways:
47 // . headless: this is determined by the command line, but can be forced by way
48 // of InitHeadless().
49 // . with a ui: this is done via InitIfNecessary().
50 class GlobalState {
51 public:
52 explicit GlobalState(mojo::ApplicationImpl* app);
53 ~GlobalState();
55 // Inits with the specified screen size and device pixel ratio.
56 // NOTE: we wait to complete setup until the device pixel ratio is available
57 // as ResourceBundle uses the device pixel ratio during initialization.
58 void InitIfNecessary(const gfx::Size& screen_size_in_pixels,
59 float device_pixel_ratio);
61 bool did_init() const { return did_init_; }
63 const gfx::Size& screen_size_in_pixels() const {
64 return screen_size_in_pixels_;
67 float device_pixel_ratio() const { return device_pixel_ratio_; }
69 scoped_refptr<base::SingleThreadTaskRunner> compositor_thread() {
70 return compositor_thread_.task_runner();
73 gles2::RasterThreadHelper* raster_thread_helper() {
74 return &raster_thread_helper_;
77 mus::MojoGpuMemoryBufferManager* gpu_memory_buffer_manager() {
78 return &gpu_memory_buffer_manager_;
81 MediaFactory* media_factory() { return media_factory_.get(); }
83 private:
84 // App for HTMLViewer, not the document's app.
85 // WARNING: do not expose this. It's too easy to use the wrong one.
86 // HTMLDocument should be using the application it creates, not this one.
87 mojo::ApplicationImpl* app_;
89 resource_provider::ResourceLoader resource_loader_;
91 // True once we've completed init.
92 bool did_init_;
94 float device_pixel_ratio_;
96 gfx::Size screen_size_in_pixels_;
98 scoped_ptr<ui::mojo::UIInit> ui_init_;
100 // Skia requires that we have one of these. Unlike the one used in chrome,
101 // this doesn't use purgable shared memory. Instead, it tries to free the
102 // oldest unlocked chunks on allocation.
104 // TODO(erg): In the long run, delete this allocator and get the real shared
105 // memory based purging allocator working here.
106 DiscardableMemoryAllocator discardable_memory_allocator_;
108 scoped_ptr<scheduler::RendererScheduler> renderer_scheduler_;
109 scoped_ptr<BlinkPlatformImpl> blink_platform_;
110 base::Thread compositor_thread_;
111 gles2::RasterThreadHelper raster_thread_helper_;
112 mus::MojoGpuMemoryBufferManager gpu_memory_buffer_manager_;
113 scoped_ptr<MediaFactory> media_factory_;
115 #if defined(OS_LINUX) && !defined(OS_ANDROID)
116 skia::RefPtr<font_service::FontLoader> font_loader_;
117 #endif
119 DISALLOW_COPY_AND_ASSIGN(GlobalState);
122 } // namespace html_viewer
124 #endif // COMPONENTS_HTML_VIEWER_GLOBAL_STATE_H_