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
|
|
|
|
|
2019-04-11 15:38:49 +03:00
|
|
|
#include <d3d11.h>
|
|
|
|
#include <vector>
|
|
|
|
#include "d3d9.h"
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#include "mozilla/GfxMessageUtils.h"
|
|
|
|
#include "mozilla/Maybe.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-03 21:34:29 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2017-07-18 05:17:41 +03:00
|
|
|
namespace gl {
|
|
|
|
class GLBlitHelper;
|
|
|
|
}
|
|
|
|
|
2013-05-03 21:34:29 +04:00
|
|
|
namespace layers {
|
|
|
|
|
2019-02-18 10:05:15 +03:00
|
|
|
already_AddRefed<TextureHost> CreateTextureHostD3D11(
|
|
|
|
const SurfaceDescriptor& aDesc, ISurfaceAllocator* aDeallocator,
|
|
|
|
LayersBackend aBackend, TextureFlags aFlags);
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
class MOZ_RAII AutoTextureLock final {
|
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;
|
|
|
|
|
2019-04-11 15:39:08 +03:00
|
|
|
class D3D11TextureData final : public TextureData {
|
2015-10-15 18:53:37 +03:00
|
|
|
public:
|
|
|
|
// If aDevice is null, use one provided by gfxWindowsPlatform.
|
2019-04-11 15:39:08 +03:00
|
|
|
static D3D11TextureData* Create(gfx::IntSize aSize,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
TextureAllocationFlags aAllocFlags,
|
|
|
|
ID3D11Device* aDevice = nullptr);
|
2019-04-11 15:38:59 +03:00
|
|
|
static D3D11TextureData* Create(gfx::SourceSurface* aSurface,
|
2019-04-11 15:39:08 +03:00
|
|
|
TextureAllocationFlags aAllocFlags,
|
|
|
|
ID3D11Device* aDevice = nullptr);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-11-21 00:55:06 +03:00
|
|
|
virtual ~D3D11TextureData();
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool UpdateFromSurface(gfx::SourceSurface* aSurface) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Lock(OpenMode aMode) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void Unlock() override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override;
|
2015-11-20 18:55:26 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
TextureData* CreateSimilar(LayersIPCChannel* aAllocator,
|
|
|
|
LayersBackend aLayersBackend, TextureFlags aFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags) const override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void SyncWithObject(SyncObjectClient* aSyncObject) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:39:08 +03:00
|
|
|
ID3D11Texture2D* GetD3D11Texture() const { return mTexture; }
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
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; }
|
|
|
|
|
2019-04-11 15:38:49 +03:00
|
|
|
TextureAllocationFlags GetTextureAllocationFlags() const {
|
|
|
|
return mAllocationFlags;
|
|
|
|
}
|
|
|
|
|
2019-04-11 15:39:08 +03:00
|
|
|
void FillInfo(TextureData::Info& aInfo) const override;
|
|
|
|
|
|
|
|
bool Serialize(SurfaceDescriptor& aOutDescrptor) override;
|
2019-11-21 00:55:06 +03:00
|
|
|
void GetSubDescriptor(RemoteDecoderVideoSubDescriptor* aOutDesc) override;
|
2019-04-11 15:39:08 +03:00
|
|
|
|
|
|
|
gfx::YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
|
|
|
|
void SetYUVColorSpace(gfx::YUVColorSpace aColorSpace) {
|
|
|
|
mYUVColorSpace = aColorSpace;
|
|
|
|
}
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::ColorRange GetColorRange() const { return mColorRange; }
|
|
|
|
void SetColorRange(gfx::ColorRange aColorRange) { mColorRange = aColorRange; }
|
2019-04-11 15:39:08 +03:00
|
|
|
|
|
|
|
gfx::IntSize GetSize() const { return mSize; }
|
|
|
|
gfx::SurfaceFormat GetSurfaceFormat() const { return mFormat; }
|
|
|
|
|
2019-06-06 01:50:50 +03:00
|
|
|
TextureFlags GetTextureFlags() const override;
|
|
|
|
|
2019-04-11 15:39:08 +03:00
|
|
|
private:
|
2015-10-15 18:53:37 +03:00
|
|
|
D3D11TextureData(ID3D11Texture2D* aTexture, gfx::IntSize aSize,
|
2019-04-11 15:38:49 +03:00
|
|
|
gfx::SurfaceFormat aFormat, TextureAllocationFlags aFlags);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:39:08 +03:00
|
|
|
void GetDXGIResource(IDXGIResource** aOutResource);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:39:08 +03:00
|
|
|
bool PrepareDrawTargetInLock(OpenMode aMode);
|
|
|
|
|
2019-04-10 23:54:57 +03:00
|
|
|
friend class gl::GLBlitHelper;
|
2019-04-11 15:39:08 +03:00
|
|
|
bool SerializeSpecific(SurfaceDescriptorD3D10* aOutDesc);
|
|
|
|
|
|
|
|
static D3D11TextureData* Create(gfx::IntSize aSize,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::SourceSurface* aSurface,
|
|
|
|
TextureAllocationFlags aAllocFlags,
|
|
|
|
ID3D11Device* aDevice = nullptr);
|
|
|
|
|
|
|
|
// Hold on to the DrawTarget because it is expensive to create one each
|
|
|
|
// ::Lock.
|
|
|
|
RefPtr<gfx::DrawTarget> mDrawTarget;
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
gfx::SurfaceFormat mFormat;
|
|
|
|
gfx::YUVColorSpace mYUVColorSpace = gfx::YUVColorSpace::UNKNOWN;
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::ColorRange mColorRange = gfx::ColorRange::LIMITED;
|
2019-04-11 15:39:08 +03:00
|
|
|
bool mNeedsClear;
|
|
|
|
bool mNeedsClearWhite;
|
|
|
|
bool mHasSynchronization;
|
|
|
|
bool mIsForOutOfBandContent;
|
2016-08-02 08:55:44 +03:00
|
|
|
|
2015-11-24 21:07:02 +03:00
|
|
|
RefPtr<ID3D11Texture2D> mTexture;
|
2019-04-11 15:38:49 +03:00
|
|
|
const TextureAllocationFlags mAllocationFlags;
|
2015-10-15 18:53:37 +03:00
|
|
|
};
|
2015-11-20 18:55:26 +03:00
|
|
|
|
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,
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::YUVColorSpace aYUVColorSpace, gfx::ColorRange aColorRange);
|
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,
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::ColorDepth aColorDepth, gfx::YUVColorSpace aYUVColorSpace,
|
|
|
|
gfx::ColorRange aColorRange);
|
2015-09-01 22:33:40 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Lock(OpenMode) override { return true; }
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void Unlock() override {}
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
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);
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
|
2019-11-21 00:55:06 +03:00
|
|
|
void GetSubDescriptor(RemoteDecoderVideoSubDescriptor* aOutDesc) override;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override {
|
2015-12-16 18:41:21 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void Deallocate(LayersIPCChannel* aAllocator) override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool UpdateFromSurface(gfx::SourceSurface*) override { return false; }
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2019-06-06 01:50:50 +03:00
|
|
|
TextureFlags GetTextureFlags() const override;
|
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; }
|
2019-04-11 15:41:33 +03:00
|
|
|
gfx::YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::ColorRange GetColorRange() const { return mColorRange; }
|
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;
|
2019-04-11 15:41:33 +03:00
|
|
|
gfx::YUVColorSpace mYUVColorSpace;
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::ColorRange mColorRange;
|
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) {}
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~TextureSourceD3D11() = default;
|
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();
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
const char* Name() const override { return "DataTextureSourceD3D11"; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
|
|
|
// DataTextureSource
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Update(gfx::DataSourceSurface* aSurface,
|
|
|
|
nsIntRegion* aDestRegion = nullptr,
|
|
|
|
gfx::IntPoint* aSrcOffset = nullptr) override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
|
|
|
// TextureSource
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
TextureSourceD3D11* AsSourceD3D11() override { return this; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
ID3D11Texture2D* GetD3D11Texture() const override;
|
2014-01-07 20:20:11 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
ID3D11ShaderResourceView* GetShaderResourceView() override;
|
2015-05-05 21:35:29 +03:00
|
|
|
|
2016-11-14 12:09:31 +03:00
|
|
|
// Returns nullptr if this texture was created by a DXGI TextureHost.
|
2019-04-11 15:36:51 +03:00
|
|
|
DataTextureSource* AsDataTextureSource() override {
|
2017-06-22 18:33:39 +03:00
|
|
|
return mAllowTextureUploads ? this : nullptr;
|
|
|
|
}
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void DeallocateDeviceData() override { mTexture = nullptr; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
gfx::IntSize GetSize() const override { return mSize; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
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
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
BigImageIterator* AsBigImageIterator() override {
|
2015-03-21 19:28:04 +03:00
|
|
|
return mIsTiled ? this : nullptr;
|
|
|
|
}
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
size_t GetTileCount() override { return mTileTextures.size(); }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool NextTile() override { return (++mCurrentTile < mTileTextures.size()); }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
gfx::IntRect GetTileRect() override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void EndBigImageIteration() override { mIterating = false; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A TextureHost for shared D3D11 textures.
|
|
|
|
*/
|
|
|
|
class DXGITextureHostD3D11 : public TextureHost {
|
|
|
|
public:
|
|
|
|
DXGITextureHostD3D11(TextureFlags aFlags,
|
|
|
|
const SurfaceDescriptorD3D10& aDescriptor);
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool BindTextureSource(CompositableTextureSourceRef& aTexture) override;
|
|
|
|
bool AcquireTextureSource(CompositableTextureSourceRef& aTexture) override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void DeallocateDeviceData() override {}
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
|
2016-06-02 12:00:21 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
gfx::SurfaceFormat GetFormat() const override { return mFormat; }
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Lock() override;
|
|
|
|
void Unlock() override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool LockWithoutCompositor() override;
|
|
|
|
void UnlockWithoutCompositor() override;
|
2016-09-05 08:17:00 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
gfx::IntSize GetSize() const override { return mSize; }
|
2019-04-11 15:38:49 +03:00
|
|
|
gfx::YUVColorSpace GetYUVColorSpace() const override {
|
|
|
|
return mYUVColorSpace;
|
|
|
|
}
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::ColorRange GetColorRange() const override { return mColorRange; }
|
2013-05-03 21:34:29 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
|
2014-01-07 20:19:52 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void CreateRenderTexture(
|
2017-08-07 13:15:22 +03:00
|
|
|
const wr::ExternalImageId& aExternalImageId) override;
|
|
|
|
|
2019-07-24 16:33:57 +03:00
|
|
|
uint32_t NumSubTextures() override;
|
2017-06-07 18:44:04 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void PushResourceUpdates(wr::TransactionBuilder& aResources,
|
|
|
|
ResourceUpdateOp aOp,
|
|
|
|
const Range<wr::ImageKey>& aImageKeys,
|
2020-03-10 06:52:08 +03:00
|
|
|
const wr::ExternalImageId& aExtID) override;
|
2017-05-18 17:59:07 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
|
|
|
|
const wr::LayoutRect& aBounds,
|
|
|
|
const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
|
2020-03-10 06:52:08 +03:00
|
|
|
const Range<wr::ImageKey>& aImageKeys,
|
|
|
|
const bool aPreferCompositorSurface) override;
|
2017-06-07 18:44:04 +03:00
|
|
|
|
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;
|
2019-04-11 15:38:49 +03:00
|
|
|
const gfx::YUVColorSpace mYUVColorSpace;
|
2019-07-26 11:45:30 +03:00
|
|
|
const gfx::ColorRange mColorRange;
|
2014-01-07 20:19:52 +04:00
|
|
|
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);
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool BindTextureSource(CompositableTextureSourceRef& aTexture) override;
|
|
|
|
bool AcquireTextureSource(CompositableTextureSourceRef& aTexture) override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void DeallocateDeviceData() override {}
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
|
2016-06-02 12:00:21 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
gfx::SurfaceFormat GetFormat() const override {
|
2015-03-21 19:28:04 +03:00
|
|
|
return gfx::SurfaceFormat::YUV;
|
|
|
|
}
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
gfx::ColorDepth GetColorDepth() const override { return mColorDepth; }
|
|
|
|
gfx::YUVColorSpace GetYUVColorSpace() const override {
|
2018-09-25 23:44:55 +03:00
|
|
|
return mYUVColorSpace;
|
|
|
|
}
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::ColorRange GetColorRange() const override { return mColorRange; }
|
2018-09-25 14:18:34 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Lock() override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void Unlock() override;
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
gfx::IntSize GetSize() const override { return mSize; }
|
2015-03-19 00:17:13 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override {
|
2015-03-19 00:17:13 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void CreateRenderTexture(
|
2017-08-07 13:15:22 +03:00
|
|
|
const wr::ExternalImageId& aExternalImageId) override;
|
|
|
|
|
2019-07-24 16:33:57 +03:00
|
|
|
uint32_t NumSubTextures() override;
|
2017-09-28 16:43:01 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void PushResourceUpdates(wr::TransactionBuilder& aResources,
|
|
|
|
ResourceUpdateOp aOp,
|
|
|
|
const Range<wr::ImageKey>& aImageKeys,
|
2020-03-10 06:52:08 +03:00
|
|
|
const wr::ExternalImageId& aExtID) override;
|
2017-05-18 17:59:07 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
|
|
|
|
const wr::LayoutRect& aBounds,
|
|
|
|
const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
|
2020-03-10 06:52:08 +03:00
|
|
|
const Range<wr::ImageKey>& aImageKeys,
|
|
|
|
const bool aPreferCompositorSurface) override;
|
2017-06-07 18:44:04 +03:00
|
|
|
|
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;
|
2019-04-11 15:41:33 +03:00
|
|
|
gfx::YUVColorSpace mYUVColorSpace;
|
2019-07-26 11:45:30 +03:00
|
|
|
gfx::ColorRange mColorRange;
|
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
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
const char* Name() const override { return "CompositingRenderTargetD3D11"; }
|
2016-02-08 13:57:00 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
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);
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
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
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Init() override;
|
2017-08-07 13:15:23 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
SyncHandle GetSyncHandle() override;
|
2017-08-07 13:15:23 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
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:
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~SyncObjectD3D11Host() = default;
|
2017-08-07 13:15:23 +03:00
|
|
|
|
|
|
|
SyncHandle mSyncHandle;
|
|
|
|
RefPtr<ID3D11Device> mDevice;
|
|
|
|
RefPtr<IDXGIResource> mSyncTexture;
|
|
|
|
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SyncObjectD3D11Client : public SyncObjectClient {
|
|
|
|
public:
|
2019-04-11 15:36:51 +03:00
|
|
|
SyncObjectD3D11Client(SyncHandle aSyncHandle, ID3D11Device* aDevice);
|
2017-08-07 13:15:23 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Synchronize(bool aFallible) override;
|
2017-08-07 13:15:23 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool IsSyncObjectValid() override;
|
2017-08-07 13:15:23 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
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 */
|