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