2010-08-06 22:09:18 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2010-05-24 08:28:51 -07:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Corporation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Bas Schouten <bschouten@mozilla.org>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-07-04 06:15:05 -07:00
|
|
|
#include "mozilla/layers/PLayers.h"
|
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
|
|
|
#include "ShadowBufferD3D9.h"
|
|
|
|
#include "gfxSharedImageSurface.h"
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
#include "ImageLayerD3D9.h"
|
2011-07-04 06:15:05 -07:00
|
|
|
#include "ThebesLayerD3D9.h"
|
|
|
|
#include "gfxPlatform.h"
|
2010-05-24 08:28:51 -07:00
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "yuv_convert.h"
|
2010-08-26 13:44:53 -07:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "Nv3DVUtils.h"
|
2010-05-24 08:28:51 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2010-12-20 14:37:01 -08:00
|
|
|
static already_AddRefed<IDirect3DTexture9>
|
2012-02-15 19:26:19 -08:00
|
|
|
DataToTexture(IDirect3DDevice9 *aDevice,
|
|
|
|
unsigned char *aData,
|
|
|
|
int aStride,
|
|
|
|
const gfxIntSize &aSize)
|
2010-12-20 14:37:01 -08:00
|
|
|
{
|
|
|
|
nsRefPtr<IDirect3DTexture9> texture;
|
|
|
|
nsRefPtr<IDirect3DDevice9Ex> deviceEx;
|
2010-12-21 02:52:00 -08:00
|
|
|
aDevice->QueryInterface(IID_IDirect3DDevice9Ex,
|
2010-12-20 14:37:01 -08:00
|
|
|
(void**)getter_AddRefs(deviceEx));
|
|
|
|
|
|
|
|
if (deviceEx) {
|
|
|
|
// D3D9Ex doesn't support managed textures. We could use dynamic textures
|
|
|
|
// here but since Images are immutable that probably isn't such a great
|
|
|
|
// idea.
|
|
|
|
if (FAILED(aDevice->
|
|
|
|
CreateTexture(aSize.width, aSize.height,
|
|
|
|
1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
|
|
|
|
getter_AddRefs(texture), NULL)))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDirect3DSurface9> surface;
|
|
|
|
if (FAILED(aDevice->
|
|
|
|
CreateOffscreenPlainSurface(aSize.width,
|
|
|
|
aSize.height,
|
|
|
|
D3DFMT_A8R8G8B8,
|
|
|
|
D3DPOOL_SYSTEMMEM,
|
|
|
|
getter_AddRefs(surface),
|
|
|
|
NULL)))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3DLOCKED_RECT lockedRect;
|
|
|
|
surface->LockRect(&lockedRect, NULL, 0);
|
|
|
|
for (int y = 0; y < aSize.height; y++) {
|
|
|
|
memcpy((char*)lockedRect.pBits + lockedRect.Pitch * y,
|
2012-02-15 19:26:19 -08:00
|
|
|
aData + aStride * y,
|
2010-12-20 14:37:01 -08:00
|
|
|
aSize.width * 4);
|
|
|
|
}
|
|
|
|
surface->UnlockRect();
|
|
|
|
nsRefPtr<IDirect3DSurface9> dstSurface;
|
|
|
|
texture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
|
|
|
|
aDevice->UpdateSurface(surface, NULL, dstSurface, NULL);
|
|
|
|
} else {
|
|
|
|
if (FAILED(aDevice->
|
|
|
|
CreateTexture(aSize.width, aSize.height,
|
|
|
|
1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
|
|
|
|
getter_AddRefs(texture), NULL)))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3DLOCKED_RECT lockrect;
|
|
|
|
/* lock the entire texture */
|
|
|
|
texture->LockRect(0, &lockrect, NULL, 0);
|
|
|
|
|
|
|
|
// copy over data. If we don't need to do any swaping we can
|
|
|
|
// use memcpy
|
|
|
|
for (int y = 0; y < aSize.height; y++) {
|
|
|
|
memcpy((char*)lockrect.pBits + lockrect.Pitch * y,
|
2012-02-15 19:26:19 -08:00
|
|
|
aData + aStride * y,
|
2010-12-20 14:37:01 -08:00
|
|
|
aSize.width * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
texture->UnlockRect(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture.forget();
|
|
|
|
}
|
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
static already_AddRefed<IDirect3DTexture9>
|
|
|
|
SurfaceToTexture(IDirect3DDevice9 *aDevice,
|
|
|
|
gfxASurface *aSurface,
|
|
|
|
const gfxIntSize &aSize)
|
|
|
|
{
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> imageSurface = aSurface->GetAsImageSurface();
|
|
|
|
|
|
|
|
if (!imageSurface) {
|
|
|
|
imageSurface = new gfxImageSurface(aSize,
|
|
|
|
gfxASurface::ImageFormatARGB32);
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(imageSurface);
|
|
|
|
context->SetSource(aSurface);
|
|
|
|
context->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
context->Paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
return DataToTexture(aDevice, imageSurface->Data(), imageSurface->Stride(), aSize);
|
|
|
|
}
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
static void AllocateTexturesYCbCr(PlanarYCbCrImage *aImage,
|
|
|
|
IDirect3DDevice9 *aDevice,
|
|
|
|
LayerManagerD3D9 *aManager)
|
2010-05-24 08:28:51 -07:00
|
|
|
{
|
2012-02-06 02:24:47 -08:00
|
|
|
nsAutoPtr<PlanarYCbCrD3D9BackendData> backendData(
|
|
|
|
new PlanarYCbCrD3D9BackendData);
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
PlanarYCbCrImage::Data &data = aImage->mData;
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
D3DLOCKED_RECT lockrectY;
|
|
|
|
D3DLOCKED_RECT lockrectCb;
|
|
|
|
D3DLOCKED_RECT lockrectCr;
|
|
|
|
PRUint8* src;
|
|
|
|
PRUint8* dest;
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
nsRefPtr<IDirect3DSurface9> tmpSurfaceY;
|
|
|
|
nsRefPtr<IDirect3DSurface9> tmpSurfaceCb;
|
|
|
|
nsRefPtr<IDirect3DSurface9> tmpSurfaceCr;
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
nsRefPtr<IDirect3DDevice9Ex> deviceEx;
|
|
|
|
aDevice->QueryInterface(IID_IDirect3DDevice9Ex,
|
|
|
|
getter_AddRefs(deviceEx));
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
bool isD3D9Ex = deviceEx;
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
if (isD3D9Ex) {
|
|
|
|
nsRefPtr<IDirect3DTexture9> tmpYTexture;
|
|
|
|
nsRefPtr<IDirect3DTexture9> tmpCbTexture;
|
|
|
|
nsRefPtr<IDirect3DTexture9> tmpCrTexture;
|
|
|
|
// D3D9Ex does not support the managed pool, could use dynamic textures
|
|
|
|
// here. But since an Image is immutable static textures are probably a
|
|
|
|
// better idea.
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
hr = aDevice->CreateTexture(data.mYSize.width, data.mYSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
|
|
|
|
getter_AddRefs(backendData->mYTexture), NULL);
|
|
|
|
if (!FAILED(hr)) {
|
|
|
|
hr = aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
|
|
|
|
getter_AddRefs(backendData->mCbTexture), NULL);
|
|
|
|
}
|
|
|
|
if (!FAILED(hr)) {
|
|
|
|
hr = aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
|
|
|
|
getter_AddRefs(backendData->mCrTexture), NULL);
|
|
|
|
}
|
|
|
|
if (!FAILED(hr)) {
|
|
|
|
hr = aDevice->CreateTexture(data.mYSize.width, data.mYSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
|
|
|
|
getter_AddRefs(tmpYTexture), NULL);
|
|
|
|
}
|
|
|
|
if (!FAILED(hr)) {
|
|
|
|
hr = aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
|
|
|
|
getter_AddRefs(tmpCbTexture), NULL);
|
|
|
|
}
|
|
|
|
if (!FAILED(hr)) {
|
|
|
|
hr = aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
|
|
|
|
getter_AddRefs(tmpCrTexture), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
aManager->ReportFailure(NS_LITERAL_CSTRING("PlanarYCbCrImageD3D9::AllocateTextures(): Failed to create texture (isD3D9Ex)"),
|
|
|
|
hr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpYTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceY));
|
|
|
|
tmpCbTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceCb));
|
|
|
|
tmpCrTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceCr));
|
|
|
|
tmpSurfaceY->LockRect(&lockrectY, NULL, 0);
|
|
|
|
tmpSurfaceCb->LockRect(&lockrectCb, NULL, 0);
|
|
|
|
tmpSurfaceCr->LockRect(&lockrectCr, NULL, 0);
|
|
|
|
} else {
|
|
|
|
HRESULT hr;
|
|
|
|
hr = aDevice->CreateTexture(data.mYSize.width, data.mYSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
|
|
|
|
getter_AddRefs(backendData->mYTexture), NULL);
|
|
|
|
if (!FAILED(hr)) {
|
|
|
|
aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
|
|
|
|
getter_AddRefs(backendData->mCbTexture), NULL);
|
|
|
|
}
|
|
|
|
if (!FAILED(hr)) {
|
|
|
|
aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
|
|
|
|
1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
|
|
|
|
getter_AddRefs(backendData->mCrTexture), NULL);
|
|
|
|
}
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
aManager->ReportFailure(NS_LITERAL_CSTRING("PlanarYCbCrImageD3D9::AllocateTextures(): Failed to create texture (!isD3D9Ex)"),
|
|
|
|
hr);
|
|
|
|
return;
|
2010-05-24 08:28:51 -07:00
|
|
|
}
|
2012-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
/* lock the entire texture */
|
|
|
|
backendData->mYTexture->LockRect(0, &lockrectY, NULL, 0);
|
|
|
|
backendData->mCbTexture->LockRect(0, &lockrectCb, NULL, 0);
|
|
|
|
backendData->mCrTexture->LockRect(0, &lockrectCr, NULL, 0);
|
2010-05-24 08:28:51 -07:00
|
|
|
}
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
src = data.mYChannel;
|
|
|
|
//FIX cast
|
|
|
|
dest = (PRUint8*)lockrectY.pBits;
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
// copy over data
|
|
|
|
for (int h=0; h<data.mYSize.height; h++) {
|
|
|
|
memcpy(dest, src, data.mYSize.width);
|
|
|
|
dest += lockrectY.Pitch;
|
|
|
|
src += data.mYStride;
|
2010-05-24 08:28:51 -07:00
|
|
|
}
|
2012-01-31 18:18:30 -08:00
|
|
|
|
|
|
|
src = data.mCbChannel;
|
|
|
|
//FIX cast
|
|
|
|
dest = (PRUint8*)lockrectCb.pBits;
|
|
|
|
|
|
|
|
// copy over data
|
|
|
|
for (int h=0; h<data.mCbCrSize.height; h++) {
|
|
|
|
memcpy(dest, src, data.mCbCrSize.width);
|
|
|
|
dest += lockrectCb.Pitch;
|
|
|
|
src += data.mCbCrStride;
|
2010-05-24 08:28:51 -07:00
|
|
|
}
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
src = data.mCrChannel;
|
|
|
|
//FIX cast
|
|
|
|
dest = (PRUint8*)lockrectCr.pBits;
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
// copy over data
|
|
|
|
for (int h=0; h<data.mCbCrSize.height; h++) {
|
|
|
|
memcpy(dest, src, data.mCbCrSize.width);
|
|
|
|
dest += lockrectCr.Pitch;
|
|
|
|
src += data.mCbCrStride;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isD3D9Ex) {
|
|
|
|
tmpSurfaceY->UnlockRect();
|
|
|
|
tmpSurfaceCb->UnlockRect();
|
|
|
|
tmpSurfaceCr->UnlockRect();
|
|
|
|
nsRefPtr<IDirect3DSurface9> dstSurface;
|
|
|
|
backendData->mYTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
|
|
|
|
aDevice->UpdateSurface(tmpSurfaceY, NULL, dstSurface, NULL);
|
|
|
|
backendData->mCbTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
|
|
|
|
aDevice->UpdateSurface(tmpSurfaceCb, NULL, dstSurface, NULL);
|
|
|
|
backendData->mCrTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
|
|
|
|
aDevice->UpdateSurface(tmpSurfaceCr, NULL, dstSurface, NULL);
|
|
|
|
} else {
|
|
|
|
backendData->mYTexture->UnlockRect(0);
|
|
|
|
backendData->mCbTexture->UnlockRect(0);
|
|
|
|
backendData->mCrTexture->UnlockRect(0);
|
2010-12-20 14:37:30 -08:00
|
|
|
}
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
aImage->SetBackendData(LayerManager::LAYERS_D3D9, backendData.forget());
|
2010-08-06 22:09:18 -07:00
|
|
|
}
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
Layer*
|
|
|
|
ImageLayerD3D9::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
/*
|
|
|
|
* Returns a texture which backs aImage
|
|
|
|
* Will only work if aImage is a cairo or remote image.
|
|
|
|
* Returns nsnull if unsuccessful.
|
|
|
|
* If successful, aHasAlpha will be set to true if the texture has an
|
|
|
|
* alpha component, false otherwise.
|
|
|
|
*/
|
|
|
|
IDirect3DTexture9*
|
|
|
|
ImageLayerD3D9::GetTexture(Image *aImage, bool& aHasAlpha)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aImage, "Null image.");
|
|
|
|
|
|
|
|
if (aImage->GetFormat() == Image::REMOTE_IMAGE_BITMAP) {
|
|
|
|
RemoteBitmapImage *remoteImage =
|
|
|
|
static_cast<RemoteBitmapImage*>(aImage);
|
|
|
|
|
|
|
|
if (!aImage->GetBackendData(LayerManager::LAYERS_D3D9)) {
|
|
|
|
nsAutoPtr<TextureD3D9BackendData> dat = new TextureD3D9BackendData();
|
|
|
|
dat->mTexture = DataToTexture(device(), remoteImage->mData, remoteImage->mStride, remoteImage->mSize);
|
|
|
|
if (dat->mTexture) {
|
|
|
|
aImage->SetBackendData(LayerManager::LAYERS_D3D9, dat.forget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aHasAlpha = remoteImage->mFormat == RemoteImageData::BGRA32;
|
|
|
|
} else if (aImage->GetFormat() == Image::CAIRO_SURFACE) {
|
|
|
|
CairoImage *cairoImage =
|
|
|
|
static_cast<CairoImage*>(aImage);
|
|
|
|
|
|
|
|
if (!cairoImage->mSurface) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aImage->GetBackendData(LayerManager::LAYERS_D3D9)) {
|
|
|
|
nsAutoPtr<TextureD3D9BackendData> dat = new TextureD3D9BackendData();
|
|
|
|
dat->mTexture = SurfaceToTexture(device(), cairoImage->mSurface, cairoImage->mSize);
|
|
|
|
if (dat->mTexture) {
|
|
|
|
aImage->SetBackendData(LayerManager::LAYERS_D3D9, dat.forget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aHasAlpha = cairoImage->mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA;
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Inappropriate image type.");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureD3D9BackendData *data =
|
|
|
|
static_cast<TextureD3D9BackendData*>(aImage->GetBackendData(LayerManager::LAYERS_D3D9));
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDirect3DDevice9> dev;
|
|
|
|
data->mTexture->GetDevice(getter_AddRefs(dev));
|
|
|
|
if (dev != device()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data->mTexture;
|
|
|
|
}
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
void
|
2010-11-08 01:06:15 -08:00
|
|
|
ImageLayerD3D9::RenderLayer()
|
2010-05-24 08:28:51 -07:00
|
|
|
{
|
2012-02-15 19:26:19 -08:00
|
|
|
ImageContainer *container = GetContainer();
|
|
|
|
if (!container) {
|
2010-05-24 08:28:51 -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-12-20 14:37:30 -08:00
|
|
|
SetShaderTransformAndOpacity();
|
|
|
|
|
2012-03-12 18:41:29 -07:00
|
|
|
gfxIntSize size = mScaleMode == SCALE_NONE ? image->GetSize() : mScaleToSize;
|
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
if (image->GetFormat() == Image::CAIRO_SURFACE ||
|
|
|
|
image->GetFormat() == Image::REMOTE_IMAGE_BITMAP)
|
2010-12-28 17:07:04 -08:00
|
|
|
{
|
2012-02-15 19:26:19 -08:00
|
|
|
bool hasAlpha = false;
|
2012-03-06 13:07:48 -08:00
|
|
|
nsRefPtr<IDirect3DTexture9> texture = GetTexture(image, hasAlpha);
|
2012-01-31 18:18:30 -08:00
|
|
|
|
2010-12-20 14:37:30 -08:00
|
|
|
device()->SetVertexShaderConstantF(CBvLayerQuad,
|
|
|
|
ShaderConstantRect(0,
|
|
|
|
0,
|
|
|
|
size.width,
|
|
|
|
size.height),
|
|
|
|
1);
|
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
if (hasAlpha) {
|
2012-03-06 13:07:48 -08:00
|
|
|
mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER, GetMaskLayer());
|
2010-12-20 14:37:30 -08:00
|
|
|
} else {
|
2012-03-06 13:07:48 -08:00
|
|
|
mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER, GetMaskLayer());
|
2010-12-20 14:37:30 -08:00
|
|
|
}
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
if (mFilter == gfxPattern::FILTER_NEAREST) {
|
|
|
|
device()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
|
|
|
|
device()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
|
|
|
}
|
2012-03-06 13:07:48 -08:00
|
|
|
device()->SetTexture(0, texture);
|
2012-02-15 19:26:19 -08:00
|
|
|
|
|
|
|
image = nsnull;
|
|
|
|
autoLock.Unlock();
|
|
|
|
|
2010-12-20 14:37:30 -08:00
|
|
|
device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
2012-01-31 18:18:30 -08:00
|
|
|
if (mFilter == gfxPattern::FILTER_NEAREST) {
|
|
|
|
device()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
|
|
|
device()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PlanarYCbCrImage *yuvImage =
|
2012-02-15 19:26:19 -08:00
|
|
|
static_cast<PlanarYCbCrImage*>(image);
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
if (!yuvImage->mBufferSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!yuvImage->GetBackendData(LayerManager::LAYERS_D3D9)) {
|
|
|
|
AllocateTexturesYCbCr(yuvImage, device(), mD3DManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlanarYCbCrD3D9BackendData *data =
|
|
|
|
static_cast<PlanarYCbCrD3D9BackendData*>(yuvImage->GetBackendData(LayerManager::LAYERS_D3D9));
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDirect3DDevice9> dev;
|
|
|
|
data->mYTexture->GetDevice(getter_AddRefs(dev));
|
|
|
|
if (dev != device()) {
|
2010-05-24 08:28:51 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-01 15:24:58 -07:00
|
|
|
device()->SetVertexShaderConstantF(CBvLayerQuad,
|
|
|
|
ShaderConstantRect(0,
|
|
|
|
0,
|
2012-03-12 18:41:29 -07:00
|
|
|
size.width,
|
|
|
|
size.height),
|
2010-10-01 15:24:58 -07:00
|
|
|
1);
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2011-07-04 19:52:34 -07:00
|
|
|
device()->SetVertexShaderConstantF(CBvTextureCoords,
|
|
|
|
ShaderConstantRect(
|
|
|
|
(float)yuvImage->mData.mPicX / yuvImage->mData.mYSize.width,
|
|
|
|
(float)yuvImage->mData.mPicY / yuvImage->mData.mYSize.height,
|
|
|
|
(float)yuvImage->mData.mPicSize.width / yuvImage->mData.mYSize.width,
|
|
|
|
(float)yuvImage->mData.mPicSize.height / yuvImage->mData.mYSize.height
|
|
|
|
),
|
|
|
|
1);
|
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
mD3DManager->SetShaderMode(DeviceManagerD3D9::YCBCRLAYER, GetMaskLayer());
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2011-01-11 20:51:27 -08:00
|
|
|
/*
|
|
|
|
* Send 3d control data and metadata
|
|
|
|
*/
|
|
|
|
if (mD3DManager->GetNv3DVUtils()) {
|
2010-11-02 16:43:29 -07:00
|
|
|
Nv_Stereo_Mode mode;
|
|
|
|
switch (yuvImage->mData.mStereoMode) {
|
|
|
|
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;
|
2011-01-11 20:51:27 -08:00
|
|
|
case STEREO_MODE_MONO:
|
|
|
|
mode = NV_STEREO_MODE_MONO;
|
|
|
|
break;
|
2010-11-02 16:43:29 -07:00
|
|
|
}
|
|
|
|
|
2011-01-11 20:51:27 -08:00
|
|
|
// Send control data even in mono case so driver knows to leave stereo mode.
|
|
|
|
mD3DManager->GetNv3DVUtils()->SendNv3DVControl(mode, true, FIREFOX_3DV_APP_HANDLE);
|
|
|
|
|
|
|
|
if (yuvImage->mData.mStereoMode != STEREO_MODE_MONO) {
|
2010-11-02 16:43:29 -07:00
|
|
|
mD3DManager->GetNv3DVUtils()->SendNv3DVControl(mode, true, FIREFOX_3DV_APP_HANDLE);
|
|
|
|
|
|
|
|
nsRefPtr<IDirect3DSurface9> renderTarget;
|
|
|
|
device()->GetRenderTarget(0, getter_AddRefs(renderTarget));
|
|
|
|
mD3DManager->GetNv3DVUtils()->SendNv3DVMetaData((unsigned int)yuvImage->mSize.width,
|
2012-01-31 18:18:30 -08:00
|
|
|
(unsigned int)yuvImage->mSize.height, (HANDLE)(data->mYTexture), (HANDLE)(renderTarget));
|
2010-11-02 16:43:29 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-26 13:44:53 -07:00
|
|
|
|
2010-12-29 11:22:18 -08:00
|
|
|
// Linear scaling is default here, adhering to mFilter is difficult since
|
|
|
|
// presumably even with point filtering we'll still want chroma upsampling
|
|
|
|
// to be linear. In the current approach we can't.
|
2012-01-31 18:18:30 -08:00
|
|
|
device()->SetTexture(0, data->mYTexture);
|
|
|
|
device()->SetTexture(1, data->mCbTexture);
|
|
|
|
device()->SetTexture(2, data->mCrTexture);
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-02-15 19:26:19 -08:00
|
|
|
image = nsnull;
|
|
|
|
data = nsnull;
|
|
|
|
autoLock.Unlock();
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
|
|
|
|
2011-07-04 19:52:34 -07:00
|
|
|
device()->SetVertexShaderConstantF(CBvTextureCoords,
|
|
|
|
ShaderConstantRect(0, 0, 1.0f, 1.0f), 1);
|
2010-05-24 08:28:51 -07:00
|
|
|
}
|
2011-03-23 15:28:57 -07:00
|
|
|
|
|
|
|
GetContainer()->NotifyPaintedImage(image);
|
2010-05-24 08:28:51 -07:00
|
|
|
}
|
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
already_AddRefed<IDirect3DTexture9>
|
|
|
|
ImageLayerD3D9::GetAsTexture(gfxIntSize* aSize)
|
|
|
|
{
|
|
|
|
if (!GetContainer()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoLockImage autoLock(GetContainer());
|
|
|
|
|
|
|
|
Image *image = autoLock.GetImage();
|
|
|
|
|
|
|
|
if (!image) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (image->GetFormat() != Image::CAIRO_SURFACE &&
|
|
|
|
image->GetFormat() != Image::REMOTE_IMAGE_BITMAP) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dontCare;
|
|
|
|
*aSize = image->GetSize();
|
|
|
|
nsRefPtr<IDirect3DTexture9> result = GetTexture(image, dontCare);
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-04 06:15:05 -07:00
|
|
|
ShadowImageLayerD3D9::ShadowImageLayerD3D9(LayerManagerD3D9* aManager)
|
|
|
|
: ShadowImageLayer(aManager, nsnull)
|
|
|
|
, LayerD3D9(aManager)
|
|
|
|
{
|
|
|
|
mImplData = static_cast<LayerD3D9*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShadowImageLayerD3D9::~ShadowImageLayerD3D9()
|
|
|
|
{}
|
|
|
|
|
2011-09-27 15:19:26 -07:00
|
|
|
void
|
|
|
|
ShadowImageLayerD3D9::Swap(const SharedImage& aNewFront,
|
|
|
|
SharedImage* aNewBack)
|
2011-07-04 06:15:05 -07:00
|
|
|
{
|
2011-09-27 15:19:26 -07:00
|
|
|
if (aNewFront.type() == SharedImage::TSurfaceDescriptor) {
|
2011-07-04 06:15:05 -07:00
|
|
|
if (!mBuffer) {
|
|
|
|
mBuffer = new ShadowBufferD3D9(this);
|
|
|
|
}
|
2011-09-27 15:19:26 -07:00
|
|
|
nsRefPtr<gfxASurface> surf =
|
2011-07-04 06:15:05 -07:00
|
|
|
ShadowLayerForwarder::OpenDescriptor(aNewFront.get_SurfaceDescriptor());
|
|
|
|
|
2011-09-27 15:19:26 -07:00
|
|
|
mBuffer->Upload(surf, GetVisibleRegion().GetBounds());
|
|
|
|
} else {
|
2011-07-04 06:15:05 -07:00
|
|
|
const YUVImage& yuv = aNewFront.get_YUVImage();
|
|
|
|
|
|
|
|
nsRefPtr<gfxSharedImageSurface> surfY =
|
|
|
|
gfxSharedImageSurface::Open(yuv.Ydata());
|
|
|
|
nsRefPtr<gfxSharedImageSurface> surfU =
|
|
|
|
gfxSharedImageSurface::Open(yuv.Udata());
|
|
|
|
nsRefPtr<gfxSharedImageSurface> surfV =
|
|
|
|
gfxSharedImageSurface::Open(yuv.Vdata());
|
|
|
|
|
|
|
|
PlanarYCbCrImage::Data data;
|
|
|
|
data.mYChannel = surfY->Data();
|
|
|
|
data.mYStride = surfY->Stride();
|
|
|
|
data.mYSize = surfY->GetSize();
|
|
|
|
data.mCbChannel = surfU->Data();
|
|
|
|
data.mCrChannel = surfV->Data();
|
|
|
|
data.mCbCrStride = surfU->Stride();
|
|
|
|
data.mCbCrSize = surfU->GetSize();
|
|
|
|
data.mPicSize = surfY->GetSize();
|
|
|
|
data.mPicX = 0;
|
|
|
|
data.mPicY = 0;
|
|
|
|
|
2011-09-27 15:19:26 -07:00
|
|
|
if (!mYCbCrImage) {
|
2012-01-31 18:18:30 -08:00
|
|
|
mYCbCrImage = new PlanarYCbCrImage(new BufferRecycleBin());
|
2011-09-27 15:19:26 -07:00
|
|
|
}
|
|
|
|
|
2011-07-04 06:15:05 -07:00
|
|
|
mYCbCrImage->SetData(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNewBack = aNewFront;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowImageLayerD3D9::Disconnect()
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowImageLayerD3D9::Destroy()
|
|
|
|
{
|
|
|
|
mBuffer = nsnull;
|
|
|
|
mYCbCrImage = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer*
|
|
|
|
ShadowImageLayerD3D9::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowImageLayerD3D9::RenderLayer()
|
|
|
|
{
|
|
|
|
if (mBuffer) {
|
|
|
|
mBuffer->RenderTo(mD3DManager, GetEffectiveVisibleRegion());
|
|
|
|
} else if (mYCbCrImage) {
|
2012-01-31 18:18:30 -08:00
|
|
|
if (!mYCbCrImage->mBufferSize) {
|
2011-07-04 06:15:05 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
if (!mYCbCrImage->GetBackendData(LayerManager::LAYERS_D3D9)) {
|
|
|
|
AllocateTexturesYCbCr(mYCbCrImage, device(), mD3DManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlanarYCbCrD3D9BackendData *data =
|
|
|
|
static_cast<PlanarYCbCrD3D9BackendData*>(mYCbCrImage->GetBackendData(LayerManager::LAYERS_D3D9));
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mYCbCrImage->mBufferSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-04 06:15:05 -07:00
|
|
|
SetShaderTransformAndOpacity();
|
|
|
|
|
|
|
|
device()->SetVertexShaderConstantF(CBvLayerQuad,
|
|
|
|
ShaderConstantRect(0,
|
|
|
|
0,
|
|
|
|
mYCbCrImage->mSize.width,
|
|
|
|
mYCbCrImage->mSize.height),
|
|
|
|
1);
|
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
mD3DManager->SetShaderMode(DeviceManagerD3D9::YCBCRLAYER, GetMaskLayer());
|
2011-07-04 06:15:05 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send 3d control data and metadata
|
|
|
|
*/
|
|
|
|
if (mD3DManager->GetNv3DVUtils()) {
|
|
|
|
// TODO Add 3D support
|
|
|
|
}
|
|
|
|
|
|
|
|
// Linear scaling is default here, adhering to mFilter is difficult since
|
|
|
|
// presumably even with point filtering we'll still want chroma upsampling
|
|
|
|
// to be linear. In the current approach we can't.
|
2012-01-31 18:18:30 -08:00
|
|
|
device()->SetTexture(0, data->mYTexture);
|
|
|
|
device()->SetTexture(1, data->mCbTexture);
|
|
|
|
device()->SetTexture(2, data->mCrTexture);
|
2011-07-04 06:15:05 -07:00
|
|
|
|
|
|
|
device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Unexpected image format.");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-18 16:02:38 -07:00
|
|
|
already_AddRefed<IDirect3DTexture9>
|
|
|
|
ShadowImageLayerD3D9::GetAsTexture(gfxIntSize* aSize)
|
|
|
|
{
|
|
|
|
if (!mBuffer) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSize = mBuffer->GetSize();
|
|
|
|
nsRefPtr<IDirect3DTexture9> result = mBuffer->GetTexture();
|
|
|
|
return result.forget();
|
|
|
|
}
|
2011-07-04 06:15:05 -07:00
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|