2017-10-27 20:33:53 +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: */
|
2012-05-21 15:12:37 +04: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/. */
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2012-07-18 03:59:45 +04:00
|
|
|
#include "base/basictypes.h"
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2019-04-06 09:02:28 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2016-01-08 22:17:39 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2019-04-10 00:38:15 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2016-03-22 21:08:38 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2018-10-25 23:23:46 +03:00
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
2013-04-24 22:42:40 +04:00
|
|
|
#include "mozilla/layers/LayerTransactionParent.h"
|
2010-08-21 03:24:41 +04:00
|
|
|
#include "nsFrameLoader.h"
|
2015-02-17 05:30:02 +03:00
|
|
|
#include "nsStyleStructInlines.h"
|
2012-07-18 03:59:45 +04:00
|
|
|
#include "nsSubDocumentFrame.h"
|
2019-06-02 20:51:33 +03:00
|
|
|
#include "RemoteLayerTreeOwner.h"
|
2016-05-23 10:27:57 +03:00
|
|
|
#include "mozilla/gfx/GPUProcessManager.h"
|
2016-03-22 21:08:38 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeChild.h"
|
2016-11-16 16:54:51 +03:00
|
|
|
#include "mozilla/layers/WebRenderLayerManager.h"
|
2017-07-31 22:27:29 +03:00
|
|
|
#include "mozilla/layers/WebRenderScrollData.h"
|
2017-07-25 15:18:49 +03:00
|
|
|
#include "mozilla/webrender/WebRenderAPI.h"
|
2019-05-24 17:28:23 +03:00
|
|
|
#include "mozilla/dom/EffectsInfo.h"
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2012-07-20 10:48:27 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-08-01 16:31:47 +04:00
|
|
|
using namespace mozilla::gfx;
|
2010-08-21 03:24:41 +04:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layout {
|
|
|
|
|
2021-07-29 20:19:48 +03:00
|
|
|
static already_AddRefed<LayerManager> GetLayerManager(
|
2019-04-10 00:38:15 +03:00
|
|
|
BrowserParent* aBrowserParent) {
|
2021-07-29 20:19:48 +03:00
|
|
|
RefPtr<LayerManager> lm;
|
2019-04-10 00:38:15 +03:00
|
|
|
if (Element* element = aBrowserParent->GetOwnerElement()) {
|
2021-07-29 20:19:48 +03:00
|
|
|
if (WindowRenderer* renderer =
|
|
|
|
nsContentUtils::WindowRendererForContent(element)) {
|
|
|
|
lm = renderer->AsLayerManager();
|
|
|
|
return lm.forget();
|
2021-07-23 01:58:57 +03:00
|
|
|
}
|
2021-07-29 20:19:48 +03:00
|
|
|
if (WindowRenderer* renderer =
|
|
|
|
nsContentUtils::WindowRendererForDocument(element->OwnerDoc())) {
|
|
|
|
lm = renderer->AsLayerManager();
|
|
|
|
return lm.forget();
|
2017-07-07 05:46:59 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-23 18:52:30 +03:00
|
|
|
return nullptr;
|
2012-07-18 03:59:45 +04:00
|
|
|
}
|
|
|
|
|
2019-06-02 20:51:33 +03:00
|
|
|
RemoteLayerTreeOwner::RemoteLayerTreeOwner()
|
2018-03-25 02:06:01 +03:00
|
|
|
: mLayersId{0},
|
2019-04-10 00:38:15 +03:00
|
|
|
mBrowserParent(nullptr),
|
2021-07-29 20:19:48 +03:00
|
|
|
mLayerManager(nullptr),
|
2018-10-25 23:23:46 +03:00
|
|
|
mInitialized(false),
|
|
|
|
mLayersConnected(false) {}
|
2016-03-29 19:49:07 +03:00
|
|
|
|
2020-03-17 12:38:32 +03:00
|
|
|
RemoteLayerTreeOwner::~RemoteLayerTreeOwner() = default;
|
2016-03-29 19:49:07 +03:00
|
|
|
|
2019-06-02 20:51:33 +03:00
|
|
|
bool RemoteLayerTreeOwner::Initialize(BrowserParent* aBrowserParent) {
|
2019-04-10 00:38:15 +03:00
|
|
|
if (mInitialized || !aBrowserParent) {
|
2016-03-29 19:49:07 +03:00
|
|
|
return false;
|
2014-05-08 18:04:00 +04:00
|
|
|
}
|
2014-01-16 01:10:39 +04:00
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
mBrowserParent = aBrowserParent;
|
2021-07-29 20:19:48 +03:00
|
|
|
RefPtr<LayerManager> lm = GetLayerManager(mBrowserParent);
|
2018-11-01 20:23:37 +03:00
|
|
|
PCompositorBridgeChild* compositor =
|
2021-07-29 20:19:48 +03:00
|
|
|
lm ? lm->GetCompositorBridgeChild() : nullptr;
|
2019-04-10 00:38:15 +03:00
|
|
|
mTabProcessId = mBrowserParent->Manager()->OtherPid();
|
2018-11-01 20:23:37 +03:00
|
|
|
|
|
|
|
// Our remote frame will push layers updates to the compositor,
|
|
|
|
// and we'll keep an indirect reference to that tree.
|
|
|
|
GPUProcessManager* gpm = GPUProcessManager::Get();
|
|
|
|
mLayersConnected = gpm->AllocateAndConnectLayerTreeId(
|
|
|
|
compositor, mTabProcessId, &mLayersId, &mCompositorOptions);
|
2016-03-29 19:49:07 +03:00
|
|
|
|
2018-10-25 23:23:46 +03:00
|
|
|
mInitialized = true;
|
2016-03-29 19:49:07 +03:00
|
|
|
return true;
|
2010-10-26 21:51:08 +04:00
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2019-06-02 20:51:33 +03:00
|
|
|
void RemoteLayerTreeOwner::Destroy() {
|
2018-11-05 23:52:47 +03:00
|
|
|
if (mLayersId.IsValid()) {
|
|
|
|
GPUProcessManager::Get()->UnmapLayerTreeId(mLayersId, mTabProcessId);
|
|
|
|
}
|
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
mBrowserParent = nullptr;
|
2021-07-29 20:19:48 +03:00
|
|
|
mLayerManager = nullptr;
|
2011-01-06 07:54:47 +03:00
|
|
|
}
|
|
|
|
|
2019-06-02 20:51:33 +03:00
|
|
|
void RemoteLayerTreeOwner::EnsureLayersConnected(
|
|
|
|
CompositorOptions* aCompositorOptions) {
|
2021-07-29 20:19:48 +03:00
|
|
|
RefPtr<LayerManager> lm = GetLayerManager(mBrowserParent);
|
|
|
|
if (!lm) {
|
2018-10-25 23:23:46 +03:00
|
|
|
return;
|
2011-01-26 09:26:37 +03:00
|
|
|
}
|
|
|
|
|
2021-07-29 20:19:48 +03:00
|
|
|
if (!lm->GetCompositorBridgeChild()) {
|
2018-10-25 23:23:46 +03:00
|
|
|
return;
|
2011-02-23 20:45:09 +03:00
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2021-07-29 20:19:48 +03:00
|
|
|
mLayersConnected = lm->GetCompositorBridgeChild()->SendNotifyChildRecreated(
|
|
|
|
mLayersId, &mCompositorOptions);
|
2018-10-25 23:23:46 +03:00
|
|
|
*aCompositorOptions = mCompositorOptions;
|
2010-08-21 03:24:41 +04:00
|
|
|
}
|
|
|
|
|
2021-07-29 20:19:48 +03:00
|
|
|
LayerManager* RemoteLayerTreeOwner::AttachLayerManager() {
|
|
|
|
RefPtr<LayerManager> lm;
|
2019-04-10 00:38:15 +03:00
|
|
|
if (mBrowserParent) {
|
2021-07-29 20:19:48 +03:00
|
|
|
lm = GetLayerManager(mBrowserParent);
|
2017-04-18 07:41:18 +03:00
|
|
|
}
|
2017-04-18 07:41:18 +03:00
|
|
|
|
2017-05-09 20:23:20 +03:00
|
|
|
// Perhaps the document containing this frame currently has no presentation?
|
2021-07-29 20:19:48 +03:00
|
|
|
if (lm && lm->GetCompositorBridgeChild() && lm != mLayerManager) {
|
2017-05-09 20:23:20 +03:00
|
|
|
mLayersConnected =
|
2021-07-29 20:19:48 +03:00
|
|
|
lm->GetCompositorBridgeChild()->SendAdoptChild(mLayersId);
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(lm);
|
2017-05-09 20:23:20 +03:00
|
|
|
}
|
2017-04-18 07:41:18 +03:00
|
|
|
|
2021-07-29 20:19:48 +03:00
|
|
|
mLayerManager = std::move(lm);
|
|
|
|
return mLayerManager;
|
2017-04-18 07:41:18 +03:00
|
|
|
}
|
|
|
|
|
2019-06-02 20:51:33 +03:00
|
|
|
void RemoteLayerTreeOwner::OwnerContentChanged() {
|
2021-07-29 20:19:48 +03:00
|
|
|
Unused << AttachLayerManager();
|
2019-06-02 20:51:33 +03:00
|
|
|
}
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2019-06-02 20:51:33 +03:00
|
|
|
void RemoteLayerTreeOwner::GetTextureFactoryIdentifier(
|
2018-11-07 00:35:37 +03:00
|
|
|
TextureFactoryIdentifier* aTextureFactoryIdentifier) const {
|
2021-07-29 20:19:48 +03:00
|
|
|
RefPtr<LayerManager> lm =
|
|
|
|
mBrowserParent ? GetLayerManager(mBrowserParent) : nullptr;
|
2014-11-16 21:23:22 +03:00
|
|
|
// Perhaps the document containing this frame currently has no presentation?
|
2021-07-29 20:19:48 +03:00
|
|
|
if (lm) {
|
|
|
|
*aTextureFactoryIdentifier = lm->GetTextureFactoryIdentifier();
|
2014-11-16 21:23:22 +03:00
|
|
|
} else {
|
|
|
|
*aTextureFactoryIdentifier = TextureFactoryIdentifier();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 23:23:46 +03:00
|
|
|
} // namespace layout
|
|
|
|
} // namespace mozilla
|