reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GrGpuGL_DEFINED |
| 19 | #define GrGpuGL_DEFINED |
| 20 | |
| 21 | #include "GrGpu.h" |
| 22 | #include "GrGLConfig.h" |
| 23 | #include "GrGLTexture.h" |
| 24 | |
| 25 | #include "GrGLVertexBuffer.h" |
| 26 | #include "GrGLIndexBuffer.h" |
| 27 | |
| 28 | class GrGpuGL : public GrGpu { |
| 29 | public: |
| 30 | GrGpuGL(); |
| 31 | virtual ~GrGpuGL(); |
| 32 | |
| 33 | // overrides from GrGpu |
| 34 | virtual void resetContext(); |
| 35 | |
| 36 | virtual GrTexture* createTexture(const TextureDesc& desc, |
| 37 | const void* srcData, size_t rowBytes); |
| 38 | virtual GrVertexBuffer* createVertexBuffer(uint32_t size, bool dynamic); |
| 39 | virtual GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic); |
| 40 | |
| 41 | virtual GrRenderTarget* createPlatformRenderTarget( |
| 42 | intptr_t platformRenderTarget, |
| 43 | int width, int height); |
| 44 | |
| 45 | virtual GrRenderTarget* defaultRenderTarget(); |
| 46 | |
| 47 | virtual void setDefaultRenderTargetSize(uint32_t width, uint32_t height); |
| 48 | |
| 49 | virtual void eraseColor(GrColor color); |
| 50 | |
| 51 | virtual void forceRenderTargetFlush(); |
| 52 | |
| 53 | virtual bool readPixels(int left, int top, int width, int height, |
| 54 | GrTexture::PixelConfig, void* buffer); |
| 55 | |
| 56 | /** |
| 57 | * Gets the struct containing the GL extensions for the context |
| 58 | * underlying the GrGpuGL |
| 59 | * |
| 60 | * @param struct containing extension function pointers |
| 61 | */ |
| 62 | const GrGLExts& extensions() { return fExts; } |
| 63 | |
| 64 | protected: |
| 65 | struct { |
| 66 | const void* |
| 67 | fPositionPtr; |
| 68 | GrVertexLayout fVertexLayout; |
| 69 | const GrVertexBuffer* fVertexBuffer; |
| 70 | const GrIndexBuffer* fIndexBuffer; |
| 71 | } fHWGeometryState; |
| 72 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 73 | DrState fHWDrawState; |
| 74 | bool fHWStencilClip; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 75 | |
| 76 | virtual void drawIndexedHelper(PrimitiveType type, |
| 77 | uint32_t startVertex, |
| 78 | uint32_t startIndex, |
| 79 | uint32_t vertexCount, |
| 80 | uint32_t indexCount); |
| 81 | |
| 82 | virtual void drawNonIndexedHelper(PrimitiveType type, |
| 83 | uint32_t vertexCount, |
| 84 | uint32_t numVertices); |
| 85 | |
| 86 | virtual void flushScissor(const GrIRect* rect); |
| 87 | |
| 88 | void eraseStencil(uint32_t value, uint32_t mask); |
| 89 | virtual void eraseStencilClip(); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame^] | 90 | |
| 91 | void setTextureUnit(int unitIdx); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 92 | |
| 93 | // flushes state that is common to fixed and programmable GL |
| 94 | // dither |
| 95 | // line smoothing |
| 96 | // blend func |
| 97 | // texture binding |
| 98 | // sampler state (filtering, tiling) |
| 99 | // FBO binding |
| 100 | // line width |
| 101 | void flushGLStateCommon(PrimitiveType type); |
| 102 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 103 | // set when this class changes the rendertarget. |
| 104 | // Subclass should notice at flush time, take appropriate action, |
| 105 | // and set false. |
| 106 | bool fRenderTargetChanged; |
| 107 | |
| 108 | // set by eraseColor or eraseStencil. Picked up in in flushStencil. |
| 109 | bool fWriteMaskChanged; |
| 110 | |
| 111 | // last scissor / viewport scissor state seen by the GL. |
| 112 | BoundsState fHWBounds; |
| 113 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | GrGLExts fExts; |
| 115 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame^] | 116 | private: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 117 | GrGLRenderTarget* fDefaultRenderTarget; |
| 118 | |
| 119 | void resetContextHelper(); |
| 120 | |
| 121 | // notify callbacks to update state tracking when related |
| 122 | // objects are bound to GL or deleted outside of the class |
| 123 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 124 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 125 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 126 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 127 | void notifyTextureDelete(GrGLTexture* texture); |
| 128 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
| 129 | void notifyTextureRemoveRenderTarget(GrGLTexture* texture); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame^] | 130 | |
| 131 | void setSpareTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 132 | |
| 133 | void flushRenderTarget(); |
| 134 | void flushStencil(); |
| 135 | void resolveTextureRenderTarget(GrGLTexture* texture); |
| 136 | |
| 137 | bool canBeTexture(GrTexture::PixelConfig config, |
| 138 | GLenum* internalFormat, |
| 139 | GLenum* format, |
| 140 | GLenum* type); |
| 141 | bool fboInternalFormat(GrTexture::PixelConfig config, GLenum* format); |
| 142 | |
| 143 | friend class GrGLVertexBuffer; |
| 144 | friend class GrGLIndexBuffer; |
| 145 | friend class GrGLTexture; |
| 146 | friend class GrGLRenderTarget; |
| 147 | |
| 148 | bool fHWBlendDisabled; |
| 149 | |
| 150 | GLuint fAASamples[4]; |
| 151 | enum { |
| 152 | kNone_MSFBO = 0, |
| 153 | kDesktop_MSFBO, |
| 154 | kApple_MSFBO, |
| 155 | kIMG_MSFBO |
| 156 | } fMSFBOType; |
| 157 | |
| 158 | // Do we have stencil wrap ops. |
| 159 | bool fHasStencilWrap; |
| 160 | |
| 161 | // ES requires an extension to support RGBA8 in RenderBufferStorage |
| 162 | bool fRGBA8Renderbuffer; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame^] | 163 | |
| 164 | int fActiveTextureUnitIdx; |
| 165 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 166 | typedef GrGpu INHERITED; |
| 167 | }; |
| 168 | |
| 169 | bool has_gl_extension(const char* ext); |
| 170 | void gl_version(int* major, int* minor); |
| 171 | |
| 172 | /** |
| 173 | * GrGL_RestoreResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write |
| 174 | * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions |
| 175 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame^] | 176 | #if GR_SUPPORT_GLDESKTOP |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 177 | static inline void GrGL_RestoreResetRowLength() { |
| 178 | GR_GL(PixelStorei(GL_UNPACK_ROW_LENGTH, 0)); |
| 179 | } |
| 180 | #else |
| 181 | #define GrGL_RestoreResetRowLength() |
| 182 | #endif |
| 183 | |
| 184 | #if SK_TextGLType != GL_FIXED |
| 185 | #define SK_GL_HAS_COLOR4UB |
| 186 | #endif |
| 187 | |
reed@google.com | ac20fb9 | 2011-01-12 17:14:53 +0000 | [diff] [blame] | 188 | /* |
| 189 | * Some drivers want the var-int arg to be zero-initialized on input. |
| 190 | */ |
| 191 | #define GR_GL_INIT_ZERO 0 |
| 192 | #define GR_GL_GetIntegerv(e, p) \ |
| 193 | do { \ |
| 194 | *(p) = GR_GL_INIT_ZERO; \ |
| 195 | GR_GL(GetIntegerv(e, p)); \ |
| 196 | } while (0) |
| 197 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 198 | #endif |
| 199 | |
| 200 | |