Skip to content

Commit

Permalink
Add MLGPU feature bits and compositor initialization. (bug 1365879 pa…
Browse files Browse the repository at this point in the history
…rt 21, r=mattwoodrow)
  • Loading branch information
David Anderson committed Jun 23, 2017
1 parent 825fe13 commit 5e3ca8b
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 14 deletions.
1 change: 1 addition & 0 deletions gfx/config/gfxFeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace gfx {
_(GPU_PROCESS, Feature, "GPU Process") \
_(WEBRENDER, Feature, "WebRender") \
_(OMTP, Feature, "Off Main Thread Painting") \
_(ADVANCED_LAYERS, Feature, "Advanced Layers") \
/* Add new entries above this comment */

enum class Feature : uint32_t {
Expand Down
8 changes: 8 additions & 0 deletions gfx/ipc/CompositorOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@ class CompositorOptions
CompositorOptions()
: mUseAPZ(false)
, mUseWebRender(false)
, mUseAdvancedLayers(false)
{
}

explicit CompositorOptions(bool aUseAPZ,
bool aUseWebRender)
: mUseAPZ(aUseAPZ)
, mUseWebRender(aUseWebRender)
, mUseAdvancedLayers(false)
{
}

bool UseAPZ() const { return mUseAPZ; }
bool UseWebRender() const { return mUseWebRender; }
bool UseAdvancedLayers() const { return mUseAdvancedLayers; }

void SetUseAdvancedLayers(bool aUseAdvancedLayers) {
mUseAdvancedLayers = aUseAdvancedLayers;
}

bool operator==(const CompositorOptions& aOther) const {
return mUseAPZ == aOther.mUseAPZ &&
Expand All @@ -55,6 +62,7 @@ class CompositorOptions
private:
bool mUseAPZ;
bool mUseWebRender;
bool mUseAdvancedLayers;

// Make sure to add new fields to the ParamTraits implementation
};
Expand Down
8 changes: 8 additions & 0 deletions gfx/ipc/GPUChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ GPUChild::Init()
devicePrefs.hwCompositing() = gfxConfig::GetValue(Feature::HW_COMPOSITING);
devicePrefs.d3d11Compositing() = gfxConfig::GetValue(Feature::D3D11_COMPOSITING);
devicePrefs.oglCompositing() = gfxConfig::GetValue(Feature::OPENGL_COMPOSITING);
devicePrefs.advancedLayers() = gfxConfig::GetValue(Feature::ADVANCED_LAYERS);
devicePrefs.useD2D1() = gfxConfig::GetValue(Feature::DIRECT2D);

nsTArray<LayerTreeIdMapping> mappings;
Expand Down Expand Up @@ -272,6 +273,13 @@ GPUChild::ActorDestroy(ActorDestroyReason aWhy)
mHost->OnChannelClosed();
}

mozilla::ipc::IPCResult
GPUChild::RecvUpdateFeature(const Feature& aFeature, const FeatureFailure& aChange)
{
gfxConfig::SetFailed(aFeature, aChange.status(), aChange.message().get(), aChange.failureId());
return IPC_OK();
}

class DeferredDeleteGPUChild : public Runnable
{
public:
Expand Down
1 change: 1 addition & 0 deletions gfx/ipc/GPUChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class GPUChild final
mozilla::ipc::IPCResult RecvNotifyDeviceReset(const GPUDeviceData& aData) override;
mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport) override;
mozilla::ipc::IPCResult RecvFinishMemoryReport(const uint32_t& aGeneration) override;
mozilla::ipc::IPCResult RecvUpdateFeature(const Feature& aFeature, const FeatureFailure& aChange) override;

bool SendRequestMemoryReport(const uint32_t& aGeneration,
const bool& aAnonymize,
Expand Down
2 changes: 2 additions & 0 deletions gfx/ipc/GPUParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ GPUParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs,
gfxConfig::Inherit(Feature::HW_COMPOSITING, devicePrefs.hwCompositing());
gfxConfig::Inherit(Feature::D3D11_COMPOSITING, devicePrefs.d3d11Compositing());
gfxConfig::Inherit(Feature::OPENGL_COMPOSITING, devicePrefs.oglCompositing());
gfxConfig::Inherit(Feature::ADVANCED_LAYERS, devicePrefs.advancedLayers());
gfxConfig::Inherit(Feature::DIRECT2D, devicePrefs.useD2D1());

for (const LayerTreeIdMapping& map : aMappings) {
Expand Down Expand Up @@ -300,6 +301,7 @@ GPUParent::RecvGetDeviceStatus(GPUDeviceData* aOut)
{
CopyFeatureChange(Feature::D3D11_COMPOSITING, &aOut->d3d11Compositing());
CopyFeatureChange(Feature::OPENGL_COMPOSITING, &aOut->oglCompositing());
CopyFeatureChange(Feature::ADVANCED_LAYERS, &aOut->advancedLayers());

#if defined(XP_WIN)
if (DeviceManagerDx* dm = DeviceManagerDx::Get()) {
Expand Down
10 changes: 10 additions & 0 deletions gfx/ipc/GfxMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "RegionBuilder.h"
#include "base/process_util.h"
#include "chrome/common/ipc_message_utils.h"
#include "gfxFeature.h"
#include "gfxPoint.h"
#include "gfxRect.h"
#include "gfxTelemetry.h"
Expand Down Expand Up @@ -219,6 +220,14 @@ struct ParamTraits<mozilla::gfx::BackendType>
mozilla::gfx::BackendType::BACKEND_LAST>
{};

template <>
struct ParamTraits<mozilla::gfx::Feature>
: public ContiguousEnumSerializer<
mozilla::gfx::Feature,
mozilla::gfx::Feature::HW_COMPOSITING,
mozilla::gfx::Feature::NumValues>
{};

template <>
struct ParamTraits<mozilla::gfx::FeatureStatus>
: public ContiguousEnumSerializer<
Expand Down Expand Up @@ -904,6 +913,7 @@ struct ParamTraits<mozilla::Array<T, Length>>
}
};


} /* namespace IPC */

#endif /* __GFXMESSAGEUTILS_H__ */
2 changes: 2 additions & 0 deletions gfx/ipc/GraphicsMessages.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct DevicePrefs
FeatureStatus hwCompositing;
FeatureStatus d3d11Compositing;
FeatureStatus oglCompositing;
FeatureStatus advancedLayers;
FeatureStatus useD2D1;
};

Expand Down Expand Up @@ -63,6 +64,7 @@ struct GPUDeviceData
{
FeatureChange d3d11Compositing;
FeatureChange oglCompositing;
FeatureChange advancedLayers;
GPUDeviceStatus gpuDevice;
};

Expand Down
5 changes: 5 additions & 0 deletions gfx/ipc/PGPU.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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::Telemetry::DiscardedData from "mozilla/TelemetryComms.h";
using mozilla::gfx::Feature from "gfxFeature.h";

namespace mozilla {
namespace gfx {
Expand Down Expand Up @@ -115,6 +116,10 @@ child:

async AddMemoryReport(MemoryReport aReport);
async FinishMemoryReport(uint32_t aGeneration);

// Update the UI process after a feature's status has changed. This is used
// outside of the normal startup flow.
async UpdateFeature(Feature aFeature, FeatureFailure aChange);
};

} // namespace gfx
Expand Down
5 changes: 3 additions & 2 deletions gfx/layers/d3d11/MLGDeviceD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ MLGTextureD3D11::GetShaderResourceView()
}

MLGDeviceD3D11::MLGDeviceD3D11(ID3D11Device* aDevice)
: mDevice(aDevice)
, mScissored(false)
: mDevice(aDevice),
mScissored(false)
{
}

Expand Down Expand Up @@ -958,6 +958,7 @@ MLGDeviceD3D11::Initialize()
}

mCtx->RSSetState(mRasterizerStateNoScissor);

return MLGDevice::Initialize();
}

Expand Down
39 changes: 34 additions & 5 deletions gfx/layers/ipc/CompositorBridgeParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "mozilla/layers/FrameUniformityData.h"
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/LayerManagerMLGPU.h"
#include "mozilla/layers/LayerTreeOwnerTracker.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layers/PLayerTransactionParent.h"
Expand Down Expand Up @@ -93,6 +94,9 @@
#ifdef MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING
# include "mozilla/widget/CompositorWidgetParent.h"
#endif
#ifdef XP_WIN
# include "mozilla/gfx/DeviceManagerDx.h"
#endif

#include "LayerScope.h"

Expand Down Expand Up @@ -1371,18 +1375,43 @@ CompositorBridgeParent::InitializeLayerManager(const nsTArray<LayersBackend>& aB
NS_ASSERTION(!mLayerManager, "Already initialised mLayerManager");
NS_ASSERTION(!mCompositor, "Already initialised mCompositor");

mCompositor = NewCompositor(aBackendHints);
if (!mCompositor) {
return;
if (!InitializeAdvancedLayers(aBackendHints, nullptr)) {
mCompositor = NewCompositor(aBackendHints);
if (!mCompositor) {
return;
}
mLayerManager = new LayerManagerComposite(mCompositor);
}

mLayerManager = new LayerManagerComposite(mCompositor);
mLayerManager->SetCompositorBridgeID(mCompositorBridgeID);

MonitorAutoLock lock(*sIndirectLayerTreesLock);
sIndirectLayerTrees[mRootLayerTreeID].mLayerManager = mLayerManager;
}

bool
CompositorBridgeParent::InitializeAdvancedLayers(const nsTArray<LayersBackend>& aBackendHints,
TextureFactoryIdentifier* aOutIdentifier)
{
#ifdef XP_WIN
if (!mOptions.UseAdvancedLayers()) {
return false;
}

RefPtr<LayerManagerMLGPU> manager = new LayerManagerMLGPU(mWidget);
if (!manager->Initialize()) {
return false;
}

if (aOutIdentifier) {
*aOutIdentifier = manager->GetTextureFactoryIdentifier();
}
mLayerManager = manager;
return true;
#else
return false;
#endif
}

RefPtr<Compositor>
CompositorBridgeParent::NewCompositor(const nsTArray<LayersBackend>& aBackendHints)
{
Expand Down
2 changes: 2 additions & 0 deletions gfx/layers/ipc/CompositorBridgeParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ class CompositorBridgeParent final : public CompositorBridgeParentBase
void FinishPendingComposite() override;
void CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect = nullptr) override;

bool InitializeAdvancedLayers(const nsTArray<LayersBackend>& aBackendHints,
TextureFactoryIdentifier* aOutIdentifier);
RefPtr<Compositor> NewCompositor(const nsTArray<LayersBackend>& aBackendHints);

/**
Expand Down
4 changes: 3 additions & 1 deletion gfx/layers/ipc/LayersMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,13 @@ struct ParamTraits<mozilla::layers::CompositorOptions>
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.mUseAPZ);
WriteParam(aMsg, aParam.mUseWebRender);
WriteParam(aMsg, aParam.mUseAdvancedLayers);
}

static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->mUseAPZ)
&& ReadParam(aMsg, aIter, &aResult->mUseWebRender);
&& ReadParam(aMsg, aIter, &aResult->mUseWebRender)
&& ReadParam(aMsg, aIter, &aResult->mUseAdvancedLayers);
}
};

Expand Down
5 changes: 4 additions & 1 deletion gfx/layers/mlgpu/LayerManagerMLGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ LayerManagerMLGPU::LayerManagerMLGPU(widget::CompositorWidget* aWidget)
return;
}

if (!mDevice) {
#ifdef WIN32
mDevice = DeviceManagerDx::Get()->GetMLGDevice();
#endif
if (!mDevice || !mDevice->IsValid()) {
gfxWarning() << "Could not acquire an MLGDevice!";
return;
}
Expand Down
1 change: 0 additions & 1 deletion gfx/layers/mlgpu/MLGDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ class MLGDevice

virtual bool Initialize();

// If Initialize returns false, these may return more useful messages.
virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() const = 0;
virtual int32_t GetMaxTextureSize() const = 0;
virtual LayersBackend GetLayersBackend() const = 0;
Expand Down
Loading

0 comments on commit 5e3ca8b

Please sign in to comment.