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_SETUP_H_
6 #define COMPONENTS_HTML_VIEWER_SETUP_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 // Setup encapsulates the necessary state needed by HTMLViewer. Some objects
38 // are created immediately in the constructor, otherwise not until
39 // InitIfNecessary() is invoked.
40 // Setup can be initialized in two distinct ways:
41 // . headless: this is determined by the command line, but can be forced by way
43 // . with a ui: this is done via InitIfNecessary().
46 explicit Setup(mojo::ApplicationImpl
* app
);
49 // Inits with the specified screen size and device pixel ratio.
50 // NOTE: we wait to complete setup until the device pixel ratio is available
51 // as ResourceBundle uses the device pixel ratio during initialization.
52 void InitIfNecessary(const gfx::Size
& screen_size_in_pixels
,
53 float device_pixel_ratio
);
55 bool is_headless() const { return is_headless_
; }
56 bool did_init() const { return did_init_
; }
58 const gfx::Size
& screen_size_in_pixels() const {
59 return screen_size_in_pixels_
;
62 float device_pixel_ratio() const { return device_pixel_ratio_
; }
64 scoped_refptr
<base::SingleThreadTaskRunner
> compositor_thread() {
65 return compositor_thread_
.task_runner();
68 gles2::RasterThreadHelper
* raster_thread_helper() {
69 return &raster_thread_helper_
;
72 gles2::MojoGpuMemoryBufferManager
* gpu_memory_buffer_manager() {
73 return &gpu_memory_buffer_manager_
;
76 MediaFactory
* media_factory() { return media_factory_
.get(); }
79 // App for HTMLViewer, not the document's app.
80 // WARNING: do not expose this. It's too easy to use the wrong one.
81 // HTMLDocument should be using the application it creates, not this one.
82 mojo::ApplicationImpl
* app_
;
84 resource_provider::ResourceLoader resource_loader_
;
86 const bool is_headless_
;
88 // True once we've completed init.
91 float device_pixel_ratio_
;
93 gfx::Size screen_size_in_pixels_
;
95 scoped_ptr
<ui::mojo::UIInit
> ui_init_
;
97 // Skia requires that we have one of these. Unlike the one used in chrome,
98 // this doesn't use purgable shared memory. Instead, it tries to free the
99 // oldest unlocked chunks on allocation.
101 // TODO(erg): In the long run, delete this allocator and get the real shared
102 // memory based purging allocator working here.
103 DiscardableMemoryAllocator discardable_memory_allocator_
;
105 scoped_ptr
<scheduler::RendererScheduler
> renderer_scheduler_
;
106 scoped_ptr
<BlinkPlatformImpl
> blink_platform_
;
107 base::Thread compositor_thread_
;
108 gles2::RasterThreadHelper raster_thread_helper_
;
109 gles2::MojoGpuMemoryBufferManager gpu_memory_buffer_manager_
;
110 scoped_ptr
<MediaFactory
> media_factory_
;
112 DISALLOW_COPY_AND_ASSIGN(Setup
);
115 } // namespace html_viewer
117 #endif // COMPONENTS_HTML_VIEWER_SETUP_H_