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
{
23 class ApplicationImpl
;
34 class RendererScheduler
;
37 namespace html_viewer
{
39 class BlinkPlatformImpl
;
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
49 // . with a ui: this is done via InitIfNecessary().
52 explicit GlobalState(mojo::ApplicationImpl
* app
);
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(); }
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.
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_
;
119 DISALLOW_COPY_AND_ASSIGN(GlobalState
);
122 } // namespace html_viewer
124 #endif // COMPONENTS_HTML_VIEWER_GLOBAL_STATE_H_