summaryrefslogtreecommitdiffstats
path: root/components/native_viewport/native_viewport_application_delegate.cc
blob: 4f247c7a5c55a20feedee52352257dc7d6b7d56a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/native_viewport/native_viewport_application_delegate.h"

#include "base/command_line.h"
#include "components/native_viewport/native_viewport_impl.h"
#include "components/native_viewport/public/cpp/args.h"
#include "mojo/application/public/cpp/application_connection.h"
#include "mojo/application/public/cpp/application_impl.h"
#include "ui/events/event_switches.h"
#include "ui/gl/gl_surface.h"

namespace native_viewport {

NativeViewportApplicationDelegate::NativeViewportApplicationDelegate()
    : is_headless_(false) {
}

NativeViewportApplicationDelegate::~NativeViewportApplicationDelegate() {
}

void NativeViewportApplicationDelegate::Initialize(
    mojo::ApplicationImpl* application) {
  tracing_.Initialize(application);

  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
  is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig);
  if (!is_headless_) {
    if (command_line->HasSwitch(mojo::kUseTestConfig))
      gfx::GLSurface::InitializeOneOffForTests();
    else
      gfx::GLSurface::InitializeOneOff();
  }
}

bool NativeViewportApplicationDelegate::ConfigureIncomingConnection(
    mojo::ApplicationConnection* connection) {
  connection->AddService<mojo::NativeViewport>(this);
  connection->AddService<mojo::Gpu>(this);
  return true;
}

void NativeViewportApplicationDelegate::Create(
    mojo::ApplicationConnection* connection,
    mojo::InterfaceRequest<mojo::NativeViewport> request) {
  if (!gpu_state_.get())
    gpu_state_ = new gles2::GpuState;
  new NativeViewportImpl(is_headless_, gpu_state_, request.Pass());
}

void NativeViewportApplicationDelegate::Create(
    mojo::ApplicationConnection* connection,
    mojo::InterfaceRequest<mojo::Gpu> request) {
  if (!gpu_state_.get())
    gpu_state_ = new gles2::GpuState;
  new gles2::GpuImpl(request.Pass(), gpu_state_);
}

}  // namespace native_viewport