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 | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 39 | // Used by GrGLProgram to bind necessary textures for GrGLEffects. |
| 40 | void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture); |
| 41 | |
| 42 | bool programUnitTest(); |
| 43 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 44 | // GrGpu overrides |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 45 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 46 | const SK_OVERRIDE; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 47 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 48 | const SK_OVERRIDE; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 49 | virtual bool readPixelsWillPayForYFlip( |
| 50 | GrRenderTarget* renderTarget, |
| 51 | int left, int top, |
| 52 | int width, int height, |
| 53 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 54 | size_t rowBytes) const SK_OVERRIDE; |
| 55 | virtual bool fullReadPixelsIsFasterThanPartial() const SK_OVERRIDE; |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 56 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 57 | virtual void abandonResources() SK_OVERRIDE; |
| 58 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame^] | 59 | private: |
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 | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 71 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE; |
| 72 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 73 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 74 | int width, |
| 75 | int height) SK_OVERRIDE; |
| 76 | virtual bool attachStencilBufferToRenderTarget( |
| 77 | GrStencilBuffer* sb, |
| 78 | GrRenderTarget* rt) 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 onClear(const GrIRect* rect, GrColor color) 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 onForceRenderTargetFlush() SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 83 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 84 | virtual bool onReadPixels(GrRenderTarget* target, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 85 | int left, int top, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 86 | int width, int height, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 87 | GrPixelConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 88 | void* buffer, |
| 89 | size_t rowBytes, |
| 90 | bool invertY) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 92 | virtual void onWriteTexturePixels(GrTexture* texture, |
| 93 | int left, int top, int width, int height, |
| 94 | GrPixelConfig config, const void* buffer, |
| 95 | size_t rowBytes) SK_OVERRIDE; |
| 96 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 97 | virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; |
| 98 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 99 | virtual void onGpuDrawIndexed(GrPrimitiveType type, |
| 100 | uint32_t startVertex, |
| 101 | uint32_t startIndex, |
| 102 | uint32_t vertexCount, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 103 | uint32_t indexCount) SK_OVERRIDE; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 104 | virtual void onGpuDrawNonIndexed(GrPrimitiveType type, |
| 105 | uint32_t vertexCount, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 106 | uint32_t numVertices) SK_OVERRIDE; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 107 | |
| 108 | virtual void setStencilPathSettings(const GrPath&, |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 109 | SkPath::FillType, |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 110 | GrStencilSettings* settings) |
| 111 | SK_OVERRIDE; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 112 | virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 113 | |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 114 | virtual void clearStencil() SK_OVERRIDE; |
| 115 | virtual void clearStencilClip(const GrIRect& rect, |
| 116 | bool insideClip) SK_OVERRIDE; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 117 | virtual bool flushGraphicsState(DrawType) SK_OVERRIDE; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 118 | virtual void setupGeometry(int* startVertex, |
| 119 | int* startIndex, |
| 120 | int vertexCount, |
| 121 | int indexCount) SK_OVERRIDE; |
| 122 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 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. |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame^] | 130 | void setBuffers(bool indexed, int* extraVertexOffset, int* extraIndexOffset); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 131 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 132 | // Subclasses should call this to flush the blend state. |
| 133 | // The params should be the final coeffecients to apply |
| 134 | // (after any blending optimizations or dual source blending considerations |
| 135 | // have been accounted for). |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame^] | 136 | void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 137 | |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 138 | bool hasExtension(const char* ext) const { |
| 139 | return fGLContextInfo.hasExtension(ext); |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | const GrGLContextInfo& glContextInfo() const { return fGLContextInfo; } |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 143 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 144 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 145 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 146 | // for readability of function impls |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 147 | typedef GrGLProgram::Desc ProgramDesc; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 148 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 149 | class ProgramCache : public ::GrNoncopyable { |
| 150 | public: |
| 151 | ProgramCache(const GrGLContextInfo& gl); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 152 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 153 | void abandon(); |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 154 | GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrEffectStage* stages[]); |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 155 | private: |
| 156 | enum { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 157 | kKeySize = sizeof(ProgramDesc), |
| 158 | // We may actually have kMaxEntries+1 shaders in the GL context because we create a new |
| 159 | // shader before evicting from the cache. |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 160 | kMaxEntries = 32 |
| 161 | }; |
| 162 | |
| 163 | class Entry; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 164 | // The value of the hash key is based on the ProgramDesc. |
| 165 | typedef GrTBinHashKey<Entry, kKeySize> ProgramHashKey; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 166 | |
| 167 | class Entry : public ::GrNoncopyable { |
| 168 | public: |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 169 | Entry() : fProgram(NULL), fLRUStamp(0) {} |
| 170 | Entry& operator = (const Entry& entry) { |
| 171 | GrSafeRef(entry.fProgram.get()); |
| 172 | fProgram.reset(entry.fProgram.get()); |
| 173 | fKey = entry.fKey; |
| 174 | fLRUStamp = entry.fLRUStamp; |
| 175 | return *this; |
| 176 | } |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 177 | int compare(const ProgramHashKey& key) const { |
| 178 | return fKey.compare(key); |
| 179 | } |
| 180 | |
| 181 | public: |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 182 | SkAutoTUnref<GrGLProgram> fProgram; |
| 183 | ProgramHashKey fKey; |
| 184 | unsigned int fLRUStamp; // Move outside entry? |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | GrTHashTable<Entry, ProgramHashKey, 8> fHashCache; |
| 188 | |
| 189 | Entry fEntries[kMaxEntries]; |
| 190 | int fCount; |
| 191 | unsigned int fCurrLRUStamp; |
| 192 | const GrGLContextInfo& fGL; |
| 193 | }; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 194 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 195 | // sets the color specified by GrDrawState::setColor() |
| 196 | void flushColor(GrColor color); |
| 197 | |
| 198 | // sets the color specified by GrDrawState::setCoverage() |
| 199 | void flushCoverage(GrColor color); |
| 200 | |
| 201 | // sets the MVP matrix uniform for currently bound program |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 202 | void flushViewMatrix(DrawType type); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 203 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 204 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 205 | // flushes dithering, color-mask, and face culling stat |
| 206 | void flushMiscFixedFunctionState(); |
| 207 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 208 | // flushes the scissor. see the note on flushBoundTextureAndParams about |
| 209 | // flushing the scissor after that function is called. |
| 210 | void flushScissor(); |
| 211 | |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 212 | void buildProgram(bool isPoints, |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 213 | BlendOptFlags blendOpts, |
| 214 | GrBlendCoeff dstCoeff, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 215 | ProgramDesc* desc); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 216 | |
bsalomon@google.com | 67e78c9 | 2012-10-17 13:36:14 +0000 | [diff] [blame] | 217 | // Inits GrDrawTarget::Caps, subclass may enable additional caps. |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 218 | void initCaps(); |
| 219 | |
| 220 | void initFSAASupport(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 221 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 222 | // determines valid stencil formats |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 223 | void initStencilFormats(); |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 224 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 225 | // notify callbacks to update state tracking when related |
| 226 | // objects are bound to GL or deleted outside of the class |
| 227 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 228 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 229 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 230 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 231 | void notifyTextureDelete(GrGLTexture* texture); |
| 232 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 233 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 234 | void setSpareTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 235 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 236 | // bound is region that may be modified and therefore has to be resolved. |
| 237 | // NULL means whole target. Can be an empty rect. |
| 238 | void flushRenderTarget(const GrIRect* bound); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 239 | void flushStencil(DrawType); |
| 240 | void flushAAState(DrawType); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 241 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 242 | bool configToGLFormats(GrPixelConfig config, |
| 243 | bool getSizedInternal, |
| 244 | GrGLenum* internalFormat, |
| 245 | GrGLenum* externalFormat, |
| 246 | GrGLenum* externalType); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 247 | // helper for onCreateTexture and writeTexturePixels |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 248 | bool uploadTexData(const GrGLTexture::Desc& desc, |
bsalomon@google.com | 1e0e607 | 2011-11-28 18:49:37 +0000 | [diff] [blame] | 249 | bool isNewTexture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 250 | int left, int top, int width, int height, |
| 251 | GrPixelConfig dataConfig, |
| 252 | const void* data, |
| 253 | size_t rowBytes); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 254 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 255 | bool createRenderTargetObjects(int width, int height, |
| 256 | GrGLuint texID, |
| 257 | GrGLRenderTarget::Desc* desc); |
| 258 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 259 | void fillInConfigRenderableTable(); |
| 260 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 261 | friend class GrGLVertexBuffer; |
| 262 | friend class GrGLIndexBuffer; |
| 263 | friend class GrGLTexture; |
| 264 | friend class GrGLRenderTarget; |
| 265 | |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 266 | GrGLContextInfo fGLContextInfo; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 267 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 268 | // GL program-related state |
| 269 | ProgramCache* fProgramCache; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 270 | SkAutoTUnref<GrGLProgram> fCurrentProgram; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 271 | |
| 272 | /////////////////////////////////////////////////////////////////////////// |
| 273 | ///@name Caching of GL State |
| 274 | ///@{ |
| 275 | int fHWActiveTextureUnitIdx; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 276 | GrGLuint fHWProgramID; |
| 277 | GrColor fHWConstAttribColor; |
| 278 | GrColor fHWConstAttribCoverage; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 279 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 280 | enum TriState { |
| 281 | kNo_TriState, |
| 282 | kYes_TriState, |
| 283 | kUnknown_TriState |
| 284 | }; |
| 285 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 286 | // last scissor / viewport scissor state seen by the GL. |
| 287 | struct { |
| 288 | TriState fEnabled; |
| 289 | GrGLIRect fRect; |
| 290 | void invalidate() { |
| 291 | fEnabled = kUnknown_TriState; |
| 292 | fRect.invalidate(); |
| 293 | } |
| 294 | } fHWScissorSettings; |
| 295 | |
| 296 | GrGLIRect fHWViewport; |
| 297 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 298 | struct { |
| 299 | size_t fVertexOffset; |
| 300 | GrVertexLayout fVertexLayout; |
| 301 | const GrVertexBuffer* fVertexBuffer; |
| 302 | const GrIndexBuffer* fIndexBuffer; |
| 303 | bool fArrayPtrsDirty; |
| 304 | } fHWGeometryState; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 305 | |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 306 | struct { |
| 307 | GrBlendCoeff fSrcCoeff; |
| 308 | GrBlendCoeff fDstCoeff; |
| 309 | GrColor fConstColor; |
| 310 | bool fConstColorValid; |
| 311 | TriState fEnabled; |
| 312 | |
| 313 | void invalidate() { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 314 | fSrcCoeff = kInvalid_GrBlendCoeff; |
| 315 | fDstCoeff = kInvalid_GrBlendCoeff; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 316 | fConstColorValid = false; |
| 317 | fEnabled = kUnknown_TriState; |
| 318 | } |
| 319 | } fHWBlendState; |
| 320 | |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 321 | struct { |
| 322 | TriState fMSAAEnabled; |
| 323 | TriState fSmoothLineEnabled; |
| 324 | void invalidate() { |
| 325 | fMSAAEnabled = kUnknown_TriState; |
| 326 | fSmoothLineEnabled = kUnknown_TriState; |
| 327 | } |
| 328 | } fHWAAState; |
| 329 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 330 | struct { |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 331 | SkMatrix fViewMatrix; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 332 | SkISize fRTSize; |
| 333 | void invalidate() { |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 334 | fViewMatrix = SkMatrix::InvalidMatrix(); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 335 | fRTSize.fWidth = -1; // just make the first value compared illegal. |
| 336 | } |
| 337 | } fHWPathMatrixState; |
| 338 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 339 | GrStencilSettings fHWStencilSettings; |
| 340 | TriState fHWStencilTestEnabled; |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 341 | |
bsalomon@google.com | c811ea3 | 2012-05-21 15:33:09 +0000 | [diff] [blame] | 342 | GrDrawState::DrawFace fHWDrawFace; |
| 343 | TriState fHWWriteToColor; |
| 344 | TriState fHWDitherEnabled; |
| 345 | GrRenderTarget* fHWBoundRenderTarget; |
| 346 | GrTexture* fHWBoundTextures[GrDrawState::kNumStages]; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 347 | ///@} |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 348 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 349 | // we record what stencil format worked last time to hopefully exit early |
| 350 | // from our loop that tries stencil formats and calls check fb status. |
| 351 | int fLastSuccessfulStencilFmtIdx; |
| 352 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 353 | bool fPrintedCaps; |
| 354 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 355 | typedef GrGpu INHERITED; |
| 356 | }; |
| 357 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 358 | #endif |