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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkTypes.h" |
| 12 | #include "include/private/SkTArray.h" |
| 13 | #include "src/core/SkLRUCache.h" |
Stephen White | b353c9b | 2020-04-16 14:14:13 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrFinishCallbacks.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrGpu.h" |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 16 | #include "src/gpu/GrNativeRect.h" |
Robert Phillips | 03e4c95 | 2019-11-26 16:20:22 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrProgramDesc.h" |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 18 | #include "src/gpu/GrThreadSafePipelineBuilder.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrWindowRectsState.h" |
| 20 | #include "src/gpu/GrXferProcessor.h" |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 21 | #include "src/gpu/gl/GrGLAttachment.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "src/gpu/gl/GrGLContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/gl/GrGLProgram.h" |
| 24 | #include "src/gpu/gl/GrGLRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/gl/GrGLTexture.h" |
| 26 | #include "src/gpu/gl/GrGLVertexArray.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 28 | class GrGLBuffer; |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 29 | class GrGLOpsRenderPass; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 30 | class GrPipeline; |
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 | |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 33 | class GrGLGpu final : public GrGpu { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 34 | public: |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 35 | static sk_sp<GrGpu> Make(sk_sp<const GrGLInterface>, const GrContextOptions&, GrDirectContext*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 36 | ~GrGLGpu() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 37 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 38 | void disconnect(DisconnectType) override; |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 39 | |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 40 | GrThreadSafePipelineBuilder* pipelineBuilder() override; |
| 41 | sk_sp<GrThreadSafePipelineBuilder> refPipelineBuilder() override; |
| 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 | |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 45 | const GrGLInterface* glInterface() const { return fGLContext->glInterface(); } |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 46 | const GrGLContextInfo& ctxInfo() const { return *fGLContext; } |
| 47 | GrGLStandard glStandard() const { return fGLContext->standard(); } |
| 48 | GrGLVersion glVersion() const { return fGLContext->version(); } |
Jim Van Verth | d8a753a | 2021-11-17 17:34:43 -0500 | [diff] [blame] | 49 | SkSL::GLSLGeneration glslGeneration() const { return fGLContext->glslGeneration(); } |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 50 | const GrGLCaps& glCaps() const { return *fGLContext->caps(); } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 51 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 52 | // Used by GrGLProgram to configure OpenGL state. |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 53 | void bindTexture(int unitIdx, GrSamplerState samplerState, const GrSwizzle&, GrGLTexture*); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 54 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 55 | // 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] | 56 | // 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] | 57 | void bindVertexArray(GrGLuint id) { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 58 | fHWVertexArrayState.setVertexArrayID(this, id); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | // These callbacks update state tracking when GL objects are deleted. They are called from |
| 62 | // GrGLResource onRelease functions. |
| 63 | void notifyVertexArrayDelete(GrGLuint id) { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 64 | fHWVertexArrayState.notifyVertexArrayDelete(id); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 65 | } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 66 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 67 | // Binds a buffer to the GL target corresponding to 'type', updates internal state tracking, and |
| 68 | // returns the GL target the buffer was bound to. |
| 69 | // When 'type' is kIndex_GrBufferType, this function will also implicitly bind the default VAO. |
| 70 | // If the caller wishes to bind an index buffer to a specific VAO, it can call glBind directly. |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 71 | GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer*); |
joshualitt | 93316b9 | 2015-10-23 09:08:08 -0700 | [diff] [blame] | 72 | |
Chris Dalton | 20e7a53 | 2020-02-28 15:37:53 +0000 | [diff] [blame] | 73 | // Flushes state from GrProgramInfo to GL. Returns false if the state couldn't be set. |
Chris Dalton | b0fed1d | 2021-04-07 21:12:22 -0600 | [diff] [blame] | 74 | bool flushGLState(GrRenderTarget*, bool useMultisampleFBO, const GrProgramInfo&); |
Robert Phillips | edc5b4d | 2021-01-06 13:06:23 -0500 | [diff] [blame] | 75 | void flushScissorRect(const SkIRect& scissor, int rtHeight, GrSurfaceOrigin); |
| 76 | |
| 77 | // The flushRenderTarget methods will all set the initial viewport to the full extent of the |
| 78 | // backing render target. |
| 79 | void flushViewport(const SkIRect& viewport, int rtHeight, GrSurfaceOrigin); |
Chris Dalton | d42d200 | 2020-02-28 12:05:04 -0700 | [diff] [blame] | 80 | |
| 81 | // Returns the last program bound by flushGLState(), or nullptr if a different program has since |
| 82 | // been put into use via some other method (e.g., resetContext, copySurfaceAsDraw). |
| 83 | // The returned GrGLProgram can be used for binding textures and vertex attributes. |
| 84 | GrGLProgram* currentProgram() { |
| 85 | this->handleDirtyContext(); |
| 86 | return fHWProgram.get(); |
Chris Dalton | b67081f | 2020-02-27 15:13:56 -0700 | [diff] [blame] | 87 | } |
Chris Dalton | b67081f | 2020-02-27 15:13:56 -0700 | [diff] [blame] | 88 | |
Chris Dalton | d42d200 | 2020-02-28 12:05:04 -0700 | [diff] [blame] | 89 | // Binds the vertex array that should be used for internal draws, enables 'numAttribs' vertex |
| 90 | // arrays, and flushes the desired primitive restart settings. If an index buffer is provided, |
| 91 | // it will be bound to the vertex array. Otherwise the index buffer binding will be left |
| 92 | // unchanged. |
| 93 | // |
| 94 | // NOTE: This binds the default VAO (ID=zero) unless we are on a core profile, in which case we |
Kevin Lubick | be03ef1 | 2021-06-16 15:28:00 -0400 | [diff] [blame] | 95 | // use a placeholder array instead. |
Chris Dalton | d42d200 | 2020-02-28 12:05:04 -0700 | [diff] [blame] | 96 | GrGLAttribArrayState* bindInternalVertexArray(const GrBuffer* indexBuffer, int numAttribs, |
| 97 | GrPrimitiveRestart primitiveRestart) { |
| 98 | auto* attribState = fHWVertexArrayState.bindInternalVertexArray(this, indexBuffer); |
| 99 | attribState->enableVertexArrays(this, numAttribs, primitiveRestart); |
| 100 | return attribState; |
| 101 | } |
Chris Dalton | d42d200 | 2020-02-28 12:05:04 -0700 | [diff] [blame] | 102 | |
Chris Dalton | 0999bce | 2020-04-03 14:42:05 -0600 | [diff] [blame] | 103 | // Applies any necessary workarounds and returns the GL primitive type to use in draw calls. |
| 104 | GrGLenum prepareToDraw(GrPrimitiveType primitiveType); |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 105 | |
Brian Salomon | 4b4c7f8 | 2021-09-23 10:30:55 -0400 | [diff] [blame] | 106 | using ResolveDirection = GrGLRenderTarget::ResolveDirection; |
Chris Dalton | 710e1c9 | 2021-04-23 13:07:52 -0600 | [diff] [blame] | 107 | |
Chris Dalton | 88dd356 | 2021-07-20 11:32:58 -0600 | [diff] [blame] | 108 | // Resolves the render target's single sample FBO into the MSAA, or vice versa. |
| 109 | // If glCaps.framebufferResolvesMustBeFullSize() is true, resolveRect must be equal the render |
| 110 | // target's bounds rect. |
| 111 | // If blitting single to MSAA, glCaps.canResolveSingleToMSAA() must be true. |
Chris Dalton | 710e1c9 | 2021-04-23 13:07:52 -0600 | [diff] [blame] | 112 | void resolveRenderFBOs(GrGLRenderTarget*, const SkIRect& resolveRect, ResolveDirection, |
| 113 | bool invalidateReadBufferAfterBlit = false); |
| 114 | |
Chris Dalton | 88dd356 | 2021-07-20 11:32:58 -0600 | [diff] [blame] | 115 | // For loading a dynamic MSAA framebuffer when glCaps.canResolveSingleToMSAA() is false. |
| 116 | // NOTE: If glCaps.framebufferResolvesMustBeFullSize() is also true, the drawBounds should be |
| 117 | // equal to the proxy bounds. This is because the render pass will have to do a full size |
| 118 | // resolve back into the single sample FBO when rendering is complete. |
| 119 | void drawSingleIntoMSAAFBO(GrGLRenderTarget* rt, const SkIRect& drawBounds) { |
| 120 | this->copySurfaceAsDraw(rt, true/*drawToMultisampleFBO*/, rt, drawBounds, |
| 121 | drawBounds.topLeft()); |
| 122 | } |
| 123 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 124 | // The GrGLOpsRenderPass does not buffer up draws before submitting them to the gpu. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 125 | // Thus this is the implementation of the clear call for the corresponding passthrough function |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 126 | // on GrGLOpsRenderPass. |
Chris Dalton | b0fed1d | 2021-04-07 21:12:22 -0600 | [diff] [blame] | 127 | void clear(const GrScissorState&, std::array<float, 4> color, GrRenderTarget*, |
| 128 | bool useMultisampleFBO, GrSurfaceOrigin); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 129 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 130 | // The GrGLOpsRenderPass does not buffer up draws before submitting them to the gpu. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 131 | // Thus this is the implementation of the clearStencil call for the corresponding passthrough |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 132 | // function on GrGLOpsrenderPass. |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 133 | void clearStencilClip(const GrScissorState&, bool insideStencilMask, |
Chris Dalton | e0fe23a | 2021-04-23 13:11:44 -0600 | [diff] [blame] | 134 | GrRenderTarget*, bool useMultisampleFBO, GrSurfaceOrigin); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 135 | |
Chris Dalton | 710e1c9 | 2021-04-23 13:07:52 -0600 | [diff] [blame] | 136 | void beginCommandBuffer(GrGLRenderTarget*, bool useMultisampleFBO, |
Chris Dalton | b0fed1d | 2021-04-07 21:12:22 -0600 | [diff] [blame] | 137 | const SkIRect& bounds, GrSurfaceOrigin, |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 138 | const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore, |
| 139 | const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore); |
| 140 | |
Chris Dalton | 710e1c9 | 2021-04-23 13:07:52 -0600 | [diff] [blame] | 141 | void endCommandBuffer(GrGLRenderTarget*, bool useMultisampleFBO, |
Chris Dalton | b0fed1d | 2021-04-07 21:12:22 -0600 | [diff] [blame] | 142 | const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore, |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 143 | const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore); |
| 144 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 145 | void invalidateBoundRenderTarget() { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 146 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Chris Dalton | e0fe23a | 2021-04-23 13:11:44 -0600 | [diff] [blame] | 149 | sk_sp<GrAttachment> makeStencilAttachment(const GrBackendFormat& colorFormat, |
| 150 | SkISize dimensions, int numStencilSamples) override; |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 151 | |
| 152 | sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions, |
| 153 | const GrBackendFormat& format, |
| 154 | int numSamples, |
Jim Van Verth | 8d59fe0 | 2021-09-20 11:48:21 -0400 | [diff] [blame] | 155 | GrProtected isProtected, |
| 156 | GrMemoryless) override; |
Greg Daniel | 5d0330e | 2020-10-12 16:05:21 -0400 | [diff] [blame] | 157 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 158 | void deleteBackendTexture(const GrBackendTexture&) override; |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 159 | |
Robert Phillips | 3bce1f7 | 2020-05-12 12:41:58 -0400 | [diff] [blame] | 160 | bool compile(const GrProgramDesc&, const GrProgramInfo&) override; |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 161 | |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 162 | bool precompileShader(const SkData& key, const SkData& data) override { |
Robert Phillips | 962708f | 2021-03-03 14:42:04 -0500 | [diff] [blame] | 163 | return fProgramCache->precompileShader(this->getContext(), key, data); |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 166 | #if GR_TEST_UTILS |
| 167 | bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
Michael Ludwig | 8ad0cbd | 2019-05-15 19:32:01 +0000 | [diff] [blame] | 168 | |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 169 | GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions, |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 170 | GrColorType, |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 171 | int sampleCnt, |
| 172 | GrProtected) override; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 173 | void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
| 174 | |
| 175 | const GrGLContext* glContextForTesting() const override { return &this->glContext(); } |
| 176 | |
Brian Osman | 0b8bb88 | 2019-04-12 11:47:19 -0400 | [diff] [blame] | 177 | void resetShaderCacheForTesting() const override { fProgramCache->reset(); } |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 178 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 179 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 180 | void submit(GrOpsRenderPass* renderPass) override; |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 181 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 182 | GrFence SK_WARN_UNUSED_RESULT insertFence() override; |
Stephen White | b353c9b | 2020-04-16 14:14:13 -0400 | [diff] [blame] | 183 | bool waitFence(GrFence) override; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 184 | void deleteFence(GrFence) const override; |
| 185 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 186 | std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override; |
Robert Phillips | 1a82a4e | 2021-07-01 10:27:44 -0400 | [diff] [blame] | 187 | std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore&, |
| 188 | GrSemaphoreWrapType, |
| 189 | GrWrapOwnership) override; |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 190 | void insertSemaphore(GrSemaphore* semaphore) override; |
| 191 | void waitSemaphore(GrSemaphore* semaphore) override; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 192 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 193 | void checkFinishProcs() override; |
Greg Daniel | a89b430 | 2021-01-29 10:48:40 -0500 | [diff] [blame] | 194 | void finishOutstandingGpuWork() override; |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 195 | |
Brian Salomon | 24069eb | 2020-06-24 10:19:52 -0400 | [diff] [blame] | 196 | // Calls glGetError() until no errors are reported. Also looks for OOMs. |
| 197 | void clearErrorsAndCheckForOOM(); |
| 198 | // Calls glGetError() once and returns the result. Also looks for an OOM. |
| 199 | GrGLenum getErrorAndCheckForOOM(); |
| 200 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 201 | std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override; |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 202 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 203 | void deleteSync(GrGLsync) const; |
| 204 | |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 205 | void bindFramebuffer(GrGLenum fboTarget, GrGLuint fboid); |
| 206 | void deleteFramebuffer(GrGLuint fboid); |
Adrienne Walker | 3ed3399 | 2018-05-15 11:44:34 -0700 | [diff] [blame] | 207 | |
Chris Dalton | e1196c5 | 2019-12-28 14:31:09 -0700 | [diff] [blame] | 208 | void insertManualFramebufferBarrier() override; |
| 209 | |
Robert Phillips | df546db | 2020-05-29 09:42:54 -0400 | [diff] [blame] | 210 | void flushProgram(sk_sp<GrGLProgram>); |
| 211 | |
| 212 | // Version for programs that aren't GrGLProgram. |
| 213 | void flushProgram(GrGLuint); |
| 214 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 215 | private: |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 216 | GrGLGpu(std::unique_ptr<GrGLContext>, GrDirectContext*); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 217 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 218 | // GrGpu overrides |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 219 | GrBackendTexture onCreateBackendTexture(SkISize dimensions, |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 220 | const GrBackendFormat&, |
| 221 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 222 | GrMipmapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 223 | GrProtected) override; |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 224 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 225 | GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, |
| 226 | const GrBackendFormat&, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 227 | GrMipmapped, |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 228 | GrProtected) override; |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 229 | |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 230 | bool onClearBackendTexture(const GrBackendTexture&, |
| 231 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 232 | std::array<float, 4> color) override; |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 233 | |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 234 | bool onUpdateCompressedBackendTexture(const GrBackendTexture&, |
| 235 | sk_sp<GrRefCntedCallback> finishedCallback, |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 236 | const void* data, |
| 237 | size_t length) override; |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 238 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 239 | void onResetContext(uint32_t resetBits) override; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 240 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 241 | void onResetTextureBindings() override; |
| 242 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 243 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override; |
| 244 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 245 | sk_sp<GrTexture> onCreateTexture(SkISize dimensions, |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 246 | const GrBackendFormat&, |
| 247 | GrRenderable, |
| 248 | int renderTargetSampleCnt, |
| 249 | SkBudgeted, |
| 250 | GrProtected, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 251 | int mipLevelCount, |
| 252 | uint32_t levelClearMask) override; |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 253 | sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, |
| 254 | const GrBackendFormat&, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 255 | SkBudgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 256 | GrMipmapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 257 | GrProtected, |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 258 | const void* data, size_t dataSize) override; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 259 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 260 | sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern, |
| 261 | const void* data) override; |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 262 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 263 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
| 264 | GrWrapOwnership, |
| 265 | GrWrapCacheable, |
| 266 | GrIOType) override; |
| 267 | sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, |
| 268 | GrWrapOwnership, |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 269 | GrWrapCacheable) override; |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 270 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
| 271 | int sampleCnt, |
| 272 | GrWrapOwnership, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 273 | GrWrapCacheable) override; |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 274 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 275 | |
Brian Salomon | f6da146 | 2019-07-11 14:21:59 -0400 | [diff] [blame] | 276 | // Given a GL format return the index into the stencil format array on GrGLCaps to a |
bsalomon | 62a627b | 2015-12-17 09:50:47 -0800 | [diff] [blame] | 277 | // compatible stencil format, or negative if there is no compatible stencil format. |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 278 | int getCompatibleStencilIndex(GrGLFormat format); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 279 | |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame] | 280 | GrBackendFormat getPreferredStencilFormat(const GrBackendFormat& format) override { |
Greg Daniel | b8949bd | 2020-10-12 15:21:02 -0400 | [diff] [blame] | 281 | int idx = this->getCompatibleStencilIndex(format.asGLFormat()); |
| 282 | if (idx < 0) { |
| 283 | return {}; |
| 284 | } |
| 285 | return GrBackendFormat::MakeGL(GrGLFormatToEnum(this->glCaps().stencilFormats()[idx]), |
| 286 | GR_GL_TEXTURE_NONE); |
| 287 | } |
| 288 | |
Adrienne Walker | ca0cdef | 2018-08-20 13:49:40 -0700 | [diff] [blame] | 289 | void onFBOChanged(); |
bsalomon | 7e68ab7 | 2016-04-13 14:29:25 -0700 | [diff] [blame] | 290 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 291 | // Returns whether the texture is successfully created. On success, a non-zero texture ID is |
| 292 | // returned. On failure, zero is returned. |
| 293 | // The texture is populated with |texels|, if it is non-null. |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 294 | // The texture parameters are cached in |initialTexParams|. |
Brian Salomon | 0f39699 | 2020-06-19 19:51:21 -0400 | [diff] [blame] | 295 | GrGLuint createTexture(SkISize dimensions, |
| 296 | GrGLFormat, |
| 297 | GrGLenum target, |
| 298 | GrRenderable, |
| 299 | GrGLTextureParameters::SamplerOverriddenState*, |
Leon Scroggins III | 63dee7e | 2021-11-17 13:18:37 -0500 | [diff] [blame^] | 300 | int mipLevelCount, |
| 301 | GrProtected isProtected); |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 302 | |
Robert Phillips | 2716daf | 2020-01-23 12:53:42 -0500 | [diff] [blame] | 303 | GrGLuint createCompressedTexture2D(SkISize dimensions, |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 304 | SkImage::CompressionType compression, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 305 | GrGLFormat, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 306 | GrMipmapped, |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 307 | GrGLTextureParameters::SamplerOverriddenState*); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 308 | |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 309 | bool onReadPixels(GrSurface*, |
| 310 | SkIRect, |
| 311 | GrColorType surfaceColorType, |
| 312 | GrColorType dstColorType, |
| 313 | void*, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 314 | size_t rowBytes) override; |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 315 | |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 316 | bool onWritePixels(GrSurface*, |
| 317 | SkIRect, |
| 318 | GrColorType surfaceColorType, |
| 319 | GrColorType srcColorType, |
| 320 | const GrMipLevel[], |
| 321 | int mipLevelCount, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 322 | bool prepForTexSampling) override; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 323 | |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 324 | bool onTransferPixelsTo(GrTexture*, |
| 325 | SkIRect, |
| 326 | GrColorType textureColorType, |
| 327 | GrColorType bufferColorType, |
| 328 | sk_sp<GrGpuBuffer>, |
| 329 | size_t offset, |
Greg Daniel | 5ad5a37 | 2021-02-01 13:34:04 -0500 | [diff] [blame] | 330 | size_t rowBytes) override; |
Brian Salomon | e2078f1 | 2021-05-24 12:40:46 -0400 | [diff] [blame] | 331 | |
| 332 | bool onTransferPixelsFrom(GrSurface*, |
| 333 | SkIRect, |
| 334 | GrColorType surfaceColorType, |
| 335 | GrColorType bufferColorType, |
| 336 | sk_sp<GrGpuBuffer>, |
| 337 | size_t offset) override; |
| 338 | |
| 339 | bool readOrTransferPixelsFrom(GrSurface*, |
| 340 | SkIRect rect, |
| 341 | GrColorType surfaceColorType, |
| 342 | GrColorType dstColorType, |
| 343 | void* offsetOrPtr, |
| 344 | int rowWidthInPixels); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 345 | |
Greg Daniel | f76259e | 2021-02-04 12:14:04 -0500 | [diff] [blame] | 346 | // Unbinds xfer buffers from GL for operations that don't need them. |
| 347 | // Before calling any variation of TexImage, TexSubImage, etc..., call this with |
| 348 | // GrGpuBufferType::kXferCpuToGpu to ensure that the PIXEL_UNPACK_BUFFER is unbound. |
| 349 | // Before calling ReadPixels and reading back into cpu memory call this with |
| 350 | // GrGpuBufferType::kXferGpuToCpu to ensure that the PIXEL_PACK_BUFFER is unbound. |
| 351 | void unbindXferBuffer(GrGpuBufferType type); |
Brian Osman | 9b56024 | 2017-09-05 15:34:52 -0400 | [diff] [blame] | 352 | |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 353 | void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) override; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 354 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 355 | bool onRegenerateMipMapLevels(GrTexture*) override; |
| 356 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 357 | bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 358 | const SkIPoint& dstPoint) override; |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 359 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 360 | // binds texture unit in GL |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 361 | void setTextureUnit(int unitIdx); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 362 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 363 | void flushBlendAndColorWrite(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 364 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 365 | void addFinishedProc(GrGpuFinishedProc finishedProc, |
| 366 | GrGpuFinishedContext finishedContext) override; |
| 367 | |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 368 | GrOpsRenderPass* onGetOpsRenderPass(GrRenderTarget*, |
Chris Dalton | e0fe23a | 2021-04-23 13:11:44 -0600 | [diff] [blame] | 369 | bool useMultisampleFBO, |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 370 | GrAttachment*, |
| 371 | GrSurfaceOrigin, |
| 372 | const SkIRect&, |
| 373 | const GrOpsRenderPass::LoadAndStoreInfo&, |
| 374 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
| 375 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 376 | GrXferBarrierFlags renderPassXferBarriers) override; |
| 377 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 378 | bool onSubmitToGpu(bool syncCpu) override; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 379 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 380 | bool waitSync(GrGLsync, uint64_t timeout, bool flush); |
| 381 | |
Chris Dalton | 7ad3aa2 | 2021-06-08 10:10:33 -0600 | [diff] [blame] | 382 | bool copySurfaceAsDraw(GrSurface* dst, bool drawToMultisampleFBO, GrSurface* src, |
| 383 | const SkIRect& srcRect, const SkIPoint& dstPoint); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 384 | void copySurfaceAsCopyTexSubImage(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 385 | const SkIPoint& dstPoint); |
| 386 | bool copySurfaceAsBlitFramebuffer(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 387 | const SkIPoint& dstPoint); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 388 | |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 389 | class ProgramCache : public GrThreadSafePipelineBuilder { |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 390 | public: |
Robert Phillips | 962708f | 2021-03-03 14:42:04 -0500 | [diff] [blame] | 391 | ProgramCache(int runtimeProgramCacheSize); |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 392 | ~ProgramCache() override; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 393 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 394 | void abandon(); |
Brian Osman | 0b8bb88 | 2019-04-12 11:47:19 -0400 | [diff] [blame] | 395 | void reset(); |
Robert Phillips | 962708f | 2021-03-03 14:42:04 -0500 | [diff] [blame] | 396 | sk_sp<GrGLProgram> findOrCreateProgram(GrDirectContext*, |
Robert Phillips | 962708f | 2021-03-03 14:42:04 -0500 | [diff] [blame] | 397 | const GrProgramInfo&); |
Robert Phillips | 2297017 | 2021-03-22 11:26:45 -0400 | [diff] [blame] | 398 | sk_sp<GrGLProgram> findOrCreateProgram(GrDirectContext*, |
| 399 | const GrProgramDesc&, |
| 400 | const GrProgramInfo&, |
| 401 | Stats::ProgramCacheResult*); |
Robert Phillips | 962708f | 2021-03-03 14:42:04 -0500 | [diff] [blame] | 402 | bool precompileShader(GrDirectContext*, const SkData& key, const SkData& data); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 403 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 404 | private: |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 405 | struct Entry; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 406 | |
Greg Daniel | 374f96c | 2021-04-21 10:32:34 -0400 | [diff] [blame] | 407 | sk_sp<GrGLProgram> findOrCreateProgramImpl(GrDirectContext*, |
| 408 | const GrProgramDesc&, |
| 409 | const GrProgramInfo&, |
| 410 | Stats::ProgramCacheResult*); |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 411 | |
Ethan Nicholas | 1b9924f | 2016-12-15 15:28:42 -0500 | [diff] [blame] | 412 | struct DescHash { |
| 413 | uint32_t operator()(const GrProgramDesc& desc) const { |
| 414 | return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0); |
| 415 | } |
| 416 | }; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 417 | |
Ethan Nicholas | 1b9924f | 2016-12-15 15:28:42 -0500 | [diff] [blame] | 418 | SkLRUCache<GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 419 | }; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 420 | |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 421 | void flushPatchVertexCount(uint8_t count); |
| 422 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 423 | void flushColorWrite(bool writeColor); |
Brian Salomon | 07bc9a2 | 2020-12-02 13:37:16 -0500 | [diff] [blame] | 424 | void flushClearColor(std::array<float, 4>); |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 425 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 426 | // flushes the scissor. see the note on flushBoundTextureAndParams about |
| 427 | // flushing the scissor after that function is called. |
Robert Phillips | edc5b4d | 2021-01-06 13:06:23 -0500 | [diff] [blame] | 428 | void flushScissor(const GrScissorState& scissorState, int rtHeight, GrSurfaceOrigin rtOrigin) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 429 | this->flushScissorTest(GrScissorTest(scissorState.enabled())); |
| 430 | if (scissorState.enabled()) { |
Robert Phillips | edc5b4d | 2021-01-06 13:06:23 -0500 | [diff] [blame] | 431 | this->flushScissorRect(scissorState.rect(), rtHeight, rtOrigin); |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | void flushScissorTest(GrScissorTest); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 435 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 436 | void flushWindowRectangles(const GrWindowRectsState&, const GrGLRenderTarget*, GrSurfaceOrigin); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 437 | void disableWindowRectangles(); |
| 438 | |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 439 | int numTextureUnits() const { return this->caps()->shaderCaps()->maxFragmentSamplers(); } |
| 440 | |
| 441 | // Binds a texture to a target on the "scratch" texture unit to use for texture operations |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 442 | // other than usual draw flow (i.e. a GrGLProgram derived from a GrPipeline used to draw). It |
| 443 | // ensures that such operations don't negatively interact with draws. The active texture unit |
| 444 | // and the binding for 'target' will change. |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 445 | void bindTextureToScratchUnit(GrGLenum target, GrGLint textureID); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 446 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 447 | // The passed bounds contains the render target's color values that will subsequently be |
| 448 | // written. |
Chris Dalton | 27d8278 | 2021-04-07 19:04:36 -0600 | [diff] [blame] | 449 | void flushRenderTarget(GrGLRenderTarget*, bool useMultisampleFBO, GrSurfaceOrigin, |
| 450 | const SkIRect& bounds); |
Chris Dalton | c8ece3d | 2018-07-30 15:03:45 -0600 | [diff] [blame] | 451 | // This version has an implicit bounds of the entire render target. |
Chris Dalton | 27d8278 | 2021-04-07 19:04:36 -0600 | [diff] [blame] | 452 | void flushRenderTarget(GrGLRenderTarget*, bool useMultisampleFBO); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 453 | // This version can be used when the render target's colors will not be written. |
Chris Dalton | 27d8278 | 2021-04-07 19:04:36 -0600 | [diff] [blame] | 454 | void flushRenderTargetNoColorWrites(GrGLRenderTarget*, bool useMultisampleFBO); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 455 | |
Chris Dalton | 71713f6 | 2019-04-18 12:41:03 -0600 | [diff] [blame] | 456 | void flushStencil(const GrStencilSettings&, GrSurfaceOrigin); |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 457 | void disableStencil(); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 458 | |
Chris Dalton | ce425af | 2019-12-16 10:39:03 -0700 | [diff] [blame] | 459 | void flushConservativeRasterState(bool enable); |
| 460 | |
Chris Dalton | 1215cda | 2019-12-17 21:44:04 -0700 | [diff] [blame] | 461 | void flushWireframeState(bool enable); |
| 462 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 463 | void flushFramebufferSRGB(bool enable); |
| 464 | |
Brian Salomon | 2255893 | 2020-05-15 14:46:34 -0400 | [diff] [blame] | 465 | // Uploads src data of a color type to the currently bound texture on the active texture unit. |
| 466 | // The caller specifies color type that the texture is being used with, which may be different |
| 467 | // than the src color type. This fails if the combination of texture format, texture color type, |
| 468 | // and src data color type are not valid. No conversion is performed on the data before passing |
| 469 | // it to GL. 'dstRect' must be the texture bounds if mipLevelCount is greater than 1. |
| 470 | bool uploadColorTypeTexData(GrGLFormat textureFormat, |
| 471 | GrColorType textureColorType, |
| 472 | SkISize texDims, |
| 473 | GrGLenum target, |
| 474 | SkIRect dstRect, |
| 475 | GrColorType srcColorType, |
| 476 | const GrMipLevel texels[], |
| 477 | int mipLevelCount); |
| 478 | |
| 479 | // Uploads a constant color to a texture using the "default" format and color type. Overwrites |
| 480 | // entire levels. Bit n in 'levelMask' indicates whether level n should be written. This |
| 481 | // function doesn't know if MIP levels have been allocated, thus levelMask should not have bits |
| 482 | // beyond the low bit set if the texture is not MIP mapped. |
| 483 | bool uploadColorToTex(GrGLFormat textureFormat, |
| 484 | SkISize texDims, |
| 485 | GrGLenum target, |
Brian Salomon | 7128323 | 2021-04-08 12:45:58 -0400 | [diff] [blame] | 486 | std::array<float, 4> color, |
Brian Salomon | 2255893 | 2020-05-15 14:46:34 -0400 | [diff] [blame] | 487 | uint32_t levelMask); |
| 488 | |
| 489 | // Pushes data to the currently bound texture to the currently active unit. 'dstRect' must be |
| 490 | // the texture bounds if mipLevelCount is greater than 1. |
| 491 | void uploadTexData(SkISize dimensions, |
| 492 | GrGLenum target, |
| 493 | SkIRect dstRect, |
| 494 | GrGLenum externalFormat, |
| 495 | GrGLenum externalType, |
| 496 | size_t bpp, |
| 497 | const GrMipLevel texels[], |
| 498 | int mipLevelCount); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 499 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 500 | // Helper for onCreateCompressedTexture. Compressed textures are read-only so we only use this |
| 501 | // to populate a new texture. Returns false if we failed to create and upload the texture. |
Greg Daniel | 01f278c | 2020-06-12 16:58:17 -0400 | [diff] [blame] | 502 | bool uploadCompressedTexData(SkImage::CompressionType compressionType, |
| 503 | GrGLFormat, |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 504 | SkISize dimensions, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 505 | GrMipmapped, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 506 | GrGLenum target, |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 507 | const void* data, size_t dataSize); |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 508 | |
Brian Salomon | d857545 | 2020-02-25 12:13:29 -0500 | [diff] [blame] | 509 | // Calls one of various versions of renderBufferStorageMultisample. |
| 510 | bool renderbufferStorageMSAA(const GrGLContext& ctx, int sampleCount, GrGLenum format, |
| 511 | int width, int height); |
| 512 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 513 | bool createRenderTargetObjects(const GrGLTexture::Desc&, |
| 514 | int sampleCount, |
| 515 | GrGLRenderTarget::IDs*); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 516 | enum TempFBOTarget { |
| 517 | kSrc_TempFBOTarget, |
| 518 | kDst_TempFBOTarget |
| 519 | }; |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 520 | |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 521 | // Binds a surface as a FBO for copying, reading, or clearing. If the surface already owns an |
| 522 | // FBO ID then that ID is bound. If not the surface is temporarily bound to a FBO and that FBO |
| 523 | // is bound. This must be paired with a call to unbindSurfaceFBOForPixelOps(). |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 524 | void bindSurfaceFBOForPixelOps(GrSurface* surface, int mipLevel, GrGLenum fboTarget, |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 525 | TempFBOTarget tempFBOTarget); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 526 | |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 527 | // Must be called if bindSurfaceFBOForPixelOps was used to bind a surface for copying. |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 528 | void unbindSurfaceFBOForPixelOps(GrSurface* surface, int mipLevel, GrGLenum fboTarget); |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 529 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 530 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 531 | void onDumpJSON(SkJSONWriter*) const override; |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 532 | #endif |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 533 | |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 534 | bool createCopyProgram(GrTexture* srcTexture); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 535 | bool createMipmapProgram(int progIdx); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 536 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 537 | std::unique_ptr<GrGLContext> fGLContext; |
| 538 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 539 | // GL program-related state |
Robert Phillips | ae67c52 | 2021-03-03 11:03:38 -0500 | [diff] [blame] | 540 | sk_sp<ProgramCache> fProgramCache; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 541 | |
| 542 | /////////////////////////////////////////////////////////////////////////// |
| 543 | ///@name Caching of GL State |
| 544 | ///@{ |
| 545 | int fHWActiveTextureUnitIdx; |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 546 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 547 | GrGLuint fHWProgramID; |
Chris Dalton | 20e7a53 | 2020-02-28 15:37:53 +0000 | [diff] [blame] | 548 | sk_sp<GrGLProgram> fHWProgram; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 549 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 550 | enum TriState { |
| 551 | kNo_TriState, |
| 552 | kYes_TriState, |
| 553 | kUnknown_TriState |
| 554 | }; |
| 555 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 556 | GrGLuint fTempSrcFBOID; |
| 557 | GrGLuint fTempDstFBOID; |
| 558 | |
| 559 | GrGLuint fStencilClearFBOID; |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 560 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 561 | // last scissor / viewport scissor state seen by the GL. |
| 562 | struct { |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 563 | TriState fEnabled; |
| 564 | GrNativeRect fRect; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 565 | void invalidate() { |
| 566 | fEnabled = kUnknown_TriState; |
| 567 | fRect.invalidate(); |
| 568 | } |
| 569 | } fHWScissorSettings; |
| 570 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 571 | class { |
| 572 | public: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 573 | bool valid() const { return kInvalidSurfaceOrigin != fRTOrigin; } |
| 574 | void invalidate() { fRTOrigin = kInvalidSurfaceOrigin; } |
| 575 | bool knownDisabled() const { return this->valid() && !fWindowState.enabled(); } |
mtklein | 8b4a202 | 2016-09-26 08:44:47 -0700 | [diff] [blame] | 576 | void setDisabled() { |
Robert Phillips | fb4a20c | 2017-08-29 14:46:43 -0400 | [diff] [blame] | 577 | fRTOrigin = kTopLeft_GrSurfaceOrigin; |
mtklein | 8b4a202 | 2016-09-26 08:44:47 -0700 | [diff] [blame] | 578 | fWindowState.setDisabled(); |
| 579 | } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 580 | |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 581 | void set(GrSurfaceOrigin rtOrigin, int width, int height, |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 582 | const GrWindowRectsState& windowState) { |
| 583 | fRTOrigin = rtOrigin; |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 584 | fWidth = width; |
| 585 | fHeight = height; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 586 | fWindowState = windowState; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 587 | } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 588 | |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 589 | bool knownEqualTo(GrSurfaceOrigin rtOrigin, int width, int height, |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 590 | const GrWindowRectsState& windowState) const { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 591 | if (!this->valid()) { |
| 592 | return false; |
| 593 | } |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 594 | if (fWindowState.numWindows() && |
| 595 | (fRTOrigin != rtOrigin || fWidth != width || fHeight != height)) { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 596 | return false; |
| 597 | } |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 598 | return fWindowState == windowState; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | private: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 602 | enum { kInvalidSurfaceOrigin = -1 }; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 603 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 604 | int fRTOrigin; |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 605 | int fWidth; |
| 606 | int fHeight; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 607 | GrWindowRectsState fWindowState; |
| 608 | } fHWWindowRectsState; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 609 | |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 610 | GrNativeRect fHWViewport; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 611 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 612 | /** |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 613 | * Tracks vertex attrib array state. |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 614 | */ |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 615 | class HWVertexArrayState { |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 616 | public: |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 617 | HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); } |
skia.committer@gmail.com | 754a3eb | 2013-03-08 07:01:25 +0000 | [diff] [blame] | 618 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 619 | ~HWVertexArrayState() { delete fCoreProfileVertexArray; } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 620 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 621 | void invalidate() { |
| 622 | fBoundVertexArrayIDIsValid = false; |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 623 | fDefaultVertexArrayAttribState.invalidate(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 624 | if (fCoreProfileVertexArray) { |
| 625 | fCoreProfileVertexArray->invalidateCachedState(); |
commit-bot@chromium.org | ce6da4d | 2013-09-09 14:55:37 +0000 | [diff] [blame] | 626 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | void notifyVertexArrayDelete(GrGLuint id) { |
| 630 | if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) { |
| 631 | // Does implicit bind to 0 |
| 632 | fBoundVertexArrayID = 0; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 636 | void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 637 | if (!gpu->glCaps().vertexArrayObjectSupport()) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 638 | SkASSERT(0 == arrayID); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 639 | return; |
| 640 | } |
| 641 | if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) { |
| 642 | GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID)); |
| 643 | fBoundVertexArrayIDIsValid = true; |
| 644 | fBoundVertexArrayID = arrayID; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 648 | /** |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 649 | * Binds the vertex array that should be used for internal draws, and returns its attrib |
| 650 | * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which |
Kevin Lubick | be03ef1 | 2021-06-16 15:28:00 -0400 | [diff] [blame] | 651 | * case we use a placeholder array instead. |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 652 | * |
Chris Dalton | d42d200 | 2020-02-28 12:05:04 -0700 | [diff] [blame] | 653 | * If an index buffer is provided, it will be bound to the vertex array. Otherwise the |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 654 | * index buffer binding will be left unchanged. |
| 655 | * |
| 656 | * The returned GrGLAttribArrayState should be used to set vertex attribute arrays. |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 657 | */ |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 658 | GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrBuffer* ibuff = nullptr); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 659 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 660 | private: |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 661 | GrGLuint fBoundVertexArrayID; |
| 662 | bool fBoundVertexArrayIDIsValid; |
mtklein | 044d3c1 | 2016-04-06 18:24:34 -0700 | [diff] [blame] | 663 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 664 | // 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] | 665 | // is bound. However, this class is internal to GrGLGpu and this object never leaks out of |
| 666 | // GrGLGpu. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 667 | GrGLAttribArrayState fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 668 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 669 | // This is used when we're using a core profile. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 670 | GrGLVertexArray* fCoreProfileVertexArray; |
Chris Dalton | 5a2f962 | 2019-12-27 14:56:38 -0700 | [diff] [blame] | 671 | } fHWVertexArrayState; |
| 672 | |
| 673 | uint8_t fHWPatchVertexCount; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 674 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 675 | struct { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 676 | GrGLenum fGLTarget; |
| 677 | GrGpuResource::UniqueID fBoundBufferUniqueID; |
| 678 | bool fBufferZeroKnownBound; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 679 | |
| 680 | void invalidate() { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 681 | fBoundBufferUniqueID.makeInvalid(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 682 | fBufferZeroKnownBound = false; |
| 683 | } |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 684 | } fHWBufferState[kGrGpuBufferTypeCount]; |
| 685 | |
| 686 | auto* hwBufferState(GrGpuBufferType type) { |
| 687 | unsigned typeAsUInt = static_cast<unsigned>(type); |
| 688 | SkASSERT(typeAsUInt < SK_ARRAY_COUNT(fHWBufferState)); |
Greg Daniel | 87d784f | 2021-02-02 15:36:06 -0500 | [diff] [blame] | 689 | SkASSERT(type != GrGpuBufferType::kUniform); |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 690 | return &fHWBufferState[typeAsUInt]; |
| 691 | } |
cdalton | c161310 | 2016-03-16 07:48:20 -0700 | [diff] [blame] | 692 | |
Greg Daniel | 78be37f | 2020-04-14 16:40:35 -0400 | [diff] [blame] | 693 | enum class FlushType { |
| 694 | kIfRequired, |
| 695 | kForce, |
| 696 | }; |
| 697 | |
| 698 | // This calls glFlush if it is required for previous operations or kForce is passed. |
| 699 | void flush(FlushType flushType = FlushType::kIfRequired); |
| 700 | |
| 701 | void setNeedsFlush() { fNeedsGLFlush = true; } |
| 702 | |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 703 | struct { |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 704 | GrBlendEquation fEquation; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 705 | GrBlendCoeff fSrcCoeff; |
| 706 | GrBlendCoeff fDstCoeff; |
Brian Osman | 422f95b | 2018-11-05 16:49:04 -0500 | [diff] [blame] | 707 | SkPMColor4f fConstColor; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 708 | bool fConstColorValid; |
| 709 | TriState fEnabled; |
| 710 | |
| 711 | void invalidate() { |
Mike Klein | 3674336 | 2018-11-06 08:23:30 -0500 | [diff] [blame] | 712 | fEquation = kIllegal_GrBlendEquation; |
| 713 | fSrcCoeff = kIllegal_GrBlendCoeff; |
| 714 | fDstCoeff = kIllegal_GrBlendCoeff; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 715 | fConstColorValid = false; |
| 716 | fEnabled = kUnknown_TriState; |
| 717 | } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 718 | } fHWBlendState; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 719 | |
Chris Dalton | ce425af | 2019-12-16 10:39:03 -0700 | [diff] [blame] | 720 | TriState fHWConservativeRasterEnabled; |
bsalomon | 54c6fe8 | 2015-12-16 11:51:22 -0800 | [diff] [blame] | 721 | |
Chris Dalton | 1215cda | 2019-12-17 21:44:04 -0700 | [diff] [blame] | 722 | TriState fHWWireframeEnabled; |
| 723 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 724 | GrStencilSettings fHWStencilSettings; |
Chris Dalton | 71713f6 | 2019-04-18 12:41:03 -0600 | [diff] [blame] | 725 | GrSurfaceOrigin fHWStencilOrigin; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 726 | TriState fHWStencilTestEnabled; |
bsalomon | 54c6fe8 | 2015-12-16 11:51:22 -0800 | [diff] [blame] | 727 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 728 | TriState fHWWriteToColor; |
| 729 | GrGpuResource::UniqueID fHWBoundRenderTargetUniqueID; |
Chris Dalton | 27d8278 | 2021-04-07 19:04:36 -0600 | [diff] [blame] | 730 | bool fHWBoundFramebufferIsMSAA; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 731 | TriState fHWSRGBFramebuffer; |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 732 | |
| 733 | class TextureUnitBindings { |
| 734 | public: |
| 735 | TextureUnitBindings() = default; |
| 736 | TextureUnitBindings(const TextureUnitBindings&) = delete; |
| 737 | TextureUnitBindings& operator=(const TextureUnitBindings&) = delete; |
| 738 | |
| 739 | GrGpuResource::UniqueID boundID(GrGLenum target) const; |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 740 | bool hasBeenModified(GrGLenum target) const; |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 741 | void setBoundID(GrGLenum target, GrGpuResource::UniqueID); |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 742 | void invalidateForScratchUse(GrGLenum target); |
| 743 | void invalidateAllTargets(bool markUnmodified); |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 744 | |
| 745 | private: |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 746 | struct TargetBinding { |
| 747 | GrGpuResource::UniqueID fBoundResourceID; |
| 748 | bool fHasBeenModified = false; |
| 749 | }; |
| 750 | TargetBinding fTargetBindings[3]; |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 751 | }; |
| 752 | SkAutoTArray<TextureUnitBindings> fHWTextureUnitBindings; |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 753 | |
Brian Salomon | 805cc7a | 2019-01-28 09:52:34 -0500 | [diff] [blame] | 754 | GrGLfloat fHWClearColor[4]; |
| 755 | |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 756 | GrGLuint fBoundDrawFramebuffer = 0; |
| 757 | |
Brian Salomon | 5711133 | 2018-02-05 15:55:54 -0500 | [diff] [blame] | 758 | /** IDs for copy surface program. (3 sampler types) */ |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 759 | struct { |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 760 | GrGLuint fProgram = 0; |
| 761 | GrGLint fTextureUniform = 0; |
| 762 | GrGLint fTexCoordXformUniform = 0; |
| 763 | GrGLint fPosXformUniform = 0; |
Brian Salomon | 5711133 | 2018-02-05 15:55:54 -0500 | [diff] [blame] | 764 | } fCopyPrograms[3]; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 765 | sk_sp<GrGLBuffer> fCopyProgramArrayBuffer; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 766 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 767 | /** IDs for texture mipmap program. (4 filter configurations) */ |
| 768 | struct { |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 769 | GrGLuint fProgram = 0; |
| 770 | GrGLint fTextureUniform = 0; |
| 771 | GrGLint fTexCoordXformUniform = 0; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 772 | } fMipmapPrograms[4]; |
| 773 | sk_sp<GrGLBuffer> fMipmapProgramArrayBuffer; |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 774 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 775 | static int TextureToCopyProgramIdx(GrTexture* texture); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 776 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 777 | static int TextureSizeToMipmapProgramIdx(int width, int height) { |
| 778 | const bool wide = (width > 1) && SkToBool(width & 0x1); |
| 779 | const bool tall = (height > 1) && SkToBool(height & 0x1); |
| 780 | return (wide ? 0x2 : 0x0) | (tall ? 0x1 : 0x0); |
| 781 | } |
| 782 | |
Chris Dalton | da40cd2 | 2018-04-16 13:19:58 -0600 | [diff] [blame] | 783 | GrPrimitiveType fLastPrimitiveType; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 784 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 785 | GrGLTextureParameters::ResetTimestamp fResetTimestampForTextureParameters = 0; |
| 786 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 787 | class SamplerObjectCache; |
| 788 | std::unique_ptr<SamplerObjectCache> fSamplerObjectCache; |
| 789 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 790 | std::unique_ptr<GrGLOpsRenderPass> fCachedOpsRenderPass; |
Stephen White | b353c9b | 2020-04-16 14:14:13 -0400 | [diff] [blame] | 791 | GrFinishCallbacks fFinishCallbacks; |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 792 | |
Greg Daniel | 78be37f | 2020-04-14 16:40:35 -0400 | [diff] [blame] | 793 | // If we've called a command that requires us to call glFlush than this will be set to true |
| 794 | // since we defer calling flush until submit time. When we call submitToGpu if this is true then |
| 795 | // we call glFlush and reset this to false. |
| 796 | bool fNeedsGLFlush = false; |
| 797 | |
Chris Dalton | 674f77a | 2019-09-30 20:49:39 -0600 | [diff] [blame] | 798 | SkDEBUGCODE(bool fIsExecutingCommandBuffer_DebugOnly = false); |
| 799 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 800 | friend class GrGLPathRendering; // For accessing setTextureUnit. |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 801 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 802 | using INHERITED = GrGpu; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 803 | }; |
| 804 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 805 | #endif |