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