VsyncIOThreadHolder.cpp (1510B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "VsyncIOThreadHolder.h" 8 9 #include "mozilla/SchedulerGroup.h" 10 11 namespace mozilla { 12 namespace gfx { 13 14 VsyncIOThreadHolder::VsyncIOThreadHolder() { 15 MOZ_COUNT_CTOR(VsyncIOThreadHolder); 16 } 17 18 VsyncIOThreadHolder::~VsyncIOThreadHolder() { 19 MOZ_COUNT_DTOR(VsyncIOThreadHolder); 20 21 if (!mThread) { 22 return; 23 } 24 25 if (NS_IsMainThread()) { 26 mThread->AsyncShutdown(); 27 } else { 28 SchedulerGroup::Dispatch(NewRunnableMethod( 29 "nsIThread::AsyncShutdown", mThread, &nsIThread::AsyncShutdown)); 30 } 31 } 32 33 bool VsyncIOThreadHolder::Start() { 34 /* "VsyncIOThread" is used as the thread we send/recv IPC messages on. We 35 * don't use the "WindowsVsyncThread" directly because it isn't servicing an 36 * nsThread event loop which is needed for IPC to return results/notify us 37 * about shutdown etc. 38 * 39 * It would be better if we could notify the IPC IO thread directly to avoid 40 * the extra ping-ponging but that doesn't seem possible. */ 41 nsresult rv = NS_NewNamedThread("VsyncIOThread", getter_AddRefs(mThread)); 42 return NS_SUCCEEDED(rv); 43 } 44 45 RefPtr<nsIThread> VsyncIOThreadHolder::GetThread() const { return mThread; } 46 47 } // namespace gfx 48 } // namespace mozilla