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