2010-08-10 16:32:45 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
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-08-10 16:32:45 -07:00
|
|
|
|
|
|
|
#include "DeviceManagerD3D9.h"
|
|
|
|
#include "LayerManagerD3D9Shaders.h"
|
|
|
|
#include "ThebesLayerD3D9.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsPrintfCString.h"
|
2010-08-26 13:44:53 -07:00
|
|
|
#include "Nv3DVUtils.h"
|
2010-09-17 11:57:46 -07:00
|
|
|
#include "plstr.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2013-12-20 08:46:29 -08:00
|
|
|
#include "gfx2DGlue.h"
|
2013-08-04 00:46:17 -07:00
|
|
|
#include "gfxPlatform.h"
|
2013-11-21 14:07:56 -08:00
|
|
|
#include "gfxWindowsPlatform.h"
|
2013-11-21 14:07:56 -08:00
|
|
|
#include "TextureD3D9.h"
|
|
|
|
#include "mozilla/gfx/Point.h"
|
|
|
|
|
2013-12-20 08:46:29 -08:00
|
|
|
using namespace mozilla::gfx;
|
2010-08-10 16:32:45 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
const LPCWSTR kClassName = L"D3D9WindowClass";
|
|
|
|
|
2010-08-10 16:39:45 -07:00
|
|
|
#define USE_D3D9EX
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
struct vertex {
|
|
|
|
float x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
SwapChainD3D9::SwapChainD3D9(DeviceManagerD3D9 *aDeviceManager)
|
|
|
|
: mDeviceManager(aDeviceManager)
|
|
|
|
, mWnd(0)
|
|
|
|
{
|
|
|
|
mDeviceManager->mSwapChains.AppendElement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
SwapChainD3D9::~SwapChainD3D9()
|
|
|
|
{
|
|
|
|
mDeviceManager->mSwapChains.RemoveElement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SwapChainD3D9::Init(HWND hWnd)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
::GetClientRect(hWnd, &r);
|
|
|
|
|
|
|
|
mWnd = hWnd;
|
|
|
|
|
|
|
|
D3DPRESENT_PARAMETERS pp;
|
|
|
|
memset(&pp, 0, sizeof(D3DPRESENT_PARAMETERS));
|
|
|
|
|
2010-08-12 11:25:12 -07:00
|
|
|
pp.BackBufferFormat = D3DFMT_A8R8G8B8;
|
2010-08-10 16:32:45 -07:00
|
|
|
pp.SwapEffect = D3DSWAPEFFECT_COPY;
|
|
|
|
pp.Windowed = TRUE;
|
|
|
|
pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
|
|
pp.hDeviceWindow = mWnd;
|
|
|
|
if (r.left == r.right || r.top == r.bottom) {
|
|
|
|
pp.BackBufferHeight = 1;
|
|
|
|
pp.BackBufferWidth = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = mDeviceManager->device()->
|
|
|
|
CreateAdditionalSwapChain(&pp,
|
|
|
|
getter_AddRefs(mSwapChain));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create swap chain for window.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
already_AddRefed<IDirect3DSurface9>
|
|
|
|
SwapChainD3D9::GetBackBuffer()
|
|
|
|
{
|
|
|
|
nsRefPtr<IDirect3DSurface9> backBuffer;
|
|
|
|
mSwapChain->GetBackBuffer(0,
|
|
|
|
D3DBACKBUFFER_TYPE_MONO,
|
|
|
|
getter_AddRefs(backBuffer));
|
|
|
|
return backBuffer.forget();
|
|
|
|
}
|
|
|
|
|
2013-11-21 14:07:57 -08:00
|
|
|
DeviceManagerState
|
2010-08-10 16:32:45 -07:00
|
|
|
SwapChainD3D9::PrepareForRendering()
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
if (!::GetClientRect(mWnd, &r)) {
|
2013-11-21 14:07:57 -08:00
|
|
|
return DeviceFail;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
2013-11-21 14:07:57 -08:00
|
|
|
DeviceManagerState deviceState = mDeviceManager->VerifyReadyForRendering();
|
|
|
|
if (deviceState != DeviceOK) {
|
|
|
|
return deviceState;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mSwapChain) {
|
|
|
|
Init(mWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSwapChain) {
|
2013-08-04 00:46:17 -07:00
|
|
|
nsRefPtr<IDirect3DSurface9> backBuffer = GetBackBuffer();
|
2010-08-10 16:32:45 -07:00
|
|
|
|
|
|
|
D3DSURFACE_DESC desc;
|
|
|
|
backBuffer->GetDesc(&desc);
|
|
|
|
|
|
|
|
if (desc.Width == r.right - r.left && desc.Height == r.bottom - r.top) {
|
|
|
|
mDeviceManager->device()->SetRenderTarget(0, backBuffer);
|
2013-11-21 14:07:57 -08:00
|
|
|
return DeviceOK;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mSwapChain = nullptr;
|
2010-08-10 16:32:45 -07:00
|
|
|
|
|
|
|
Init(mWnd);
|
|
|
|
|
|
|
|
if (!mSwapChain) {
|
2013-11-21 14:07:57 -08:00
|
|
|
return DeviceFail;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
backBuffer = GetBackBuffer();
|
2010-08-10 16:32:45 -07:00
|
|
|
mDeviceManager->device()->SetRenderTarget(0, backBuffer);
|
|
|
|
|
2013-11-21 14:07:57 -08:00
|
|
|
return DeviceOK;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
2013-11-21 14:07:57 -08:00
|
|
|
|
|
|
|
return DeviceFail;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SwapChainD3D9::Present(const nsIntRect &aRect)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
r.left = aRect.x;
|
|
|
|
r.top = aRect.y;
|
|
|
|
r.right = aRect.XMost();
|
|
|
|
r.bottom = aRect.YMost();
|
|
|
|
|
|
|
|
mSwapChain->Present(&r, &r, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
void
|
|
|
|
SwapChainD3D9::Present()
|
|
|
|
{
|
2014-01-06 07:06:04 -08:00
|
|
|
mSwapChain->Present(nullptr, nullptr, 0, 0, 0);
|
2013-08-04 00:46:17 -07:00
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
void
|
|
|
|
SwapChainD3D9::Reset()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mSwapChain = nullptr;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define HAS_CAP(a, b) (((a) & (b)) == (b))
|
|
|
|
#define LACKS_CAP(a, b) !(((a) & (b)) == (b))
|
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
uint32_t DeviceManagerD3D9::sMaskQuadRegister = 11;
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
DeviceManagerD3D9::DeviceManagerD3D9()
|
2013-11-21 14:07:56 -08:00
|
|
|
: mTextureHostList(nullptr)
|
|
|
|
, mDeviceResetCount(0)
|
2011-07-08 03:42:21 -07:00
|
|
|
, mMaxTextureSize(0)
|
2013-08-04 00:46:17 -07:00
|
|
|
, mTextureAddressingMode(D3DTADDRESS_CLAMP)
|
2011-01-19 00:27:54 -08:00
|
|
|
, mHasDynamicTextures(false)
|
2010-09-15 15:15:59 -07:00
|
|
|
, mDeviceWasRemoved(false)
|
2010-08-10 16:32:45 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-14 07:43:14 -07:00
|
|
|
DeviceManagerD3D9::~DeviceManagerD3D9()
|
|
|
|
{
|
2013-11-21 14:07:57 -08:00
|
|
|
DestroyDevice();
|
2010-08-14 07:43:14 -07:00
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
bool
|
|
|
|
DeviceManagerD3D9::Init()
|
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
2010-08-10 16:39:45 -07:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-07-20 01:48:55 -07:00
|
|
|
if (!GetClassInfoW(GetModuleHandle(nullptr), kClassName, &wc)) {
|
2010-08-10 16:32:45 -07:00
|
|
|
ZeroMemory(&wc, sizeof(WNDCLASSW));
|
2013-07-20 01:48:55 -07:00
|
|
|
wc.hInstance = GetModuleHandle(nullptr);
|
2010-08-10 16:32:45 -07:00
|
|
|
wc.lpfnWndProc = ::DefWindowProc;
|
|
|
|
wc.lpszClassName = kClassName;
|
|
|
|
if (!RegisterClassW(&wc)) {
|
|
|
|
NS_WARNING("Failed to register window class for DeviceManager.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-11 09:05:14 -07:00
|
|
|
mFocusWnd = ::CreateWindowW(kClassName, L"D3D9Window", WS_OVERLAPPEDWINDOW,
|
2013-07-20 01:48:55 -07:00
|
|
|
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr,
|
|
|
|
nullptr, GetModuleHandle(nullptr), nullptr);
|
2010-08-10 16:32:45 -07:00
|
|
|
|
|
|
|
if (!mFocusWnd) {
|
|
|
|
NS_WARNING("Failed to create DeviceManagerD3D9 Window.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-26 13:44:53 -07:00
|
|
|
/* Create an Nv3DVUtils instance */
|
|
|
|
if (!mNv3DVUtils) {
|
|
|
|
mNv3DVUtils = new Nv3DVUtils();
|
|
|
|
if (!mNv3DVUtils) {
|
|
|
|
NS_WARNING("Could not create a new instance of Nv3DVUtils.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the Nv3DVUtils object */
|
|
|
|
if (mNv3DVUtils) {
|
|
|
|
mNv3DVUtils->Initialize();
|
|
|
|
}
|
|
|
|
|
2010-08-10 16:39:45 -07:00
|
|
|
HMODULE d3d9 = LoadLibraryW(L"d3d9.dll");
|
2014-02-17 14:32:52 -08:00
|
|
|
decltype(Direct3DCreate9)* d3d9Create = (decltype(Direct3DCreate9)*)
|
2010-08-10 16:39:45 -07:00
|
|
|
GetProcAddress(d3d9, "Direct3DCreate9");
|
2014-02-17 14:32:52 -08:00
|
|
|
decltype(Direct3DCreate9Ex)* d3d9CreateEx = (decltype(Direct3DCreate9Ex)*)
|
2010-08-10 16:39:45 -07:00
|
|
|
GetProcAddress(d3d9, "Direct3DCreate9Ex");
|
2014-02-17 14:32:52 -08:00
|
|
|
|
2010-08-10 16:39:45 -07:00
|
|
|
#ifdef USE_D3D9EX
|
|
|
|
if (d3d9CreateEx) {
|
|
|
|
hr = d3d9CreateEx(D3D_SDK_VERSION, getter_AddRefs(mD3D9Ex));
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
mD3D9 = mD3D9Ex;
|
|
|
|
}
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
2010-08-10 16:39:45 -07:00
|
|
|
#endif
|
2010-08-10 16:32:45 -07:00
|
|
|
|
2010-08-10 16:39:45 -07:00
|
|
|
if (!mD3D9) {
|
|
|
|
if (!d3d9Create) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mD3D9 = dont_AddRef(d3d9Create(D3D_SDK_VERSION));
|
|
|
|
|
|
|
|
if (!mD3D9) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-08-10 16:32:45 -07:00
|
|
|
|
2010-09-17 11:57:46 -07:00
|
|
|
D3DADAPTER_IDENTIFIER9 ident;
|
|
|
|
hr = mD3D9->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &ident);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
D3DPRESENT_PARAMETERS pp;
|
|
|
|
memset(&pp, 0, sizeof(D3DPRESENT_PARAMETERS));
|
|
|
|
|
|
|
|
pp.BackBufferWidth = 1;
|
|
|
|
pp.BackBufferHeight = 1;
|
|
|
|
pp.BackBufferFormat = D3DFMT_A8R8G8B8;
|
|
|
|
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
|
pp.Windowed = TRUE;
|
|
|
|
pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
|
|
|
|
pp.hDeviceWindow = mFocusWnd;
|
|
|
|
|
2010-08-10 16:39:45 -07:00
|
|
|
if (mD3D9Ex) {
|
|
|
|
hr = mD3D9Ex->CreateDeviceEx(D3DADAPTER_DEFAULT,
|
|
|
|
D3DDEVTYPE_HAL,
|
|
|
|
mFocusWnd,
|
|
|
|
D3DCREATE_FPU_PRESERVE |
|
|
|
|
D3DCREATE_MULTITHREADED |
|
|
|
|
D3DCREATE_MIXED_VERTEXPROCESSING,
|
|
|
|
&pp,
|
2013-07-20 01:48:55 -07:00
|
|
|
nullptr,
|
2010-08-10 16:39:45 -07:00
|
|
|
getter_AddRefs(mDeviceEx));
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
mDevice = mDeviceEx;
|
|
|
|
}
|
2010-08-10 16:32:45 -07:00
|
|
|
|
2010-08-10 16:39:45 -07:00
|
|
|
D3DCAPS9 caps;
|
2010-09-05 09:59:57 -07:00
|
|
|
if (mDeviceEx && mDeviceEx->GetDeviceCaps(&caps)) {
|
2010-08-10 16:39:45 -07:00
|
|
|
if (LACKS_CAP(caps.Caps2, D3DCAPS2_DYNAMICTEXTURES)) {
|
|
|
|
// XXX - Should we actually hit this we'll need a CanvasLayer that
|
|
|
|
// supports static D3DPOOL_DEFAULT textures.
|
|
|
|
NS_WARNING("D3D9Ex device not used because of lack of support for \
|
|
|
|
dynamic textures. This is unexpected.");
|
2012-07-30 07:20:58 -07:00
|
|
|
mDevice = nullptr;
|
|
|
|
mDeviceEx = nullptr;
|
2010-08-10 16:39:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDevice) {
|
|
|
|
hr = mD3D9->CreateDevice(D3DADAPTER_DEFAULT,
|
|
|
|
D3DDEVTYPE_HAL,
|
|
|
|
mFocusWnd,
|
|
|
|
D3DCREATE_FPU_PRESERVE |
|
|
|
|
D3DCREATE_MULTITHREADED |
|
|
|
|
D3DCREATE_MIXED_VERTEXPROCESSING,
|
|
|
|
&pp,
|
|
|
|
getter_AddRefs(mDevice));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create Device for DeviceManagerD3D9.");
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!VerifyCaps()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-23 09:18:00 -08:00
|
|
|
/* Grab the associated HMONITOR so that we can find out
|
|
|
|
* if it changed later */
|
|
|
|
D3DDEVICE_CREATION_PARAMETERS parameters;
|
|
|
|
if (FAILED(mDevice->GetCreationParameters(¶meters)))
|
|
|
|
return false;
|
|
|
|
mDeviceMonitor = mD3D9->GetAdapterMonitor(parameters.AdapterOrdinal);
|
|
|
|
|
|
|
|
|
2010-08-26 13:44:53 -07:00
|
|
|
/*
|
|
|
|
* Do some post device creation setup
|
|
|
|
*/
|
|
|
|
if (mNv3DVUtils) {
|
2013-07-20 01:48:55 -07:00
|
|
|
IUnknown* devUnknown = nullptr;
|
2010-08-26 13:44:53 -07:00
|
|
|
if (mDevice) {
|
|
|
|
mDevice->QueryInterface(IID_IUnknown, (void **)&devUnknown);
|
|
|
|
}
|
|
|
|
mNv3DVUtils->SetDeviceInfo(devUnknown);
|
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
hr = mDevice->CreateVertexShader((DWORD*)LayerQuadVS,
|
|
|
|
getter_AddRefs(mLayerVS));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)RGBShaderPS,
|
|
|
|
getter_AddRefs(mRGBPS));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-02 20:51:04 -07:00
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)RGBAShaderPS,
|
|
|
|
getter_AddRefs(mRGBAPS));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)ComponentPass1ShaderPS,
|
|
|
|
getter_AddRefs(mComponentPass1PS));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)ComponentPass2ShaderPS,
|
|
|
|
getter_AddRefs(mComponentPass2PS));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)YCbCrShaderPS,
|
|
|
|
getter_AddRefs(mYCbCrPS));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)SolidColorShaderPS,
|
|
|
|
getter_AddRefs(mSolidColorPS));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
hr = mDevice->CreateVertexShader((DWORD*)LayerQuadVSMask,
|
|
|
|
getter_AddRefs(mLayerVSMask));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
hr = mDevice->CreateVertexShader((DWORD*)LayerQuadVSMask3D,
|
|
|
|
getter_AddRefs(mLayerVSMask3D));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)RGBShaderPSMask,
|
|
|
|
getter_AddRefs(mRGBPSMask));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)RGBAShaderPSMask,
|
|
|
|
getter_AddRefs(mRGBAPSMask));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)RGBAShaderPSMask3D,
|
|
|
|
getter_AddRefs(mRGBAPSMask3D));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)ComponentPass1ShaderPSMask,
|
|
|
|
getter_AddRefs(mComponentPass1PSMask));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)ComponentPass2ShaderPSMask,
|
|
|
|
getter_AddRefs(mComponentPass2PSMask));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)YCbCrShaderPSMask,
|
|
|
|
getter_AddRefs(mYCbCrPSMask));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->CreatePixelShader((DWORD*)SolidColorShaderPSMask,
|
|
|
|
getter_AddRefs(mSolidColorPSMask));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-23 08:24:39 -08:00
|
|
|
if (!CreateVertexBuffer()) {
|
2010-08-10 16:32:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDevice->SetStreamSource(0, mVB, 0, sizeof(vertex));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3DVERTEXELEMENT9 elements[] = {
|
|
|
|
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT,
|
|
|
|
D3DDECLUSAGE_POSITION, 0 },
|
|
|
|
D3DDECL_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
mDevice->CreateVertexDeclaration(elements, getter_AddRefs(mVD));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService>
|
|
|
|
console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
|
|
|
|
D3DADAPTER_IDENTIFIER9 identifier;
|
|
|
|
mD3D9->GetAdapterIdentifier(D3DADAPTER_DEFAULT, 0, &identifier);
|
|
|
|
|
|
|
|
if (console) {
|
|
|
|
nsString msg;
|
|
|
|
msg +=
|
2012-10-05 09:48:15 -07:00
|
|
|
NS_LITERAL_STRING("Direct3D 9 DeviceManager Initialized Successfully.\nDriver: ");
|
2010-08-10 16:32:45 -07:00
|
|
|
msg += NS_ConvertUTF8toUTF16(
|
|
|
|
nsDependentCString((const char*)identifier.Driver));
|
|
|
|
msg += NS_LITERAL_STRING("\nDescription: ");
|
|
|
|
msg += NS_ConvertUTF8toUTF16(
|
|
|
|
nsDependentCString((const char*)identifier.Description));
|
|
|
|
msg += NS_LITERAL_STRING("\nVersion: ");
|
|
|
|
msg += NS_ConvertUTF8toUTF16(
|
|
|
|
nsPrintfCString("%d.%d.%d.%d",
|
|
|
|
HIWORD(identifier.DriverVersion.HighPart),
|
|
|
|
LOWORD(identifier.DriverVersion.HighPart),
|
|
|
|
HIWORD(identifier.DriverVersion.LowPart),
|
|
|
|
LOWORD(identifier.DriverVersion.LowPart)));
|
|
|
|
console->LogStringMessage(msg.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeviceManagerD3D9::SetupRenderState()
|
|
|
|
{
|
|
|
|
mDevice->SetStreamSource(0, mVB, 0, sizeof(vertex));
|
|
|
|
mDevice->SetVertexDeclaration(mVD);
|
|
|
|
mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
|
|
|
mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
|
|
|
mDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
|
|
|
|
mDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
|
|
|
mDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
|
|
|
|
mDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
|
2010-08-26 13:44:11 -07:00
|
|
|
mDevice->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_ONE);
|
|
|
|
mDevice->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_INVSRCALPHA);
|
2010-08-23 20:57:22 -07:00
|
|
|
mDevice->SetRenderState(D3DRS_BLENDOPALPHA, D3DBLENDOP_ADD);
|
2010-12-29 11:22:18 -08:00
|
|
|
mDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
|
|
|
mDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
|
|
|
mDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
|
|
|
mDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
|
|
|
mDevice->SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
|
|
|
mDevice->SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
2013-08-04 00:46:17 -07:00
|
|
|
mDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, mTextureAddressingMode);
|
|
|
|
mDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, mTextureAddressingMode);
|
|
|
|
mDevice->SetSamplerState(1, D3DSAMP_ADDRESSU, mTextureAddressingMode);
|
|
|
|
mDevice->SetSamplerState(1, D3DSAMP_ADDRESSV, mTextureAddressingMode);
|
|
|
|
mDevice->SetSamplerState(2, D3DSAMP_ADDRESSU, mTextureAddressingMode);
|
|
|
|
mDevice->SetSamplerState(2, D3DSAMP_ADDRESSV, mTextureAddressingMode);
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SwapChainD3D9>
|
|
|
|
DeviceManagerD3D9::CreateSwapChain(HWND hWnd)
|
|
|
|
{
|
|
|
|
nsRefPtr<SwapChainD3D9> swapChain = new SwapChainD3D9(this);
|
|
|
|
|
2010-12-20 14:35:28 -08:00
|
|
|
// See bug 604647. This line means that if we create a window while the
|
|
|
|
// device is lost LayerManager initialization will fail, this window
|
|
|
|
// will be permanently unaccelerated. This should be a rare situation
|
|
|
|
// though and the need for a low-risk fix for this bug outweighs the
|
|
|
|
// downside.
|
2013-11-21 14:07:57 -08:00
|
|
|
if (VerifyReadyForRendering() != DeviceOK) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-12-20 14:35:28 -08:00
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
if (!swapChain->Init(hWnd)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return swapChain.forget();
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
/*
|
|
|
|
* Finds a texture for the mask layer and sets it as an
|
|
|
|
* input to the shaders.
|
|
|
|
* Returns true if a texture is loaded, false if
|
|
|
|
* a texture for the mask layer could not be loaded.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
LoadMaskTexture(Layer* aMask, IDirect3DDevice9* aDevice,
|
2013-08-04 00:46:17 -07:00
|
|
|
uint32_t aMaskTexRegister)
|
2012-03-06 13:07:48 -08:00
|
|
|
{
|
2014-01-27 12:25:19 -08:00
|
|
|
IntSize size;
|
2012-03-06 13:07:48 -08:00
|
|
|
nsRefPtr<IDirect3DTexture9> texture =
|
|
|
|
static_cast<LayerD3D9*>(aMask->ImplData())->GetAsTexture(&size);
|
2014-01-24 17:49:19 -08:00
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
if (!texture) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-24 17:49:19 -08:00
|
|
|
|
2014-01-27 12:25:19 -08:00
|
|
|
Matrix maskTransform;
|
|
|
|
Matrix4x4 effectiveTransform = aMask->GetEffectiveTransform();
|
2014-01-24 17:49:19 -08:00
|
|
|
bool maskIs2D = effectiveTransform.CanDraw2D(&maskTransform);
|
2012-10-05 09:48:15 -07:00
|
|
|
NS_ASSERTION(maskIs2D, "How did we end up with a 3D transform here?!");
|
2014-01-27 12:25:19 -08:00
|
|
|
Rect bounds = Rect(Point(), Size(size));
|
2012-03-06 13:07:48 -08:00
|
|
|
bounds = maskTransform.TransformBounds(bounds);
|
|
|
|
|
2014-01-24 17:49:19 -08:00
|
|
|
aDevice->SetVertexShaderConstantF(DeviceManagerD3D9::sMaskQuadRegister,
|
2012-03-06 13:07:48 -08:00
|
|
|
ShaderConstantRect((float)bounds.x,
|
|
|
|
(float)bounds.y,
|
|
|
|
(float)bounds.width,
|
|
|
|
(float)bounds.height),
|
|
|
|
1);
|
|
|
|
|
|
|
|
aDevice->SetTexture(aMaskTexRegister, texture);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
uint32_t
|
|
|
|
DeviceManagerD3D9::SetShaderMode(ShaderMode aMode, MaskType aMaskType)
|
2010-08-10 16:32:45 -07:00
|
|
|
{
|
2014-04-25 19:34:06 -07:00
|
|
|
if (aMaskType == MaskType::MaskNone) {
|
2012-03-06 13:07:48 -08:00
|
|
|
switch (aMode) {
|
|
|
|
case RGBLAYER:
|
|
|
|
mDevice->SetVertexShader(mLayerVS);
|
|
|
|
mDevice->SetPixelShader(mRGBPS);
|
|
|
|
break;
|
|
|
|
case RGBALAYER:
|
|
|
|
mDevice->SetVertexShader(mLayerVS);
|
|
|
|
mDevice->SetPixelShader(mRGBAPS);
|
|
|
|
break;
|
|
|
|
case COMPONENTLAYERPASS1:
|
|
|
|
mDevice->SetVertexShader(mLayerVS);
|
|
|
|
mDevice->SetPixelShader(mComponentPass1PS);
|
|
|
|
break;
|
|
|
|
case COMPONENTLAYERPASS2:
|
|
|
|
mDevice->SetVertexShader(mLayerVS);
|
|
|
|
mDevice->SetPixelShader(mComponentPass2PS);
|
|
|
|
break;
|
|
|
|
case YCBCRLAYER:
|
|
|
|
mDevice->SetVertexShader(mLayerVS);
|
|
|
|
mDevice->SetPixelShader(mYCbCrPS);
|
|
|
|
break;
|
|
|
|
case SOLIDCOLORLAYER:
|
|
|
|
mDevice->SetVertexShader(mLayerVS);
|
|
|
|
mDevice->SetPixelShader(mSolidColorPS);
|
|
|
|
break;
|
|
|
|
}
|
2013-08-04 00:46:17 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t maskTexRegister;
|
|
|
|
switch (aMode) {
|
|
|
|
case RGBLAYER:
|
|
|
|
mDevice->SetVertexShader(mLayerVSMask);
|
|
|
|
mDevice->SetPixelShader(mRGBPSMask);
|
|
|
|
maskTexRegister = 1;
|
|
|
|
break;
|
|
|
|
case RGBALAYER:
|
2014-04-25 19:34:06 -07:00
|
|
|
if (aMaskType == MaskType::Mask2d) {
|
2013-08-04 00:46:17 -07:00
|
|
|
mDevice->SetVertexShader(mLayerVSMask);
|
|
|
|
mDevice->SetPixelShader(mRGBAPSMask);
|
|
|
|
} else {
|
|
|
|
mDevice->SetVertexShader(mLayerVSMask3D);
|
|
|
|
mDevice->SetPixelShader(mRGBAPSMask3D);
|
|
|
|
}
|
|
|
|
maskTexRegister = 1;
|
|
|
|
break;
|
|
|
|
case COMPONENTLAYERPASS1:
|
|
|
|
mDevice->SetVertexShader(mLayerVSMask);
|
|
|
|
mDevice->SetPixelShader(mComponentPass1PSMask);
|
|
|
|
maskTexRegister = 2;
|
|
|
|
break;
|
|
|
|
case COMPONENTLAYERPASS2:
|
|
|
|
mDevice->SetVertexShader(mLayerVSMask);
|
|
|
|
mDevice->SetPixelShader(mComponentPass2PSMask);
|
|
|
|
maskTexRegister = 2;
|
|
|
|
break;
|
|
|
|
case YCBCRLAYER:
|
|
|
|
mDevice->SetVertexShader(mLayerVSMask);
|
|
|
|
mDevice->SetPixelShader(mYCbCrPSMask);
|
|
|
|
maskTexRegister = 3;
|
|
|
|
break;
|
|
|
|
case SOLIDCOLORLAYER:
|
|
|
|
mDevice->SetVertexShader(mLayerVSMask);
|
|
|
|
mDevice->SetPixelShader(mSolidColorPSMask);
|
|
|
|
maskTexRegister = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return maskTexRegister;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeviceManagerD3D9::SetShaderMode(ShaderMode aMode, Layer* aMask, bool aIs2D)
|
|
|
|
{
|
2014-04-25 19:34:06 -07:00
|
|
|
MaskType maskType = MaskType::MaskNone;
|
2013-08-04 00:46:17 -07:00
|
|
|
if (aMask) {
|
2014-04-25 19:34:06 -07:00
|
|
|
maskType = aIs2D ? MaskType::Mask2d : MaskType::Mask3d;
|
2013-08-04 00:46:17 -07:00
|
|
|
}
|
|
|
|
uint32_t maskTexRegister = SetShaderMode(aMode, maskType);
|
|
|
|
if (aMask) {
|
|
|
|
// register allocations are taken from LayerManagerD3D9Shaders.h after
|
|
|
|
// the shaders are compiled (genshaders.sh)
|
|
|
|
if (!LoadMaskTexture(aMask, mDevice, maskTexRegister)) {
|
|
|
|
// if we can't load the mask, fall back to unmasked rendering
|
|
|
|
NS_WARNING("Could not load texture for mask layer.");
|
2014-04-25 19:34:06 -07:00
|
|
|
SetShaderMode(aMode, MaskType::MaskNone);
|
2013-08-04 00:46:17 -07:00
|
|
|
}
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 14:07:57 -08:00
|
|
|
void
|
|
|
|
DeviceManagerD3D9::DestroyDevice()
|
|
|
|
{
|
2014-01-26 20:10:40 -08:00
|
|
|
++mDeviceResetCount;
|
2013-11-21 14:07:57 -08:00
|
|
|
mDeviceWasRemoved = true;
|
|
|
|
if (!IsD3D9Ex()) {
|
|
|
|
ReleaseTextureResources();
|
|
|
|
}
|
|
|
|
gfxWindowsPlatform::GetPlatform()->OnDeviceManagerDestroy(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceManagerState
|
2010-08-10 16:32:45 -07:00
|
|
|
DeviceManagerD3D9::VerifyReadyForRendering()
|
|
|
|
{
|
2013-11-21 14:07:57 -08:00
|
|
|
if (mDeviceWasRemoved) {
|
|
|
|
return DeviceMustRecreate;
|
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
HRESULT hr = mDevice->TestCooperativeLevel();
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
2010-08-10 16:39:45 -07:00
|
|
|
if (IsD3D9Ex()) {
|
|
|
|
hr = mDeviceEx->CheckDeviceState(mFocusWnd);
|
2010-09-15 15:15:59 -07:00
|
|
|
|
2011-01-17 13:28:24 -08:00
|
|
|
if (FAILED(hr)) {
|
2013-11-21 14:07:57 -08:00
|
|
|
DestroyDevice();
|
|
|
|
return DeviceMustRecreate;
|
2010-09-15 15:15:59 -07:00
|
|
|
}
|
2010-08-10 16:39:45 -07:00
|
|
|
}
|
2013-11-21 14:07:57 -08:00
|
|
|
return DeviceOK;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
2013-11-21 14:07:57 -08:00
|
|
|
// We need to release all texture resources and swap chains before resetting.
|
|
|
|
for (unsigned int i = 0; i < mLayersWithResources.Length(); i++) {
|
2010-09-14 03:56:39 -07:00
|
|
|
mLayersWithResources[i]->CleanResources();
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
2013-11-21 14:07:57 -08:00
|
|
|
ReleaseTextureResources();
|
|
|
|
for (unsigned int i = 0; i < mSwapChains.Length(); i++) {
|
2010-08-10 16:32:45 -07:00
|
|
|
mSwapChains[i]->Reset();
|
|
|
|
}
|
2010-11-23 08:24:39 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mVB = nullptr;
|
2013-11-21 14:07:56 -08:00
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
D3DPRESENT_PARAMETERS pp;
|
|
|
|
memset(&pp, 0, sizeof(D3DPRESENT_PARAMETERS));
|
|
|
|
|
|
|
|
pp.BackBufferWidth = 1;
|
|
|
|
pp.BackBufferHeight = 1;
|
|
|
|
pp.BackBufferFormat = D3DFMT_A8R8G8B8;
|
|
|
|
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
|
pp.Windowed = TRUE;
|
|
|
|
pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
|
|
|
|
pp.hDeviceWindow = mFocusWnd;
|
|
|
|
|
2014-01-26 20:10:40 -08:00
|
|
|
// Whatever happens from now on, either we reset the device, or we should
|
|
|
|
// pretend we reset the device so that the layer manager or compositor
|
|
|
|
// doesn't ignore it.
|
|
|
|
++mDeviceResetCount;
|
|
|
|
|
2013-11-21 14:07:57 -08:00
|
|
|
// if we got this far, we know !SUCCEEDEED(hr), that means hr is one of
|
|
|
|
// D3DERR_DEVICELOST, D3DERR_DEVICENOTRESET, D3DERR_DRIVERINTERNALERROR.
|
|
|
|
// It is only worth resetting if we get D3DERR_DEVICENOTRESET. If we get
|
|
|
|
// D3DERR_DEVICELOST we can wait and see if we get D3DERR_DEVICENOTRESET
|
|
|
|
// later, then reset.
|
|
|
|
if (hr == D3DERR_DEVICELOST) {
|
2013-11-21 14:07:58 -08:00
|
|
|
HMONITOR hMonitorWindow;
|
|
|
|
hMonitorWindow = MonitorFromWindow(mFocusWnd, MONITOR_DEFAULTTOPRIMARY);
|
|
|
|
if (hMonitorWindow != mDeviceMonitor) {
|
|
|
|
/* jrmuizel: I'm not sure how to trigger this case. Usually, we get
|
|
|
|
* DEVICENOTRESET right away and Reset() succeeds without going through a
|
|
|
|
* set of DEVICELOSTs. This is presumeably because we don't call
|
|
|
|
* VerifyReadyForRendering when we don't have any reason to paint.
|
|
|
|
* Hopefully comparing HMONITORs is not overly aggressive.
|
|
|
|
* See bug 626678.
|
|
|
|
*/
|
2014-01-26 20:10:40 -08:00
|
|
|
/* The monitor has changed. We have to assume that the
|
|
|
|
* DEVICENOTRESET will not be coming. */
|
|
|
|
DestroyDevice();
|
2013-11-21 14:07:58 -08:00
|
|
|
return DeviceMustRecreate;
|
|
|
|
}
|
2014-01-26 20:10:40 -08:00
|
|
|
return DeviceFail;
|
2013-11-21 14:07:57 -08:00
|
|
|
}
|
|
|
|
if (hr == D3DERR_DEVICENOTRESET) {
|
|
|
|
hr = mDevice->Reset(&pp);
|
|
|
|
}
|
2010-08-10 16:32:45 -07:00
|
|
|
|
2010-11-23 08:24:39 -08:00
|
|
|
if (FAILED(hr) || !CreateVertexBuffer()) {
|
2013-11-21 14:07:57 -08:00
|
|
|
DestroyDevice();
|
|
|
|
return DeviceMustRecreate;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
2013-11-21 14:07:57 -08:00
|
|
|
return DeviceOK;
|
2010-08-10 16:32:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DeviceManagerD3D9::VerifyCaps()
|
|
|
|
{
|
|
|
|
D3DCAPS9 caps;
|
|
|
|
HRESULT hr = mDevice->GetDeviceCaps(&caps);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LACKS_CAP(caps.DevCaps, D3DDEVCAPS_TEXTUREVIDEOMEMORY)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LACKS_CAP(caps.PrimitiveMiscCaps, D3DPMISCCAPS_CULLNONE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LACKS_CAP(caps.SrcBlendCaps, D3DPBLENDCAPS_ONE) ||
|
|
|
|
LACKS_CAP(caps.SrcBlendCaps, D3DBLEND_SRCALPHA) ||
|
|
|
|
LACKS_CAP(caps.DestBlendCaps, D3DPBLENDCAPS_INVSRCALPHA)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LACKS_CAP(caps.RasterCaps, D3DPRASTERCAPS_SCISSORTEST)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LACKS_CAP(caps.TextureCaps, D3DPTEXTURECAPS_ALPHA) ||
|
|
|
|
HAS_CAP(caps.TextureCaps, D3DPTEXTURECAPS_SQUAREONLY) ||
|
|
|
|
(HAS_CAP(caps.TextureCaps, D3DPTEXTURECAPS_POW2) &&
|
|
|
|
LACKS_CAP(caps.TextureCaps, D3DPTEXTURECAPS_NONPOW2CONDITIONAL))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LACKS_CAP(caps.TextureFilterCaps, D3DPTFILTERCAPS_MAGFLINEAR) ||
|
|
|
|
LACKS_CAP(caps.TextureFilterCaps, D3DPTFILTERCAPS_MINFLINEAR)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LACKS_CAP(caps.TextureAddressCaps, D3DPTADDRESSCAPS_CLAMP)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caps.MaxTextureHeight < 4096 ||
|
|
|
|
caps.MaxTextureWidth < 4096) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-15 04:22:03 -08:00
|
|
|
mMaxTextureSize = std::min(caps.MaxTextureHeight, caps.MaxTextureWidth);
|
2010-08-10 16:32:45 -07:00
|
|
|
|
|
|
|
if ((caps.PixelShaderVersion & 0xffff) < 0x200 ||
|
|
|
|
(caps.VertexShaderVersion & 0xffff) < 0x200) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-10 16:39:45 -07:00
|
|
|
if (HAS_CAP(caps.Caps2, D3DCAPS2_DYNAMICTEXTURES)) {
|
|
|
|
mHasDynamicTextures = true;
|
|
|
|
}
|
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
if (HAS_CAP(caps.TextureAddressCaps, D3DPTADDRESSCAPS_WRAP) &&
|
|
|
|
LACKS_CAP(caps.TextureCaps, D3DPTEXTURECAPS_NONPOW2CONDITIONAL)) {
|
|
|
|
mTextureAddressingMode = D3DTADDRESS_WRAP;
|
|
|
|
} else {
|
|
|
|
gfxPlatform::DisableBufferRotation();
|
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-23 08:24:39 -08:00
|
|
|
bool
|
|
|
|
DeviceManagerD3D9::CreateVertexBuffer()
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = mDevice->CreateVertexBuffer(sizeof(vertex) * 4,
|
|
|
|
D3DUSAGE_WRITEONLY,
|
|
|
|
0,
|
|
|
|
D3DPOOL_DEFAULT,
|
|
|
|
getter_AddRefs(mVB),
|
2013-07-20 01:48:55 -07:00
|
|
|
nullptr);
|
2010-11-23 08:24:39 -08:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vertex *vertices;
|
|
|
|
hr = mVB->Lock(0, 0, (void**)&vertices, 0);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vertices[0].x = vertices[0].y = 0;
|
|
|
|
vertices[1].x = 1; vertices[1].y = 0;
|
|
|
|
vertices[2].x = 0; vertices[2].y = 1;
|
|
|
|
vertices[3].x = 1; vertices[3].y = 1;
|
|
|
|
|
|
|
|
mVB->Unlock();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 14:07:56 -08:00
|
|
|
TemporaryRef<IDirect3DTexture9>
|
|
|
|
DeviceManagerD3D9::CreateTexture(const IntSize &aSize,
|
|
|
|
_D3DFORMAT aFormat,
|
|
|
|
D3DPOOL aPool,
|
|
|
|
TextureSourceD3D9* aTextureHost)
|
|
|
|
{
|
|
|
|
if (mDeviceWasRemoved) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
RefPtr<IDirect3DTexture9> result;
|
|
|
|
if (FAILED(device()->CreateTexture(aSize.width, aSize.height,
|
|
|
|
1, 0, aFormat, aPool,
|
|
|
|
byRef(result), nullptr))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-11-21 14:07:57 -08:00
|
|
|
NS_ASSERTION(aPool != D3DPOOL_MANAGED,
|
|
|
|
"Should not be using MANAGED texture pool. We will get an error when we have to recreate the device");
|
2013-11-21 14:07:56 -08:00
|
|
|
if (aPool == D3DPOOL_DEFAULT) {
|
|
|
|
MOZ_ASSERT(aTextureHost, "We need a texture host to track so we can release the texture.");
|
|
|
|
RegisterTextureHost(aTextureHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool
|
|
|
|
DeviceManagerD3D9::IsInTextureHostList(TextureSourceD3D9* aFind)
|
|
|
|
{
|
|
|
|
TextureSourceD3D9* cur = mTextureHostList;
|
|
|
|
while(cur) {
|
|
|
|
if (cur == aFind) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
cur = cur->mNextHost;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
DeviceManagerD3D9::RegisterTextureHost(TextureSourceD3D9* aHost)
|
|
|
|
{
|
|
|
|
if (!aHost) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't add aHost to the list twice.
|
|
|
|
if (aHost->mPreviousHost ||
|
|
|
|
mTextureHostList == aHost) {
|
|
|
|
MOZ_ASSERT(IsInTextureHostList(aHost));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!aHost->mNextHost);
|
|
|
|
MOZ_ASSERT(!IsInTextureHostList(aHost));
|
|
|
|
|
|
|
|
if (mTextureHostList) {
|
|
|
|
MOZ_ASSERT(!mTextureHostList->mPreviousHost);
|
|
|
|
mTextureHostList->mPreviousHost = aHost;
|
|
|
|
aHost->mNextHost = mTextureHostList;
|
|
|
|
}
|
|
|
|
mTextureHostList = aHost;
|
|
|
|
MOZ_ASSERT(!aHost->mCreatingDeviceManager, "Already created texture?");
|
|
|
|
MOZ_ASSERT(IsInTextureHostList(aHost));
|
|
|
|
aHost->mCreatingDeviceManager = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeviceManagerD3D9::ReleaseTextureResources()
|
|
|
|
{
|
|
|
|
TextureSourceD3D9* host = mTextureHostList;
|
|
|
|
while (host) {
|
|
|
|
host->ReleaseTextureResources();
|
|
|
|
TextureSourceD3D9* oldHost = host;
|
|
|
|
host = oldHost->mNextHost;
|
|
|
|
oldHost->mPreviousHost = nullptr;
|
|
|
|
oldHost->mNextHost = nullptr;
|
|
|
|
oldHost->mCreatingDeviceManager = nullptr;
|
|
|
|
}
|
|
|
|
mTextureHostList = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DeviceManagerD3D9::RemoveTextureListHead(TextureSourceD3D9* aHost)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aHost->mCreatingDeviceManager || aHost->mCreatingDeviceManager == this,
|
|
|
|
"Wrong device manager");
|
|
|
|
MOZ_ASSERT(aHost && mTextureHostList == aHost,
|
|
|
|
"aHost is not the head of the texture host list");
|
|
|
|
mTextureHostList = aHost->mNextHost;
|
|
|
|
}
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
} /* namespace layers */
|
|
|
|
} /* namespace mozilla */
|