• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 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(DisplayD3D *displayD3D, EGLint backbufferWidth, EGLint backbufferHeight) override;
35     EGLint reset(DisplayD3D *displayD3D,
36                  EGLint backbufferWidth,
37                  EGLint backbufferHeight,
38                  EGLint swapInterval) override;
39     EGLint swapRect(DisplayD3D *displayD3D,
40                     EGLint x,
41                     EGLint y,
42                     EGLint width,
43                     EGLint height) override;
44     void recreate() override;
45 
46     RenderTargetD3D *getColorRenderTarget() override;
47     RenderTargetD3D *getDepthStencilRenderTarget() override;
48 
49     const TextureHelper11 &getOffscreenTexture();
50     const d3d11::RenderTargetView &getRenderTarget();
51     const d3d11::SharedSRV &getRenderTargetShaderResource(d3d::Context *context);
52 
53     const TextureHelper11 &getDepthStencilTexture();
54     const d3d11::DepthStencilView &getDepthStencil();
55     const d3d11::SharedSRV &getDepthStencilShaderResource();
56 
getWidth()57     EGLint getWidth() const { return mWidth; }
getHeight()58     EGLint getHeight() const { return mHeight; }
59     void *getKeyedMutex() override;
getSamples()60     EGLint getSamples() const { return mEGLSamples; }
61 
62     egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) override;
63 
64   private:
65     void release();
66     angle::Result initPassThroughResources(DisplayD3D *displayD3D);
67 
68     void releaseOffscreenColorBuffer();
69     void releaseOffscreenDepthBuffer();
70     EGLint resetOffscreenBuffers(DisplayD3D *displayD3D, int backbufferWidth, int backbufferHeight);
71     EGLint resetOffscreenColorBuffer(DisplayD3D *displayD3D,
72                                      int backbufferWidth,
73                                      int backbufferHeight);
74     EGLint resetOffscreenDepthBuffer(DisplayD3D *displayD3D,
75                                      int backbufferWidth,
76                                      int backbufferHeight);
77 
78     DXGI_FORMAT getSwapChainNativeFormat() const;
79 
80     EGLint copyOffscreenToBackbuffer(DisplayD3D *displayD3D,
81                                      EGLint x,
82                                      EGLint y,
83                                      EGLint width,
84                                      EGLint height);
85     EGLint present(DisplayD3D *displayD3D, EGLint x, EGLint y, EGLint width, EGLint height);
86     UINT getD3DSamples() const;
87 
88     Renderer11 *mRenderer;
89     EGLint mWidth;
90     EGLint mHeight;
91     const EGLint mOrientation;
92     bool mAppCreatedShareHandle;
93     unsigned int mSwapInterval;
94     bool mPassThroughResourcesInit;
95 
96     NativeWindow11 *mNativeWindow;  // Handler for the Window that the surface is created for.
97 
98     bool mFirstSwap;
99     IDXGISwapChain *mSwapChain;
100     IDXGISwapChain1 *mSwapChain1;
101     IDXGIKeyedMutex *mKeyedMutex;
102 
103     TextureHelper11 mBackBufferTexture;
104     d3d11::RenderTargetView mBackBufferRTView;
105     d3d11::SharedSRV mBackBufferSRView;
106 
107     const bool mNeedsOffscreenTexture;
108     TextureHelper11 mOffscreenTexture;
109     d3d11::RenderTargetView mOffscreenRTView;
110     d3d11::SharedSRV mOffscreenSRView;
111     bool mNeedsOffscreenTextureCopy;
112     TextureHelper11 mOffscreenTextureCopyForSRV;
113 
114     TextureHelper11 mDepthStencilTexture;
115     d3d11::DepthStencilView mDepthStencilDSView;
116     d3d11::SharedSRV mDepthStencilSRView;
117 
118     d3d11::Buffer mQuadVB;
119     d3d11::SamplerState mPassThroughSampler;
120     d3d11::InputLayout mPassThroughIL;
121     d3d11::VertexShader mPassThroughVS;
122     d3d11::PixelShader mPassThroughOrResolvePS;
123     d3d11::RasterizerState mPassThroughRS;
124 
125     SurfaceRenderTarget11 mColorRenderTarget;
126     SurfaceRenderTarget11 mDepthStencilRenderTarget;
127 
128     EGLint mEGLSamples;
129     LONGLONG mQPCFrequency;
130 };
131 
132 }  // namespace rx
133 #endif  // LIBANGLE_RENDERER_D3D_D3D11_SWAPCHAIN11_H_
134