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/resource_provider/public/cpp/resource_loader.h"
13 #include "components/view_manager/gles2/mojo_gpu_memory_buffer_manager.h"
14 #include "components/view_manager/gles2/raster_thread_helper.h"
15 #include "ui/gfx/geometry/size.h"
18 class ApplicationImpl
;
29 class RendererScheduler
;
32 namespace html_viewer
{
34 class BlinkPlatformImpl
;
37 // GlobalState encapsulates the necessary state needed by HTMLViewer. Some
38 // objects are created immediately in the constructor, otherwise not until
39 // InitIfNecessary() is invoked.
41 // GlobalState can be initialized in two distinct ways:
42 // . headless: this is determined by the command line, but can be forced by way
44 // . with a ui: this is done via InitIfNecessary().
47 explicit GlobalState(mojo::ApplicationImpl
* app
);
50 // Inits with the specified screen size and device pixel ratio.
51 // NOTE: we wait to complete setup until the device pixel ratio is available
52 // as ResourceBundle uses the device pixel ratio during initialization.
53 void InitIfNecessary(const gfx::Size
& screen_size_in_pixels
,
54 float device_pixel_ratio
);
56 bool is_headless() const { return is_headless_
; }
57 bool did_init() const { return did_init_
; }
59 const gfx::Size
& screen_size_in_pixels() const {
60 return screen_size_in_pixels_
;
63 float device_pixel_ratio() const { return device_pixel_ratio_
; }
65 scoped_refptr
<base::SingleThreadTaskRunner
> compositor_thread() {
66 return compositor_thread_
.task_runner();
69 gles2::RasterThreadHelper
* raster_thread_helper() {
70 return &raster_thread_helper_
;
73 gles2::MojoGpuMemoryBufferManager
* gpu_memory_buffer_manager() {
74 return &gpu_memory_buffer_manager_
;
77 MediaFactory
* media_factory() { return media_factory_
.get(); }
80 // App for HTMLViewer, not the document's app.
81 // WARNING: do not expose this. It's too easy to use the wrong one.
82 // HTMLDocument should be using the application it creates, not this one.
83 mojo::ApplicationImpl
* app_
;
85 resource_provider::ResourceLoader resource_loader_
;
87 const bool is_headless_
;
89 // True once we've completed init.
92 float device_pixel_ratio_
;
94 gfx::Size screen_size_in_pixels_
;
96 scoped_ptr
<ui::mojo::UIInit
> ui_init_
;
98 // Skia requires that we have one of these. Unlike the one used in chrome,
99 // this doesn't use purgable shared memory. Instead, it tries to free the
100 // oldest unlocked chunks on allocation.
102 // TODO(erg): In the long run, delete this allocator and get the real shared
103 // memory based purging allocator working here.
104 DiscardableMemoryAllocator discardable_memory_allocator_
;
106 scoped_ptr
<scheduler::RendererScheduler
> renderer_scheduler_
;
107 scoped_ptr
<BlinkPlatformImpl
> blink_platform_
;
108 base::Thread compositor_thread_
;
109 gles2::RasterThreadHelper raster_thread_helper_
;
110 gles2::MojoGpuMemoryBufferManager gpu_memory_buffer_manager_
;
111 scoped_ptr
<MediaFactory
> media_factory_
;
113 DISALLOW_COPY_AND_ASSIGN(GlobalState
);
116 } // namespace html_viewer
118 #endif // COMPONENTS_HTML_VIEWER_GLOBAL_STATE_H_