Bug 1101974. Part 6. Create VsyncSource on b2g. r=kats

This commit is contained in:
Mason Chang 2014-12-18 08:30:06 -08:00
Родитель 86ee98b4cd
Коммит 3027d1493e
8 изменённых файлов: 119 добавлений и 2 удалений

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsServiceManagerUtils.h"
#include "gfxPrefs.h"
#include "cairo.h"
#include "VsyncSource.h"
#ifdef MOZ_WIDGET_ANDROID
#include "AndroidBridge.h"
@ -30,6 +31,8 @@
#ifdef MOZ_WIDGET_GONK
#include <cutils/properties.h>
#include "mozilla/layers/CompositorParent.h"
#include "HwcComposer2D.h"
#endif
#include "ft2build.h"
@ -420,3 +423,72 @@ bool gfxAndroidPlatform::HaveChoiceOfHWAndSWCanvas()
#endif
return gfxPlatform::HaveChoiceOfHWAndSWCanvas();
}
#ifdef MOZ_WIDGET_GONK
class GonkVsyncSource MOZ_FINAL : public VsyncSource
{
public:
GonkVsyncSource()
{
}
virtual Display& GetGlobalDisplay() MOZ_OVERRIDE
{
return mGlobalDisplay;
}
protected:
class GonkDisplay MOZ_FINAL : public VsyncSource::Display
{
public:
GonkDisplay() : mVsyncEnabled(false)
{
EnableVsync();
}
~GonkDisplay()
{
DisableVsync();
}
virtual void EnableVsync() MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
mVsyncEnabled = HwcComposer2D::GetInstance()->EnableVsync(true);
}
virtual void DisableVsync() MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
mVsyncEnabled = HwcComposer2D::GetInstance()->EnableVsync(false);
}
virtual bool IsVsyncEnabled() MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
return mVsyncEnabled;
}
private:
bool mVsyncEnabled;
}; // GonkDisplay
private:
virtual ~GonkVsyncSource()
{
}
GonkDisplay mGlobalDisplay;
}; // GonkVsyncSource
#endif
already_AddRefed<mozilla::gfx::VsyncSource>
gfxAndroidPlatform::CreateHardwareVsyncSource()
{
#ifdef MOZ_WIDGET_GONK
nsRefPtr<VsyncSource> vsyncSource = new GonkVsyncSource();
return vsyncSource.forget();
#else
NS_WARNING("Hardware vsync not supported on android yet");
return nullptr;
#endif
}

Просмотреть файл

@ -89,6 +89,8 @@ public:
virtual bool HaveChoiceOfHWAndSWCanvas() MOZ_OVERRIDE;
virtual bool UseAcceleratedSkiaCanvas() MOZ_OVERRIDE;
virtual already_AddRefed<mozilla::gfx::VsyncSource> CreateHardwareVsyncSource() MOZ_OVERRIDE;
#ifdef MOZ_WIDGET_GONK
virtual bool IsInGonkEmulator() const { return mIsInGonkEmulator; }

Просмотреть файл

@ -29,6 +29,7 @@
#include "mozilla/TimeStamp.h"
#include "mozilla/TouchEvents.h"
#include "mozilla/dom/Touch.h"
#include "mozilla/layers/CompositorParent.h"
#include "nsAppShell.h"
#include "nsDebug.h"
#include "nsThreadUtils.h"
@ -115,11 +116,23 @@ private:
MultiTouchInput mTouch;
};
/* static */ void
GeckoTouchDispatcher::SetCompositorVsyncObserver(mozilla::layers::CompositorVsyncObserver *aObserver)
{
MOZ_ASSERT(sTouchDispatcher != nullptr);
MOZ_ASSERT(NS_IsMainThread());
// We assume on b2g that there is only 1 CompositorParent
MOZ_ASSERT(sTouchDispatcher->mCompositorVsyncObserver == nullptr);
if (gfxPrefs::TouchResampling()) {
sTouchDispatcher->mCompositorVsyncObserver = aObserver;
}
}
// Timestamp is in nanoseconds
/* static */ bool
GeckoTouchDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
{
if (sTouchDispatcher == nullptr) {
if ((sTouchDispatcher == nullptr) || !gfxPrefs::TouchResampling()) {
return false;
}
@ -141,6 +154,10 @@ GeckoTouchDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
void
GeckoTouchDispatcher::NotifyTouch(MultiTouchInput& aTouch, TimeStamp aEventTime)
{
if (aTouch.mType == MultiTouchInput::MULTITOUCH_START && mCompositorVsyncObserver) {
mCompositorVsyncObserver->SetNeedsComposite(true);
}
if (aTouch.mType == MultiTouchInput::MULTITOUCH_MOVE) {
MutexAutoLock lock(mTouchQueueLock);
if (mResamplingEnabled) {

Просмотреть файл

@ -22,12 +22,17 @@
#include "Units.h"
#include "mozilla/Mutex.h"
#include <vector>
#include "nsRefPtr.h"
class nsIWidget;
namespace mozilla {
class WidgetMouseEvent;
namespace layers {
class CompositorVsyncObserver;
}
// Used to resample touch events whenever a vsync event occurs. It batches
// touch moves and on every vsync, resamples the touch position to create smooth
// scrolls. We use the Android touch resample algorithm. It uses a combination of
@ -48,6 +53,7 @@ public:
void DispatchTouchEvent(MultiTouchInput& aMultiTouch);
void DispatchTouchMoveEvents(TimeStamp aVsyncTime);
static bool NotifyVsync(TimeStamp aVsyncTimestamp);
static void SetCompositorVsyncObserver(layers::CompositorVsyncObserver* aObserver);
private:
void ResampleTouchMoves(MultiTouchInput& aOutTouch, TimeStamp vsyncTime);
@ -78,6 +84,8 @@ private:
// How far ahead can vsync events get ahead of touch events.
TimeDuration mOldTouchThreshold;
nsRefPtr<layers::CompositorVsyncObserver> mCompositorVsyncObserver;
};
} // namespace mozilla

Просмотреть файл

@ -30,6 +30,7 @@
#include "mozilla/StaticPtr.h"
#include "cutils/properties.h"
#include "gfx2DGlue.h"
#include "nsWindow.h"
#if ANDROID_VERSION >= 17
#include "libdisplay/FramebufferSurface.h"
@ -224,7 +225,7 @@ HwcComposer2D::Vsync(int aDisplay, nsecs_t aVsyncTimestamp)
LOGE("Non-uniform vsync interval: %lld\n", vsyncInterval);
}
mLastVsyncTime = aVsyncTimestamp;
VsyncDispatcher::GetInstance()->NotifyVsync(vsyncTime);
nsWindow::NotifyVsync(vsyncTime);
}
// Called on the "invalidator" thread (run from HAL).

Просмотреть файл

@ -73,6 +73,7 @@
// Defines kKeyMapping and GetKeyNameIndex()
#include "GonkKeyMapping.h"
#include "mozilla/layers/CompositorParent.h"
#include "GeckoTouchDispatcher.h"
#define LOG(args...) \

Просмотреть файл

@ -213,6 +213,21 @@ nsWindow::DoDraw(void)
}
}
/* static */ void
nsWindow::NotifyVsync(TimeStamp aVsyncTimestamp)
{
if (!gFocusedWindow) {
return;
}
VsyncDispatcher* vsyncDispatcher = gFocusedWindow->GetVsyncDispatcher();
// During bootup, there is a delay between when the nsWindow is created
// and when the Compositor is created, but vsync is already turned on
if (vsyncDispatcher) {
vsyncDispatcher->NotifyVsync(aVsyncTimestamp);
}
}
nsEventStatus
nsWindow::DispatchInputEvent(WidgetGUIEvent& aEvent, bool* aWasCaptured)
{

Просмотреть файл

@ -49,6 +49,7 @@ public:
nsWindow();
virtual ~nsWindow();
static void NotifyVsync(mozilla::TimeStamp aVsyncTimestamp);
static void DoDraw(void);
static nsEventStatus DispatchInputEvent(mozilla::WidgetGUIEvent& aEvent,
bool* aWasCaptured = nullptr);