Fixes line endings on SwapChain9 and SwapChain11

TRAC #22134 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1476 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent def9f0f3
// //
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// SwapChain11.cpp: Implements a back-end specific class for the D3D11 swap chain. // SwapChain11.cpp: Implements a back-end specific class for the D3D11 swap chain.
#include "libGLESv2/renderer/SwapChain11.h" #include "libGLESv2/renderer/SwapChain11.h"
#include "common/debug.h" #include "common/debug.h"
#include "libGLESv2/utilities.h" #include "libGLESv2/utilities.h"
#include "libGLESv2/renderer/renderer11_utils.h" #include "libGLESv2/renderer/renderer11_utils.h"
#include "libGLESv2/renderer/Renderer11.h" #include "libGLESv2/renderer/Renderer11.h"
#include "libGLESv2/Context.h" #include "libGLESv2/Context.h"
#include "libGLESv2/main.h" #include "libGLESv2/main.h"
namespace rx namespace rx
{ {
SwapChain11::SwapChain11(Renderer11 *renderer, HWND window, HANDLE shareHandle, SwapChain11::SwapChain11(Renderer11 *renderer, HWND window, HANDLE shareHandle,
GLenum backBufferFormat, GLenum depthBufferFormat) GLenum backBufferFormat, GLenum depthBufferFormat)
: mRenderer(renderer), SwapChain(window, shareHandle, backBufferFormat, depthBufferFormat) : mRenderer(renderer), SwapChain(window, shareHandle, backBufferFormat, depthBufferFormat)
{ {
mSwapChain = NULL; mSwapChain = NULL;
mBackBuffer = NULL; mBackBuffer = NULL;
mBackBufferView = NULL; mBackBufferView = NULL;
mRenderTargetView = NULL; mRenderTargetView = NULL;
mDepthStencil = NULL; mDepthStencil = NULL;
mDepthStencilView = NULL; mDepthStencilView = NULL;
mOffscreenTexture = NULL; mOffscreenTexture = NULL;
mWidth = -1; mWidth = -1;
mHeight = -1; mHeight = -1;
} }
SwapChain11::~SwapChain11() SwapChain11::~SwapChain11()
{ {
release(); release();
} }
void SwapChain11::release() void SwapChain11::release()
{ {
if (mSwapChain) if (mSwapChain)
{ {
mSwapChain->Release(); mSwapChain->Release();
mSwapChain = NULL; mSwapChain = NULL;
} }
if (mBackBuffer) if (mBackBuffer)
{ {
mBackBuffer->Release(); mBackBuffer->Release();
mBackBuffer = NULL; mBackBuffer = NULL;
} }
if (mBackBufferView) if (mBackBufferView)
{ {
mBackBufferView->Release(); mBackBufferView->Release();
mBackBufferView = NULL; mBackBufferView = NULL;
} }
if (mRenderTargetView) if (mRenderTargetView)
{ {
mRenderTargetView->Release(); mRenderTargetView->Release();
mRenderTargetView = NULL; mRenderTargetView = NULL;
} }
if (mDepthStencil) if (mDepthStencil)
{ {
mDepthStencil->Release(); mDepthStencil->Release();
mDepthStencil = NULL; mDepthStencil = NULL;
} }
if (mDepthStencilView) if (mDepthStencilView)
{ {
mDepthStencilView->Release(); mDepthStencilView->Release();
mDepthStencilView = NULL; mDepthStencilView = NULL;
} }
if (mOffscreenTexture) if (mOffscreenTexture)
{ {
mOffscreenTexture->Release(); mOffscreenTexture->Release();
mOffscreenTexture = NULL; mOffscreenTexture = NULL;
} }
if (mWindow) if (mWindow)
mShareHandle = NULL; mShareHandle = NULL;
} }
EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval) EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval)
{ {
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
if (device == NULL) if (device == NULL)
{ {
return EGL_BAD_ACCESS; return EGL_BAD_ACCESS;
} }
// Release specific resources to free up memory for the new render target, while the // Release specific resources to free up memory for the new render target, while the
// old render target still exists for the purpose of preserving its contents. // old render target still exists for the purpose of preserving its contents.
if (mSwapChain) if (mSwapChain)
{ {
mSwapChain->Release(); mSwapChain->Release();
mSwapChain = NULL; mSwapChain = NULL;
} }
if (mBackBuffer) if (mBackBuffer)
{ {
mBackBuffer->Release(); mBackBuffer->Release();
mBackBuffer = NULL; mBackBuffer = NULL;
} }
if (mBackBufferView) if (mBackBufferView)
{ {
mBackBufferView->Release(); mBackBufferView->Release();
mBackBufferView = NULL; mBackBufferView = NULL;
} }
if (mRenderTargetView) // TODO: Preserve the render target content if (mRenderTargetView) // TODO: Preserve the render target content
{ {
mRenderTargetView->Release(); mRenderTargetView->Release();
mRenderTargetView = NULL; mRenderTargetView = NULL;
} }
if (mOffscreenTexture) if (mOffscreenTexture)
{ {
mOffscreenTexture->Release(); mOffscreenTexture->Release();
mOffscreenTexture = NULL; mOffscreenTexture = NULL;
} }
if (mDepthStencil) if (mDepthStencil)
{ {
mDepthStencil->Release(); mDepthStencil->Release();
mDepthStencil = NULL; mDepthStencil = NULL;
} }
if (mDepthStencilView) if (mDepthStencilView)
{ {
mDepthStencilView->Release(); mDepthStencilView->Release();
mDepthStencilView = NULL; mDepthStencilView = NULL;
} }
HANDLE *pShareHandle = NULL; HANDLE *pShareHandle = NULL;
if (!mWindow && mRenderer->getShareHandleSupport()) if (!mWindow && mRenderer->getShareHandleSupport())
{ {
pShareHandle = &mShareHandle; pShareHandle = &mShareHandle;
} }
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0}; D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
offscreenTextureDesc.Width = backbufferWidth; offscreenTextureDesc.Width = backbufferWidth;
offscreenTextureDesc.Height = backbufferHeight; offscreenTextureDesc.Height = backbufferHeight;
offscreenTextureDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat); offscreenTextureDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat);
offscreenTextureDesc.MipLevels = 1; offscreenTextureDesc.MipLevels = 1;
offscreenTextureDesc.ArraySize = 1; offscreenTextureDesc.ArraySize = 1;
offscreenTextureDesc.SampleDesc.Count = 1; offscreenTextureDesc.SampleDesc.Count = 1;
offscreenTextureDesc.SampleDesc.Quality = 0; offscreenTextureDesc.SampleDesc.Quality = 0;
offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT; offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT;
offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET; offscreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET;
offscreenTextureDesc.CPUAccessFlags = 0; offscreenTextureDesc.CPUAccessFlags = 0;
offscreenTextureDesc.MiscFlags = 0; // D3D11_RESOURCE_MISC_SHARED offscreenTextureDesc.MiscFlags = 0; // D3D11_RESOURCE_MISC_SHARED
HRESULT result = device->CreateTexture2D(&offscreenTextureDesc, NULL, &mOffscreenTexture); HRESULT result = device->CreateTexture2D(&offscreenTextureDesc, NULL, &mOffscreenTexture);
if (FAILED(result)) if (FAILED(result))
{ {
ERR("Could not create offscreen texture: %08lX", result); ERR("Could not create offscreen texture: %08lX", result);
release(); release();
if (isDeviceLostError(result)) if (isDeviceLostError(result))
{ {
return EGL_CONTEXT_LOST; return EGL_CONTEXT_LOST;
} }
else else
{ {
return EGL_BAD_ALLOC; return EGL_BAD_ALLOC;
} }
} }
result = device->CreateRenderTargetView(mOffscreenTexture, NULL, &mRenderTargetView); result = device->CreateRenderTargetView(mOffscreenTexture, NULL, &mRenderTargetView);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (mWindow) if (mWindow)
{ {
IDXGIFactory *factory = mRenderer->getDxgiFactory(); IDXGIFactory *factory = mRenderer->getDxgiFactory();
DXGI_SWAP_CHAIN_DESC swapChainDesc = {0}; DXGI_SWAP_CHAIN_DESC swapChainDesc = {0};
swapChainDesc.BufferCount = 2; swapChainDesc.BufferCount = 2;
swapChainDesc.BufferDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat); swapChainDesc.BufferDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mBackBufferFormat);
swapChainDesc.BufferDesc.Width = 1; swapChainDesc.BufferDesc.Width = 1;
swapChainDesc.BufferDesc.Height = 1; swapChainDesc.BufferDesc.Height = 1;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.Flags = 0; swapChainDesc.Flags = 0;
swapChainDesc.OutputWindow = mWindow; swapChainDesc.OutputWindow = mWindow;
swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = TRUE; swapChainDesc.Windowed = TRUE;
result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain); result = factory->CreateSwapChain(device, &swapChainDesc, &mSwapChain);
if (FAILED(result)) if (FAILED(result))
{ {
ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result); ERR("Could not create additional swap chains or offscreen surfaces: %08lX", result);
release(); release();
if (isDeviceLostError(result)) if (isDeviceLostError(result))
{ {
return EGL_CONTEXT_LOST; return EGL_CONTEXT_LOST;
} }
else else
{ {
return EGL_BAD_ALLOC; return EGL_BAD_ALLOC;
} }
} }
result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBuffer); result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBuffer);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
result = device->CreateRenderTargetView(mBackBuffer, NULL, &mBackBufferView); result = device->CreateRenderTargetView(mBackBuffer, NULL, &mBackBufferView);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
} }
if (mDepthBufferFormat != GL_NONE) if (mDepthBufferFormat != GL_NONE)
{ {
D3D11_TEXTURE2D_DESC depthStencilDesc = {0}; D3D11_TEXTURE2D_DESC depthStencilDesc = {0};
depthStencilDesc.Width = backbufferWidth; depthStencilDesc.Width = backbufferWidth;
depthStencilDesc.Height = backbufferHeight; depthStencilDesc.Height = backbufferHeight;
depthStencilDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mDepthBufferFormat); depthStencilDesc.Format = gl_d3d11::ConvertRenderbufferFormat(mDepthBufferFormat);
depthStencilDesc.MipLevels = 1; depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1; depthStencilDesc.ArraySize = 1;
depthStencilDesc.SampleDesc.Count = 1; depthStencilDesc.SampleDesc.Count = 1;
depthStencilDesc.SampleDesc.Quality = 0; depthStencilDesc.SampleDesc.Quality = 0;
depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0; depthStencilDesc.MiscFlags = 0;
result = device->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencil); result = device->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencil);
if (FAILED(result)) if (FAILED(result))
{ {
ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result); ERR("Could not create depthstencil surface for new swap chain: 0x%08X", result);
release(); release();
if (isDeviceLostError(result)) if (isDeviceLostError(result))
{ {
return EGL_CONTEXT_LOST; return EGL_CONTEXT_LOST;
} }
else else
{ {
return EGL_BAD_ALLOC; return EGL_BAD_ALLOC;
} }
} }
result = device->CreateDepthStencilView(mDepthStencil, NULL, &mDepthStencilView); result = device->CreateDepthStencilView(mDepthStencil, NULL, &mDepthStencilView);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
} }
mWidth = backbufferWidth; mWidth = backbufferWidth;
mHeight = backbufferHeight; mHeight = backbufferHeight;
return EGL_SUCCESS; return EGL_SUCCESS;
} }
// parameters should be validated/clamped by caller // parameters should be validated/clamped by caller
EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
{ {
if (!mSwapChain) if (!mSwapChain)
{ {
return EGL_SUCCESS; return EGL_SUCCESS;
} }
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
// TODO // TODO
UNIMPLEMENTED(); UNIMPLEMENTED();
return EGL_SUCCESS; return EGL_SUCCESS;
} }
// Increments refcount on view. // Increments refcount on view.
// caller must Release() the returned view // caller must Release() the returned view
ID3D11RenderTargetView *SwapChain11::getRenderTarget() ID3D11RenderTargetView *SwapChain11::getRenderTarget()
{ {
if (mRenderTargetView) if (mRenderTargetView)
{ {
mRenderTargetView->AddRef(); mRenderTargetView->AddRef();
} }
return mRenderTargetView; return mRenderTargetView;
} }
// Increments refcount on view. // Increments refcount on view.
// caller must Release() the returned view // caller must Release() the returned view
ID3D11DepthStencilView *SwapChain11::getDepthStencil() ID3D11DepthStencilView *SwapChain11::getDepthStencil()
{ {
if (mDepthStencilView) if (mDepthStencilView)
{ {
mDepthStencilView->AddRef(); mDepthStencilView->AddRef();
} }
return mDepthStencilView; return mDepthStencilView;
} }
// Increments refcount on texture. // Increments refcount on texture.
// caller must Release() the returned texture // caller must Release() the returned texture
ID3D11Texture2D *SwapChain11::getOffscreenTexture() ID3D11Texture2D *SwapChain11::getOffscreenTexture()
{ {
if (mOffscreenTexture) if (mOffscreenTexture)
{ {
mOffscreenTexture->AddRef(); mOffscreenTexture->AddRef();
} }
return mOffscreenTexture; return mOffscreenTexture;
} }
} }
// //
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// SwapChain11.h: Defines a back-end specific class for the D3D11 swap chain. // SwapChain11.h: Defines a back-end specific class for the D3D11 swap chain.
#ifndef LIBGLESV2_RENDERER_SWAPCHAIN11_H_ #ifndef LIBGLESV2_RENDERER_SWAPCHAIN11_H_
#define LIBGLESV2_RENDERER_SWAPCHAIN11_H_ #define LIBGLESV2_RENDERER_SWAPCHAIN11_H_
#include <d3d11.h> #include <d3d11.h>
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libGLESv2/renderer/SwapChain.h" #include "libGLESv2/renderer/SwapChain.h"
namespace rx namespace rx
{ {
class Renderer11; class Renderer11;
class SwapChain11 : public SwapChain class SwapChain11 : public SwapChain
{ {
public: public:
SwapChain11(Renderer11 *renderer, HWND window, HANDLE shareHandle, SwapChain11(Renderer11 *renderer, HWND window, HANDLE shareHandle,
GLenum backBufferFormat, GLenum depthBufferFormat); GLenum backBufferFormat, GLenum depthBufferFormat);
virtual ~SwapChain11(); virtual ~SwapChain11();
virtual EGLint reset(EGLint backbufferWidth, EGLint backbufferHeight, EGLint swapInterval); virtual EGLint reset(EGLint backbufferWidth, EGLint backbufferHeight, EGLint swapInterval);
virtual EGLint swapRect(EGLint x, EGLint y, EGLint width, EGLint height); virtual EGLint swapRect(EGLint x, EGLint y, EGLint width, EGLint height);
virtual ID3D11RenderTargetView *getRenderTarget(); virtual ID3D11RenderTargetView *getRenderTarget();
virtual ID3D11DepthStencilView *getDepthStencil(); virtual ID3D11DepthStencilView *getDepthStencil();
virtual ID3D11Texture2D *getOffscreenTexture(); virtual ID3D11Texture2D *getOffscreenTexture();
private: private:
DISALLOW_COPY_AND_ASSIGN(SwapChain11); DISALLOW_COPY_AND_ASSIGN(SwapChain11);
void release(); void release();
Renderer11 *mRenderer; Renderer11 *mRenderer;
EGLint mHeight; EGLint mHeight;
EGLint mWidth; EGLint mWidth;
IDXGISwapChain *mSwapChain; IDXGISwapChain *mSwapChain;
ID3D11Texture2D *mBackBuffer; ID3D11Texture2D *mBackBuffer;
ID3D11RenderTargetView *mBackBufferView; ID3D11RenderTargetView *mBackBufferView;
ID3D11RenderTargetView *mRenderTargetView; ID3D11RenderTargetView *mRenderTargetView;
ID3D11Texture2D *mDepthStencil; ID3D11Texture2D *mDepthStencil;
ID3D11DepthStencilView *mDepthStencilView; ID3D11DepthStencilView *mDepthStencilView;
ID3D11Texture2D *mOffscreenTexture; ID3D11Texture2D *mOffscreenTexture;
}; };
} }
#endif // LIBGLESV2_RENDERER_SWAPCHAIN11_H_ #endif // LIBGLESV2_RENDERER_SWAPCHAIN11_H_
// //
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// SwapChain9.h: Defines a back-end specific class for the D3D9 swap chain. // SwapChain9.h: Defines a back-end specific class for the D3D9 swap chain.
#ifndef LIBGLESV2_RENDERER_SWAPCHAIN9_H_ #ifndef LIBGLESV2_RENDERER_SWAPCHAIN9_H_
#define LIBGLESV2_RENDERER_SWAPCHAIN9_H_ #define LIBGLESV2_RENDERER_SWAPCHAIN9_H_
#include <d3d9.h> #include <d3d9.h>
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libGLESv2/renderer/SwapChain.h" #include "libGLESv2/renderer/SwapChain.h"
namespace rx namespace rx
{ {
class Renderer9; class Renderer9;
class SwapChain9 : public SwapChain class SwapChain9 : public SwapChain
{ {
public: public:
SwapChain9(Renderer9 *renderer, HWND window, HANDLE shareHandle, SwapChain9(Renderer9 *renderer, HWND window, HANDLE shareHandle,
GLenum backBufferFormat, GLenum depthBufferFormat); GLenum backBufferFormat, GLenum depthBufferFormat);
virtual ~SwapChain9(); virtual ~SwapChain9();
virtual EGLint reset(EGLint backbufferWidth, EGLint backbufferHeight, EGLint swapInterval); virtual EGLint reset(EGLint backbufferWidth, EGLint backbufferHeight, EGLint swapInterval);
virtual EGLint swapRect(EGLint x, EGLint y, EGLint width, EGLint height); virtual EGLint swapRect(EGLint x, EGLint y, EGLint width, EGLint height);
virtual IDirect3DSurface9 *getRenderTarget(); virtual IDirect3DSurface9 *getRenderTarget();
virtual IDirect3DSurface9 *getDepthStencil(); virtual IDirect3DSurface9 *getDepthStencil();
virtual IDirect3DTexture9 *getOffscreenTexture(); virtual IDirect3DTexture9 *getOffscreenTexture();
private: private:
DISALLOW_COPY_AND_ASSIGN(SwapChain9); DISALLOW_COPY_AND_ASSIGN(SwapChain9);
void release(); void release();
Renderer9 *mRenderer; Renderer9 *mRenderer;
EGLint mHeight; EGLint mHeight;
EGLint mWidth; EGLint mWidth;
IDirect3DSwapChain9 *mSwapChain; IDirect3DSwapChain9 *mSwapChain;
IDirect3DSurface9 *mBackBuffer; IDirect3DSurface9 *mBackBuffer;
IDirect3DSurface9 *mRenderTarget; IDirect3DSurface9 *mRenderTarget;
IDirect3DSurface9 *mDepthStencil; IDirect3DSurface9 *mDepthStencil;
IDirect3DTexture9* mOffscreenTexture; IDirect3DTexture9* mOffscreenTexture;
}; };
} }
#endif // LIBGLESV2_RENDERER_SWAPCHAIN9_H_ #endif // LIBGLESV2_RENDERER_SWAPCHAIN9_H_
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