Bug 1358014 - Allocate PipelineId with IPC MozPromise r=nical

This commit is contained in:
sotaro 2017-04-26 19:18:06 -07:00
Родитель 76b7d0e370
Коммит e00af8354a
7 изменённых файлов: 79 добавлений и 0 удалений

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

@ -5280,6 +5280,18 @@ ContentParent::RecvClassifyLocal(const URIParams& aURI, const nsCString& aTables
return IPC_OK();
}
mozilla::ipc::IPCResult
ContentParent::RecvAllocPipelineId(RefPtr<AllocPipelineIdPromise>&& aPromise)
{
GPUProcessManager* pm = GPUProcessManager::Get();
if (!pm) {
aPromise->Reject(PromiseRejectReason::HandlerRejected, __func__);
return IPC_OK();
}
aPromise->Resolve(wr::AsPipelineId(pm->AllocateLayerTreeId()), __func__);
return IPC_OK();
}
mozilla::ipc::IPCResult
ContentParent::RecvFileCreationRequest(const nsID& aID,
const nsString& aFullPath,

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

@ -656,6 +656,9 @@ public:
nsresult* aRv,
nsTArray<nsCString>* aResults) override;
virtual mozilla::ipc::IPCResult
RecvAllocPipelineId(RefPtr<AllocPipelineIdPromise>&& aPromise) override;
// Use the PHangMonitor channel to ask the child to repaint a tab.
void ForceTabPaint(TabParent* aTabParent, uint64_t aLayerObserverEpoch);

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

@ -63,6 +63,7 @@ include MemoryReportTypes;
// are put into different UnifiedProtocolsXX.cpp files.
// XXX Remove this once bug 1069073 is fixed
include "mozilla/dom/PContentBridgeParent.h";
include "mozilla/layers/WebRenderMessageUtils.h";
using GeoPosition from "nsGeoPositionIPCSerialiser.h";
using AlertNotificationType from "mozilla/AlertNotificationIPCSerializer.h";
@ -95,6 +96,7 @@ using mozilla::Telemetry::KeyedAccumulation from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::ScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::KeyedScalarAction from "mozilla/TelemetryComms.h";
using mozilla::Telemetry::ChildEventData from "mozilla/TelemetryComms.h";
using mozilla::wr::PipelineId from "mozilla/webrender/WebRenderTypes.h";
union ChromeRegistryItem
{
@ -1108,6 +1110,8 @@ parent:
async AddMemoryReport(MemoryReport aReport);
async FinishMemoryReport(uint32_t aGeneration);
async AllocPipelineId() returns (PipelineId pipelineId);
both:
async AsyncMessage(nsString aMessage, CpowEntry[] aCpows,
Principal aPrincipal, ClonedMessageData aData);

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

@ -28,6 +28,7 @@ WebRenderImageLayer::WebRenderImageLayer(WebRenderLayerManager* aLayerManager)
WebRenderImageLayer::~WebRenderImageLayer()
{
MOZ_COUNT_DTOR(WebRenderImageLayer);
mPipelineIdRequest.DisconnectIfExists();
if (mKey.isSome()) {
WrManager()->AddImageKeyForDiscard(mKey.value());
}
@ -95,6 +96,24 @@ WebRenderImageLayer::RenderLayer(wr::DisplayListBuilder& aBuilder)
MOZ_ASSERT(GetImageClientType() != CompositableType::UNKNOWN);
// Allocate PipelineId if necessary
if (GetImageClientType() == CompositableType::IMAGE_BRIDGE &&
mPipelineId.isNothing() && !mPipelineIdRequest.Exists()) {
// Use Holder to pass this pointer to lambda.
// Static anaysis tool does not permit to pass refcounted variable to lambda.
// And we do not want to use RefPtr<WebRenderImageLayer> here.
Holder holder(this);
Manager()->AllocPipelineId()
->Then(AbstractThread::GetCurrent(), __func__,
[holder] (const wr::PipelineId& aPipelineId) {
holder->mPipelineIdRequest.Complete();
holder->mPipelineId = Some(aPipelineId);
},
[holder] (const ipc::PromiseRejectReason &aReason) {
holder->mPipelineIdRequest.Complete();
})->Track(mPipelineIdRequest);
}
if (GetImageClientType() == CompositableType::IMAGE && !mImageClient) {
mImageClient = ImageClient::CreateImageClient(CompositableType::IMAGE,
WrBridge(),

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

@ -22,6 +22,7 @@ public:
virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
virtual void ClearCachedResources() override;
protected:
virtual ~WebRenderImageLayer();
@ -38,10 +39,22 @@ public:
protected:
CompositableType GetImageClientType();
class Holder {
public:
explicit Holder(WebRenderImageLayer* aLayer)
: mLayer(aLayer)
{}
WebRenderImageLayer* operator ->() const { return mLayer; }
private:
WebRenderImageLayer* mLayer;
};
wr::MaybeExternalImageId mExternalImageId;
Maybe<wr::ImageKey> mKey;
RefPtr<ImageClient> mImageClient;
CompositableType mImageClientTypeContainer;
Maybe<wr::PipelineId> mPipelineId;
MozPromiseRequestHolder<PipelineIdPromise> mPipelineIdRequest;
};
} // namespace layers

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

@ -8,7 +8,9 @@
#include "apz/src/AsyncPanZoomController.h"
#include "gfxPrefs.h"
#include "LayersLogging.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/layers/APZCTreeManager.h"
#include "mozilla/layers/AsyncCompositionManager.h"
#include "mozilla/layers/CompositorBridgeChild.h"
@ -683,6 +685,25 @@ WebRenderLayerManager::Composite()
WrBridge()->SendForceComposite();
}
RefPtr<PipelineIdPromise>
WebRenderLayerManager::AllocPipelineId()
{
if (XRE_IsParentProcess()) {
GPUProcessManager* pm = GPUProcessManager::Get();
if (!pm) {
return PipelineIdPromise::CreateAndReject(ipc::PromiseRejectReason::HandlerRejected, __func__);
}
return PipelineIdPromise::CreateAndResolve(wr::AsPipelineId(pm->AllocateLayerTreeId()), __func__);;
}
MOZ_ASSERT(XRE_IsContentProcess());
RefPtr<dom::ContentChild> contentChild = dom::ContentChild::GetSingleton();
if (!contentChild) {
return PipelineIdPromise::CreateAndReject(ipc::PromiseRejectReason::HandlerRejected, __func__);
}
return contentChild->SendAllocPipelineId();
}
void
WebRenderLayerManager::SetRoot(Layer* aLayer)
{

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

@ -7,8 +7,10 @@
#define GFX_WEBRENDERLAYERMANAGER_H
#include "Layers.h"
#include "mozilla/ipc/MessageChannel.h"
#include "mozilla/layers/CompositorController.h"
#include "mozilla/layers/TransactionIdAllocator.h"
#include "mozilla/MozPromise.h"
#include "mozilla/webrender/webrender_ffi.h"
#include "mozilla/webrender/WebRenderTypes.h"
#include "mozilla/webrender/WebRenderAPI.h"
@ -26,6 +28,9 @@ class WebRenderBridgeChild;
class WebRenderLayerManager;
class APZCTreeManager;
typedef MozPromise<mozilla::wr::PipelineId, mozilla::ipc::PromiseRejectReason, false> PipelineIdPromise;
class WebRenderLayer
{
public:
@ -171,6 +176,8 @@ public:
void SetTransactionIncomplete() { mTransactionIncomplete = true; }
bool IsMutatedLayer(Layer* aLayer);
RefPtr<PipelineIdPromise> AllocPipelineId();
private:
/**
* Take a snapshot of the parent context, and copy