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