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

android_webview / browser / gfx / gpu_service_webview.cc [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "android_webview/browser/gfx/gpu_service_webview.h"

#include "base/command_line.h"
#include "base/logging.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/gpu_utils.h"
#include "gpu/command_buffer/service/scheduler.h"
#include "gpu/command_buffer/service/shared_image/shared_image_manager.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/config/gpu_util.h"

namespace android_webview {

// static
GpuServiceWebView* GpuServiceWebView::GetInstance() {
  static GpuServiceWebView* gpu_service = CreateGpuServiceWebView();
  return gpu_service;
}

// static
GpuServiceWebView* GpuServiceWebView::CreateGpuServiceWebView() {
  gpu::GPUInfo gpu_info;
  gpu::GpuFeatureInfo gpu_feature_info;
  DCHECK(base::CommandLine::InitializedForCurrentProcess());
  gpu::GpuPreferences gpu_preferences =
      content::GetGpuPreferencesFromCommandLine();
  auto* command_line = base::CommandLine::ForCurrentProcess();
  gl::GLDisplay* display = gpu::InitializeGLThreadSafe(
      command_line, gpu_preferences, &gpu_info, &gpu_feature_info);
  if (!display) {
    LOG(FATAL) << "gpu::InitializeGLThreadSafe() failed.";
  }
  auto sync_point_manager = std::make_unique<gpu::SyncPointManager>();
  // The shared_image_manager will be shared between renderer thread and GPU
  // main thread, so it should be thread safe.
  auto shared_image_manager = std::make_unique<gpu::SharedImageManager>(
      true /* is_thread_safe */, true /* display_context_on_another_thread */);
  auto scheduler = std::make_unique<gpu::Scheduler>(sync_point_manager.get());
  return new GpuServiceWebView(
      std::move(sync_point_manager), std::move(shared_image_manager),
      std::move(scheduler), gpu_info, gpu_preferences, gpu_feature_info);
}

GpuServiceWebView::~GpuServiceWebView() = default;

GpuServiceWebView::GpuServiceWebView(
    std::unique_ptr<gpu::SyncPointManager> sync_point_manager,
    std::unique_ptr<gpu::SharedImageManager> shared_image_manager,
    std::unique_ptr<gpu::Scheduler> scheduler,
    const gpu::GPUInfo& gpu_info,
    const gpu::GpuPreferences& gpu_preferences,
    const gpu::GpuFeatureInfo& gpu_feature_info)
    : sync_point_manager_(std::move(sync_point_manager)),
      shared_image_manager_(std::move(shared_image_manager)),
      scheduler_(std::move(scheduler)),
      gpu_info_(gpu_info),
      gpu_preferences_(gpu_preferences),
      gpu_feature_info_(gpu_feature_info) {}

}  // namespace android_webview