tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

StateManager9.h (6894B)


      1 //
      2 // Copyright 2015 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 // StateManager9.h: Defines a class for caching D3D9 state
      8 
      9 #ifndef LIBANGLE_RENDERER_D3D9_STATEMANAGER9_H_
     10 #define LIBANGLE_RENDERER_D3D9_STATEMANAGER9_H_
     11 
     12 #include "libANGLE/State.h"
     13 #include "libANGLE/angletypes.h"
     14 #include "libANGLE/renderer/d3d/RendererD3D.h"
     15 
     16 namespace rx
     17 {
     18 
     19 class Renderer9;
     20 
     21 struct dx_VertexConstants9
     22 {
     23    float depthRange[4];
     24    float viewAdjust[4];
     25    float viewCoords[4];
     26 };
     27 
     28 struct dx_PixelConstants9
     29 {
     30    float depthRange[4];
     31    float viewCoords[4];
     32    float depthFront[4];
     33 };
     34 
     35 class StateManager9 final : angle::NonCopyable
     36 {
     37  public:
     38    StateManager9(Renderer9 *renderer9);
     39    ~StateManager9();
     40 
     41    void initialize();
     42 
     43    void syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits);
     44 
     45    void setBlendDepthRasterStates(const gl::State &glState, unsigned int sampleMask);
     46    void setScissorState(const gl::Rectangle &scissor, bool enabled);
     47    void setViewportState(const gl::Rectangle &viewport,
     48                          float zNear,
     49                          float zFar,
     50                          gl::PrimitiveMode drawMode,
     51                          GLenum frontFace,
     52                          bool ignoreViewport);
     53 
     54    void setShaderConstants();
     55 
     56    void forceSetBlendState();
     57    void forceSetRasterState();
     58    void forceSetDepthStencilState();
     59    void forceSetScissorState();
     60    void forceSetViewportState();
     61    void forceSetDXUniformsState();
     62 
     63    void updateDepthSizeIfChanged(bool depthStencilInitialized, unsigned int depthSize);
     64    void updateStencilSizeIfChanged(bool depthStencilInitialized, unsigned int stencilSize);
     65 
     66    void setRenderTargetBounds(size_t width, size_t height);
     67 
     68    int getRenderTargetWidth() const { return mRenderTargetBounds.width; }
     69    int getRenderTargetHeight() const { return mRenderTargetBounds.height; }
     70 
     71    void setAllDirtyBits() { mDirtyBits.set(); }
     72    void resetDirtyBits() { mDirtyBits.reset(); }
     73 
     74  private:
     75    // Blend state functions
     76    void setBlendEnabled(bool enabled);
     77    void setBlendColor(const gl::BlendState &blendState, const gl::ColorF &blendColor);
     78    void setBlendFuncsEquations(const gl::BlendState &blendState);
     79    void setColorMask(const gl::Framebuffer *framebuffer,
     80                      bool red,
     81                      bool blue,
     82                      bool green,
     83                      bool alpha);
     84    void setSampleAlphaToCoverage(bool enabled);
     85    void setDither(bool dither);
     86    void setSampleMask(unsigned int sampleMask);
     87 
     88    // Current raster state functions
     89    void setCullMode(bool cullFace, gl::CullFaceMode cullMode, GLenum frontFace);
     90    void setDepthBias(bool polygonOffsetFill,
     91                      GLfloat polygonOffsetFactor,
     92                      GLfloat polygonOffsetUnits);
     93 
     94    // Depth stencil state functions
     95    void setStencilOpsFront(GLenum stencilFail,
     96                            GLenum stencilPassDepthFail,
     97                            GLenum stencilPassDepthPass,
     98                            bool frontFaceCCW);
     99    void setStencilOpsBack(GLenum stencilBackFail,
    100                           GLenum stencilBackPassDepthFail,
    101                           GLenum stencilBackPassDepthPass,
    102                           bool frontFaceCCW);
    103    void setStencilBackWriteMask(GLuint stencilBackWriteMask, bool frontFaceCCW);
    104    void setDepthFunc(bool depthTest, GLenum depthFunc);
    105    void setStencilTestEnabled(bool enabled);
    106    void setDepthMask(bool depthMask);
    107    void setStencilFuncsFront(GLenum stencilFunc,
    108                              GLuint stencilMask,
    109                              GLint stencilRef,
    110                              bool frontFaceCCW,
    111                              unsigned int maxStencil);
    112    void setStencilFuncsBack(GLenum stencilBackFunc,
    113                             GLuint stencilBackMask,
    114                             GLint stencilBackRef,
    115                             bool frontFaceCCW,
    116                             unsigned int maxStencil);
    117    void setStencilWriteMask(GLuint stencilWriteMask, bool frontFaceCCW);
    118 
    119    void setScissorEnabled(bool scissorEnabled);
    120    void setScissorRect(const gl::Rectangle &scissor, bool enabled);
    121 
    122    enum DirtyBitType
    123    {
    124        // Blend dirty bits
    125        DIRTY_BIT_BLEND_ENABLED,
    126        DIRTY_BIT_BLEND_COLOR,
    127        DIRTY_BIT_BLEND_FUNCS_EQUATIONS,
    128        DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE,
    129        DIRTY_BIT_COLOR_MASK,
    130        DIRTY_BIT_DITHER,
    131        DIRTY_BIT_SAMPLE_MASK,
    132 
    133        // Rasterizer dirty bits
    134        DIRTY_BIT_CULL_MODE,
    135        DIRTY_BIT_DEPTH_BIAS,
    136 
    137        // Depth stencil dirty bits
    138        DIRTY_BIT_STENCIL_DEPTH_MASK,
    139        DIRTY_BIT_STENCIL_DEPTH_FUNC,
    140        DIRTY_BIT_STENCIL_TEST_ENABLED,
    141        DIRTY_BIT_STENCIL_FUNCS_FRONT,
    142        DIRTY_BIT_STENCIL_FUNCS_BACK,
    143        DIRTY_BIT_STENCIL_WRITEMASK_FRONT,
    144        DIRTY_BIT_STENCIL_WRITEMASK_BACK,
    145        DIRTY_BIT_STENCIL_OPS_FRONT,
    146        DIRTY_BIT_STENCIL_OPS_BACK,
    147 
    148        // Scissor dirty bits
    149        DIRTY_BIT_SCISSOR_ENABLED,
    150        DIRTY_BIT_SCISSOR_RECT,
    151 
    152        // Viewport dirty bits
    153        DIRTY_BIT_VIEWPORT,
    154 
    155        DIRTY_BIT_MAX
    156    };
    157 
    158    using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>;
    159 
    160    bool mUsingZeroColorMaskWorkaround;
    161 
    162    bool mCurSampleAlphaToCoverage;
    163 
    164    // Currently applied blend state
    165    gl::BlendState mCurBlendState;
    166    gl::ColorF mCurBlendColor;
    167    unsigned int mCurSampleMask;
    168    DirtyBits mBlendStateDirtyBits;
    169 
    170    // Currently applied raster state
    171    gl::RasterizerState mCurRasterState;
    172    unsigned int mCurDepthSize;
    173    DirtyBits mRasterizerStateDirtyBits;
    174 
    175    // Currently applied depth stencil state
    176    gl::DepthStencilState mCurDepthStencilState;
    177    int mCurStencilRef;
    178    int mCurStencilBackRef;
    179    bool mCurFrontFaceCCW;
    180    unsigned int mCurStencilSize;
    181    DirtyBits mDepthStencilStateDirtyBits;
    182 
    183    // Currently applied scissor states
    184    gl::Rectangle mCurScissorRect;
    185    bool mCurScissorEnabled;
    186    gl::Extents mRenderTargetBounds;
    187    DirtyBits mScissorStateDirtyBits;
    188 
    189    // Currently applied viewport states
    190    bool mForceSetViewport;
    191    gl::Rectangle mCurViewport;
    192    float mCurNear;
    193    float mCurFar;
    194    float mCurDepthFront;
    195    bool mCurIgnoreViewport;
    196 
    197    dx_VertexConstants9 mVertexConstants;
    198    dx_PixelConstants9 mPixelConstants;
    199    bool mDxUniformsDirty;
    200 
    201    // FIXME: Unsupported by D3D9
    202    static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILREF       = D3DRS_STENCILREF;
    203    static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILMASK      = D3DRS_STENCILMASK;
    204    static const D3DRENDERSTATETYPE D3DRS_CCW_STENCILWRITEMASK = D3DRS_STENCILWRITEMASK;
    205 
    206    Renderer9 *mRenderer9;
    207    DirtyBits mDirtyBits;
    208 };
    209 
    210 }  // namespace rx
    211 #endif  // LIBANGLE_RENDERER_D3D9_STATEMANAGER9_H_