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