2014-09-01 02:38:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sts=2 et sw=2 tw=80: */
|
|
|
|
/* Copyright 2014 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GECKO_TOUCH_INPUT_DISPATCHER_h
|
|
|
|
#define GECKO_TOUCH_INPUT_DISPATCHER_h
|
|
|
|
|
|
|
|
#include "InputData.h"
|
|
|
|
#include "Units.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include <vector>
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-09-01 02:38:00 +04:00
|
|
|
|
|
|
|
class nsIWidget;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2014-12-18 19:30:06 +03:00
|
|
|
namespace layers {
|
2015-04-30 21:35:13 +03:00
|
|
|
class CompositorVsyncScheduler;
|
2014-12-18 19:30:06 +03:00
|
|
|
}
|
|
|
|
|
2014-09-01 02:38:00 +04:00
|
|
|
// 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
|
|
|
|
// extrapolation and interpolation. The algorithm takes the vsync time and
|
|
|
|
// subtracts mVsyncAdjust time in ms and creates a sample time. All touch events are
|
|
|
|
// relative to this sample time. If the last touch event occurs AFTER this
|
|
|
|
// sample time, interpolate the last two touch events. If the last touch event occurs BEFORE
|
|
|
|
// this sample time, we extrapolate the last two touch events to the sample
|
|
|
|
// time. The magic numbers defined as constants are taken from android
|
|
|
|
// InputTransport.cpp.
|
2015-03-21 19:28:04 +03:00
|
|
|
class GeckoTouchDispatcher final
|
2014-09-01 02:38:00 +04:00
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GeckoTouchDispatcher)
|
|
|
|
|
|
|
|
public:
|
2015-02-24 23:52:16 +03:00
|
|
|
static GeckoTouchDispatcher* GetInstance();
|
2014-10-29 23:37:06 +03:00
|
|
|
void NotifyTouch(MultiTouchInput& aTouch, TimeStamp aEventTime);
|
2015-02-10 16:24:23 +03:00
|
|
|
void DispatchTouchEvent(MultiTouchInput aMultiTouch);
|
2015-03-09 19:46:04 +03:00
|
|
|
void DispatchTouchNonMoveEvent(MultiTouchInput aInput);
|
2014-10-29 23:37:06 +03:00
|
|
|
void DispatchTouchMoveEvents(TimeStamp aVsyncTime);
|
2015-03-09 19:46:04 +03:00
|
|
|
void NotifyVsync(TimeStamp aVsyncTimestamp);
|
2015-04-30 21:35:13 +03:00
|
|
|
void SetCompositorVsyncScheduler(layers::CompositorVsyncScheduler* aObserver);
|
2014-09-01 02:38:00 +04:00
|
|
|
|
2015-03-10 15:44:02 +03:00
|
|
|
protected:
|
|
|
|
~GeckoTouchDispatcher() {}
|
|
|
|
|
2014-09-01 02:38:00 +04:00
|
|
|
private:
|
2015-02-24 23:52:16 +03:00
|
|
|
GeckoTouchDispatcher();
|
2014-10-29 23:37:06 +03:00
|
|
|
void ResampleTouchMoves(MultiTouchInput& aOutTouch, TimeStamp vsyncTime);
|
2014-09-01 02:38:00 +04:00
|
|
|
void SendTouchEvent(MultiTouchInput& aData);
|
|
|
|
void DispatchMouseEvent(MultiTouchInput& aMultiTouch,
|
|
|
|
bool aForwardToChildren);
|
|
|
|
|
2015-03-09 19:46:04 +03:00
|
|
|
// mTouchQueueLock is used to protect the vector and state below
|
|
|
|
// as it is accessed on multiple threads.
|
2014-09-01 02:38:00 +04:00
|
|
|
Mutex mTouchQueueLock;
|
|
|
|
std::vector<MultiTouchInput> mTouchMoveEvents;
|
2015-03-09 19:46:04 +03:00
|
|
|
bool mHavePendingTouchMoves;
|
2015-03-09 19:46:04 +03:00
|
|
|
int mInflightNonMoveEvents;
|
2015-03-09 19:46:04 +03:00
|
|
|
// end stuff protected by mTouchQueueLock
|
2014-09-01 02:38:00 +04:00
|
|
|
|
|
|
|
bool mResamplingEnabled;
|
|
|
|
bool mTouchEventsFiltered;
|
|
|
|
bool mEnabledUniformityInfo;
|
|
|
|
|
|
|
|
// All times below are in nanoseconds
|
2014-10-29 23:37:06 +03:00
|
|
|
TimeDuration mVsyncAdjust; // Time from vsync we create sample times from
|
|
|
|
TimeDuration mMaxPredict; // How far into the future we're allowed to extrapolate
|
2015-08-19 08:02:21 +03:00
|
|
|
TimeDuration mMinDelta; // Minimal time difference between touches for resampling
|
2014-09-01 02:38:00 +04:00
|
|
|
|
|
|
|
// Amount of time between vsync and the last event that is required before we
|
|
|
|
// resample
|
2014-10-29 23:37:06 +03:00
|
|
|
TimeDuration mMinResampleTime;
|
2014-09-01 02:38:00 +04:00
|
|
|
|
2014-10-16 16:02:00 +04:00
|
|
|
// Threshold if a vsync event runs too far behind touch events
|
2014-10-29 23:37:06 +03:00
|
|
|
TimeDuration mDelayedVsyncThreshold;
|
2014-11-11 17:39:00 +03:00
|
|
|
|
|
|
|
// How far ahead can vsync events get ahead of touch events.
|
|
|
|
TimeDuration mOldTouchThreshold;
|
2014-12-18 19:30:06 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<layers::CompositorVsyncScheduler> mCompositorVsyncScheduler;
|
2014-09-01 02:38:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2014-09-01 02:38:00 +04:00
|
|
|
#endif // GECKO_TOUCH_INPUT_DISPATCHER_h
|