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