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 | |
robertphillips@google.com | 37ebe3f | 2013-03-04 20:03:44 +0000 | [diff] [blame] | 13 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 14 | #include "GrBinHashKey.h" |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 15 | #include "GrDrawState.h" |
| 16 | #include "GrGpu.h" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 17 | #include "GrGLContext.h" |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 18 | #include "GrGLIndexBuffer.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 19 | #include "GrGLIRect.h" |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 20 | #include "GrGLProgram.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 21 | #include "GrGLStencilBuffer.h" |
| 22 | #include "GrGLTexture.h" |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 23 | #include "GrGLVertexArray.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 24 | #include "GrGLVertexBuffer.h" |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 25 | #include "../GrTHashCache.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | |
commit-bot@chromium.org | 174db77 | 2013-03-21 12:46:01 +0000 | [diff] [blame^] | 27 | #ifdef SK_DEVELOPER |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 28 | #define PROGRAM_CACHE_STATS |
| 29 | #endif |
| 30 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 31 | class GrGpuGL : public GrGpu { |
| 32 | public: |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 33 | GrGpuGL(const GrGLContext& ctx, GrContext* context); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 34 | virtual ~GrGpuGL(); |
| 35 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 36 | const GrGLInterface* glInterface() const { return fGLContext.interface(); } |
| 37 | GrGLBinding glBinding() const { return fGLContext.info().binding(); } |
| 38 | GrGLVersion glVersion() const { return fGLContext.info().version(); } |
| 39 | GrGLSLGeneration glslGeneration() const { return fGLContext.info().glslGeneration(); } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 41 | // Used by GrGLProgram to bind necessary textures for GrGLEffects. |
| 42 | void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture); |
| 43 | |
bsalomon@google.com | a45afcf | 2013-02-04 18:46:49 +0000 | [diff] [blame] | 44 | bool programUnitTest(int maxStages); |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 45 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 46 | // GrGpu overrides |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 47 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) const SK_OVERRIDE; |
| 48 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) const SK_OVERRIDE; |
| 49 | virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const SK_OVERRIDE; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 50 | virtual bool readPixelsWillPayForYFlip( |
| 51 | GrRenderTarget* renderTarget, |
| 52 | int left, int top, |
| 53 | int width, int height, |
| 54 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 55 | size_t rowBytes) const SK_OVERRIDE; |
| 56 | virtual bool fullReadPixelsIsFasterThanPartial() const SK_OVERRIDE; |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 57 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 58 | virtual void abandonResources() SK_OVERRIDE; |
| 59 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 60 | const GrGLCaps& glCaps() const { return fGLContext.info().caps(); } |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 61 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 62 | // These functions should be used to bind GL objects. They track the GL state and skip redundant |
skia.committer@gmail.com | 754a3eb | 2013-03-08 07:01:25 +0000 | [diff] [blame] | 63 | // bindings. Making the equivalent glBind calls directly will confuse the state tracking. |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 64 | void bindVertexArray(GrGLuint id) { |
| 65 | fHWGeometryState.setVertexArrayID(this, id); |
| 66 | } |
| 67 | void bindIndexBufferAndDefaultVertexArray(GrGLuint id) { |
| 68 | fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, id); |
| 69 | } |
| 70 | void bindVertexBuffer(GrGLuint id) { |
| 71 | fHWGeometryState.setVertexBufferID(this, id); |
| 72 | } |
| 73 | |
| 74 | // These callbacks update state tracking when GL objects are deleted. They are called from |
| 75 | // GrGLResource onRelease functions. |
| 76 | void notifyVertexArrayDelete(GrGLuint id) { |
| 77 | fHWGeometryState.notifyVertexArrayDelete(id); |
| 78 | } |
| 79 | void notifyVertexBufferDelete(GrGLuint id) { |
| 80 | fHWGeometryState.notifyVertexBufferDelete(id); |
| 81 | } |
| 82 | void notifyIndexBufferDelete(GrGLuint id) { |
| 83 | fHWGeometryState.notifyIndexBufferDelete(id); |
| 84 | } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 85 | void notifyTextureDelete(GrGLTexture* texture); |
| 86 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
| 87 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 88 | private: |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 89 | // GrGpu overrides |
bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 90 | virtual void onResetContext() SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 92 | virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 93 | const void* srcData, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 94 | size_t rowBytes) SK_OVERRIDE; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 95 | virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 96 | bool dynamic) SK_OVERRIDE; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 97 | virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 98 | bool dynamic) SK_OVERRIDE; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 99 | virtual GrPath* onCreatePath(const SkPath&) SK_OVERRIDE; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 100 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE; |
| 101 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 102 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 103 | int width, |
| 104 | int height) SK_OVERRIDE; |
| 105 | virtual bool attachStencilBufferToRenderTarget( |
| 106 | GrStencilBuffer* sb, |
| 107 | GrRenderTarget* rt) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 108 | |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 109 | virtual void onClear(const GrIRect* rect, GrColor color) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 110 | |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 111 | virtual void onForceRenderTargetFlush() SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 112 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 113 | virtual bool onReadPixels(GrRenderTarget* target, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 114 | int left, int top, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 115 | int width, int height, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 116 | GrPixelConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 117 | void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 118 | size_t rowBytes) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 119 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 120 | virtual bool onWriteTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 121 | int left, int top, int width, int height, |
| 122 | GrPixelConfig config, const void* buffer, |
| 123 | size_t rowBytes) SK_OVERRIDE; |
| 124 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 125 | virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; |
| 126 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 127 | virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 128 | |
| 129 | virtual void setStencilPathSettings(const GrPath&, |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 130 | SkPath::FillType, |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 131 | GrStencilSettings* settings) |
| 132 | SK_OVERRIDE; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 133 | virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 134 | |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 135 | virtual void clearStencil() SK_OVERRIDE; |
| 136 | virtual void clearStencilClip(const GrIRect& rect, |
| 137 | bool insideClip) SK_OVERRIDE; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 138 | virtual bool flushGraphicsState(DrawType) SK_OVERRIDE; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 139 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 140 | // binds texture unit in GL |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 141 | void setTextureUnit(int unitIdx); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 142 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 143 | // Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset |
| 144 | // an into the index buffer. It does not account for drawInfo.startIndex() but rather the start |
| 145 | // index is relative to the returned offset. |
| 146 | void setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 147 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 148 | // Subclasses should call this to flush the blend state. |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 149 | // The params should be the final coefficients to apply |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 150 | // (after any blending optimizations or dual source blending considerations |
| 151 | // have been accounted for). |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 152 | void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 153 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 154 | bool hasExtension(const char* ext) const { return fGLContext.info().hasExtension(ext); } |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 155 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 156 | const GrGLContext& glContext() const { return fGLContext; } |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 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 | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 160 | class ProgramCache : public ::GrNoncopyable { |
| 161 | public: |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 162 | ProgramCache(const GrGLContext& gl); |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 163 | ~ProgramCache(); |
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 | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 166 | GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrEffectStage* stages[]); |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 167 | private: |
| 168 | enum { |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 169 | kKeySize = sizeof(GrGLProgram::Desc), |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 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; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 204 | const GrGLContext& fGL; |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 205 | #ifdef PROGRAM_CACHE_STATS |
| 206 | int fTotalRequests; |
| 207 | int fCacheMisses; |
| 208 | #endif |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 209 | }; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 210 | |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 211 | // sets the matrix for path stenciling (uses the GL fixed pipe matrices) |
| 212 | void flushPathStencilMatrix(); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 213 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 214 | // flushes dithering, color-mask, and face culling stat |
| 215 | void flushMiscFixedFunctionState(); |
| 216 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 217 | // flushes the scissor. see the note on flushBoundTextureAndParams about |
| 218 | // flushing the scissor after that function is called. |
| 219 | void flushScissor(); |
| 220 | |
bsalomon@google.com | 67e78c9 | 2012-10-17 13:36:14 +0000 | [diff] [blame] | 221 | // Inits GrDrawTarget::Caps, subclass may enable additional caps. |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 222 | void initCaps(); |
| 223 | |
| 224 | void initFSAASupport(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 225 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 226 | // determines valid stencil formats |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 227 | void initStencilFormats(); |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 228 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 229 | void setSpareTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 230 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 231 | // bound is region that may be modified and therefore has to be resolved. |
| 232 | // NULL means whole target. Can be an empty rect. |
| 233 | void flushRenderTarget(const GrIRect* bound); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 234 | void flushStencil(DrawType); |
| 235 | void flushAAState(DrawType); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 236 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 237 | bool configToGLFormats(GrPixelConfig config, |
| 238 | bool getSizedInternal, |
| 239 | GrGLenum* internalFormat, |
| 240 | GrGLenum* externalFormat, |
| 241 | GrGLenum* externalType); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 242 | // helper for onCreateTexture and writeTexturePixels |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 243 | bool uploadTexData(const GrGLTexture::Desc& desc, |
bsalomon@google.com | 1e0e607 | 2011-11-28 18:49:37 +0000 | [diff] [blame] | 244 | bool isNewTexture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 245 | int left, int top, int width, int height, |
| 246 | GrPixelConfig dataConfig, |
| 247 | const void* data, |
| 248 | size_t rowBytes); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 249 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 250 | bool createRenderTargetObjects(int width, int height, |
| 251 | GrGLuint texID, |
| 252 | GrGLRenderTarget::Desc* desc); |
| 253 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 254 | void fillInConfigRenderableTable(); |
| 255 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 256 | GrGLContext fGLContext; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 257 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 258 | // GL program-related state |
| 259 | ProgramCache* fProgramCache; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 260 | SkAutoTUnref<GrGLProgram> fCurrentProgram; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 261 | |
| 262 | /////////////////////////////////////////////////////////////////////////// |
| 263 | ///@name Caching of GL State |
| 264 | ///@{ |
| 265 | int fHWActiveTextureUnitIdx; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 266 | GrGLuint fHWProgramID; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 267 | |
| 268 | GrGLProgram::SharedGLState fSharedGLProgramState; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 269 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 270 | enum TriState { |
| 271 | kNo_TriState, |
| 272 | kYes_TriState, |
| 273 | kUnknown_TriState |
| 274 | }; |
| 275 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 276 | // last scissor / viewport scissor state seen by the GL. |
| 277 | struct { |
| 278 | TriState fEnabled; |
| 279 | GrGLIRect fRect; |
| 280 | void invalidate() { |
| 281 | fEnabled = kUnknown_TriState; |
| 282 | fRect.invalidate(); |
| 283 | } |
| 284 | } fHWScissorSettings; |
| 285 | |
| 286 | GrGLIRect fHWViewport; |
| 287 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 288 | /** |
| 289 | * Tracks bound vertex and index buffers and vertex attrib array state. |
| 290 | */ |
| 291 | class HWGeometryState { |
| 292 | public: |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 293 | HWGeometryState() { fVBOVertexArray = NULL; this->invalidate(); } |
skia.committer@gmail.com | 754a3eb | 2013-03-08 07:01:25 +0000 | [diff] [blame] | 294 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 295 | ~HWGeometryState() { SkSafeUnref(fVBOVertexArray); } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 296 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 297 | void invalidate() { |
| 298 | fBoundVertexArrayIDIsValid = false; |
| 299 | fBoundVertexBufferIDIsValid = false; |
| 300 | fDefaultVertexArrayBoundIndexBufferID = false; |
| 301 | fDefaultVertexArrayBoundIndexBufferIDIsValid = false; |
| 302 | fDefaultVertexArrayAttribState.invalidate(); |
| 303 | } |
| 304 | |
| 305 | void notifyVertexArrayDelete(GrGLuint id) { |
| 306 | if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) { |
| 307 | // Does implicit bind to 0 |
| 308 | fBoundVertexArrayID = 0; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 312 | void setVertexArrayID(GrGpuGL* gpu, GrGLuint arrayID) { |
| 313 | if (!gpu->glCaps().vertexArrayObjectSupport()) { |
| 314 | GrAssert(0 == arrayID); |
| 315 | return; |
| 316 | } |
| 317 | if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) { |
| 318 | GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID)); |
| 319 | fBoundVertexArrayIDIsValid = true; |
| 320 | fBoundVertexArrayID = arrayID; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 324 | void notifyVertexBufferDelete(GrGLuint id) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 325 | if (fBoundVertexBufferIDIsValid && id == fBoundVertexBufferID) { |
| 326 | fBoundVertexBufferID = 0; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 327 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 328 | if (NULL != fVBOVertexArray) { |
| 329 | fVBOVertexArray->notifyVertexBufferDelete(id); |
| 330 | } |
| 331 | fDefaultVertexArrayAttribState.notifyVertexBufferDelete(id); |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 332 | } |
| 333 | |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 334 | void notifyIndexBufferDelete(GrGLuint id) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 335 | if (fDefaultVertexArrayBoundIndexBufferIDIsValid && |
| 336 | id == fDefaultVertexArrayBoundIndexBufferID) { |
| 337 | fDefaultVertexArrayBoundIndexBufferID = 0; |
| 338 | } |
| 339 | if (NULL != fVBOVertexArray) { |
| 340 | fVBOVertexArray->notifyIndexBufferDelete(id); |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 344 | void setVertexBufferID(GrGpuGL* gpu, GrGLuint id) { |
| 345 | if (!fBoundVertexBufferIDIsValid || id != fBoundVertexBufferID) { |
| 346 | GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ARRAY_BUFFER, id)); |
| 347 | fBoundVertexBufferIDIsValid = true; |
| 348 | fBoundVertexBufferID = id; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 352 | /** |
| 353 | * Binds the default vertex array and binds the index buffer. This is used when binding |
| 354 | * an index buffer in order to update it. |
| 355 | */ |
| 356 | void setIndexBufferIDOnDefaultVertexArray(GrGpuGL* gpu, GrGLuint id) { |
| 357 | this->setVertexArrayID(gpu, 0); |
| 358 | if (!fDefaultVertexArrayBoundIndexBufferIDIsValid || |
| 359 | id != fDefaultVertexArrayBoundIndexBufferID) { |
| 360 | GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id)); |
| 361 | fDefaultVertexArrayBoundIndexBufferIDIsValid = true; |
| 362 | fDefaultVertexArrayBoundIndexBufferID = id; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Binds the vertex array object that should be used to render from the vertex buffer. |
| 368 | * The vertex array is bound and its attrib array state object is returned. The vertex |
| 369 | * buffer is bound. The index buffer (if non-NULL) is bound to the vertex array. The |
skia.committer@gmail.com | 754a3eb | 2013-03-08 07:01:25 +0000 | [diff] [blame] | 370 | * returned GrGLAttribArrayState should be used to set vertex attribute arrays. |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 371 | */ |
| 372 | GrGLAttribArrayState* bindArrayAndBuffersToDraw(GrGpuGL* gpu, |
| 373 | const GrGLVertexBuffer* vbuffer, |
| 374 | const GrGLIndexBuffer* ibuffer); |
| 375 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 376 | private: |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 377 | GrGLuint fBoundVertexArrayID; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 378 | GrGLuint fBoundVertexBufferID; |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 379 | bool fBoundVertexArrayIDIsValid; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 380 | bool fBoundVertexBufferIDIsValid; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 381 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 382 | GrGLuint fDefaultVertexArrayBoundIndexBufferID; |
| 383 | bool fDefaultVertexArrayBoundIndexBufferIDIsValid; |
| 384 | // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0 |
| 385 | // is bound. However, this class is internal to GrGpuGL and this object never leaks out of |
| 386 | // GrGpuGL. |
| 387 | GrGLAttribArrayState fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 388 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 389 | // This is used when we're using a core profile and the vertices are in a VBO. |
| 390 | GrGLVertexArray* fVBOVertexArray; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 391 | } fHWGeometryState; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 392 | |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 393 | struct { |
| 394 | GrBlendCoeff fSrcCoeff; |
| 395 | GrBlendCoeff fDstCoeff; |
| 396 | GrColor fConstColor; |
| 397 | bool fConstColorValid; |
| 398 | TriState fEnabled; |
| 399 | |
| 400 | void invalidate() { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 401 | fSrcCoeff = kInvalid_GrBlendCoeff; |
| 402 | fDstCoeff = kInvalid_GrBlendCoeff; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 403 | fConstColorValid = false; |
| 404 | fEnabled = kUnknown_TriState; |
| 405 | } |
| 406 | } fHWBlendState; |
| 407 | |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 408 | struct { |
| 409 | TriState fMSAAEnabled; |
| 410 | TriState fSmoothLineEnabled; |
| 411 | void invalidate() { |
| 412 | fMSAAEnabled = kUnknown_TriState; |
| 413 | fSmoothLineEnabled = kUnknown_TriState; |
| 414 | } |
| 415 | } fHWAAState; |
| 416 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 417 | |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 418 | GrGLProgram::MatrixState fHWPathStencilMatrixState; |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 419 | |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 420 | GrStencilSettings fHWStencilSettings; |
| 421 | TriState fHWStencilTestEnabled; |
| 422 | |
| 423 | GrDrawState::DrawFace fHWDrawFace; |
| 424 | TriState fHWWriteToColor; |
| 425 | TriState fHWDitherEnabled; |
| 426 | GrRenderTarget* fHWBoundRenderTarget; |
| 427 | GrTexture* fHWBoundTextures[GrDrawState::kNumStages]; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 428 | ///@} |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 429 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 430 | // we record what stencil format worked last time to hopefully exit early |
| 431 | // from our loop that tries stencil formats and calls check fb status. |
| 432 | int fLastSuccessfulStencilFmtIdx; |
| 433 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 434 | bool fPrintedCaps; |
| 435 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 436 | typedef GrGpu INHERITED; |
| 437 | }; |
| 438 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 439 | #endif |