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