2017-10-28 02:10:06 +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: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2013-05-03 21:34:29 +04:00
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_TEXTURED3D11_H
|
|
|
|
#define MOZILLA_GFX_TEXTURED3D11_H
|
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-05-03 21:34:29 +04:00
|
|
|
#include "mozilla/layers/Compositor.h"
|
2017-08-07 13:15:24 +03:00
|
|
|
#include "mozilla/layers/SyncObject.h"
|
2013-05-03 21:34:29 +04:00
|
|
|
#include "mozilla/layers/TextureClient.h"
|
2013-07-30 13:59:51 +04:00
|
|
|
#include "mozilla/layers/TextureHost.h"
|
2013-05-09 19:32:50 +04:00
|
|
|
#include "gfxWindowsPlatform.h"
|
2013-07-26 23:28:31 +04:00
|
|
|
#include "mozilla/GfxMessageUtils.h"
|
2013-05-03 21:34:29 +04:00
|
|
|
#include <d3d11.h>
|
2015-09-01 22:33:40 +03:00
|
|
|
#include "d3d9.h"
|
2013-05-03 21:34:29 +04:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace mozilla {
|
2017-07-18 05:17:41 +03:00
|
|
|
namespace gl {
|
|
|
|
class GLBlitHelper;
|
|
|
|
}
|
|
|
|
|
2013-05-03 21:34:29 +04:00
|
|
|
namespace layers {
|
|
|
|
|
2016-11-17 09:57:00 +03:00
|
|
|
class MOZ_RAII AutoTextureLock {
|
2016-11-07 08:48:00 +03:00
|
|
|
public:
|
|
|
|
AutoTextureLock(IDXGIKeyedMutex* aMutex, HRESULT& aResult,
|
|
|
|
uint32_t aTimeout = 0);
|
|
|
|
~AutoTextureLock();
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<IDXGIKeyedMutex> mMutex;
|
|
|
|
HRESULT mResult;
|
|
|
|
};
|
|
|
|
|
2014-01-07 20:19:52 +04:00
|
|
|
class CompositorD3D11;
|
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
class DXGITextureData : public TextureData {
|
2014-01-07 20:19:52 +04:00
|
|
|
public:
|
2016-04-22 19:05:26 +03:00
|
|
|
virtual void FillInfo(TextureData::Info& aInfo) const override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2017-04-12 08:58:47 +03:00
|
|
|
bool SerializeSpecific(SurfaceDescriptorD3D10* aOutDesc);
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual bool Serialize(SurfaceDescriptor& aOutDescrptor) override;
|
2017-04-12 08:58:47 +03:00
|
|
|
virtual void GetSubDescriptor(GPUVideoSubDescriptor* aOutDesc) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
static DXGITextureData* Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
|
|
|
|
TextureAllocationFlags aFlags);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
protected:
|
|
|
|
bool PrepareDrawTargetInLock(OpenMode aMode);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-12-02 22:31:17 +03:00
|
|
|
DXGITextureData(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
|
|
|
|
bool aNeedsClear, bool aNeedsClearWhite,
|
|
|
|
bool aIsForOutOfBandContent);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual void GetDXGIResource(IDXGIResource** aOutResource) = 0;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
// Hold on to the DrawTarget because it is expensive to create one each
|
|
|
|
// ::Lock.
|
|
|
|
RefPtr<gfx::DrawTarget> mDrawTarget;
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
gfx::SurfaceFormat mFormat;
|
|
|
|
bool mNeedsClear;
|
|
|
|
bool mNeedsClearWhite;
|
|
|
|
bool mHasSynchronization;
|
2015-12-02 22:31:17 +03:00
|
|
|
bool mIsForOutOfBandContent;
|
2015-10-15 18:53:37 +03:00
|
|
|
};
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
class D3D11TextureData : public DXGITextureData {
|
|
|
|
public:
|
|
|
|
// If aDevice is null, use one provided by gfxWindowsPlatform.
|
|
|
|
static DXGITextureData* Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
|
|
|
|
TextureAllocationFlags aAllocFlags,
|
|
|
|
ID3D11Device* aDevice = nullptr);
|
2016-08-02 08:55:44 +03:00
|
|
|
static DXGITextureData* Create(gfx::SourceSurface* aSurface,
|
|
|
|
TextureAllocationFlags aAllocFlags,
|
|
|
|
ID3D11Device* aDevice = nullptr);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual bool UpdateFromSurface(gfx::SourceSurface* aSurface) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2016-10-27 11:02:09 +03:00
|
|
|
virtual bool Lock(OpenMode aMode) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual void Unlock() override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override;
|
2015-11-20 18:55:26 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual TextureData* CreateSimilar(
|
2016-09-27 06:22:20 +03:00
|
|
|
LayersIPCChannel* aAllocator, LayersBackend aLayersBackend,
|
2015-10-15 18:53:37 +03:00
|
|
|
TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2017-08-07 13:15:24 +03:00
|
|
|
virtual void SyncWithObject(SyncObjectClient* aSyncObject) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-11-24 21:07:02 +03:00
|
|
|
ID3D11Texture2D* GetD3D11Texture() { return mTexture; }
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
virtual void Deallocate(LayersIPCChannel* aAllocator) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-12-02 22:31:17 +03:00
|
|
|
D3D11TextureData* AsD3D11TextureData() override { return this; }
|
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
~D3D11TextureData();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
protected:
|
2015-10-15 18:53:37 +03:00
|
|
|
D3D11TextureData(ID3D11Texture2D* aTexture, gfx::IntSize aSize,
|
|
|
|
gfx::SurfaceFormat aFormat, bool aNeedsClear,
|
2015-12-02 22:31:17 +03:00
|
|
|
bool aNeedsClearWhite, bool aIsForOutOfBandContent);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual void GetDXGIResource(IDXGIResource** aOutResource) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2016-08-02 08:55:44 +03:00
|
|
|
static DXGITextureData* Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::SourceSurface* aSurface,
|
|
|
|
TextureAllocationFlags aAllocFlags,
|
|
|
|
ID3D11Device* aDevice = nullptr);
|
|
|
|
|
2015-11-24 21:07:02 +03:00
|
|
|
RefPtr<ID3D11Texture2D> mTexture;
|
2015-10-15 18:53:37 +03:00
|
|
|
};
|
2015-11-20 18:55:26 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
already_AddRefed<TextureClient> CreateD3D11extureClientWithDevice(
|
|
|
|
gfx::IntSize aSize, gfx::SurfaceFormat aFormat, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags, ID3D11Device* aDevice,
|
2016-09-27 06:22:20 +03:00
|
|
|
LayersIPCChannel* aAllocator);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
|
|
|
class DXGIYCbCrTextureData : public TextureData {
|
2017-07-18 05:17:41 +03:00
|
|
|
friend class gl::GLBlitHelper;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
public:
|
|
|
|
static DXGIYCbCrTextureData* Create(
|
2017-05-04 00:23:45 +03:00
|
|
|
IDirect3DTexture9* aTextureY, IDirect3DTexture9* aTextureCb,
|
|
|
|
IDirect3DTexture9* aTextureCr, HANDLE aHandleY, HANDLE aHandleCb,
|
2015-04-29 20:34:00 +03:00
|
|
|
HANDLE aHandleCr, const gfx::IntSize& aSize, const gfx::IntSize& aSizeY,
|
2017-11-10 12:15:54 +03:00
|
|
|
const gfx::IntSize& aSizeCbCr, gfx::ColorDepth aColorDepth,
|
|
|
|
YUVColorSpace aYUVColorSpace);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
static DXGIYCbCrTextureData* Create(
|
2017-05-04 00:23:45 +03:00
|
|
|
ID3D11Texture2D* aTextureCb, ID3D11Texture2D* aTextureY,
|
2015-09-01 22:33:40 +03:00
|
|
|
ID3D11Texture2D* aTextureCr, const gfx::IntSize& aSize,
|
2017-11-10 12:15:54 +03:00
|
|
|
const gfx::IntSize& aSizeY, const gfx::IntSize& aSizeCbCr,
|
|
|
|
gfx::ColorDepth aColorDepth, YUVColorSpace aYUVColorSpace);
|
2015-09-01 22:33:40 +03:00
|
|
|
|
2016-10-27 11:02:09 +03:00
|
|
|
virtual bool Lock(OpenMode) override { return true; }
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual void Unlock() override {}
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
virtual void FillInfo(TextureData::Info& aInfo) const override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2017-04-12 08:58:47 +03:00
|
|
|
void SerializeSpecific(SurfaceDescriptorDXGIYCbCr* aOutDesc);
|
2016-04-22 19:05:26 +03:00
|
|
|
virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
|
2017-04-12 08:58:47 +03:00
|
|
|
virtual void GetSubDescriptor(GPUVideoSubDescriptor* aOutDesc) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-12-16 18:41:21 +03:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
virtual void Deallocate(LayersIPCChannel* aAllocator) override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual bool UpdateFromSurface(gfx::SourceSurface*) override { return false; }
|
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
virtual TextureFlags GetTextureFlags() const override {
|
|
|
|
return TextureFlags::DEALLOCATE_MAIN_THREAD;
|
|
|
|
}
|
2015-11-20 18:55:26 +03:00
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
DXGIYCbCrTextureData* AsDXGIYCbCrTextureData() override { return this; }
|
|
|
|
|
|
|
|
gfx::IntSize GetYSize() const { return mSizeY; }
|
|
|
|
|
|
|
|
gfx::IntSize GetCbCrSize() const { return mSizeCbCr; }
|
|
|
|
|
2018-09-25 23:44:55 +03:00
|
|
|
gfx::ColorDepth GetColorDepth() const { return mColorDepth; }
|
2018-09-25 14:18:34 +03:00
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
ID3D11Texture2D* GetD3D11Texture(size_t index) {
|
|
|
|
return mD3D11Textures[index];
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
protected:
|
2017-05-04 00:23:45 +03:00
|
|
|
RefPtr<ID3D11Texture2D> mD3D11Textures[3];
|
|
|
|
RefPtr<IDirect3DTexture9> mD3D9Textures[3];
|
2015-10-15 18:53:37 +03:00
|
|
|
HANDLE mHandles[3];
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
gfx::IntSize mSizeY;
|
|
|
|
gfx::IntSize mSizeCbCr;
|
2018-09-25 23:44:55 +03:00
|
|
|
gfx::ColorDepth mColorDepth;
|
2017-11-10 12:15:54 +03:00
|
|
|
YUVColorSpace mYUVColorSpace;
|
2015-10-15 18:53:37 +03:00
|
|
|
};
|
2015-11-24 21:07:02 +03:00
|
|
|
|
2014-01-07 20:19:52 +04:00
|
|
|
/**
|
|
|
|
* TextureSource that provides with the necessary APIs to be composited by a
|
|
|
|
* CompositorD3D11.
|
|
|
|
*/
|
2013-05-03 21:34:29 +04:00
|
|
|
class TextureSourceD3D11 {
|
|
|
|
public:
|
2015-09-22 16:38:28 +03:00
|
|
|
TextureSourceD3D11() : mFormatOverride(DXGI_FORMAT_UNKNOWN) {}
|
2013-07-23 03:05:04 +04:00
|
|
|
virtual ~TextureSourceD3D11() {}
|
2013-05-03 21:34:29 +04:00
|
|
|
|
2014-01-07 20:19:52 +04:00
|
|
|
virtual ID3D11Texture2D* GetD3D11Texture() const { return mTexture; }
|
2015-05-05 21:35:29 +03:00
|
|
|
virtual ID3D11ShaderResourceView* GetShaderResourceView();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-01-07 20:19:52 +04:00
|
|
|
protected:
|
|
|
|
virtual gfx::IntSize GetSize() const { return mSize; }
|
|
|
|
|
|
|
|
gfx::IntSize mSize;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID3D11Texture2D> mTexture;
|
|
|
|
RefPtr<ID3D11ShaderResourceView> mSRV;
|
2015-09-22 16:38:28 +03:00
|
|
|
DXGI_FORMAT mFormatOverride;
|
2014-01-07 20:19:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A TextureSource that implements the DataTextureSource interface.
|
|
|
|
* it can be used without a TextureHost and is able to upload texture data
|
|
|
|
* from a gfx::DataSourceSurface.
|
|
|
|
*/
|
|
|
|
class DataTextureSourceD3D11 : public DataTextureSource,
|
|
|
|
public TextureSourceD3D11,
|
2014-04-28 15:27:25 +04:00
|
|
|
public BigImageIterator {
|
2014-01-07 20:19:52 +04:00
|
|
|
public:
|
2016-11-14 12:09:31 +03:00
|
|
|
/// Constructor allowing the texture to perform texture uploads.
|
|
|
|
///
|
|
|
|
/// The texture can be used as an actual DataTextureSource.
|
2017-03-22 06:32:53 +03:00
|
|
|
DataTextureSourceD3D11(ID3D11Device* aDevice, gfx::SurfaceFormat aFormat,
|
|
|
|
TextureFlags aFlags);
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2016-11-14 12:09:31 +03:00
|
|
|
/// Constructor for textures created around DXGI shared handles, disallowing
|
|
|
|
/// texture uploads.
|
|
|
|
///
|
|
|
|
/// The texture CANNOT be used as a DataTextureSource.
|
2017-03-22 06:32:53 +03:00
|
|
|
DataTextureSourceD3D11(ID3D11Device* aDevice, gfx::SurfaceFormat aFormat,
|
|
|
|
ID3D11Texture2D* aTexture);
|
|
|
|
|
2017-03-22 06:32:54 +03:00
|
|
|
DataTextureSourceD3D11(gfx::SurfaceFormat aFormat,
|
|
|
|
TextureSourceProvider* aProvider,
|
|
|
|
ID3D11Texture2D* aTexture);
|
|
|
|
DataTextureSourceD3D11(gfx::SurfaceFormat aFormat,
|
|
|
|
TextureSourceProvider* aProvider, TextureFlags aFlags);
|
2013-07-23 03:05:04 +04:00
|
|
|
|
2014-01-07 20:19:52 +04:00
|
|
|
virtual ~DataTextureSourceD3D11();
|
|
|
|
|
2016-02-08 13:57:00 +03:00
|
|
|
virtual const char* Name() const override { return "DataTextureSourceD3D11"; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
|
|
|
// DataTextureSource
|
|
|
|
|
|
|
|
virtual bool Update(gfx::DataSourceSurface* aSurface,
|
|
|
|
nsIntRegion* aDestRegion = nullptr,
|
2015-03-21 19:28:04 +03:00
|
|
|
gfx::IntPoint* aSrcOffset = nullptr) override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
|
|
|
// TextureSource
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual TextureSourceD3D11* AsSourceD3D11() override { return this; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual ID3D11Texture2D* GetD3D11Texture() const override;
|
2014-01-07 20:20:11 +04:00
|
|
|
|
2015-05-05 21:35:29 +03:00
|
|
|
virtual ID3D11ShaderResourceView* GetShaderResourceView() override;
|
|
|
|
|
2016-11-14 12:09:31 +03:00
|
|
|
// Returns nullptr if this texture was created by a DXGI TextureHost.
|
2017-06-22 18:33:39 +03:00
|
|
|
virtual DataTextureSource* AsDataTextureSource() override {
|
|
|
|
return mAllowTextureUploads ? this : nullptr;
|
|
|
|
}
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DeallocateDeviceData() override { mTexture = nullptr; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual gfx::IntSize GetSize() const override { return mSize; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual gfx::SurfaceFormat GetFormat() const override { return mFormat; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2014-04-28 15:27:25 +04:00
|
|
|
// BigImageIterator
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual BigImageIterator* AsBigImageIterator() override {
|
|
|
|
return mIsTiled ? this : nullptr;
|
|
|
|
}
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual size_t GetTileCount() override { return mTileTextures.size(); }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool NextTile() override {
|
|
|
|
return (++mCurrentTile < mTileTextures.size());
|
|
|
|
}
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-05-07 12:07:35 +03:00
|
|
|
virtual gfx::IntRect GetTileRect() override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void EndBigImageIteration() override { mIterating = false; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void BeginBigImageIteration() override {
|
2014-01-07 20:19:52 +04:00
|
|
|
mIterating = true;
|
|
|
|
mCurrentTile = 0;
|
2013-05-03 21:34:29 +04:00
|
|
|
}
|
2013-07-23 03:05:04 +04:00
|
|
|
|
2017-06-20 11:17:18 +03:00
|
|
|
RefPtr<TextureSource> ExtractCurrentTile() override;
|
|
|
|
|
2017-05-31 12:48:12 +03:00
|
|
|
void Reset();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-03 21:34:29 +04:00
|
|
|
protected:
|
2014-01-07 20:19:52 +04:00
|
|
|
gfx::IntRect GetTileRect(uint32_t aIndex) const;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
std::vector<RefPtr<ID3D11Texture2D> > mTileTextures;
|
|
|
|
std::vector<RefPtr<ID3D11ShaderResourceView> > mTileSRVs;
|
2017-03-22 06:32:53 +03:00
|
|
|
RefPtr<ID3D11Device> mDevice;
|
2014-01-07 20:19:52 +04:00
|
|
|
gfx::SurfaceFormat mFormat;
|
|
|
|
TextureFlags mFlags;
|
|
|
|
uint32_t mCurrentTile;
|
|
|
|
bool mIsTiled;
|
|
|
|
bool mIterating;
|
2016-11-14 12:09:31 +03:00
|
|
|
// Sadly, the code was originally organized so that this class is used both in
|
|
|
|
// the cases where we want to perform texture uploads through the
|
|
|
|
// DataTextureSource interface, and the cases where we wrap the texture around
|
|
|
|
// an existing DXGI handle in which case we should not use it as a
|
|
|
|
// DataTextureSource. This member differentiates the two scenarios. When it is
|
|
|
|
// false the texture "pretends" to not be a DataTextureSource.
|
|
|
|
bool mAllowTextureUploads;
|
2014-01-07 20:19:52 +04:00
|
|
|
};
|
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
already_AddRefed<TextureClient> CreateD3D11TextureClientWithDevice(
|
|
|
|
gfx::IntSize aSize, gfx::SurfaceFormat aFormat, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags, ID3D11Device* aDevice,
|
2016-09-27 06:22:20 +03:00
|
|
|
LayersIPCChannel* aAllocator);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2014-01-07 20:19:52 +04:00
|
|
|
/**
|
|
|
|
* A TextureHost for shared D3D11 textures.
|
|
|
|
*/
|
|
|
|
class DXGITextureHostD3D11 : public TextureHost {
|
|
|
|
public:
|
|
|
|
DXGITextureHostD3D11(TextureFlags aFlags,
|
|
|
|
const SurfaceDescriptorD3D10& aDescriptor);
|
|
|
|
|
2015-03-27 13:16:34 +03:00
|
|
|
virtual bool BindTextureSource(
|
|
|
|
CompositableTextureSourceRef& aTexture) override;
|
2017-06-20 11:17:17 +03:00
|
|
|
virtual bool AcquireTextureSource(
|
|
|
|
CompositableTextureSourceRef& aTexture) override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DeallocateDeviceData() override {}
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2017-03-22 06:32:54 +03:00
|
|
|
virtual void SetTextureSourceProvider(
|
|
|
|
TextureSourceProvider* aProvider) override;
|
2016-06-02 12:00:21 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual gfx::SurfaceFormat GetFormat() const override { return mFormat; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Lock() override;
|
|
|
|
virtual void Unlock() override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2016-09-05 08:17:00 +03:00
|
|
|
virtual bool LockWithoutCompositor() override;
|
|
|
|
virtual void UnlockWithoutCompositor() override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual gfx::IntSize GetSize() const override { return mSize; }
|
2013-05-03 21:34:29 +04:00
|
|
|
|
2017-07-06 10:33:19 +03:00
|
|
|
virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2017-08-07 13:15:22 +03:00
|
|
|
virtual void CreateRenderTexture(
|
|
|
|
const wr::ExternalImageId& aExternalImageId) override;
|
|
|
|
|
2017-09-26 16:30:46 +03:00
|
|
|
virtual uint32_t NumSubTextures() const override;
|
2017-06-07 18:44:04 +03:00
|
|
|
|
2018-01-29 16:33:39 +03:00
|
|
|
virtual void PushResourceUpdates(wr::TransactionBuilder& aResources,
|
2017-09-26 16:30:51 +03:00
|
|
|
ResourceUpdateOp aOp,
|
|
|
|
const Range<wr::ImageKey>& aImageKeys,
|
|
|
|
const wr::ExternalImageId& aExtID) override;
|
2017-05-18 17:59:07 +03:00
|
|
|
|
2017-09-26 16:31:00 +03:00
|
|
|
virtual void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
|
|
|
|
const wr::LayoutRect& aBounds,
|
|
|
|
const wr::LayoutRect& aClip,
|
|
|
|
wr::ImageRendering aFilter,
|
|
|
|
const Range<wr::ImageKey>& aImageKeys) override;
|
2017-06-07 18:44:04 +03:00
|
|
|
|
2018-07-25 17:30:08 +03:00
|
|
|
virtual bool SupportsWrNativeTexture() override { return true; }
|
|
|
|
|
2014-01-07 20:19:52 +04:00
|
|
|
protected:
|
2016-09-05 08:17:00 +03:00
|
|
|
bool LockInternal();
|
|
|
|
void UnlockInternal();
|
|
|
|
|
2017-06-20 11:17:17 +03:00
|
|
|
bool EnsureTextureSource();
|
|
|
|
|
2016-03-21 10:14:05 +03:00
|
|
|
RefPtr<ID3D11Device> GetDevice();
|
2014-01-07 20:20:11 +04:00
|
|
|
|
2017-08-17 10:31:09 +03:00
|
|
|
bool EnsureTexture();
|
2014-07-23 22:17:15 +04:00
|
|
|
|
2017-03-28 00:02:50 +03:00
|
|
|
RefPtr<ID3D11Device> mDevice;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID3D11Texture2D> mTexture;
|
|
|
|
RefPtr<DataTextureSourceD3D11> mTextureSource;
|
2013-05-03 21:34:29 +04:00
|
|
|
gfx::IntSize mSize;
|
2014-01-07 20:19:52 +04:00
|
|
|
WindowsHandle mHandle;
|
|
|
|
gfx::SurfaceFormat mFormat;
|
|
|
|
bool mIsLocked;
|
2013-05-03 21:34:29 +04:00
|
|
|
};
|
|
|
|
|
2015-03-19 00:17:13 +03:00
|
|
|
class DXGIYCbCrTextureHostD3D11 : public TextureHost {
|
|
|
|
public:
|
|
|
|
DXGIYCbCrTextureHostD3D11(TextureFlags aFlags,
|
|
|
|
const SurfaceDescriptorDXGIYCbCr& aDescriptor);
|
|
|
|
|
2015-03-27 13:16:34 +03:00
|
|
|
virtual bool BindTextureSource(
|
|
|
|
CompositableTextureSourceRef& aTexture) override;
|
2017-06-20 11:17:17 +03:00
|
|
|
virtual bool AcquireTextureSource(
|
|
|
|
CompositableTextureSourceRef& aTexture) override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DeallocateDeviceData() override {}
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2017-03-22 06:32:54 +03:00
|
|
|
virtual void SetTextureSourceProvider(
|
|
|
|
TextureSourceProvider* aProvider) override;
|
2016-06-02 12:00:21 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual gfx::SurfaceFormat GetFormat() const override {
|
|
|
|
return gfx::SurfaceFormat::YUV;
|
|
|
|
}
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2018-09-25 23:44:55 +03:00
|
|
|
virtual gfx::ColorDepth GetColorDepth() const override { return mColorDepth; }
|
2016-10-25 04:17:39 +03:00
|
|
|
|
2018-09-25 23:44:55 +03:00
|
|
|
virtual YUVColorSpace GetYUVColorSpace() const override {
|
|
|
|
return mYUVColorSpace;
|
|
|
|
}
|
2018-09-25 14:18:34 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Lock() override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Unlock() override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual gfx::IntSize GetSize() const override { return mSize; }
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override {
|
2015-03-19 00:17:13 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-08-07 13:15:22 +03:00
|
|
|
virtual void CreateRenderTexture(
|
|
|
|
const wr::ExternalImageId& aExternalImageId) override;
|
|
|
|
|
2017-09-28 16:43:01 +03:00
|
|
|
virtual uint32_t NumSubTextures() const override;
|
|
|
|
|
2018-01-29 16:33:39 +03:00
|
|
|
virtual void PushResourceUpdates(wr::TransactionBuilder& aResources,
|
2017-09-26 16:30:51 +03:00
|
|
|
ResourceUpdateOp aOp,
|
|
|
|
const Range<wr::ImageKey>& aImageKeys,
|
|
|
|
const wr::ExternalImageId& aExtID) override;
|
2017-05-18 17:59:07 +03:00
|
|
|
|
2017-09-26 16:31:00 +03:00
|
|
|
virtual void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
|
|
|
|
const wr::LayoutRect& aBounds,
|
|
|
|
const wr::LayoutRect& aClip,
|
|
|
|
wr::ImageRendering aFilter,
|
|
|
|
const Range<wr::ImageKey>& aImageKeys) override;
|
2017-06-07 18:44:04 +03:00
|
|
|
|
2018-07-25 17:30:08 +03:00
|
|
|
virtual bool SupportsWrNativeTexture() override { return true; }
|
|
|
|
|
2017-06-20 11:17:17 +03:00
|
|
|
private:
|
|
|
|
bool EnsureTextureSource();
|
|
|
|
|
2015-03-19 00:17:13 +03:00
|
|
|
protected:
|
2016-03-21 10:14:05 +03:00
|
|
|
RefPtr<ID3D11Device> GetDevice();
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2017-08-17 10:31:09 +03:00
|
|
|
bool EnsureTexture();
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID3D11Texture2D> mTextures[3];
|
|
|
|
RefPtr<DataTextureSourceD3D11> mTextureSources[3];
|
2015-03-19 00:17:13 +03:00
|
|
|
|
|
|
|
gfx::IntSize mSize;
|
2017-11-30 15:30:35 +03:00
|
|
|
gfx::IntSize mSizeCbCr;
|
2015-03-19 00:17:13 +03:00
|
|
|
WindowsHandle mHandles[3];
|
|
|
|
bool mIsLocked;
|
2018-09-25 23:44:55 +03:00
|
|
|
gfx::ColorDepth mColorDepth;
|
2017-11-10 12:15:54 +03:00
|
|
|
YUVColorSpace mYUVColorSpace;
|
2015-03-19 00:17:13 +03:00
|
|
|
};
|
|
|
|
|
2013-05-03 21:34:29 +04:00
|
|
|
class CompositingRenderTargetD3D11 : public CompositingRenderTarget,
|
|
|
|
public TextureSourceD3D11 {
|
|
|
|
public:
|
2013-11-07 13:53:08 +04:00
|
|
|
CompositingRenderTargetD3D11(
|
2015-09-22 16:38:28 +03:00
|
|
|
ID3D11Texture2D* aTexture, const gfx::IntPoint& aOrigin,
|
|
|
|
DXGI_FORMAT aFormatOverride = DXGI_FORMAT_UNKNOWN);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-02-08 13:57:00 +03:00
|
|
|
virtual const char* Name() const override {
|
|
|
|
return "CompositingRenderTargetD3D11";
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual TextureSourceD3D11* AsSourceD3D11() override { return this; }
|
2013-05-03 21:34:29 +04:00
|
|
|
|
2014-11-04 01:27:32 +03:00
|
|
|
void BindRenderTarget(ID3D11DeviceContext* aContext);
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual gfx::IntSize GetSize() const override;
|
2013-05-03 21:34:29 +04:00
|
|
|
|
|
|
|
void SetSize(const gfx::IntSize& aSize) { mSize = aSize; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class CompositorD3D11;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID3D11RenderTargetView> mRTView;
|
2013-05-03 21:34:29 +04:00
|
|
|
};
|
|
|
|
|
2017-08-07 13:15:23 +03:00
|
|
|
class SyncObjectD3D11Host : public SyncObjectHost {
|
2014-12-13 04:50:47 +03:00
|
|
|
public:
|
2017-08-07 13:15:23 +03:00
|
|
|
explicit SyncObjectD3D11Host(ID3D11Device* aDevice);
|
2014-12-13 04:50:47 +03:00
|
|
|
|
2017-08-07 13:15:23 +03:00
|
|
|
virtual bool Init() override;
|
|
|
|
|
|
|
|
virtual SyncHandle GetSyncHandle() override;
|
|
|
|
|
2018-10-05 08:49:04 +03:00
|
|
|
virtual bool Synchronize(bool aFallible) override;
|
2017-08-07 13:15:23 +03:00
|
|
|
|
2017-08-07 13:15:24 +03:00
|
|
|
IDXGIKeyedMutex* GetKeyedMutex() { return mKeyedMutex.get(); };
|
|
|
|
|
2017-08-07 13:15:23 +03:00
|
|
|
private:
|
|
|
|
virtual ~SyncObjectD3D11Host() {}
|
|
|
|
|
|
|
|
SyncHandle mSyncHandle;
|
|
|
|
RefPtr<ID3D11Device> mDevice;
|
|
|
|
RefPtr<IDXGIResource> mSyncTexture;
|
|
|
|
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SyncObjectD3D11Client : public SyncObjectClient {
|
|
|
|
public:
|
|
|
|
explicit SyncObjectD3D11Client(SyncHandle aSyncHandle, ID3D11Device* aDevice);
|
|
|
|
|
2017-11-06 11:07:22 +03:00
|
|
|
virtual bool Synchronize(bool aFallible) override;
|
2017-08-07 13:15:23 +03:00
|
|
|
|
|
|
|
virtual bool IsSyncObjectValid() override;
|
|
|
|
|
|
|
|
virtual SyncType GetSyncType() override { return SyncType::D3D11; }
|
2014-12-13 04:50:47 +03:00
|
|
|
|
|
|
|
void RegisterTexture(ID3D11Texture2D* aTexture);
|
|
|
|
|
|
|
|
private:
|
2017-11-06 11:07:22 +03:00
|
|
|
bool Init(bool aFallible);
|
2016-11-30 01:07:27 +03:00
|
|
|
|
|
|
|
SyncHandle mSyncHandle;
|
2017-08-07 13:15:23 +03:00
|
|
|
RefPtr<ID3D11Device> mDevice;
|
|
|
|
RefPtr<ID3D11Texture2D> mSyncTexture;
|
2016-11-30 01:07:27 +03:00
|
|
|
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
2017-08-07 13:15:23 +03:00
|
|
|
std::vector<ID3D11Texture2D*> mSyncedTextures;
|
2017-08-11 07:41:31 +03:00
|
|
|
Mutex mSyncLock;
|
2014-12-13 04:50:47 +03:00
|
|
|
};
|
|
|
|
|
2013-05-03 21:34:29 +04:00
|
|
|
inline uint32_t GetMaxTextureSizeForFeatureLevel(
|
|
|
|
D3D_FEATURE_LEVEL aFeatureLevel) {
|
|
|
|
int32_t maxTextureSize;
|
|
|
|
switch (aFeatureLevel) {
|
|
|
|
case D3D_FEATURE_LEVEL_11_1:
|
|
|
|
case D3D_FEATURE_LEVEL_11_0:
|
|
|
|
maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_10_1:
|
|
|
|
case D3D_FEATURE_LEVEL_10_0:
|
|
|
|
maxTextureSize = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
|
|
|
break;
|
|
|
|
case D3D_FEATURE_LEVEL_9_3:
|
|
|
|
maxTextureSize = D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
maxTextureSize = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
|
|
|
}
|
|
|
|
return maxTextureSize;
|
|
|
|
}
|
|
|
|
|
2017-03-22 06:32:53 +03:00
|
|
|
uint32_t GetMaxTextureSizeFromDevice(ID3D11Device* aDevice);
|
2017-06-24 00:23:12 +03:00
|
|
|
void ReportTextureMemoryUsage(ID3D11Texture2D* aTexture, size_t aBytes);
|
2017-03-22 06:32:53 +03:00
|
|
|
|
2017-05-04 14:54:05 +03:00
|
|
|
class AutoLockD3D11Texture {
|
|
|
|
public:
|
|
|
|
explicit AutoLockD3D11Texture(ID3D11Texture2D* aTexture);
|
|
|
|
~AutoLockD3D11Texture();
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<IDXGIKeyedMutex> mMutex;
|
|
|
|
};
|
|
|
|
|
2017-06-20 21:45:40 +03:00
|
|
|
class D3D11MTAutoEnter {
|
|
|
|
public:
|
|
|
|
explicit D3D11MTAutoEnter(already_AddRefed<ID3D10Multithread> aMT)
|
|
|
|
: mMT(aMT) {
|
2017-09-07 17:39:14 +03:00
|
|
|
if (mMT) {
|
|
|
|
mMT->Enter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~D3D11MTAutoEnter() {
|
|
|
|
if (mMT) {
|
|
|
|
mMT->Leave();
|
|
|
|
}
|
2017-06-20 21:45:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<ID3D10Multithread> mMT;
|
|
|
|
};
|
|
|
|
|
2017-03-22 06:32:53 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
2013-05-03 21:34:29 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_TEXTURED3D11_H */
|