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