Commit b0a53105 by Geoff Lang Committed by Commit Bot

Add a NativeWindowD3D abstract class to handle native window interactions.

The previous NativeWindow class included D3D11 headers while being included in all D3D backds and had platform-dependent includes and members. This turns it into an abstract class that only implements the minimal functionality for each renderer. BUG=angleproject:1345 Change-Id: I8f20339dd6bba719e574a1dcb3ec859897c9228f Reviewed-on: https://chromium-review.googlesource.com/336780Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent ae2d0a0e
......@@ -168,33 +168,14 @@ SurfaceImpl *DisplayD3D::createWindowSurface(const egl::Config *configuration,
const egl::AttributeMap &attribs)
{
ASSERT(mRenderer != nullptr);
EGLint width = static_cast<EGLint>(attribs.get(EGL_WIDTH, 0));
EGLint height = static_cast<EGLint>(attribs.get(EGL_HEIGHT, 0));
EGLint fixedSize = static_cast<EGLint>(attribs.get(EGL_FIXED_SIZE_ANGLE, EGL_FALSE));
EGLint orientation = static_cast<EGLint>(attribs.get(EGL_SURFACE_ORIENTATION_ANGLE, 0));
EGLint directComposition =
static_cast<EGLint>(attribs.get(EGL_DIRECT_COMPOSITION_ANGLE, EGL_FALSE));
if (!fixedSize)
{
width = -1;
height = -1;
}
return SurfaceD3D::createFromWindow(mRenderer, mDisplay, configuration, window, fixedSize,
directComposition, width, height, orientation);
return SurfaceD3D::createFromWindow(mRenderer, mDisplay, configuration, window, attribs);
}
SurfaceImpl *DisplayD3D::createPbufferSurface(const egl::Config *configuration,
const egl::AttributeMap &attribs)
{
ASSERT(mRenderer != nullptr);
EGLint width = static_cast<EGLint>(attribs.get(EGL_WIDTH, 0));
EGLint height = static_cast<EGLint>(attribs.get(EGL_HEIGHT, 0));
return SurfaceD3D::createOffscreen(mRenderer, mDisplay, configuration, nullptr, width, height);
return SurfaceD3D::createOffscreen(mRenderer, mDisplay, configuration, nullptr, attribs);
}
SurfaceImpl *DisplayD3D::createPbufferFromClientBuffer(const egl::Config *configuration,
......@@ -202,12 +183,7 @@ SurfaceImpl *DisplayD3D::createPbufferFromClientBuffer(const egl::Config *config
const egl::AttributeMap &attribs)
{
ASSERT(mRenderer != nullptr);
EGLint width = static_cast<EGLint>(attribs.get(EGL_WIDTH, 0));
EGLint height = static_cast<EGLint>(attribs.get(EGL_HEIGHT, 0));
return SurfaceD3D::createOffscreen(
mRenderer, mDisplay, configuration, shareHandle, width, height);
return SurfaceD3D::createOffscreen(mRenderer, mDisplay, configuration, shareHandle, attribs);
}
SurfaceImpl *DisplayD3D::createPixmapSurface(const egl::Config *configuration,
......@@ -320,7 +296,7 @@ egl::Error DisplayD3D::restoreLostDevice()
bool DisplayD3D::isValidNativeWindow(EGLNativeWindowType window) const
{
return NativeWindow::isValidNativeWindow(window);
return mRenderer->isValidNativeWindow(window);
}
void DisplayD3D::generateExtensions(egl::DisplayExtensions *outExtensions) const
......
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindowD3D.cpp: Defines NativeWindowD3D, a class for managing and performing operations on
// an EGLNativeWindowType for the D3D renderers.
#include "libANGLE/renderer/d3d/NativeWindowD3D.h"
namespace rx
{
NativeWindowD3D::NativeWindowD3D(EGLNativeWindowType window) : mWindow(window)
{
}
NativeWindowD3D::~NativeWindowD3D()
{
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindowD3D.h: Defines NativeWindowD3D, a class for managing and performing operations on an
// EGLNativeWindowType for the D3D renderers.
#ifndef LIBANGLE_RENDERER_D3D_NATIVEWINDOWD3D_H_
#define LIBANGLE_RENDERER_D3D_NATIVEWINDOWD3D_H_
#include "common/debug.h"
#include "common/platform.h"
#include <EGL/eglplatform.h>
#include "libANGLE/Config.h"
namespace rx
{
class NativeWindowD3D : angle::NonCopyable
{
public:
NativeWindowD3D(EGLNativeWindowType window);
virtual ~NativeWindowD3D();
virtual bool initialize() = 0;
virtual bool getClientRect(LPRECT rect) const = 0;
virtual bool isIconic() const = 0;
inline EGLNativeWindowType getNativeWindow() const { return mWindow; }
private:
EGLNativeWindowType mWindow;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_NATIVEWINDOWD3D_H_
......@@ -18,7 +18,6 @@
#include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h"
#include "libANGLE/renderer/d3d/WorkaroundsD3D.h"
#include "libANGLE/renderer/d3d/d3d11/NativeWindow.h"
//FIXME(jmadill): std::array is currently prohibited by Chromium style guide
#include <array>
......@@ -44,6 +43,7 @@ class DeviceD3D;
class EGLImageD3D;
class ImageD3D;
class IndexBuffer;
class NativeWindowD3D;
class ProgramD3D;
class RenderTargetD3D;
class ShaderExecutableD3D;
......@@ -147,7 +147,12 @@ class RendererD3D : public Renderer, public BufferFactoryD3D
// Direct3D Specific methods
virtual DeviceIdentifier getAdapterIdentifier() const = 0;
virtual SwapChainD3D *createSwapChain(NativeWindow nativeWindow,
virtual bool isValidNativeWindow(EGLNativeWindowType window) const = 0;
virtual NativeWindowD3D *createNativeWindow(EGLNativeWindowType window,
const egl::Config *config,
const egl::AttributeMap &attribs) const = 0;
virtual SwapChainD3D *createSwapChain(NativeWindowD3D *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
......
......@@ -21,57 +21,58 @@
namespace rx
{
SurfaceD3D *SurfaceD3D::createOffscreen(RendererD3D *renderer, egl::Display *display, const egl::Config *config, EGLClientBuffer shareHandle,
EGLint width, EGLint height)
{
return new SurfaceD3D(renderer, display, config, width, height, EGL_TRUE, 0, EGL_FALSE,
shareHandle, NULL);
}
SurfaceD3D *SurfaceD3D::createFromWindow(RendererD3D *renderer,
egl::Display *display,
const egl::Config *config,
EGLNativeWindowType window,
EGLint fixedSize,
EGLint directComposition,
EGLint width,
EGLint height,
EGLint orientation)
const egl::AttributeMap &attribs)
{
return new SurfaceD3D(renderer, display, config, window, static_cast<EGLClientBuffer>(0),
attribs);
}
SurfaceD3D *SurfaceD3D::createOffscreen(RendererD3D *renderer,
egl::Display *display,
const egl::Config *config,
EGLClientBuffer shareHandle,
const egl::AttributeMap &attribs)
{
return new SurfaceD3D(renderer, display, config, width, height, fixedSize, orientation,
directComposition, static_cast<EGLClientBuffer>(0), window);
return new SurfaceD3D(renderer, display, config, static_cast<EGLNativeWindowType>(0),
shareHandle, attribs);
}
SurfaceD3D::SurfaceD3D(RendererD3D *renderer,
egl::Display *display,
const egl::Config *config,
EGLint width,
EGLint height,
EGLint fixedSize,
EGLint orientation,
EGLint directComposition,
EGLNativeWindowType window,
EGLClientBuffer shareHandle,
EGLNativeWindowType window)
const egl::AttributeMap &attribs)
: SurfaceImpl(),
mRenderer(renderer),
mDisplay(display),
mFixedSize(fixedSize == EGL_TRUE),
mOrientation(orientation),
mFixedSize(window == nullptr || attribs.get(EGL_FIXED_SIZE_ANGLE, EGL_FALSE) == EGL_TRUE),
mOrientation(static_cast<EGLint>(attribs.get(EGL_SURFACE_ORIENTATION_ANGLE, 0))),
mRenderTargetFormat(config->renderTargetFormat),
mDepthStencilFormat(config->depthStencilFormat),
mSwapChain(nullptr),
mSwapIntervalDirty(true),
mNativeWindow(window, config, directComposition == EGL_TRUE),
mWidth(width),
mHeight(height),
mNativeWindow(renderer->createNativeWindow(window, config, attribs)),
mWidth(static_cast<EGLint>(attribs.get(EGL_WIDTH, 0))),
mHeight(static_cast<EGLint>(attribs.get(EGL_HEIGHT, 0))),
mSwapInterval(1),
mShareHandle(reinterpret_cast<HANDLE *>(shareHandle))
{
if (window != nullptr && !mFixedSize)
{
mWidth = -1;
mHeight = -1;
}
}
SurfaceD3D::~SurfaceD3D()
{
releaseSwapChain();
SafeDelete(mNativeWindow);
}
void SurfaceD3D::releaseSwapChain()
......@@ -81,9 +82,9 @@ void SurfaceD3D::releaseSwapChain()
egl::Error SurfaceD3D::initialize()
{
if (mNativeWindow.getNativeWindow())
if (mNativeWindow->getNativeWindow())
{
if (!mNativeWindow.initialize())
if (!mNativeWindow->initialize())
{
return egl::Error(EGL_BAD_SURFACE);
}
......@@ -123,7 +124,7 @@ egl::Error SurfaceD3D::resetSwapChain()
if (!mFixedSize)
{
RECT windowRect;
if (!mNativeWindow.getClientRect(&windowRect))
if (!mNativeWindow->getClientRect(&windowRect))
{
ASSERT(false);
......@@ -247,11 +248,11 @@ bool SurfaceD3D::checkForOutOfDateSwapChain()
int clientWidth = getWidth();
int clientHeight = getHeight();
bool sizeDirty = false;
if (!mFixedSize && !mNativeWindow.isIconic())
if (!mFixedSize && !mNativeWindow->isIconic())
{
// The window is automatically resized to 150x22 when it's minimized, but the swapchain shouldn't be resized
// because that's not a useful size to render to.
if (!mNativeWindow.getClientRect(&client))
if (!mNativeWindow->getClientRect(&client))
{
ASSERT(false);
return false;
......
......@@ -10,7 +10,7 @@
#define LIBANGLE_RENDERER_D3D_SURFACED3D_H_
#include "libANGLE/renderer/SurfaceImpl.h"
#include "libANGLE/renderer/d3d/d3d11/NativeWindow.h"
#include "libANGLE/renderer/d3d/NativeWindowD3D.h"
namespace egl
{
......@@ -29,13 +29,12 @@ class SurfaceD3D : public SurfaceImpl
egl::Display *display,
const egl::Config *config,
EGLNativeWindowType window,
EGLint fixedSize,
EGLint directComposition,
EGLint width,
EGLint height,
EGLint orientation);
static SurfaceD3D *createOffscreen(RendererD3D *renderer, egl::Display *display, const egl::Config *config,
EGLClientBuffer shareHandle, EGLint width, EGLint height);
const egl::AttributeMap &attribs);
static SurfaceD3D *createOffscreen(RendererD3D *renderer,
egl::Display *display,
const egl::Config *config,
EGLClientBuffer shareHandle,
const egl::AttributeMap &attribs);
~SurfaceD3D() override;
void releaseSwapChain();
......@@ -70,13 +69,9 @@ class SurfaceD3D : public SurfaceImpl
SurfaceD3D(RendererD3D *renderer,
egl::Display *display,
const egl::Config *config,
EGLint width,
EGLint height,
EGLint fixedSize,
EGLint orientation,
EGLint directComposition,
EGLNativeWindowType window,
EGLClientBuffer shareHandle,
EGLNativeWindowType window);
const egl::AttributeMap &attribs);
egl::Error swapRect(EGLint x, EGLint y, EGLint width, EGLint height);
egl::Error resetSwapChain(int backbufferWidth, int backbufferHeight);
......@@ -94,7 +89,7 @@ class SurfaceD3D : public SurfaceImpl
SwapChainD3D *mSwapChain;
bool mSwapIntervalDirty;
NativeWindow mNativeWindow; // Handler for the Window that the surface is created for.
NativeWindowD3D *mNativeWindow; // Handler for the Window that the surface is created for.
EGLint mWidth;
EGLint mHeight;
......
......@@ -16,9 +16,6 @@
#include "common/angleutils.h"
#include "common/platform.h"
// TODO: move out of D3D11
#include "libANGLE/renderer/d3d/d3d11/NativeWindow.h"
#if !defined(ANGLE_FORCE_VSYNC_OFF)
#define ANGLE_FORCE_VSYNC_OFF 0
#endif
......@@ -30,8 +27,10 @@ class RenderTargetD3D;
class SwapChainD3D : angle::NonCopyable
{
public:
SwapChainD3D(rx::NativeWindow nativeWindow, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat)
: mNativeWindow(nativeWindow), mOffscreenRenderTargetFormat(backBufferFormat), mDepthBufferFormat(depthBufferFormat), mShareHandle(shareHandle)
SwapChainD3D(HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat)
: mOffscreenRenderTargetFormat(backBufferFormat),
mDepthBufferFormat(depthBufferFormat),
mShareHandle(shareHandle)
{
}
......@@ -52,7 +51,6 @@ class SwapChainD3D : angle::NonCopyable
virtual void *getKeyedMutex() = 0;
protected:
rx::NativeWindow mNativeWindow; // Handler for the Window that the surface is created for.
const GLenum mOffscreenRenderTargetFormat;
const GLenum mDepthBufferFormat;
......
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow.h: Defines NativeWindow, a class for managing and
// performing operations on an EGLNativeWindowType.
// It is used for HWND (Desktop Windows) and IInspectable objects
//(Windows Store Applications).
#ifndef LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW_H_
#define LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW_H_
#include "common/debug.h"
#include "common/platform.h"
#include <EGL/eglplatform.h>
#include "libANGLE/Config.h"
// DXGISwapChain and DXGIFactory are typedef'd to specific required
// types. The HWND NativeWindow implementation requires IDXGISwapChain
// and IDXGIFactory and the Windows Store NativeWindow
// implementation requires IDXGISwapChain1 and IDXGIFactory2.
#if defined(ANGLE_ENABLE_WINDOWS_STORE)
typedef IDXGISwapChain1 DXGISwapChain;
typedef IDXGIFactory2 DXGIFactory;
#include <wrl.h>
#include <wrl/wrappers/corewrappers.h>
#include <windows.applicationmodel.core.h>
#include <memory>
namespace rx
{
class InspectableNativeWindow;
}
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
#else
typedef IDXGISwapChain DXGISwapChain;
typedef IDXGIFactory DXGIFactory;
#endif
typedef interface IDCompositionDevice IDCompositionDevice;
typedef interface IDCompositionTarget IDCompositionTarget;
typedef interface IDCompositionVisual IDCompositionVisual;
namespace rx
{
class NativeWindow
{
public:
explicit NativeWindow(EGLNativeWindowType window,
const egl::Config *config,
bool directComposition);
~NativeWindow();
bool initialize();
bool getClientRect(LPRECT rect);
bool isIconic();
static bool isValidNativeWindow(EGLNativeWindowType window);
HRESULT createSwapChain(ID3D11Device* device, DXGIFactory* factory,
DXGI_FORMAT format, UINT width, UINT height,
DXGISwapChain** swapChain);
inline EGLNativeWindowType getNativeWindow() const { return mWindow; }
void commitChange();
private:
EGLNativeWindowType mWindow;
bool mDirectComposition;
IDCompositionDevice *mDevice;
IDCompositionTarget *mCompositionTarget;
IDCompositionVisual *mVisual;
const egl::Config *mConfig;
#if defined(ANGLE_ENABLE_WINDOWS_STORE)
std::shared_ptr<InspectableNativeWindow> mImpl;
#endif
};
}
#endif // LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW_H_
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow11.h: Defines NativeWindow11, a class for managing and performing operations on an
// EGLNativeWindowType for the D3D11 renderer.
#ifndef LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW11_H_
#define LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW11_H_
#include "common/debug.h"
#include "common/platform.h"
#include "libANGLE/Config.h"
#include "libANGLE/renderer/d3d/NativeWindowD3D.h"
namespace rx
{
class NativeWindow11 : public NativeWindowD3D
{
public:
NativeWindow11(EGLNativeWindowType window) : NativeWindowD3D(window) {}
virtual HRESULT createSwapChain(ID3D11Device *device,
IDXGIFactory *factory,
DXGI_FORMAT format,
UINT width,
UINT height,
IDXGISwapChain **swapChain) = 0;
virtual void commitChange() = 0;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_NATIVEWINDOW11_H_
......@@ -58,6 +58,12 @@
#include "libANGLE/Surface.h"
#include "third_party/trace_event/trace_event.h"
#ifdef ANGLE_ENABLE_WINDOWS_STORE
#include "libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h"
#else
#include "libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h"
#endif
// Include the D3D9 debug annotator header for use by the desktop D3D11 renderer
// because the D3D11 interface method ID3DUserDefinedAnnotation::GetStatus
// doesn't work with the Graphics Diagnostics tools in Visual Studio 2013.
......@@ -1097,14 +1103,37 @@ gl::Error Renderer11::finish()
return gl::Error(GL_NO_ERROR);
}
SwapChainD3D *Renderer11::createSwapChain(NativeWindow nativeWindow,
bool Renderer11::isValidNativeWindow(EGLNativeWindowType window) const
{
#ifdef ANGLE_ENABLE_WINDOWS_STORE
return NativeWindow11WinRT::IsValidNativeWindow(window);
#else
return NativeWindow11Win32::IsValidNativeWindow(window);
#endif
}
NativeWindowD3D *Renderer11::createNativeWindow(EGLNativeWindowType window,
const egl::Config *config,
const egl::AttributeMap &attribs) const
{
#ifdef ANGLE_ENABLE_WINDOWS_STORE
UNUSED_VARIABLE(attribs);
return new NativeWindow11WinRT(window, config->alphaSize > 0);
#else
return new NativeWindow11Win32(
window, config->alphaSize > 0,
attribs.get(EGL_DIRECT_COMPOSITION_ANGLE, EGL_FALSE) == EGL_TRUE);
#endif
}
SwapChainD3D *Renderer11::createSwapChain(NativeWindowD3D *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
EGLint orientation)
{
return new SwapChain11(this, nativeWindow, shareHandle, backBufferFormat, depthBufferFormat,
orientation);
return new SwapChain11(this, GetAs<NativeWindow11>(nativeWindow), shareHandle, backBufferFormat,
depthBufferFormat, orientation);
}
CompilerImpl *Renderer11::createCompiler()
......
......@@ -113,7 +113,12 @@ class Renderer11 : public RendererD3D
gl::Error flush() override;
gl::Error finish() override;
SwapChainD3D *createSwapChain(NativeWindow nativeWindow,
bool isValidNativeWindow(EGLNativeWindowType window) const override;
NativeWindowD3D *createNativeWindow(EGLNativeWindowType window,
const egl::Config *config,
const egl::AttributeMap &attribs) const override;
SwapChainD3D *createSwapChain(NativeWindowD3D *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
......@@ -247,7 +252,7 @@ class Renderer11 : public RendererD3D
void *getD3DDevice() override;
ID3D11DeviceContext *getDeviceContext() { return mDeviceContext; };
ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; };
DXGIFactory *getDxgiFactory() { return mDxgiFactory; };
IDXGIFactory *getDxgiFactory() { return mDxgiFactory; };
RenderStateCache &getStateCache() { return mStateCache; }
......@@ -482,7 +487,7 @@ class Renderer11 : public RendererD3D
IDXGIAdapter *mDxgiAdapter;
DXGI_ADAPTER_DESC mAdapterDescription;
char mDescription[128];
DXGIFactory *mDxgiFactory;
IDXGIFactory *mDxgiFactory;
ID3D11Debug *mDebug;
std::vector<GLuint> mScratchIndexDataBuffer;
......
......@@ -12,7 +12,7 @@
#include "libANGLE/features.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/NativeWindow.h"
#include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
......@@ -33,22 +33,22 @@ namespace rx
namespace
{
bool NeedsOffscreenTexture(Renderer11 *renderer, NativeWindow nativeWindow, EGLint orientation)
bool NeedsOffscreenTexture(Renderer11 *renderer, NativeWindow11 *nativeWindow, EGLint orientation)
{
// We don't need an offscreen texture if either orientation = INVERT_Y,
// or present path fast is enabled and we're not rendering onto an offscreen surface.
return orientation != EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE &&
!(renderer->presentPathFastEnabled() && nativeWindow.getNativeWindow());
!(renderer->presentPathFastEnabled() && nativeWindow->getNativeWindow());
}
} // anonymous namespace
SwapChain11::SwapChain11(Renderer11 *renderer,
NativeWindow nativeWindow,
NativeWindow11 *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
EGLint orientation)
: SwapChainD3D(nativeWindow, shareHandle, backBufferFormat, depthBufferFormat),
: SwapChainD3D(shareHandle, backBufferFormat, depthBufferFormat),
mRenderer(renderer),
mWidth(-1),
mHeight(-1),
......@@ -56,6 +56,7 @@ SwapChain11::SwapChain11(Renderer11 *renderer,
mAppCreatedShareHandle(mShareHandle != nullptr),
mSwapInterval(0),
mPassThroughResourcesInit(false),
mNativeWindow(nativeWindow),
mFirstSwap(true),
mSwapChain(nullptr),
mSwapChain1(nullptr),
......@@ -218,7 +219,8 @@ EGLint SwapChain11::resetOffscreenColorBuffer(int backbufferWidth, int backbuffe
}
else
{
const bool useSharedResource = !mNativeWindow.getNativeWindow() && mRenderer->getShareHandleSupport();
const bool useSharedResource =
!mNativeWindow->getNativeWindow() && mRenderer->getShareHandleSupport();
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
offscreenTextureDesc.Width = backbufferWidth;
......@@ -525,11 +527,11 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
return EGL_SUCCESS;
}
if (mNativeWindow.getNativeWindow())
if (mNativeWindow->getNativeWindow())
{
HRESULT result = mNativeWindow.createSwapChain(device, mRenderer->getDxgiFactory(),
getSwapChainNativeFormat(),
backbufferWidth, backbufferHeight, &mSwapChain);
HRESULT result = mNativeWindow->createSwapChain(device, mRenderer->getDxgiFactory(),
getSwapChainNativeFormat(), backbufferWidth,
backbufferHeight, &mSwapChain);
if (FAILED(result))
{
......@@ -834,7 +836,7 @@ EGLint SwapChain11::present(EGLint x, EGLint y, EGLint width, EGLint height)
ERR("Present failed with error code 0x%08X", result);
}
mNativeWindow.commitChange();
mNativeWindow->commitChange();
return EGL_SUCCESS;
}
......
......@@ -16,12 +16,13 @@
namespace rx
{
class Renderer11;
class NativeWindow11;
class SwapChain11 : public SwapChainD3D
{
public:
SwapChain11(Renderer11 *renderer,
NativeWindow nativeWindow,
NativeWindow11 *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
......@@ -71,8 +72,10 @@ class SwapChain11 : public SwapChainD3D
unsigned int mSwapInterval;
bool mPassThroughResourcesInit;
NativeWindow11 *mNativeWindow; // Handler for the Window that the surface is created for.
bool mFirstSwap;
DXGISwapChain *mSwapChain;
IDXGISwapChain *mSwapChain;
IDXGISwapChain1 *mSwapChain1;
IDXGIKeyedMutex *mKeyedMutex;
......
......@@ -11,9 +11,15 @@
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#if defined (ANGLE_ENABLE_WINDOWS_STORE)
using namespace ABI::Windows::Foundation;
#include <wrl.h>
#include <wrl/wrappers/corewrappers.h>
#include <windows.applicationmodel.core.h>
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::ApplicationModel;
using namespace ABI::Windows::ApplicationModel::Core;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Foundation::Collections;
#endif
namespace rx
......
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow.cpp: Handler for managing HWND native window types.
// NativeWindow11Win32.cpp: Implementation of NativeWindow11 using win32 window APIs.
#include "libANGLE/renderer/d3d/d3d11/NativeWindow.h"
#include "libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "common/debug.h"
......@@ -17,48 +17,46 @@
namespace rx
{
NativeWindow::NativeWindow(EGLNativeWindowType window,
const egl::Config *config,
bool directComposition)
: mWindow(window),
NativeWindow11Win32::NativeWindow11Win32(EGLNativeWindowType window,
bool hasAlpha,
bool directComposition)
: NativeWindow11(window),
mDirectComposition(directComposition),
mHasAlpha(hasAlpha),
mDevice(nullptr),
mCompositionTarget(nullptr),
mVisual(nullptr),
mConfig(config)
mVisual(nullptr)
{
}
NativeWindow::~NativeWindow()
NativeWindow11Win32::~NativeWindow11Win32()
{
SafeRelease(mCompositionTarget);
SafeRelease(mDevice);
SafeRelease(mVisual);
}
bool NativeWindow::initialize()
bool NativeWindow11Win32::initialize()
{
return true;
}
bool NativeWindow::getClientRect(LPRECT rect)
bool NativeWindow11Win32::getClientRect(LPRECT rect) const
{
return GetClientRect(mWindow, rect) == TRUE;
return GetClientRect(getNativeWindow(), rect) == TRUE;
}
bool NativeWindow::isIconic()
bool NativeWindow11Win32::isIconic() const
{
return IsIconic(mWindow) == TRUE;
return IsIconic(getNativeWindow()) == TRUE;
}
bool NativeWindow::isValidNativeWindow(EGLNativeWindowType window)
{
return IsWindow(window) == TRUE;
}
HRESULT NativeWindow::createSwapChain(ID3D11Device* device, DXGIFactory* factory,
DXGI_FORMAT format, unsigned int width, unsigned int height,
DXGISwapChain** swapChain)
HRESULT NativeWindow11Win32::createSwapChain(ID3D11Device *device,
IDXGIFactory *factory,
DXGI_FORMAT format,
UINT width,
UINT height,
IDXGISwapChain **swapChain)
{
if (device == NULL || factory == NULL || swapChain == NULL || width == 0 || height == 0)
{
......@@ -98,7 +96,8 @@ HRESULT NativeWindow::createSwapChain(ID3D11Device* device, DXGIFactory* factory
if (!mCompositionTarget)
{
HRESULT result = mDevice->CreateTargetForHwnd(mWindow, TRUE, &mCompositionTarget);
HRESULT result =
mDevice->CreateTargetForHwnd(getNativeWindow(), TRUE, &mCompositionTarget);
if (FAILED(result))
{
return result;
......@@ -121,21 +120,21 @@ HRESULT NativeWindow::createSwapChain(ID3D11Device* device, DXGIFactory* factory
swapChainDesc.Format = format;
swapChainDesc.Stereo = FALSE;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage =
DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_BACK_BUFFER | DXGI_USAGE_SHADER_INPUT;
swapChainDesc.BufferCount = 2;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.BufferCount = 2;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
swapChainDesc.AlphaMode =
mConfig->alphaSize == 0 ? DXGI_ALPHA_MODE_IGNORE : DXGI_ALPHA_MODE_PREMULTIPLIED;
mHasAlpha ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE;
swapChainDesc.Flags = 0;
IDXGISwapChain1 *swapChain1 = nullptr;
HRESULT result =
factory2->CreateSwapChainForComposition(device, &swapChainDesc, nullptr, &swapChain1);
if (SUCCEEDED(result))
{
*swapChain = static_cast<DXGISwapChain *>(swapChain1);
*swapChain = static_cast<IDXGISwapChain *>(swapChain1);
}
mVisual->SetContent(swapChain1);
mCompositionTarget->SetRoot(mVisual);
......@@ -143,60 +142,68 @@ HRESULT NativeWindow::createSwapChain(ID3D11Device* device, DXGIFactory* factory
return result;
}
// Use IDXGIFactory2::CreateSwapChainForHwnd if DXGI 1.2 is available to create a DXGI_SWAP_EFFECT_SEQUENTIAL swap chain.
// Use IDXGIFactory2::CreateSwapChainForHwnd if DXGI 1.2 is available to create a
// DXGI_SWAP_EFFECT_SEQUENTIAL swap chain.
IDXGIFactory2 *factory2 = d3d11::DynamicCastComObject<IDXGIFactory2>(factory);
if (factory2 != nullptr)
{
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 };
swapChainDesc.Width = width;
swapChainDesc.Height = height;
swapChainDesc.Format = format;
swapChainDesc.Stereo = FALSE;
swapChainDesc.SampleDesc.Count = 1;
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Width = width;
swapChainDesc.Height = height;
swapChainDesc.Format = format;
swapChainDesc.Stereo = FALSE;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage =
DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_BACK_BUFFER;
swapChainDesc.BufferCount = 1;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
swapChainDesc.Flags = 0;
swapChainDesc.BufferCount = 1;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
swapChainDesc.Flags = 0;
IDXGISwapChain1 *swapChain1 = nullptr;
HRESULT result = factory2->CreateSwapChainForHwnd(device, mWindow, &swapChainDesc, nullptr, nullptr, &swapChain1);
HRESULT result = factory2->CreateSwapChainForHwnd(device, getNativeWindow(), &swapChainDesc,
nullptr, nullptr, &swapChain1);
if (SUCCEEDED(result))
{
*swapChain = static_cast<DXGISwapChain*>(swapChain1);
*swapChain = static_cast<IDXGISwapChain *>(swapChain1);
}
SafeRelease(factory2);
return result;
}
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Format = format;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Format = format;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage =
DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_BACK_BUFFER;
swapChainDesc.Flags = 0;
swapChainDesc.OutputWindow = mWindow;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.Flags = 0;
swapChainDesc.OutputWindow = getNativeWindow();
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = TRUE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
swapChainDesc.Windowed = TRUE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
return factory->CreateSwapChain(device, &swapChainDesc, swapChain);
}
void NativeWindow::commitChange()
void NativeWindow11Win32::commitChange()
{
if (mDevice)
{
mDevice->Commit();
}
}
// static
bool NativeWindow11Win32::IsValidNativeWindow(EGLNativeWindowType window)
{
return IsWindow(window) == TRUE;
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow11Win32.h: Implementation of NativeWindow11 using win32 window APIs.
#ifndef LIBANGLE_RENDERER_D3D_D3D11_WIN32_NATIVEWINDOW11WIN32_H_
#define LIBANGLE_RENDERER_D3D_D3D11_WIN32_NATIVEWINDOW11WIN32_H_
#include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h"
typedef interface IDCompositionDevice IDCompositionDevice;
typedef interface IDCompositionTarget IDCompositionTarget;
typedef interface IDCompositionVisual IDCompositionVisual;
namespace rx
{
class NativeWindow11Win32 : public NativeWindow11
{
public:
NativeWindow11Win32(EGLNativeWindowType window, bool hasAlpha, bool directComposition);
~NativeWindow11Win32() override;
bool initialize() override;
bool getClientRect(LPRECT rect) const override;
bool isIconic() const override;
HRESULT createSwapChain(ID3D11Device *device,
IDXGIFactory *factory,
DXGI_FORMAT format,
UINT width,
UINT height,
IDXGISwapChain **swapChain) override;
void commitChange() override;
static bool IsValidNativeWindow(EGLNativeWindowType window);
private:
bool mDirectComposition;
bool mHasAlpha;
IDCompositionDevice *mDevice;
IDCompositionTarget *mCompositionTarget;
IDCompositionVisual *mVisual;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_WIN32_NATIVEWINDOW11WIN32_H_
......@@ -135,12 +135,12 @@ void CoreWindowNativeWindow::unregisterForSizeChangeEvents()
}
HRESULT CoreWindowNativeWindow::createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
IDXGIFactory2 *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain)
IDXGISwapChain1 **swapChain)
{
if (device == NULL || factory == NULL || swapChain == NULL || width == 0 || height == 0)
{
......
......@@ -13,6 +13,8 @@
#include <memory>
#include <EGL/eglplatform.h>
typedef ABI::Windows::Foundation::__FITypedEventHandler_2_Windows__CUI__CCore__CCoreWindow_Windows__CUI__CCore__CWindowSizeChangedEventArgs_t IWindowSizeChangedEventHandler;
namespace rx
......@@ -26,12 +28,12 @@ class CoreWindowNativeWindow : public InspectableNativeWindow, public std::enabl
bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) override;
HRESULT createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
IDXGIFactory2 *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain) override;
IDXGISwapChain1 **swapChain) override;
protected:
HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) override;
......
......@@ -11,96 +11,6 @@
namespace rx
{
NativeWindow::NativeWindow(EGLNativeWindowType window,
const egl::Config *config,
bool directComposition)
{
mWindow = window;
mConfig = config;
}
NativeWindow::~NativeWindow()
{
}
void NativeWindow::commitChange()
{
}
bool NativeWindow::initialize()
{
// If the native window type is a IPropertySet, extract the
// EGLNativeWindowType (IInspectable) and initialize the
// proper host with this IPropertySet.
ComPtr<ABI::Windows::Foundation::Collections::IPropertySet> propertySet;
ComPtr<IInspectable> eglNativeWindow;
if (IsEGLConfiguredPropertySet(mWindow, &propertySet, &eglNativeWindow))
{
// A property set was found and the EGLNativeWindowType was
// retrieved. The mWindow member of the host to must be updated
// to use the EGLNativeWindowType specified in the property set.
// mWindow is treated as a raw pointer not an AddRef'd interface, so
// the old mWindow does not need a Release() before this assignment.
mWindow = eglNativeWindow.Get();
}
ComPtr<ABI::Windows::UI::Core::ICoreWindow> coreWindow;
ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> swapChainPanel;
if (IsCoreWindow(mWindow, &coreWindow))
{
mImpl = std::make_shared<CoreWindowNativeWindow>();
if (mImpl)
{
return mImpl->initialize(mWindow, propertySet.Get());
}
}
else if (IsSwapChainPanel(mWindow, &swapChainPanel))
{
mImpl = std::make_shared<SwapChainPanelNativeWindow>();
if (mImpl)
{
return mImpl->initialize(mWindow, propertySet.Get());
}
}
else
{
ERR("Invalid IInspectable EGLNativeWindowType detected. Valid IInspectables include ICoreWindow, ISwapChainPanel and IPropertySet");
}
return false;
}
bool NativeWindow::getClientRect(RECT *rect)
{
if (mImpl)
{
return mImpl->getClientRect(rect);
}
return false;
}
bool NativeWindow::isIconic()
{
return false;
}
bool NativeWindow::isValidNativeWindow(EGLNativeWindowType window)
{
return IsValidEGLNativeWindowType(window);
}
HRESULT NativeWindow::createSwapChain(ID3D11Device *device, DXGIFactory *factory, DXGI_FORMAT format, unsigned int width, unsigned int height, DXGISwapChain **swapChain)
{
if (mImpl)
{
bool containsAlpha = (mConfig->alphaSize > 0);
return mImpl->createSwapChain(device, factory, format, width, height, containsAlpha,
swapChain);
}
return E_UNEXPECTED;
}
bool IsCoreWindow(EGLNativeWindowType window, ComPtr<ABI::Windows::UI::Core::ICoreWindow> *coreWindow)
{
......@@ -207,18 +117,6 @@ bool IsEGLConfiguredPropertySet(EGLNativeWindowType window, ABI::Windows::Founda
return false;
}
// A Valid EGLNativeWindowType IInspectable can only be:
//
// ICoreWindow
// ISwapChainPanel
// IPropertySet
//
// Anything else will be rejected as an invalid IInspectable.
bool IsValidEGLNativeWindowType(EGLNativeWindowType window)
{
return IsCoreWindow(window) || IsSwapChainPanel(window) || IsEGLConfiguredPropertySet(window);
}
// Retrieve an optional property from a property set
HRESULT GetOptionalPropertyValue(const ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> &propertyMap,
const wchar_t *propertyName,
......
......@@ -10,14 +10,18 @@
#ifndef LIBANGLE_RENDERER_D3D_D3D11_WINRT_INSPECTABLENATIVEWINDOW_H_
#define LIBANGLE_RENDERER_D3D_D3D11_WINRT_INSPECTABLENATIVEWINDOW_H_
#include "libANGLE/renderer/d3d/d3d11/NativeWindow.h"
#include "common/debug.h"
#include "common/platform.h"
#include "angle_windowsstore.h"
#include <EGL/eglplatform.h>
#include <windows.applicationmodel.core.h>
#include <windows.ui.xaml.h>
#include <windows.ui.xaml.media.dxinterop.h>
#include <wrl.h>
#include <wrl/wrappers/corewrappers.h>
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
......@@ -44,12 +48,12 @@ class InspectableNativeWindow
virtual bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) = 0;
virtual HRESULT createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
IDXGIFactory2 *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain) = 0;
IDXGISwapChain1 **swapChain) = 0;
bool getClientRect(RECT *rect)
{
......@@ -108,7 +112,6 @@ class InspectableNativeWindow
EventRegistrationToken mSizeChangedEventToken;
};
bool IsValidEGLNativeWindowType(EGLNativeWindowType window);
bool IsCoreWindow(EGLNativeWindowType window, ComPtr<ABI::Windows::UI::Core::ICoreWindow> *coreWindow = nullptr);
bool IsSwapChainPanel(EGLNativeWindowType window, ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> *swapChainPanel = nullptr);
bool IsEGLConfiguredPropertySet(EGLNativeWindowType window, ABI::Windows::Foundation::Collections::IPropertySet **propertySet = nullptr, IInspectable **inspectable = nullptr);
......
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow11WinRT.cpp: NativeWindow base class for managing IInspectable native window types.
#include "libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h"
#include "libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h"
#include "libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h"
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
namespace rx
{
NativeWindow11WinRT::NativeWindow11WinRT(EGLNativeWindowType window, bool hasAlpha)
: NativeWindow11(window), mHasAlpha(hasAlpha)
{
}
bool NativeWindow11WinRT::initialize()
{
EGLNativeWindowType window = getNativeWindow();
// If the native window type is a IPropertySet, extract the
// EGLNativeWindowType (IInspectable) and initialize the
// proper host with this IPropertySet.
ComPtr<ABI::Windows::Foundation::Collections::IPropertySet> propertySet;
ComPtr<IInspectable> eglNativeWindow;
if (IsEGLConfiguredPropertySet(window, &propertySet, &eglNativeWindow))
{
// A property set was found and the EGLNativeWindowType was
// retrieved. The mWindow member of the host to must be updated
// to use the EGLNativeWindowType specified in the property set.
// mWindow is treated as a raw pointer not an AddRef'd interface, so
// the old mWindow does not need a Release() before this assignment.
window = eglNativeWindow.Get();
}
ComPtr<ABI::Windows::UI::Core::ICoreWindow> coreWindow;
ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> swapChainPanel;
if (IsCoreWindow(window, &coreWindow))
{
mImpl = std::make_shared<CoreWindowNativeWindow>();
if (mImpl)
{
return mImpl->initialize(window, propertySet.Get());
}
}
else if (IsSwapChainPanel(window, &swapChainPanel))
{
mImpl = std::make_shared<SwapChainPanelNativeWindow>();
if (mImpl)
{
return mImpl->initialize(window, propertySet.Get());
}
}
else
{
ERR(
"Invalid IInspectable EGLNativeWindowType detected. Valid IInspectables include "
"ICoreWindow, ISwapChainPanel and IPropertySet");
}
return false;
}
bool NativeWindow11WinRT::getClientRect(LPRECT rect) const
{
if (mImpl)
{
return mImpl->getClientRect(rect);
}
return false;
}
bool NativeWindow11WinRT::isIconic() const
{
return false;
}
HRESULT NativeWindow11WinRT::createSwapChain(ID3D11Device *device,
IDXGIFactory *factory,
DXGI_FORMAT format,
UINT width,
UINT height,
IDXGISwapChain **swapChain)
{
if (mImpl)
{
IDXGIFactory2 *factory2 = d3d11::DynamicCastComObject<IDXGIFactory2>(factory);
IDXGISwapChain1 *swapChain1 = nullptr;
HRESULT result =
mImpl->createSwapChain(device, factory2, format, width, height, mHasAlpha, &swapChain1);
SafeRelease(factory2);
*swapChain = static_cast<IDXGISwapChain *>(swapChain1);
return result;
}
return E_UNEXPECTED;
}
void NativeWindow11WinRT::commitChange()
{
}
// static
bool NativeWindow11WinRT::IsValidNativeWindow(EGLNativeWindowType window)
{
// A Valid EGLNativeWindowType IInspectable can only be:
//
// ICoreWindow
// ISwapChainPanel
// IPropertySet
//
// Anything else will be rejected as an invalid IInspectable.
return IsCoreWindow(window) || IsSwapChainPanel(window) || IsEGLConfiguredPropertySet(window);
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow11WinRT.h: NativeWindow base class for managing IInspectable native window types.
#ifndef LIBANGLE_RENDERER_D3D_D3D11_WINRT_NATIVEWINDOW11WINRT_H_
#define LIBANGLE_RENDERER_D3D_D3D11_WINRT_NATIVEWINDOW11WINRT_H_
#include "libANGLE/renderer/d3d/d3d11/NativeWindow11.h"
#include <memory>
#include <windows.applicationmodel.core.h>
#include <wrl.h>
#include <wrl/wrappers/corewrappers.h>
namespace rx
{
class InspectableNativeWindow;
class NativeWindow11WinRT : public NativeWindow11
{
public:
NativeWindow11WinRT(EGLNativeWindowType window, bool hasAlpha);
bool initialize() override;
bool getClientRect(LPRECT rect) const override;
bool isIconic() const override;
HRESULT createSwapChain(ID3D11Device *device,
IDXGIFactory *factory,
DXGI_FORMAT format,
UINT width,
UINT height,
IDXGISwapChain **swapChain) override;
void commitChange() override;
static bool IsValidNativeWindow(EGLNativeWindowType window);
private:
bool mHasAlpha;
std::shared_ptr<InspectableNativeWindow> mImpl;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_NATIVEWINDOW11WINRT_H_
......@@ -238,12 +238,12 @@ void SwapChainPanelNativeWindow::unregisterForSizeChangeEvents()
}
HRESULT SwapChainPanelNativeWindow::createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
IDXGIFactory2 *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain)
IDXGISwapChain1 **swapChain)
{
if (device == NULL || factory == NULL || swapChain == NULL || width == 0 || height == 0)
{
......
......@@ -11,6 +11,8 @@
#include "libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h"
#include <memory>
namespace rx
{
class SwapChainPanelNativeWindow : public InspectableNativeWindow, public std::enable_shared_from_this<SwapChainPanelNativeWindow>
......@@ -20,12 +22,12 @@ class SwapChainPanelNativeWindow : public InspectableNativeWindow, public std::e
bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) override;
HRESULT createSwapChain(ID3D11Device *device,
DXGIFactory *factory,
IDXGIFactory2 *factory,
DXGI_FORMAT format,
unsigned int width,
unsigned int height,
bool containsAlpha,
DXGISwapChain **swapChain) override;
IDXGISwapChain1 **swapChain) override;
protected:
HRESULT scaleSwapChain(const SIZE &windowSize, const RECT &clientRect) override;
......@@ -37,7 +39,7 @@ class SwapChainPanelNativeWindow : public InspectableNativeWindow, public std::e
ComPtr<ABI::Windows::UI::Xaml::Controls::ISwapChainPanel> mSwapChainPanel;
ComPtr<ABI::Windows::UI::Core::ICoreDispatcher> mSwapChainPanelDispatcher;
ComPtr<IMap<HSTRING, IInspectable*>> mPropertyMap;
ComPtr<DXGISwapChain> mSwapChain;
ComPtr<IDXGISwapChain1> mSwapChain;
};
[uuid(8ACBD974-8187-4508-AD80-AEC77F93CF36)]
......
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow9.cpp: Defines NativeWindow9, a class for managing and
// performing operations on an EGLNativeWindowType for the D3D9 renderer.
#include "libANGLE/renderer/d3d/d3d9/NativeWindow9.h"
namespace rx
{
NativeWindow9::NativeWindow9(EGLNativeWindowType window) : NativeWindowD3D(window)
{
}
bool NativeWindow9::initialize()
{
return true;
}
bool NativeWindow9::getClientRect(LPRECT rect) const
{
return GetClientRect(getNativeWindow(), rect) == TRUE;
}
bool NativeWindow9::isIconic() const
{
return IsIconic(getNativeWindow()) == TRUE;
}
// static
bool NativeWindow9::IsValidNativeWindow(EGLNativeWindowType window)
{
return IsWindow(window) == TRUE;
}
} // namespace rx
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// NativeWindow9.h: Defines NativeWindow9, a class for managing and
// performing operations on an EGLNativeWindowType for the D3D9 renderer.
#ifndef LIBANGLE_RENDERER_D3D_D3D9_NATIVEWINDOW9_H_
#define LIBANGLE_RENDERER_D3D_D3D9_NATIVEWINDOW9_H_
#include "common/debug.h"
#include "common/platform.h"
#include "libANGLE/renderer/d3d/NativeWindowD3D.h"
namespace rx
{
class NativeWindow9 : public NativeWindowD3D
{
public:
explicit NativeWindow9(EGLNativeWindowType window);
bool initialize() override;
bool getClientRect(LPRECT rect) const override;
bool isIconic() const override;
static bool IsValidNativeWindow(EGLNativeWindowType window);
};
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D9_NATIVEWINDOW9_H_
......@@ -28,6 +28,7 @@
#include "libANGLE/renderer/d3d/d3d9/Framebuffer9.h"
#include "libANGLE/renderer/d3d/d3d9/Image9.h"
#include "libANGLE/renderer/d3d/d3d9/IndexBuffer9.h"
#include "libANGLE/renderer/d3d/d3d9/NativeWindow9.h"
#include "libANGLE/renderer/d3d/d3d9/Query9.h"
#include "libANGLE/renderer/d3d/d3d9/renderer9_utils.h"
#include "libANGLE/renderer/d3d/d3d9/RenderTarget9.h"
......@@ -657,14 +658,26 @@ gl::Error Renderer9::finish()
return gl::Error(GL_NO_ERROR);
}
SwapChainD3D *Renderer9::createSwapChain(NativeWindow nativeWindow,
bool Renderer9::isValidNativeWindow(EGLNativeWindowType window) const
{
return NativeWindow9::IsValidNativeWindow(window);
}
NativeWindowD3D *Renderer9::createNativeWindow(EGLNativeWindowType window,
const egl::Config *,
const egl::AttributeMap &) const
{
return new NativeWindow9(window);
}
SwapChainD3D *Renderer9::createSwapChain(NativeWindowD3D *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
EGLint orientation)
{
return new SwapChain9(this, nativeWindow, shareHandle, backBufferFormat, depthBufferFormat,
orientation);
return new SwapChain9(this, GetAs<NativeWindow9>(nativeWindow), shareHandle, backBufferFormat,
depthBufferFormat, orientation);
}
CompilerImpl *Renderer9::createCompiler()
......
......@@ -79,7 +79,12 @@ class Renderer9 : public RendererD3D
gl::Error flush() override;
gl::Error finish() override;
SwapChainD3D *createSwapChain(NativeWindow nativeWindow,
bool isValidNativeWindow(EGLNativeWindowType window) const override;
NativeWindowD3D *createNativeWindow(EGLNativeWindowType window,
const egl::Config *config,
const egl::AttributeMap &attribs) const override;
SwapChainD3D *createSwapChain(NativeWindowD3D *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
......
......@@ -9,6 +9,7 @@
#include "libANGLE/renderer/d3d/d3d9/SwapChain9.h"
#include "libANGLE/renderer/d3d/d3d9/renderer9_utils.h"
#include "libANGLE/renderer/d3d/d3d9/formatutils9.h"
#include "libANGLE/renderer/d3d/d3d9/NativeWindow9.h"
#include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
#include "libANGLE/features.h"
......@@ -16,16 +17,17 @@ namespace rx
{
SwapChain9::SwapChain9(Renderer9 *renderer,
NativeWindow nativeWindow,
NativeWindow9 *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
EGLint orientation)
: SwapChainD3D(nativeWindow, shareHandle, backBufferFormat, depthBufferFormat),
: SwapChainD3D(shareHandle, backBufferFormat, depthBufferFormat),
mRenderer(renderer),
mWidth(-1),
mHeight(-1),
mSwapInterval(-1),
mNativeWindow(nativeWindow),
mSwapChain(nullptr),
mBackBuffer(nullptr),
mRenderTarget(nullptr),
......@@ -50,7 +52,7 @@ void SwapChain9::release()
SafeRelease(mRenderTarget);
SafeRelease(mOffscreenTexture);
if (mNativeWindow.getNativeWindow())
if (mNativeWindow->getNativeWindow())
{
mShareHandle = NULL;
}
......@@ -104,7 +106,7 @@ EGLint SwapChain9::reset(int backbufferWidth, int backbufferHeight, EGLint swapI
SafeRelease(mDepthStencil);
HANDLE *pShareHandle = NULL;
if (!mNativeWindow.getNativeWindow() && mRenderer->getShareHandleSupport())
if (!mNativeWindow->getNativeWindow() && mRenderer->getShareHandleSupport())
{
pShareHandle = &mShareHandle;
}
......@@ -163,7 +165,7 @@ EGLint SwapChain9::reset(int backbufferWidth, int backbufferHeight, EGLint swapI
// Don't create a swapchain for NULLREF devices
D3DDEVTYPE deviceType = mRenderer->getD3D9DeviceType();
EGLNativeWindowType window = mNativeWindow.getNativeWindow();
EGLNativeWindowType window = mNativeWindow->getNativeWindow();
if (window && deviceType != D3DDEVTYPE_NULLREF)
{
D3DPRESENT_PARAMETERS presentParameters = {0};
......
......@@ -15,13 +15,14 @@
namespace rx
{
class NativeWindow9;
class Renderer9;
class SwapChain9 : public SwapChainD3D
{
public:
SwapChain9(Renderer9 *renderer,
NativeWindow nativeWindow,
NativeWindow9 *nativeWindow,
HANDLE shareHandle,
GLenum backBufferFormat,
GLenum depthBufferFormat,
......@@ -53,6 +54,8 @@ class SwapChain9 : public SwapChainD3D
EGLint mHeight;
EGLint mSwapInterval;
NativeWindow9 *mNativeWindow;
IDirect3DSwapChain9 *mSwapChain;
IDirect3DSurface9 *mBackBuffer;
IDirect3DSurface9 *mRenderTarget;
......
......@@ -208,6 +208,8 @@
'libANGLE/renderer/d3d/loadimageSSE2.cpp',
'libANGLE/renderer/d3d/loadimage_etc.cpp',
'libANGLE/renderer/d3d/loadimage_etc.h',
'libANGLE/renderer/d3d/NativeWindowD3D.cpp',
'libANGLE/renderer/d3d/NativeWindowD3D.h',
'libANGLE/renderer/d3d/ProgramD3D.cpp',
'libANGLE/renderer/d3d/ProgramD3D.h',
'libANGLE/renderer/d3d/RenderbufferD3D.cpp',
......@@ -255,6 +257,8 @@
'libANGLE/renderer/d3d/d3d9/Image9.h',
'libANGLE/renderer/d3d/d3d9/IndexBuffer9.cpp',
'libANGLE/renderer/d3d/d3d9/IndexBuffer9.h',
'libANGLE/renderer/d3d/d3d9/NativeWindow9.cpp',
'libANGLE/renderer/d3d/d3d9/NativeWindow9.h',
'libANGLE/renderer/d3d/d3d9/Query9.cpp',
'libANGLE/renderer/d3d/d3d9/Query9.h',
'libANGLE/renderer/d3d/d3d9/Renderer9.cpp',
......@@ -312,7 +316,7 @@
'libANGLE/renderer/d3d/d3d11/InputLayoutCache.h',
'libANGLE/renderer/d3d/d3d11/load_functions_table.h',
'libANGLE/renderer/d3d/d3d11/load_functions_table_autogen.cpp',
'libANGLE/renderer/d3d/d3d11/NativeWindow.h',
'libANGLE/renderer/d3d/d3d11/NativeWindow11.h',
'libANGLE/renderer/d3d/d3d11/PixelTransfer11.cpp',
'libANGLE/renderer/d3d/d3d11/PixelTransfer11.h',
'libANGLE/renderer/d3d/d3d11/Query11.cpp',
......@@ -399,18 +403,21 @@
],
'libangle_d3d11_win32_sources':
[
'libANGLE/renderer/d3d/d3d11/win32/NativeWindow.cpp',
'libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.cpp',
'libANGLE/renderer/d3d/d3d11/win32/NativeWindow11Win32.h',
'third_party/systeminfo/SystemInfo.cpp',
'third_party/systeminfo/SystemInfo.h',
],
'libangle_d3d11_winrt_sources':
[
'libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.cpp',
'libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h',
'libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.cpp',
'libANGLE/renderer/d3d/d3d11/winrt/CoreWindowNativeWindow.h',
'libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.cpp',
'libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h',
'libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.cpp',
'libANGLE/renderer/d3d/d3d11/winrt/NativeWindow11WinRT.h',
'libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.cpp',
'libANGLE/renderer/d3d/d3d11/winrt/SwapChainPanelNativeWindow.h',
],
'libangle_gl_sources':
[
......
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