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 "gfxImageSurface.h"
|
|
|
|
#include "Effects.h"
|
|
|
|
#include "ipc/AutoOpenSurface.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"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
|
2013-07-08 14:30:44 -07:00
|
|
|
TemporaryRef<DeprecatedTextureHost>
|
|
|
|
CreateDeprecatedTextureHostD3D11(SurfaceDescriptorType aDescriptorType,
|
2013-07-22 16:05:04 -07:00
|
|
|
uint32_t aDeprecatedTextureHostFlags,
|
|
|
|
uint32_t aTextureFlags)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
2013-07-08 14:30:44 -07:00
|
|
|
RefPtr<DeprecatedTextureHost> result;
|
2013-05-03 10:34:29 -07:00
|
|
|
if (aDescriptorType == SurfaceDescriptor::TYCbCrImage) {
|
2013-07-08 14:30:44 -07:00
|
|
|
result = new DeprecatedTextureHostYCbCrD3D11();
|
2013-05-03 10:34:29 -07:00
|
|
|
} else if (aDescriptorType == SurfaceDescriptor::TSurfaceDescriptorD3D10) {
|
2013-07-08 14:30:44 -07:00
|
|
|
result = new DeprecatedTextureHostDXGID3D11();
|
2013-05-03 10:34:29 -07:00
|
|
|
} else {
|
2013-07-08 14:30:44 -07:00
|
|
|
result = new DeprecatedTextureHostShmemD3D11();
|
2013-05-03 10:34:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
result->SetFlags(aTextureFlags);
|
|
|
|
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-22 16:05:04 -07:00
|
|
|
CompositingRenderTargetD3D11::CompositingRenderTargetD3D11(ID3D11Texture2D* aTexture)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
2013-07-22 16:07:49 -07:00
|
|
|
MOZ_ASSERT(aTexture);
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
mTextures[0] = aTexture;
|
|
|
|
|
|
|
|
RefPtr<ID3D11Device> device;
|
|
|
|
mTextures[0]->GetDevice(byRef(device));
|
|
|
|
|
2013-07-20 01:48:55 -07:00
|
|
|
HRESULT hr = device->CreateRenderTargetView(mTextures[0], 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();
|
|
|
|
}
|
|
|
|
|
2013-07-22 16:05:04 -07:00
|
|
|
DeprecatedTextureClientD3D11::DeprecatedTextureClientD3D11(
|
|
|
|
CompositableForwarder* aCompositableForwarder,
|
|
|
|
const TextureInfo& aTextureInfo)
|
2013-07-08 14:30:44 -07:00
|
|
|
: DeprecatedTextureClient(aCompositableForwarder, aTextureInfo)
|
2013-05-03 10:34:29 -07:00
|
|
|
, mIsLocked(false)
|
|
|
|
{
|
|
|
|
mTextureInfo = aTextureInfo;
|
|
|
|
}
|
|
|
|
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::~DeprecatedTextureClientD3D11()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
mDescriptor = SurfaceDescriptor();
|
|
|
|
|
|
|
|
ClearDT();
|
|
|
|
}
|
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
bool
|
2013-07-22 16:05:04 -07:00
|
|
|
DeprecatedTextureClientD3D11::EnsureAllocated(gfx::IntSize aSize,
|
|
|
|
gfxASurface::gfxContentType aType)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
D3D10_TEXTURE2D_DESC desc;
|
|
|
|
|
|
|
|
if (mTexture) {
|
|
|
|
mTexture->GetDesc(&desc);
|
|
|
|
|
2013-07-22 16:05:49 -07:00
|
|
|
if (desc.Width == aSize.width && desc.Height == aSize.height) {
|
2013-08-04 00:46:17 -07:00
|
|
|
return true;
|
2013-05-03 10:34:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mTexture = nullptr;
|
|
|
|
mSurface = nullptr;
|
|
|
|
ClearDT();
|
|
|
|
}
|
|
|
|
|
|
|
|
mSize = aSize;
|
|
|
|
|
2013-07-22 16:05:04 -07:00
|
|
|
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
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!");
|
2013-08-04 00:46:17 -07:00
|
|
|
return false;
|
2013-05-03 10:34:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIResource> resource;
|
|
|
|
mTexture->QueryInterface((IDXGIResource**)byRef(resource));
|
|
|
|
|
|
|
|
HANDLE sharedHandle;
|
|
|
|
hr = resource->GetSharedHandle(&sharedHandle);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
LOGD3D11("Error getting shared handle for texture.");
|
|
|
|
}
|
|
|
|
|
2013-07-22 16:05:04 -07:00
|
|
|
mDescriptor = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle,
|
|
|
|
aType == gfxASurface::CONTENT_COLOR_ALPHA);
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
mContentType = aType;
|
2013-08-04 00:46:17 -07:00
|
|
|
return true;
|
2013-05-03 10:34:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxASurface*
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::LockSurface()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
EnsureSurface();
|
|
|
|
|
|
|
|
LockTexture();
|
|
|
|
return mSurface.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawTarget*
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::LockDrawTarget()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
EnsureDrawTarget();
|
|
|
|
|
|
|
|
LockTexture();
|
|
|
|
return mDrawTarget.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::Unlock()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
// TODO - Things seem to believe they can hold on to our surface... well...
|
|
|
|
// They shouldn't!!
|
|
|
|
ReleaseTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::SetDescriptor(const SurfaceDescriptor& aDescriptor)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
if (aDescriptor.type() == SurfaceDescriptor::Tnull_t) {
|
|
|
|
EnsureAllocated(mSize, mContentType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDescriptor = aDescriptor;
|
|
|
|
mSurface = nullptr;
|
|
|
|
ClearDT();
|
|
|
|
|
|
|
|
if (aDescriptor.type() == SurfaceDescriptor::T__None) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorD3D10);
|
2013-07-22 16:05:04 -07:00
|
|
|
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
device->OpenSharedResource((HANDLE)aDescriptor.get_SurfaceDescriptorD3D10().handle(),
|
|
|
|
__uuidof(ID3D10Texture2D),
|
|
|
|
(void**)(ID3D10Texture2D**)byRef(mTexture));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::EnsureSurface()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
if (mSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LockTexture();
|
|
|
|
mSurface = new gfxD2DSurface(mTexture, mContentType);
|
|
|
|
ReleaseTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::EnsureDrawTarget()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
if (mDrawTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LockTexture();
|
|
|
|
|
|
|
|
SurfaceFormat format;
|
|
|
|
switch (mContentType) {
|
|
|
|
case gfxASurface::CONTENT_ALPHA:
|
|
|
|
format = FORMAT_A8;
|
|
|
|
break;
|
|
|
|
case gfxASurface::CONTENT_COLOR:
|
|
|
|
format = FORMAT_B8G8R8X8;
|
|
|
|
break;
|
|
|
|
case gfxASurface::CONTENT_COLOR_ALPHA:
|
|
|
|
format = FORMAT_B8G8R8A8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = FORMAT_B8G8R8A8;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, format);
|
|
|
|
ReleaseTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::LockTexture()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
RefPtr<IDXGIKeyedMutex> mutex;
|
|
|
|
mTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
|
|
|
|
|
|
|
|
mutex->AcquireSync(0, INFINITE);
|
|
|
|
mIsLocked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::ReleaseTexture()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
// TODO - Bas - We seem to have places that unlock without ever having locked,
|
|
|
|
// that's kind of bad.
|
|
|
|
if (!mIsLocked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDrawTarget) {
|
|
|
|
mDrawTarget->Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIKeyedMutex> mutex;
|
|
|
|
mTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
|
|
|
|
|
|
|
|
mutex->ReleaseSync(0);
|
|
|
|
mIsLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureClientD3D11::ClearDT()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
2013-07-20 01:48:55 -07:00
|
|
|
// An Azure DrawTarget needs to be locked when it gets nullptr'ed as this is
|
2013-05-03 10:34:29 -07:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Perhaps this should be debug only.
|
|
|
|
if (mDrawTarget) {
|
|
|
|
LockTexture();
|
|
|
|
mDrawTarget = nullptr;
|
|
|
|
ReleaseTexture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostShmemD3D11::GetSize() const
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
if (mIterating) {
|
|
|
|
gfx::IntRect rect = GetTileRect(mCurrentTile);
|
|
|
|
return gfx::IntSize(rect.width, rect.height);
|
|
|
|
}
|
|
|
|
return TextureSourceD3D11::GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostShmemD3D11::GetTileRect()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
IntRect rect = GetTileRect(mCurrentTile);
|
|
|
|
return nsIntRect(rect.x, rect.y, rect.width, rect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t GetRequiredTiles(uint32_t aSize, uint32_t aMaxSize)
|
|
|
|
{
|
|
|
|
uint32_t requiredTiles = aSize / aMaxSize;
|
|
|
|
if (aSize % aMaxSize) {
|
|
|
|
requiredTiles++;
|
|
|
|
}
|
|
|
|
return requiredTiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostShmemD3D11::SetCompositor(Compositor* aCompositor)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
2013-07-22 16:05:04 -07:00
|
|
|
CompositorD3D11* d3dCompositor = static_cast<CompositorD3D11*>(aCompositor);
|
2013-05-03 10:34:29 -07:00
|
|
|
mDevice = d3dCompositor ? d3dCompositor->GetDevice() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostShmemD3D11::UpdateImpl(const SurfaceDescriptor& aImage,
|
2013-07-22 16:05:04 -07:00
|
|
|
nsIntRegion* aRegion,
|
|
|
|
nsIntPoint* aOffset)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
2013-07-04 14:46:34 -07:00
|
|
|
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TShmem ||
|
|
|
|
aImage.type() == SurfaceDescriptor::TMemoryImage);
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
AutoOpenSurface openSurf(OPEN_READ_ONLY, aImage);
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> surf = openSurf.GetAsImage();
|
|
|
|
|
|
|
|
gfxIntSize size = surf->GetSize();
|
|
|
|
|
|
|
|
uint32_t bpp = 0;
|
|
|
|
|
|
|
|
DXGI_FORMAT dxgiFormat;
|
|
|
|
switch (surf->Format()) {
|
|
|
|
case gfxImageSurface::ImageFormatRGB24:
|
|
|
|
mFormat = FORMAT_B8G8R8X8;
|
2013-08-08 16:32:19 -07:00
|
|
|
dxgiFormat = DXGI_FORMAT_B8G8R8X8_UNORM;
|
2013-05-03 10:34:29 -07:00
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
case gfxImageSurface::ImageFormatARGB32:
|
|
|
|
mFormat = FORMAT_B8G8R8A8;
|
|
|
|
dxgiFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
case gfxImageSurface::ImageFormatA8:
|
|
|
|
mFormat = FORMAT_A8;
|
|
|
|
dxgiFormat = DXGI_FORMAT_A8_UNORM;
|
|
|
|
bpp = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSize = IntSize(size.width, size.height);
|
|
|
|
|
|
|
|
CD3D11_TEXTURE2D_DESC desc(dxgiFormat, size.width, size.height,
|
2013-07-22 16:05:04 -07:00
|
|
|
1, 1, D3D11_BIND_SHADER_RESOURCE,
|
|
|
|
D3D11_USAGE_IMMUTABLE);
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
int32_t maxSize = GetMaxTextureSizeForFeatureLevel(mDevice->GetFeatureLevel());
|
|
|
|
if (size.width <= maxSize && size.height <= maxSize) {
|
|
|
|
D3D11_SUBRESOURCE_DATA initData;
|
|
|
|
initData.pSysMem = surf->Data();
|
|
|
|
initData.SysMemPitch = surf->Stride();
|
|
|
|
|
2013-08-08 16:32:19 -07:00
|
|
|
HRESULT hr = mDevice->CreateTexture2D(&desc, &initData, byRef(mTextures[0]));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
printf("FAILED to create texture\n");
|
|
|
|
}
|
2013-05-03 10:34:29 -07:00
|
|
|
mIsTiled = false;
|
|
|
|
} else {
|
|
|
|
mIsTiled = true;
|
|
|
|
uint32_t tileCount = GetRequiredTiles(size.width, maxSize) *
|
2013-07-22 16:05:04 -07:00
|
|
|
GetRequiredTiles(size.height, maxSize);
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
mTileTextures.resize(tileCount);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < tileCount; i++) {
|
|
|
|
IntRect tileRect = GetTileRect(i);
|
|
|
|
|
|
|
|
desc.Width = tileRect.width;
|
|
|
|
desc.Height = tileRect.height;
|
|
|
|
|
|
|
|
D3D11_SUBRESOURCE_DATA initData;
|
2013-07-22 16:05:04 -07:00
|
|
|
initData.pSysMem = surf->Data() +
|
|
|
|
tileRect.y * surf->Stride() +
|
|
|
|
tileRect.x * bpp;
|
2013-05-03 10:34:29 -07:00
|
|
|
initData.SysMemPitch = surf->Stride();
|
|
|
|
|
|
|
|
mDevice->CreateTexture2D(&desc, &initData, byRef(mTileTextures[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IntRect
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostShmemD3D11::GetTileRect(uint32_t aID) const
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
uint32_t maxSize = GetMaxTextureSizeForFeatureLevel(mDevice->GetFeatureLevel());
|
|
|
|
uint32_t horizontalTiles = GetRequiredTiles(mSize.width, maxSize);
|
|
|
|
uint32_t verticalTiles = GetRequiredTiles(mSize.height, maxSize);
|
|
|
|
|
|
|
|
uint32_t verticalTile = aID / horizontalTiles;
|
|
|
|
uint32_t horizontalTile = aID % horizontalTiles;
|
|
|
|
|
|
|
|
return IntRect(horizontalTile * maxSize,
|
|
|
|
verticalTile * maxSize,
|
|
|
|
horizontalTile < (horizontalTiles - 1) ? maxSize : mSize.width % maxSize,
|
|
|
|
verticalTile < (verticalTiles - 1) ? maxSize : mSize.height % maxSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostDXGID3D11::SetCompositor(Compositor* aCompositor)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
2013-07-22 16:05:04 -07:00
|
|
|
CompositorD3D11* d3dCompositor = static_cast<CompositorD3D11*>(aCompositor);
|
2013-05-03 10:34:29 -07:00
|
|
|
mDevice = d3dCompositor ? d3dCompositor->GetDevice() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostDXGID3D11::GetSize() const
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
return TextureSourceD3D11::GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostDXGID3D11::Lock()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
LockTexture();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostDXGID3D11::Unlock()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
ReleaseTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostDXGID3D11::UpdateImpl(const SurfaceDescriptor& aImage,
|
2013-07-22 16:05:04 -07:00
|
|
|
nsIntRegion* aRegion,
|
|
|
|
nsIntPoint* aOffset)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceDescriptorD3D10);
|
|
|
|
|
|
|
|
mDevice->OpenSharedResource((HANDLE)aImage.get_SurfaceDescriptorD3D10().handle(),
|
2013-07-22 16:05:04 -07:00
|
|
|
__uuidof(ID3D11Texture2D),
|
|
|
|
(void**)(ID3D11Texture2D**)byRef(mTextures[0]));
|
2013-05-03 10:34:29 -07:00
|
|
|
mFormat = aImage.get_SurfaceDescriptorD3D10().hasAlpha() ? FORMAT_B8G8R8A8 : FORMAT_B8G8R8X8;
|
|
|
|
|
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
|
|
|
mTextures[0]->GetDesc(&desc);
|
|
|
|
|
|
|
|
mSize = IntSize(desc.Width, desc.Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostDXGID3D11::LockTexture()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
RefPtr<IDXGIKeyedMutex> mutex;
|
|
|
|
mTextures[0]->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
|
|
|
|
|
|
|
|
mutex->AcquireSync(0, INFINITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostDXGID3D11::ReleaseTexture()
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
RefPtr<IDXGIKeyedMutex> mutex;
|
|
|
|
mTextures[0]->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
|
|
|
|
|
|
|
|
mutex->ReleaseSync(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostYCbCrD3D11::SetCompositor(Compositor* aCompositor)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
2013-07-22 16:05:04 -07:00
|
|
|
CompositorD3D11* d3dCompositor = static_cast<CompositorD3D11*>(aCompositor);
|
2013-05-03 10:34:29 -07:00
|
|
|
mDevice = d3dCompositor ? d3dCompositor->GetDevice() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostYCbCrD3D11::GetSize() const
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
return TextureSourceD3D11::GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-08 14:30:44 -07:00
|
|
|
DeprecatedTextureHostYCbCrD3D11::UpdateImpl(const SurfaceDescriptor& aImage,
|
2013-07-22 16:05:04 -07:00
|
|
|
nsIntRegion* aRegion,
|
|
|
|
nsIntPoint* aOffset)
|
2013-05-03 10:34:29 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TYCbCrImage);
|
|
|
|
|
2013-05-23 00:17:10 -07:00
|
|
|
YCbCrImageDataDeserializer yuvDeserializer(aImage.get_YCbCrImage().data().get<uint8_t>());
|
2013-05-03 10:34:29 -07:00
|
|
|
|
2013-05-23 00:17:10 -07:00
|
|
|
gfxIntSize gfxCbCrSize = yuvDeserializer.GetCbCrSize();
|
2013-05-03 10:34:29 -07:00
|
|
|
|
2013-05-23 00:17:10 -07:00
|
|
|
gfxIntSize size = yuvDeserializer.GetYSize();
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
D3D11_SUBRESOURCE_DATA initData;
|
2013-05-23 00:17:10 -07:00
|
|
|
initData.pSysMem = yuvDeserializer.GetYData();
|
|
|
|
initData.SysMemPitch = yuvDeserializer.GetYStride();
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_R8_UNORM, size.width, size.height,
|
2013-07-22 16:05:04 -07:00
|
|
|
1, 1, D3D11_BIND_SHADER_RESOURCE,
|
|
|
|
D3D11_USAGE_IMMUTABLE);
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
mDevice->CreateTexture2D(&desc, &initData, byRef(mTextures[0]));
|
|
|
|
|
2013-05-23 00:17:10 -07:00
|
|
|
initData.pSysMem = yuvDeserializer.GetCbData();
|
|
|
|
initData.SysMemPitch = yuvDeserializer.GetCbCrStride();
|
|
|
|
desc.Width = yuvDeserializer.GetCbCrSize().width;
|
|
|
|
desc.Height = yuvDeserializer.GetCbCrSize().height;
|
2013-05-03 10:34:29 -07:00
|
|
|
|
|
|
|
mDevice->CreateTexture2D(&desc, &initData, byRef(mTextures[1]));
|
|
|
|
|
2013-05-23 00:17:10 -07:00
|
|
|
initData.pSysMem = yuvDeserializer.GetCrData();
|
2013-05-03 10:34:29 -07:00
|
|
|
mDevice->CreateTexture2D(&desc, &initData, byRef(mTextures[2]));
|
|
|
|
|
|
|
|
mSize = IntSize(size.width, size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|