summaryrefslogtreecommitdiff
path: root/chromium/gpu/ipc/service/gpu_init.h
blob: 9ee296c3716bccfd04c5b0ede6c0fa5a96171b71 (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
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2016 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.

#ifndef GPU_IPC_SERVICE_GPU_INIT_H_
#define GPU_IPC_SERVICE_GPU_INIT_H_

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "gpu/command_buffer/service/gpu_preferences.h"
#include "gpu/config/gpu_feature_info.h"
#include "gpu/config/gpu_info.h"
#include "gpu/ipc/service/gpu_ipc_service_export.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h"

namespace base {
class CommandLine;
}

namespace gpu {

class GPU_IPC_SERVICE_EXPORT GpuSandboxHelper {
 public:
  virtual ~GpuSandboxHelper() = default;

  virtual void PreSandboxStartup() = 0;

  virtual bool EnsureSandboxInitialized(GpuWatchdogThread* watchdog_thread,
                                        const GPUInfo* gpu_info,
                                        const GpuPreferences& gpu_prefs) = 0;
};

class GPU_IPC_SERVICE_EXPORT GpuInit {
 public:
  GpuInit();
  ~GpuInit();

  void set_sandbox_helper(GpuSandboxHelper* helper) {
    sandbox_helper_ = helper;
  }

  // TODO(zmo): Get rid of |command_line| in the following two functions.
  // Pass all bits through GpuPreferences.
  bool InitializeAndStartSandbox(base::CommandLine* command_line,
                                 const GpuPreferences& gpu_preferences);
  void InitializeInProcess(base::CommandLine* command_line,
                           const GpuPreferences& gpu_preferences);

  const GPUInfo& gpu_info() const { return gpu_info_; }
  const GpuFeatureInfo& gpu_feature_info() const { return gpu_feature_info_; }
  const GpuPreferences& gpu_preferences() const { return gpu_preferences_; }
  std::unique_ptr<GpuWatchdogThread> TakeWatchdogThread() {
    return std::move(watchdog_thread_);
  }
  bool init_successful() const { return init_successful_; }

 private:
  GpuSandboxHelper* sandbox_helper_ = nullptr;
  std::unique_ptr<GpuWatchdogThread> watchdog_thread_;
  GPUInfo gpu_info_;
  GpuFeatureInfo gpu_feature_info_;
  GpuPreferences gpu_preferences_;
  bool init_successful_ = false;

  bool ShouldEnableSwiftShader(base::CommandLine* command_line,
                               bool blacklist_needs_more_info);
  void AdjustInfoToSwiftShader();
  DISALLOW_COPY_AND_ASSIGN(GpuInit);
};

}  // namespace gpu

#endif  // GPU_IPC_SERVICE_GPU_INIT_H_