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