Bug 1444449 - Implement CompositorD3D11::GetWindowRenderTarget API r=mstange,bas

Differential Revision: https://phabricator.services.mozilla.com/D18145

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Barret Rennie 2019-02-19 14:54:12 +00:00
Родитель 714fecebd4
Коммит d31c311fda
2 изменённых файлов: 58 добавлений и 0 удалений

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

@ -50,6 +50,7 @@ const FLOAT sBlendFactor[] = {0, 0, 0, 0};
CompositorD3D11::CompositorD3D11(CompositorBridgeParent* aParent,
widget::CompositorWidget* aWidget)
: Compositor(aWidget, aParent),
mWindowRTCopy(nullptr),
mAttachments(nullptr),
mHwnd(nullptr),
mDisableSequenceForNextFrame(false),
@ -397,6 +398,55 @@ CompositorD3D11::CreateRenderTargetFromSource(
return rt.forget();
}
already_AddRefed<CompositingRenderTarget>
CompositorD3D11::GetWindowRenderTarget() const {
#ifndef MOZ_GECKO_PROFILER
return nullptr;
#else
if (!profiler_feature_active(ProfilerFeature::Screenshots)) {
return nullptr;
}
if (!mDefaultRT) {
return nullptr;
}
const IntSize size = mDefaultRT->GetSize();
RefPtr<ID3D11Texture2D> rtTexture;
if (!mWindowRTCopy || mWindowRTCopy->GetSize() != size) {
/*
* The compositor screenshots infrastructure is going to scale down the
* render target returned by this method. However, mDefaultRT does not
* contain a texture created wth the D3D11_BIND_SHADER_RESOURCE flag, so if
* we were to simply return mDefaultRT then scaling would fail.
*/
CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, size.width,
size.height, 1, 1, D3D11_BIND_SHADER_RESOURCE);
HRESULT hr =
mDevice->CreateTexture2D(&desc, nullptr, getter_AddRefs(rtTexture));
if (FAILED(hr)) {
return nullptr;
}
mWindowRTCopy = MakeRefPtr<CompositingRenderTargetD3D11>(
rtTexture, IntPoint(0, 0), DXGI_FORMAT_B8G8R8A8_UNORM);
mWindowRTCopy->SetSize(size);
} else {
rtTexture = mWindowRTCopy->GetD3D11Texture();
}
const RefPtr<ID3D11Texture2D> sourceTexture = mDefaultRT->GetD3D11Texture();
mContext->CopyResource(rtTexture, sourceTexture);
return RefPtr<CompositingRenderTarget>(
static_cast<CompositingRenderTarget*>(mWindowRTCopy))
.forget();
#endif
}
bool CompositorD3D11::CopyBackdrop(const gfx::IntRect& aRect,
RefPtr<ID3D11Texture2D>* aOutTexture,
RefPtr<ID3D11ShaderResourceView>* aOutView) {
@ -1050,6 +1100,10 @@ void CompositorD3D11::BeginFrame(const nsIntRegion& aInvalidRegion,
void CompositorD3D11::NormalDrawingDone() { mDiagnostics->End(); }
void CompositorD3D11::EndFrame() {
if (!profiler_feature_active(ProfilerFeature::Screenshots) && mWindowRTCopy) {
mWindowRTCopy = nullptr;
}
if (!mDefaultRT) {
Compositor::EndFrame();
return;
@ -1281,6 +1335,7 @@ bool CompositorD3D11::VerifyBufferSize() {
if (mCurrentRT == mDefaultRT) {
mCurrentRT = nullptr;
}
MOZ_ASSERT(mDefaultRT->hasOneRef());
mDefaultRT = nullptr;

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

@ -58,6 +58,8 @@ class CompositorD3D11 : public Compositor {
const override {
return do_AddRef(mCurrentRT);
}
virtual already_AddRefed<CompositingRenderTarget> GetWindowRenderTarget()
const override;
virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) override {}
@ -206,6 +208,7 @@ class CompositorD3D11 : public Compositor {
RefPtr<IDXGISwapChain> mSwapChain;
RefPtr<CompositingRenderTargetD3D11> mDefaultRT;
RefPtr<CompositingRenderTargetD3D11> mCurrentRT;
mutable RefPtr<CompositingRenderTargetD3D11> mWindowRTCopy;
RefPtr<ID3D11Query> mQuery;