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 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrGpuGL_DEFINED |
| 9 | #define GrGpuGL_DEFINED |
| 10 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 11 | #include "GrBinHashKey.h" |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 12 | #include "GrDrawState.h" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 13 | #include "GrGLContext.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 14 | #include "GrGLIRect.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 15 | #include "GrGLIndexBuffer.h" |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 16 | #include "GrGLProgram.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 17 | #include "GrGLStencilBuffer.h" |
| 18 | #include "GrGLTexture.h" |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 19 | #include "GrGLVertexArray.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 20 | #include "GrGLVertexBuffer.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 21 | #include "GrGpu.h" |
mtklein@google.com | 4c2af74 | 2013-10-21 21:04:06 +0000 | [diff] [blame] | 22 | #include "GrTHashTable.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 23 | #include "SkTypes.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
commit-bot@chromium.org | 174db77 | 2013-03-21 12:46:01 +0000 | [diff] [blame] | 25 | #ifdef SK_DEVELOPER |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 26 | #define PROGRAM_CACHE_STATS |
| 27 | #endif |
| 28 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 29 | class GrGpuGL : public GrGpu { |
| 30 | public: |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 31 | GrGpuGL(const GrGLContext& ctx, GrContext* context); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 32 | virtual ~GrGpuGL(); |
| 33 | |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 34 | const GrGLContext& glContext() const { return fGLContext; } |
| 35 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 36 | const GrGLInterface* glInterface() const { return fGLContext.interface(); } |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 37 | const GrGLContextInfo& ctxInfo() const { return fGLContext; } |
| 38 | GrGLStandard glStandard() const { return fGLContext.standard(); } |
| 39 | GrGLVersion glVersion() const { return fGLContext.version(); } |
| 40 | GrGLSLGeneration glslGeneration() const { return fGLContext.glslGeneration(); } |
| 41 | const GrGLCaps& glCaps() const { return *fGLContext.caps(); } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 42 | |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 43 | // Used by GrGLProgram and GrGLTexGenProgramEffects to configure OpenGL state. |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 44 | void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture); |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 45 | void setProjectionMatrix(const SkMatrix& matrix, |
| 46 | const SkISize& renderTargetSize, |
| 47 | GrSurfaceOrigin renderTargetOrigin); |
| 48 | enum TexGenComponents { |
| 49 | kS_TexGenComponents = 1, |
| 50 | kST_TexGenComponents = 2, |
| 51 | kSTR_TexGenComponents = 3 |
| 52 | }; |
| 53 | void enableTexGen(int unitIdx, TexGenComponents, const GrGLfloat* coefficients); |
| 54 | void enableTexGen(int unitIdx, TexGenComponents, const SkMatrix& matrix); |
commit-bot@chromium.org | 2080722 | 2013-11-01 11:54:54 +0000 | [diff] [blame] | 55 | void flushTexGenSettings(int numUsedTexCoordSets); |
commit-bot@chromium.org | 8e919ad | 2013-10-21 14:48:23 +0000 | [diff] [blame] | 56 | bool shouldUseFixedFunctionTexturing() const { |
| 57 | return this->glCaps().fixedFunctionSupport() && |
| 58 | this->glCaps().pathRenderingSupport(); |
| 59 | } |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 60 | |
bsalomon@google.com | a45afcf | 2013-02-04 18:46:49 +0000 | [diff] [blame] | 61 | bool programUnitTest(int maxStages); |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 62 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 63 | // GrGpu overrides |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 64 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig, |
| 65 | GrPixelConfig surfaceConfig) const SK_OVERRIDE; |
| 66 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig, |
| 67 | GrPixelConfig surfaceConfig) const SK_OVERRIDE; |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 68 | virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const SK_OVERRIDE; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 69 | virtual bool readPixelsWillPayForYFlip( |
| 70 | GrRenderTarget* renderTarget, |
| 71 | int left, int top, |
| 72 | int width, int height, |
| 73 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 74 | size_t rowBytes) const SK_OVERRIDE; |
| 75 | virtual bool fullReadPixelsIsFasterThanPartial() const SK_OVERRIDE; |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 76 | |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 77 | virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) SK_OVERRIDE; |
| 78 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 79 | virtual void abandonResources() SK_OVERRIDE; |
| 80 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 81 | // 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] | 82 | // 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] | 83 | void bindVertexArray(GrGLuint id) { |
| 84 | fHWGeometryState.setVertexArrayID(this, id); |
| 85 | } |
| 86 | void bindIndexBufferAndDefaultVertexArray(GrGLuint id) { |
| 87 | fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, id); |
| 88 | } |
| 89 | void bindVertexBuffer(GrGLuint id) { |
| 90 | fHWGeometryState.setVertexBufferID(this, id); |
| 91 | } |
| 92 | |
| 93 | // These callbacks update state tracking when GL objects are deleted. They are called from |
| 94 | // GrGLResource onRelease functions. |
| 95 | void notifyVertexArrayDelete(GrGLuint id) { |
| 96 | fHWGeometryState.notifyVertexArrayDelete(id); |
| 97 | } |
| 98 | void notifyVertexBufferDelete(GrGLuint id) { |
| 99 | fHWGeometryState.notifyVertexBufferDelete(id); |
| 100 | } |
| 101 | void notifyIndexBufferDelete(GrGLuint id) { |
| 102 | fHWGeometryState.notifyIndexBufferDelete(id); |
| 103 | } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 104 | void notifyTextureDelete(GrGLTexture* texture); |
| 105 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
| 106 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 107 | protected: |
| 108 | virtual bool onCopySurface(GrSurface* dst, |
| 109 | GrSurface* src, |
| 110 | const SkIRect& srcRect, |
| 111 | const SkIPoint& dstPoint) SK_OVERRIDE; |
| 112 | |
| 113 | virtual bool onCanCopySurface(GrSurface* dst, |
| 114 | GrSurface* src, |
| 115 | const SkIRect& srcRect, |
| 116 | const SkIPoint& dstPoint) SK_OVERRIDE; |
| 117 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 118 | private: |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 119 | // GrGpu overrides |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 120 | virtual void onResetContext(uint32_t resetBits) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 121 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 122 | virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 123 | const void* srcData, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 124 | size_t rowBytes) SK_OVERRIDE; |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 125 | virtual GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) SK_OVERRIDE; |
| 126 | virtual GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 127 | virtual GrPath* onCreatePath(const SkPath&, const SkStrokeRec&) SK_OVERRIDE; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 128 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE; |
| 129 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 130 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 131 | int width, |
| 132 | int height) SK_OVERRIDE; |
| 133 | virtual bool attachStencilBufferToRenderTarget( |
| 134 | GrStencilBuffer* sb, |
| 135 | GrRenderTarget* rt) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 136 | |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 137 | virtual void onClear(const SkIRect* rect, GrColor color, bool canIgnoreRect) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 138 | |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 139 | virtual void onForceRenderTargetFlush() SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 140 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 141 | virtual bool onReadPixels(GrRenderTarget* target, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 142 | int left, int top, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 143 | int width, int height, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 144 | GrPixelConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 145 | void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 146 | size_t rowBytes) SK_OVERRIDE; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 147 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 148 | virtual bool onWriteTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 149 | int left, int top, int width, int height, |
| 150 | GrPixelConfig config, const void* buffer, |
| 151 | size_t rowBytes) SK_OVERRIDE; |
| 152 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 153 | virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; |
| 154 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 155 | virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 156 | |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 157 | virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 158 | virtual void onGpuDrawPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 159 | |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 160 | virtual void clearStencil() SK_OVERRIDE; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 161 | virtual void clearStencilClip(const SkIRect& rect, |
bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 162 | bool insideClip) SK_OVERRIDE; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 163 | virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 164 | |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame^] | 165 | // GrDrawTarget ovverides |
| 166 | virtual void onInstantGpuTraceEvent(const char* marker) SK_OVERRIDE; |
| 167 | virtual void onPushGpuTraceEvent(const char* marker) SK_OVERRIDE; |
| 168 | virtual void onPopGpuTraceEvent() SK_OVERRIDE; |
| 169 | |
| 170 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 171 | // binds texture unit in GL |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 172 | void setTextureUnit(int unitIdx); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 173 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 174 | // Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset |
| 175 | // an into the index buffer. It does not account for drawInfo.startIndex() but rather the start |
| 176 | // index is relative to the returned offset. |
| 177 | void setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 178 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 179 | // Subclasses should call this to flush the blend state. |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 180 | // The params should be the final coefficients to apply |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 181 | // (after any blending optimizations or dual source blending considerations |
| 182 | // have been accounted for). |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 183 | void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 184 | |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 185 | bool hasExtension(const char* ext) const { return fGLContext.hasExtension(ext); } |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 186 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 187 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 188 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 189 | class ProgramCache : public ::SkNoncopyable { |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 190 | public: |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 191 | ProgramCache(GrGpuGL* gpu); |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 192 | ~ProgramCache(); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 193 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 194 | void abandon(); |
bsalomon@google.com | 2c84aa3 | 2013-06-06 20:28:57 +0000 | [diff] [blame] | 195 | GrGLProgram* getProgram(const GrGLProgramDesc& desc, |
| 196 | const GrEffectStage* colorStages[], |
| 197 | const GrEffectStage* coverageStages[]); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 198 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 199 | private: |
| 200 | enum { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 201 | // We may actually have kMaxEntries+1 shaders in the GL context because we create a new |
| 202 | // shader before evicting from the cache. |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 203 | kMaxEntries = 32, |
| 204 | kHashBits = 6, |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 207 | struct Entry; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 208 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 209 | struct ProgDescLess; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 210 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 211 | // binary search for entry matching desc. returns index into fEntries that matches desc or ~ |
| 212 | // of the index of where it should be inserted. |
| 213 | int search(const GrGLProgramDesc& desc) const; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 214 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 215 | // sorted array of all the entries |
| 216 | Entry* fEntries[kMaxEntries]; |
| 217 | // hash table based on lowest kHashBits bits of the program key. Used to avoid binary |
| 218 | // searching fEntries. |
| 219 | Entry* fHashTable[1 << kHashBits]; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 220 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 221 | int fCount; |
| 222 | unsigned int fCurrLRUStamp; |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 223 | GrGpuGL* fGpu; |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 224 | #ifdef PROGRAM_CACHE_STATS |
| 225 | int fTotalRequests; |
| 226 | int fCacheMisses; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 227 | int fHashMisses; // cache hit but hash table missed |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 228 | #endif |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 229 | }; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 230 | |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 231 | // flushes dithering, color-mask, and face culling stat |
| 232 | void flushMiscFixedFunctionState(); |
| 233 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 234 | // flushes the scissor. see the note on flushBoundTextureAndParams about |
| 235 | // flushing the scissor after that function is called. |
| 236 | void flushScissor(); |
| 237 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 238 | void initFSAASupport(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 239 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 240 | // determines valid stencil formats |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 241 | void initStencilFormats(); |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 242 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 243 | // sets a texture unit to use for texture operations other than binding a texture to a program. |
| 244 | // ensures that such operations don't negatively interact with tracking bound textures. |
| 245 | void setScratchTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 246 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 247 | // bound is region that may be modified and therefore has to be resolved. |
| 248 | // NULL means whole target. Can be an empty rect. |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 249 | void flushRenderTarget(const SkIRect* bound); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 250 | void flushStencil(DrawType); |
| 251 | void flushAAState(DrawType); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 252 | void flushPathStencilSettings(SkPath::FillType fill); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 253 | |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 254 | bool configToGLFormats(GrPixelConfig config, |
| 255 | bool getSizedInternal, |
| 256 | GrGLenum* internalFormat, |
| 257 | GrGLenum* externalFormat, |
| 258 | GrGLenum* externalType); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 259 | // helper for onCreateTexture and writeTexturePixels |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 260 | bool uploadTexData(const GrGLTexture::Desc& desc, |
bsalomon@google.com | 1e0e607 | 2011-11-28 18:49:37 +0000 | [diff] [blame] | 261 | bool isNewTexture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 262 | int left, int top, int width, int height, |
| 263 | GrPixelConfig dataConfig, |
| 264 | const void* data, |
| 265 | size_t rowBytes); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 266 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 267 | bool createRenderTargetObjects(int width, int height, |
| 268 | GrGLuint texID, |
| 269 | GrGLRenderTarget::Desc* desc); |
| 270 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 271 | GrGLContext fGLContext; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 272 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 273 | // GL program-related state |
| 274 | ProgramCache* fProgramCache; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 275 | SkAutoTUnref<GrGLProgram> fCurrentProgram; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 276 | |
| 277 | /////////////////////////////////////////////////////////////////////////// |
| 278 | ///@name Caching of GL State |
| 279 | ///@{ |
| 280 | int fHWActiveTextureUnitIdx; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 281 | GrGLuint fHWProgramID; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 282 | |
| 283 | GrGLProgram::SharedGLState fSharedGLProgramState; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 284 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 285 | enum TriState { |
| 286 | kNo_TriState, |
| 287 | kYes_TriState, |
| 288 | kUnknown_TriState |
| 289 | }; |
| 290 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 291 | // last scissor / viewport scissor state seen by the GL. |
| 292 | struct { |
| 293 | TriState fEnabled; |
| 294 | GrGLIRect fRect; |
| 295 | void invalidate() { |
| 296 | fEnabled = kUnknown_TriState; |
| 297 | fRect.invalidate(); |
| 298 | } |
| 299 | } fHWScissorSettings; |
| 300 | |
| 301 | GrGLIRect fHWViewport; |
| 302 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 303 | /** |
| 304 | * Tracks bound vertex and index buffers and vertex attrib array state. |
| 305 | */ |
| 306 | class HWGeometryState { |
| 307 | public: |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 308 | HWGeometryState() { fVBOVertexArray = NULL; this->invalidate(); } |
skia.committer@gmail.com | 754a3eb | 2013-03-08 07:01:25 +0000 | [diff] [blame] | 309 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 310 | ~HWGeometryState() { SkSafeUnref(fVBOVertexArray); } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 311 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 312 | void invalidate() { |
| 313 | fBoundVertexArrayIDIsValid = false; |
| 314 | fBoundVertexBufferIDIsValid = false; |
| 315 | fDefaultVertexArrayBoundIndexBufferID = false; |
| 316 | fDefaultVertexArrayBoundIndexBufferIDIsValid = false; |
| 317 | fDefaultVertexArrayAttribState.invalidate(); |
commit-bot@chromium.org | ce6da4d | 2013-09-09 14:55:37 +0000 | [diff] [blame] | 318 | if (NULL != fVBOVertexArray) { |
| 319 | fVBOVertexArray->invalidateCachedState(); |
| 320 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void notifyVertexArrayDelete(GrGLuint id) { |
| 324 | if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) { |
| 325 | // Does implicit bind to 0 |
| 326 | fBoundVertexArrayID = 0; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 330 | void setVertexArrayID(GrGpuGL* gpu, GrGLuint arrayID) { |
| 331 | if (!gpu->glCaps().vertexArrayObjectSupport()) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 332 | SkASSERT(0 == arrayID); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 333 | return; |
| 334 | } |
| 335 | if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) { |
| 336 | GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID)); |
| 337 | fBoundVertexArrayIDIsValid = true; |
| 338 | fBoundVertexArrayID = arrayID; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 342 | void notifyVertexBufferDelete(GrGLuint id) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 343 | if (fBoundVertexBufferIDIsValid && id == fBoundVertexBufferID) { |
| 344 | fBoundVertexBufferID = 0; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 345 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 346 | if (NULL != fVBOVertexArray) { |
| 347 | fVBOVertexArray->notifyVertexBufferDelete(id); |
| 348 | } |
| 349 | fDefaultVertexArrayAttribState.notifyVertexBufferDelete(id); |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 350 | } |
| 351 | |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 352 | void notifyIndexBufferDelete(GrGLuint id) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 353 | if (fDefaultVertexArrayBoundIndexBufferIDIsValid && |
| 354 | id == fDefaultVertexArrayBoundIndexBufferID) { |
| 355 | fDefaultVertexArrayBoundIndexBufferID = 0; |
| 356 | } |
| 357 | if (NULL != fVBOVertexArray) { |
| 358 | fVBOVertexArray->notifyIndexBufferDelete(id); |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 362 | void setVertexBufferID(GrGpuGL* gpu, GrGLuint id) { |
| 363 | if (!fBoundVertexBufferIDIsValid || id != fBoundVertexBufferID) { |
| 364 | GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ARRAY_BUFFER, id)); |
| 365 | fBoundVertexBufferIDIsValid = true; |
| 366 | fBoundVertexBufferID = id; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 370 | /** |
| 371 | * Binds the default vertex array and binds the index buffer. This is used when binding |
| 372 | * an index buffer in order to update it. |
| 373 | */ |
| 374 | void setIndexBufferIDOnDefaultVertexArray(GrGpuGL* gpu, GrGLuint id) { |
| 375 | this->setVertexArrayID(gpu, 0); |
| 376 | if (!fDefaultVertexArrayBoundIndexBufferIDIsValid || |
| 377 | id != fDefaultVertexArrayBoundIndexBufferID) { |
| 378 | GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id)); |
| 379 | fDefaultVertexArrayBoundIndexBufferIDIsValid = true; |
| 380 | fDefaultVertexArrayBoundIndexBufferID = id; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Binds the vertex array object that should be used to render from the vertex buffer. |
| 386 | * The vertex array is bound and its attrib array state object is returned. The vertex |
| 387 | * 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] | 388 | * returned GrGLAttribArrayState should be used to set vertex attribute arrays. |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 389 | */ |
| 390 | GrGLAttribArrayState* bindArrayAndBuffersToDraw(GrGpuGL* gpu, |
| 391 | const GrGLVertexBuffer* vbuffer, |
| 392 | const GrGLIndexBuffer* ibuffer); |
| 393 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 394 | private: |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 395 | GrGLuint fBoundVertexArrayID; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 396 | GrGLuint fBoundVertexBufferID; |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 397 | bool fBoundVertexArrayIDIsValid; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 398 | bool fBoundVertexBufferIDIsValid; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 399 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 400 | GrGLuint fDefaultVertexArrayBoundIndexBufferID; |
| 401 | bool fDefaultVertexArrayBoundIndexBufferIDIsValid; |
| 402 | // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0 |
| 403 | // is bound. However, this class is internal to GrGpuGL and this object never leaks out of |
| 404 | // GrGpuGL. |
| 405 | GrGLAttribArrayState fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 406 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 407 | // This is used when we're using a core profile and the vertices are in a VBO. |
| 408 | GrGLVertexArray* fVBOVertexArray; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 409 | } fHWGeometryState; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 410 | |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 411 | struct { |
| 412 | GrBlendCoeff fSrcCoeff; |
| 413 | GrBlendCoeff fDstCoeff; |
| 414 | GrColor fConstColor; |
| 415 | bool fConstColorValid; |
| 416 | TriState fEnabled; |
| 417 | |
| 418 | void invalidate() { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 419 | fSrcCoeff = kInvalid_GrBlendCoeff; |
| 420 | fDstCoeff = kInvalid_GrBlendCoeff; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 421 | fConstColorValid = false; |
| 422 | fEnabled = kUnknown_TriState; |
| 423 | } |
| 424 | } fHWBlendState; |
| 425 | |
bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 426 | struct { |
| 427 | TriState fMSAAEnabled; |
| 428 | TriState fSmoothLineEnabled; |
| 429 | void invalidate() { |
| 430 | fMSAAEnabled = kUnknown_TriState; |
| 431 | fSmoothLineEnabled = kUnknown_TriState; |
| 432 | } |
| 433 | } fHWAAState; |
| 434 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 435 | |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 436 | GrGLProgram::MatrixState fHWProjectionMatrixState; |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 437 | |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 438 | GrStencilSettings fHWStencilSettings; |
| 439 | TriState fHWStencilTestEnabled; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 440 | GrStencilSettings fHWPathStencilSettings; |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 441 | |
| 442 | GrDrawState::DrawFace fHWDrawFace; |
| 443 | TriState fHWWriteToColor; |
| 444 | TriState fHWDitherEnabled; |
| 445 | GrRenderTarget* fHWBoundRenderTarget; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 446 | SkTArray<GrTexture*, true> fHWBoundTextures; |
commit-bot@chromium.org | 6b30e45 | 2013-10-04 20:02:53 +0000 | [diff] [blame] | 447 | |
| 448 | struct TexGenData { |
| 449 | GrGLenum fMode; |
| 450 | GrGLint fNumComponents; |
| 451 | GrGLfloat fCoefficients[3 * 3]; |
| 452 | }; |
| 453 | int fHWActiveTexGenSets; |
| 454 | SkTArray<TexGenData, true> fHWTexGenSettings; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 455 | ///@} |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 456 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 457 | // we record what stencil format worked last time to hopefully exit early |
| 458 | // from our loop that tries stencil formats and calls check fb status. |
| 459 | int fLastSuccessfulStencilFmtIdx; |
| 460 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 461 | typedef GrGpu INHERITED; |
| 462 | }; |
| 463 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 464 | #endif |