2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2016-07-18 07:24:27 +03: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/. */
|
|
|
|
|
|
|
|
#include "InProcessCompositorSession.h"
|
|
|
|
|
2020-04-05 06:50:33 +03:00
|
|
|
#include "mozilla/gfx/GPUProcessManager.h"
|
|
|
|
#include "mozilla/layers/CompositorBridgeChild.h"
|
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
|
|
|
#include "mozilla/layers/CompositorManagerChild.h"
|
|
|
|
#include "mozilla/layers/CompositorManagerParent.h"
|
2016-07-20 14:37:00 +03:00
|
|
|
#include "mozilla/layers/IAPZCTreeManager.h"
|
2020-04-05 06:50:33 +03:00
|
|
|
#include "mozilla/widget/CompositorWidget.h"
|
|
|
|
#include "mozilla/widget/PlatformWidgetTypes.h"
|
2017-06-15 21:34:00 +03:00
|
|
|
#include "nsBaseWidget.h"
|
2016-07-20 14:37:00 +03:00
|
|
|
|
2016-07-18 07:24:27 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
InProcessCompositorSession::InProcessCompositorSession(
|
2019-06-19 19:14:56 +03:00
|
|
|
nsBaseWidget* aWidget, widget::CompositorWidget* aCompositorWidget,
|
2016-07-18 07:24:27 +03:00
|
|
|
CompositorBridgeChild* aChild, CompositorBridgeParent* aParent)
|
2019-06-19 19:14:56 +03:00
|
|
|
: CompositorSession(aWidget, aCompositorWidget->AsDelegate(), aChild,
|
2016-07-18 07:24:27 +03:00
|
|
|
aParent->RootLayerTreeId()),
|
2016-07-18 07:24:27 +03:00
|
|
|
mCompositorBridgeParent(aParent),
|
2019-06-19 19:14:56 +03:00
|
|
|
mCompositorWidget(aCompositorWidget) {
|
2020-04-05 06:50:33 +03:00
|
|
|
gfx::GPUProcessManager::Get()->RegisterInProcessSession(this);
|
2016-07-18 07:24:27 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
RefPtr<InProcessCompositorSession> InProcessCompositorSession::Create(
|
2016-11-08 18:42:19 +03:00
|
|
|
nsBaseWidget* aWidget, LayerManager* aLayerManager,
|
2018-03-25 02:06:01 +03:00
|
|
|
const LayersId& aRootLayerTreeId, CSSToLayoutDeviceScale aScale,
|
2017-01-13 01:29:41 +03:00
|
|
|
const CompositorOptions& aOptions, bool aUseExternalSurfaceSize,
|
2017-04-14 11:06:09 +03:00
|
|
|
const gfx::IntSize& aSurfaceSize, uint32_t aNamespace) {
|
2020-04-05 06:50:33 +03:00
|
|
|
widget::CompositorWidgetInitData initData;
|
2016-07-18 07:24:27 +03:00
|
|
|
aWidget->GetCompositorWidgetInitData(&initData);
|
|
|
|
|
2017-01-13 01:29:42 +03:00
|
|
|
RefPtr<CompositorWidget> widget =
|
|
|
|
CompositorWidget::CreateLocal(initData, aOptions, aWidget);
|
2016-07-18 07:24:27 +03:00
|
|
|
RefPtr<CompositorBridgeParent> parent =
|
2017-06-14 18:39:59 +03:00
|
|
|
CompositorManagerParent::CreateSameProcessWidgetCompositorBridge(
|
|
|
|
aScale, aOptions, aUseExternalSurfaceSize, aSurfaceSize);
|
|
|
|
MOZ_ASSERT(parent);
|
|
|
|
parent->InitSameProcess(widget, aRootLayerTreeId);
|
|
|
|
|
|
|
|
RefPtr<CompositorBridgeChild> child =
|
|
|
|
CompositorManagerChild::CreateSameProcessWidgetCompositorBridge(
|
|
|
|
aLayerManager, aNamespace);
|
|
|
|
MOZ_ASSERT(child);
|
2016-07-18 07:24:27 +03:00
|
|
|
|
2019-06-19 19:14:56 +03:00
|
|
|
return new InProcessCompositorSession(aWidget, widget, child, parent);
|
2017-06-15 21:34:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void InProcessCompositorSession::NotifySessionLost() {
|
|
|
|
mWidget->NotifyCompositorSessionLost(this);
|
2016-07-18 07:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CompositorBridgeParent* InProcessCompositorSession::GetInProcessBridge() const {
|
|
|
|
return mCompositorBridgeParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InProcessCompositorSession::SetContentController(
|
|
|
|
GeckoContentController* aController) {
|
2016-07-18 07:24:27 +03:00
|
|
|
mCompositorBridgeParent->SetControllerForLayerTree(mRootLayerTreeId,
|
|
|
|
aController);
|
2016-07-18 07:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IAPZCTreeManager> InProcessCompositorSession::GetAPZCTreeManager()
|
|
|
|
const {
|
2016-07-18 07:24:27 +03:00
|
|
|
return mCompositorBridgeParent->GetAPZCTreeManager(mRootLayerTreeId);
|
2016-07-18 07:24:27 +03:00
|
|
|
}
|
|
|
|
|
2017-06-15 21:34:00 +03:00
|
|
|
nsIWidget* InProcessCompositorSession::GetWidget() const { return mWidget; }
|
|
|
|
|
2016-07-18 07:24:27 +03:00
|
|
|
void InProcessCompositorSession::Shutdown() {
|
|
|
|
// Destroy will synchronously wait for the parent to acknowledge shutdown,
|
|
|
|
// at which point CBP will defer a Release on the compositor thread. We
|
|
|
|
// can safely release our reference now, and let the destructor run on either
|
|
|
|
// thread.
|
2017-04-06 01:42:50 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
if (mUiCompositorControllerChild) {
|
|
|
|
mUiCompositorControllerChild->Destroy();
|
|
|
|
mUiCompositorControllerChild = nullptr;
|
|
|
|
}
|
|
|
|
#endif // defined(MOZ_WIDGET_ANDROID)
|
2017-09-01 00:26:46 +03:00
|
|
|
mCompositorBridgeChild->Destroy();
|
|
|
|
mCompositorBridgeChild = nullptr;
|
|
|
|
mCompositorBridgeParent = nullptr;
|
|
|
|
mCompositorWidget = nullptr;
|
2020-04-05 06:50:33 +03:00
|
|
|
gfx::GPUProcessManager::Get()->UnregisterInProcessSession(this);
|
2016-07-18 07:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|