Commit 6ad6ce8d by apatrick@chromium.org

Fixed Display::initialize so it does not crash for devices that do not support PS 2.0.

The crash occurs when createDevice attempts to dereference mD3d9, which is NULL. Review URL: http://codereview.appspot.com/1956042 git-svn-id: https://angleproject.googlecode.com/svn/trunk@382 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c7b6eba9
...@@ -70,86 +70,84 @@ bool Display::initialize() ...@@ -70,86 +70,84 @@ bool Display::initialize()
if (mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(2, 0)) if (mDeviceCaps.PixelShaderVersion < D3DPS_VERSION(2, 0))
{ {
mD3d9->Release(); terminate();
mD3d9 = NULL; return error(EGL_NOT_INITIALIZED, false);
} }
else
{
mMinSwapInterval = 4;
mMaxSwapInterval = 0;
if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) {mMinSwapInterval = std::min(mMinSwapInterval, 0); mMaxSwapInterval = std::max(mMaxSwapInterval, 0);} mMinSwapInterval = 4;
if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) {mMinSwapInterval = std::min(mMinSwapInterval, 1); mMaxSwapInterval = std::max(mMaxSwapInterval, 1);} mMaxSwapInterval = 0;
if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) {mMinSwapInterval = std::min(mMinSwapInterval, 2); mMaxSwapInterval = std::max(mMaxSwapInterval, 2);}
if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) {mMinSwapInterval = std::min(mMinSwapInterval, 3); mMaxSwapInterval = std::max(mMaxSwapInterval, 3);}
if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) {mMinSwapInterval = std::min(mMinSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);}
const D3DFORMAT renderTargetFormats[] = if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) {mMinSwapInterval = std::min(mMinSwapInterval, 0); mMaxSwapInterval = std::max(mMaxSwapInterval, 0);}
{ if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) {mMinSwapInterval = std::min(mMinSwapInterval, 1); mMaxSwapInterval = std::max(mMaxSwapInterval, 1);}
D3DFMT_A1R5G5B5, if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) {mMinSwapInterval = std::min(mMinSwapInterval, 2); mMaxSwapInterval = std::max(mMaxSwapInterval, 2);}
// D3DFMT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value. if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) {mMinSwapInterval = std::min(mMinSwapInterval, 3); mMaxSwapInterval = std::max(mMaxSwapInterval, 3);}
D3DFMT_A8R8G8B8, if (mDeviceCaps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) {mMinSwapInterval = std::min(mMinSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);}
D3DFMT_R5G6B5,
D3DFMT_X1R5G5B5, const D3DFORMAT renderTargetFormats[] =
D3DFMT_X8R8G8B8 {
}; D3DFMT_A1R5G5B5,
// D3DFMT_A2R10G10B10, // The color_ramp conformance test uses ReadPixels with UNSIGNED_BYTE causing it to think that rendering skipped a colour value.
const D3DFORMAT depthStencilFormats[] = D3DFMT_A8R8G8B8,
{ D3DFMT_R5G6B5,
// D3DFMT_D16_LOCKABLE, D3DFMT_X1R5G5B5,
D3DFMT_D32, D3DFMT_X8R8G8B8
// D3DFMT_D15S1, };
D3DFMT_D24S8,
D3DFMT_D24X8, const D3DFORMAT depthStencilFormats[] =
// D3DFMT_D24X4S4, {
D3DFMT_D16, // D3DFMT_D16_LOCKABLE,
// D3DFMT_D32F_LOCKABLE, D3DFMT_D32,
// D3DFMT_D24FS8 // D3DFMT_D15S1,
}; D3DFMT_D24S8,
D3DFMT_D24X8,
D3DDISPLAYMODE currentDisplayMode; // D3DFMT_D24X4S4,
mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode); D3DFMT_D16,
// D3DFMT_D32F_LOCKABLE,
ConfigSet configSet; // D3DFMT_D24FS8
};
for (int formatIndex = 0; formatIndex < sizeof(renderTargetFormats) / sizeof(D3DFORMAT); formatIndex++)
{ D3DDISPLAYMODE currentDisplayMode;
D3DFORMAT renderTargetFormat = renderTargetFormats[formatIndex]; mD3d9->GetAdapterDisplayMode(mAdapter, &currentDisplayMode);
ConfigSet configSet;
for (int formatIndex = 0; formatIndex < sizeof(renderTargetFormats) / sizeof(D3DFORMAT); formatIndex++)
{
D3DFORMAT renderTargetFormat = renderTargetFormats[formatIndex];
HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat); HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, renderTargetFormat);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{
for (int depthStencilIndex = 0; depthStencilIndex < sizeof(depthStencilFormats) / sizeof(D3DFORMAT); depthStencilIndex++)
{ {
for (int depthStencilIndex = 0; depthStencilIndex < sizeof(depthStencilFormats) / sizeof(D3DFORMAT); depthStencilIndex++) D3DFORMAT depthStencilFormat = depthStencilFormats[depthStencilIndex];
HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat);
if (SUCCEEDED(result))
{ {
D3DFORMAT depthStencilFormat = depthStencilFormats[depthStencilIndex]; HRESULT result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, currentDisplayMode.Format, renderTargetFormat, depthStencilFormat);
HRESULT result = mD3d9->CheckDeviceFormat(mAdapter, mDeviceType, currentDisplayMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthStencilFormat);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
HRESULT result = mD3d9->CheckDepthStencilMatch(mAdapter, mDeviceType, currentDisplayMode.Format, renderTargetFormat, depthStencilFormat); // FIXME: Enumerate multi-sampling
if (SUCCEEDED(result))
{
// FIXME: Enumerate multi-sampling
configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0); configSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0);
}
} }
} }
} }
} }
}
// Give the sorted configs a unique ID and store them internally // Give the sorted configs a unique ID and store them internally
EGLint index = 1; EGLint index = 1;
for (ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++) for (ConfigSet::Iterator config = configSet.mSet.begin(); config != configSet.mSet.end(); config++)
{ {
Config configuration = *config; Config configuration = *config;
configuration.mConfigID = index; configuration.mConfigID = index;
index++; index++;
mConfigSet.mSet.insert(configuration); mConfigSet.mSet.insert(configuration);
}
} }
if (!createDevice()) if (!createDevice())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment