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 | |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 8 | #ifndef GrGLGpu_DEFINED |
| 9 | #define GrGLGpu_DEFINED |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 11 | #include "GrGLContext.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 12 | #include "GrGLIRect.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 13 | #include "GrGLPathRendering.h" |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 14 | #include "GrGLProgram.h" |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 15 | #include "GrGLRenderTarget.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 16 | #include "GrGLStencilAttachment.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 17 | #include "GrGLTexture.h" |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 18 | #include "GrGLVertexArray.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 19 | #include "GrGpu.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 20 | #include "GrPipelineBuilder.h" |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 21 | #include "GrTypes.h" |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 22 | #include "GrXferProcessor.h" |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 23 | #include "SkTArray.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 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 26 | class GrGLBuffer; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 27 | class GrPipeline; |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 28 | class GrNonInstancedMesh; |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 29 | class GrSwizzle; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 30 | |
djsollen | efe46d2 | 2016-04-29 06:41:35 -0700 | [diff] [blame] | 31 | #ifdef SK_DEBUG |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 32 | #define PROGRAM_CACHE_STATS |
| 33 | #endif |
| 34 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 35 | class GrGLGpu final : public GrGpu { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 36 | public: |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 37 | static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options, |
| 38 | GrContext* context); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 39 | ~GrGLGpu() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 41 | void disconnect(DisconnectType) override; |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 42 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 43 | const GrGLContext& glContext() const { return *fGLContext; } |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 44 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 45 | const GrGLInterface* glInterface() const { return fGLContext->interface(); } |
| 46 | const GrGLContextInfo& ctxInfo() const { return *fGLContext; } |
| 47 | GrGLStandard glStandard() const { return fGLContext->standard(); } |
| 48 | GrGLVersion glVersion() const { return fGLContext->version(); } |
| 49 | GrGLSLGeneration glslGeneration() const { return fGLContext->glslGeneration(); } |
| 50 | const GrGLCaps& glCaps() const { return *fGLContext->caps(); } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 51 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 52 | GrGLPathRendering* glPathRendering() { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 53 | SkASSERT(glCaps().shaderCaps()->pathRenderingSupport()); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 54 | return static_cast<GrGLPathRendering*>(pathRendering()); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 55 | } |
| 56 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 57 | void discard(GrRenderTarget*) override; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 58 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 59 | // Used by GrGLProgram to configure OpenGL state. |
brianosman | a167e74 | 2016-05-24 06:18:48 -0700 | [diff] [blame^] | 60 | void bindTexture(int unitIdx, const GrTextureParams& params, bool allowSRGBInputs, |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 61 | GrGLTexture* texture); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 62 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 63 | void bindTexelBuffer(int unitIdx, intptr_t offsetInBytes, GrPixelConfig, GrGLBuffer*); |
| 64 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 65 | bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes, |
| 66 | GrPixelConfig readConfig, DrawPreference*, |
| 67 | ReadPixelTempDrawInfo*) override; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 68 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 69 | bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
cblume | ed82800 | 2016-02-16 13:00:01 -0800 | [diff] [blame] | 70 | GrPixelConfig srcConfig, DrawPreference*, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 71 | WritePixelTempDrawInfo*) override; |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 72 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 73 | bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const override; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 74 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 75 | // 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] | 76 | // 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] | 77 | void bindVertexArray(GrGLuint id) { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 78 | fHWVertexArrayState.setVertexArrayID(this, id); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | // These callbacks update state tracking when GL objects are deleted. They are called from |
| 82 | // GrGLResource onRelease functions. |
| 83 | void notifyVertexArrayDelete(GrGLuint id) { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 84 | fHWVertexArrayState.notifyVertexArrayDelete(id); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 85 | } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 86 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 87 | // Binds a buffer to the GL target corresponding to 'type', updates internal state tracking, and |
| 88 | // returns the GL target the buffer was bound to. |
| 89 | // When 'type' is kIndex_GrBufferType, this function will also implicitly bind the default VAO. |
| 90 | // If the caller wishes to bind an index buffer to a specific VAO, it can call glBind directly. |
| 91 | GrGLenum bindBuffer(GrBufferType type, const GrGLBuffer*); |
joshualitt | 93316b9 | 2015-10-23 09:08:08 -0700 | [diff] [blame] | 92 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 93 | // Called by GrGLBuffer after its buffer object has been destroyed. |
| 94 | void notifyBufferReleased(const GrGLBuffer*); |
| 95 | |
reed | f9ad558 | 2015-06-25 21:29:25 -0700 | [diff] [blame] | 96 | const GrGLContext* glContextForTesting() const override { |
| 97 | return &this->glContext(); |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 98 | } |
| 99 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 100 | void clearStencil(GrRenderTarget*) override; |
| 101 | |
| 102 | void invalidateBoundRenderTarget() { |
| 103 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 104 | } |
| 105 | |
| 106 | GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget* rt, |
| 107 | int width, |
| 108 | int height) override; |
| 109 | |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 110 | GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 111 | GrPixelConfig config) override; |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 112 | bool isTestingOnlyBackendTexture(GrBackendObject) const override; |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 113 | void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override; |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 114 | |
joshualitt | 8fd844f | 2015-12-02 13:36:47 -0800 | [diff] [blame] | 115 | void resetShaderCacheForTesting() const override; |
| 116 | |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 117 | void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override; |
| 118 | |
jvanverth | d2d2eb9 | 2016-02-17 14:04:46 -0800 | [diff] [blame] | 119 | void finishDrawTarget() override; |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 120 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 121 | private: |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 122 | GrGLGpu(GrGLContext* ctx, GrContext* context); |
| 123 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 124 | // GrGpu overrides |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 125 | void onResetContext(uint32_t resetBits) override; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 126 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 127 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override; |
| 128 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 129 | GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 130 | const SkTArray<GrMipLevel>& texels) override; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 131 | GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 132 | SkBudgeted budgeted, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 133 | const SkTArray<GrMipLevel>& texels) override; |
| 134 | |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 135 | GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, |
| 136 | const void* data) override; |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 137 | GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; |
| 138 | GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, |
| 139 | GrWrapOwnership) override; |
kkinnunen | 49c4c22 | 2016-04-01 04:50:37 -0700 | [diff] [blame] | 140 | GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 141 | // Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a |
bsalomon | 62a627b | 2015-12-17 09:50:47 -0800 | [diff] [blame] | 142 | // compatible stencil format, or negative if there is no compatible stencil format. |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 143 | int getCompatibleStencilIndex(GrPixelConfig config); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 144 | |
bsalomon | 7e68ab7 | 2016-04-13 14:29:25 -0700 | [diff] [blame] | 145 | |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 146 | // Returns whether the texture is successfully created. On success, the |
| 147 | // result is stored in |info|. |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 148 | // The texture is populated with |texels|, if it exists. |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 149 | // The texture parameters are cached in |initialTexParams|. |
| 150 | bool createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 151 | bool renderTarget, GrGLTexture::TexParams* initialTexParams, |
| 152 | const SkTArray<GrMipLevel>& texels); |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 153 | |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 154 | void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 155 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 156 | void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override; |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 157 | |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame] | 158 | bool onMakeCopyForTextureParams(GrTexture*, const GrTextureParams&, |
| 159 | GrTextureProducer::CopyParams*) const override; |
| 160 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 161 | // Checks whether glReadPixels can be called to get pixel values in readConfig from the |
| 162 | // render target. |
| 163 | bool readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConfig); |
| 164 | |
| 165 | // Checks whether glReadPixels can be called to get pixel values in readConfig from a |
| 166 | // render target that has renderTargetConfig. This may have to create a temporary |
| 167 | // render target and thus is less preferable than the variant that takes a render target. |
| 168 | bool readPixelsSupported(GrPixelConfig renderTargetConfig, GrPixelConfig readConfig); |
| 169 | |
| 170 | // Checks whether glReadPixels can be called to get pixel values in readConfig from a |
| 171 | // render target that has the same config as surfaceForConfig. Calls one of the the two |
| 172 | // variations above, depending on whether the surface is a render target or not. |
| 173 | bool readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig readConfig); |
| 174 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 175 | bool onReadPixels(GrSurface*, |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 176 | int left, int top, |
| 177 | int width, int height, |
| 178 | GrPixelConfig, |
| 179 | void* buffer, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 180 | size_t rowBytes) override; |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 181 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 182 | bool onWritePixels(GrSurface*, |
| 183 | int left, int top, int width, int height, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 184 | GrPixelConfig config, |
| 185 | const SkTArray<GrMipLevel>& texels) override; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 186 | |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 187 | bool onTransferPixels(GrSurface*, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 188 | int left, int top, int width, int height, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 189 | GrPixelConfig config, GrBuffer* transferBuffer, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 190 | size_t offset, size_t rowBytes) override; |
| 191 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 192 | void onResolveRenderTarget(GrRenderTarget* target) override; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 193 | |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 194 | void onDraw(const GrPipeline&, |
| 195 | const GrPrimitiveProcessor&, |
| 196 | const GrMesh*, |
| 197 | int meshCount) override; |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 198 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 199 | bool onCopySurface(GrSurface* dst, |
| 200 | GrSurface* src, |
| 201 | const SkIRect& srcRect, |
| 202 | const SkIPoint& dstPoint) override; |
| 203 | |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 204 | void onGetMultisampleSpecs(GrRenderTarget*, |
| 205 | const GrStencilSettings&, |
| 206 | int* effectiveSampleCnt, |
| 207 | SkAutoTDeleteArray<SkPoint>* sampleLocations) override; |
| 208 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 209 | // binds texture unit in GL |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 210 | void setTextureUnit(int unitIdx); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 211 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 212 | void setTextureSwizzle(int unitIdx, GrGLenum target, const GrGLenum swizzle[]); |
| 213 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 214 | // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set. |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 215 | bool flushGLState(const GrPipeline& pipeline, const GrPrimitiveProcessor& primProc); |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 216 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 217 | // Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 218 | // an into the index buffer. It does not account for vertices.startIndex() but rather the start |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 219 | // index is relative to the returned offset. |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 220 | void setupGeometry(const GrPrimitiveProcessor&, |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 221 | const GrNonInstancedMesh& mesh, |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 222 | size_t* indexOffsetInBytes); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 223 | |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 224 | void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 225 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 226 | bool hasExtension(const char* ext) const { return fGLContext->hasExtension(ext); } |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 227 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 228 | bool copySurfaceAsDraw(GrSurface* dst, |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 229 | GrSurface* src, |
| 230 | const SkIRect& srcRect, |
| 231 | const SkIPoint& dstPoint); |
| 232 | void copySurfaceAsCopyTexSubImage(GrSurface* dst, |
| 233 | GrSurface* src, |
| 234 | const SkIRect& srcRect, |
| 235 | const SkIPoint& dstPoint); |
| 236 | bool copySurfaceAsBlitFramebuffer(GrSurface* dst, |
| 237 | GrSurface* src, |
| 238 | const SkIRect& srcRect, |
| 239 | const SkIPoint& dstPoint); |
| 240 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 241 | void stampPLSSetupRect(const SkRect& bounds); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 242 | |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 243 | void setupPixelLocalStorage(const GrPipeline&, const GrPrimitiveProcessor&); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 244 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 245 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 246 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 247 | class ProgramCache : public ::SkNoncopyable { |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 248 | public: |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 249 | ProgramCache(GrGLGpu* gpu); |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 250 | ~ProgramCache(); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 251 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 252 | void abandon(); |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 253 | GrGLProgram* refProgram(const GrGLGpu* gpu, const GrPipeline&, const GrPrimitiveProcessor&); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 254 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 255 | private: |
| 256 | enum { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 257 | // We may actually have kMaxEntries+1 shaders in the GL context because we create a new |
| 258 | // shader before evicting from the cache. |
commit-bot@chromium.org | b556422 | 2014-03-28 15:52:18 +0000 | [diff] [blame] | 259 | kMaxEntries = 128, |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 260 | kHashBits = 6, |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 261 | }; |
| 262 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 263 | struct Entry; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 264 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 265 | struct ProgDescLess; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 266 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 267 | // binary search for entry matching desc. returns index into fEntries that matches desc or ~ |
| 268 | // of the index of where it should be inserted. |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 269 | int search(const GrProgramDesc& desc) const; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 270 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 271 | // sorted array of all the entries |
| 272 | Entry* fEntries[kMaxEntries]; |
| 273 | // hash table based on lowest kHashBits bits of the program key. Used to avoid binary |
| 274 | // searching fEntries. |
| 275 | Entry* fHashTable[1 << kHashBits]; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 276 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 277 | int fCount; |
| 278 | unsigned int fCurrLRUStamp; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 279 | GrGLGpu* fGpu; |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 280 | #ifdef PROGRAM_CACHE_STATS |
| 281 | int fTotalRequests; |
| 282 | int fCacheMisses; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 283 | int fHashMisses; // cache hit but hash table missed |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 284 | #endif |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 285 | }; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 286 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 287 | void flushColorWrite(bool writeColor); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 288 | void flushDrawFace(GrPipelineBuilder::DrawFace face); |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 289 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 290 | // flushes the scissor. see the note on flushBoundTextureAndParams about |
| 291 | // flushing the scissor after that function is called. |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 292 | void flushScissor(const GrScissorState&, |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 293 | const GrGLIRect& rtViewport, |
| 294 | GrSurfaceOrigin rtOrigin); |
| 295 | |
| 296 | // disables the scissor |
| 297 | void disableScissor(); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 298 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 299 | void initFSAASupport(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 300 | |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 301 | // determines valid stencil formats |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 302 | void initStencilFormats(); |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 303 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 304 | // sets a texture unit to use for texture operations other than binding a texture to a program. |
| 305 | // ensures that such operations don't negatively interact with tracking bound textures. |
| 306 | void setScratchTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 307 | |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 308 | // bounds is region that may be modified. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 309 | // nullptr means whole target. Can be an empty rect. |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 310 | void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds, bool disableSRGB = false); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 311 | |
| 312 | // Need not be called if flushRenderTarget is used. |
| 313 | void flushViewport(const GrGLIRect&); |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 314 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 315 | void flushStencil(const GrStencilSettings&); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 316 | |
| 317 | // rt is used only if useHWAA is true. |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 318 | void flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabled); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 319 | |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 320 | void flushMinSampleShading(float minSampleShading); |
| 321 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 322 | // helper for onCreateTexture and writeTexturePixels |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 323 | enum UploadType { |
| 324 | kNewTexture_UploadType, // we are creating a new texture |
| 325 | kWrite_UploadType, // we are using TexSubImage2D to copy data to an existing texture |
| 326 | kTransfer_UploadType, // we are using a transfer buffer to copy data |
| 327 | }; |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 328 | bool uploadTexData(const GrSurfaceDesc& desc, |
jcgregorio | e7d7f90 | 2016-02-04 19:51:25 -0800 | [diff] [blame] | 329 | GrGLenum target, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 330 | UploadType uploadType, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 331 | int left, int top, int width, int height, |
| 332 | GrPixelConfig dataConfig, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 333 | const SkTArray<GrMipLevel>& texels); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 334 | |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 335 | // helper for onCreateCompressedTexture. If width and height are |
| 336 | // set to -1, then this function will use desc.fWidth and desc.fHeight |
| 337 | // for the size of the data. The isNewTexture flag should be set to true |
| 338 | // whenever a new texture needs to be created. Otherwise, we assume that |
| 339 | // the texture is already in GPU memory and that it's going to be updated |
| 340 | // with new data. |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 341 | bool uploadCompressedTexData(const GrSurfaceDesc& desc, |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 342 | GrGLenum target, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 343 | const SkTArray<GrMipLevel>& texels, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 344 | UploadType uploadType = kNewTexture_UploadType, |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 345 | int left = 0, int top = 0, |
| 346 | int width = -1, int height = -1); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 347 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 348 | bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo, |
| 349 | GrGLRenderTarget::IDDesc*); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 350 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 351 | enum TempFBOTarget { |
| 352 | kSrc_TempFBOTarget, |
| 353 | kDst_TempFBOTarget |
| 354 | }; |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 355 | |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 356 | // Binds a surface as a FBO for a copy operation. If the surface already owns an FBO ID then |
| 357 | // that ID is bound. If not the surface is temporarily bound to a FBO and that FBO is bound. |
| 358 | // This must be paired with a call to unbindSurfaceFBOForCopy(). |
| 359 | void bindSurfaceFBOForCopy(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport, |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 360 | TempFBOTarget tempFBOTarget); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 361 | |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 362 | // Must be called if bindSurfaceFBOForCopy was used to bind a surface for copying. |
| 363 | void unbindTextureFBOForCopy(GrGLenum fboTarget, GrSurface* surface); |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 364 | |
reed | f9ad558 | 2015-06-25 21:29:25 -0700 | [diff] [blame] | 365 | SkAutoTUnref<GrGLContext> fGLContext; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 366 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 367 | bool createCopyProgram(int progIdx); |
| 368 | bool createWireRectProgram(); |
| 369 | bool createPLSSetupProgram(); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 370 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 371 | // GL program-related state |
| 372 | ProgramCache* fProgramCache; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 373 | |
| 374 | /////////////////////////////////////////////////////////////////////////// |
| 375 | ///@name Caching of GL State |
| 376 | ///@{ |
| 377 | int fHWActiveTextureUnitIdx; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 378 | GrGLuint fHWProgramID; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 379 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 380 | enum TriState { |
| 381 | kNo_TriState, |
| 382 | kYes_TriState, |
| 383 | kUnknown_TriState |
| 384 | }; |
| 385 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 386 | GrGLuint fTempSrcFBOID; |
| 387 | GrGLuint fTempDstFBOID; |
| 388 | |
| 389 | GrGLuint fStencilClearFBOID; |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 390 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 391 | // last scissor / viewport scissor state seen by the GL. |
| 392 | struct { |
| 393 | TriState fEnabled; |
| 394 | GrGLIRect fRect; |
| 395 | void invalidate() { |
| 396 | fEnabled = kUnknown_TriState; |
| 397 | fRect.invalidate(); |
| 398 | } |
| 399 | } fHWScissorSettings; |
| 400 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 401 | GrGLIRect fHWViewport; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 402 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 403 | /** |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 404 | * Tracks vertex attrib array state. |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 405 | */ |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 406 | class HWVertexArrayState { |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 407 | public: |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 408 | HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); } |
skia.committer@gmail.com | 754a3eb | 2013-03-08 07:01:25 +0000 | [diff] [blame] | 409 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 410 | ~HWVertexArrayState() { delete fCoreProfileVertexArray; } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 411 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 412 | void invalidate() { |
| 413 | fBoundVertexArrayIDIsValid = false; |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 414 | fDefaultVertexArrayAttribState.invalidate(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 415 | if (fCoreProfileVertexArray) { |
| 416 | fCoreProfileVertexArray->invalidateCachedState(); |
commit-bot@chromium.org | ce6da4d | 2013-09-09 14:55:37 +0000 | [diff] [blame] | 417 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void notifyVertexArrayDelete(GrGLuint id) { |
| 421 | if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) { |
| 422 | // Does implicit bind to 0 |
| 423 | fBoundVertexArrayID = 0; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 427 | void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 428 | if (!gpu->glCaps().vertexArrayObjectSupport()) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 429 | SkASSERT(0 == arrayID); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 430 | return; |
| 431 | } |
| 432 | if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) { |
| 433 | GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID)); |
| 434 | fBoundVertexArrayIDIsValid = true; |
| 435 | fBoundVertexArrayID = arrayID; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 439 | /** |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 440 | * Binds the vertex array that should be used for internal draws, and returns its attrib |
| 441 | * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which |
| 442 | * case we use a dummy array instead. |
| 443 | * |
| 444 | * If an index buffer is privided, it will be bound to the vertex array. Otherwise the |
| 445 | * index buffer binding will be left unchanged. |
| 446 | * |
| 447 | * The returned GrGLAttribArrayState should be used to set vertex attribute arrays. |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 448 | */ |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 449 | GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrGLBuffer* ibuff = nullptr); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 450 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 451 | private: |
mtklein | 044d3c1 | 2016-04-06 18:24:34 -0700 | [diff] [blame] | 452 | GrGLuint fBoundVertexArrayID; |
mtklein | 044d3c1 | 2016-04-06 18:24:34 -0700 | [diff] [blame] | 453 | bool fBoundVertexArrayIDIsValid; |
mtklein | 044d3c1 | 2016-04-06 18:24:34 -0700 | [diff] [blame] | 454 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 455 | // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0 |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 456 | // is bound. However, this class is internal to GrGLGpu and this object never leaks out of |
| 457 | // GrGLGpu. |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 458 | GrGLAttribArrayState fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 459 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 460 | // This is used when we're using a core profile. |
| 461 | GrGLVertexArray* fCoreProfileVertexArray; |
| 462 | } fHWVertexArrayState; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 463 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 464 | struct { |
| 465 | GrGLenum fGLTarget; |
| 466 | uint32_t fBoundBufferUniqueID; |
| 467 | bool fBufferZeroKnownBound; |
| 468 | |
| 469 | void invalidate() { |
| 470 | fBoundBufferUniqueID = SK_InvalidUniqueID; |
| 471 | fBufferZeroKnownBound = false; |
| 472 | } |
| 473 | } fHWBufferState[kGrBufferTypeCount]; |
cdalton | c161310 | 2016-03-16 07:48:20 -0700 | [diff] [blame] | 474 | |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 475 | struct { |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 476 | GrBlendEquation fEquation; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 477 | GrBlendCoeff fSrcCoeff; |
| 478 | GrBlendCoeff fDstCoeff; |
| 479 | GrColor fConstColor; |
| 480 | bool fConstColorValid; |
| 481 | TriState fEnabled; |
| 482 | |
| 483 | void invalidate() { |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 484 | fEquation = static_cast<GrBlendEquation>(-1); |
| 485 | fSrcCoeff = static_cast<GrBlendCoeff>(-1); |
| 486 | fDstCoeff = static_cast<GrBlendCoeff>(-1); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 487 | fConstColorValid = false; |
| 488 | fEnabled = kUnknown_TriState; |
| 489 | } |
| 490 | } fHWBlendState; |
| 491 | |
bsalomon | 54c6fe8 | 2015-12-16 11:51:22 -0800 | [diff] [blame] | 492 | TriState fMSAAEnabled; |
| 493 | |
| 494 | GrStencilSettings fHWStencilSettings; |
| 495 | TriState fHWStencilTestEnabled; |
| 496 | |
| 497 | |
| 498 | GrPipelineBuilder::DrawFace fHWDrawFace; |
| 499 | TriState fHWWriteToColor; |
| 500 | uint32_t fHWBoundRenderTargetUniqueID; |
| 501 | TriState fHWSRGBFramebuffer; |
| 502 | SkTArray<uint32_t, true> fHWBoundTextureUniqueIDs; |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 503 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 504 | struct BufferTexture { |
| 505 | BufferTexture() : fTextureID(0), fKnownBound(false), |
| 506 | fAttachedBufferUniqueID(SK_InvalidUniqueID), |
| 507 | fSwizzle(GrSwizzle::RGBA()) {} |
| 508 | |
| 509 | GrGLuint fTextureID; |
| 510 | bool fKnownBound; |
| 511 | intptr_t fOffsetInBytes; |
| 512 | GrPixelConfig fTexelConfig; |
| 513 | size_t fAttachedSizeInBytes; |
| 514 | uint32_t fAttachedBufferUniqueID; |
| 515 | GrSwizzle fSwizzle; |
| 516 | }; |
| 517 | |
| 518 | SkTArray<BufferTexture, true> fHWBufferTextures; |
| 519 | int fHWMaxUsedBufferTextureUnit; |
| 520 | |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 521 | // EXT_raster_multisample. |
| 522 | TriState fHWRasterMultisampleEnabled; |
| 523 | int fHWNumRasterSamples; |
bsalomon | 54c6fe8 | 2015-12-16 11:51:22 -0800 | [diff] [blame] | 524 | ///@} |
| 525 | |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 526 | /** IDs for copy surface program. */ |
| 527 | struct { |
| 528 | GrGLuint fProgram; |
| 529 | GrGLint fTextureUniform; |
| 530 | GrGLint fTexCoordXformUniform; |
| 531 | GrGLint fPosXformUniform; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 532 | } fCopyPrograms[3]; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 533 | SkAutoTUnref<GrGLBuffer> fCopyProgramArrayBuffer; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 534 | |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 535 | struct { |
| 536 | GrGLuint fProgram; |
| 537 | GrGLint fColorUniform; |
| 538 | GrGLint fRectUniform; |
| 539 | } fWireRectProgram; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 540 | SkAutoTUnref<GrGLBuffer> fWireRectArrayBuffer; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 541 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 542 | static int TextureTargetToCopyProgramIdx(GrGLenum target) { |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 543 | switch (target) { |
| 544 | case GR_GL_TEXTURE_2D: |
| 545 | return 0; |
| 546 | case GR_GL_TEXTURE_EXTERNAL: |
| 547 | return 1; |
| 548 | case GR_GL_TEXTURE_RECTANGLE: |
| 549 | return 2; |
| 550 | default: |
| 551 | SkFAIL("Unexpected texture target type."); |
| 552 | return 0; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 553 | } |
| 554 | } |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 555 | |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 556 | struct { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 557 | GrGLuint fProgram; |
| 558 | GrGLint fPosXformUniform; |
| 559 | SkAutoTUnref<GrGLBuffer> fArrayBuffer; |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 560 | } fPLSSetupProgram; |
| 561 | |
| 562 | bool fHWPLSEnabled; |
| 563 | bool fPLSHasBeenUsed; |
| 564 | |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 565 | float fHWMinSampleShading; |
| 566 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 567 | typedef GrGpu INHERITED; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 568 | friend class GrGLPathRendering; // For accessing setTextureUnit. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 569 | }; |
| 570 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 571 | #endif |