1 // 2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // SwapChain11.h: Defines a back-end specific class for the D3D11 swap chain. 8 9 #ifndef LIBANGLE_RENDERER_D3D_D3D11_SWAPCHAIN11_H_ 10 #define LIBANGLE_RENDERER_D3D_D3D11_SWAPCHAIN11_H_ 11 12 #include "common/angleutils.h" 13 #include "libANGLE/renderer/d3d/SwapChainD3D.h" 14 #include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" 15 16 namespace rx 17 { 18 class Renderer11; 19 class NativeWindow11; 20 21 class SwapChain11 final : public SwapChainD3D 22 { 23 public: 24 SwapChain11(Renderer11 *renderer, 25 NativeWindow11 *nativeWindow, 26 HANDLE shareHandle, 27 IUnknown *d3dTexture, 28 GLenum backBufferFormat, 29 GLenum depthBufferFormat, 30 EGLint orientation, 31 EGLint samples); 32 ~SwapChain11() override; 33 34 EGLint resize(const gl::Context *context, 35 EGLint backbufferWidth, 36 EGLint backbufferHeight) override; 37 EGLint reset(const gl::Context *context, 38 EGLint backbufferWidth, 39 EGLint backbufferHeight, 40 EGLint swapInterval) override; 41 EGLint swapRect(const gl::Context *context, 42 EGLint x, 43 EGLint y, 44 EGLint width, 45 EGLint height) override; 46 void recreate() override; 47 48 RenderTargetD3D *getColorRenderTarget() override; 49 RenderTargetD3D *getDepthStencilRenderTarget() override; 50 51 const TextureHelper11 &getOffscreenTexture(); 52 const d3d11::RenderTargetView &getRenderTarget(); 53 const d3d11::SharedSRV &getRenderTargetShaderResource(); 54 55 const TextureHelper11 &getDepthStencilTexture(); 56 const d3d11::DepthStencilView &getDepthStencil(); 57 const d3d11::SharedSRV &getDepthStencilShaderResource(); 58 getWidth()59 EGLint getWidth() const { return mWidth; } getHeight()60 EGLint getHeight() const { return mHeight; } 61 void *getKeyedMutex() override; getSamples()62 EGLint getSamples() const { return mEGLSamples; } 63 64 void *getDevice() override; 65 66 egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) override; 67 68 private: 69 void release(); 70 void initPassThroughResources(); 71 72 void releaseOffscreenColorBuffer(); 73 void releaseOffscreenDepthBuffer(); 74 EGLint resetOffscreenBuffers(const gl::Context *context, 75 int backbufferWidth, 76 int backbufferHeight); 77 EGLint resetOffscreenColorBuffer(const gl::Context *context, 78 int backbufferWidth, 79 int backbufferHeight); 80 EGLint resetOffscreenDepthBuffer(int backbufferWidth, int backbufferHeight); 81 82 DXGI_FORMAT getSwapChainNativeFormat() const; 83 84 EGLint copyOffscreenToBackbuffer(const gl::Context *context, 85 EGLint x, 86 EGLint y, 87 EGLint width, 88 EGLint height); 89 EGLint present(const gl::Context *context, EGLint x, EGLint y, EGLint width, EGLint height); 90 UINT getD3DSamples() const; 91 92 Renderer11 *mRenderer; 93 EGLint mWidth; 94 EGLint mHeight; 95 const EGLint mOrientation; 96 bool mAppCreatedShareHandle; 97 unsigned int mSwapInterval; 98 bool mPassThroughResourcesInit; 99 100 NativeWindow11 *mNativeWindow; // Handler for the Window that the surface is created for. 101 102 bool mFirstSwap; 103 IDXGISwapChain *mSwapChain; 104 IDXGISwapChain1 *mSwapChain1; 105 IDXGIKeyedMutex *mKeyedMutex; 106 107 TextureHelper11 mBackBufferTexture; 108 d3d11::RenderTargetView mBackBufferRTView; 109 d3d11::SharedSRV mBackBufferSRView; 110 111 const bool mNeedsOffscreenTexture; 112 TextureHelper11 mOffscreenTexture; 113 d3d11::RenderTargetView mOffscreenRTView; 114 d3d11::SharedSRV mOffscreenSRView; 115 bool mNeedsOffscreenTextureCopy; 116 TextureHelper11 mOffscreenTextureCopyForSRV; 117 118 TextureHelper11 mDepthStencilTexture; 119 d3d11::DepthStencilView mDepthStencilDSView; 120 d3d11::SharedSRV mDepthStencilSRView; 121 122 d3d11::Buffer mQuadVB; 123 d3d11::SamplerState mPassThroughSampler; 124 d3d11::InputLayout mPassThroughIL; 125 d3d11::VertexShader mPassThroughVS; 126 d3d11::PixelShader mPassThroughPS; 127 d3d11::RasterizerState mPassThroughRS; 128 129 SurfaceRenderTarget11 mColorRenderTarget; 130 SurfaceRenderTarget11 mDepthStencilRenderTarget; 131 132 EGLint mEGLSamples; 133 LONGLONG mQPCFrequency; 134 }; 135 136 } // namespace rx 137 #endif // LIBANGLE_RENDERER_D3D_D3D11_SWAPCHAIN11_H_ 138