2012-07-17 23:59:45 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-01-19 14:45:37 +00:00
|
|
|
/* vim: set sw=2 ts=2 et tw=80 : */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2012-01-19 14:45:37 +00:00
|
|
|
|
2014-10-27 12:57:36 +00:00
|
|
|
#include "mozilla/layers/CompositorChild.h"
|
2015-03-09 17:43:39 +00:00
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2013-08-11 23:17:23 +00:00
|
|
|
#include <stddef.h> // for size_t
|
2013-11-21 22:07:56 +00:00
|
|
|
#include "ClientLayerManager.h" // for ClientLayerManager
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "base/message_loop.h" // for MessageLoop
|
|
|
|
#include "base/task.h" // for NewRunnableMethod, etc
|
|
|
|
#include "base/tracked.h" // for FROM_HERE
|
2013-04-24 18:42:40 +00:00
|
|
|
#include "mozilla/layers/LayerTransactionChild.h"
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "mozilla/layers/PLayerTransactionChild.h"
|
|
|
|
#include "mozilla/mozalloc.h" // for operator new, etc
|
|
|
|
#include "nsDebug.h" // for NS_RUNTIMEABORT
|
|
|
|
#include "nsIObserver.h" // for nsIObserver
|
2014-02-26 21:36:35 +00:00
|
|
|
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "nsTArray.h" // for nsTArray, nsTArray_Impl
|
|
|
|
#include "nsXULAppAPI.h" // for XRE_GetIOMessageLoop, etc
|
2013-11-21 22:07:56 +00:00
|
|
|
#include "FrameLayerBuilder.h"
|
2014-03-07 03:24:32 +00:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-05-23 18:19:00 +00:00
|
|
|
#include "mozilla/unused.h"
|
2015-01-29 19:41:55 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include "WinUtils.h"
|
|
|
|
#endif
|
2012-01-19 14:45:37 +00:00
|
|
|
|
2013-04-24 18:42:40 +00:00
|
|
|
using mozilla::layers::LayerTransactionChild;
|
2014-05-23 18:19:00 +00:00
|
|
|
using mozilla::dom::TabChildBase;
|
|
|
|
using mozilla::unused;
|
2012-01-19 14:45:37 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-07-17 23:59:45 +00:00
|
|
|
/*static*/ CompositorChild* CompositorChild::sCompositor;
|
|
|
|
|
2014-02-16 22:23:39 +00:00
|
|
|
Atomic<int32_t> CompositableForwarder::sSerialCounter(0);
|
|
|
|
|
2013-11-21 22:07:56 +00:00
|
|
|
CompositorChild::CompositorChild(ClientLayerManager *aLayerManager)
|
2012-01-19 14:45:37 +00:00
|
|
|
: mLayerManager(aLayerManager)
|
2015-03-09 17:43:39 +00:00
|
|
|
, mCanSend(false)
|
2012-01-19 14:45:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositorChild::~CompositorChild()
|
|
|
|
{
|
2015-03-09 17:43:39 +00:00
|
|
|
if (mCanSend) {
|
|
|
|
gfxCriticalError() << "CompositorChild was not deinitialized";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DeferredDestroyCompositor(nsRefPtr<CompositorParent> aCompositorParent,
|
|
|
|
nsRefPtr<CompositorChild> aCompositorChild)
|
|
|
|
{
|
|
|
|
// Bug 848949 needs to be fixed before
|
|
|
|
// we can close the channel properly
|
|
|
|
//aCompositorChild->Close();
|
2012-01-19 14:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CompositorChild::Destroy()
|
|
|
|
{
|
2015-03-09 17:43:39 +00:00
|
|
|
// This must not be called from the destructor!
|
|
|
|
MOZ_ASSERT(mRefCnt != 0);
|
|
|
|
|
|
|
|
if (!mCanSend) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCanSend = false;
|
|
|
|
|
|
|
|
// Destroying the layer manager may cause all sorts of things to happen, so
|
|
|
|
// let's make sure there is still a reference to keep this alive whatever
|
|
|
|
// happens.
|
|
|
|
nsRefPtr<CompositorChild> selfRef = this;
|
|
|
|
|
|
|
|
SendWillStop();
|
|
|
|
// The call just made to SendWillStop can result in IPC from the
|
|
|
|
// CompositorParent to the CompositorChild (e.g. caused by the destruction
|
|
|
|
// of shared memory). We need to ensure this gets processed by the
|
|
|
|
// CompositorChild before it gets destroyed. It suffices to ensure that
|
|
|
|
// events already in the MessageLoop get processed before the
|
|
|
|
// CompositorChild is destroyed, so we add a task to the MessageLoop to
|
|
|
|
// handle compositor desctruction.
|
|
|
|
|
|
|
|
// From now on the only message we can send is Stop.
|
|
|
|
|
|
|
|
if (mLayerManager) {
|
|
|
|
mLayerManager->Destroy();
|
|
|
|
mLayerManager = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-13 08:43:59 +00:00
|
|
|
// start from the end of the array because Destroy() can cause the
|
|
|
|
// LayerTransactionChild to be removed from the array.
|
|
|
|
for (int i = ManagedPLayerTransactionChild().Length() - 1; i >= 0; --i) {
|
2014-05-07 13:23:14 +00:00
|
|
|
RefPtr<LayerTransactionChild> layers =
|
2014-10-13 08:43:59 +00:00
|
|
|
static_cast<LayerTransactionChild*>(ManagedPLayerTransactionChild()[i]);
|
2012-01-19 14:45:37 +00:00
|
|
|
layers->Destroy();
|
|
|
|
}
|
2015-03-09 17:43:39 +00:00
|
|
|
|
2012-01-19 14:45:37 +00:00
|
|
|
SendStop();
|
2015-03-09 17:43:39 +00:00
|
|
|
|
|
|
|
// The DeferredDestroyCompositor task takes ownership of compositorParent and
|
|
|
|
// will release them when it runs.
|
|
|
|
MessageLoop::current()->PostTask(FROM_HERE,
|
|
|
|
NewRunnableFunction(DeferredDestroyCompositor, mCompositorParent, selfRef));
|
2012-01-19 14:45:37 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 20:19:25 +00:00
|
|
|
bool
|
|
|
|
CompositorChild::LookupCompositorFrameMetrics(const FrameMetrics::ViewID aId,
|
|
|
|
FrameMetrics& aFrame)
|
|
|
|
{
|
|
|
|
SharedFrameMetricsData* data = mFrameMetricsTable.Get(aId);
|
|
|
|
if (data) {
|
|
|
|
data->CopyFrameMetrics(&aFrame);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-26 04:19:09 +00:00
|
|
|
/*static*/ PCompositorChild*
|
2015-04-01 08:40:35 +00:00
|
|
|
CompositorChild::Create(Transport* aTransport, ProcessId aOtherPid)
|
2012-07-17 23:59:45 +00:00
|
|
|
{
|
|
|
|
// There's only one compositor per child process.
|
|
|
|
MOZ_ASSERT(!sCompositor);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsRefPtr<CompositorChild> child(new CompositorChild(nullptr));
|
2015-04-01 08:40:35 +00:00
|
|
|
if (!child->Open(aTransport, aOtherPid, XRE_GetIOMessageLoop(), ipc::ChildSide)) {
|
2012-07-17 23:59:45 +00:00
|
|
|
NS_RUNTIMEABORT("Couldn't Open() Compositor channel.");
|
2013-09-26 04:19:09 +00:00
|
|
|
return nullptr;
|
2012-07-17 23:59:45 +00:00
|
|
|
}
|
2014-11-12 22:55:13 +00:00
|
|
|
|
2015-03-09 17:43:39 +00:00
|
|
|
child->mCanSend = true;
|
|
|
|
|
2012-07-17 23:59:45 +00:00
|
|
|
// We release this ref in ActorDestroy().
|
2014-11-12 22:55:13 +00:00
|
|
|
sCompositor = child.forget().take();
|
|
|
|
|
|
|
|
int32_t width;
|
|
|
|
int32_t height;
|
|
|
|
sCompositor->SendGetTileSize(&width, &height);
|
|
|
|
gfxPlatform::GetPlatform()->SetTileSize(width, height);
|
|
|
|
|
2015-01-20 21:20:54 +00:00
|
|
|
// We release this ref in ActorDestroy().
|
2014-11-12 22:55:13 +00:00
|
|
|
return sCompositor;
|
2012-07-17 23:59:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 17:43:39 +00:00
|
|
|
bool
|
|
|
|
CompositorChild::OpenSameProcess(CompositorParent* aParent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aParent);
|
|
|
|
|
|
|
|
mCompositorParent = aParent;
|
|
|
|
mCanSend = Open(mCompositorParent->GetIPCChannel(),
|
|
|
|
CompositorParent::CompositorLoop(),
|
|
|
|
ipc::ChildSide);
|
|
|
|
return mCanSend;
|
|
|
|
}
|
|
|
|
|
2013-12-19 20:19:25 +00:00
|
|
|
/*static*/ CompositorChild*
|
2012-07-17 23:59:45 +00:00
|
|
|
CompositorChild::Get()
|
|
|
|
{
|
|
|
|
// This is only expected to be used in child processes.
|
|
|
|
MOZ_ASSERT(XRE_GetProcessType() != GeckoProcessType_Default);
|
|
|
|
return sCompositor;
|
|
|
|
}
|
|
|
|
|
2013-04-24 18:42:40 +00:00
|
|
|
PLayerTransactionChild*
|
2013-08-18 06:46:16 +00:00
|
|
|
CompositorChild::AllocPLayerTransactionChild(const nsTArray<LayersBackend>& aBackendHints,
|
2013-07-08 15:48:39 +00:00
|
|
|
const uint64_t& aId,
|
2013-08-04 07:46:17 +00:00
|
|
|
TextureFactoryIdentifier*,
|
|
|
|
bool*)
|
2012-01-19 14:45:37 +00:00
|
|
|
{
|
2015-03-05 18:03:16 +00:00
|
|
|
MOZ_ASSERT(mCanSend);
|
2015-03-06 11:25:33 +00:00
|
|
|
LayerTransactionChild* c = new LayerTransactionChild(aId);
|
2013-11-27 15:18:38 +00:00
|
|
|
c->AddIPDLReference();
|
|
|
|
return c;
|
2012-01-19 14:45:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 11:26:34 +00:00
|
|
|
/*static*/ PLDHashOperator
|
|
|
|
CompositorChild::RemoveSharedMetricsForLayersId(const uint64_t& aKey,
|
|
|
|
nsAutoPtr<SharedFrameMetricsData>& aData,
|
|
|
|
void* aLayerTransactionChild)
|
|
|
|
{
|
|
|
|
uint64_t childId = static_cast<LayerTransactionChild*>(aLayerTransactionChild)->GetId();
|
|
|
|
if (aData->GetLayersId() == childId) {
|
|
|
|
return PLDHashOperator::PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
return PLDHashOperator::PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2012-01-19 14:45:37 +00:00
|
|
|
bool
|
2013-07-08 15:48:39 +00:00
|
|
|
CompositorChild::DeallocPLayerTransactionChild(PLayerTransactionChild* actor)
|
2012-01-19 14:45:37 +00:00
|
|
|
{
|
2015-03-06 11:26:34 +00:00
|
|
|
mFrameMetricsTable.Enumerate(RemoveSharedMetricsForLayersId, actor);
|
2013-11-27 15:18:38 +00:00
|
|
|
static_cast<LayerTransactionChild*>(actor)->ReleaseIPDLReference();
|
2012-01-19 14:45:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 22:07:56 +00:00
|
|
|
bool
|
|
|
|
CompositorChild::RecvInvalidateAll()
|
|
|
|
{
|
2014-04-29 20:33:12 +00:00
|
|
|
if (mLayerManager) {
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(mLayerManager);
|
|
|
|
}
|
2013-11-21 22:07:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-29 19:41:55 +00:00
|
|
|
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
|
2015-05-07 09:07:53 +00:00
|
|
|
static void CalculatePluginClip(const gfx::IntRect& aBounds,
|
|
|
|
const nsTArray<gfx::IntRect>& aPluginClipRects,
|
2015-01-29 19:41:55 +00:00
|
|
|
const nsIntPoint& aContentOffset,
|
|
|
|
const nsIntRegion& aParentLayerVisibleRegion,
|
2015-05-07 09:07:53 +00:00
|
|
|
nsTArray<gfx::IntRect>& aResult,
|
|
|
|
gfx::IntRect& aVisibleBounds,
|
2015-01-29 19:41:55 +00:00
|
|
|
bool& aPluginIsVisible)
|
|
|
|
{
|
|
|
|
aPluginIsVisible = true;
|
|
|
|
// aBounds (content origin)
|
|
|
|
nsIntRegion contentVisibleRegion(aBounds);
|
|
|
|
// aPluginClipRects (plugin widget origin)
|
|
|
|
for (uint32_t idx = 0; idx < aPluginClipRects.Length(); idx++) {
|
2015-05-07 09:07:53 +00:00
|
|
|
gfx::IntRect rect = aPluginClipRects[idx];
|
2015-01-29 19:41:55 +00:00
|
|
|
// shift to content origin
|
|
|
|
rect.MoveBy(aBounds.x, aBounds.y);
|
|
|
|
contentVisibleRegion.AndWith(rect);
|
|
|
|
}
|
|
|
|
// apply layers clip (window origin)
|
|
|
|
nsIntRegion region = aParentLayerVisibleRegion;
|
|
|
|
region.MoveBy(-aContentOffset.x, -aContentOffset.y);
|
|
|
|
contentVisibleRegion.AndWith(region);
|
|
|
|
if (contentVisibleRegion.IsEmpty()) {
|
|
|
|
aPluginIsVisible = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// shift to plugin widget origin
|
|
|
|
contentVisibleRegion.MoveBy(-aBounds.x, -aBounds.y);
|
|
|
|
nsIntRegionRectIterator iter(contentVisibleRegion);
|
2015-05-07 09:07:53 +00:00
|
|
|
for (const gfx::IntRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) {
|
2015-01-29 19:41:55 +00:00
|
|
|
aResult.AppendElement(*rgnRect);
|
|
|
|
aVisibleBounds.UnionRect(aVisibleBounds, *rgnRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::RecvUpdatePluginConfigurations(const nsIntPoint& aContentOffset,
|
|
|
|
const nsIntRegion& aParentLayerVisibleRegion,
|
|
|
|
nsTArray<PluginWindowData>&& aPlugins)
|
|
|
|
{
|
|
|
|
#if !defined(XP_WIN) && !defined(MOZ_WIDGET_GTK)
|
|
|
|
NS_NOTREACHED("CompositorChild::RecvUpdatePluginConfigurations calls "
|
|
|
|
"unexpected on this platform.");
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
// Now that we are on the main thread, update plugin widget config.
|
|
|
|
// This should happen a little before we paint to the screen assuming
|
|
|
|
// the main thread is running freely.
|
|
|
|
DebugOnly<nsresult> rv;
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// Tracks visible plugins we update, so we can hide any plugins we don't.
|
|
|
|
nsTArray<uintptr_t> visiblePluginIds;
|
|
|
|
|
|
|
|
for (uint32_t pluginsIdx = 0; pluginsIdx < aPlugins.Length(); pluginsIdx++) {
|
2015-01-29 19:41:57 +00:00
|
|
|
nsIWidget* widget =
|
|
|
|
nsIWidget::LookupRegisteredPluginWindow(aPlugins[pluginsIdx].windowId());
|
|
|
|
if (!widget) {
|
|
|
|
NS_WARNING("Unexpected, plugin id not found!");
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-29 19:41:55 +00:00
|
|
|
bool isVisible = aPlugins[pluginsIdx].visible();
|
|
|
|
if (widget && !widget->Destroyed()) {
|
2015-05-07 09:07:53 +00:00
|
|
|
gfx::IntRect bounds;
|
|
|
|
gfx::IntRect visibleBounds;
|
2015-01-29 19:41:55 +00:00
|
|
|
// If the plugin is visible update it's geometry.
|
|
|
|
if (isVisible) {
|
|
|
|
// bounds (content origin) - don't pass true to Resize, it triggers a
|
|
|
|
// sync paint update to the plugin process on Windows, which happens
|
|
|
|
// prior to clipping information being applied.
|
|
|
|
bounds = aPlugins[pluginsIdx].bounds();
|
|
|
|
rv = widget->Resize(aContentOffset.x + bounds.x,
|
|
|
|
aContentOffset.y + bounds.y,
|
|
|
|
bounds.width, bounds.height, false);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "widget call failure");
|
2015-05-07 09:07:53 +00:00
|
|
|
nsTArray<gfx::IntRect> rectsOut;
|
2015-02-13 18:27:56 +00:00
|
|
|
// This call may change the value of isVisible
|
2015-01-29 19:41:55 +00:00
|
|
|
CalculatePluginClip(bounds, aPlugins[pluginsIdx].clip(),
|
|
|
|
aContentOffset, aParentLayerVisibleRegion,
|
|
|
|
rectsOut, visibleBounds, isVisible);
|
2015-02-13 18:27:56 +00:00
|
|
|
// content clipping region (widget origin)
|
|
|
|
rv = widget->SetWindowClipRegion(rectsOut, false);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "widget call failure");
|
2015-01-29 19:41:55 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 18:27:56 +00:00
|
|
|
rv = widget->Enable(isVisible);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "widget call failure");
|
|
|
|
|
2015-01-29 19:41:55 +00:00
|
|
|
// visible state - updated after clipping, prior to invalidating
|
|
|
|
rv = widget->Show(isVisible);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "widget call failure");
|
|
|
|
|
|
|
|
// Handle invalidation, this can be costly, avoid if it is not needed.
|
|
|
|
if (isVisible) {
|
|
|
|
// invalidate region (widget origin)
|
2015-05-07 09:07:53 +00:00
|
|
|
gfx::IntRect bounds = aPlugins[pluginsIdx].bounds();
|
|
|
|
gfx::IntRect rect(0, 0, bounds.width, bounds.height);
|
2015-01-29 19:41:55 +00:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// Work around for flash's crummy sandbox. See bug 762948. This call
|
|
|
|
// digs down into the window hirearchy, invalidating regions on
|
|
|
|
// windows owned by other processes.
|
|
|
|
mozilla::widget::WinUtils::InvalidatePluginAsWorkaround(widget, visibleBounds);
|
|
|
|
#else
|
|
|
|
rv = widget->Invalidate(visibleBounds);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "widget call failure");
|
|
|
|
#endif
|
|
|
|
visiblePluginIds.AppendElement(aPlugins[pluginsIdx].windowId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Any plugins we didn't update need to be hidden, as they are
|
|
|
|
// not associated with visible content.
|
|
|
|
nsIWidget::UpdateRegisteredPluginWindowVisibility(visiblePluginIds);
|
|
|
|
return true;
|
|
|
|
#endif // !defined(XP_WIN) && !defined(MOZ_WIDGET_GTK)
|
|
|
|
}
|
|
|
|
|
2015-03-04 13:46:15 +00:00
|
|
|
bool
|
|
|
|
CompositorChild::RecvUpdatePluginVisibility(nsTArray<uintptr_t>&& aVisibleIdList)
|
|
|
|
{
|
|
|
|
#if !defined(XP_WIN) && !defined(MOZ_WIDGET_GTK)
|
|
|
|
NS_NOTREACHED("CompositorChild::RecvUpdatePluginVisibility calls "
|
|
|
|
"unexpected on this platform.");
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsIWidget::UpdateRegisteredPluginWindowVisibility(aVisibleIdList);
|
|
|
|
return true;
|
|
|
|
#endif // !defined(XP_WIN) && !defined(MOZ_WIDGET_GTK)
|
|
|
|
}
|
|
|
|
|
2014-03-07 03:24:32 +00:00
|
|
|
bool
|
2014-05-28 21:42:14 +00:00
|
|
|
CompositorChild::RecvDidComposite(const uint64_t& aId, const uint64_t& aTransactionId)
|
2014-03-07 03:24:32 +00:00
|
|
|
{
|
|
|
|
if (mLayerManager) {
|
|
|
|
MOZ_ASSERT(aId == 0);
|
2014-05-28 21:42:14 +00:00
|
|
|
mLayerManager->DidComposite(aTransactionId);
|
2014-03-07 03:24:32 +00:00
|
|
|
} else if (aId != 0) {
|
|
|
|
dom::TabChild *child = dom::TabChild::GetFrom(aId);
|
|
|
|
if (child) {
|
2014-05-28 21:42:14 +00:00
|
|
|
child->DidComposite(aTransactionId);
|
2014-03-07 03:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-08 15:32:00 +00:00
|
|
|
bool
|
|
|
|
CompositorChild::RecvOverfill(const uint32_t &aOverfill)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < mOverfillObservers.Length(); i++) {
|
|
|
|
mOverfillObservers[i]->RunOverfillCallback(aOverfill);
|
|
|
|
}
|
|
|
|
mOverfillObservers.Clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CompositorChild::AddOverfillObserver(ClientLayerManager* aLayerManager)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aLayerManager);
|
|
|
|
mOverfillObservers.AppendElement(aLayerManager);
|
|
|
|
}
|
|
|
|
|
2012-07-17 23:59:45 +00:00
|
|
|
void
|
|
|
|
CompositorChild::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
2015-03-05 18:03:16 +00:00
|
|
|
MOZ_ASSERT(!mCanSend);
|
2012-07-17 23:59:45 +00:00
|
|
|
MOZ_ASSERT(sCompositor == this);
|
2013-04-12 20:25:04 +00:00
|
|
|
|
2013-10-10 16:44:03 +00:00
|
|
|
#ifdef MOZ_B2G
|
|
|
|
// Due to poor lifetime management of gralloc (and possibly shmems) we will
|
|
|
|
// crash at some point in the future when we get destroyed due to abnormal
|
|
|
|
// shutdown. Its better just to crash here. On desktop though, we have a chance
|
|
|
|
// of recovering.
|
2013-04-12 20:25:04 +00:00
|
|
|
if (aWhy == AbnormalShutdown) {
|
|
|
|
NS_RUNTIMEABORT("ActorDestroy by IPC channel failure at CompositorChild");
|
|
|
|
}
|
2013-10-10 16:44:03 +00:00
|
|
|
#endif
|
2015-03-09 17:43:39 +00:00
|
|
|
|
2012-07-17 23:59:45 +00:00
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableMethod(this, &CompositorChild::Release));
|
|
|
|
}
|
|
|
|
|
2013-12-19 20:19:25 +00:00
|
|
|
bool
|
|
|
|
CompositorChild::RecvSharedCompositorFrameMetrics(
|
|
|
|
const mozilla::ipc::SharedMemoryBasic::Handle& metrics,
|
|
|
|
const CrossProcessMutexHandle& handle,
|
2015-03-06 11:25:40 +00:00
|
|
|
const uint64_t& aLayersId,
|
2013-12-19 20:19:25 +00:00
|
|
|
const uint32_t& aAPZCId)
|
|
|
|
{
|
2015-03-06 11:25:40 +00:00
|
|
|
SharedFrameMetricsData* data = new SharedFrameMetricsData(
|
|
|
|
metrics, handle, aLayersId, aAPZCId);
|
2013-12-19 20:19:25 +00:00
|
|
|
mFrameMetricsTable.Put(data->GetViewID(), data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::RecvReleaseSharedCompositorFrameMetrics(
|
|
|
|
const ViewID& aId,
|
|
|
|
const uint32_t& aAPZCId)
|
|
|
|
{
|
|
|
|
SharedFrameMetricsData* data = mFrameMetricsTable.Get(aId);
|
|
|
|
// The SharedFrameMetricsData may have been removed previously if
|
|
|
|
// a SharedFrameMetricsData with the same ViewID but later APZCId had
|
|
|
|
// been store and over wrote it.
|
|
|
|
if (data && (data->GetAPZCId() == aAPZCId)) {
|
|
|
|
mFrameMetricsTable.Remove(aId);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositorChild::SharedFrameMetricsData::SharedFrameMetricsData(
|
|
|
|
const ipc::SharedMemoryBasic::Handle& metrics,
|
|
|
|
const CrossProcessMutexHandle& handle,
|
2015-03-06 11:25:40 +00:00
|
|
|
const uint64_t& aLayersId,
|
|
|
|
const uint32_t& aAPZCId)
|
|
|
|
: mMutex(nullptr)
|
|
|
|
, mLayersId(aLayersId)
|
|
|
|
, mAPZCId(aAPZCId)
|
2013-12-19 20:19:25 +00:00
|
|
|
{
|
|
|
|
mBuffer = new ipc::SharedMemoryBasic(metrics);
|
|
|
|
mBuffer->Map(sizeof(FrameMetrics));
|
|
|
|
mMutex = new CrossProcessMutex(handle);
|
|
|
|
MOZ_COUNT_CTOR(SharedFrameMetricsData);
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositorChild::SharedFrameMetricsData::~SharedFrameMetricsData()
|
|
|
|
{
|
|
|
|
// When the hash table deletes the class, delete
|
|
|
|
// the shared memory and mutex.
|
|
|
|
delete mMutex;
|
2014-07-16 19:39:03 +00:00
|
|
|
mBuffer = nullptr;
|
2013-12-19 20:19:25 +00:00
|
|
|
MOZ_COUNT_DTOR(SharedFrameMetricsData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CompositorChild::SharedFrameMetricsData::CopyFrameMetrics(FrameMetrics* aFrame)
|
|
|
|
{
|
|
|
|
FrameMetrics* frame = static_cast<FrameMetrics*>(mBuffer->memory());
|
|
|
|
MOZ_ASSERT(frame);
|
|
|
|
mMutex->Lock();
|
|
|
|
*aFrame = *frame;
|
|
|
|
mMutex->Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameMetrics::ViewID
|
|
|
|
CompositorChild::SharedFrameMetricsData::GetViewID()
|
|
|
|
{
|
|
|
|
FrameMetrics* frame = static_cast<FrameMetrics*>(mBuffer->memory());
|
|
|
|
MOZ_ASSERT(frame);
|
|
|
|
// Not locking to read of mScrollId since it should not change after being
|
|
|
|
// initially set.
|
2014-03-21 21:48:08 +00:00
|
|
|
return frame->GetScrollId();
|
2013-12-19 20:19:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 11:25:40 +00:00
|
|
|
uint64_t
|
|
|
|
CompositorChild::SharedFrameMetricsData::GetLayersId() const
|
|
|
|
{
|
|
|
|
return mLayersId;
|
|
|
|
}
|
|
|
|
|
2013-12-19 20:19:25 +00:00
|
|
|
uint32_t
|
|
|
|
CompositorChild::SharedFrameMetricsData::GetAPZCId()
|
|
|
|
{
|
|
|
|
return mAPZCId;
|
|
|
|
}
|
2012-07-17 23:59:45 +00:00
|
|
|
|
2014-05-23 18:19:00 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::RecvRemotePaintIsReady()
|
|
|
|
{
|
|
|
|
// Used on the content thread, this bounces the message to the
|
|
|
|
// TabParent (via the TabChild) if the notification was previously requested.
|
|
|
|
// XPCOM gives a soup of compiler errors when trying to do_QueryReference
|
|
|
|
// so I'm using static_cast<>
|
|
|
|
MOZ_LAYERS_LOG(("[RemoteGfx] CompositorChild received RemotePaintIsReady"));
|
|
|
|
nsRefPtr<nsISupports> iTabChildBase(do_QueryReferent(mWeakTabChild));
|
|
|
|
if (!iTabChildBase) {
|
|
|
|
MOZ_LAYERS_LOG(("[RemoteGfx] Note: TabChild was released before RemotePaintIsReady. "
|
|
|
|
"MozAfterRemotePaint will not be sent to listener."));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
TabChildBase* tabChildBase = static_cast<TabChildBase*>(iTabChildBase.get());
|
|
|
|
TabChild* tabChild = static_cast<TabChild*>(tabChildBase);
|
|
|
|
MOZ_ASSERT(tabChild);
|
|
|
|
unused << tabChild->SendRemotePaintIsReady();
|
|
|
|
mWeakTabChild = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CompositorChild::RequestNotifyAfterRemotePaint(TabChild* aTabChild)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTabChild, "NULL TabChild not allowed in CompositorChild::RequestNotifyAfterRemotePaint");
|
|
|
|
mWeakTabChild = do_GetWeakReference( static_cast<dom::TabChildBase*>(aTabChild) );
|
|
|
|
unused << SendRequestNotifyAfterRemotePaint();
|
|
|
|
}
|
|
|
|
|
2014-09-04 12:20:45 +00:00
|
|
|
void
|
|
|
|
CompositorChild::CancelNotifyAfterRemotePaint(TabChild* aTabChild)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsISupports> iTabChildBase(do_QueryReferent(mWeakTabChild));
|
|
|
|
if (!iTabChildBase) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TabChildBase* tabChildBase = static_cast<TabChildBase*>(iTabChildBase.get());
|
|
|
|
TabChild* tabChild = static_cast<TabChild*>(tabChildBase);
|
|
|
|
if (tabChild == aTabChild) {
|
|
|
|
mWeakTabChild = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2014-05-23 18:19:00 +00:00
|
|
|
|
2015-03-05 18:03:16 +00:00
|
|
|
bool
|
|
|
|
CompositorChild::SendWillStop()
|
|
|
|
{
|
|
|
|
return PCompositorChild::SendWillStop();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendPause()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendResume()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendResume();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendNotifyChildCreated(const uint64_t& id)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendNotifyChildCreated(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendAdoptChild(const uint64_t& id)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendAdoptChild(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-05-07 09:07:53 +00:00
|
|
|
CompositorChild::SendMakeSnapshot(const SurfaceDescriptor& inSnapshot, const gfx::IntRect& dirtyRect)
|
2015-03-05 18:03:16 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendMakeSnapshot(inSnapshot, dirtyRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendFlushRendering()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendFlushRendering();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendGetTileSize(int32_t* tileWidth, int32_t* tileHeight)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendGetTileSize(tileWidth, tileHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendStartFrameTimeRecording(const int32_t& bufferSize, uint32_t* startIndex)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendStartFrameTimeRecording(bufferSize, startIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendStopFrameTimeRecording(const uint32_t& startIndex, nsTArray<float>* intervals)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendStopFrameTimeRecording(startIndex, intervals);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendNotifyRegionInvalidated(const nsIntRegion& region)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendNotifyRegionInvalidated(region);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CompositorChild::SendRequestNotifyAfterRemotePaint()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCanSend);
|
|
|
|
if (!mCanSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return PCompositorChild::SendRequestNotifyAfterRemotePaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-19 14:45:37 +00:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|