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