2010-09-30 15:53:49 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07: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/. */
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
#include "ImageLayerD3D10.h"
|
|
|
|
#include "gfxImageSurface.h"
|
2010-12-15 12:37:12 -08:00
|
|
|
#include "gfxD2DSurface.h"
|
2010-12-15 12:37:10 -08:00
|
|
|
#include "gfxWindowsSurface.h"
|
2010-09-30 15:53:49 -07:00
|
|
|
#include "yuv_convert.h"
|
2011-01-11 20:51:27 -08:00
|
|
|
#include "../d3d9/Nv3DVUtils.h"
|
2013-05-04 03:12:40 -07:00
|
|
|
#include "D3D9SurfaceImage.h"
|
2013-12-13 09:32:02 -08:00
|
|
|
#include "mozilla/gfx/Point.h"
|
|
|
|
#include "gfx2DGlue.h"
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2012-05-29 22:14:30 -07:00
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
|
2013-12-13 09:32:02 -08:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
2012-07-18 09:31:40 -07:00
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
static already_AddRefed<ID3D10Texture2D>
|
|
|
|
DataToTexture(ID3D10Device *aDevice,
|
|
|
|
unsigned char *data,
|
|
|
|
int stride,
|
2013-12-20 08:46:29 -08:00
|
|
|
const IntSize &aSize)
|
2012-02-15 19:26:19 -08:00
|
|
|
{
|
|
|
|
D3D10_SUBRESOURCE_DATA srdata;
|
2012-07-18 09:31:40 -07:00
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
aSize.width,
|
|
|
|
aSize.height,
|
|
|
|
1, 1);
|
|
|
|
desc.Usage = D3D10_USAGE_IMMUTABLE;
|
2012-07-18 09:31:40 -07:00
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
srdata.pSysMem = data;
|
|
|
|
srdata.SysMemPitch = stride;
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Texture2D> texture;
|
|
|
|
HRESULT hr = aDevice->CreateTexture2D(&desc, &srdata, getter_AddRefs(texture));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
LayerManagerD3D10::ReportFailure(NS_LITERAL_CSTRING("Failed to create texture for data"),
|
|
|
|
hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture.forget();
|
|
|
|
}
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2010-12-15 12:37:10 -08:00
|
|
|
static already_AddRefed<ID3D10Texture2D>
|
|
|
|
SurfaceToTexture(ID3D10Device *aDevice,
|
|
|
|
gfxASurface *aSurface,
|
2013-12-20 08:46:29 -08:00
|
|
|
const IntSize &aSize)
|
2010-12-15 12:37:10 -08:00
|
|
|
{
|
2012-01-19 06:53:56 -08:00
|
|
|
if (!aSurface) {
|
2013-07-20 01:48:55 -07:00
|
|
|
return nullptr;
|
2012-01-19 06:53:56 -08:00
|
|
|
}
|
|
|
|
|
2013-09-24 13:45:13 -07:00
|
|
|
if (aSurface->GetType() == gfxSurfaceTypeD2D) {
|
2010-12-15 12:37:10 -08:00
|
|
|
void *data = aSurface->GetData(&gKeyD3D10Texture);
|
|
|
|
if (data) {
|
|
|
|
nsRefPtr<ID3D10Texture2D> texture = static_cast<ID3D10Texture2D*>(data);
|
|
|
|
ID3D10Device *dev;
|
|
|
|
texture->GetDevice(&dev);
|
|
|
|
if (dev == aDevice) {
|
|
|
|
return texture.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> imageSurface = aSurface->GetAsImageSurface();
|
|
|
|
|
|
|
|
if (!imageSurface) {
|
2013-12-20 08:46:29 -08:00
|
|
|
imageSurface = new gfxImageSurface(ThebesIntSize(aSize),
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxImageFormatARGB32);
|
2012-01-19 06:53:56 -08:00
|
|
|
|
2010-12-15 12:37:10 -08:00
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(imageSurface);
|
|
|
|
context->SetSource(aSurface);
|
|
|
|
context->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
context->Paint();
|
|
|
|
}
|
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
return DataToTexture(aDevice, imageSurface->Data(), imageSurface->Stride(), aSize);
|
2010-12-15 12:37:10 -08:00
|
|
|
}
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
Layer*
|
|
|
|
ImageLayerD3D10::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-02-15 15:34:23 -08:00
|
|
|
/**
|
|
|
|
* Returns a shader resource view for a Cairo or remote image.
|
2012-07-30 07:20:58 -07:00
|
|
|
* Returns nullptr if unsuccessful.
|
2013-05-04 03:12:40 -07:00
|
|
|
* If successful, aHasAlpha will be true iff the resulting texture
|
2012-02-15 15:34:23 -08:00
|
|
|
* has an alpha component.
|
|
|
|
*/
|
|
|
|
ID3D10ShaderResourceView*
|
2012-05-29 22:14:30 -07:00
|
|
|
ImageLayerD3D10::GetImageSRView(Image* aImage, bool& aHasAlpha, IDXGIKeyedMutex **aMutex)
|
2012-02-15 15:34:23 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aImage, "Null image.");
|
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
if (aImage->GetFormat() == ImageFormat::REMOTE_IMAGE_BITMAP) {
|
2012-02-15 15:34:23 -08:00
|
|
|
RemoteBitmapImage *remoteImage =
|
|
|
|
static_cast<RemoteBitmapImage*>(aImage);
|
2012-07-18 09:31:40 -07:00
|
|
|
|
|
|
|
if (!aImage->GetBackendData(mozilla::layers::LAYERS_D3D10)) {
|
2012-05-21 02:03:23 -07:00
|
|
|
nsAutoPtr<TextureD3D10BackendData> dat(new TextureD3D10BackendData());
|
2012-02-15 15:34:23 -08:00
|
|
|
dat->mTexture = DataToTexture(device(), remoteImage->mData, remoteImage->mStride, remoteImage->mSize);
|
|
|
|
|
|
|
|
if (dat->mTexture) {
|
2013-07-20 01:48:55 -07:00
|
|
|
device()->CreateShaderResourceView(dat->mTexture, nullptr, getter_AddRefs(dat->mSRView));
|
2012-07-18 09:31:40 -07:00
|
|
|
aImage->SetBackendData(mozilla::layers::LAYERS_D3D10, dat.forget());
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-29 22:14:30 -07:00
|
|
|
aHasAlpha = remoteImage->mFormat == RemoteImageData::BGRA32;
|
2012-08-19 12:33:25 -07:00
|
|
|
} else if (aImage->GetFormat() == ImageFormat::REMOTE_IMAGE_DXGI_TEXTURE) {
|
2012-05-29 22:14:30 -07:00
|
|
|
RemoteDXGITextureImage *remoteImage =
|
|
|
|
static_cast<RemoteDXGITextureImage*>(aImage);
|
|
|
|
|
|
|
|
remoteImage->GetD3D10TextureBackendData(device());
|
|
|
|
|
2012-02-15 15:34:23 -08:00
|
|
|
aHasAlpha = remoteImage->mFormat == RemoteImageData::BGRA32;
|
2012-08-19 12:33:25 -07:00
|
|
|
} else if (aImage->GetFormat() == ImageFormat::CAIRO_SURFACE) {
|
2012-02-15 15:34:23 -08:00
|
|
|
CairoImage *cairoImage =
|
|
|
|
static_cast<CairoImage*>(aImage);
|
|
|
|
|
2014-01-17 08:22:09 -08:00
|
|
|
nsRefPtr<gfxASurface> surf = cairoImage->DeprecatedGetAsSurface();
|
|
|
|
if (!surf) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
|
|
|
|
2012-07-18 09:31:40 -07:00
|
|
|
if (!aImage->GetBackendData(mozilla::layers::LAYERS_D3D10)) {
|
2012-05-21 02:03:23 -07:00
|
|
|
nsAutoPtr<TextureD3D10BackendData> dat(new TextureD3D10BackendData());
|
2014-01-17 08:22:09 -08:00
|
|
|
dat->mTexture = SurfaceToTexture(device(), surf, cairoImage->GetSize());
|
2012-02-15 15:34:23 -08:00
|
|
|
|
|
|
|
if (dat->mTexture) {
|
2013-07-20 01:48:55 -07:00
|
|
|
device()->CreateShaderResourceView(dat->mTexture, nullptr, getter_AddRefs(dat->mSRView));
|
2012-07-18 09:31:40 -07:00
|
|
|
aImage->SetBackendData(mozilla::layers::LAYERS_D3D10, dat.forget());
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-17 08:22:09 -08:00
|
|
|
aHasAlpha = surf->GetContentType() == GFX_CONTENT_COLOR_ALPHA;
|
2013-05-04 03:12:40 -07:00
|
|
|
} else if (aImage->GetFormat() == ImageFormat::D3D9_RGB32_TEXTURE) {
|
|
|
|
if (!aImage->GetBackendData(mozilla::layers::LAYERS_D3D10)) {
|
|
|
|
// Use resource sharing to open the D3D9 texture as a D3D10 texture,
|
|
|
|
HRESULT hr;
|
|
|
|
D3D9SurfaceImage* d3dImage = reinterpret_cast<D3D9SurfaceImage*>(aImage);
|
|
|
|
nsRefPtr<ID3D10Texture2D> texture;
|
|
|
|
hr = device()->OpenSharedResource(d3dImage->GetShareHandle(),
|
|
|
|
IID_ID3D10Texture2D,
|
|
|
|
(void**)getter_AddRefs(texture));
|
|
|
|
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
|
|
|
|
|
|
|
|
nsAutoPtr<TextureD3D10BackendData> dat(new TextureD3D10BackendData());
|
|
|
|
dat->mTexture = texture;
|
|
|
|
|
2013-07-20 01:48:55 -07:00
|
|
|
hr = device()->CreateShaderResourceView(dat->mTexture, nullptr, getter_AddRefs(dat->mSRView));
|
2013-05-04 03:12:40 -07:00
|
|
|
NS_ENSURE_TRUE(SUCCEEDED(hr) && dat->mSRView, nullptr);
|
|
|
|
|
|
|
|
aImage->SetBackendData(mozilla::layers::LAYERS_D3D10, dat.forget());
|
|
|
|
}
|
|
|
|
aHasAlpha = false;
|
2012-02-15 15:34:23 -08:00
|
|
|
} else {
|
|
|
|
NS_WARNING("Incorrect image type.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TextureD3D10BackendData *data =
|
2012-07-18 09:31:40 -07:00
|
|
|
static_cast<TextureD3D10BackendData*>(aImage->GetBackendData(mozilla::layers::LAYERS_D3D10));
|
2012-02-15 15:34:23 -08:00
|
|
|
|
|
|
|
if (!data) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
|
|
|
|
2012-05-29 22:14:30 -07:00
|
|
|
if (aMutex &&
|
|
|
|
SUCCEEDED(data->mTexture->QueryInterface(IID_IDXGIKeyedMutex, (void**)aMutex))) {
|
|
|
|
if (FAILED((*aMutex)->AcquireSync(0, 0))) {
|
|
|
|
NS_WARNING("Failed to acquire sync on keyed mutex, plugin forgot to release?");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-29 22:14:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-15 15:34:23 -08:00
|
|
|
nsRefPtr<ID3D10Device> dev;
|
|
|
|
data->mTexture->GetDevice(getter_AddRefs(dev));
|
|
|
|
if (dev != device()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return data->mSRView;
|
|
|
|
}
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
void
|
2010-11-08 01:06:15 -08:00
|
|
|
ImageLayerD3D10::RenderLayer()
|
2010-09-30 15:53:49 -07:00
|
|
|
{
|
2012-02-15 19:26:19 -08:00
|
|
|
ImageContainer *container = GetContainer();
|
|
|
|
if (!container) {
|
2010-09-30 15:53:49 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
AutoLockImage autoLock(container);
|
|
|
|
|
|
|
|
Image *image = autoLock.GetImage();
|
2011-01-19 00:27:54 -08:00
|
|
|
if (!image) {
|
|
|
|
return;
|
|
|
|
}
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2013-12-13 09:32:02 -08:00
|
|
|
IntSize size = image->GetSize();
|
2012-03-12 18:41:29 -07:00
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
SetEffectTransformAndOpacity();
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
ID3D10EffectTechnique *technique;
|
2012-05-29 22:14:30 -07:00
|
|
|
nsRefPtr<IDXGIKeyedMutex> keyedMutex;
|
2014-01-22 14:18:13 -08:00
|
|
|
nsRefPtr<gfxASurface> surf = image->DeprecatedGetAsSurface();
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2013-05-04 03:12:40 -07:00
|
|
|
if (image->GetFormat() == ImageFormat::CAIRO_SURFACE ||
|
|
|
|
image->GetFormat() == ImageFormat::REMOTE_IMAGE_BITMAP ||
|
|
|
|
image->GetFormat() == ImageFormat::REMOTE_IMAGE_DXGI_TEXTURE ||
|
|
|
|
image->GetFormat() == ImageFormat::D3D9_RGB32_TEXTURE) {
|
2012-08-19 12:33:25 -07:00
|
|
|
NS_ASSERTION(image->GetFormat() != ImageFormat::CAIRO_SURFACE ||
|
2014-01-22 14:18:13 -08:00
|
|
|
!surf || surf->GetContentType() != GFX_CONTENT_ALPHA,
|
2012-06-25 19:43:31 -07:00
|
|
|
"Image layer has alpha image");
|
2012-02-15 19:26:19 -08:00
|
|
|
bool hasAlpha = false;
|
2010-12-15 12:37:15 -08:00
|
|
|
|
2012-05-29 22:14:30 -07:00
|
|
|
nsRefPtr<ID3D10ShaderResourceView> srView = GetImageSRView(image, hasAlpha, getter_AddRefs(keyedMutex));
|
2012-02-15 15:34:23 -08:00
|
|
|
if (!srView) {
|
2012-01-31 18:18:30 -08:00
|
|
|
return;
|
|
|
|
}
|
2012-07-18 09:31:40 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t shaderFlags = SHADER_PREMUL;
|
2012-03-01 09:29:30 -08:00
|
|
|
shaderFlags |= LoadMaskTexture();
|
|
|
|
shaderFlags |= hasAlpha
|
|
|
|
? SHADER_RGBA : SHADER_RGB;
|
2013-10-01 14:01:19 -07:00
|
|
|
shaderFlags |= mFilter == GraphicsFilter::FILTER_NEAREST
|
2012-03-01 09:29:30 -08:00
|
|
|
? SHADER_POINT : SHADER_LINEAR;
|
|
|
|
technique = SelectShader(shaderFlags);
|
|
|
|
|
2010-12-15 12:37:15 -08:00
|
|
|
|
2012-02-15 15:34:23 -08:00
|
|
|
effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(srView);
|
2010-12-15 12:37:15 -08:00
|
|
|
|
|
|
|
effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
|
|
|
|
ShaderConstantRectD3D10(
|
|
|
|
(float)0,
|
|
|
|
(float)0,
|
2012-02-15 19:26:19 -08:00
|
|
|
(float)size.width,
|
|
|
|
(float)size.height)
|
2010-12-15 12:37:15 -08:00
|
|
|
);
|
2012-08-19 12:33:25 -07:00
|
|
|
} else if (image->GetFormat() == ImageFormat::PLANAR_YCBCR) {
|
2012-01-31 18:18:30 -08:00
|
|
|
PlanarYCbCrImage *yuvImage =
|
2012-02-15 19:26:19 -08:00
|
|
|
static_cast<PlanarYCbCrImage*>(image);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2012-08-21 03:18:20 -07:00
|
|
|
if (!yuvImage->IsValid()) {
|
2010-09-30 15:53:49 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-18 09:31:40 -07:00
|
|
|
if (!yuvImage->GetBackendData(mozilla::layers::LAYERS_D3D10)) {
|
2012-01-31 18:18:30 -08:00
|
|
|
AllocateTexturesYCbCr(yuvImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlanarYCbCrD3D10BackendData *data =
|
2012-07-18 09:31:40 -07:00
|
|
|
static_cast<PlanarYCbCrD3D10BackendData*>(yuvImage->GetBackendData(mozilla::layers::LAYERS_D3D10));
|
2012-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Device> dev;
|
|
|
|
data->mYTexture->GetDevice(getter_AddRefs(dev));
|
|
|
|
if (dev != device()) {
|
|
|
|
return;
|
2011-01-11 16:52:29 -08:00
|
|
|
}
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
// TODO: At some point we should try to deal with mFilter here, you don't
|
|
|
|
// really want to use point filtering in the case of NEAREST, since that
|
|
|
|
// would also use point filtering for Chroma upsampling. Where most likely
|
|
|
|
// the user would only want point filtering for final RGB image upsampling.
|
|
|
|
|
2012-03-01 09:29:30 -08:00
|
|
|
technique = SelectShader(SHADER_YCBCR | LoadMaskTexture());
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
effect()->GetVariableByName("tY")->AsShaderResource()->SetResource(data->mYView);
|
|
|
|
effect()->GetVariableByName("tCb")->AsShaderResource()->SetResource(data->mCbView);
|
|
|
|
effect()->GetVariableByName("tCr")->AsShaderResource()->SetResource(data->mCrView);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2011-01-11 20:51:27 -08:00
|
|
|
/*
|
|
|
|
* Send 3d control data and metadata to NV3DVUtils
|
|
|
|
*/
|
|
|
|
if (GetNv3DVUtils()) {
|
|
|
|
Nv_Stereo_Mode mode;
|
2012-08-21 03:18:20 -07:00
|
|
|
switch (yuvImage->GetData()->mStereoMode) {
|
2011-01-11 20:51:27 -08:00
|
|
|
case STEREO_MODE_LEFT_RIGHT:
|
|
|
|
mode = NV_STEREO_MODE_LEFT_RIGHT;
|
|
|
|
break;
|
|
|
|
case STEREO_MODE_RIGHT_LEFT:
|
|
|
|
mode = NV_STEREO_MODE_RIGHT_LEFT;
|
|
|
|
break;
|
|
|
|
case STEREO_MODE_BOTTOM_TOP:
|
|
|
|
mode = NV_STEREO_MODE_BOTTOM_TOP;
|
|
|
|
break;
|
|
|
|
case STEREO_MODE_TOP_BOTTOM:
|
|
|
|
mode = NV_STEREO_MODE_TOP_BOTTOM;
|
|
|
|
break;
|
|
|
|
case STEREO_MODE_MONO:
|
|
|
|
mode = NV_STEREO_MODE_MONO;
|
|
|
|
break;
|
|
|
|
}
|
2013-05-04 03:12:40 -07:00
|
|
|
|
2011-01-11 20:51:27 -08:00
|
|
|
// Send control data even in mono case so driver knows to leave stereo mode.
|
|
|
|
GetNv3DVUtils()->SendNv3DVControl(mode, true, FIREFOX_3DV_APP_HANDLE);
|
|
|
|
|
2012-08-21 03:18:20 -07:00
|
|
|
if (yuvImage->GetData()->mStereoMode != STEREO_MODE_MONO) {
|
2011-01-11 20:51:27 -08:00
|
|
|
// Dst resource is optional
|
2012-08-21 03:18:20 -07:00
|
|
|
GetNv3DVUtils()->SendNv3DVMetaData((unsigned int)yuvImage->GetData()->mYSize.width,
|
2013-07-20 01:48:55 -07:00
|
|
|
(unsigned int)yuvImage->GetData()->mYSize.height, (HANDLE)(data->mYTexture), (HANDLE)(nullptr));
|
2011-01-11 20:51:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
|
|
|
|
ShaderConstantRectD3D10(
|
|
|
|
(float)0,
|
|
|
|
(float)0,
|
2012-03-12 18:41:29 -07:00
|
|
|
(float)size.width,
|
|
|
|
(float)size.height)
|
2010-09-30 15:53:49 -07:00
|
|
|
);
|
2011-07-04 19:52:50 -07:00
|
|
|
|
|
|
|
effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(
|
|
|
|
ShaderConstantRectD3D10(
|
2012-08-21 03:18:20 -07:00
|
|
|
(float)yuvImage->GetData()->mPicX / yuvImage->GetData()->mYSize.width,
|
|
|
|
(float)yuvImage->GetData()->mPicY / yuvImage->GetData()->mYSize.height,
|
|
|
|
(float)yuvImage->GetData()->mPicSize.width / yuvImage->GetData()->mYSize.width,
|
|
|
|
(float)yuvImage->GetData()->mPicSize.height / yuvImage->GetData()->mYSize.height)
|
2011-07-04 19:52:50 -07:00
|
|
|
);
|
2010-09-30 15:53:49 -07:00
|
|
|
}
|
2013-05-04 03:12:40 -07:00
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
bool resetTexCoords = image->GetFormat() == ImageFormat::PLANAR_YCBCR;
|
2012-07-30 07:20:58 -07:00
|
|
|
image = nullptr;
|
2012-02-15 19:26:19 -08:00
|
|
|
autoLock.Unlock();
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
technique->GetPassByIndex(0)->Apply(0);
|
|
|
|
device()->Draw(4, 0);
|
2011-03-23 15:28:57 -07:00
|
|
|
|
2012-05-29 22:14:30 -07:00
|
|
|
if (keyedMutex) {
|
|
|
|
keyedMutex->ReleaseSync(0);
|
|
|
|
}
|
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
if (resetTexCoords) {
|
2011-07-04 19:52:50 -07:00
|
|
|
effect()->GetVariableByName("vTextureCoords")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
|
|
|
|
}
|
|
|
|
|
2011-03-23 15:28:57 -07:00
|
|
|
GetContainer()->NotifyPaintedImage(image);
|
2010-09-30 15:53:49 -07:00
|
|
|
}
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
void ImageLayerD3D10::AllocateTexturesYCbCr(PlanarYCbCrImage *aImage)
|
2010-09-30 15:53:49 -07:00
|
|
|
{
|
2012-02-06 02:24:47 -08:00
|
|
|
nsAutoPtr<PlanarYCbCrD3D10BackendData> backendData(
|
|
|
|
new PlanarYCbCrD3D10BackendData);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2013-10-01 17:57:50 -07:00
|
|
|
const PlanarYCbCrData *data = aImage->GetData();
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
D3D10_SUBRESOURCE_DATA dataY;
|
|
|
|
D3D10_SUBRESOURCE_DATA dataCb;
|
|
|
|
D3D10_SUBRESOURCE_DATA dataCr;
|
2013-11-21 08:41:58 -08:00
|
|
|
CD3D10_TEXTURE2D_DESC descY(DXGI_FORMAT_A8_UNORM,
|
2012-08-21 03:18:20 -07:00
|
|
|
data->mYSize.width,
|
|
|
|
data->mYSize.height, 1, 1);
|
2013-11-21 08:41:58 -08:00
|
|
|
CD3D10_TEXTURE2D_DESC descCbCr(DXGI_FORMAT_A8_UNORM,
|
2012-08-21 03:18:20 -07:00
|
|
|
data->mCbCrSize.width,
|
|
|
|
data->mCbCrSize.height, 1, 1);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
descY.Usage = descCbCr.Usage = D3D10_USAGE_IMMUTABLE;
|
|
|
|
|
2012-08-21 03:18:20 -07:00
|
|
|
dataY.pSysMem = data->mYChannel;
|
|
|
|
dataY.SysMemPitch = data->mYStride;
|
|
|
|
dataCb.pSysMem = data->mCbChannel;
|
|
|
|
dataCb.SysMemPitch = data->mCbCrStride;
|
|
|
|
dataCr.pSysMem = data->mCrChannel;
|
|
|
|
dataCr.SysMemPitch = data->mCbCrStride;
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
HRESULT hr = device()->CreateTexture2D(&descY, &dataY, getter_AddRefs(backendData->mYTexture));
|
2011-11-03 12:10:10 -07:00
|
|
|
if (!FAILED(hr)) {
|
2012-01-31 18:18:30 -08:00
|
|
|
hr = device()->CreateTexture2D(&descCbCr, &dataCb, getter_AddRefs(backendData->mCbTexture));
|
2011-11-03 12:10:10 -07:00
|
|
|
}
|
|
|
|
if (!FAILED(hr)) {
|
2012-01-31 18:18:30 -08:00
|
|
|
hr = device()->CreateTexture2D(&descCbCr, &dataCr, getter_AddRefs(backendData->mCrTexture));
|
2011-11-03 12:10:10 -07:00
|
|
|
}
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
LayerManagerD3D10::ReportFailure(NS_LITERAL_CSTRING("PlanarYCbCrImageD3D10::AllocateTextures(): Failed to create texture"),
|
|
|
|
hr);
|
|
|
|
return;
|
|
|
|
}
|
2013-07-20 01:48:55 -07:00
|
|
|
device()->CreateShaderResourceView(backendData->mYTexture, nullptr, getter_AddRefs(backendData->mYView));
|
|
|
|
device()->CreateShaderResourceView(backendData->mCbTexture, nullptr, getter_AddRefs(backendData->mCbView));
|
|
|
|
device()->CreateShaderResourceView(backendData->mCrTexture, nullptr, getter_AddRefs(backendData->mCrView));
|
2011-01-03 09:05:47 -08:00
|
|
|
|
2012-07-18 09:31:40 -07:00
|
|
|
aImage->SetBackendData(mozilla::layers::LAYERS_D3D10, backendData.forget());
|
2010-09-30 15:53:49 -07:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:34:23 -08:00
|
|
|
already_AddRefed<ID3D10ShaderResourceView>
|
2013-12-20 08:46:29 -08:00
|
|
|
ImageLayerD3D10::GetAsTexture(gfx::IntSize* aSize)
|
2012-02-15 15:34:23 -08:00
|
|
|
{
|
|
|
|
if (!GetContainer()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoLockImage autoLock(GetContainer());
|
|
|
|
|
|
|
|
Image *image = autoLock.GetImage();
|
|
|
|
if (!image) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
if (image->GetFormat() != ImageFormat::CAIRO_SURFACE) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-02-15 15:34:23 -08:00
|
|
|
}
|
2013-05-04 03:12:40 -07:00
|
|
|
|
2013-12-31 01:06:12 -08:00
|
|
|
*aSize = image->GetSize();
|
2012-02-15 15:34:23 -08:00
|
|
|
bool dontCare;
|
|
|
|
nsRefPtr<ID3D10ShaderResourceView> result = GetImageSRView(image, dontCare);
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2012-05-29 22:14:30 -07:00
|
|
|
already_AddRefed<gfxASurface>
|
2014-01-15 07:06:43 -08:00
|
|
|
RemoteDXGITextureImage::DeprecatedGetAsSurface()
|
2012-05-29 22:14:30 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<ID3D10Device1> device =
|
|
|
|
gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
|
|
|
|
if (!device) {
|
|
|
|
NS_WARNING("Cannot readback from shared texture because no D3D10 device is available.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-29 22:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TextureD3D10BackendData* data = GetD3D10TextureBackendData(device);
|
|
|
|
|
|
|
|
if (!data) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-29 22:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDXGIKeyedMutex> keyedMutex;
|
|
|
|
|
|
|
|
if (FAILED(data->mTexture->QueryInterface(IID_IDXGIKeyedMutex, getter_AddRefs(keyedMutex)))) {
|
|
|
|
NS_WARNING("Failed to QueryInterface for IDXGIKeyedMutex, strange.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-29 22:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(keyedMutex->AcquireSync(0, 0))) {
|
|
|
|
NS_WARNING("Failed to acquire sync for keyedMutex, plugin failed to release?");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-29 22:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_TEXTURE2D_DESC desc;
|
|
|
|
|
|
|
|
data->mTexture->GetDesc(&desc);
|
|
|
|
|
|
|
|
desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
|
|
|
|
desc.BindFlags = 0;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.Usage = D3D10_USAGE_STAGING;
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Texture2D> softTexture;
|
2013-07-20 01:48:55 -07:00
|
|
|
HRESULT hr = device->CreateTexture2D(&desc, nullptr, getter_AddRefs(softTexture));
|
2012-05-29 22:14:30 -07:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create 2D staging texture.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-29 22:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
device->CopyResource(softTexture, data->mTexture);
|
|
|
|
keyedMutex->ReleaseSync(0);
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> surface =
|
2013-12-13 09:32:02 -08:00
|
|
|
new gfxImageSurface(ThebesIntSize(mSize),
|
|
|
|
mFormat == RemoteImageData::BGRX32 ?
|
|
|
|
gfxImageFormatRGB24 :
|
|
|
|
gfxImageFormatARGB32);
|
2012-05-29 22:14:30 -07:00
|
|
|
|
|
|
|
if (!surface->CairoSurface() || surface->CairoStatus()) {
|
|
|
|
NS_WARNING("Failed to created image surface for DXGI texture.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-29 22:14:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
D3D10_MAPPED_TEXTURE2D mapped;
|
|
|
|
softTexture->Map(0, D3D10_MAP_READ, 0, &mapped);
|
|
|
|
|
|
|
|
for (int y = 0; y < mSize.height; y++) {
|
|
|
|
memcpy(surface->Data() + surface->Stride() * y,
|
|
|
|
(unsigned char*)(mapped.pData) + mapped.RowPitch * y,
|
|
|
|
mSize.width * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
softTexture->Unmap(0);
|
|
|
|
|
|
|
|
return surface.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureD3D10BackendData*
|
|
|
|
RemoteDXGITextureImage::GetD3D10TextureBackendData(ID3D10Device *aDevice)
|
|
|
|
{
|
2012-07-18 09:31:40 -07:00
|
|
|
if (GetBackendData(mozilla::layers::LAYERS_D3D10)) {
|
2012-05-29 22:14:30 -07:00
|
|
|
TextureD3D10BackendData *data =
|
2012-07-18 09:31:40 -07:00
|
|
|
static_cast<TextureD3D10BackendData*>(GetBackendData(mozilla::layers::LAYERS_D3D10));
|
2013-05-04 03:12:40 -07:00
|
|
|
|
2012-05-29 22:14:30 -07:00
|
|
|
nsRefPtr<ID3D10Device> device;
|
|
|
|
data->mTexture->GetDevice(getter_AddRefs(device));
|
|
|
|
|
|
|
|
if (device == aDevice) {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsRefPtr<ID3D10Texture2D> texture;
|
|
|
|
aDevice->OpenSharedResource(mHandle, __uuidof(ID3D10Texture2D), getter_AddRefs(texture));
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
NS_WARNING("Failed to get texture for shared texture handle.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-29 22:14:30 -07:00
|
|
|
}
|
|
|
|
|
2012-06-04 04:02:02 -07:00
|
|
|
nsAutoPtr<TextureD3D10BackendData> data(new TextureD3D10BackendData());
|
2012-05-29 22:14:30 -07:00
|
|
|
|
|
|
|
data->mTexture = texture;
|
|
|
|
|
2013-07-20 01:48:55 -07:00
|
|
|
aDevice->CreateShaderResourceView(texture, nullptr, getter_AddRefs(data->mSRView));
|
2012-05-29 22:14:30 -07:00
|
|
|
|
2012-07-18 09:31:40 -07:00
|
|
|
SetBackendData(mozilla::layers::LAYERS_D3D10, data);
|
2012-05-29 22:14:30 -07:00
|
|
|
|
|
|
|
return data.forget();
|
|
|
|
}
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|