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