blob: 8c83f439f58c7bb5fe09936f6d6da04a14d7f586 [file] [log] [blame]
[email protected]d7a2d892013-08-16 07:45:361// Copyright 2013 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.
4
[email protected]8707caa2013-09-04 16:41:305#include "content/gpu/in_process_gpu_thread.h"
[email protected]d7a2d892013-08-16 07:45:366
Thoren Paulson6dcf39e2017-08-02 16:33:297#include "base/command_line.h"
xhwang9c8e1282015-10-10 01:54:078#include "base/time/time.h"
avi66a07722015-12-25 23:38:129#include "build/build_config.h"
[email protected]d7a2d892013-08-16 07:45:3610#include "content/gpu/gpu_child_thread.h"
11#include "content/gpu/gpu_process.h"
Zhenyao Modb2790b2017-08-30 00:10:1512#include "content/public/common/content_client.h"
Thoren Paulson6dcf39e2017-08-02 16:33:2913#include "content/public/common/content_switches.h"
Jonathan Backer0af509962018-05-30 16:05:0714#include "gpu/config/gpu_preferences.h"
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5715#include "gpu/ipc/service/gpu_init.h"
[email protected]d7a2d892013-08-16 07:45:3616
hush5380add2015-12-18 00:41:4217#if defined(OS_ANDROID)
18#include "base/android/jni_android.h"
19#endif
20
[email protected]d7a2d892013-08-16 07:45:3621namespace content {
22
Zhenyao Mo83b895e2017-10-18 18:50:5423InProcessGpuThread::InProcessGpuThread(
24 const InProcessChildThreadParams& params,
25 const gpu::GpuPreferences& gpu_preferences)
[email protected]d7a2d892013-08-16 07:45:3626 : base::Thread("Chrome_InProcGpuThread"),
morritac6238ab2015-03-18 01:48:2927 params_(params),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2828 gpu_process_(nullptr),
Zhenyao Mo83b895e2017-10-18 18:50:5429 gpu_preferences_(gpu_preferences) {}
[email protected]d7a2d892013-08-16 07:45:3630
[email protected]8707caa2013-09-04 16:41:3031InProcessGpuThread::~InProcessGpuThread() {
[email protected]d7a2d892013-08-16 07:45:3632 Stop();
33}
34
[email protected]8707caa2013-09-04 16:41:3035void InProcessGpuThread::Init() {
reveman7caf8cf2016-02-16 02:39:0536 base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL;
37
38#if defined(OS_ANDROID)
hush5380add2015-12-18 00:41:4239 // Call AttachCurrentThreadWithName, before any other AttachCurrentThread()
40 // calls. The latter causes Java VM to assign Thread-??? to the thread name.
41 // Please note calls to AttachCurrentThreadWithName after AttachCurrentThread
42 // will not change the thread name kept in Java VM.
hush5380add2015-12-18 00:41:4243 base::android::AttachCurrentThreadWithName(thread_name());
reveman7caf8cf2016-02-16 02:39:0544 // Up the priority of the |io_thread_| on Android.
45 io_thread_priority = base::ThreadPriority::DISPLAY;
hush5380add2015-12-18 00:41:4246#endif
47
reveman7caf8cf2016-02-16 02:39:0548 gpu_process_ = new GpuProcess(io_thread_priority);
xhwang9c8e1282015-10-10 01:54:0749
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5750 auto gpu_init = std::make_unique<gpu::GpuInit>();
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5751 gpu_init->InitializeInProcess(base::CommandLine::ForCurrentProcess(),
Zhenyao Moe23f75262018-02-07 02:15:0052 gpu_preferences_);
kylechar002b2ee2017-03-15 23:50:1253
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5754 GetContentClient()->SetGpuInfo(gpu_init->gpu_info());
ericrk41a1579e2017-02-10 20:56:2855
[email protected]d7a2d892013-08-16 07:45:3656 // The process object takes ownership of the thread object, so do not
57 // save and delete the pointer.
sadrul6d41b822017-04-02 03:38:5058 GpuChildThread* child_thread =
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5759 new GpuChildThread(params_, std::move(gpu_init));
xhwang9c8e1282015-10-10 01:54:0760
61 // Since we are in the browser process, use the thread start time as the
62 // process start time.
63 child_thread->Init(base::Time::Now());
64
65 gpu_process_->set_main_thread(child_thread);
[email protected]d7a2d892013-08-16 07:45:3666}
67
[email protected]8707caa2013-09-04 16:41:3068void InProcessGpuThread::CleanUp() {
[email protected]242f6cf2014-06-09 20:24:5869 SetThreadWasQuitProperly(true);
[email protected]d7a2d892013-08-16 07:45:3670 delete gpu_process_;
71}
72
morritac6238ab2015-03-18 01:48:2973base::Thread* CreateInProcessGpuThread(
Zhenyao Mo83b895e2017-10-18 18:50:5474 const InProcessChildThreadParams& params,
75 const gpu::GpuPreferences& gpu_preferences) {
76 return new InProcessGpuThread(params, gpu_preferences);
[email protected]d7a2d892013-08-16 07:45:3677}
78
79} // namespace content