2015-05-05 21:35:29 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2013-05-03 21:34:29 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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"
|
|
|
|
#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 {
|
|
|
|
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
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual bool Serialize(SurfaceDescriptor& aOutDescrptor) 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*
|
2016-09-27 06:22:20 +03:00
|
|
|
CreateSimilar(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
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
virtual void SyncWithObject(SyncObject* aSync) 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();
|
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,
|
2015-12-02 22:31:17 +03:00
|
|
|
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) 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
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static DXGIYCbCrTextureData*
|
2016-09-27 06:22:20 +03:00
|
|
|
Create(TextureFlags aFlags,
|
2015-10-15 18:53:37 +03:00
|
|
|
IUnknown* aTextureY,
|
|
|
|
IUnknown* aTextureCb,
|
|
|
|
IUnknown* aTextureCr,
|
2015-04-29 20:34:00 +03:00
|
|
|
HANDLE aHandleY,
|
|
|
|
HANDLE aHandleCb,
|
|
|
|
HANDLE aHandleCr,
|
|
|
|
const gfx::IntSize& aSize,
|
|
|
|
const gfx::IntSize& aSizeY,
|
|
|
|
const gfx::IntSize& aSizeCbCr);
|
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
static DXGIYCbCrTextureData*
|
2016-09-27 06:22:20 +03:00
|
|
|
Create(TextureFlags aFlags,
|
2015-11-24 21:07:02 +03:00
|
|
|
ID3D11Texture2D* aTextureCb,
|
2015-10-15 18:53:37 +03:00
|
|
|
ID3D11Texture2D* aTextureY,
|
2015-09-01 22:33:40 +03:00
|
|
|
ID3D11Texture2D* aTextureCr,
|
|
|
|
const gfx::IntSize& aSize,
|
|
|
|
const gfx::IntSize& aSizeY,
|
|
|
|
const gfx::IntSize& aSizeCbCr);
|
|
|
|
|
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
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) 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
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
protected:
|
2015-10-15 18:53:37 +03:00
|
|
|
RefPtr<IUnknown> mHoldRefs[3];
|
|
|
|
HANDLE mHandles[3];
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
gfx::IntSize mSizeY;
|
|
|
|
gfx::IntSize mSizeCbCr;
|
|
|
|
};
|
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();
|
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.
|
|
|
|
virtual DataTextureSource* AsDataTextureSource() override { return mAllowTextureUploads ? this : false; }
|
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
|
2013-07-23 03:05:04 +04:00
|
|
|
{
|
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-05-31 12:48:12 +03:00
|
|
|
void Reset();
|
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
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override
|
2014-01-07 20:19:52 +04:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-06-07 18:44:04 +03:00
|
|
|
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
|
|
|
|
const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
|
|
|
|
|
2017-05-18 17:59:07 +03:00
|
|
|
virtual void AddWRImage(wr::WebRenderAPI* aAPI,
|
2017-05-18 19:25:41 +03:00
|
|
|
Range<const wr::ImageKey>& aImageKeys,
|
2017-05-18 17:59:07 +03:00
|
|
|
const wr::ExternalImageId& aExtID) override;
|
|
|
|
|
2017-06-07 18:44:04 +03:00
|
|
|
virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
|
|
|
|
const WrRect& aBounds,
|
|
|
|
const WrClipRegionToken aClip,
|
|
|
|
wr::ImageRendering aFilter,
|
|
|
|
Range<const wr::ImageKey>& aImageKeys) override;
|
|
|
|
|
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
|
|
|
|
2014-07-23 22:17:15 +04:00
|
|
|
bool OpenSharedHandle();
|
|
|
|
|
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
|
|
|
|
2016-10-25 04:17:39 +03:00
|
|
|
// Bug 1305906 fixes YUVColorSpace handling
|
|
|
|
virtual YUVColorSpace GetYUVColorSpace() const override { return YUVColorSpace::BT601; }
|
|
|
|
|
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-06-07 18:44:04 +03:00
|
|
|
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
|
|
|
|
const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
|
|
|
|
|
2017-05-18 17:59:07 +03:00
|
|
|
virtual void AddWRImage(wr::WebRenderAPI* aAPI,
|
2017-05-18 19:25:41 +03:00
|
|
|
Range<const wr::ImageKey>& aImageKeys,
|
2017-05-18 17:59:07 +03:00
|
|
|
const wr::ExternalImageId& aExtID) override;
|
|
|
|
|
2017-06-07 18:44:04 +03:00
|
|
|
virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
|
|
|
|
const WrRect& aBounds,
|
|
|
|
const WrClipRegionToken aClip,
|
|
|
|
wr::ImageRendering aFilter,
|
|
|
|
Range<const wr::ImageKey>& aImageKeys) override;
|
|
|
|
|
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
|
|
|
|
|
|
|
bool OpenSharedHandle();
|
|
|
|
|
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;
|
|
|
|
WindowsHandle mHandles[3];
|
|
|
|
bool mIsLocked;
|
|
|
|
};
|
|
|
|
|
2013-05-03 21:34:29 +04:00
|
|
|
class CompositingRenderTargetD3D11 : public CompositingRenderTarget,
|
|
|
|
public TextureSourceD3D11
|
|
|
|
{
|
|
|
|
public:
|
2013-11-07 13:53:08 +04:00
|
|
|
CompositingRenderTargetD3D11(ID3D11Texture2D* aTexture,
|
2015-09-22 16:38:28 +03:00
|
|
|
const gfx::IntPoint& aOrigin,
|
|
|
|
DXGI_FORMAT aFormatOverride = DXGI_FORMAT_UNKNOWN);
|
2013-05-03 21:34:29 +04: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
|
|
|
};
|
|
|
|
|
2014-12-13 04:50:47 +03:00
|
|
|
class SyncObjectD3D11 : public SyncObject
|
|
|
|
{
|
|
|
|
public:
|
2017-03-07 23:55:19 +03:00
|
|
|
explicit SyncObjectD3D11(SyncHandle aSyncHandle, ID3D11Device* aDevice);
|
2015-11-20 16:25:03 +03:00
|
|
|
virtual void FinalizeFrame();
|
2017-01-18 05:12:42 +03:00
|
|
|
virtual bool IsSyncObjectValid();
|
2014-12-13 04:50:47 +03:00
|
|
|
|
|
|
|
virtual SyncType GetSyncType() { return SyncType::D3D11; }
|
|
|
|
|
|
|
|
void RegisterTexture(ID3D11Texture2D* aTexture);
|
|
|
|
|
|
|
|
private:
|
2016-11-30 01:07:27 +03:00
|
|
|
bool Init();
|
|
|
|
|
|
|
|
private:
|
|
|
|
SyncHandle mSyncHandle;
|
2017-01-18 05:12:42 +03:00
|
|
|
RefPtr<ID3D11Device> mD3D11Device;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ID3D11Texture2D> mD3D11Texture;
|
2016-11-30 01:07:27 +03:00
|
|
|
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
2014-12-13 04:50:47 +03:00
|
|
|
std::vector<ID3D11Texture2D*> mD3D11SyncedTextures;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
2013-05-03 21:34:29 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_TEXTURED3D11_H */
|