Commit bcf38ab5 authored by Allan Sandfeld Jensen's avatar Allan Sandfeld Jensen
Browse files

Avoid context-switches when not switching thread contexts


When UI and GPU threads are the same we not need to do async scheduling
or calls between them, and doing so comes at a much higher cost than
in a multithreaded environment.

Change-Id: Icddee1a78d87ce08362882da5740471dfef1224a
Reviewed-by: default avatarJüri Valdmann <juri.valdmann@qt.io>
Showing with 6 additions and 0 deletions
...@@ -213,6 +213,9 @@ void CompositorResourceTracker::scheduleUpdateMailboxes(std::vector<CompositorRe ...@@ -213,6 +213,9 @@ void CompositorResourceTracker::scheduleUpdateMailboxes(std::vector<CompositorRe
#if QT_CONFIG(opengl) #if QT_CONFIG(opengl)
scoped_refptr<base::SingleThreadTaskRunner> gpuTaskRunner = gpu_task_runner(); scoped_refptr<base::SingleThreadTaskRunner> gpuTaskRunner = gpu_task_runner();
DCHECK(gpuTaskRunner); DCHECK(gpuTaskRunner);
thread_local bool currentThreadIsGpu = gpuTaskRunner->BelongsToCurrentThread();
if (currentThreadIsGpu)
return updateMailboxes(std::move(resources));
gpuTaskRunner->PostTask( gpuTaskRunner->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&CompositorResourceTracker::updateMailboxes, base::BindOnce(&CompositorResourceTracker::updateMailboxes,
...@@ -243,6 +246,9 @@ void CompositorResourceTracker::updateMailboxes(std::vector<CompositorResource * ...@@ -243,6 +246,9 @@ void CompositorResourceTracker::updateMailboxes(std::vector<CompositorResource *
void CompositorResourceTracker::scheduleRunSubmitCallback() void CompositorResourceTracker::scheduleRunSubmitCallback()
{ {
thread_local bool currentThreadIsUi = content::BrowserThread::CurrentlyOn(content::BrowserThread::UI);
if (currentThreadIsUi)
return runSubmitCallback();
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, { content::BrowserThread::UI, base::TaskPriority::USER_VISIBLE }, FROM_HERE, { content::BrowserThread::UI, base::TaskPriority::USER_VISIBLE },
base::BindOnce(&CompositorResourceTracker::runSubmitCallback, base::BindOnce(&CompositorResourceTracker::runSubmitCallback,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment