Bug 1754978 - Part 1. Refactor CompositableHandle infrastructure to allow in-process driven handles. r=sotaro

For WebGPU, we produce the textures in the compositor process and the
content process doesn't need to be that involved except for hooking up
the texture to the display list. Currently this is done via an external
image ID.

Given that WebGPU needs to work with OffscreenCanvas, it would be best
if its display pipeline was consistent whether it was gotten from an
HTMLCanvasElement, OffscreenCanvas on the main thread, or on a worker
thread. As such, using an AsyncImagePipeline would be best.

However there is no real need to bounce the handles across process
boundaries. Hence this patch which adds CompositableInProcessManager.
This static class is responsible for collecting WebRenderImageHost
objects backed by TextureHost objects which do not leave the compositor
process. This will allow WebGPUParent to schedule compositions directly
in future patches.

Differential Revision: https://phabricator.services.mozilla.com/D138588
This commit is contained in:
Andrew Osmond 2022-02-18 15:59:12 +00:00
Родитель 9a6806f4f8
Коммит 45ae50555d
25 изменённых файлов: 327 добавлений и 48 удалений

Просмотреть файл

@ -952,7 +952,7 @@
fun:wr_thread_pool_new
fun:WebRenderThreadPool
fun:RenderThread
fun:_ZN7mozilla2wr12RenderThread5StartEv
fun:_ZN7mozilla2wr12RenderThread5StartEj
}
{

Просмотреть файл

@ -73,7 +73,8 @@ void GPUChild::Init() {
features = gfxInfoRaw->GetAllFeatures();
}
SendInit(updates, devicePrefs, mappings, features);
SendInit(updates, devicePrefs, mappings, features,
GPUProcessManager::Get()->AllocateNamespace());
gfxVars::AddReceiver(this);

Просмотреть файл

@ -229,7 +229,7 @@ void GPUParent::NotifyDeviceReset() {
mozilla::ipc::IPCResult GPUParent::RecvInit(
nsTArray<GfxVarUpdate>&& vars, const DevicePrefs& devicePrefs,
nsTArray<LayerTreeIdMapping>&& aMappings,
nsTArray<GfxInfoFeatureStatus>&& aFeatures) {
nsTArray<GfxInfoFeatureStatus>&& aFeatures, uint32_t aWrNamespace) {
for (const auto& var : vars) {
gfxVars::ApplyUpdate(var);
}
@ -346,7 +346,7 @@ mozilla::ipc::IPCResult GPUParent::RecvInit(
// Make sure to do this *after* we update gfxVars above.
if (gfxVars::UseWebRender()) {
wr::RenderThread::Start();
wr::RenderThread::Start(aWrNamespace);
image::ImageMemoryReporter::InitForWebRender();
}
#ifdef XP_WIN
@ -549,7 +549,8 @@ mozilla::ipc::IPCResult GPUParent::RecvNewContentVRManager(
mozilla::ipc::IPCResult GPUParent::RecvNewContentRemoteDecoderManager(
Endpoint<PRemoteDecoderManagerParent>&& aEndpoint) {
if (!RemoteDecoderManagerParent::CreateForContent(std::move(aEndpoint), /* AllowHardwareDecoding */ true)) {
if (!RemoteDecoderManagerParent::CreateForContent(
std::move(aEndpoint), /* AllowHardwareDecoding */ true)) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();

Просмотреть файл

@ -43,7 +43,8 @@ class GPUParent final : public PGPUParent {
mozilla::ipc::IPCResult RecvInit(nsTArray<GfxVarUpdate>&& vars,
const DevicePrefs& devicePrefs,
nsTArray<LayerTreeIdMapping>&& mappings,
nsTArray<GfxInfoFeatureStatus>&& features);
nsTArray<GfxInfoFeatureStatus>&& features,
uint32_t wrNamespace);
mozilla::ipc::IPCResult RecvInitCompositorManager(
Endpoint<PCompositorManagerParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvInitVsyncBridge(

Просмотреть файл

@ -57,7 +57,8 @@ parent:
async Init(GfxVarUpdate[] vars,
DevicePrefs devicePrefs,
LayerTreeIdMapping[] mapping,
GfxInfoFeatureStatus[] features);
GfxInfoFeatureStatus[] features,
uint32_t wrNamespace);
async InitCompositorManager(Endpoint<PCompositorManagerParent> endpoint);
async InitVsyncBridge(Endpoint<PVsyncBridgeParent> endpoint);

Просмотреть файл

@ -316,6 +316,12 @@ class CompositableHandle final {
uint64_t mHandle;
};
enum class CompositableHandleOwner : uint8_t {
WebRenderBridge,
ImageBridge,
InProcessManager,
};
// clang-format off
MOZ_DEFINE_ENUM_CLASS_WITH_BASE(ScrollDirection, uint8_t, (
eVertical,

Просмотреть файл

@ -0,0 +1,76 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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 "CompositableInProcessManager.h"
#include "mozilla/layers/CompositorThread.h"
namespace mozilla::layers {
std::map<std::pair<base::ProcessId, uint64_t>, RefPtr<WebRenderImageHost>>
CompositableInProcessManager::sCompositables;
StaticMutex CompositableInProcessManager::sMutex;
uint32_t CompositableInProcessManager::sNamespace(0);
Atomic<uint32_t> CompositableInProcessManager::sNextResourceId(1);
Atomic<uint64_t> CompositableInProcessManager::sNextHandle(1);
/* static */ void CompositableInProcessManager::Initialize(
uint32_t aNamespace) {
MOZ_ASSERT(NS_IsMainThread());
sNamespace = aNamespace;
}
/* static */ void CompositableInProcessManager::Shutdown() {
MOZ_ASSERT(NS_IsMainThread());
StaticMutexAutoLock lock(sMutex);
sCompositables.clear();
}
/* static */ RefPtr<WebRenderImageHost> CompositableInProcessManager::Add(
const CompositableHandle& aHandle, base::ProcessId aForPid,
const TextureInfo& aTextureInfo) {
MOZ_RELEASE_ASSERT(aHandle.Value());
StaticMutexAutoLock lock(sMutex);
const auto key = std::pair(aForPid, aHandle.Value());
if (sCompositables.find(key) != sCompositables.end()) {
MOZ_ASSERT_UNREACHABLE("Duplicate handle!");
return nullptr;
}
auto host = MakeRefPtr<WebRenderImageHost>(aTextureInfo);
sCompositables[key] = host;
host->SetAsyncRef(AsyncCompositableRef(aForPid, aHandle));
return host;
}
/* static */ RefPtr<WebRenderImageHost> CompositableInProcessManager::Find(
const CompositableHandle& aHandle, base::ProcessId aForPid) {
StaticMutexAutoLock lock(sMutex);
const auto key = std::pair(aForPid, aHandle.Value());
const auto i = sCompositables.find(key);
if (NS_WARN_IF(i == sCompositables.end())) {
return nullptr;
}
return i->second;
}
/* static */ void CompositableInProcessManager::Release(
const CompositableHandle& aHandle, base::ProcessId aForPid) {
StaticMutexAutoLock lock(sMutex);
const auto key = std::pair(aForPid, aHandle.Value());
const auto i = sCompositables.find(key);
if (NS_WARN_IF(i == sCompositables.end())) {
return;
}
sCompositables.erase(i);
}
} // namespace mozilla::layers

Просмотреть файл

@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/LayersTypes.h"
#include "mozilla/layers/WebRenderImageHost.h"
#include "mozilla/webrender/WebRenderTypes.h"
#include "mozilla/Atomics.h"
#include "mozilla/Mutex.h"
#include <map>
#include <utility>
namespace mozilla::layers {
/**
* CompostaibleInProcessManager is responsible for tracking textures that the
* content process knows nothing about, beyond the CompositableHandle itself
* for the purpose of binding to an AsyncImagePipeline in the display list.
*
* Hence the compositor process is responsible for creating and updating the
* WebRenderImageHost object. This will allow frames to be composited without
* interacting with the content process.
*/
class CompositableInProcessManager final {
public:
static void Initialize(uint32_t aNamespace);
static void Shutdown();
static RefPtr<WebRenderImageHost> Add(const CompositableHandle& aHandle,
base::ProcessId aForPid,
const TextureInfo& aTextureInfo);
static RefPtr<WebRenderImageHost> Find(const CompositableHandle& aHandle,
base::ProcessId aForPid);
static void Release(const CompositableHandle& aHandle,
base::ProcessId aForPid);
static CompositableHandle GetNextHandle() {
return CompositableHandle(sNextHandle++);
}
static uint32_t GetNextResourceId() {
uint32_t resourceId = sNextResourceId++;
MOZ_RELEASE_ASSERT(resourceId != 0);
return resourceId;
}
static wr::ExternalImageId GetNextExternalImageId() {
return wr::ToExternalImageId(GetShiftedNamespace() | GetNextResourceId());
}
private:
static uint64_t GetShiftedNamespace() {
MOZ_ASSERT(sNamespace != 0);
return static_cast<uint64_t>(sNamespace) << 32;
}
static std::map<std::pair<base::ProcessId, uint64_t>,
RefPtr<WebRenderImageHost>>
sCompositables;
static StaticMutex sMutex;
static uint32_t sNamespace;
static Atomic<uint32_t> sNextResourceId;
static Atomic<uint64_t> sNextHandle;
};
} // namespace mozilla::layers

Просмотреть файл

@ -206,6 +206,13 @@ struct ParamTraits<mozilla::layers::CompositableHandle> {
}
};
template <>
struct ParamTraits<mozilla::layers::CompositableHandleOwner>
: public ContiguousEnumSerializerInclusive<
mozilla::layers::CompositableHandleOwner,
mozilla::layers::CompositableHandleOwner::WebRenderBridge,
mozilla::layers::CompositableHandleOwner::InProcessManager> {};
template <>
struct ParamTraits<mozilla::layers::FrameMetrics>
: BitfieldHelper<mozilla::layers::FrameMetrics> {

Просмотреть файл

@ -13,6 +13,7 @@ include LayersMessages;
include protocol PTexture;
using mozilla::layers::CompositableHandle from "mozilla/layers/LayersTypes.h";
using mozilla::layers::CompositableHandleOwner from "mozilla/layers/LayersTypes.h";
using mozilla::wr::LayoutSize from "mozilla/webrender/webrender_ffi.h";
using mozilla::wr::ImageDescriptor from "mozilla/webrender/webrender_ffi.h";
using mozilla::wr::ImageRendering from "mozilla/webrender/webrender_ffi.h";
@ -66,7 +67,7 @@ struct OpAddCompositorAnimations {
struct OpAddPipelineIdForCompositable {
PipelineId pipelineId;
CompositableHandle handle;
bool isAsync;
CompositableHandleOwner owner;
};
struct OpRemovePipelineIdForCompositable {

Просмотреть файл

@ -140,6 +140,7 @@ EXPORTS.mozilla.layers += [
"ipc/CanvasThread.h",
"ipc/CanvasTranslator.h",
"ipc/CompositableForwarder.h",
"ipc/CompositableInProcessManager.h",
"ipc/CompositableTransactionParent.h",
"ipc/CompositorBridgeChild.h",
"ipc/CompositorBridgeParent.h",
@ -359,6 +360,7 @@ UNIFIED_SOURCES += [
"ipc/CanvasThread.cpp",
"ipc/CanvasTranslator.cpp",
"ipc/CompositableForwarder.cpp",
"ipc/CompositableInProcessManager.cpp",
"ipc/CompositableTransactionParent.cpp",
"ipc/CompositorBench.cpp",
"ipc/CompositorBridgeChild.cpp",

Просмотреть файл

@ -181,13 +181,10 @@ void RenderRootStateManager::UpdateResources(
wr::IpcResourceUpdateQueue& aResources) {
WrBridge()->UpdateResources(aResources);
}
void RenderRootStateManager::AddPipelineIdForAsyncCompositable(
const wr::PipelineId& aPipelineId, const CompositableHandle& aHandle) {
WrBridge()->AddPipelineIdForAsyncCompositable(aPipelineId, aHandle);
}
void RenderRootStateManager::AddPipelineIdForCompositable(
const wr::PipelineId& aPipelineId, const CompositableHandle& aHandle) {
WrBridge()->AddPipelineIdForCompositable(aPipelineId, aHandle);
const wr::PipelineId& aPipelineId, const CompositableHandle& aHandle,
CompositableHandleOwner aOwner) {
WrBridge()->AddPipelineIdForCompositable(aPipelineId, aHandle, aOwner);
}
void RenderRootStateManager::RemovePipelineIdForCompositable(
const wr::PipelineId& aPipelineId) {

Просмотреть файл

@ -57,10 +57,9 @@ class RenderRootStateManager {
void AddWebRenderParentCommand(const WebRenderParentCommand& aCmd);
void UpdateResources(wr::IpcResourceUpdateQueue& aResources);
void AddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId,
const CompositableHandle& aHandlee);
void AddPipelineIdForCompositable(const wr::PipelineId& aPipelineId,
const CompositableHandle& aHandlee);
const CompositableHandle& aHandle,
CompositableHandleOwner aOwner);
void RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId);
/// Release TextureClient that is bounded to ImageKey.
/// It is used for recycling TextureClient.

Просмотреть файл

@ -181,16 +181,11 @@ void WebRenderBridgeChild::ProcessWebRenderParentCommands() {
}
}
void WebRenderBridgeChild::AddPipelineIdForAsyncCompositable(
const wr::PipelineId& aPipelineId, const CompositableHandle& aHandle) {
AddWebRenderParentCommand(
OpAddPipelineIdForCompositable(aPipelineId, aHandle, /* isAsync */ true));
}
void WebRenderBridgeChild::AddPipelineIdForCompositable(
const wr::PipelineId& aPipelineId, const CompositableHandle& aHandle) {
AddWebRenderParentCommand(OpAddPipelineIdForCompositable(
aPipelineId, aHandle, /* isAsync */ false));
const wr::PipelineId& aPipelineId, const CompositableHandle& aHandle,
CompositableHandleOwner aOwner) {
AddWebRenderParentCommand(
OpAddPipelineIdForCompositable(aPipelineId, aHandle, aOwner));
}
void WebRenderBridgeChild::RemovePipelineIdForCompositable(

Просмотреть файл

@ -98,10 +98,9 @@ class WebRenderBridgeChild final : public PWebRenderBridgeChild,
return mActiveResourceTracker.get();
}
void AddPipelineIdForAsyncCompositable(const wr::PipelineId& aPipelineId,
const CompositableHandle& aHandlee);
void AddPipelineIdForCompositable(const wr::PipelineId& aPipelineId,
const CompositableHandle& aHandlee);
const CompositableHandle& aHandle,
CompositableHandleOwner aOwner);
void RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId);
/// Release TextureClient that is bounded to ImageKey.

Просмотреть файл

@ -25,6 +25,7 @@
#include "mozilla/layers/AnimationHelper.h"
#include "mozilla/layers/APZSampler.h"
#include "mozilla/layers/APZUpdater.h"
#include "mozilla/layers/CompositableInProcessManager.h"
#include "mozilla/layers/Compositor.h"
#include "mozilla/layers/CompositorBridgeParent.h"
#include "mozilla/layers/CompositorAnimationStorage.h"
@ -1513,7 +1514,7 @@ bool WebRenderBridgeParent::ProcessWebRenderParentCommands(
case WebRenderParentCommand::TOpAddPipelineIdForCompositable: {
const OpAddPipelineIdForCompositable& op =
cmd.get_OpAddPipelineIdForCompositable();
AddPipelineIdForCompositable(op.pipelineId(), op.handle(), op.isAsync(),
AddPipelineIdForCompositable(op.pipelineId(), op.handle(), op.owner(),
aTxn, txnForImageBridge);
break;
}
@ -1801,7 +1802,7 @@ mozilla::ipc::IPCResult WebRenderBridgeParent::RecvGetSnapshot(
void WebRenderBridgeParent::AddPipelineIdForCompositable(
const wr::PipelineId& aPipelineId, const CompositableHandle& aHandle,
const bool& aAsync, wr::TransactionBuilder& aTxn,
const CompositableHandleOwner& aOwner, wr::TransactionBuilder& aTxn,
wr::TransactionBuilder& aTxnForImageBridge) {
if (mDestroyed) {
return;
@ -1811,16 +1812,24 @@ void WebRenderBridgeParent::AddPipelineIdForCompositable(
mAsyncCompositables.end());
RefPtr<CompositableHost> host;
if (aAsync) {
RefPtr<ImageBridgeParent> imageBridge =
ImageBridgeParent::GetInstance(OtherPid());
if (!imageBridge) {
return;
switch (aOwner) {
case CompositableHandleOwner::WebRenderBridge:
host = FindCompositable(aHandle);
break;
case CompositableHandleOwner::ImageBridge: {
RefPtr<ImageBridgeParent> imageBridge =
ImageBridgeParent::GetInstance(OtherPid());
if (!imageBridge) {
return;
}
host = imageBridge->FindCompositable(aHandle);
break;
}
host = imageBridge->FindCompositable(aHandle);
} else {
host = FindCompositable(aHandle);
case CompositableHandleOwner::InProcessManager:
host = CompositableInProcessManager::Find(aHandle, OtherPid());
break;
}
if (!host) {
return;
}

Просмотреть файл

@ -378,7 +378,7 @@ class WebRenderBridgeParent final : public PWebRenderBridgeParent,
void AddPipelineIdForCompositable(const wr::PipelineId& aPipelineIds,
const CompositableHandle& aHandle,
const bool& aAsync,
const CompositableHandleOwner& aOwner,
wr::TransactionBuilder& aTxn,
wr::TransactionBuilder& aTxnForImageBridge);
void RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId,

Просмотреть файл

@ -48,8 +48,9 @@ bool WebRenderCanvasRendererAsync::CreateCompositable() {
// Alloc async image pipeline id.
mPipelineId = Some(
mManager->WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
mManager->AddPipelineIdForCompositable(mPipelineId.ref(),
mCanvasClient->GetIPCHandle());
mManager->AddPipelineIdForCompositable(
mPipelineId.ref(), mCanvasClient->GetIPCHandle(),
CompositableHandleOwner::WebRenderBridge);
}
return true;

Просмотреть файл

@ -2053,6 +2053,24 @@ bool WebRenderCommandBuilder::PushImageProvider(
return true;
}
void WebRenderCommandBuilder::PushInProcessImage(
nsDisplayItem* aItem, const CompositableHandle& aHandle,
mozilla::wr::DisplayListBuilder& aBuilder,
mozilla::wr::IpcResourceUpdateQueue& aResources,
const StackingContextHelper& aSc,
const LayoutDeviceRect& aAsyncImageBounds) {
RefPtr<WebRenderInProcessImageData> imageData =
CreateOrRecycleWebRenderUserData<WebRenderInProcessImageData>(aItem);
MOZ_ASSERT(imageData);
auto rendering = wr::ToImageRendering(aItem->Frame()->UsedImageRendering());
LayoutDeviceRect scBounds(LayoutDevicePoint(0, 0), aAsyncImageBounds.Size());
imageData->CreateWebRenderCommands(aBuilder, aHandle, aSc, aAsyncImageBounds,
scBounds, VideoInfo::Rotation::kDegree_0,
rendering, wr::MixBlendMode::Normal,
!aItem->BackfaceIsHidden());
}
static void PaintItemByDrawTarget(nsDisplayItem* aItem, gfx::DrawTarget* aDT,
const LayoutDevicePoint& aOffset,
const IntRect& visibleRect,

Просмотреть файл

@ -93,6 +93,13 @@ class WebRenderCommandBuilder final {
const LayoutDeviceRect& aRect,
const LayoutDeviceRect& aClip);
void PushInProcessImage(nsDisplayItem* aItem,
const CompositableHandle& aHandle,
mozilla::wr::DisplayListBuilder& aBuilder,
mozilla::wr::IpcResourceUpdateQueue& aResources,
const StackingContextHelper& aSc,
const LayoutDeviceRect& aAsyncImageBounds);
Maybe<wr::ImageMask> BuildWrMaskImage(
nsDisplayMasksAndClipPaths* aMaskItem, wr::DisplayListBuilder& aBuilder,
wr::IpcResourceUpdateQueue& aResources, const StackingContextHelper& aSc,

Просмотреть файл

@ -210,8 +210,9 @@ void WebRenderImageData::CreateAsyncImageWebRenderCommands(
// Alloc async image pipeline id.
mPipelineId =
Some(WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
WrBridge()->AddPipelineIdForAsyncCompositable(
mPipelineId.ref(), aContainer->GetAsyncContainerHandle());
WrBridge()->AddPipelineIdForCompositable(
mPipelineId.ref(), aContainer->GetAsyncContainerHandle(),
CompositableHandleOwner::ImageBridge);
mContainer = aContainer;
}
MOZ_ASSERT(!mImageClient);
@ -288,6 +289,61 @@ bool WebRenderImageProviderData::Invalidate(ImageProviderId aProviderId) const {
return NS_SUCCEEDED(rv) && mKey.ref() == key;
}
WebRenderInProcessImageData::WebRenderInProcessImageData(
RenderRootStateManager* aManager, nsDisplayItem* aItem)
: WebRenderUserData(aManager, aItem) {}
WebRenderInProcessImageData::WebRenderInProcessImageData(
RenderRootStateManager* aManager, uint32_t aDisplayItemKey,
nsIFrame* aFrame)
: WebRenderUserData(aManager, aDisplayItemKey, aFrame) {}
WebRenderInProcessImageData::~WebRenderInProcessImageData() {
if (mPipelineId) {
mManager->RemovePipelineIdForCompositable(mPipelineId.ref());
}
}
void WebRenderInProcessImageData::CreateWebRenderCommands(
mozilla::wr::DisplayListBuilder& aBuilder,
const CompositableHandle& aHandle, const StackingContextHelper& aSc,
const LayoutDeviceRect& aBounds, const LayoutDeviceRect& aSCBounds,
VideoInfo::Rotation aRotation, const wr::ImageRendering& aFilter,
const wr::MixBlendMode& aMixBlendMode, bool aIsBackfaceVisible) {
MOZ_ASSERT(aHandle);
if (mPipelineId.isSome() && !(mHandle == aHandle)) {
// In this case, we need to remove the existed pipeline and create new one
// because the CompositableHandle has changed.
WrBridge()->RemovePipelineIdForCompositable(mPipelineId.ref());
mPipelineId.reset();
}
if (!mPipelineId) {
// Alloc in process image pipeline id.
mPipelineId =
Some(WrBridge()->GetCompositorBridgeChild()->GetNextPipelineId());
WrBridge()->AddPipelineIdForCompositable(
mPipelineId.ref(), aHandle, CompositableHandleOwner::InProcessManager);
mHandle = aHandle;
}
// Push IFrame for in process image pipeline.
//
// We don't push a stacking context for this in process image pipeline here.
// Instead, we do it inside the iframe that hosts the image. As a result,
// a bunch of the calculations normally done as part of that stacking
// context need to be done manually and pushed over to the parent side,
// where it will be done when we build the display list for the iframe.
// That happens in AsyncImagePipelineManager.
wr::LayoutRect r = wr::ToLayoutRect(aBounds);
aBuilder.PushIFrame(r, aIsBackfaceVisible, mPipelineId.ref(),
/*ignoreMissingPipelines*/ false);
WrBridge()->AddWebRenderParentCommand(OpUpdateAsyncImagePipeline(
mPipelineId.value(), aSCBounds, aRotation, aFilter, aMixBlendMode));
}
WebRenderFallbackData::WebRenderFallbackData(RenderRootStateManager* aManager,
nsDisplayItem* aItem)
: WebRenderUserData(aManager, aItem), mOpacity(1.0f), mInvalid(false) {}

Просмотреть файл

@ -11,6 +11,7 @@
#include "mozilla/webrender/WebRenderAPI.h"
#include "mozilla/image/WebRenderImageProvider.h"
#include "mozilla/layers/AnimationInfo.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/dom/RemoteBrowser.h"
#include "mozilla/UniquePtr.h"
#include "nsIFrame.h"
@ -47,6 +48,7 @@ class WebRenderCanvasRenderer;
class WebRenderCanvasRendererAsync;
class WebRenderImageData;
class WebRenderImageProviderData;
class WebRenderInProcessImageData;
class WebRenderFallbackData;
class WebRenderLocalCanvasData;
class RenderRootStateManager;
@ -82,6 +84,9 @@ class WebRenderUserData {
virtual WebRenderImageData* AsImageData() { return nullptr; }
virtual WebRenderImageProviderData* AsImageProviderData() { return nullptr; }
virtual WebRenderInProcessImageData* AsInProcessImageData() {
return nullptr;
}
virtual WebRenderFallbackData* AsFallbackData() { return nullptr; }
virtual WebRenderCanvasData* AsCanvasData() { return nullptr; }
virtual WebRenderLocalCanvasData* AsLocalCanvasData() { return nullptr; }
@ -98,6 +103,7 @@ class WebRenderUserData {
eGroup,
eMask,
eImageProvider, // ImageLib
eInProcessImage,
};
virtual UserDataType GetType() = 0;
@ -209,6 +215,30 @@ class WebRenderImageProviderData final : public WebRenderUserData {
image::ImgDrawResult mDrawResult;
};
class WebRenderInProcessImageData final : public WebRenderUserData {
public:
WebRenderInProcessImageData(RenderRootStateManager* aManager,
nsDisplayItem* aItem);
WebRenderInProcessImageData(RenderRootStateManager* aManager,
uint32_t aDisplayItemKey, nsIFrame* aFrame);
~WebRenderInProcessImageData() override;
WebRenderInProcessImageData* AsInProcessImageData() override { return this; }
UserDataType GetType() override { return UserDataType::eInProcessImage; }
static UserDataType Type() { return UserDataType::eInProcessImage; }
void CreateWebRenderCommands(
mozilla::wr::DisplayListBuilder& aBuilder,
const CompositableHandle& aHandle, const StackingContextHelper& aSc,
const LayoutDeviceRect& aBounds, const LayoutDeviceRect& aSCBounds,
VideoInfo::Rotation aRotation, const wr::ImageRendering& aFilter,
const wr::MixBlendMode& aMixBlendMode, bool aIsBackfaceVisible);
protected:
Maybe<wr::PipelineId> mPipelineId;
CompositableHandle mHandle = CompositableHandle();
};
/// Used for fallback rendering.
///
/// In most cases this uses blob images but it can also render on the content

Просмотреть файл

@ -1287,7 +1287,7 @@ void gfxPlatform::InitLayersIPC() {
}
#endif
if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS) && UseWebRender()) {
wr::RenderThread::Start();
wr::RenderThread::Start(GPUProcessManager::Get()->AllocateNamespace());
image::ImageMemoryReporter::InitForWebRender();
}
@ -3313,7 +3313,7 @@ void gfxPlatform::DisableGPUProcess() {
if (gfxVars::UseWebRender()) {
// We need to initialize the parent process to prepare for WebRender if we
// did not end up disabling it, despite losing the GPU process.
wr::RenderThread::Start();
wr::RenderThread::Start(GPUProcessManager::Get()->AllocateNamespace());
image::ImageMemoryReporter::InitForWebRender();
}
}

Просмотреть файл

@ -17,6 +17,7 @@
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/gfx/GPUParent.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/layers/CompositableInProcessManager.h"
#include "mozilla/layers/CompositorThread.h"
#include "mozilla/layers/CompositorBridgeParent.h"
#include "mozilla/layers/CompositorManagerParent.h"
@ -85,7 +86,7 @@ RenderThread::~RenderThread() { MOZ_ASSERT(mRenderTexturesDeferred.empty()); }
RenderThread* RenderThread::Get() { return sRenderThread; }
// static
void RenderThread::Start() {
void RenderThread::Start(uint32_t aNamespace) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sRenderThread);
@ -116,6 +117,7 @@ void RenderThread::Start() {
#ifdef XP_WIN
widget::WinCompositorWindowThread::Start();
#endif
layers::CompositableInProcessManager::Initialize(aNamespace);
layers::SharedSurfacesParent::Initialize();
RefPtr<Runnable> runnable = WrapRunnable(
@ -141,6 +143,7 @@ void RenderThread::ShutDown() {
task.Wait();
layers::SharedSurfacesParent::Shutdown();
layers::CompositableInProcessManager::Shutdown();
sRenderThread = nullptr;
#ifdef XP_WIN

Просмотреть файл

@ -138,7 +138,7 @@ class RenderThread final {
static RenderThread* Get();
/// Can only be called from the main thread.
static void Start();
static void Start(uint32_t aNamespace);
/// Can only be called from the main thread.
static void ShutDown();