blob: f14bd2372103256cba4fa0c89880d3eb55465f7f [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comac10a2d2010-12-22 21:39:39 +00006 */
7
jvanverth39edf762014-12-22 11:44:19 -08008#ifndef GrGLGpu_DEFINED
9#define GrGLGpu_DEFINED
reed@google.comac10a2d2010-12-22 21:39:39 +000010
robertphillips@google.com6177e692013-02-28 20:16:25 +000011#include "GrGLContext.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000012#include "GrGLIRect.h"
kkinnunenccdaa042014-08-20 01:36:23 -070013#include "GrGLPathRendering.h"
bsalomon@google.com5739d2c2012-05-31 15:07:19 +000014#include "GrGLProgram.h"
bsalomon37dd3312014-11-03 08:47:23 -080015#include "GrGLRenderTarget.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070016#include "GrGLStencilAttachment.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000017#include "GrGLTexture.h"
bsalomon@google.com6918d482013-03-07 19:09:11 +000018#include "GrGLVertexArray.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000019#include "GrGpu.h"
Chris Dalton114a3c02017-05-26 15:17:19 -060020#include "GrMesh.h"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070021#include "GrWindowRectsState.h"
egdaniel080e6732014-12-22 07:35:52 -080022#include "GrXferProcessor.h"
Ethan Nicholas1b9924f2016-12-15 15:28:42 -050023#include "SkLRUCache.h"
cblume55f2d2d2016-02-26 13:20:48 -080024#include "SkTArray.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000025#include "SkTypes.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000026
cdalton397536c2016-03-25 12:15:03 -070027class GrGLBuffer;
Robert Phillips5b5d84c2018-08-09 15:12:18 -040028class GrGLGpuRTCommandBuffer;
29class GrGLGpuTextureCommandBuffer;
egdaniel8dd688b2015-01-22 10:16:09 -080030class GrPipeline;
bsalomon7f9b2e42016-01-12 13:29:26 -080031class GrSwizzle;
egdaniel8dd688b2015-01-22 10:16:09 -080032
djsollenefe46d22016-04-29 06:41:35 -070033#ifdef SK_DEBUG
jvanverth@google.com94878772013-03-12 16:00:54 +000034#define PROGRAM_CACHE_STATS
35#endif
36
Chris Dalton114a3c02017-05-26 15:17:19 -060037class GrGLGpu final : public GrGpu, private GrMesh::SendToGpuImpl {
reed@google.comac10a2d2010-12-22 21:39:39 +000038public:
Robert Phillipse42edcc2017-12-13 11:50:22 -050039 static sk_sp<GrGpu> Make(sk_sp<const GrGLInterface>, const GrContextOptions&, GrContext*);
mtklein36352bf2015-03-25 18:17:31 -070040 ~GrGLGpu() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000041
bsalomon6e2aad42016-04-01 11:54:31 -070042 void disconnect(DisconnectType) override;
bsalomonc8dc1f72014-08-21 13:02:13 -070043
bsalomon424cc262015-05-22 10:37:30 -070044 const GrGLContext& glContext() const { return *fGLContext; }
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000045
bsalomon424cc262015-05-22 10:37:30 -070046 const GrGLInterface* glInterface() const { return fGLContext->interface(); }
47 const GrGLContextInfo& ctxInfo() const { return *fGLContext; }
48 GrGLStandard glStandard() const { return fGLContext->standard(); }
49 GrGLVersion glVersion() const { return fGLContext->version(); }
50 GrGLSLGeneration glslGeneration() const { return fGLContext->glslGeneration(); }
51 const GrGLCaps& glCaps() const { return *fGLContext->caps(); }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000052
kkinnunenccdaa042014-08-20 01:36:23 -070053 GrGLPathRendering* glPathRendering() {
jvanverthe9c0fc62015-04-29 11:18:05 -070054 SkASSERT(glCaps().shaderCaps()->pathRenderingSupport());
kkinnunenccdaa042014-08-20 01:36:23 -070055 return static_cast<GrGLPathRendering*>(pathRendering());
cdaltonc7103a12014-08-11 14:05:05 -070056 }
57
kkinnunencfe62e32015-07-01 02:58:50 -070058 // Used by GrGLProgram to configure OpenGL state.
Brian Salomondc829942018-10-23 16:07:24 -040059 void bindTexture(int unitIdx, GrSamplerState samplerState, GrGLTexture* texture);
kkinnunenccdaa042014-08-20 01:36:23 -070060
bsalomon@google.com6918d482013-03-07 19:09:11 +000061 // These functions should be used to bind GL objects. They track the GL state and skip redundant
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +000062 // bindings. Making the equivalent glBind calls directly will confuse the state tracking.
bsalomon@google.com6918d482013-03-07 19:09:11 +000063 void bindVertexArray(GrGLuint id) {
cdaltone2e71c22016-04-07 18:13:29 -070064 fHWVertexArrayState.setVertexArrayID(this, id);
bsalomon@google.com6918d482013-03-07 19:09:11 +000065 }
66
67 // These callbacks update state tracking when GL objects are deleted. They are called from
68 // GrGLResource onRelease functions.
69 void notifyVertexArrayDelete(GrGLuint id) {
cdaltone2e71c22016-04-07 18:13:29 -070070 fHWVertexArrayState.notifyVertexArrayDelete(id);
bsalomon@google.com6918d482013-03-07 19:09:11 +000071 }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +000072
cdaltone2e71c22016-04-07 18:13:29 -070073 // Binds a buffer to the GL target corresponding to 'type', updates internal state tracking, and
74 // returns the GL target the buffer was bound to.
75 // When 'type' is kIndex_GrBufferType, this function will also implicitly bind the default VAO.
76 // If the caller wishes to bind an index buffer to a specific VAO, it can call glBind directly.
Brian Salomonae64c192019-02-05 09:41:37 -050077 GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer*);
joshualitt93316b92015-10-23 09:08:08 -070078
Greg Daniel500d58b2017-08-24 15:59:33 -040079 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -070080 // Thus this is the implementation of the draw call for the corresponding passthrough function
Greg Daniel500d58b2017-08-24 15:59:33 -040081 // on GrGLRTGpuCommandBuffer.
Robert Phillipsd0fe8752019-01-31 14:13:59 -050082 void draw(GrRenderTarget*, GrSurfaceOrigin,
83 const GrPrimitiveProcessor&,
Brian Salomonff168d92018-06-23 15:17:27 -040084 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -040085 const GrPipeline::FixedDynamicState*,
86 const GrPipeline::DynamicStateArrays*,
Chris Dalton46983b72017-06-06 12:27:16 -060087 const GrMesh[],
egdaniel9cb63402016-06-23 08:37:05 -070088 int meshCount);
89
Chris Dalton114a3c02017-05-26 15:17:19 -060090 // GrMesh::SendToGpuImpl methods. These issue the actual GL draw calls.
91 // Marked final as a hint to the compiler to not use virtual dispatch.
Brian Salomon802cb312018-06-08 18:05:20 -040092 void sendMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount,
93 int baseVertex) final;
Chris Dalton114a3c02017-05-26 15:17:19 -060094
Brian Salomon802cb312018-06-08 18:05:20 -040095 void sendIndexedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount,
96 int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue,
97 const GrBuffer* vertexBuffer, int baseVertex,
98 GrPrimitiveRestart) final;
Chris Dalton114a3c02017-05-26 15:17:19 -060099
Brian Salomon802cb312018-06-08 18:05:20 -0400100 void sendInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount,
101 int baseVertex, const GrBuffer* instanceBuffer, int instanceCount,
Chris Dalton1d616352017-05-31 12:51:23 -0600102 int baseInstance) final;
103
Brian Salomon802cb312018-06-08 18:05:20 -0400104 void sendIndexedInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount,
105 int baseIndex, const GrBuffer* vertexBuffer, int baseVertex,
Chris Dalton1d616352017-05-31 12:51:23 -0600106 const GrBuffer* instanceBuffer, int instanceCount,
Brian Salomon802cb312018-06-08 18:05:20 -0400107 int baseInstance, GrPrimitiveRestart) final;
Chris Dalton1d616352017-05-31 12:51:23 -0600108
Greg Daniel500d58b2017-08-24 15:59:33 -0400109 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700110 // Thus this is the implementation of the clear call for the corresponding passthrough function
Greg Daniel500d58b2017-08-24 15:59:33 -0400111 // on GrGLGpuRTCommandBuffer.
Brian Osman9a9baae2018-11-05 15:06:26 -0500112 void clear(const GrFixedClip&, const SkPMColor4f&, GrRenderTarget*, GrSurfaceOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700113
Greg Daniel500d58b2017-08-24 15:59:33 -0400114 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700115 // Thus this is the implementation of the clearStencil call for the corresponding passthrough
Greg Daniel500d58b2017-08-24 15:59:33 -0400116 // function on GrGLGpuRTCommandBuffer.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400117 void clearStencilClip(const GrFixedClip&, bool insideStencilMask,
118 GrRenderTarget*, GrSurfaceOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700119
Michael Ludwigc39d0c82019-01-15 10:03:43 -0500120 // FIXME (michaelludwig): Can this go away and just use clearStencilClip() + marking the
121 // stencil buffer as not dirty?
Greg Danielcfa39352018-10-05 12:01:59 -0400122 void clearStencil(GrRenderTarget*, int clearValue);
egdanielec00d942015-09-14 12:56:10 -0700123
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400124 GrGpuRTCommandBuffer* getCommandBuffer(
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400125 GrRenderTarget*, GrSurfaceOrigin, const SkRect&,
Greg Daniel500d58b2017-08-24 15:59:33 -0400126 const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
127 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
128
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400129 GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
egdaniel066df7c2016-06-08 14:02:27 -0700130
egdanielec00d942015-09-14 12:56:10 -0700131 void invalidateBoundRenderTarget() {
Robert Phillips294870f2016-11-11 12:38:40 -0500132 fHWBoundRenderTargetUniqueID.makeInvalid();
egdanielec00d942015-09-14 12:56:10 -0700133 }
134
135 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
136 int width,
137 int height) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500138#if GR_TEST_UTILS
Brian Salomon52e943a2018-03-13 09:32:39 -0400139 GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
Robert Phillips646f6372018-09-25 09:31:10 -0400140 GrColorType colorType, bool isRenderTarget,
141 GrMipMapped mipMapped,
142 size_t rowBytes = 0) override;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500143 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Brian Salomon26102cb2018-03-09 09:33:19 -0500144 void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
jvanverth672bb7f2015-07-13 07:19:57 -0700145
Brian Osman2d010b62018-08-09 10:55:09 -0400146 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500147
148 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
149
150 const GrGLContext* glContextForTesting() const override { return &this->glContext(); }
151
152 void resetShaderCacheForTesting() const override { fProgramCache->abandon(); }
joshualitt8fd844f2015-12-02 13:36:47 -0800153
Greg Daniel26b50a42018-03-08 09:49:58 -0500154 void testingOnly_flushGpuAndSync() override;
Brian Salomonf865b052018-03-09 09:01:53 -0500155#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500156
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400157 void submit(GrGpuCommandBuffer* buffer) override;
158
Greg Daniel6be35232017-03-01 17:01:09 -0500159 GrFence SK_WARN_UNUSED_RESULT insertFence() override;
160 bool waitFence(GrFence, uint64_t timeout) override;
jvanverth84741b32016-09-30 08:39:02 -0700161 void deleteFence(GrFence) const override;
162
Greg Daniela5cb7812017-06-16 09:45:32 -0400163 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override;
Greg Daniel48661b82018-01-22 16:11:35 -0500164 sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
165 GrResourceProvider::SemaphoreWrapType wrapType,
166 GrWrapOwnership ownership) override;
Greg Daniel858e12c2018-12-06 11:11:37 -0500167 void insertSemaphore(sk_sp<GrSemaphore> semaphore) override;
Greg Daniel48661b82018-01-22 16:11:35 -0500168 void waitSemaphore(sk_sp<GrSemaphore> semaphore) override;
Greg Daniel6be35232017-03-01 17:01:09 -0500169
Brian Osman13dddce2017-05-09 13:19:50 -0400170 sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
171
Greg Daniel6be35232017-03-01 17:01:09 -0500172 void deleteSync(GrGLsync) const;
173
Robert Phillips65a88fa2017-08-08 08:36:22 -0400174 void insertEventMarker(const char*);
175
Adrienne Walker4ee88512018-05-17 11:37:14 -0700176 void bindFramebuffer(GrGLenum fboTarget, GrGLuint fboid);
177 void deleteFramebuffer(GrGLuint fboid);
Adrienne Walker3ed33992018-05-15 11:44:34 -0700178
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000179private:
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500180 GrGLGpu(std::unique_ptr<GrGLContext>, GrContext*);
bsalomon424cc262015-05-22 10:37:30 -0700181
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000182 // GrGpu overrides
mtklein36352bf2015-03-25 18:17:31 -0700183 void onResetContext(uint32_t resetBits) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000184
Brian Salomon1f05d452019-02-08 12:33:08 -0500185 void onResetTextureBindings() override;
186
bsalomoncb02b382015-08-12 11:14:50 -0700187 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
188
Robert Phillips67d52cf2017-06-05 13:38:13 -0400189 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
Brian Salomon58389b92018-03-07 13:01:25 -0500190 const GrMipLevel texels[], int mipLevelCount) override;
cblume55f2d2d2016-02-26 13:20:48 -0800191
Brian Salomondbf70722019-02-07 11:31:24 -0500192 sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern,
193 const void* data) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000194
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500195 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
196 GrIOType) override;
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500197 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
198 GrWrapOwnership, GrWrapCacheable) override;
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400199 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000200 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Greg Daniel7ef28f32017-04-20 16:41:55 +0000201 int sampleCnt) override;
csmartdaltone0d36292016-07-29 08:14:20 -0700202
egdanielff1d5472015-09-10 08:37:20 -0700203 // Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a
bsalomon62a627b2015-12-17 09:50:47 -0800204 // compatible stencil format, or negative if there is no compatible stencil format.
egdanielff1d5472015-09-10 08:37:20 -0700205 int getCompatibleStencilIndex(GrPixelConfig config);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000206
Adrienne Walkerca0cdef2018-08-20 13:49:40 -0700207 void onFBOChanged();
bsalomon7e68ab72016-04-13 14:29:25 -0700208
erikchen9a1ed5d2016-02-10 16:32:34 -0800209 // Returns whether the texture is successfully created. On success, the
210 // result is stored in |info|.
cblume55f2d2d2016-02-26 13:20:48 -0800211 // The texture is populated with |texels|, if it exists.
erikchen9a1ed5d2016-02-10 16:32:34 -0800212 // The texture parameters are cached in |initialTexParams|.
Brian Salomon2a4f9832018-03-03 22:43:43 -0500213 bool createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info, bool renderTarget,
Brian Salomondc829942018-10-23 16:07:24 -0400214 GrGLTexture::SamplerParams* initialTexParams, const GrMipLevel texels[],
Brian Salomon58389b92018-03-07 13:01:25 -0500215 int mipLevelCount, GrMipMapsStatus* mipMapsStatus);
erikchen9a1ed5d2016-02-10 16:32:34 -0800216
bsalomon1aa20292016-01-22 08:16:09 -0800217 // Checks whether glReadPixels can be called to get pixel values in readConfig from the
218 // render target.
219 bool readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConfig);
220
221 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
222 // render target that has renderTargetConfig. This may have to create a temporary
223 // render target and thus is less preferable than the variant that takes a render target.
224 bool readPixelsSupported(GrPixelConfig renderTargetConfig, GrPixelConfig readConfig);
225
226 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
227 // render target that has the same config as surfaceForConfig. Calls one of the the two
228 // variations above, depending on whether the surface is a render target or not.
229 bool readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig readConfig);
230
Brian Salomona6948702018-06-01 15:33:20 -0400231 bool onReadPixels(GrSurface*, int left, int top, int width, int height, GrColorType,
232 void* buffer, size_t rowBytes) override;
bsalomond95263c2014-12-16 13:05:12 -0800233
Brian Salomona9b04b92018-06-01 15:04:28 -0400234 bool onWritePixels(GrSurface*, int left, int top, int width, int height, GrColorType,
235 const GrMipLevel texels[], int mipLevelCount) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000236
Brian Salomonc320b152018-02-20 14:05:36 -0500237 bool onTransferPixels(GrTexture*, int left, int top, int width, int height, GrColorType,
Brian Salomondbf70722019-02-07 11:31:24 -0500238 GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
jvanverth17aa0472016-01-05 10:41:27 -0800239
Brian Osman9b560242017-09-05 15:34:52 -0400240 // Before calling any variation of TexImage, TexSubImage, etc..., call this to ensure that the
241 // PIXEL_UNPACK_BUFFER is unbound.
242 void unbindCpuToGpuXferBuffer();
243
Brian Salomon1fabd512018-02-09 09:54:25 -0500244 void onResolveRenderTarget(GrRenderTarget* target) override;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000245
Brian Salomon930f9392018-06-20 16:25:26 -0400246 bool onRegenerateMipMapLevels(GrTexture*) override;
247
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400248 bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin,
249 GrSurface* src, GrSurfaceOrigin srcOrigin,
Greg Daniel55fa6472018-03-16 16:13:10 -0400250 const SkIRect& srcRect, const SkIPoint& dstPoint,
251 bool canDiscardOutsideDstRect) override;
joshualitt1cbdcde2015-08-21 11:53:29 -0700252
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000253 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000254 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000255
Brian Salomonf7232642018-09-19 08:58:08 -0400256 /**
257 * primitiveProcessorTextures must contain GrPrimitiveProcessor::numTextureSamplers() *
258 * numPrimitiveProcessorTextureSets entries.
259 */
260 void resolveAndGenerateMipMapsForProcessorTextures(
Brian Salomon7eae3e02018-08-07 14:02:38 +0000261 const GrPrimitiveProcessor&, const GrPipeline&,
Brian Salomonf7232642018-09-19 08:58:08 -0400262 const GrTextureProxy* const primitiveProcessorTextures[],
263 int numPrimitiveProcessorTextureSets);
Brian Salomondfec99f2018-08-02 10:40:05 -0400264
egdaniel8dd688b2015-01-22 10:16:09 -0800265 // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set.
bsalomon2eda5b32016-09-21 10:53:24 -0700266 // willDrawPoints must be true if point primitives will be rendered after setting the GL state.
Brian Salomonf7232642018-09-19 08:58:08 -0400267 // If DynamicStateArrays is not null then dynamicStateArraysLength is the number of dynamic
268 // state entries in each array.
Robert Phillipsd0fe8752019-01-31 14:13:59 -0500269 bool flushGLState(GrRenderTarget*, GrSurfaceOrigin, const GrPrimitiveProcessor&,
270 const GrPipeline&, const GrPipeline::FixedDynamicState*,
271 const GrPipeline::DynamicStateArrays*, int dynamicStateArraysLength,
272 bool willDrawPoints);
bsalomond95263c2014-12-16 13:05:12 -0800273
Brian Salomon802cb312018-06-08 18:05:20 -0400274 void flushProgram(sk_sp<GrGLProgram>);
275
276 // Version for programs that aren't GrGLProgram.
277 void flushProgram(GrGLuint);
278
Chris Dalton114a3c02017-05-26 15:17:19 -0600279 // Sets up vertex/instance attribute pointers and strides.
Brian Salomon802cb312018-06-08 18:05:20 -0400280 void setupGeometry(const GrBuffer* indexBuffer,
Chris Daltonff926502017-05-03 14:36:54 -0400281 const GrBuffer* vertexBuffer,
Chris Dalton1d616352017-05-31 12:51:23 -0600282 int baseVertex,
283 const GrBuffer* instanceBuffer,
Brian Salomon802cb312018-06-08 18:05:20 -0400284 int baseInstance,
285 GrPrimitiveRestart);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000286
bsalomon7f9b2e42016-01-12 13:29:26 -0800287 void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000288
Greg Daniel51316782017-08-02 15:10:09 +0000289 void onFinishFlush(bool insertedSemaphores) override;
290
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400291 bool copySurfaceAsDraw(GrSurface* dst, GrSurfaceOrigin dstOrigin,
292 GrSurface* src, GrSurfaceOrigin srcOrigin,
293 const SkIRect& srcRect, const SkIPoint& dstPoint);
294 void copySurfaceAsCopyTexSubImage(GrSurface* dst, GrSurfaceOrigin dstOrigin,
295 GrSurface* src, GrSurfaceOrigin srcOrigin,
296 const SkIRect& srcRect, const SkIPoint& dstPoint);
297 bool copySurfaceAsBlitFramebuffer(GrSurface* dst, GrSurfaceOrigin dstOrigin,
298 GrSurface* src, GrSurfaceOrigin srcOrigin,
299 const SkIRect& srcRect, const SkIPoint& dstPoint);
bsalomon6df86402015-06-01 10:41:49 -0700300
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000301 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
bsalomon@google.com080773c2011-03-15 19:09:25 +0000302
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000303 class ProgramCache : public ::SkNoncopyable {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000304 public:
bsalomon861e1032014-12-16 07:33:49 -0800305 ProgramCache(GrGLGpu* gpu);
jvanverth@google.com94878772013-03-12 16:00:54 +0000306 ~ProgramCache();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000307
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000308 void abandon();
Robert Phillipsd0fe8752019-01-31 14:13:59 -0500309 GrGLProgram* refProgram(GrGLGpu*, GrRenderTarget*, GrSurfaceOrigin,
310 const GrPrimitiveProcessor&,
Greg Daniel9a51a862018-11-30 10:18:14 -0500311 const GrTextureProxy* const primProcProxies[],
312 const GrPipeline&, bool hasPointSize);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000313
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000314 private:
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500315 // We may actually have kMaxEntries+1 shaders in the GL context because we create a new
316 // shader before evicting from the cache.
317 static const int kMaxEntries = 128;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000318
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000319 struct Entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000320
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000321 // binary search for entry matching desc. returns index into fEntries that matches desc or ~
322 // of the index of where it should be inserted.
joshualitt79f8fae2014-10-28 17:59:26 -0700323 int search(const GrProgramDesc& desc) const;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000324
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500325 struct DescHash {
326 uint32_t operator()(const GrProgramDesc& desc) const {
327 return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);
328 }
329 };
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000330
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500331 SkLRUCache<GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap;
332
bsalomon861e1032014-12-16 07:33:49 -0800333 GrGLGpu* fGpu;
jvanverth@google.com94878772013-03-12 16:00:54 +0000334#ifdef PROGRAM_CACHE_STATS
335 int fTotalRequests;
336 int fCacheMisses;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000337 int fHashMisses; // cache hit but hash table missed
jvanverth@google.com94878772013-03-12 16:00:54 +0000338#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000339 };
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000340
egdaniel080e6732014-12-22 07:35:52 -0800341 void flushColorWrite(bool writeColor);
Brian Salomon805cc7a2019-01-28 09:52:34 -0500342 void flushClearColor(GrGLfloat r, GrGLfloat g, GrGLfloat b, GrGLfloat a);
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000343
Brian Salomond818ebf2018-07-02 14:08:49 +0000344 // flushes the scissor. see the note on flushBoundTextureAndParams about
345 // flushing the scissor after that function is called.
346 void flushScissor(const GrScissorState&,
347 const GrGLIRect& rtViewport,
348 GrSurfaceOrigin rtOrigin);
349
350 // disables the scissor
351 void disableScissor();
bsalomon@google.coma3201942012-06-21 19:58:20 +0000352
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400353 void flushWindowRectangles(const GrWindowRectsState&, const GrGLRenderTarget*, GrSurfaceOrigin);
csmartdalton28341fa2016-08-17 10:00:21 -0700354 void disableWindowRectangles();
355
Brian Salomond978b902019-02-07 15:09:18 -0500356 int numTextureUnits() const { return this->caps()->shaderCaps()->maxFragmentSamplers(); }
357
358 // Binds a texture to a target on the "scratch" texture unit to use for texture operations
359 // other than usual draw flow (i.e. a GrGLProgram derived from a GrPipeline used to draw
360 // GrMesh). It ensures that such operations don't negatively interact with draws.
361 // The active texture unit and the binding for 'target' will change.
362 void bindTextureToScratchUnit(GrGLenum target, GrGLint textureID);
reed@google.comac10a2d2010-12-22 21:39:39 +0000363
Brian Salomon1fabd512018-02-09 09:54:25 -0500364 // The passed bounds contains the render target's color values that will subsequently be
365 // written.
Chris Daltonc8ece3d2018-07-30 15:03:45 -0600366 void flushRenderTarget(GrGLRenderTarget*, GrSurfaceOrigin, const SkIRect& bounds);
367 // This version has an implicit bounds of the entire render target.
368 void flushRenderTarget(GrGLRenderTarget*);
Brian Salomon1fabd512018-02-09 09:54:25 -0500369 // This version can be used when the render target's colors will not be written.
Brian Osman9aa30c62018-07-02 15:21:46 -0400370 void flushRenderTargetNoColorWrites(GrGLRenderTarget*);
bsalomon083617b2016-02-12 12:10:14 -0800371
372 // Need not be called if flushRenderTarget is used.
373 void flushViewport(const GrGLIRect&);
bsalomonb0bd4f62014-09-03 07:19:50 -0700374
bsalomon3e791242014-12-17 13:43:13 -0800375 void flushStencil(const GrStencilSettings&);
csmartdaltonc7d85332016-10-26 10:13:46 -0700376 void disableStencil();
bsalomon083617b2016-02-12 12:10:14 -0800377
378 // rt is used only if useHWAA is true.
cdaltonaf8bc7d2016-02-05 09:35:20 -0800379 void flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabled);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000380
brianosman33f6b3f2016-06-02 05:49:21 -0700381 void flushFramebufferSRGB(bool enable);
382
bsalomon@google.com6f379512011-11-16 20:36:03 +0000383 // helper for onCreateTexture and writeTexturePixels
jvanverth17aa0472016-01-05 10:41:27 -0800384 enum UploadType {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400385 kNewTexture_UploadType, // we are creating a new texture
386 kWrite_UploadType, // we are using TexSubImage2D to copy data to an existing texture
jvanverth17aa0472016-01-05 10:41:27 -0800387 };
Brian Salomona9b04b92018-06-01 15:04:28 -0400388 bool uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight, GrGLenum target,
389 UploadType uploadType, int left, int top, int width, int height,
390 GrPixelConfig dataConfig, const GrMipLevel texels[], int mipLevelCount,
Greg Daniel0fc4d2d2017-10-12 11:23:36 -0400391 GrMipMapsStatus* mipMapsStatus = nullptr);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000392
Jim Van Verth1676cb92019-01-15 13:24:45 -0500393 // helper for onCreateCompressedTexture. Compressed textures are read-only so we
394 // only use this to populate a new texture.
395 bool uploadCompressedTexData(GrPixelConfig texConfig, int texWidth, int texHeight,
396 GrGLenum target, GrPixelConfig dataConfig,
397 const GrMipLevel texels[], int mipLevelCount,
398 GrMipMapsStatus* mipMapsStatus = nullptr);
399
kkinnunen2e6055b2016-04-22 01:48:29 -0700400 bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo,
401 GrGLRenderTarget::IDDesc*);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000402
egdanield803f272015-03-18 13:01:52 -0700403 enum TempFBOTarget {
404 kSrc_TempFBOTarget,
405 kDst_TempFBOTarget
406 };
egdaniel0f5f9672015-02-03 11:10:51 -0800407
Brian Salomond17b4a62017-05-23 16:53:47 -0400408 // Binds a surface as a FBO for copying, reading, or clearing. If the surface already owns an
409 // FBO ID then that ID is bound. If not the surface is temporarily bound to a FBO and that FBO
410 // is bound. This must be paired with a call to unbindSurfaceFBOForPixelOps().
Brian Salomon71d9d842016-11-03 13:42:00 -0400411 void bindSurfaceFBOForPixelOps(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport,
412 TempFBOTarget tempFBOTarget);
egdaniel0f5f9672015-02-03 11:10:51 -0800413
Brian Salomon71d9d842016-11-03 13:42:00 -0400414 // Must be called if bindSurfaceFBOForPixelOps was used to bind a surface for copying.
415 void unbindTextureFBOForPixelOps(GrGLenum fboTarget, GrSurface* surface);
robertphillips754f4e92014-09-18 13:52:08 -0700416
Kevin Lubickf4def342018-10-04 12:52:50 -0400417#ifdef SK_ENABLE_DUMP_GPU
Brian Osman71a18892017-08-10 10:23:25 -0400418 void onDumpJSON(SkJSONWriter*) const override;
Kevin Lubickf4def342018-10-04 12:52:50 -0400419#endif
Brian Osman71a18892017-08-10 10:23:25 -0400420
Brian Salomonbf7b6202016-11-11 16:08:03 -0500421 bool createCopyProgram(GrTexture* srcTexture);
brianosman33f6b3f2016-06-02 05:49:21 -0700422 bool createMipmapProgram(int progIdx);
ethannicholas22793252016-01-30 09:59:10 -0800423
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500424 std::unique_ptr<GrGLContext> fGLContext;
425
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000426 // GL program-related state
427 ProgramCache* fProgramCache;
bsalomon@google.com49209392012-06-05 15:13:46 +0000428
429 ///////////////////////////////////////////////////////////////////////////
430 ///@name Caching of GL State
431 ///@{
432 int fHWActiveTextureUnitIdx;
Brian Salomon802cb312018-06-08 18:05:20 -0400433
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000434 GrGLuint fHWProgramID;
Brian Salomon802cb312018-06-08 18:05:20 -0400435 sk_sp<GrGLProgram> fHWProgram;
bsalomon@google.com91207482013-02-12 21:45:24 +0000436
bsalomon@google.com49209392012-06-05 15:13:46 +0000437 enum TriState {
438 kNo_TriState,
439 kYes_TriState,
440 kUnknown_TriState
441 };
442
egdanield803f272015-03-18 13:01:52 -0700443 GrGLuint fTempSrcFBOID;
444 GrGLuint fTempDstFBOID;
445
446 GrGLuint fStencilClearFBOID;
bsalomondd3143b2015-02-23 09:27:45 -0800447
bsalomon@google.coma3201942012-06-21 19:58:20 +0000448 // last scissor / viewport scissor state seen by the GL.
449 struct {
450 TriState fEnabled;
451 GrGLIRect fRect;
452 void invalidate() {
453 fEnabled = kUnknown_TriState;
454 fRect.invalidate();
455 }
456 } fHWScissorSettings;
457
csmartdalton28341fa2016-08-17 10:00:21 -0700458 class {
459 public:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700460 bool valid() const { return kInvalidSurfaceOrigin != fRTOrigin; }
461 void invalidate() { fRTOrigin = kInvalidSurfaceOrigin; }
462 bool knownDisabled() const { return this->valid() && !fWindowState.enabled(); }
mtklein8b4a2022016-09-26 08:44:47 -0700463 void setDisabled() {
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400464 fRTOrigin = kTopLeft_GrSurfaceOrigin;
mtklein8b4a2022016-09-26 08:44:47 -0700465 fWindowState.setDisabled();
466 }
csmartdalton28341fa2016-08-17 10:00:21 -0700467
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700468 void set(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
469 const GrWindowRectsState& windowState) {
470 fRTOrigin = rtOrigin;
471 fViewport = viewport;
472 fWindowState = windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700473 }
csmartdalton28341fa2016-08-17 10:00:21 -0700474
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700475 bool knownEqualTo(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
476 const GrWindowRectsState& windowState) const {
csmartdalton28341fa2016-08-17 10:00:21 -0700477 if (!this->valid()) {
478 return false;
479 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700480 if (fWindowState.numWindows() && (fRTOrigin != rtOrigin || fViewport != viewport)) {
csmartdalton28341fa2016-08-17 10:00:21 -0700481 return false;
482 }
Brian Salomon9a767722017-03-13 17:57:28 -0400483 return fWindowState == windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700484 }
485
486 private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700487 enum { kInvalidSurfaceOrigin = -1 };
csmartdalton28341fa2016-08-17 10:00:21 -0700488
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700489 int fRTOrigin;
csmartdalton28341fa2016-08-17 10:00:21 -0700490 GrGLIRect fViewport;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700491 GrWindowRectsState fWindowState;
492 } fHWWindowRectsState;
csmartdalton28341fa2016-08-17 10:00:21 -0700493
bsalomon424cc262015-05-22 10:37:30 -0700494 GrGLIRect fHWViewport;
bsalomon@google.coma3201942012-06-21 19:58:20 +0000495
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000496 /**
cdaltone2e71c22016-04-07 18:13:29 -0700497 * Tracks vertex attrib array state.
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000498 */
cdaltone2e71c22016-04-07 18:13:29 -0700499 class HWVertexArrayState {
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000500 public:
cdaltone2e71c22016-04-07 18:13:29 -0700501 HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); }
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000502
cdaltone2e71c22016-04-07 18:13:29 -0700503 ~HWVertexArrayState() { delete fCoreProfileVertexArray; }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000504
bsalomon@google.com6918d482013-03-07 19:09:11 +0000505 void invalidate() {
506 fBoundVertexArrayIDIsValid = false;
bsalomon@google.com6918d482013-03-07 19:09:11 +0000507 fDefaultVertexArrayAttribState.invalidate();
cdaltone2e71c22016-04-07 18:13:29 -0700508 if (fCoreProfileVertexArray) {
509 fCoreProfileVertexArray->invalidateCachedState();
commit-bot@chromium.orgce6da4d2013-09-09 14:55:37 +0000510 }
bsalomon@google.com6918d482013-03-07 19:09:11 +0000511 }
512
513 void notifyVertexArrayDelete(GrGLuint id) {
514 if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) {
515 // Does implicit bind to 0
516 fBoundVertexArrayID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000517 }
518 }
519
bsalomon861e1032014-12-16 07:33:49 -0800520 void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000521 if (!gpu->glCaps().vertexArrayObjectSupport()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000522 SkASSERT(0 == arrayID);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000523 return;
524 }
525 if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) {
526 GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID));
527 fBoundVertexArrayIDIsValid = true;
528 fBoundVertexArrayID = arrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000529 }
530 }
531
bsalomon@google.com6918d482013-03-07 19:09:11 +0000532 /**
cdaltone2e71c22016-04-07 18:13:29 -0700533 * Binds the vertex array that should be used for internal draws, and returns its attrib
534 * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which
535 * case we use a dummy array instead.
536 *
537 * If an index buffer is privided, it will be bound to the vertex array. Otherwise the
538 * index buffer binding will be left unchanged.
539 *
540 * The returned GrGLAttribArrayState should be used to set vertex attribute arrays.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000541 */
csmartdalton485a1202016-07-13 10:16:32 -0700542 GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrBuffer* ibuff = nullptr);
bsalomon6df86402015-06-01 10:41:49 -0700543
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000544 private:
Robert Phillips294870f2016-11-11 12:38:40 -0500545 GrGLuint fBoundVertexArrayID;
546 bool fBoundVertexArrayIDIsValid;
mtklein044d3c12016-04-06 18:24:34 -0700547
bsalomon@google.com6918d482013-03-07 19:09:11 +0000548 // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
jvanverth39edf762014-12-22 11:44:19 -0800549 // is bound. However, this class is internal to GrGLGpu and this object never leaks out of
550 // GrGLGpu.
Robert Phillips294870f2016-11-11 12:38:40 -0500551 GrGLAttribArrayState fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000552
cdaltone2e71c22016-04-07 18:13:29 -0700553 // This is used when we're using a core profile.
Robert Phillips294870f2016-11-11 12:38:40 -0500554 GrGLVertexArray* fCoreProfileVertexArray;
555 } fHWVertexArrayState;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000556
cdaltone2e71c22016-04-07 18:13:29 -0700557 struct {
Robert Phillips294870f2016-11-11 12:38:40 -0500558 GrGLenum fGLTarget;
559 GrGpuResource::UniqueID fBoundBufferUniqueID;
560 bool fBufferZeroKnownBound;
cdaltone2e71c22016-04-07 18:13:29 -0700561
562 void invalidate() {
Robert Phillips294870f2016-11-11 12:38:40 -0500563 fBoundBufferUniqueID.makeInvalid();
cdaltone2e71c22016-04-07 18:13:29 -0700564 fBufferZeroKnownBound = false;
565 }
Brian Salomonae64c192019-02-05 09:41:37 -0500566 } fHWBufferState[kGrGpuBufferTypeCount];
567
568 auto* hwBufferState(GrGpuBufferType type) {
569 unsigned typeAsUInt = static_cast<unsigned>(type);
570 SkASSERT(typeAsUInt < SK_ARRAY_COUNT(fHWBufferState));
571 return &fHWBufferState[typeAsUInt];
572 }
cdaltonc1613102016-03-16 07:48:20 -0700573
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000574 struct {
cdalton8917d622015-05-06 13:40:21 -0700575 GrBlendEquation fEquation;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000576 GrBlendCoeff fSrcCoeff;
577 GrBlendCoeff fDstCoeff;
Brian Osman422f95b2018-11-05 16:49:04 -0500578 SkPMColor4f fConstColor;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000579 bool fConstColorValid;
580 TriState fEnabled;
581
582 void invalidate() {
Mike Klein36743362018-11-06 08:23:30 -0500583 fEquation = kIllegal_GrBlendEquation;
584 fSrcCoeff = kIllegal_GrBlendCoeff;
585 fDstCoeff = kIllegal_GrBlendCoeff;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000586 fConstColorValid = false;
587 fEnabled = kUnknown_TriState;
588 }
Robert Phillips294870f2016-11-11 12:38:40 -0500589 } fHWBlendState;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000590
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400591 TriState fMSAAEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800592
Robert Phillips294870f2016-11-11 12:38:40 -0500593 GrStencilSettings fHWStencilSettings;
594 TriState fHWStencilTestEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800595
596
Robert Phillips294870f2016-11-11 12:38:40 -0500597 TriState fHWWriteToColor;
598 GrGpuResource::UniqueID fHWBoundRenderTargetUniqueID;
599 TriState fHWSRGBFramebuffer;
Brian Salomond978b902019-02-07 15:09:18 -0500600
601 class TextureUnitBindings {
602 public:
603 TextureUnitBindings() = default;
604 TextureUnitBindings(const TextureUnitBindings&) = delete;
605 TextureUnitBindings& operator=(const TextureUnitBindings&) = delete;
606
607 GrGpuResource::UniqueID boundID(GrGLenum target) const;
Brian Salomon1f05d452019-02-08 12:33:08 -0500608 bool hasBeenModified(GrGLenum target) const;
Brian Salomond978b902019-02-07 15:09:18 -0500609 void setBoundID(GrGLenum target, GrGpuResource::UniqueID);
Brian Salomon1f05d452019-02-08 12:33:08 -0500610 void invalidateForScratchUse(GrGLenum target);
611 void invalidateAllTargets(bool markUnmodified);
Brian Salomond978b902019-02-07 15:09:18 -0500612
613 private:
Brian Salomon1f05d452019-02-08 12:33:08 -0500614 struct TargetBinding {
615 GrGpuResource::UniqueID fBoundResourceID;
616 bool fHasBeenModified = false;
617 };
618 TargetBinding fTargetBindings[3];
Brian Salomond978b902019-02-07 15:09:18 -0500619 };
620 SkAutoTArray<TextureUnitBindings> fHWTextureUnitBindings;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800621
Brian Salomon805cc7a2019-01-28 09:52:34 -0500622 GrGLfloat fHWClearColor[4];
623
Adrienne Walker4ee88512018-05-17 11:37:14 -0700624 GrGLuint fBoundDrawFramebuffer = 0;
625
cdaltonaf8bc7d2016-02-05 09:35:20 -0800626 // EXT_raster_multisample.
Robert Phillips294870f2016-11-11 12:38:40 -0500627 TriState fHWRasterMultisampleEnabled;
628 int fHWNumRasterSamples;
bsalomon54c6fe82015-12-16 11:51:22 -0800629 ///@}
630
Brian Salomon57111332018-02-05 15:55:54 -0500631 /** IDs for copy surface program. (3 sampler types) */
bsalomon6df86402015-06-01 10:41:49 -0700632 struct {
Brian Salomon43f8bf02017-10-18 08:33:29 -0400633 GrGLuint fProgram = 0;
634 GrGLint fTextureUniform = 0;
635 GrGLint fTexCoordXformUniform = 0;
636 GrGLint fPosXformUniform = 0;
Brian Salomon57111332018-02-05 15:55:54 -0500637 } fCopyPrograms[3];
Robert Phillips294870f2016-11-11 12:38:40 -0500638 sk_sp<GrGLBuffer> fCopyProgramArrayBuffer;
bsalomon7ea33f52015-11-22 14:51:00 -0800639
brianosman33f6b3f2016-06-02 05:49:21 -0700640 /** IDs for texture mipmap program. (4 filter configurations) */
641 struct {
Brian Salomon43f8bf02017-10-18 08:33:29 -0400642 GrGLuint fProgram = 0;
643 GrGLint fTextureUniform = 0;
644 GrGLint fTexCoordXformUniform = 0;
Robert Phillips294870f2016-11-11 12:38:40 -0500645 } fMipmapPrograms[4];
646 sk_sp<GrGLBuffer> fMipmapProgramArrayBuffer;
brianosman33f6b3f2016-06-02 05:49:21 -0700647
Robert Phillips646e4292017-06-13 12:44:56 -0400648 static int TextureToCopyProgramIdx(GrTexture* texture);
bsalomon6df86402015-06-01 10:41:49 -0700649
brianosman33f6b3f2016-06-02 05:49:21 -0700650 static int TextureSizeToMipmapProgramIdx(int width, int height) {
651 const bool wide = (width > 1) && SkToBool(width & 0x1);
652 const bool tall = (height > 1) && SkToBool(height & 0x1);
653 return (wide ? 0x2 : 0x0) | (tall ? 0x1 : 0x0);
654 }
655
Chris Daltonda40cd22018-04-16 13:19:58 -0600656 GrPrimitiveType fLastPrimitiveType;
ethannicholas28ef4452016-03-25 09:26:03 -0700657
Brian Salomondc829942018-10-23 16:07:24 -0400658 class SamplerObjectCache;
659 std::unique_ptr<SamplerObjectCache> fSamplerObjectCache;
660
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400661 std::unique_ptr<GrGLGpuRTCommandBuffer> fCachedRTCommandBuffer;
662 std::unique_ptr<GrGLGpuTextureCommandBuffer> fCachedTexCommandBuffer;
663
kkinnunenccdaa042014-08-20 01:36:23 -0700664 friend class GrGLPathRendering; // For accessing setTextureUnit.
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400665
666 typedef GrGpu INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000667};
668
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000669#endif