2013-05-03 10:34:29 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#include "TextureD3D11.h"
|
|
|
|
#include "CompositorD3D11.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "Effects.h"
|
2013-05-23 00:17:10 -07:00
|
|
|
#include "mozilla/layers/YCbCrImageDataSerializer.h"
|
2013-05-03 10:34:29 -07:00
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#include "gfxD2DSurface.h"
|
2013-12-20 08:46:31 -08:00
|
|
|
#include "gfx2DGlue.h"
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
static DXGI_FORMAT
|
|
|
|
SurfaceFormatToDXGIFormat(gfx::SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
switch (aFormat) {
|
2014-01-10 11:06:16 -08:00
|
|
|
case SurfaceFormat::B8G8R8A8:
|
2014-01-07 08:19:52 -08:00
|
|
|
return DXGI_FORMAT_B8G8R8A8_UNORM;
|
2014-01-10 11:06:16 -08:00
|
|
|
case SurfaceFormat::B8G8R8X8:
|
2014-01-07 08:19:52 -08:00
|
|
|
return DXGI_FORMAT_B8G8R8A8_UNORM;
|
2014-01-10 11:06:16 -08:00
|
|
|
case SurfaceFormat::A8:
|
2014-01-07 08:19:52 -08:00
|
|
|
return DXGI_FORMAT_A8_UNORM;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "unsupported format");
|
2014-01-09 06:26:20 -08:00
|
|
|
return DXGI_FORMAT_UNKNOWN;
|
2014-01-07 08:19:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
GetRequiredTilesD3D11(uint32_t aSize, uint32_t aMaxSize)
|
|
|
|
{
|
|
|
|
uint32_t requiredTiles = aSize / aMaxSize;
|
|
|
|
if (aSize % aMaxSize) {
|
|
|
|
requiredTiles++;
|
|
|
|
}
|
|
|
|
return requiredTiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IntRect
|
|
|
|
GetTileRectD3D11(uint32_t aID, IntSize aSize, uint32_t aMaxSize)
|
|
|
|
{
|
|
|
|
uint32_t horizontalTiles = GetRequiredTilesD3D11(aSize.width, aMaxSize);
|
|
|
|
uint32_t verticalTiles = GetRequiredTilesD3D11(aSize.height, aMaxSize);
|
|
|
|
|
|
|
|
uint32_t verticalTile = aID / horizontalTiles;
|
|
|
|
uint32_t horizontalTile = aID % horizontalTiles;
|
|
|
|
|
|
|
|
return IntRect(horizontalTile * aMaxSize,
|
|
|
|
verticalTile * aMaxSize,
|
|
|
|
horizontalTile < (horizontalTiles - 1) ? aMaxSize : aSize.width % aMaxSize,
|
|
|
|
verticalTile < (verticalTiles - 1) ? aMaxSize : aSize.height % aMaxSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
DataTextureSourceD3D11::DataTextureSourceD3D11(SurfaceFormat aFormat,
|
2014-02-11 08:13:14 -08:00
|
|
|
CompositorD3D11* aCompositor,
|
|
|
|
TextureFlags aFlags)
|
2014-01-07 08:20:11 -08:00
|
|
|
: mCompositor(aCompositor)
|
|
|
|
, mFormat(aFormat)
|
2014-02-11 08:13:14 -08:00
|
|
|
, mFlags(aFlags)
|
2014-01-07 08:20:11 -08:00
|
|
|
, mCurrentTile(0)
|
|
|
|
, mIsTiled(false)
|
|
|
|
, mIterating(false)
|
2014-01-07 08:19:52 -08:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(DataTextureSourceD3D11);
|
|
|
|
}
|
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
DataTextureSourceD3D11::DataTextureSourceD3D11(SurfaceFormat aFormat,
|
|
|
|
CompositorD3D11* aCompositor,
|
|
|
|
ID3D11Texture2D* aTexture)
|
|
|
|
: mCompositor(aCompositor)
|
|
|
|
, mFormat(aFormat)
|
|
|
|
, mFlags(0)
|
|
|
|
, mCurrentTile(0)
|
|
|
|
, mIsTiled(false)
|
|
|
|
, mIterating(false)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(DataTextureSourceD3D11);
|
|
|
|
|
|
|
|
mTexture = aTexture;
|
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
|
|
|
aTexture->GetDesc(&desc);
|
|
|
|
|
|
|
|
mSize = IntSize(desc.Width, desc.Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
DataTextureSourceD3D11::~DataTextureSourceD3D11()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(DataTextureSourceD3D11);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> // ID3D10Texture2D or ID3D11Texture2D
|
|
|
|
static void LockD3DTexture(T* aTexture)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTexture);
|
|
|
|
RefPtr<IDXGIKeyedMutex> mutex;
|
|
|
|
aTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
|
2014-04-06 20:09:22 -07:00
|
|
|
if (mutex) {
|
|
|
|
mutex->AcquireSync(0, INFINITE);
|
|
|
|
}
|
2014-01-07 08:19:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T> // ID3D10Texture2D or ID3D11Texture2D
|
|
|
|
static void UnlockD3DTexture(T* aTexture)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTexture);
|
|
|
|
RefPtr<IDXGIKeyedMutex> mutex;
|
|
|
|
aTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
|
2014-04-06 20:09:22 -07:00
|
|
|
if (mutex) {
|
|
|
|
mutex->ReleaseSync(0);
|
|
|
|
}
|
2014-01-07 08:19:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<TextureHost>
|
|
|
|
CreateTextureHostD3D11(const SurfaceDescriptor& aDesc,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags)
|
|
|
|
{
|
|
|
|
RefPtr<TextureHost> result;
|
|
|
|
switch (aDesc.type()) {
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorShmem:
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMemory: {
|
|
|
|
result = CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
|
|
|
|
result = new DXGITextureHostD3D11(aFlags,
|
|
|
|
aDesc.get_SurfaceDescriptorD3D10());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
NS_WARNING("Unsupported SurfaceDescriptor type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
TextureClientD3D11::TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags aFlags)
|
|
|
|
: TextureClient(aFlags)
|
|
|
|
, mFormat(aFormat)
|
|
|
|
, mIsLocked(false)
|
2014-01-29 08:26:42 -08:00
|
|
|
, mNeedsClear(false)
|
2014-01-07 08:20:11 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
TextureClientD3D11::~TextureClientD3D11()
|
2014-02-10 02:21:11 -08:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
// An Azure DrawTarget needs to be locked when it gets nullptr'ed as this is
|
|
|
|
// when it calls EndDraw. This EndDraw should not execute anything so it
|
|
|
|
// shouldn't -really- need the lock but the debug layer chokes on this.
|
|
|
|
if (mDrawTarget) {
|
|
|
|
MOZ_ASSERT(!mIsLocked);
|
|
|
|
MOZ_ASSERT(mTexture);
|
2014-02-10 02:50:43 -08:00
|
|
|
MOZ_ASSERT(mDrawTarget->refCount() == 1);
|
2014-02-10 02:21:11 -08:00
|
|
|
LockD3DTexture(mTexture.get());
|
|
|
|
mDrawTarget = nullptr;
|
|
|
|
UnlockD3DTexture(mTexture.get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2014-01-07 08:20:11 -08:00
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
bool
|
|
|
|
TextureClientD3D11::Lock(OpenMode aMode)
|
|
|
|
{
|
2014-04-08 05:50:41 -07:00
|
|
|
if (!mTexture) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-07 08:19:52 -08:00
|
|
|
MOZ_ASSERT(!mIsLocked, "The Texture is already locked!");
|
|
|
|
LockD3DTexture(mTexture.get());
|
2014-02-04 12:35:22 -08:00
|
|
|
mIsLocked = true;
|
2014-01-29 08:26:42 -08:00
|
|
|
|
|
|
|
if (mNeedsClear) {
|
2014-02-04 12:35:22 -08:00
|
|
|
mDrawTarget = GetAsDrawTarget();
|
2014-01-29 08:26:42 -08:00
|
|
|
mDrawTarget->ClearRect(Rect(0, 0, GetSize().width, GetSize().height));
|
|
|
|
mNeedsClear = false;
|
|
|
|
}
|
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextureClientD3D11::Unlock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsLocked, "Unlocked called while the texture is not locked!");
|
2014-04-08 05:50:41 -07:00
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
if (mDrawTarget) {
|
2014-04-10 01:14:28 -07:00
|
|
|
// see the comment on TextureClient::GetAsDrawTarget.
|
2014-03-21 10:03:20 -07:00
|
|
|
// This DrawTarget is internal to the TextureClient and is only exposed to the
|
|
|
|
// outside world between Lock() and Unlock(). This assertion checks that no outside
|
|
|
|
// reference remains by the time Unlock() is called.
|
2014-02-04 12:35:22 -08:00
|
|
|
MOZ_ASSERT(mDrawTarget->refCount() == 1);
|
2014-01-07 08:20:11 -08:00
|
|
|
mDrawTarget->Flush();
|
|
|
|
}
|
2014-02-04 12:35:22 -08:00
|
|
|
|
|
|
|
// The DrawTarget is created only once, and is only usable between calls
|
|
|
|
// to Lock and Unlock.
|
2014-01-07 08:19:52 -08:00
|
|
|
UnlockD3DTexture(mTexture.get());
|
|
|
|
mIsLocked = false;
|
|
|
|
}
|
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
TextureClientD3D11::GetAsDrawTarget()
|
2014-01-07 08:19:52 -08:00
|
|
|
{
|
2014-01-07 08:20:11 -08:00
|
|
|
MOZ_ASSERT(mIsLocked, "Calling TextureClient::GetAsDrawTarget without locking :(");
|
2014-01-07 08:19:52 -08:00
|
|
|
|
2014-04-08 05:50:41 -07:00
|
|
|
if (!mTexture) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
if (mDrawTarget) {
|
|
|
|
return mDrawTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, mFormat);
|
|
|
|
return mDrawTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-01-20 05:52:12 -08:00
|
|
|
TextureClientD3D11::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags)
|
2014-01-07 08:20:11 -08:00
|
|
|
{
|
|
|
|
mSize = aSize;
|
|
|
|
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
|
|
|
|
|
2014-04-08 05:50:36 -07:00
|
|
|
CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM,
|
2014-01-07 08:20:11 -08:00
|
|
|
aSize.width, aSize.height, 1, 1,
|
|
|
|
D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE);
|
|
|
|
|
|
|
|
newDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
|
|
|
|
|
|
|
HRESULT hr = device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
LOGD3D11("Error creating texture for client!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-29 08:26:42 -08:00
|
|
|
// Defer clearing to the next time we lock to avoid an extra (expensive) lock.
|
|
|
|
mNeedsClear = aFlags & ALLOC_CLEAR_BUFFER;
|
2014-01-20 05:52:12 -08:00
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TextureClientD3D11::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
|
|
|
|
{
|
|
|
|
if (!IsAllocated()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIResource> resource;
|
|
|
|
mTexture->QueryInterface((IDXGIResource**)byRef(resource));
|
|
|
|
HANDLE sharedHandle;
|
|
|
|
HRESULT hr = resource->GetSharedHandle(&sharedHandle);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
LOGD3D11("Error getting shared handle for texture.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-06 20:23:06 -07:00
|
|
|
aOutDescriptor = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle, mFormat, mSize);
|
2014-01-07 08:20:11 -08:00
|
|
|
return true;
|
2014-01-07 08:19:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
DXGITextureHostD3D11::DXGITextureHostD3D11(TextureFlags aFlags,
|
|
|
|
const SurfaceDescriptorD3D10& aDescriptor)
|
|
|
|
: TextureHost(aFlags)
|
|
|
|
, mHandle(aDescriptor.handle())
|
2014-01-07 08:20:11 -08:00
|
|
|
, mFormat(aDescriptor.format())
|
2014-01-07 08:19:52 -08:00
|
|
|
, mIsLocked(false)
|
|
|
|
{}
|
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
ID3D11Device*
|
|
|
|
DXGITextureHostD3D11::GetDevice()
|
|
|
|
{
|
|
|
|
return mCompositor ? mCompositor->GetDevice() : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
void
|
|
|
|
DXGITextureHostD3D11::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
2014-01-07 08:20:11 -08:00
|
|
|
mCompositor = static_cast<CompositorD3D11*>(aCompositor);
|
2014-01-07 08:19:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DXGITextureHostD3D11::Lock()
|
|
|
|
{
|
2014-01-07 08:20:11 -08:00
|
|
|
if (!GetDevice()) {
|
2014-01-07 08:19:52 -08:00
|
|
|
NS_WARNING("trying to lock a TextureHost without a D3D device");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!mTextureSource) {
|
|
|
|
RefPtr<ID3D11Texture2D> tex;
|
2014-01-07 08:20:11 -08:00
|
|
|
HRESULT hr = GetDevice()->OpenSharedResource((HANDLE)mHandle,
|
|
|
|
__uuidof(ID3D11Texture2D),
|
|
|
|
(void**)(ID3D11Texture2D**)byRef(tex));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to open shared texture");
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-07 08:19:52 -08:00
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
mTextureSource = new DataTextureSourceD3D11(mFormat, mCompositor, tex);
|
2014-01-07 08:19:52 -08:00
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
|
|
|
tex->GetDesc(&desc);
|
|
|
|
mSize = IntSize(desc.Width, desc.Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
LockD3DTexture(mTextureSource->GetD3D11Texture());
|
|
|
|
|
|
|
|
mIsLocked = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DXGITextureHostD3D11::Unlock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsLocked);
|
|
|
|
UnlockD3DTexture(mTextureSource->GetD3D11Texture());
|
|
|
|
mIsLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NewTextureSource*
|
|
|
|
DXGITextureHostD3D11::GetTextureSources()
|
|
|
|
{
|
|
|
|
return mTextureSource.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DataTextureSourceD3D11::Update(DataSourceSurface* aSurface,
|
|
|
|
nsIntRegion* aDestRegion,
|
|
|
|
IntPoint* aSrcOffset)
|
|
|
|
{
|
2014-04-08 06:17:26 -07:00
|
|
|
// Right now we only support full surface update. If aDestRegion is provided,
|
|
|
|
// It will be ignored. Incremental update with a source offset is only used
|
|
|
|
// on Mac so it is not clear that we ever will need to support it for D3D.
|
|
|
|
MOZ_ASSERT(!aSrcOffset);
|
2014-01-07 08:19:52 -08:00
|
|
|
MOZ_ASSERT(aSurface);
|
|
|
|
|
|
|
|
if (!mCompositor || !mCompositor->GetDevice()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t bpp = BytesPerPixel(aSurface->GetFormat());
|
|
|
|
DXGI_FORMAT dxgiFormat = SurfaceFormatToDXGIFormat(aSurface->GetFormat());
|
|
|
|
|
|
|
|
mSize = aSurface->GetSize();
|
2014-01-07 08:20:11 -08:00
|
|
|
mFormat = aSurface->GetFormat();
|
2014-01-07 08:19:52 -08:00
|
|
|
|
|
|
|
CD3D11_TEXTURE2D_DESC desc(dxgiFormat, mSize.width, mSize.height,
|
|
|
|
1, 1, D3D11_BIND_SHADER_RESOURCE,
|
|
|
|
D3D11_USAGE_IMMUTABLE);
|
|
|
|
|
|
|
|
int32_t maxSize = mCompositor->GetMaxTextureSize();
|
2014-01-07 08:20:11 -08:00
|
|
|
if ((mSize.width <= maxSize && mSize.height <= maxSize) ||
|
|
|
|
(mFlags & TEXTURE_DISALLOW_BIGIMAGE)) {
|
2014-01-07 08:19:52 -08:00
|
|
|
D3D11_SUBRESOURCE_DATA initData;
|
|
|
|
initData.pSysMem = aSurface->GetData();
|
|
|
|
initData.SysMemPitch = aSurface->Stride();
|
|
|
|
|
|
|
|
mCompositor->GetDevice()->CreateTexture2D(&desc, &initData, byRef(mTexture));
|
|
|
|
mIsTiled = false;
|
2014-01-07 08:20:11 -08:00
|
|
|
if (!mTexture) {
|
|
|
|
Reset();
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-07 08:19:52 -08:00
|
|
|
} else {
|
|
|
|
mIsTiled = true;
|
|
|
|
uint32_t tileCount = GetRequiredTilesD3D11(mSize.width, maxSize) *
|
|
|
|
GetRequiredTilesD3D11(mSize.height, maxSize);
|
|
|
|
|
|
|
|
mTileTextures.resize(tileCount);
|
2014-01-07 08:20:11 -08:00
|
|
|
mTexture = nullptr;
|
2014-01-07 08:19:52 -08:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < tileCount; i++) {
|
|
|
|
IntRect tileRect = GetTileRect(i);
|
|
|
|
|
|
|
|
desc.Width = tileRect.width;
|
|
|
|
desc.Height = tileRect.height;
|
|
|
|
|
|
|
|
D3D11_SUBRESOURCE_DATA initData;
|
|
|
|
initData.pSysMem = aSurface->GetData() +
|
|
|
|
tileRect.y * aSurface->Stride() +
|
|
|
|
tileRect.x * bpp;
|
|
|
|
initData.SysMemPitch = aSurface->Stride();
|
|
|
|
|
|
|
|
mCompositor->GetDevice()->CreateTexture2D(&desc, &initData, byRef(mTileTextures[i]));
|
2014-01-07 08:20:11 -08:00
|
|
|
if (!mTileTextures[i]) {
|
|
|
|
Reset();
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-07 08:19:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
ID3D11Texture2D*
|
|
|
|
DataTextureSourceD3D11::GetD3D11Texture() const
|
|
|
|
{
|
|
|
|
return mIterating ? mTileTextures[mCurrentTile]
|
|
|
|
: mTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DataTextureSourceD3D11::Reset()
|
|
|
|
{
|
|
|
|
mTexture = nullptr;
|
|
|
|
mTileTextures.resize(0);
|
|
|
|
mIsTiled = false;
|
|
|
|
mSize.width = 0;
|
|
|
|
mSize.height = 0;
|
|
|
|
}
|
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
IntRect
|
|
|
|
DataTextureSourceD3D11::GetTileRect(uint32_t aIndex) const
|
|
|
|
{
|
|
|
|
return GetTileRectD3D11(aIndex, mSize, mCompositor->GetMaxTextureSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect
|
|
|
|
DataTextureSourceD3D11::GetTileRect()
|
|
|
|
{
|
|
|
|
IntRect rect = GetTileRect(mCurrentTile);
|
|
|
|
return nsIntRect(rect.x, rect.y, rect.width, rect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DataTextureSourceD3D11::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
|
|
|
CompositorD3D11* d3dCompositor = static_cast<CompositorD3D11*>(aCompositor);
|
2014-02-11 08:13:14 -08:00
|
|
|
if (mCompositor && mCompositor != d3dCompositor) {
|
2014-01-07 08:20:11 -08:00
|
|
|
Reset();
|
2014-01-07 08:19:52 -08:00
|
|
|
}
|
|
|
|
mCompositor = d3dCompositor;
|
|
|
|
}
|
|
|
|
|
2013-11-07 01:53:08 -08:00
|
|
|
CompositingRenderTargetD3D11::CompositingRenderTargetD3D11(ID3D11Texture2D* aTexture,
|
|
|
|
const gfx::IntPoint& aOrigin)
|
|
|
|
: CompositingRenderTarget(aOrigin)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
2013-07-22 16:07:49 -07:00
|
|
|
MOZ_ASSERT(aTexture);
|
2014-03-31 23:28:14 -07:00
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
mTexture = aTexture;
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
RefPtr<ID3D11Device> device;
|
2014-01-07 08:19:52 -08:00
|
|
|
mTexture->GetDevice(byRef(device));
|
2013-05-03 10:34:29 -07:00
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
HRESULT hr = device->CreateRenderTargetView(mTexture, nullptr, byRef(mRTView));
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
LOGD3D11("Failed to create RenderTargetView.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize
|
|
|
|
CompositingRenderTargetD3D11::GetSize() const
|
|
|
|
{
|
|
|
|
return TextureSourceD3D11::GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|