APZInputBridgeParent.cpp (7534B)
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 "mozilla/layers/APZInputBridgeParent.h" 8 9 #include "mozilla/ipc/Endpoint.h" 10 #include "mozilla/layers/APZInputBridge.h" 11 #include "mozilla/layers/CompositorBridgeParent.h" 12 #include "mozilla/layers/IAPZCTreeManager.h" 13 #include "InputData.h" 14 15 namespace mozilla { 16 namespace layers { 17 18 /* static */ 19 APZInputBridgeParent* APZInputBridgeParent::Create( 20 const LayersId& aLayersId, Endpoint<PAPZInputBridgeParent>&& aEndpoint) { 21 APZInputBridgeParent* parent = new APZInputBridgeParent(aLayersId); 22 if (!aEndpoint.Bind(parent)) { 23 // We can't recover from this. 24 MOZ_CRASH("Failed to bind APZInputBridgeParent to endpoint"); 25 } 26 27 CompositorBridgeParent::SetAPZInputBridgeParent(aLayersId, parent); 28 return parent; 29 } 30 31 APZInputBridgeParent::APZInputBridgeParent(const LayersId& aLayersId) { 32 MOZ_ASSERT(XRE_IsGPUProcess()); 33 MOZ_ASSERT(NS_IsMainThread()); 34 35 mLayersId = aLayersId; 36 mTreeManager = CompositorBridgeParent::GetAPZCTreeManager(aLayersId); 37 MOZ_ASSERT(mTreeManager); 38 } 39 40 APZInputBridgeParent::~APZInputBridgeParent() = default; 41 42 mozilla::ipc::IPCResult APZInputBridgeParent::RecvReceiveMultiTouchInputEvent( 43 const MultiTouchInput& aEvent, bool aWantsCallback, 44 APZEventResult* aOutResult, MultiTouchInput* aOutEvent) { 45 MultiTouchInput event = aEvent; 46 47 APZInputBridge::InputBlockCallback callback; 48 if (aWantsCallback) { 49 callback = [self = RefPtr<APZInputBridgeParent>(this)]( 50 uint64_t aInputBlockId, 51 const APZHandledResult& aHandledResult) { 52 (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); 53 }; 54 } 55 56 *aOutResult = mTreeManager->InputBridge()->ReceiveInputEvent( 57 event, std::move(callback)); 58 *aOutEvent = event; 59 60 return IPC_OK(); 61 } 62 63 mozilla::ipc::IPCResult APZInputBridgeParent::RecvReceiveMouseInputEvent( 64 const MouseInput& aEvent, bool aWantsCallback, APZEventResult* aOutResult, 65 MouseInput* aOutEvent) { 66 MouseInput event = aEvent; 67 68 APZInputBridge::InputBlockCallback callback; 69 if (aWantsCallback) { 70 callback = [self = RefPtr<APZInputBridgeParent>(this)]( 71 uint64_t aInputBlockId, 72 const APZHandledResult& aHandledResult) { 73 (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); 74 }; 75 } 76 77 *aOutResult = mTreeManager->InputBridge()->ReceiveInputEvent( 78 event, std::move(callback)); 79 *aOutEvent = event; 80 81 return IPC_OK(); 82 } 83 84 mozilla::ipc::IPCResult APZInputBridgeParent::RecvReceivePanGestureInputEvent( 85 const PanGestureInput& aEvent, bool aWantsCallback, 86 APZEventResult* aOutResult, PanGestureInput* aOutEvent) { 87 PanGestureInput event = aEvent; 88 89 APZInputBridge::InputBlockCallback callback; 90 if (aWantsCallback) { 91 callback = [self = RefPtr<APZInputBridgeParent>(this)]( 92 uint64_t aInputBlockId, 93 const APZHandledResult& aHandledResult) { 94 (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); 95 }; 96 } 97 98 *aOutResult = mTreeManager->InputBridge()->ReceiveInputEvent( 99 event, std::move(callback)); 100 *aOutEvent = event; 101 102 return IPC_OK(); 103 } 104 105 mozilla::ipc::IPCResult APZInputBridgeParent::RecvReceivePinchGestureInputEvent( 106 const PinchGestureInput& aEvent, bool aWantsCallback, 107 APZEventResult* aOutResult, PinchGestureInput* aOutEvent) { 108 PinchGestureInput event = aEvent; 109 110 APZInputBridge::InputBlockCallback callback; 111 if (aWantsCallback) { 112 callback = [self = RefPtr<APZInputBridgeParent>(this)]( 113 uint64_t aInputBlockId, 114 const APZHandledResult& aHandledResult) { 115 (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); 116 }; 117 } 118 119 *aOutResult = mTreeManager->InputBridge()->ReceiveInputEvent( 120 event, std::move(callback)); 121 *aOutEvent = event; 122 123 return IPC_OK(); 124 } 125 126 mozilla::ipc::IPCResult APZInputBridgeParent::RecvReceiveTapGestureInputEvent( 127 const TapGestureInput& aEvent, bool aWantsCallback, 128 APZEventResult* aOutResult, TapGestureInput* aOutEvent) { 129 TapGestureInput event = aEvent; 130 131 APZInputBridge::InputBlockCallback callback; 132 if (aWantsCallback) { 133 callback = [self = RefPtr<APZInputBridgeParent>(this)]( 134 uint64_t aInputBlockId, 135 const APZHandledResult& aHandledResult) { 136 (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); 137 }; 138 } 139 140 *aOutResult = mTreeManager->InputBridge()->ReceiveInputEvent( 141 event, std::move(callback)); 142 *aOutEvent = event; 143 144 return IPC_OK(); 145 } 146 147 mozilla::ipc::IPCResult APZInputBridgeParent::RecvReceiveScrollWheelInputEvent( 148 const ScrollWheelInput& aEvent, bool aWantsCallback, 149 APZEventResult* aOutResult, ScrollWheelInput* aOutEvent) { 150 ScrollWheelInput event = aEvent; 151 152 APZInputBridge::InputBlockCallback callback; 153 if (aWantsCallback) { 154 callback = [self = RefPtr<APZInputBridgeParent>(this)]( 155 uint64_t aInputBlockId, 156 const APZHandledResult& aHandledResult) { 157 (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); 158 }; 159 } 160 161 *aOutResult = mTreeManager->InputBridge()->ReceiveInputEvent( 162 event, std::move(callback)); 163 *aOutEvent = event; 164 165 return IPC_OK(); 166 } 167 168 mozilla::ipc::IPCResult APZInputBridgeParent::RecvReceiveKeyboardInputEvent( 169 const KeyboardInput& aEvent, bool aWantsCallback, 170 APZEventResult* aOutResult, KeyboardInput* aOutEvent) { 171 KeyboardInput event = aEvent; 172 173 APZInputBridge::InputBlockCallback callback; 174 if (aWantsCallback) { 175 callback = [self = RefPtr<APZInputBridgeParent>(this)]( 176 uint64_t aInputBlockId, 177 const APZHandledResult& aHandledResult) { 178 (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); 179 }; 180 } 181 182 *aOutResult = mTreeManager->InputBridge()->ReceiveInputEvent( 183 event, std::move(callback)); 184 *aOutEvent = event; 185 186 return IPC_OK(); 187 } 188 189 mozilla::ipc::IPCResult APZInputBridgeParent::RecvUpdateWheelTransaction( 190 const LayoutDeviceIntPoint& aRefPoint, const EventMessage& aEventMessage, 191 const Maybe<ScrollableLayerGuid>& aTargetGuid) { 192 mTreeManager->InputBridge()->UpdateWheelTransaction(aRefPoint, aEventMessage, 193 aTargetGuid); 194 return IPC_OK(); 195 } 196 197 mozilla::ipc::IPCResult APZInputBridgeParent::RecvProcessUnhandledEvent( 198 const LayoutDeviceIntPoint& aRefPoint, LayoutDeviceIntPoint* aOutRefPoint, 199 ScrollableLayerGuid* aOutTargetGuid, uint64_t* aOutFocusSequenceNumber, 200 LayersId* aOutLayersId) { 201 LayoutDeviceIntPoint refPoint = aRefPoint; 202 mTreeManager->InputBridge()->ProcessUnhandledEvent( 203 &refPoint, aOutTargetGuid, aOutFocusSequenceNumber, aOutLayersId); 204 *aOutRefPoint = refPoint; 205 206 return IPC_OK(); 207 } 208 209 void APZInputBridgeParent::ActorDestroy(ActorDestroyReason aWhy) { 210 StaticMonitorAutoLock lock(CompositorBridgeParent::sIndirectLayerTreesLock); 211 CompositorBridgeParent::LayerTreeState& state = 212 CompositorBridgeParent::sIndirectLayerTrees[mLayersId]; 213 state.mApzInputBridgeParent = nullptr; 214 // We shouldn't need it after this 215 mTreeManager = nullptr; 216 } 217 218 } // namespace layers 219 } // namespace mozilla