forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1101974. Part 3 - Create VsyncSource / Display framework. r=kats
- Loading branch information
Mason Chang
committed
Dec 18, 2014
1 parent
8c6ce77
commit 5119b7e
Showing
5 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "VsyncSource.h" | ||
#include "gfxPlatform.h" | ||
#include "mozilla/TimeStamp.h" | ||
#include "mozilla/VsyncDispatcher.h" | ||
|
||
using namespace mozilla; | ||
using namespace mozilla::gfx; | ||
|
||
void | ||
VsyncSource::AddVsyncDispatcher(VsyncDispatcher* aVsyncDispatcher) | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
GetGlobalDisplay().AddVsyncDispatcher(aVsyncDispatcher); | ||
} | ||
|
||
void | ||
VsyncSource::RemoveVsyncDispatcher(VsyncDispatcher* aVsyncDispatcher) | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
GetGlobalDisplay().RemoveVsyncDispatcher(aVsyncDispatcher); | ||
} | ||
|
||
VsyncSource::Display& | ||
VsyncSource::FindDisplay(VsyncDispatcher* aVsyncDispatcher) | ||
{ | ||
return GetGlobalDisplay(); | ||
} | ||
|
||
void | ||
VsyncSource::Display::NotifyVsync(TimeStamp aVsyncTimestamp) | ||
{ | ||
// Called on the hardware vsync thread | ||
for (size_t i = 0; i < mVsyncDispatchers.Length(); i++) { | ||
mVsyncDispatchers[i]->NotifyVsync(aVsyncTimestamp); | ||
} | ||
} | ||
|
||
VsyncSource::Display::Display() | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
} | ||
|
||
VsyncSource::Display::~Display() | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
mVsyncDispatchers.Clear(); | ||
} | ||
|
||
void | ||
VsyncSource::Display::AddVsyncDispatcher(VsyncDispatcher* aVsyncDispatcher) | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
mVsyncDispatchers.AppendElement(aVsyncDispatcher); | ||
} | ||
|
||
void | ||
VsyncSource::Display::RemoveVsyncDispatcher(VsyncDispatcher* aVsyncDispatcher) | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
mVsyncDispatchers.RemoveElement(aVsyncDispatcher); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "mozilla/RefPtr.h" | ||
#include "mozilla/TimeStamp.h" | ||
#include "nsISupportsImpl.h" | ||
#include "nsTArray.h" | ||
|
||
namespace mozilla { | ||
class VsyncDispatcher; | ||
|
||
namespace gfx { | ||
|
||
// Controls how and when to enable/disable vsync. Lives as long as the | ||
// gfxPlatform does on the parent process | ||
class VsyncSource | ||
{ | ||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource) | ||
public: | ||
// Controls vsync unique to each display and unique on each platform | ||
class Display { | ||
public: | ||
Display(); | ||
virtual ~Display(); | ||
void AddVsyncDispatcher(mozilla::VsyncDispatcher* aVsyncDispatcher); | ||
void RemoveVsyncDispatcher(mozilla::VsyncDispatcher* aVsyncDispatcher); | ||
// Notified when this display's vsync occurs, on the hardware vsync thread | ||
void NotifyVsync(mozilla::TimeStamp aVsyncTimestamp); | ||
|
||
// These should all only be called on the main thread | ||
virtual void EnableVsync() = 0; | ||
virtual void DisableVsync() = 0; | ||
virtual bool IsVsyncEnabled() = 0; | ||
|
||
private: | ||
nsTArray<nsRefPtr<mozilla::VsyncDispatcher>> mVsyncDispatchers; | ||
}; // end Display | ||
|
||
void AddVsyncDispatcher(mozilla::VsyncDispatcher* aVsyncDispatcher); | ||
void RemoveVsyncDispatcher(mozilla::VsyncDispatcher* aVsyncDispatcher); | ||
|
||
protected: | ||
virtual Display& GetGlobalDisplay() = 0; // Works across all displays | ||
virtual Display& FindDisplay(mozilla::VsyncDispatcher* aVsyncDispatcher); | ||
virtual ~VsyncSource() {} | ||
}; // VsyncSource | ||
} // gfx | ||
} // mozilla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters