Bug 1289432 - Introduce a skeleton QueuedInput class. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 12 Sep 2016 22:42:17 -0400
changeset 412855 5de5a38ecb530c20dc50465eb304396998c2d42e
parent 412854 13070745f7db93ffccdb7c1099c6c4cba5a1919f
child 412856 3f2e93c1c88709d499e2db8c7bf93118f12e6581
push id29274
push userkgupta@mozilla.com
push dateTue, 13 Sep 2016 02:44:31 +0000
reviewersbotond
bugs1289432
milestone51.0a1
Bug 1289432 - Introduce a skeleton QueuedInput class. r?botond MozReview-Commit-ID: 7hb2VCdpStl
gfx/layers/apz/src/InputQueue.cpp
gfx/layers/apz/src/InputQueue.h
gfx/layers/apz/src/QueuedInput.cpp
gfx/layers/apz/src/QueuedInput.h
gfx/layers/moz.build
widget/InputData.cpp
widget/InputData.h
--- a/gfx/layers/apz/src/InputQueue.cpp
+++ b/gfx/layers/apz/src/InputQueue.cpp
@@ -7,16 +7,17 @@
 #include "InputQueue.h"
 
 #include "AsyncPanZoomController.h"
 #include "gfxPrefs.h"
 #include "InputBlockState.h"
 #include "LayersLogging.h"
 #include "mozilla/layers/APZThreadUtils.h"
 #include "OverscrollHandoffState.h"
+#include "QueuedInput.h"
 
 #define INPQ_LOG(...)
 // #define INPQ_LOG(...) printf_stderr("INPQ: " __VA_ARGS__)
 
 namespace mozilla {
 namespace layers {
 
 InputQueue::InputQueue()
--- a/gfx/layers/apz/src/InputQueue.h
+++ b/gfx/layers/apz/src/InputQueue.h
@@ -6,16 +6,17 @@
 #ifndef mozilla_layers_InputQueue_h
 #define mozilla_layers_InputQueue_h
 
 #include "APZUtils.h"
 #include "DragTracker.h"
 #include "InputData.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/RefPtr.h"
+#include "mozilla/UniquePtr.h"
 #include "nsTArray.h"
 #include "TouchCounter.h"
 
 namespace mozilla {
 
 class InputData;
 class MultiTouchInput;
 class ScrollWheelInput;
@@ -24,16 +25,17 @@ namespace layers {
 
 class AsyncPanZoomController;
 class CancelableBlockState;
 class TouchBlockState;
 class WheelBlockState;
 class DragBlockState;
 class PanGestureBlockState;
 class AsyncDragMetrics;
+class QueuedInput;
 
 /**
  * This class stores incoming input events, separated into "input blocks", until
  * they are ready for handling. Currently input blocks are only created from
  * touch input.
  */
 class InputQueue {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InputQueue)
@@ -180,16 +182,19 @@ private:
   void ProcessInputBlocks();
   void ClearActiveBlock(CancelableBlockState* aBlock);
   void UpdateActiveApzc(const RefPtr<AsyncPanZoomController>& aNewActive);
 
 private:
   // The queue of input blocks that have not yet been fully processed.
   // This member must only be accessed on the controller/UI thread.
   nsTArray<RefPtr<CancelableBlockState>> mInputBlockQueue;
+  // The queue of input events that have not yet been fully processed.
+  // This member must only be accessed on the controller/UI thread.
+  nsTArray<UniquePtr<QueuedInput>> mQueuedInputs;
 
   // These are the most recently created blocks of each input type. They are
   // "active" in the sense that new inputs of that type are associated with
   // them. Note that these pointers may be null if no inputs of the type have
   // arrived, or if the inputs for the type formed a complete block that was
   // then discarded.
   RefPtr<TouchBlockState> mActiveTouchBlock;
   RefPtr<WheelBlockState> mActiveWheelBlock;
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/src/QueuedInput.cpp
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=8 et tw=80 : */
+/* 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 "QueuedInput.h"
+
+#include "AsyncPanZoomController.h"
+#include "InputBlockState.h"
+#include "InputData.h"
+#include "OverscrollHandoffState.h"
+
+namespace mozilla {
+namespace layers {
+
+QueuedInput::QueuedInput(const MultiTouchInput& aInput, TouchBlockState& aBlock)
+  : mInput(MakeUnique<MultiTouchInput>(aInput))
+  , mBlock(&aBlock)
+{
+}
+
+QueuedInput::QueuedInput(const ScrollWheelInput& aInput, WheelBlockState& aBlock)
+  : mInput(MakeUnique<ScrollWheelInput>(aInput))
+  , mBlock(&aBlock)
+{
+}
+
+QueuedInput::QueuedInput(const MouseInput& aInput, DragBlockState& aBlock)
+  : mInput(MakeUnique<MouseInput>(aInput))
+  , mBlock(&aBlock)
+{
+}
+
+QueuedInput::QueuedInput(const PanGestureInput& aInput, PanGestureBlockState& aBlock)
+  : mInput(MakeUnique<PanGestureInput>(aInput))
+  , mBlock(&aBlock)
+{
+}
+
+} // namespace layers
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/src/QueuedInput.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=8 et tw=80 : */
+/* 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/. */
+
+#ifndef mozilla_layers_QueuedInput_h
+#define mozilla_layers_QueuedInput_h
+
+#include "mozilla/RefPtr.h"
+#include "mozilla/UniquePtr.h"
+
+namespace mozilla {
+
+class InputData;
+class MultiTouchInput;
+class ScrollWheelInput;
+class MouseInput;
+class PanGestureInput;
+
+namespace layers {
+
+class CancelableBlockState;
+class TouchBlockState;
+class WheelBlockState;
+class DragBlockState;
+class PanGestureBlockState;
+
+/**
+ * This lightweight class holds a pointer to an input event that has not yet
+ * been completely processed, along with the input block that the input event
+ * is associated with.
+ */
+class QueuedInput
+{
+public:
+  QueuedInput(const MultiTouchInput& aInput, TouchBlockState& aBlock);
+  QueuedInput(const ScrollWheelInput& aInput, WheelBlockState& aBlock);
+  QueuedInput(const MouseInput& aInput, DragBlockState& aBlock);
+  QueuedInput(const PanGestureInput& aInput, PanGestureBlockState& aBlock);
+
+private:
+  // A copy of the input event that is provided to the constructor. This must
+  // be non-null, and is owned by this QueuedInput instance (hence the
+  // UniquePtr).
+  UniquePtr<InputData> mInput;
+  // A pointer to the block that the input event is associated with. This must
+  // be non-null.
+  RefPtr<CancelableBlockState> mBlock;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif // mozilla_layers_QueuedInput_h
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -276,16 +276,17 @@ UNIFIED_SOURCES += [
     'apz/src/CheckerboardEvent.cpp',
     'apz/src/DragTracker.cpp',
     'apz/src/GestureEventListener.cpp',
     'apz/src/HitTestingTreeNode.cpp',
     'apz/src/InputBlockState.cpp',
     'apz/src/InputQueue.cpp',
     'apz/src/OverscrollHandoffState.cpp',
     'apz/src/PotentialCheckerboardDurationTracker.cpp',
+    'apz/src/QueuedInput.cpp',
     'apz/src/TouchCounter.cpp',
     'apz/src/WheelScrollAnimation.cpp',
     'apz/testutil/APZTestData.cpp',
     'apz/util/ActiveElementManager.cpp',
     'apz/util/APZCCallbackHelper.cpp',
     'apz/util/APZEventState.cpp',
     'apz/util/APZThreadUtils.cpp',
     'apz/util/CheckerboardReportService.cpp',
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -11,16 +11,20 @@
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "UnitTransforms.h"
 
 namespace mozilla {
 
 using namespace dom;
 
+InputData::~InputData()
+{
+}
+
 InputData::InputData(InputType aInputType)
   : mInputType(aInputType)
   , mTime(0)
   , modifiers(0)
 {
 }
 
 InputData::InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -89,16 +89,17 @@ public:
 
   INPUTDATA_AS_CHILD_TYPE(MultiTouchInput, MULTITOUCH_INPUT)
   INPUTDATA_AS_CHILD_TYPE(MouseInput, MOUSE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(PanGestureInput, PANGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(ScrollWheelInput, SCROLLWHEEL_INPUT)
 
+  virtual ~InputData();
   explicit InputData(InputType aInputType);
 
 protected:
   InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
             Modifiers aModifiers);
 };
 
 /**