reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 8 | #ifndef GrGLGpu_DEFINED |
| 9 | #define GrGLGpu_DEFINED |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 11 | #include "GrGLContext.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 12 | #include "GrGLIRect.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 13 | #include "GrGLPathRendering.h" |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 14 | #include "GrGLProgram.h" |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 15 | #include "GrGLRenderTarget.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 16 | #include "GrGLStencilAttachment.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 17 | #include "GrGLTexture.h" |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 18 | #include "GrGLVertexArray.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 19 | #include "GrGpu.h" |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 20 | #include "GrMesh.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 21 | #include "GrWindowRectsState.h" |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 22 | #include "GrXferProcessor.h" |
Ethan Nicholas | 1b9924f | 2016-12-15 15:28:42 -0500 | [diff] [blame] | 23 | #include "SkLRUCache.h" |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 24 | #include "SkTArray.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 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 27 | class GrGLBuffer; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 28 | class GrPipeline; |
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 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 31 | namespace gr_instanced { class GLInstancedRendering; } |
| 32 | |
djsollen | efe46d2 | 2016-04-29 06:41:35 -0700 | [diff] [blame] | 33 | #ifdef SK_DEBUG |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 34 | #define PROGRAM_CACHE_STATS |
| 35 | #endif |
| 36 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 37 | class GrGLGpu final : public GrGpu, private GrMesh::SendToGpuImpl { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 38 | public: |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 39 | static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options, |
| 40 | GrContext* context); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 41 | static GrGpu* Create(const GrGLInterface*, const GrContextOptions& options, |
| 42 | GrContext* context); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 43 | ~GrGLGpu() override; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 45 | void disconnect(DisconnectType) override; |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 46 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 47 | const GrGLContext& glContext() const { return *fGLContext; } |
commit-bot@chromium.org | c9424b8 | 2013-10-30 20:03:16 +0000 | [diff] [blame] | 48 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 49 | const GrGLInterface* glInterface() const { return fGLContext->interface(); } |
| 50 | const GrGLContextInfo& ctxInfo() const { return *fGLContext; } |
| 51 | GrGLStandard glStandard() const { return fGLContext->standard(); } |
| 52 | GrGLVersion glVersion() const { return fGLContext->version(); } |
| 53 | GrGLSLGeneration glslGeneration() const { return fGLContext->glslGeneration(); } |
| 54 | const GrGLCaps& glCaps() const { return *fGLContext->caps(); } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 55 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 56 | GrGLPathRendering* glPathRendering() { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 57 | SkASSERT(glCaps().shaderCaps()->pathRenderingSupport()); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 58 | return static_cast<GrGLPathRendering*>(pathRendering()); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 59 | } |
| 60 | |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 61 | // Used by GrGLProgram to configure OpenGL state. |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 62 | void bindTexture(int unitIdx, const GrSamplerState& samplerState, bool allowSRGBInputs, |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 63 | GrGLTexture* texture, GrSurfaceOrigin textureOrigin); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 64 | |
csmartdalton | 1897cfd | 2016-06-03 08:50:54 -0700 | [diff] [blame] | 65 | void bindTexelBuffer(int unitIdx, GrPixelConfig, GrGLBuffer*); |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 66 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 67 | void bindImageStorage(int unitIdx, GrIOType, GrGLTexture *); |
| 68 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 69 | void generateMipmaps(const GrSamplerState& params, bool allowSRGBInputs, GrGLTexture* texture, |
| 70 | GrSurfaceOrigin textureOrigin); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 71 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 72 | bool onGetReadPixelsInfo(GrSurface* srcSurface, GrSurfaceOrigin srcOrigin, |
| 73 | int readWidth, int readHeight, size_t rowBytes, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 74 | GrPixelConfig readConfig, DrawPreference*, |
| 75 | ReadPixelTempDrawInfo*) override; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 76 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 77 | bool onGetWritePixelsInfo(GrSurface* dstSurface, GrSurfaceOrigin dstOrigin, |
| 78 | int width, int height, |
cblume | ed82800 | 2016-02-16 13:00:01 -0800 | [diff] [blame] | 79 | GrPixelConfig srcConfig, DrawPreference*, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 80 | WritePixelTempDrawInfo*) override; |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 81 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 82 | // 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] | 83 | // 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] | 84 | void bindVertexArray(GrGLuint id) { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 85 | fHWVertexArrayState.setVertexArrayID(this, id); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | // These callbacks update state tracking when GL objects are deleted. They are called from |
| 89 | // GrGLResource onRelease functions. |
| 90 | void notifyVertexArrayDelete(GrGLuint id) { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 91 | fHWVertexArrayState.notifyVertexArrayDelete(id); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 92 | } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 93 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 94 | // Binds a buffer to the GL target corresponding to 'type', updates internal state tracking, and |
| 95 | // returns the GL target the buffer was bound to. |
| 96 | // When 'type' is kIndex_GrBufferType, this function will also implicitly bind the default VAO. |
| 97 | // If the caller wishes to bind an index buffer to a specific VAO, it can call glBind directly. |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 98 | GrGLenum bindBuffer(GrBufferType type, const GrBuffer*); |
joshualitt | 93316b9 | 2015-10-23 09:08:08 -0700 | [diff] [blame] | 99 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 100 | // Called by GrGLBuffer after its buffer object has been destroyed. |
| 101 | void notifyBufferReleased(const GrGLBuffer*); |
| 102 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 103 | // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 104 | // Thus this is the implementation of the draw call for the corresponding passthrough function |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 105 | // on GrGLRTGpuCommandBuffer. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 106 | void draw(const GrPipeline&, |
| 107 | const GrPrimitiveProcessor&, |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 108 | const GrMesh[], |
| 109 | const GrPipeline::DynamicState[], |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 110 | int meshCount); |
| 111 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 112 | |
| 113 | // GrMesh::SendToGpuImpl methods. These issue the actual GL draw calls. |
| 114 | // Marked final as a hint to the compiler to not use virtual dispatch. |
| 115 | void sendMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType, |
| 116 | const GrBuffer* vertexBuffer, int vertexCount, int baseVertex) final; |
| 117 | |
| 118 | void sendIndexedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType, |
| 119 | const GrBuffer* indexBuffer, int indexCount, int baseIndex, |
| 120 | uint16_t minIndexValue, uint16_t maxIndexValue, |
| 121 | const GrBuffer* vertexBuffer, int baseVertex) final; |
| 122 | |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 123 | void sendInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType, |
| 124 | const GrBuffer* vertexBuffer, int vertexCount, int baseVertex, |
| 125 | const GrBuffer* instanceBuffer, int instanceCount, |
| 126 | int baseInstance) final; |
| 127 | |
| 128 | void sendIndexedInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType, |
| 129 | const GrBuffer* indexBuffer, int indexCount, int baseIndex, |
| 130 | const GrBuffer* vertexBuffer, int baseVertex, |
| 131 | const GrBuffer* instanceBuffer, int instanceCount, |
| 132 | int baseInstance) final; |
| 133 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 134 | // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 135 | // Thus this is the implementation of the clear call for the corresponding passthrough function |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 136 | // on GrGLGpuRTCommandBuffer. |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 137 | void clear(const GrFixedClip&, GrColor, GrRenderTarget*, GrSurfaceOrigin); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 138 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 139 | // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 140 | // Thus this is the implementation of the clearStencil call for the corresponding passthrough |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 141 | // function on GrGLGpuRTCommandBuffer. |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 142 | void clearStencilClip(const GrFixedClip&, bool insideStencilMask, |
| 143 | GrRenderTarget*, GrSurfaceOrigin); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 144 | |
reed | f9ad558 | 2015-06-25 21:29:25 -0700 | [diff] [blame] | 145 | const GrGLContext* glContextForTesting() const override { |
| 146 | return &this->glContext(); |
bsalomon | 993a421 | 2015-05-29 11:37:25 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 149 | void clearStencil(GrRenderTarget*, int clearValue) override; |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 150 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 151 | GrGpuRTCommandBuffer* createCommandBuffer( |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 152 | GrRenderTarget*, GrSurfaceOrigin, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 153 | const GrGpuRTCommandBuffer::LoadAndStoreInfo&, |
| 154 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override; |
| 155 | |
| 156 | GrGpuTextureCommandBuffer* createCommandBuffer(GrTexture*, GrSurfaceOrigin) override; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 157 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 158 | void invalidateBoundRenderTarget() { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 159 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget* rt, |
| 163 | int width, |
| 164 | int height) override; |
| 165 | |
jvanverth | 8895792 | 2015-07-14 11:02:52 -0700 | [diff] [blame] | 166 | GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 167 | GrPixelConfig config, |
| 168 | bool isRenderTarget = false) override; |
bsalomon | 67d7620 | 2015-11-11 12:40:42 -0800 | [diff] [blame] | 169 | bool isTestingOnlyBackendTexture(GrBackendObject) const override; |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 170 | void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override; |
jvanverth | 672bb7f | 2015-07-13 07:19:57 -0700 | [diff] [blame] | 171 | |
joshualitt | 8fd844f | 2015-12-02 13:36:47 -0800 | [diff] [blame] | 172 | void resetShaderCacheForTesting() const override; |
| 173 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 174 | GrFence SK_WARN_UNUSED_RESULT insertFence() override; |
| 175 | bool waitFence(GrFence, uint64_t timeout) override; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 176 | void deleteFence(GrFence) const override; |
| 177 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 178 | sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override; |
| 179 | sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore, |
| 180 | GrWrapOwnership ownership) override; |
Brian Osman | dc87c95 | 2017-04-28 13:57:38 -0400 | [diff] [blame] | 181 | void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 182 | void waitSemaphore(sk_sp<GrSemaphore> semaphore) override; |
| 183 | |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 184 | sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override; |
| 185 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 186 | void deleteSync(GrGLsync) const; |
| 187 | |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 188 | void insertEventMarker(const char*); |
| 189 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 190 | private: |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 191 | GrGLGpu(GrGLContext* ctx, GrContext* context); |
| 192 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 193 | // GrGpu overrides |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 194 | void onResetContext(uint32_t resetBits) override; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 195 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 196 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override; |
| 197 | |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 198 | sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 199 | const GrMipLevel texels[], |
| 200 | int mipLevelCount) override; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 201 | |
cdalton | 1bf3e71 | 2016-04-19 10:00:02 -0700 | [diff] [blame] | 202 | GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, |
| 203 | const void* data) override; |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 204 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 205 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 206 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 207 | int sampleCnt, |
| 208 | GrWrapOwnership) override; |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 209 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 210 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 211 | int sampleCnt) override; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 212 | |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 213 | std::unique_ptr<gr_instanced::OpAllocator> onCreateInstancedRenderingAllocator() override; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 214 | gr_instanced::InstancedRendering* onCreateInstancedRendering() override; |
| 215 | |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 216 | // 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] | 217 | // compatible stencil format, or negative if there is no compatible stencil format. |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 218 | int getCompatibleStencilIndex(GrPixelConfig config); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 219 | |
bsalomon | 7e68ab7 | 2016-04-13 14:29:25 -0700 | [diff] [blame] | 220 | |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 221 | // Returns whether the texture is successfully created. On success, the |
| 222 | // result is stored in |info|. |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 223 | // The texture is populated with |texels|, if it exists. |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 224 | // The texture parameters are cached in |initialTexParams|. |
| 225 | bool createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 226 | bool renderTarget, GrGLTexture::TexParams* initialTexParams, |
Greg Daniel | 834f120 | 2017-10-09 15:06:20 -0400 | [diff] [blame^] | 227 | const GrMipLevel texels[], int mipLevelCount, |
| 228 | bool* wasFullMipMapDataProvided); |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 229 | |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 230 | bool onIsACopyNeededForTextureParams(GrTextureProxy*, const GrSamplerState&, |
Robert Phillips | 81444fb | 2017-03-21 09:14:35 -0400 | [diff] [blame] | 231 | GrTextureProducer::CopyParams*, |
| 232 | SkScalar scaleAdjust[2]) const override; |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame] | 233 | |
bsalomon | 1aa2029 | 2016-01-22 08:16:09 -0800 | [diff] [blame] | 234 | // Checks whether glReadPixels can be called to get pixel values in readConfig from the |
| 235 | // render target. |
| 236 | bool readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConfig); |
| 237 | |
| 238 | // Checks whether glReadPixels can be called to get pixel values in readConfig from a |
| 239 | // render target that has renderTargetConfig. This may have to create a temporary |
| 240 | // render target and thus is less preferable than the variant that takes a render target. |
| 241 | bool readPixelsSupported(GrPixelConfig renderTargetConfig, GrPixelConfig readConfig); |
| 242 | |
| 243 | // Checks whether glReadPixels can be called to get pixel values in readConfig from a |
| 244 | // render target that has the same config as surfaceForConfig. Calls one of the the two |
| 245 | // variations above, depending on whether the surface is a render target or not. |
| 246 | bool readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig readConfig); |
| 247 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 248 | bool onReadPixels(GrSurface*, GrSurfaceOrigin, |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 249 | int left, int top, |
| 250 | int width, int height, |
| 251 | GrPixelConfig, |
| 252 | void* buffer, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 253 | size_t rowBytes) override; |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 254 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 255 | bool onWritePixels(GrSurface*, GrSurfaceOrigin, |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 256 | int left, int top, int width, int height, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 257 | GrPixelConfig config, |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 258 | const GrMipLevel texels[], int mipLevelCount) override; |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 259 | |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 260 | bool onTransferPixels(GrTexture*, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 261 | int left, int top, int width, int height, |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 262 | GrPixelConfig config, GrBuffer* transferBuffer, |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 263 | size_t offset, size_t rowBytes) override; |
| 264 | |
Brian Osman | 9b56024 | 2017-09-05 15:34:52 -0400 | [diff] [blame] | 265 | // Before calling any variation of TexImage, TexSubImage, etc..., call this to ensure that the |
| 266 | // PIXEL_UNPACK_BUFFER is unbound. |
| 267 | void unbindCpuToGpuXferBuffer(); |
| 268 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 269 | void onResolveRenderTarget(GrRenderTarget* target, GrSurfaceOrigin) override; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 270 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 271 | bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, |
| 272 | GrSurface* src, GrSurfaceOrigin srcOrigin, |
| 273 | const SkIRect& srcRect, const SkIPoint& dstPoint) override; |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 274 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 275 | void onQueryMultisampleSpecs(GrRenderTarget*, GrSurfaceOrigin, const GrStencilSettings&, |
csmartdalton | c25c5d7 | 2016-11-01 07:03:59 -0700 | [diff] [blame] | 276 | int* effectiveSampleCnt, SamplePattern*) override; |
cdalton | 28f45b9 | 2016-03-07 13:58:26 -0800 | [diff] [blame] | 277 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 278 | // binds texture unit in GL |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 279 | void setTextureUnit(int unitIdx); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 280 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 281 | void setTextureSwizzle(int unitIdx, GrGLenum target, const GrGLenum swizzle[]); |
| 282 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 283 | // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set. |
bsalomon | 2eda5b3 | 2016-09-21 10:53:24 -0700 | [diff] [blame] | 284 | // willDrawPoints must be true if point primitives will be rendered after setting the GL state. |
| 285 | bool flushGLState(const GrPipeline&, const GrPrimitiveProcessor&, bool willDrawPoints); |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 286 | |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 287 | // Sets up vertex/instance attribute pointers and strides. |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 288 | void setupGeometry(const GrPrimitiveProcessor&, |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 289 | const GrBuffer* indexBuffer, |
| 290 | const GrBuffer* vertexBuffer, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 291 | int baseVertex, |
| 292 | const GrBuffer* instanceBuffer, |
| 293 | int baseInstance); |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 294 | |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 295 | void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 296 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 297 | void onFinishFlush(bool insertedSemaphores) override; |
| 298 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 299 | bool hasExtension(const char* ext) const { return fGLContext->hasExtension(ext); } |
bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 300 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 301 | bool copySurfaceAsDraw(GrSurface* dst, GrSurfaceOrigin dstOrigin, |
| 302 | GrSurface* src, GrSurfaceOrigin srcOrigin, |
| 303 | const SkIRect& srcRect, const SkIPoint& dstPoint); |
| 304 | void copySurfaceAsCopyTexSubImage(GrSurface* dst, GrSurfaceOrigin dstOrigin, |
| 305 | GrSurface* src, GrSurfaceOrigin srcOrigin, |
| 306 | const SkIRect& srcRect, const SkIPoint& dstPoint); |
| 307 | bool copySurfaceAsBlitFramebuffer(GrSurface* dst, GrSurfaceOrigin dstOrigin, |
| 308 | GrSurface* src, GrSurfaceOrigin srcOrigin, |
| 309 | const SkIRect& srcRect, const SkIPoint& dstPoint); |
| 310 | bool generateMipmap(GrGLTexture* texture, GrSurfaceOrigin textureOrigin, bool gammaCorrect); |
| 311 | void clearStencilClipAsDraw(const GrFixedClip&, bool insideStencilMask, |
| 312 | GrRenderTarget*, GrSurfaceOrigin); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 313 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 314 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 315 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 316 | class ProgramCache : public ::SkNoncopyable { |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 317 | public: |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 318 | ProgramCache(GrGLGpu* gpu); |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 319 | ~ProgramCache(); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 320 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 321 | void abandon(); |
bsalomon | 2eda5b3 | 2016-09-21 10:53:24 -0700 | [diff] [blame] | 322 | GrGLProgram* refProgram(const GrGLGpu*, const GrPipeline&, const GrPrimitiveProcessor&, |
| 323 | bool hasPointSize); |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 324 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 325 | private: |
Ethan Nicholas | 1b9924f | 2016-12-15 15:28:42 -0500 | [diff] [blame] | 326 | // We may actually have kMaxEntries+1 shaders in the GL context because we create a new |
| 327 | // shader before evicting from the cache. |
| 328 | static const int kMaxEntries = 128; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 329 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 330 | struct Entry; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 331 | |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 332 | // binary search for entry matching desc. returns index into fEntries that matches desc or ~ |
| 333 | // of the index of where it should be inserted. |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 334 | int search(const GrProgramDesc& desc) const; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 335 | |
Ethan Nicholas | 1b9924f | 2016-12-15 15:28:42 -0500 | [diff] [blame] | 336 | struct DescHash { |
| 337 | uint32_t operator()(const GrProgramDesc& desc) const { |
| 338 | return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0); |
| 339 | } |
| 340 | }; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 341 | |
Ethan Nicholas | 1b9924f | 2016-12-15 15:28:42 -0500 | [diff] [blame] | 342 | SkLRUCache<GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap; |
| 343 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 344 | GrGLGpu* fGpu; |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 345 | #ifdef PROGRAM_CACHE_STATS |
| 346 | int fTotalRequests; |
| 347 | int fCacheMisses; |
bsalomon@google.com | 2db3ded | 2013-05-22 14:34:04 +0000 | [diff] [blame] | 348 | int fHashMisses; // cache hit but hash table missed |
jvanverth@google.com | 9487877 | 2013-03-12 16:00:54 +0000 | [diff] [blame] | 349 | #endif |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 350 | }; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 351 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 352 | void flushColorWrite(bool writeColor); |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 353 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 354 | // flushes the scissor. see the note on flushBoundTextureAndParams about |
| 355 | // flushing the scissor after that function is called. |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 356 | void flushScissor(const GrScissorState&, |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 357 | const GrGLIRect& rtViewport, |
| 358 | GrSurfaceOrigin rtOrigin); |
| 359 | |
| 360 | // disables the scissor |
| 361 | void disableScissor(); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 362 | |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 363 | void flushWindowRectangles(const GrWindowRectsState&, const GrGLRenderTarget*, GrSurfaceOrigin); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 364 | void disableWindowRectangles(); |
| 365 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 366 | // sets a texture unit to use for texture operations other than binding a texture to a program. |
| 367 | // ensures that such operations don't negatively interact with tracking bound textures. |
| 368 | void setScratchTextureUnit(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 369 | |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 370 | // bounds is region that may be modified. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 371 | // nullptr means whole target. Can be an empty rect. |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 372 | void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds, bool disableSRGB = false); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 373 | |
| 374 | // Need not be called if flushRenderTarget is used. |
| 375 | void flushViewport(const GrGLIRect&); |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 376 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 377 | void flushStencil(const GrStencilSettings&); |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 378 | void disableStencil(); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 379 | |
| 380 | // rt is used only if useHWAA is true. |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 381 | void flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabled); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 382 | |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 383 | void flushMinSampleShading(float minSampleShading); |
| 384 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 385 | void flushFramebufferSRGB(bool enable); |
| 386 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 387 | // helper for onCreateTexture and writeTexturePixels |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 388 | enum UploadType { |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 389 | kNewTexture_UploadType, // we are creating a new texture |
| 390 | kWrite_UploadType, // we are using TexSubImage2D to copy data to an existing texture |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 391 | }; |
Brian Salomon | d1eaf49 | 2017-05-18 10:02:08 -0400 | [diff] [blame] | 392 | bool uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight, |
| 393 | GrSurfaceOrigin texOrigin, GrGLenum target, UploadType uploadType, int left, |
| 394 | int top, int width, int height, GrPixelConfig dataConfig, |
Greg Daniel | 834f120 | 2017-10-09 15:06:20 -0400 | [diff] [blame^] | 395 | const GrMipLevel texels[], int mipLevelCount, |
| 396 | bool* wasFullMipMapDataProvided = nullptr); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 397 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 398 | bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo, |
| 399 | GrGLRenderTarget::IDDesc*); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 400 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 401 | enum TempFBOTarget { |
| 402 | kSrc_TempFBOTarget, |
| 403 | kDst_TempFBOTarget |
| 404 | }; |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 405 | |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 406 | // Binds a surface as a FBO for copying, reading, or clearing. If the surface already owns an |
| 407 | // FBO ID then that ID is bound. If not the surface is temporarily bound to a FBO and that FBO |
| 408 | // is bound. This must be paired with a call to unbindSurfaceFBOForPixelOps(). |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 409 | void bindSurfaceFBOForPixelOps(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport, |
| 410 | TempFBOTarget tempFBOTarget); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 411 | |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 412 | // Must be called if bindSurfaceFBOForPixelOps was used to bind a surface for copying. |
| 413 | void unbindTextureFBOForPixelOps(GrGLenum fboTarget, GrSurface* surface); |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 414 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 415 | void onDumpJSON(SkJSONWriter*) const override; |
| 416 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 417 | sk_sp<GrGLContext> fGLContext; |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 418 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 419 | bool createCopyProgram(GrTexture* srcTexture); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 420 | bool createMipmapProgram(int progIdx); |
Mike Klein | 31550db | 2017-06-06 23:29:53 +0000 | [diff] [blame] | 421 | bool createStencilClipClearProgram(); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 422 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 423 | // GL program-related state |
| 424 | ProgramCache* fProgramCache; |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 425 | |
| 426 | /////////////////////////////////////////////////////////////////////////// |
| 427 | ///@name Caching of GL State |
| 428 | ///@{ |
| 429 | int fHWActiveTextureUnitIdx; |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 430 | GrGLuint fHWProgramID; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 431 | |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 432 | enum TriState { |
| 433 | kNo_TriState, |
| 434 | kYes_TriState, |
| 435 | kUnknown_TriState |
| 436 | }; |
| 437 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 438 | GrGLuint fTempSrcFBOID; |
| 439 | GrGLuint fTempDstFBOID; |
| 440 | |
| 441 | GrGLuint fStencilClearFBOID; |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 442 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 443 | // last scissor / viewport scissor state seen by the GL. |
| 444 | struct { |
| 445 | TriState fEnabled; |
| 446 | GrGLIRect fRect; |
| 447 | void invalidate() { |
| 448 | fEnabled = kUnknown_TriState; |
| 449 | fRect.invalidate(); |
| 450 | } |
| 451 | } fHWScissorSettings; |
| 452 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 453 | class { |
| 454 | public: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 455 | bool valid() const { return kInvalidSurfaceOrigin != fRTOrigin; } |
| 456 | void invalidate() { fRTOrigin = kInvalidSurfaceOrigin; } |
| 457 | bool knownDisabled() const { return this->valid() && !fWindowState.enabled(); } |
mtklein | 8b4a202 | 2016-09-26 08:44:47 -0700 | [diff] [blame] | 458 | void setDisabled() { |
Robert Phillips | fb4a20c | 2017-08-29 14:46:43 -0400 | [diff] [blame] | 459 | fRTOrigin = kTopLeft_GrSurfaceOrigin; |
mtklein | 8b4a202 | 2016-09-26 08:44:47 -0700 | [diff] [blame] | 460 | fWindowState.setDisabled(); |
| 461 | } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 462 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 463 | void set(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport, |
| 464 | const GrWindowRectsState& windowState) { |
| 465 | fRTOrigin = rtOrigin; |
| 466 | fViewport = viewport; |
| 467 | fWindowState = windowState; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 468 | } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 469 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 470 | bool knownEqualTo(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport, |
| 471 | const GrWindowRectsState& windowState) const { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 472 | if (!this->valid()) { |
| 473 | return false; |
| 474 | } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 475 | if (fWindowState.numWindows() && (fRTOrigin != rtOrigin || fViewport != viewport)) { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 476 | return false; |
| 477 | } |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 478 | return fWindowState == windowState; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | private: |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 482 | enum { kInvalidSurfaceOrigin = -1 }; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 483 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 484 | int fRTOrigin; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 485 | GrGLIRect fViewport; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 486 | GrWindowRectsState fWindowState; |
| 487 | } fHWWindowRectsState; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 488 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 489 | GrGLIRect fHWViewport; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 490 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 491 | /** |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 492 | * Tracks vertex attrib array state. |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 493 | */ |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 494 | class HWVertexArrayState { |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 495 | public: |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 496 | HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); } |
skia.committer@gmail.com | 754a3eb | 2013-03-08 07:01:25 +0000 | [diff] [blame] | 497 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 498 | ~HWVertexArrayState() { delete fCoreProfileVertexArray; } |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 499 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 500 | void invalidate() { |
| 501 | fBoundVertexArrayIDIsValid = false; |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 502 | fDefaultVertexArrayAttribState.invalidate(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 503 | if (fCoreProfileVertexArray) { |
| 504 | fCoreProfileVertexArray->invalidateCachedState(); |
commit-bot@chromium.org | ce6da4d | 2013-09-09 14:55:37 +0000 | [diff] [blame] | 505 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | void notifyVertexArrayDelete(GrGLuint id) { |
| 509 | if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) { |
| 510 | // Does implicit bind to 0 |
| 511 | fBoundVertexArrayID = 0; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 515 | void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 516 | if (!gpu->glCaps().vertexArrayObjectSupport()) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 517 | SkASSERT(0 == arrayID); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 518 | return; |
| 519 | } |
| 520 | if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) { |
| 521 | GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID)); |
| 522 | fBoundVertexArrayIDIsValid = true; |
| 523 | fBoundVertexArrayID = arrayID; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 527 | /** |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 528 | * Binds the vertex array that should be used for internal draws, and returns its attrib |
| 529 | * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which |
| 530 | * case we use a dummy array instead. |
| 531 | * |
| 532 | * If an index buffer is privided, it will be bound to the vertex array. Otherwise the |
| 533 | * index buffer binding will be left unchanged. |
| 534 | * |
| 535 | * The returned GrGLAttribArrayState should be used to set vertex attribute arrays. |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 536 | */ |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 537 | GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrBuffer* ibuff = nullptr); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 538 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 539 | private: |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 540 | GrGLuint fBoundVertexArrayID; |
| 541 | bool fBoundVertexArrayIDIsValid; |
mtklein | 044d3c1 | 2016-04-06 18:24:34 -0700 | [diff] [blame] | 542 | |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 543 | // 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] | 544 | // is bound. However, this class is internal to GrGLGpu and this object never leaks out of |
| 545 | // GrGLGpu. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 546 | GrGLAttribArrayState fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 547 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 548 | // This is used when we're using a core profile. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 549 | GrGLVertexArray* fCoreProfileVertexArray; |
| 550 | } fHWVertexArrayState; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 551 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 552 | struct { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 553 | GrGLenum fGLTarget; |
| 554 | GrGpuResource::UniqueID fBoundBufferUniqueID; |
| 555 | bool fBufferZeroKnownBound; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 556 | |
| 557 | void invalidate() { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 558 | fBoundBufferUniqueID.makeInvalid(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 559 | fBufferZeroKnownBound = false; |
| 560 | } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 561 | } fHWBufferState[kGrBufferTypeCount]; |
cdalton | c161310 | 2016-03-16 07:48:20 -0700 | [diff] [blame] | 562 | |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 563 | struct { |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 564 | GrBlendEquation fEquation; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 565 | GrBlendCoeff fSrcCoeff; |
| 566 | GrBlendCoeff fDstCoeff; |
| 567 | GrColor fConstColor; |
| 568 | bool fConstColorValid; |
| 569 | TriState fEnabled; |
| 570 | |
| 571 | void invalidate() { |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 572 | fEquation = static_cast<GrBlendEquation>(-1); |
| 573 | fSrcCoeff = static_cast<GrBlendCoeff>(-1); |
| 574 | fDstCoeff = static_cast<GrBlendCoeff>(-1); |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 575 | fConstColorValid = false; |
| 576 | fEnabled = kUnknown_TriState; |
| 577 | } |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 578 | } fHWBlendState; |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 579 | |
bsalomon | 54c6fe8 | 2015-12-16 11:51:22 -0800 | [diff] [blame] | 580 | TriState fMSAAEnabled; |
| 581 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 582 | GrStencilSettings fHWStencilSettings; |
| 583 | TriState fHWStencilTestEnabled; |
bsalomon | 54c6fe8 | 2015-12-16 11:51:22 -0800 | [diff] [blame] | 584 | |
| 585 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 586 | TriState fHWWriteToColor; |
| 587 | GrGpuResource::UniqueID fHWBoundRenderTargetUniqueID; |
| 588 | TriState fHWSRGBFramebuffer; |
| 589 | SkTArray<GrGpuResource::UniqueID, true> fHWBoundTextureUniqueIDs; |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 590 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 591 | struct Image { |
| 592 | GrGpuResource::UniqueID fTextureUniqueID; |
| 593 | GrIOType fIOType; |
| 594 | }; |
| 595 | SkTArray<Image, true> fHWBoundImageStorages; |
| 596 | |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 597 | struct BufferTexture { |
| 598 | BufferTexture() : fTextureID(0), fKnownBound(false), |
| 599 | fAttachedBufferUniqueID(SK_InvalidUniqueID), |
| 600 | fSwizzle(GrSwizzle::RGBA()) {} |
| 601 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 602 | GrGLuint fTextureID; |
| 603 | bool fKnownBound; |
| 604 | GrPixelConfig fTexelConfig; |
| 605 | GrGpuResource::UniqueID fAttachedBufferUniqueID; |
| 606 | GrSwizzle fSwizzle; |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 607 | }; |
| 608 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 609 | SkTArray<BufferTexture, true> fHWBufferTextures; |
| 610 | int fHWMaxUsedBufferTextureUnit; |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 611 | |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 612 | // EXT_raster_multisample. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 613 | TriState fHWRasterMultisampleEnabled; |
| 614 | int fHWNumRasterSamples; |
bsalomon | 54c6fe8 | 2015-12-16 11:51:22 -0800 | [diff] [blame] | 615 | ///@} |
| 616 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 617 | /** IDs for copy surface program. (4 sampler types) */ |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 618 | struct { |
| 619 | GrGLuint fProgram; |
| 620 | GrGLint fTextureUniform; |
| 621 | GrGLint fTexCoordXformUniform; |
| 622 | GrGLint fPosXformUniform; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 623 | } fCopyPrograms[4]; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 624 | sk_sp<GrGLBuffer> fCopyProgramArrayBuffer; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 625 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 626 | /** IDs for texture mipmap program. (4 filter configurations) */ |
| 627 | struct { |
| 628 | GrGLuint fProgram; |
| 629 | GrGLint fTextureUniform; |
| 630 | GrGLint fTexCoordXformUniform; |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 631 | } fMipmapPrograms[4]; |
| 632 | sk_sp<GrGLBuffer> fMipmapProgramArrayBuffer; |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 633 | |
Mike Klein | 31550db | 2017-06-06 23:29:53 +0000 | [diff] [blame] | 634 | GrGLuint fStencilClipClearProgram; |
| 635 | sk_sp<GrGLBuffer> fStencilClipClearArrayBuffer; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 636 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 637 | static int TextureToCopyProgramIdx(GrTexture* texture); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 638 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 639 | static int TextureSizeToMipmapProgramIdx(int width, int height) { |
| 640 | const bool wide = (width > 1) && SkToBool(width & 0x1); |
| 641 | const bool tall = (height > 1) && SkToBool(height & 0x1); |
| 642 | return (wide ? 0x2 : 0x0) | (tall ? 0x1 : 0x0); |
| 643 | } |
| 644 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 645 | float fHWMinSampleShading; |
Brian Salomon | af971de | 2017-06-08 16:11:33 -0400 | [diff] [blame] | 646 | GrPrimitiveType fLastPrimitiveType; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 647 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 648 | typedef GrGpu INHERITED; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 649 | friend class GrGLPathRendering; // For accessing setTextureUnit. |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 650 | friend class gr_instanced::GLInstancedRendering; // For accessing flushGLState. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 651 | }; |
| 652 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 653 | #endif |