1 // 2 // Copyright 2016 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 // ContextImpl: 7 // Implementation-specific functionality associated with a GL Context. 8 // 9 10 #ifndef LIBANGLE_RENDERER_CONTEXTIMPL_H_ 11 #define LIBANGLE_RENDERER_CONTEXTIMPL_H_ 12 13 #include <vector> 14 15 #include "common/angleutils.h" 16 #include "libANGLE/ContextState.h" 17 #include "libANGLE/renderer/GLImplFactory.h" 18 19 namespace gl 20 { 21 class MemoryProgramCache; 22 class Path; 23 struct Workarounds; 24 } 25 26 namespace rx 27 { 28 class ContextImpl : public GLImplFactory 29 { 30 public: 31 ContextImpl(const gl::ContextState &state); 32 ~ContextImpl() override; 33 onDestroy(const gl::Context * context)34 virtual void onDestroy(const gl::Context *context) {} 35 36 virtual gl::Error initialize() = 0; 37 38 // Flush and finish. 39 virtual gl::Error flush(const gl::Context *context) = 0; 40 virtual gl::Error finish(const gl::Context *context) = 0; 41 42 // Drawing methods. 43 virtual gl::Error drawArrays(const gl::Context *context, 44 GLenum mode, 45 GLint first, 46 GLsizei count) = 0; 47 virtual gl::Error drawArraysInstanced(const gl::Context *context, 48 GLenum mode, 49 GLint first, 50 GLsizei count, 51 GLsizei instanceCount) = 0; 52 53 virtual gl::Error drawElements(const gl::Context *context, 54 GLenum mode, 55 GLsizei count, 56 GLenum type, 57 const void *indices) = 0; 58 virtual gl::Error drawElementsInstanced(const gl::Context *context, 59 GLenum mode, 60 GLsizei count, 61 GLenum type, 62 const void *indices, 63 GLsizei instances) = 0; 64 virtual gl::Error drawRangeElements(const gl::Context *context, 65 GLenum mode, 66 GLuint start, 67 GLuint end, 68 GLsizei count, 69 GLenum type, 70 const void *indices) = 0; 71 72 virtual gl::Error drawArraysIndirect(const gl::Context *context, 73 GLenum mode, 74 const void *indirect) = 0; 75 virtual gl::Error drawElementsIndirect(const gl::Context *context, 76 GLenum mode, 77 GLenum type, 78 const void *indirect) = 0; 79 80 // CHROMIUM_path_rendering path drawing methods. 81 virtual void stencilFillPath(const gl::Path *path, GLenum fillMode, GLuint mask); 82 virtual void stencilStrokePath(const gl::Path *path, GLint reference, GLuint mask); 83 virtual void coverFillPath(const gl::Path *path, GLenum coverMode); 84 virtual void coverStrokePath(const gl::Path *path, GLenum coverMode); 85 virtual void stencilThenCoverFillPath(const gl::Path *path, 86 GLenum fillMode, 87 GLuint mask, 88 GLenum coverMode); 89 90 virtual void stencilThenCoverStrokePath(const gl::Path *path, 91 GLint reference, 92 GLuint mask, 93 GLenum coverMode); 94 95 virtual void coverFillPathInstanced(const std::vector<gl::Path *> &paths, 96 GLenum coverMode, 97 GLenum transformType, 98 const GLfloat *transformValues); 99 virtual void coverStrokePathInstanced(const std::vector<gl::Path *> &paths, 100 GLenum coverMode, 101 GLenum transformType, 102 const GLfloat *transformValues); 103 virtual void stencilFillPathInstanced(const std::vector<gl::Path *> &paths, 104 GLenum fillMode, 105 GLuint mask, 106 GLenum transformType, 107 const GLfloat *transformValues); 108 virtual void stencilStrokePathInstanced(const std::vector<gl::Path *> &paths, 109 GLint reference, 110 GLuint mask, 111 GLenum transformType, 112 const GLfloat *transformValues); 113 virtual void stencilThenCoverFillPathInstanced(const std::vector<gl::Path *> &paths, 114 GLenum coverMode, 115 GLenum fillMode, 116 GLuint mask, 117 GLenum transformType, 118 const GLfloat *transformValues); 119 virtual void stencilThenCoverStrokePathInstanced(const std::vector<gl::Path *> &paths, 120 GLenum coverMode, 121 GLint reference, 122 GLuint mask, 123 GLenum transformType, 124 const GLfloat *transformValues); 125 126 // Device loss 127 virtual GLenum getResetStatus() = 0; 128 129 // Vendor and description strings. 130 virtual std::string getVendorString() const = 0; 131 virtual std::string getRendererDescription() const = 0; 132 133 // EXT_debug_marker 134 virtual void insertEventMarker(GLsizei length, const char *marker) = 0; 135 virtual void pushGroupMarker(GLsizei length, const char *marker) = 0; 136 virtual void popGroupMarker() = 0; 137 138 // KHR_debug 139 virtual void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) = 0; 140 virtual void popDebugGroup() = 0; 141 142 // State sync with dirty bits. 143 virtual void syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits) = 0; 144 145 // Disjoint timer queries 146 virtual GLint getGPUDisjoint() = 0; 147 virtual GLint64 getTimestamp() = 0; 148 149 // Context switching 150 virtual void onMakeCurrent(const gl::Context *context) = 0; 151 152 // Native capabilities, unmodified by gl::Context. 153 virtual const gl::Caps &getNativeCaps() const = 0; 154 virtual const gl::TextureCapsMap &getNativeTextureCaps() const = 0; 155 virtual const gl::Extensions &getNativeExtensions() const = 0; 156 virtual const gl::Limitations &getNativeLimitations() const = 0; 157 applyNativeWorkarounds(gl::Workarounds * workarounds)158 virtual void applyNativeWorkarounds(gl::Workarounds *workarounds) const {} 159 160 virtual gl::Error dispatchCompute(const gl::Context *context, 161 GLuint numGroupsX, 162 GLuint numGroupsY, 163 GLuint numGroupsZ) = 0; 164 getContextState()165 const gl::ContextState &getContextState() { return mState; } getClientMajorVersion()166 int getClientMajorVersion() const { return mState.getClientMajorVersion(); } getClientMinorVersion()167 int getClientMinorVersion() const { return mState.getClientMinorVersion(); } getGLState()168 const gl::State &getGLState() const { return mState.getState(); } getCaps()169 const gl::Caps &getCaps() const { return mState.getCaps(); } getTextureCaps()170 const gl::TextureCapsMap &getTextureCaps() const { return mState.getTextureCaps(); } getExtensions()171 const gl::Extensions &getExtensions() const { return mState.getExtensions(); } getLimitations()172 const gl::Limitations &getLimitations() const { return mState.getLimitations(); } 173 174 // A common GL driver behaviour is to trigger dynamic shader recompilation on a draw call, 175 // based on the current render states. We store a mutable pointer to the program cache so 176 // on draw calls we can store the refreshed shaders in the cache. 177 void setMemoryProgramCache(gl::MemoryProgramCache *memoryProgramCache); 178 179 protected: 180 const gl::ContextState &mState; 181 gl::MemoryProgramCache *mMemoryProgramCache; 182 }; 183 184 } // namespace rx 185 186 #endif // LIBANGLE_RENDERER_CONTEXTIMPL_H_ 187