blob: f0a97b7cdb6c561edbb72971b596ae7f7282a70d [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
xhwang9c8e1282015-10-10 01:54:077#include "base/time/time.h"
avi66a07722015-12-25 23:38:128#include "build/build_config.h"
grt8c648422015-06-29 18:17:179#include "content/common/gpu/gpu_memory_buffer_factory.h"
[email protected]d7a2d892013-08-16 07:45:3610#include "content/gpu/gpu_child_thread.h"
11#include "content/gpu/gpu_process.h"
boliuc5befe72015-07-21 19:08:5612#include "gpu/command_buffer/service/sync_point_manager.h"
[email protected]d7a2d892013-08-16 07:45:3613
hush5380add2015-12-18 00:41:4214#if defined(OS_ANDROID)
15#include "base/android/jni_android.h"
16#endif
17
[email protected]d7a2d892013-08-16 07:45:3618namespace content {
19
boliuc5befe72015-07-21 19:08:5620InProcessGpuThread::InProcessGpuThread(
21 const InProcessChildThreadParams& params,
22 gpu::SyncPointManager* sync_point_manager_override)
[email protected]d7a2d892013-08-16 07:45:3623 : base::Thread("Chrome_InProcGpuThread"),
morritac6238ab2015-03-18 01:48:2924 params_(params),
grt8c648422015-06-29 18:17:1725 gpu_process_(NULL),
boliuc5befe72015-07-21 19:08:5626 sync_point_manager_override_(sync_point_manager_override),
revemanfb8c8e102015-10-07 20:26:3227 gpu_memory_buffer_factory_(
28 GpuMemoryBufferFactory::GetNativeType() != gfx::EMPTY_BUFFER
29 ? GpuMemoryBufferFactory::CreateNativeType()
30 : nullptr) {
boliuc5befe72015-07-21 19:08:5631 if (!sync_point_manager_override_) {
32 sync_point_manager_.reset(new gpu::SyncPointManager(false));
33 sync_point_manager_override_ = sync_point_manager_.get();
34 }
[email protected]d7a2d892013-08-16 07:45:3635}
36
[email protected]8707caa2013-09-04 16:41:3037InProcessGpuThread::~InProcessGpuThread() {
[email protected]d7a2d892013-08-16 07:45:3638 Stop();
39}
40
[email protected]8707caa2013-09-04 16:41:3041void InProcessGpuThread::Init() {
reveman7caf8cf2016-02-16 02:39:0542 base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL;
43
44#if defined(OS_ANDROID)
hush5380add2015-12-18 00:41:4245 // Call AttachCurrentThreadWithName, before any other AttachCurrentThread()
46 // calls. The latter causes Java VM to assign Thread-??? to the thread name.
47 // Please note calls to AttachCurrentThreadWithName after AttachCurrentThread
48 // will not change the thread name kept in Java VM.
hush5380add2015-12-18 00:41:4249 base::android::AttachCurrentThreadWithName(thread_name());
reveman7caf8cf2016-02-16 02:39:0550 // Up the priority of the |io_thread_| on Android.
51 io_thread_priority = base::ThreadPriority::DISPLAY;
hush5380add2015-12-18 00:41:4252#endif
53
reveman7caf8cf2016-02-16 02:39:0554 gpu_process_ = new GpuProcess(io_thread_priority);
xhwang9c8e1282015-10-10 01:54:0755
[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.
xhwang9c8e1282015-10-10 01:54:0758 GpuChildThread* child_thread = new GpuChildThread(
59 params_, gpu_memory_buffer_factory_.get(), sync_point_manager_override_);
60
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(
74 const InProcessChildThreadParams& params) {
boliuc5befe72015-07-21 19:08:5675 return new InProcessGpuThread(params, nullptr);
[email protected]d7a2d892013-08-16 07:45:3676}
77
78} // namespace content