2016-01-08 22:17:39 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
|
|
|
/* 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/RemoteContentController.h"
|
|
|
|
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/task.h"
|
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/TabParent.h"
|
|
|
|
#include "mozilla/layers/APZThreadUtils.h"
|
|
|
|
#include "mozilla/layout/RenderFrameParent.h"
|
2016-05-23 10:27:51 +03:00
|
|
|
#include "mozilla/gfx/GPUProcessManager.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2016-01-08 22:17:39 +03:00
|
|
|
#include "Units.h"
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2016-05-23 10:27:57 +03:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2016-08-11 02:51:45 +03:00
|
|
|
RemoteContentController::RemoteContentController()
|
2016-08-02 09:59:00 +03:00
|
|
|
: mCompositorThread(MessageLoop::current())
|
|
|
|
, mCanSend(true)
|
2016-01-08 22:17:39 +03:00
|
|
|
, mMutex("RemoteContentController")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoteContentController::~RemoteContentController()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoteContentController::RequestContentRepaint(const FrameMetrics& aFrameMetrics)
|
|
|
|
{
|
2016-08-02 09:59:00 +03:00
|
|
|
MOZ_ASSERT(IsRepaintThread());
|
|
|
|
|
|
|
|
if (mCanSend) {
|
2016-07-31 22:39:00 +03:00
|
|
|
Unused << SendRequestContentRepaint(aFrameMetrics);
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-05 20:24:54 +03:00
|
|
|
RemoteContentController::HandleTap(TapType aTapType,
|
2016-07-29 21:44:29 +03:00
|
|
|
const LayoutDevicePoint& aPoint,
|
2016-07-05 20:24:54 +03:00
|
|
|
Modifiers aModifiers,
|
|
|
|
const ScrollableLayerGuid& aGuid,
|
|
|
|
uint64_t aInputBlockId)
|
2016-01-08 22:17:39 +03:00
|
|
|
{
|
2016-08-02 09:59:00 +03:00
|
|
|
if (MessageLoop::current() != mCompositorThread) {
|
|
|
|
// We have to send messages from the compositor thread
|
|
|
|
mCompositorThread->PostTask(NewRunnableMethod<TapType, LayoutDevicePoint, Modifiers,
|
2016-07-05 20:24:54 +03:00
|
|
|
ScrollableLayerGuid, uint64_t>(this,
|
|
|
|
&RemoteContentController::HandleTap,
|
|
|
|
aTapType, aPoint, aModifiers, aGuid,
|
|
|
|
aInputBlockId));
|
2016-01-08 22:17:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-02 09:59:00 +03:00
|
|
|
if (mCanSend) {
|
|
|
|
Unused << SendHandleTap(aTapType, aPoint,
|
2016-09-21 17:25:05 +03:00
|
|
|
aModifiers, aGuid, aInputBlockId);
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-28 03:06:05 +03:00
|
|
|
RemoteContentController::PostDelayedTask(already_AddRefed<Runnable> aTask, int aDelayMs)
|
2016-01-08 22:17:39 +03:00
|
|
|
{
|
2016-08-06 00:38:51 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2016-04-28 03:06:05 +03:00
|
|
|
AndroidBridge::Bridge()->PostTaskToUiThread(Move(aTask), aDelayMs);
|
2016-01-08 22:17:39 +03:00
|
|
|
#else
|
2016-08-02 09:59:00 +03:00
|
|
|
(MessageLoop::current() ? MessageLoop::current() : mCompositorThread)->
|
2016-04-28 03:06:05 +03:00
|
|
|
PostDelayedTask(Move(aTask), aDelayMs);
|
2016-01-08 22:17:39 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-02 09:59:00 +03:00
|
|
|
bool
|
|
|
|
RemoteContentController::IsRepaintThread()
|
|
|
|
{
|
|
|
|
return MessageLoop::current() == mCompositorThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoteContentController::DispatchToRepaintThread(already_AddRefed<Runnable> aTask)
|
|
|
|
{
|
|
|
|
mCompositorThread->PostTask(Move(aTask));
|
|
|
|
}
|
|
|
|
|
2016-01-08 22:17:39 +03:00
|
|
|
bool
|
|
|
|
RemoteContentController::GetTouchSensitiveRegion(CSSRect* aOutRegion)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
if (mTouchSensitiveRegion.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aOutRegion = CSSRect::FromAppUnits(mTouchSensitiveRegion.GetBounds());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoteContentController::NotifyAPZStateChange(const ScrollableLayerGuid& aGuid,
|
|
|
|
APZStateChange aChange,
|
|
|
|
int aArg)
|
|
|
|
{
|
2016-08-02 09:59:00 +03:00
|
|
|
if (MessageLoop::current() != mCompositorThread) {
|
|
|
|
// We have to send messages from the compositor thread
|
|
|
|
mCompositorThread->PostTask(NewRunnableMethod<ScrollableLayerGuid,
|
2016-05-05 11:45:00 +03:00
|
|
|
APZStateChange,
|
|
|
|
int>(this,
|
|
|
|
&RemoteContentController::NotifyAPZStateChange,
|
|
|
|
aGuid, aChange, aArg));
|
2016-01-08 22:17:39 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-08-02 09:59:00 +03:00
|
|
|
|
|
|
|
if (mCanSend) {
|
2016-08-11 02:51:45 +03:00
|
|
|
Unused << SendNotifyAPZStateChange(aGuid, aChange, aArg);
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 02:51:45 +03:00
|
|
|
void
|
|
|
|
RemoteContentController::UpdateOverscrollVelocity(float aX, float aY, bool aIsRootContent)
|
|
|
|
{
|
|
|
|
if (MessageLoop::current() != mCompositorThread) {
|
|
|
|
mCompositorThread->PostTask(NewRunnableMethod<float,
|
|
|
|
float, bool>(this,
|
|
|
|
&RemoteContentController::UpdateOverscrollVelocity,
|
|
|
|
aX, aY, aIsRootContent));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Unused << SendUpdateOverscrollVelocity(aX, aY, aIsRootContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoteContentController::UpdateOverscrollOffset(float aX, float aY, bool aIsRootContent)
|
|
|
|
{
|
|
|
|
if (MessageLoop::current() != mCompositorThread) {
|
|
|
|
mCompositorThread->PostTask(NewRunnableMethod<float,
|
|
|
|
float, bool>(this,
|
|
|
|
&RemoteContentController::UpdateOverscrollOffset,
|
|
|
|
aX, aY, aIsRootContent));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Unused << SendUpdateOverscrollOffset(aX, aY, aIsRootContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoteContentController::SetScrollingRootContent(bool aIsRootContent)
|
|
|
|
{
|
|
|
|
if (MessageLoop::current() != mCompositorThread) {
|
|
|
|
mCompositorThread->PostTask(NewRunnableMethod<bool>(this,
|
|
|
|
&RemoteContentController::SetScrollingRootContent,
|
|
|
|
aIsRootContent));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Unused << SendSetScrollingRootContent(aIsRootContent);
|
|
|
|
}
|
|
|
|
|
2016-01-08 22:17:39 +03:00
|
|
|
void
|
|
|
|
RemoteContentController::NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrollId,
|
|
|
|
const nsString& aEvent)
|
|
|
|
{
|
2016-08-02 09:59:00 +03:00
|
|
|
if (MessageLoop::current() != mCompositorThread) {
|
|
|
|
// We have to send messages from the compositor thread
|
|
|
|
mCompositorThread->PostTask(NewRunnableMethod<FrameMetrics::ViewID,
|
2016-05-05 11:45:00 +03:00
|
|
|
nsString>(this,
|
|
|
|
&RemoteContentController::NotifyMozMouseScrollEvent,
|
|
|
|
aScrollId, aEvent));
|
2016-01-08 22:17:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-02 09:59:00 +03:00
|
|
|
if (mCanSend) {
|
2016-08-11 02:51:45 +03:00
|
|
|
Unused << SendNotifyMozMouseScrollEvent(aScrollId, aEvent);
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoteContentController::NotifyFlushComplete()
|
|
|
|
{
|
2016-08-02 09:59:00 +03:00
|
|
|
MOZ_ASSERT(IsRepaintThread());
|
|
|
|
|
|
|
|
if (mCanSend) {
|
2016-01-08 22:17:39 +03:00
|
|
|
Unused << SendNotifyFlushComplete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RemoteContentController::RecvUpdateHitRegion(const nsRegion& aRegion)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
mTouchSensitiveRegion = aRegion;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoteContentController::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
2016-08-22 03:43:08 +03:00
|
|
|
// This controller could possibly be kept alive longer after this
|
|
|
|
// by a RefPtr, but it is no longer valid to send messages.
|
2016-08-02 09:59:00 +03:00
|
|
|
mCanSend = false;
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoteContentController::Destroy()
|
|
|
|
{
|
2016-08-02 09:59:00 +03:00
|
|
|
if (mCanSend) {
|
|
|
|
Unused << SendDestroy();
|
|
|
|
}
|
2016-01-08 22:17:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|