| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #ifndef GrGpuGL_DEFINED |
| 11 | #define GrGpuGL_DEFINED |
| 12 | |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 13 | #include "GrBinHashKey.h" |
| tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 14 | #include "GrDrawState.h" |
| 15 | #include "GrGpu.h" |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 16 | #include "GrGLContextInfo.h" |
| bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 17 | #include "GrGLIndexBuffer.h" |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 18 | #include "GrGLIRect.h" |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 19 | #include "GrGLProgram.h" |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 20 | #include "GrGLStencilBuffer.h" |
| 21 | #include "GrGLTexture.h" |
| 22 | #include "GrGLVertexBuffer.h" |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 23 | #include "../GrTHashCache.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
| 25 | class GrGpuGL : public GrGpu { |
| 26 | public: |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 27 | GrGpuGL(const GrGLContextInfo& ctxInfo); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | virtual ~GrGpuGL(); |
| 29 | |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 30 | const GrGLInterface* glInterface() const { |
| 31 | return fGLContextInfo.interface(); |
| 32 | } |
| tomhudson@google.com | dd182cb | 2012-02-10 21:01:00 +0000 | [diff] [blame] | 33 | GrGLBinding glBinding() const { return fGLContextInfo.binding(); } |
| 34 | GrGLVersion glVersion() const { return fGLContextInfo.version(); } |
| 35 | GrGLSLGeneration glslGeneration() const { |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 36 | return fGLContextInfo.glslGeneration(); |
| 37 | } |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 38 | |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 39 | // GrGpu overrides |
| bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 40 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 41 | const SK_OVERRIDE; |
| bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 42 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 43 | const SK_OVERRIDE; |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 44 | virtual bool readPixelsWillPayForYFlip( |
| 45 | GrRenderTarget* renderTarget, |
| 46 | int left, int top, |
| 47 | int width, int height, |
| 48 | GrPixelConfig config, |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 49 | size_t rowBytes) const SK_OVERRIDE; |
| 50 | virtual bool fullReadPixelsIsFasterThanPartial() const SK_OVERRIDE; |
| bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 51 | |
| bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 52 | virtual bool canPreserveReadWriteUnpremulPixels() SK_OVERRIDE; |
| 53 | |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 54 | virtual void abandonResources() SK_OVERRIDE; |
| 55 | |
| 56 | bool programUnitTest(); |
| 57 | |
| bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 58 | protected: |
| bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 59 | |
| bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 60 | enum TriState { |
| 61 | kNo_TriState, |
| 62 | kYes_TriState, |
| 63 | kUnknown_TriState |
| 64 | }; |
| 65 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | struct { |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 67 | size_t fVertexOffset; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 68 | GrVertexLayout fVertexLayout; |
| 69 | const GrVertexBuffer* fVertexBuffer; |
| 70 | const GrIndexBuffer* fIndexBuffer; |
| bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 71 | bool fArrayPtrsDirty; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | } fHWGeometryState; |
| 73 | |
| bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 74 | enum UnpremulConversion { |
| 75 | kUpOnWrite_DownOnRead_UnpremulConversion, |
| 76 | kDownOnWrite_UpOnRead_UnpremulConversion |
| 77 | } fUnpremulConversion; |
| 78 | |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 79 | // last scissor / viewport scissor state seen by the GL. |
| bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 80 | struct { |
| 81 | bool fScissorEnabled; |
| 82 | GrGLIRect fScissorRect; |
| 83 | GrGLIRect fViewportRect; |
| 84 | } fHWBounds; |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 85 | |
| bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 86 | const GrGLCaps& glCaps() const { return fGLContextInfo.caps(); } |
| bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 87 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 88 | // GrGpu overrides |
| bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 89 | virtual void onResetContext() SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 90 | |
| bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 91 | virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 92 | const void* srcData, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 93 | size_t rowBytes) SK_OVERRIDE; |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 94 | virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 95 | bool dynamic) SK_OVERRIDE; |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 96 | virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 97 | bool dynamic) SK_OVERRIDE; |
| 98 | virtual GrTexture* onCreatePlatformTexture( |
| 99 | const GrPlatformTextureDesc& desc) SK_OVERRIDE; |
| 100 | virtual GrRenderTarget* onCreatePlatformRenderTarget( |
| 101 | const GrPlatformRenderTargetDesc& desc) SK_OVERRIDE; |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 102 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 103 | int width, |
| 104 | int height) SK_OVERRIDE; |
| 105 | virtual bool attachStencilBufferToRenderTarget( |
| 106 | GrStencilBuffer* sb, |
| 107 | GrRenderTarget* rt) SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 108 | |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 109 | virtual void onClear(const GrIRect* rect, GrColor color) SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 110 | |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 111 | virtual void onForceRenderTargetFlush() SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 112 | |
| bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 113 | virtual bool onReadPixels(GrRenderTarget* target, |
| bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 114 | int left, int top, |
| 115 | int width, int height, |
| 116 | GrPixelConfig, |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 117 | void* buffer, |
| 118 | size_t rowBytes, |
| 119 | bool invertY) SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 120 | |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 121 | virtual void onWriteTexturePixels(GrTexture* texture, |
| 122 | int left, int top, int width, int height, |
| 123 | GrPixelConfig config, const void* buffer, |
| 124 | size_t rowBytes) SK_OVERRIDE; |
| 125 | |
| bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 126 | virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; |
| 127 | |
| 128 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 129 | virtual void onGpuDrawIndexed(GrPrimitiveType type, |
| 130 | uint32_t startVertex, |
| 131 | uint32_t startIndex, |
| 132 | uint32_t vertexCount, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 133 | uint32_t indexCount) SK_OVERRIDE; |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 134 | virtual void onGpuDrawNonIndexed(GrPrimitiveType type, |
| 135 | uint32_t vertexCount, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 136 | uint32_t numVertices) SK_OVERRIDE; |
| 137 | virtual void enableScissoring(const GrIRect& rect) SK_OVERRIDE; |
| 138 | virtual void disableScissor() SK_OVERRIDE; |
| robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 139 | |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 140 | virtual void clearStencil() SK_OVERRIDE; |
| 141 | virtual void clearStencilClip(const GrIRect& rect, |
| 142 | bool insideClip) SK_OVERRIDE; |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 143 | virtual bool flushGraphicsState(GrPrimitiveType type) SK_OVERRIDE; |
| 144 | virtual void setupGeometry(int* startVertex, |
| 145 | int* startIndex, |
| 146 | int vertexCount, |
| 147 | int indexCount) SK_OVERRIDE; |
| 148 | |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 149 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 150 | // binds texture unit in GL |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 151 | void setTextureUnit(int unitIdx); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 152 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 153 | // binds appropriate vertex and index buffers, also returns any extra |
| 154 | // extra verts or indices to offset by. |
| 155 | void setBuffers(bool indexed, |
| 156 | int* extraVertexOffset, |
| 157 | int* extraIndexOffset); |
| bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 158 | |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 159 | // Subclasses should call this to flush the blend state. |
| 160 | // The params should be the final coeffecients to apply |
| 161 | // (after any blending optimizations or dual source blending considerations |
| 162 | // have been accounted for). |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 163 | void flushBlend(GrPrimitiveType type, |
| 164 | GrBlendCoeff srcCoeff, |
| 165 | GrBlendCoeff dstCoeff); |
| 166 | |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 167 | bool hasExtension(const char* ext) const { |
| 168 | return fGLContextInfo.hasExtension(ext); |
| bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | const GrGLContextInfo& glContextInfo() const { return fGLContextInfo; } |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 172 | |
| bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 173 | // adjusts texture matrix to account for orientation |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 174 | static void AdjustTextureMatrix(const GrGLTexture* texture, |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 175 | GrMatrix* matrix); |
| bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 176 | |
| 177 | // subclass may try to take advantage of identity tex matrices. |
| 178 | // This helper determines if matrix will be identity after all |
| 179 | // adjustments are applied. |
| 180 | static bool TextureMatrixIsIdentity(const GrGLTexture* texture, |
| 181 | const GrSamplerState& sampler); |
| 182 | |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 183 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
| bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 184 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 185 | private: |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 186 | // for readability of function impls |
| 187 | typedef GrGLProgram::ProgramDesc ProgramDesc; |
| 188 | typedef ProgramDesc::StageDesc StageDesc; |
| 189 | typedef GrGLProgram::CachedData CachedData; |
| 190 | |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 191 | class ProgramCache : public ::GrNoncopyable { |
| 192 | public: |
| 193 | ProgramCache(const GrGLContextInfo& gl); |
| 194 | ~ProgramCache(); |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 195 | |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 196 | void abandon(); |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 197 | CachedData* getProgramData(const GrGLProgram& desc, |
| 198 | GrCustomStage** stages); |
| 199 | private: |
| 200 | enum { |
| 201 | kKeySize = GrGLProgram::kProgramKeySize, |
| 202 | // We may actually have kMaxEntries+1 shaders in the GL context |
| 203 | // because we create a new shader before evicting from the cache. |
| 204 | kMaxEntries = 32 |
| 205 | }; |
| 206 | |
| 207 | class Entry; |
| 208 | typedef GrBinHashKey<Entry, kKeySize> ProgramHashKey; |
| 209 | |
| 210 | class Entry : public ::GrNoncopyable { |
| 211 | public: |
| 212 | Entry() {} |
| 213 | void copyAndTakeOwnership(Entry& entry); |
| 214 | int compare(const ProgramHashKey& key) const { |
| 215 | return fKey.compare(key); |
| 216 | } |
| 217 | |
| 218 | public: |
| 219 | CachedData fProgramData; |
| 220 | ProgramHashKey fKey; |
| 221 | unsigned int fLRUStamp; |
| 222 | }; |
| 223 | |
| 224 | GrTHashTable<Entry, ProgramHashKey, 8> fHashCache; |
| 225 | |
| 226 | Entry fEntries[kMaxEntries]; |
| 227 | int fCount; |
| 228 | unsigned int fCurrLRUStamp; |
| 229 | const GrGLContextInfo& fGL; |
| 230 | }; |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 231 | |
| bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 232 | // binds the texture and sets its texture params |
| 233 | void flushBoundTextureAndParams(int stage); |
| 234 | |
| bsalomon@google.com | 890e3b5 | 2012-06-01 19:01:37 +0000 | [diff] [blame] | 235 | // sets the texture matrix and domain for the currently bound program |
| 236 | void flushTextureMatrixAndDomain(int stage); |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 237 | |
| 238 | // sets the color specified by GrDrawState::setColor() |
| 239 | void flushColor(GrColor color); |
| 240 | |
| 241 | // sets the color specified by GrDrawState::setCoverage() |
| 242 | void flushCoverage(GrColor color); |
| 243 | |
| 244 | // sets the MVP matrix uniform for currently bound program |
| 245 | void flushViewMatrix(); |
| 246 | |
| 247 | // flushes the parameters to two point radial gradient |
| 248 | void flushRadial2(int stage); |
| 249 | |
| 250 | // flushes the parameters for convolution |
| 251 | void flushConvolution(int stage); |
| 252 | |
| 253 | // flushes the normalized texel size |
| 254 | void flushTexelSize(int stage); |
| 255 | |
| 256 | // flushes the color matrix |
| 257 | void flushColorMatrix(); |
| 258 | |
| bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame^] | 259 | // flushes dithering, color-mask, and face culling stat |
| 260 | void flushMiscFixedFunctionState(); |
| 261 | |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 262 | static void DeleteProgram(const GrGLInterface* gl, |
| 263 | CachedData* programData); |
| 264 | |
| 265 | void buildProgram(GrPrimitiveType typeBlend, |
| 266 | BlendOptFlags blendOpts, |
| 267 | GrBlendCoeff dstCoeff, |
| 268 | GrCustomStage** customStages); |
| 269 | |
| bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 270 | // Inits GrDrawTarget::Caps, sublcass may enable additional caps. |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 271 | void initCaps(); |
| 272 | |
| 273 | void initFSAASupport(); |
| bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 274 | |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 275 | // determines valid stencil formats |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 276 | void initStencilFormats(); |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 277 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 278 | // notify callbacks to update state tracking when related |
| 279 | // objects are bound to GL or deleted outside of the class |
| 280 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 281 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 282 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 283 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 284 | void notifyTextureDelete(GrGLTexture* texture); |
| 285 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 286 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 287 | void setSpareTextureUnit(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 288 | |
| bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 289 | // bound is region that may be modified and therefore has to be resolved. |
| 290 | // NULL means whole target. Can be an empty rect. |
| 291 | void flushRenderTarget(const GrIRect* bound); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 292 | void flushStencil(); |
| bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 293 | void flushAAState(GrPrimitiveType type); |
| bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 294 | |
| bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 295 | bool configToGLFormats(GrPixelConfig config, |
| 296 | bool getSizedInternal, |
| 297 | GrGLenum* internalFormat, |
| 298 | GrGLenum* externalFormat, |
| 299 | GrGLenum* externalType); |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 300 | // helper for onCreateTexture and writeTexturePixels |
| bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 301 | bool uploadTexData(const GrGLTexture::Desc& desc, |
| bsalomon@google.com | 1e0e607 | 2011-11-28 18:49:37 +0000 | [diff] [blame] | 302 | bool isNewTexture, |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 303 | int left, int top, int width, int height, |
| 304 | GrPixelConfig dataConfig, |
| 305 | const void* data, |
| 306 | size_t rowBytes); |
| bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 307 | |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 308 | bool createRenderTargetObjects(int width, int height, |
| 309 | GrGLuint texID, |
| 310 | GrGLRenderTarget::Desc* desc); |
| 311 | |
| robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 312 | void fillInConfigRenderableTable(); |
| 313 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 314 | friend class GrGLVertexBuffer; |
| 315 | friend class GrGLIndexBuffer; |
| 316 | friend class GrGLTexture; |
| 317 | friend class GrGLRenderTarget; |
| 318 | |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 319 | GrGLContextInfo fGLContextInfo; |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 320 | |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 321 | // GL program-related state |
| 322 | ProgramCache* fProgramCache; |
| 323 | CachedData* fProgramData; |
| 324 | GrGLuint fHWProgramID; |
| 325 | GrColor fHWConstAttribColor; |
| 326 | GrColor fHWConstAttribCoverage; |
| 327 | GrGLProgram fCurrentProgram; |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 328 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 329 | int fActiveTextureUnitIdx; |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 330 | |
| bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 331 | struct { |
| 332 | GrBlendCoeff fSrcCoeff; |
| 333 | GrBlendCoeff fDstCoeff; |
| 334 | GrColor fConstColor; |
| 335 | bool fConstColorValid; |
| 336 | TriState fEnabled; |
| 337 | |
| 338 | void invalidate() { |
| 339 | fSrcCoeff = kInvalid_BlendCoeff; |
| 340 | fDstCoeff = kInvalid_BlendCoeff; |
| 341 | fConstColorValid = false; |
| 342 | fEnabled = kUnknown_TriState; |
| 343 | } |
| 344 | } fHWBlendState; |
| 345 | |
| bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 346 | struct { |
| 347 | TriState fMSAAEnabled; |
| 348 | TriState fSmoothLineEnabled; |
| 349 | void invalidate() { |
| 350 | fMSAAEnabled = kUnknown_TriState; |
| 351 | fSmoothLineEnabled = kUnknown_TriState; |
| 352 | } |
| 353 | } fHWAAState; |
| 354 | |
| bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 355 | // The high bit of the stencil buffer is used for clipping. This enum is |
| 356 | // used to track whether the clip bit of the stencil buffer is being used, |
| 357 | // manipulated, or neither. |
| 358 | enum StencilClipMode { |
| 359 | // Draw to the clip bit of the stencil buffer |
| 360 | kModifyClip_StencilClipMode, |
| 361 | // Clip against the existing representation of the clip in the high bit |
| 362 | // of the stencil buffer. |
| 363 | kUseClip_StencilClipMode, |
| 364 | // Neither writing to nor clipping against the clip bit. |
| 365 | kIgnoreClip_StencilClipMode, |
| 366 | // Unknown state of HW |
| 367 | kInvalid_StencilClipMode, |
| 368 | }; |
| 369 | StencilClipMode fHWStencilClipMode; |
| 370 | GrStencilSettings fHWStencilSettings; |
| 371 | |
| bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 372 | GrDrawState::DrawFace fHWDrawFace; |
| 373 | TriState fHWWriteToColor; |
| 374 | TriState fHWDitherEnabled; |
| 375 | GrRenderTarget* fHWBoundRenderTarget; |
| 376 | GrTexture* fHWBoundTextures[GrDrawState::kNumStages]; |
| bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 377 | |
| bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 378 | // we record what stencil format worked last time to hopefully exit early |
| 379 | // from our loop that tries stencil formats and calls check fb status. |
| 380 | int fLastSuccessfulStencilFmtIdx; |
| 381 | |
| bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 382 | enum CanPreserveUnpremulRoundtrip { |
| 383 | kUnknown_CanPreserveUnpremulRoundtrip, |
| 384 | kNo_CanPreserveUnpremulRoundtrip, |
| 385 | kYes_CanPreserveUnpremulRoundtrip, |
| 386 | } fCanPreserveUnpremulRoundtrip; |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 387 | |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 388 | bool fPrintedCaps; |
| 389 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 390 | typedef GrGpu INHERITED; |
| 391 | }; |
| 392 | |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 393 | #endif |
| bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 394 | |