23
23
#include "base/command_line.h"
24
#include "base/files/file_path.h"
25
24
#include "base/logging.h"
26
25
#include "base/memory/ref_counted.h"
27
26
#include "base/memory/scoped_ptr.h"
28
#include "base/message_loop/message_loop.h"
29
#include "base/scoped_native_library.h"
30
27
#include "content/browser/gpu/compositor_util.h"
31
28
#include "content/browser/gpu/gpu_data_manager_impl.h"
32
29
#include "content/browser/gpu/gpu_process_host.h"
33
#include "content/public/browser/browser_main_parts.h"
34
30
#include "content/public/browser/certificate_request_result_type.h"
35
31
#include "content/public/browser/render_frame_host.h"
36
32
#include "content/public/browser/render_process_host.h"
37
33
#include "content/public/browser/resource_dispatcher_host.h"
38
34
#include "content/public/common/content_switches.h"
39
35
#include "content/public/common/web_preferences.h"
40
#include "net/base/net_module.h"
41
#include "third_party/khronos/EGL/egl.h"
42
#include "third_party/WebKit/public/platform/WebScreenInfo.h"
43
#include "ui/gfx/display.h"
44
#include "ui/gfx/screen.h"
45
#include "ui/gfx/screen_type_delegate.h"
46
36
#include "ui/gl/gl_context.h"
47
37
#include "ui/gl/gl_implementation.h"
48
38
#include "ui/gl/gl_share_group.h"
49
#include "ui/gl/gl_surface.h"
51
#include "shared/browser/compositor/oxide_compositor_utils.h"
52
40
#include "shared/common/oxide_constants.h"
53
41
#include "shared/common/oxide_content_client.h"
54
42
#include "shared/common/oxide_messages.h"
55
#include "shared/common/oxide_net_resource_provider.h"
56
43
#include "shared/gl/oxide_shared_gl_context.h"
58
45
#include "oxide_access_token_store.h"
59
46
#include "oxide_browser_context.h"
60
47
#include "oxide_browser_process_main.h"
61
#include "oxide_default_screen_info.h"
62
48
#include "oxide_form_factor.h"
63
#include "oxide_io_thread.h"
64
#include "oxide_message_pump.h"
65
49
#include "oxide_resource_dispatcher_host_delegate.h"
66
50
#include "oxide_script_message_dispatcher_browser.h"
67
51
#include "oxide_user_agent_override_provider.h"
83
scoped_ptr<base::MessagePump> CreateMessagePumpForUI() {
84
return make_scoped_ptr(
85
ContentClient::instance()->browser()->CreateMessagePumpForUI());
88
class ScopedBindGLESAPI {
91
virtual ~ScopedBindGLESAPI();
94
typedef EGLBoolean (*_eglBindAPI)(EGLenum);
95
typedef EGLenum (*_eglQueryAPI)(void);
98
base::ScopedNativeLibrary egl_lib_;
102
ScopedBindGLESAPI::ScopedBindGLESAPI()
104
orig_api_(EGL_NONE) {
105
egl_lib_.Reset(base::LoadNativeLibrary(base::FilePath("libEGL.so.1"), NULL));
106
if (!egl_lib_.is_valid()) {
110
_eglBindAPI eglBindAPI = reinterpret_cast<_eglBindAPI>(
111
egl_lib_.GetFunctionPointer("eglBindAPI"));
112
_eglQueryAPI eglQueryAPI = reinterpret_cast<_eglQueryAPI>(
113
egl_lib_.GetFunctionPointer("eglQueryAPI"));
114
if (!eglBindAPI || !eglQueryAPI) {
118
orig_api_ = eglQueryAPI();
119
if (orig_api_ == EGL_NONE) {
125
eglBindAPI(EGL_OPENGL_ES_API);
128
ScopedBindGLESAPI::~ScopedBindGLESAPI() {
133
DCHECK(egl_lib_.is_valid());
134
DCHECK_NE(orig_api_, EGL_NONE);
136
_eglBindAPI eglBindAPI = reinterpret_cast<_eglBindAPI>(
137
egl_lib_.GetFunctionPointer("eglBindAPI"));
140
eglBindAPI(orig_api_);
143
class Screen : public gfx::Screen {
147
bool IsDIPEnabled() FINAL {
152
gfx::Point GetCursorScreenPoint() FINAL {
157
gfx::NativeWindow GetWindowUnderCursor() FINAL {
162
gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) FINAL {
167
int GetNumDisplays() const FINAL {
172
std::vector<gfx::Display> GetAllDisplays() const FINAL {
174
return std::vector<gfx::Display>();
177
gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const FINAL {
179
return gfx::Display();
182
gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const FINAL {
184
return gfx::Display();
187
gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const FINAL {
189
return gfx::Display();
192
gfx::Display GetPrimaryDisplay() const FINAL {
193
blink::WebScreenInfo info(GetDefaultWebScreenInfo());
195
gfx::Display display;
196
display.set_bounds(info.rect);
197
display.set_work_area(info.availableRect);
198
display.set_device_scale_factor(info.deviceScaleFactor);
203
void AddObserver(gfx::DisplayObserver* observer) FINAL {
206
void RemoveObserver(gfx::DisplayObserver* observer) FINAL {
211
class BrowserMainParts : public content::BrowserMainParts {
213
BrowserMainParts() {}
214
~BrowserMainParts() {}
216
void PreEarlyInitialization() FINAL {
217
base::MessageLoop::InitMessagePumpForUIFactory(CreateMessagePumpForUI);
218
main_message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI));
221
int PreCreateThreads() FINAL {
222
// When using EGL, we need GLES for surfaceless contexts. Whilst the
223
// default API is GLES and this will be the selected API on the GPU
224
// thread, it is possible that the embedder has selected a different API
225
// on the main thread. Temporarily switch to GLES whilst we initialize
227
ScopedBindGLESAPI gles_binder;
229
// Work around a mesa race - see https://launchpad.net/bugs/1267893
230
gfx::GLSurface::InitializeOneOff();
232
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
234
io_thread_.reset(new IOThread());
239
void PreMainMessageLoopRun() FINAL {
240
CompositorUtils::GetInstance()->Initialize();
241
net::NetModule::SetResourceProvider(NetResourceProvider);
244
bool MainMessageLoopRun(int* result_code) FINAL {
245
MessageLoopForUI::current()->Start();
249
void PostMainMessageLoopRun() FINAL {
250
CompositorUtils::GetInstance()->Destroy();
253
void PostDestroyThreads() FINAL {
254
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
259
scoped_ptr<base::MessageLoop> main_message_loop_;
260
scoped_ptr<IOThread> io_thread_;
261
Screen primary_screen_;
266
65
content::BrowserMainParts* ContentBrowserClient::CreateBrowserMainParts(
267
66
const content::MainFunctionParams& parameters) {
268
return new BrowserMainParts();
67
return new BrowserMainParts(CreateBrowserMainPartsDelegate());
271
70
void ContentBrowserClient::RenderProcessWillLaunch(