/* 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/layers/APZBridgeParent.h" #include "InputData.h" #include "mozilla/ipc/Endpoint.h" #include "mozilla/layers/APZBridge.h" #include "mozilla/layers/APZThreadUtils.h" #include "mozilla/layers/CompositorBridgeParent.h" #include "mozilla/layers/IAPZCTreeManager.h" namespace mozilla { namespace layers { /* static */ void APZBridgeParent::Create(const LayersId& aLayersId, Endpoint&& aEndpoint) { auto parent = MakeRefPtr(aLayersId); if (!aEndpoint.Bind(parent)) { // We can't recover from this. MOZ_CRASH("Failed to bind APZBridgeParent to endpoint"); } CompositorBridgeParent::SetAPZBridgeParent(aLayersId, std::move(parent)); } APZBridgeParent::APZBridgeParent(const LayersId& aLayersId) { MOZ_RELEASE_ASSERT(XRE_IsGPUProcess()); MOZ_RELEASE_ASSERT(NS_IsMainThread()); mLayersId = aLayersId; mTreeManager = CompositorBridgeParent::GetAPZCTreeManager(aLayersId); MOZ_RELEASE_ASSERT(mTreeManager); } APZBridgeParent::~APZBridgeParent() = default; mozilla::ipc::IPCResult APZBridgeParent::RecvReceiveMultiTouchInputEvent( const MultiTouchInput& aEvent, bool aWantsCallback, APZEventResult* aOutResult, MultiTouchInput* aOutEvent) { MultiTouchInput event = aEvent; APZBridge::InputBlockCallback callback; if (aWantsCallback) { callback = [self = RefPtr(this)]( uint64_t aInputBlockId, const APZHandledResult& aHandledResult) { (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); }; } *aOutResult = mTreeManager->Bridge()->ReceiveInputEvent(event, std::move(callback)); *aOutEvent = std::move(event); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvReceiveMouseInputEvent( const MouseInput& aEvent, bool aWantsCallback, APZEventResult* aOutResult, MouseInput* aOutEvent) { MouseInput event = aEvent; APZBridge::InputBlockCallback callback; if (aWantsCallback) { callback = [self = RefPtr(this)]( uint64_t aInputBlockId, const APZHandledResult& aHandledResult) { (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); }; } *aOutResult = mTreeManager->Bridge()->ReceiveInputEvent(event, std::move(callback)); *aOutEvent = std::move(event); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvReceivePanGestureInputEvent( const PanGestureInput& aEvent, bool aWantsCallback, APZEventResult* aOutResult, PanGestureInput* aOutEvent) { PanGestureInput event = aEvent; APZBridge::InputBlockCallback callback; if (aWantsCallback) { callback = [self = RefPtr(this)]( uint64_t aInputBlockId, const APZHandledResult& aHandledResult) { (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); }; } *aOutResult = mTreeManager->Bridge()->ReceiveInputEvent(event, std::move(callback)); *aOutEvent = std::move(event); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvReceivePinchGestureInputEvent( const PinchGestureInput& aEvent, bool aWantsCallback, APZEventResult* aOutResult, PinchGestureInput* aOutEvent) { PinchGestureInput event = aEvent; APZBridge::InputBlockCallback callback; if (aWantsCallback) { callback = [self = RefPtr(this)]( uint64_t aInputBlockId, const APZHandledResult& aHandledResult) { (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); }; } *aOutResult = mTreeManager->Bridge()->ReceiveInputEvent(event, std::move(callback)); *aOutEvent = std::move(event); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvReceiveTapGestureInputEvent( const TapGestureInput& aEvent, bool aWantsCallback, APZEventResult* aOutResult, TapGestureInput* aOutEvent) { TapGestureInput event = aEvent; APZBridge::InputBlockCallback callback; if (aWantsCallback) { callback = [self = RefPtr(this)]( uint64_t aInputBlockId, const APZHandledResult& aHandledResult) { (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); }; } *aOutResult = mTreeManager->Bridge()->ReceiveInputEvent(event, std::move(callback)); *aOutEvent = std::move(event); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvReceiveScrollWheelInputEvent( const ScrollWheelInput& aEvent, bool aWantsCallback, APZEventResult* aOutResult, ScrollWheelInput* aOutEvent) { ScrollWheelInput event = aEvent; APZBridge::InputBlockCallback callback; if (aWantsCallback) { callback = [self = RefPtr(this)]( uint64_t aInputBlockId, const APZHandledResult& aHandledResult) { (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); }; } *aOutResult = mTreeManager->Bridge()->ReceiveInputEvent(event, std::move(callback)); *aOutEvent = std::move(event); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvReceiveKeyboardInputEvent( const KeyboardInput& aEvent, bool aWantsCallback, APZEventResult* aOutResult, KeyboardInput* aOutEvent) { KeyboardInput event = aEvent; APZBridge::InputBlockCallback callback; if (aWantsCallback) { callback = [self = RefPtr(this)]( uint64_t aInputBlockId, const APZHandledResult& aHandledResult) { (void)self->SendCallInputBlockCallback(aInputBlockId, aHandledResult); }; } *aOutResult = mTreeManager->Bridge()->ReceiveInputEvent(event, std::move(callback)); *aOutEvent = std::move(event); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvUpdateWheelTransaction( const LayoutDeviceIntPoint& aRefPoint, const EventMessage& aEventMessage, const Maybe& aTargetGuid) { mTreeManager->Bridge()->UpdateWheelTransaction(aRefPoint, aEventMessage, aTargetGuid); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvProcessUnhandledEvent( const LayoutDeviceIntPoint& aRefPoint, LayoutDeviceIntPoint* aOutRefPoint, ScrollableLayerGuid* aOutTargetGuid, uint64_t* aOutFocusSequenceNumber, LayersId* aOutLayersId) { LayoutDeviceIntPoint refPoint = aRefPoint; mTreeManager->Bridge()->ProcessUnhandledEvent( &refPoint, aOutTargetGuid, aOutFocusSequenceNumber, aOutLayersId); *aOutRefPoint = refPoint; return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvSetKeyboardMap( const KeyboardMap& aKeyboardMap) { mTreeManager->Bridge()->SetKeyboardMap(aKeyboardMap); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvSetDPI(const float& aDpiValue) { mTreeManager->Bridge()->SetDPI(aDpiValue); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvSetBrowserGestureResponse( const uint64_t& aInputBlockId, const BrowserGestureResponse& aResponse) { mTreeManager->Bridge()->SetBrowserGestureResponse(aInputBlockId, aResponse); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvStartAutoscroll( const ScrollableLayerGuid& aGuid, const ScreenPoint& aAnchorLocation) { mTreeManager->Bridge()->StartAutoscroll(aGuid, aAnchorLocation); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvStopAutoscroll( const ScrollableLayerGuid& aGuid) { mTreeManager->Bridge()->StopAutoscroll(aGuid); return IPC_OK(); } mozilla::ipc::IPCResult APZBridgeParent::RecvSetLongTapEnabled( const bool& aTapGestureEnabled) { mTreeManager->Bridge()->SetLongTapEnabled(aTapGestureEnabled); return IPC_OK(); } void APZBridgeParent::ActorDestroy(ActorDestroyReason aWhy) { // EnsureLayerTreeStateUnderLock mirrors the previous sIndirectLayerTrees[] // access (insert-or-get), so this stays a behavior-preserving translation. CompositorBridgeParent::WithIndirectLayerTreesLock( [&](const StaticMonitorAutoLock& aProofOfLock) { CompositorBridgeParent::EnsureLayerTreeStateUnderLock(mLayersId, aProofOfLock) .mApzBridgeParent = nullptr; }); // We shouldn't need it after this mTreeManager = nullptr; } } // namespace layers } // namespace mozilla