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 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 30 | const GrGLInterface* glInterface() const { |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 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 | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 52 | virtual void abandonResources() SK_OVERRIDE; |
| 53 | |
| 54 | bool programUnitTest(); |
| 55 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 56 | |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 57 | protected: |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 58 | // GrGpu overrides |
bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 59 | virtual void onResetContext() SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 60 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 61 | virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 62 | const void* srcData, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 63 | size_t rowBytes) SK_OVERRIDE; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 64 | virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 65 | bool dynamic) SK_OVERRIDE; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 66 | virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 67 | bool dynamic) SK_OVERRIDE; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 68 | virtual GrPath* onCreatePath(const SkPath&) SK_OVERRIDE; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 69 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE; |
| 70 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 71 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 72 | int width, |
| 73 | int height) SK_OVERRIDE; |
| 74 | virtual bool attachStencilBufferToRenderTarget( |
| 75 | GrStencilBuffer* sb, |
| 76 | GrRenderTarget* rt) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 77 | |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 78 | virtual void onClear(const GrIRect* rect, GrColor color) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 79 | |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 80 | virtual void onForceRenderTargetFlush() SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 81 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 82 | virtual bool onReadPixels(GrRenderTarget* target, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 83 | int left, int top, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 84 | int width, int height, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 85 | GrPixelConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 86 | void* buffer, |
| 87 | size_t rowBytes, |
| 88 | bool invertY) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 89 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 90 | virtual void onWriteTexturePixels(GrTexture* texture, |
| 91 | int left, int top, int width, int height, |
| 92 | GrPixelConfig config, const void* buffer, |
| 93 | size_t rowBytes) SK_OVERRIDE; |
| 94 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 95 | virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; |
| 96 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 97 | virtual void onGpuDrawIndexed(GrPrimitiveType type, |
| 98 | uint32_t startVertex, |
| 99 | uint32_t startIndex, |
| 100 | uint32_t vertexCount, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 101 | uint32_t indexCount) SK_OVERRIDE; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 102 | virtual void onGpuDrawNonIndexed(GrPrimitiveType type, |
| 103 | uint32_t vertexCount, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 104 | uint32_t numVertices) SK_OVERRIDE; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 105 | |
| 106 | virtual void setStencilPathSettings(const GrPath&, |
| 107 | GrPathFill, |
| 108 | GrStencilSettings* settings) |
| 109 | SK_OVERRIDE; |
| 110 | virtual void onGpuStencilPath(const GrPath*, GrPathFill) 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 | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 115 | virtual bool flushGraphicsState(DrawType) SK_OVERRIDE; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 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 | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 138 | void flushBlend(bool isLines, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 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 | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 149 | static void AdjustTextureMatrix(const GrTexture* texture, GrMatrix* matrix); |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 150 | |
bsalomon@google.com | 288d954 | 2012-10-17 12:53:54 +0000 | [diff] [blame] | 151 | // This helper determines if what optimizations can be applied to the matrix after any coord |
| 152 | // adjustments are applied. The return is a bitfield of GrGLProgram::StageDesc::OptFlags. |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 153 | static int TextureMatrixOptFlags(const GrGLTexture* texture, const GrEffectStage& sampler); |
bsalomon@google.com | 88939ae | 2011-12-14 15:58:11 +0000 | [diff] [blame] | 154 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 155 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 156 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 157 | // for readability of function impls |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 158 | typedef GrGLProgram::Desc ProgramDesc; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 159 | typedef ProgramDesc::StageDesc StageDesc; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 160 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 161 | class ProgramCache : public ::GrNoncopyable { |
| 162 | public: |
| 163 | ProgramCache(const GrGLContextInfo& gl); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 164 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 165 | void abandon(); |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 166 | GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrEffect** stages); |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 167 | private: |
| 168 | enum { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 169 | kKeySize = sizeof(ProgramDesc), |
| 170 | // We may actually have kMaxEntries+1 shaders in the GL context because we create a new |
| 171 | // shader before evicting from the cache. |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 172 | kMaxEntries = 32 |
| 173 | }; |
| 174 | |
| 175 | class Entry; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 176 | // The value of the hash key is based on the ProgramDesc. |
| 177 | typedef GrTBinHashKey<Entry, kKeySize> ProgramHashKey; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 178 | |
| 179 | class Entry : public ::GrNoncopyable { |
| 180 | public: |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 181 | Entry() : fProgram(NULL), fLRUStamp(0) {} |
| 182 | Entry& operator = (const Entry& entry) { |
| 183 | GrSafeRef(entry.fProgram.get()); |
| 184 | fProgram.reset(entry.fProgram.get()); |
| 185 | fKey = entry.fKey; |
| 186 | fLRUStamp = entry.fLRUStamp; |
| 187 | return *this; |
| 188 | } |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 189 | int compare(const ProgramHashKey& key) const { |
| 190 | return fKey.compare(key); |
| 191 | } |
| 192 | |
| 193 | public: |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 194 | SkAutoTUnref<GrGLProgram> fProgram; |
| 195 | ProgramHashKey fKey; |
| 196 | unsigned int fLRUStamp; // Move outside entry? |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | GrTHashTable<Entry, ProgramHashKey, 8> fHashCache; |
| 200 | |
| 201 | Entry fEntries[kMaxEntries]; |
| 202 | int fCount; |
| 203 | unsigned int fCurrLRUStamp; |
| 204 | const GrGLContextInfo& fGL; |
| 205 | }; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 206 | |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 207 | // binds the texture and sets its texture params |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 208 | // This may also perform a downsample on the src texture which may or may |
| 209 | // not modify the scissor test and rect. So in flushGraphicsState a |
| 210 | // call to flushScissor must occur after all textures have been flushed via |
| 211 | // this function. |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 212 | void flushBoundTextureAndParams(int stage); |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 213 | void flushBoundTextureAndParams(int stage, |
| 214 | const GrTextureParams& params, |
| 215 | GrGLTexture* nextTexture); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 216 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 217 | // sets the texture matrix for the currently bound program |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 218 | void flushTextureMatrix(int stageIdx); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 219 | |
| 220 | // sets the color specified by GrDrawState::setColor() |
| 221 | void flushColor(GrColor color); |
| 222 | |
| 223 | // sets the color specified by GrDrawState::setCoverage() |
| 224 | void flushCoverage(GrColor color); |
| 225 | |
| 226 | // sets the MVP matrix uniform for currently bound program |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 227 | void flushViewMatrix(DrawType type); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 228 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 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 | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 233 | // flushes the scissor. see the note on flushBoundTextureAndParams about |
| 234 | // flushing the scissor after that function is called. |
| 235 | void flushScissor(); |
| 236 | |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 237 | void buildProgram(bool isPoints, |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 238 | BlendOptFlags blendOpts, |
| 239 | GrBlendCoeff dstCoeff, |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 240 | const GrEffect** effects, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 241 | ProgramDesc* desc); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 242 | |
bsalomon@google.com | 67e78c9 | 2012-10-17 13:36:14 +0000 | [diff] [blame] | 243 | // Inits GrDrawTarget::Caps, subclass may enable additional caps. |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 244 | void initCaps(); |
| 245 | |
| 246 | void initFSAASupport(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 247 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 248 | // determines valid stencil formats |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 249 | void initStencilFormats(); |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 250 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 251 | // notify callbacks to update state tracking when related |
| 252 | // objects are bound to GL or deleted outside of the class |
| 253 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 254 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 255 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 256 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 257 | void notifyTextureDelete(GrGLTexture* texture); |
| 258 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 259 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 260 | void setSpareTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 261 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 262 | // bound is region that may be modified and therefore has to be resolved. |
| 263 | // NULL means whole target. Can be an empty rect. |
| 264 | void flushRenderTarget(const GrIRect* bound); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 265 | void flushStencil(DrawType); |
| 266 | void flushAAState(DrawType); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 267 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 268 | bool configToGLFormats(GrPixelConfig config, |
| 269 | bool getSizedInternal, |
| 270 | GrGLenum* internalFormat, |
| 271 | GrGLenum* externalFormat, |
| 272 | GrGLenum* externalType); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 273 | // helper for onCreateTexture and writeTexturePixels |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 274 | bool uploadTexData(const GrGLTexture::Desc& desc, |
bsalomon@google.com | 1e0e607 | 2011-11-28 18:49:37 +0000 | [diff] [blame] | 275 | bool isNewTexture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 276 | int left, int top, int width, int height, |
| 277 | GrPixelConfig dataConfig, |
| 278 | const void* data, |
| 279 | size_t rowBytes); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 280 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 281 | bool createRenderTargetObjects(int width, int height, |
| 282 | GrGLuint texID, |
| 283 | GrGLRenderTarget::Desc* desc); |
| 284 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 285 | void fillInConfigRenderableTable(); |
| 286 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 287 | friend class GrGLVertexBuffer; |
| 288 | friend class GrGLIndexBuffer; |
| 289 | friend class GrGLTexture; |
| 290 | friend class GrGLRenderTarget; |
| 291 | |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 292 | GrGLContextInfo fGLContextInfo; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 293 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 294 | // GL program-related state |
| 295 | ProgramCache* fProgramCache; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 296 | SkAutoTUnref<GrGLProgram> fCurrentProgram; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 297 | |
| 298 | /////////////////////////////////////////////////////////////////////////// |
| 299 | ///@name Caching of GL State |
| 300 | ///@{ |
| 301 | int fHWActiveTextureUnitIdx; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 302 | GrGLuint fHWProgramID; |
| 303 | GrColor fHWConstAttribColor; |
| 304 | GrColor fHWConstAttribCoverage; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 305 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 306 | enum TriState { |
| 307 | kNo_TriState, |
| 308 | kYes_TriState, |
| 309 | kUnknown_TriState |
| 310 | }; |
| 311 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 312 | // last scissor / viewport scissor state seen by the GL. |
| 313 | struct { |
| 314 | TriState fEnabled; |
| 315 | GrGLIRect fRect; |
| 316 | void invalidate() { |
| 317 | fEnabled = kUnknown_TriState; |
| 318 | fRect.invalidate(); |
| 319 | } |
| 320 | } fHWScissorSettings; |
| 321 | |
| 322 | GrGLIRect fHWViewport; |
| 323 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 324 | struct { |
| 325 | size_t fVertexOffset; |
| 326 | GrVertexLayout fVertexLayout; |
| 327 | const GrVertexBuffer* fVertexBuffer; |
| 328 | const GrIndexBuffer* fIndexBuffer; |
| 329 | bool fArrayPtrsDirty; |
| 330 | } fHWGeometryState; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 331 | |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 332 | struct { |
| 333 | GrBlendCoeff fSrcCoeff; |
| 334 | GrBlendCoeff fDstCoeff; |
| 335 | GrColor fConstColor; |
| 336 | bool fConstColorValid; |
| 337 | TriState fEnabled; |
| 338 | |
| 339 | void invalidate() { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 340 | fSrcCoeff = kInvalid_GrBlendCoeff; |
| 341 | fDstCoeff = kInvalid_GrBlendCoeff; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 342 | fConstColorValid = false; |
| 343 | fEnabled = kUnknown_TriState; |
| 344 | } |
| 345 | } fHWBlendState; |
| 346 | |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 347 | struct { |
| 348 | TriState fMSAAEnabled; |
| 349 | TriState fSmoothLineEnabled; |
| 350 | void invalidate() { |
| 351 | fMSAAEnabled = kUnknown_TriState; |
| 352 | fSmoothLineEnabled = kUnknown_TriState; |
| 353 | } |
| 354 | } fHWAAState; |
| 355 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 356 | struct { |
| 357 | GrMatrix fViewMatrix; |
| 358 | SkISize fRTSize; |
| 359 | void invalidate() { |
| 360 | fViewMatrix = GrMatrix::InvalidMatrix(); |
| 361 | fRTSize.fWidth = -1; // just make the first value compared illegal. |
| 362 | } |
| 363 | } fHWPathMatrixState; |
| 364 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 365 | GrStencilSettings fHWStencilSettings; |
| 366 | TriState fHWStencilTestEnabled; |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 367 | |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 368 | GrDrawState::DrawFace fHWDrawFace; |
| 369 | TriState fHWWriteToColor; |
| 370 | TriState fHWDitherEnabled; |
| 371 | GrRenderTarget* fHWBoundRenderTarget; |
| 372 | GrTexture* fHWBoundTextures[GrDrawState::kNumStages]; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 373 | ///@} |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 374 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 375 | // we record what stencil format worked last time to hopefully exit early |
| 376 | // from our loop that tries stencil formats and calls check fb status. |
| 377 | int fLastSuccessfulStencilFmtIdx; |
| 378 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 379 | bool fPrintedCaps; |
| 380 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 381 | typedef GrGpu INHERITED; |
| 382 | }; |
| 383 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 384 | #endif |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 385 | |