blob: 497ea89c57b16d9da043486f9d68ac59d83fdbdf [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
Chris Daltond7291ba2019-03-07 14:17:03 -0700187 void querySampleLocations(
188 GrRenderTarget*, const GrStencilSettings&, SkTArray<SkPoint>*) override;
189
bsalomoncb02b382015-08-12 11:14:50 -0700190 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
191
Robert Phillips67d52cf2017-06-05 13:38:13 -0400192 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
Brian Salomon58389b92018-03-07 13:01:25 -0500193 const GrMipLevel texels[], int mipLevelCount) override;
cblume55f2d2d2016-02-26 13:20:48 -0800194
Brian Salomondbf70722019-02-07 11:31:24 -0500195 sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern,
196 const void* data) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000197
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500198 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
199 GrIOType) override;
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500200 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
201 GrWrapOwnership, GrWrapCacheable) override;
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400202 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000203 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Greg Daniel7ef28f32017-04-20 16:41:55 +0000204 int sampleCnt) override;
csmartdaltone0d36292016-07-29 08:14:20 -0700205
egdanielff1d5472015-09-10 08:37:20 -0700206 // Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a
bsalomon62a627b2015-12-17 09:50:47 -0800207 // compatible stencil format, or negative if there is no compatible stencil format.
egdanielff1d5472015-09-10 08:37:20 -0700208 int getCompatibleStencilIndex(GrPixelConfig config);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000209
Adrienne Walkerca0cdef2018-08-20 13:49:40 -0700210 void onFBOChanged();
bsalomon7e68ab72016-04-13 14:29:25 -0700211
erikchen9a1ed5d2016-02-10 16:32:34 -0800212 // Returns whether the texture is successfully created. On success, the
213 // result is stored in |info|.
cblume55f2d2d2016-02-26 13:20:48 -0800214 // The texture is populated with |texels|, if it exists.
erikchen9a1ed5d2016-02-10 16:32:34 -0800215 // The texture parameters are cached in |initialTexParams|.
Brian Salomon2a4f9832018-03-03 22:43:43 -0500216 bool createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info, bool renderTarget,
Brian Salomondc829942018-10-23 16:07:24 -0400217 GrGLTexture::SamplerParams* initialTexParams, const GrMipLevel texels[],
Brian Salomon58389b92018-03-07 13:01:25 -0500218 int mipLevelCount, GrMipMapsStatus* mipMapsStatus);
erikchen9a1ed5d2016-02-10 16:32:34 -0800219
bsalomon1aa20292016-01-22 08:16:09 -0800220 // Checks whether glReadPixels can be called to get pixel values in readConfig from the
221 // render target.
222 bool readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConfig);
223
224 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
225 // render target that has renderTargetConfig. This may have to create a temporary
226 // render target and thus is less preferable than the variant that takes a render target.
227 bool readPixelsSupported(GrPixelConfig renderTargetConfig, GrPixelConfig readConfig);
228
229 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
230 // render target that has the same config as surfaceForConfig. Calls one of the the two
231 // variations above, depending on whether the surface is a render target or not.
232 bool readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig readConfig);
233
Brian Salomona6948702018-06-01 15:33:20 -0400234 bool onReadPixels(GrSurface*, int left, int top, int width, int height, GrColorType,
235 void* buffer, size_t rowBytes) override;
bsalomond95263c2014-12-16 13:05:12 -0800236
Brian Salomona9b04b92018-06-01 15:04:28 -0400237 bool onWritePixels(GrSurface*, int left, int top, int width, int height, GrColorType,
238 const GrMipLevel texels[], int mipLevelCount) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000239
Brian Salomonc320b152018-02-20 14:05:36 -0500240 bool onTransferPixels(GrTexture*, int left, int top, int width, int height, GrColorType,
Brian Salomondbf70722019-02-07 11:31:24 -0500241 GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
jvanverth17aa0472016-01-05 10:41:27 -0800242
Brian Osman9b560242017-09-05 15:34:52 -0400243 // Before calling any variation of TexImage, TexSubImage, etc..., call this to ensure that the
244 // PIXEL_UNPACK_BUFFER is unbound.
245 void unbindCpuToGpuXferBuffer();
246
Brian Salomon1fabd512018-02-09 09:54:25 -0500247 void onResolveRenderTarget(GrRenderTarget* target) override;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000248
Brian Salomon930f9392018-06-20 16:25:26 -0400249 bool onRegenerateMipMapLevels(GrTexture*) override;
250
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400251 bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin,
252 GrSurface* src, GrSurfaceOrigin srcOrigin,
Greg Daniel55fa6472018-03-16 16:13:10 -0400253 const SkIRect& srcRect, const SkIPoint& dstPoint,
254 bool canDiscardOutsideDstRect) override;
joshualitt1cbdcde2015-08-21 11:53:29 -0700255
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000256 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000257 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000258
Brian Salomonf7232642018-09-19 08:58:08 -0400259 /**
260 * primitiveProcessorTextures must contain GrPrimitiveProcessor::numTextureSamplers() *
261 * numPrimitiveProcessorTextureSets entries.
262 */
263 void resolveAndGenerateMipMapsForProcessorTextures(
Brian Salomon7eae3e02018-08-07 14:02:38 +0000264 const GrPrimitiveProcessor&, const GrPipeline&,
Brian Salomonf7232642018-09-19 08:58:08 -0400265 const GrTextureProxy* const primitiveProcessorTextures[],
266 int numPrimitiveProcessorTextureSets);
Brian Salomondfec99f2018-08-02 10:40:05 -0400267
egdaniel8dd688b2015-01-22 10:16:09 -0800268 // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set.
bsalomon2eda5b32016-09-21 10:53:24 -0700269 // willDrawPoints must be true if point primitives will be rendered after setting the GL state.
Brian Salomonf7232642018-09-19 08:58:08 -0400270 // If DynamicStateArrays is not null then dynamicStateArraysLength is the number of dynamic
271 // state entries in each array.
Robert Phillipsd0fe8752019-01-31 14:13:59 -0500272 bool flushGLState(GrRenderTarget*, GrSurfaceOrigin, const GrPrimitiveProcessor&,
273 const GrPipeline&, const GrPipeline::FixedDynamicState*,
274 const GrPipeline::DynamicStateArrays*, int dynamicStateArraysLength,
275 bool willDrawPoints);
bsalomond95263c2014-12-16 13:05:12 -0800276
Brian Salomon802cb312018-06-08 18:05:20 -0400277 void flushProgram(sk_sp<GrGLProgram>);
278
279 // Version for programs that aren't GrGLProgram.
280 void flushProgram(GrGLuint);
281
Chris Dalton114a3c02017-05-26 15:17:19 -0600282 // Sets up vertex/instance attribute pointers and strides.
Brian Salomon802cb312018-06-08 18:05:20 -0400283 void setupGeometry(const GrBuffer* indexBuffer,
Chris Daltonff926502017-05-03 14:36:54 -0400284 const GrBuffer* vertexBuffer,
Chris Dalton1d616352017-05-31 12:51:23 -0600285 int baseVertex,
286 const GrBuffer* instanceBuffer,
Brian Salomon802cb312018-06-08 18:05:20 -0400287 int baseInstance,
288 GrPrimitiveRestart);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000289
bsalomon7f9b2e42016-01-12 13:29:26 -0800290 void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000291
Greg Danielbae71212019-03-01 15:24:35 -0500292 void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
293 SkSurface::FlushFlags flags, bool insertedSemaphores) override;
Greg Daniel51316782017-08-02 15:10:09 +0000294
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400295 bool copySurfaceAsDraw(GrSurface* dst, GrSurfaceOrigin dstOrigin,
296 GrSurface* src, GrSurfaceOrigin srcOrigin,
297 const SkIRect& srcRect, const SkIPoint& dstPoint);
298 void copySurfaceAsCopyTexSubImage(GrSurface* dst, GrSurfaceOrigin dstOrigin,
299 GrSurface* src, GrSurfaceOrigin srcOrigin,
300 const SkIRect& srcRect, const SkIPoint& dstPoint);
301 bool copySurfaceAsBlitFramebuffer(GrSurface* dst, GrSurfaceOrigin dstOrigin,
302 GrSurface* src, GrSurfaceOrigin srcOrigin,
303 const SkIRect& srcRect, const SkIPoint& dstPoint);
bsalomon6df86402015-06-01 10:41:49 -0700304
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000305 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
bsalomon@google.com080773c2011-03-15 19:09:25 +0000306
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000307 class ProgramCache : public ::SkNoncopyable {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000308 public:
bsalomon861e1032014-12-16 07:33:49 -0800309 ProgramCache(GrGLGpu* gpu);
jvanverth@google.com94878772013-03-12 16:00:54 +0000310 ~ProgramCache();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000311
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000312 void abandon();
Robert Phillipsd0fe8752019-01-31 14:13:59 -0500313 GrGLProgram* refProgram(GrGLGpu*, GrRenderTarget*, GrSurfaceOrigin,
314 const GrPrimitiveProcessor&,
Greg Daniel9a51a862018-11-30 10:18:14 -0500315 const GrTextureProxy* const primProcProxies[],
316 const GrPipeline&, bool hasPointSize);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000317
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000318 private:
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500319 // We may actually have kMaxEntries+1 shaders in the GL context because we create a new
320 // shader before evicting from the cache.
321 static const int kMaxEntries = 128;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000322
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000323 struct Entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000324
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000325 // binary search for entry matching desc. returns index into fEntries that matches desc or ~
326 // of the index of where it should be inserted.
joshualitt79f8fae2014-10-28 17:59:26 -0700327 int search(const GrProgramDesc& desc) const;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000328
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500329 struct DescHash {
330 uint32_t operator()(const GrProgramDesc& desc) const {
331 return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);
332 }
333 };
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000334
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500335 SkLRUCache<GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap;
336
bsalomon861e1032014-12-16 07:33:49 -0800337 GrGLGpu* fGpu;
jvanverth@google.com94878772013-03-12 16:00:54 +0000338#ifdef PROGRAM_CACHE_STATS
339 int fTotalRequests;
340 int fCacheMisses;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000341 int fHashMisses; // cache hit but hash table missed
jvanverth@google.com94878772013-03-12 16:00:54 +0000342#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000343 };
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000344
egdaniel080e6732014-12-22 07:35:52 -0800345 void flushColorWrite(bool writeColor);
Brian Salomon805cc7a2019-01-28 09:52:34 -0500346 void flushClearColor(GrGLfloat r, GrGLfloat g, GrGLfloat b, GrGLfloat a);
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000347
Brian Salomond818ebf2018-07-02 14:08:49 +0000348 // flushes the scissor. see the note on flushBoundTextureAndParams about
349 // flushing the scissor after that function is called.
350 void flushScissor(const GrScissorState&,
351 const GrGLIRect& rtViewport,
352 GrSurfaceOrigin rtOrigin);
353
354 // disables the scissor
355 void disableScissor();
bsalomon@google.coma3201942012-06-21 19:58:20 +0000356
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400357 void flushWindowRectangles(const GrWindowRectsState&, const GrGLRenderTarget*, GrSurfaceOrigin);
csmartdalton28341fa2016-08-17 10:00:21 -0700358 void disableWindowRectangles();
359
Brian Salomond978b902019-02-07 15:09:18 -0500360 int numTextureUnits() const { return this->caps()->shaderCaps()->maxFragmentSamplers(); }
361
362 // Binds a texture to a target on the "scratch" texture unit to use for texture operations
363 // other than usual draw flow (i.e. a GrGLProgram derived from a GrPipeline used to draw
364 // GrMesh). It ensures that such operations don't negatively interact with draws.
365 // The active texture unit and the binding for 'target' will change.
366 void bindTextureToScratchUnit(GrGLenum target, GrGLint textureID);
reed@google.comac10a2d2010-12-22 21:39:39 +0000367
Brian Salomon1fabd512018-02-09 09:54:25 -0500368 // The passed bounds contains the render target's color values that will subsequently be
369 // written.
Chris Daltonc8ece3d2018-07-30 15:03:45 -0600370 void flushRenderTarget(GrGLRenderTarget*, GrSurfaceOrigin, const SkIRect& bounds);
371 // This version has an implicit bounds of the entire render target.
372 void flushRenderTarget(GrGLRenderTarget*);
Brian Salomon1fabd512018-02-09 09:54:25 -0500373 // This version can be used when the render target's colors will not be written.
Brian Osman9aa30c62018-07-02 15:21:46 -0400374 void flushRenderTargetNoColorWrites(GrGLRenderTarget*);
bsalomon083617b2016-02-12 12:10:14 -0800375
376 // Need not be called if flushRenderTarget is used.
377 void flushViewport(const GrGLIRect&);
bsalomonb0bd4f62014-09-03 07:19:50 -0700378
bsalomon3e791242014-12-17 13:43:13 -0800379 void flushStencil(const GrStencilSettings&);
csmartdaltonc7d85332016-10-26 10:13:46 -0700380 void disableStencil();
bsalomon083617b2016-02-12 12:10:14 -0800381
382 // rt is used only if useHWAA is true.
Chris Dalton4c56b032019-03-04 12:28:42 -0700383 void flushHWAAState(GrRenderTarget* rt, bool useHWAA);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000384
brianosman33f6b3f2016-06-02 05:49:21 -0700385 void flushFramebufferSRGB(bool enable);
386
bsalomon@google.com6f379512011-11-16 20:36:03 +0000387 // helper for onCreateTexture and writeTexturePixels
jvanverth17aa0472016-01-05 10:41:27 -0800388 enum UploadType {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400389 kNewTexture_UploadType, // we are creating a new texture
390 kWrite_UploadType, // we are using TexSubImage2D to copy data to an existing texture
jvanverth17aa0472016-01-05 10:41:27 -0800391 };
Brian Salomona9b04b92018-06-01 15:04:28 -0400392 bool uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight, GrGLenum target,
393 UploadType uploadType, int left, int top, int width, int height,
394 GrPixelConfig dataConfig, const GrMipLevel texels[], int mipLevelCount,
Greg Daniel0fc4d2d2017-10-12 11:23:36 -0400395 GrMipMapsStatus* mipMapsStatus = nullptr);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000396
Jim Van Verth1676cb92019-01-15 13:24:45 -0500397 // helper for onCreateCompressedTexture. Compressed textures are read-only so we
398 // only use this to populate a new texture.
399 bool uploadCompressedTexData(GrPixelConfig texConfig, int texWidth, int texHeight,
400 GrGLenum target, GrPixelConfig dataConfig,
401 const GrMipLevel texels[], int mipLevelCount,
402 GrMipMapsStatus* mipMapsStatus = nullptr);
403
kkinnunen2e6055b2016-04-22 01:48:29 -0700404 bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo,
405 GrGLRenderTarget::IDDesc*);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000406
egdanield803f272015-03-18 13:01:52 -0700407 enum TempFBOTarget {
408 kSrc_TempFBOTarget,
409 kDst_TempFBOTarget
410 };
egdaniel0f5f9672015-02-03 11:10:51 -0800411
Brian Salomond17b4a62017-05-23 16:53:47 -0400412 // Binds a surface as a FBO for copying, reading, or clearing. If the surface already owns an
413 // FBO ID then that ID is bound. If not the surface is temporarily bound to a FBO and that FBO
414 // is bound. This must be paired with a call to unbindSurfaceFBOForPixelOps().
Brian Salomon71d9d842016-11-03 13:42:00 -0400415 void bindSurfaceFBOForPixelOps(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport,
416 TempFBOTarget tempFBOTarget);
egdaniel0f5f9672015-02-03 11:10:51 -0800417
Brian Salomon71d9d842016-11-03 13:42:00 -0400418 // Must be called if bindSurfaceFBOForPixelOps was used to bind a surface for copying.
419 void unbindTextureFBOForPixelOps(GrGLenum fboTarget, GrSurface* surface);
robertphillips754f4e92014-09-18 13:52:08 -0700420
Kevin Lubickf4def342018-10-04 12:52:50 -0400421#ifdef SK_ENABLE_DUMP_GPU
Brian Osman71a18892017-08-10 10:23:25 -0400422 void onDumpJSON(SkJSONWriter*) const override;
Kevin Lubickf4def342018-10-04 12:52:50 -0400423#endif
Brian Osman71a18892017-08-10 10:23:25 -0400424
Brian Salomonbf7b6202016-11-11 16:08:03 -0500425 bool createCopyProgram(GrTexture* srcTexture);
brianosman33f6b3f2016-06-02 05:49:21 -0700426 bool createMipmapProgram(int progIdx);
ethannicholas22793252016-01-30 09:59:10 -0800427
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500428 std::unique_ptr<GrGLContext> fGLContext;
429
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000430 // GL program-related state
431 ProgramCache* fProgramCache;
bsalomon@google.com49209392012-06-05 15:13:46 +0000432
433 ///////////////////////////////////////////////////////////////////////////
434 ///@name Caching of GL State
435 ///@{
436 int fHWActiveTextureUnitIdx;
Brian Salomon802cb312018-06-08 18:05:20 -0400437
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000438 GrGLuint fHWProgramID;
Brian Salomon802cb312018-06-08 18:05:20 -0400439 sk_sp<GrGLProgram> fHWProgram;
bsalomon@google.com91207482013-02-12 21:45:24 +0000440
bsalomon@google.com49209392012-06-05 15:13:46 +0000441 enum TriState {
442 kNo_TriState,
443 kYes_TriState,
444 kUnknown_TriState
445 };
446
egdanield803f272015-03-18 13:01:52 -0700447 GrGLuint fTempSrcFBOID;
448 GrGLuint fTempDstFBOID;
449
450 GrGLuint fStencilClearFBOID;
bsalomondd3143b2015-02-23 09:27:45 -0800451
bsalomon@google.coma3201942012-06-21 19:58:20 +0000452 // last scissor / viewport scissor state seen by the GL.
453 struct {
454 TriState fEnabled;
455 GrGLIRect fRect;
456 void invalidate() {
457 fEnabled = kUnknown_TriState;
458 fRect.invalidate();
459 }
460 } fHWScissorSettings;
461
csmartdalton28341fa2016-08-17 10:00:21 -0700462 class {
463 public:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700464 bool valid() const { return kInvalidSurfaceOrigin != fRTOrigin; }
465 void invalidate() { fRTOrigin = kInvalidSurfaceOrigin; }
466 bool knownDisabled() const { return this->valid() && !fWindowState.enabled(); }
mtklein8b4a2022016-09-26 08:44:47 -0700467 void setDisabled() {
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400468 fRTOrigin = kTopLeft_GrSurfaceOrigin;
mtklein8b4a2022016-09-26 08:44:47 -0700469 fWindowState.setDisabled();
470 }
csmartdalton28341fa2016-08-17 10:00:21 -0700471
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700472 void set(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
473 const GrWindowRectsState& windowState) {
474 fRTOrigin = rtOrigin;
475 fViewport = viewport;
476 fWindowState = windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700477 }
csmartdalton28341fa2016-08-17 10:00:21 -0700478
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700479 bool knownEqualTo(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
480 const GrWindowRectsState& windowState) const {
csmartdalton28341fa2016-08-17 10:00:21 -0700481 if (!this->valid()) {
482 return false;
483 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700484 if (fWindowState.numWindows() && (fRTOrigin != rtOrigin || fViewport != viewport)) {
csmartdalton28341fa2016-08-17 10:00:21 -0700485 return false;
486 }
Brian Salomon9a767722017-03-13 17:57:28 -0400487 return fWindowState == windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700488 }
489
490 private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700491 enum { kInvalidSurfaceOrigin = -1 };
csmartdalton28341fa2016-08-17 10:00:21 -0700492
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700493 int fRTOrigin;
csmartdalton28341fa2016-08-17 10:00:21 -0700494 GrGLIRect fViewport;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700495 GrWindowRectsState fWindowState;
496 } fHWWindowRectsState;
csmartdalton28341fa2016-08-17 10:00:21 -0700497
bsalomon424cc262015-05-22 10:37:30 -0700498 GrGLIRect fHWViewport;
bsalomon@google.coma3201942012-06-21 19:58:20 +0000499
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000500 /**
cdaltone2e71c22016-04-07 18:13:29 -0700501 * Tracks vertex attrib array state.
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000502 */
cdaltone2e71c22016-04-07 18:13:29 -0700503 class HWVertexArrayState {
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000504 public:
cdaltone2e71c22016-04-07 18:13:29 -0700505 HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); }
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000506
cdaltone2e71c22016-04-07 18:13:29 -0700507 ~HWVertexArrayState() { delete fCoreProfileVertexArray; }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000508
bsalomon@google.com6918d482013-03-07 19:09:11 +0000509 void invalidate() {
510 fBoundVertexArrayIDIsValid = false;
bsalomon@google.com6918d482013-03-07 19:09:11 +0000511 fDefaultVertexArrayAttribState.invalidate();
cdaltone2e71c22016-04-07 18:13:29 -0700512 if (fCoreProfileVertexArray) {
513 fCoreProfileVertexArray->invalidateCachedState();
commit-bot@chromium.orgce6da4d2013-09-09 14:55:37 +0000514 }
bsalomon@google.com6918d482013-03-07 19:09:11 +0000515 }
516
517 void notifyVertexArrayDelete(GrGLuint id) {
518 if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) {
519 // Does implicit bind to 0
520 fBoundVertexArrayID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000521 }
522 }
523
bsalomon861e1032014-12-16 07:33:49 -0800524 void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000525 if (!gpu->glCaps().vertexArrayObjectSupport()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000526 SkASSERT(0 == arrayID);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000527 return;
528 }
529 if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) {
530 GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID));
531 fBoundVertexArrayIDIsValid = true;
532 fBoundVertexArrayID = arrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000533 }
534 }
535
bsalomon@google.com6918d482013-03-07 19:09:11 +0000536 /**
cdaltone2e71c22016-04-07 18:13:29 -0700537 * Binds the vertex array that should be used for internal draws, and returns its attrib
538 * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which
539 * case we use a dummy array instead.
540 *
541 * If an index buffer is privided, it will be bound to the vertex array. Otherwise the
542 * index buffer binding will be left unchanged.
543 *
544 * The returned GrGLAttribArrayState should be used to set vertex attribute arrays.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000545 */
csmartdalton485a1202016-07-13 10:16:32 -0700546 GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrBuffer* ibuff = nullptr);
bsalomon6df86402015-06-01 10:41:49 -0700547
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000548 private:
Robert Phillips294870f2016-11-11 12:38:40 -0500549 GrGLuint fBoundVertexArrayID;
550 bool fBoundVertexArrayIDIsValid;
mtklein044d3c12016-04-06 18:24:34 -0700551
bsalomon@google.com6918d482013-03-07 19:09:11 +0000552 // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
jvanverth39edf762014-12-22 11:44:19 -0800553 // is bound. However, this class is internal to GrGLGpu and this object never leaks out of
554 // GrGLGpu.
Robert Phillips294870f2016-11-11 12:38:40 -0500555 GrGLAttribArrayState fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000556
cdaltone2e71c22016-04-07 18:13:29 -0700557 // This is used when we're using a core profile.
Robert Phillips294870f2016-11-11 12:38:40 -0500558 GrGLVertexArray* fCoreProfileVertexArray;
559 } fHWVertexArrayState;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000560
cdaltone2e71c22016-04-07 18:13:29 -0700561 struct {
Robert Phillips294870f2016-11-11 12:38:40 -0500562 GrGLenum fGLTarget;
563 GrGpuResource::UniqueID fBoundBufferUniqueID;
564 bool fBufferZeroKnownBound;
cdaltone2e71c22016-04-07 18:13:29 -0700565
566 void invalidate() {
Robert Phillips294870f2016-11-11 12:38:40 -0500567 fBoundBufferUniqueID.makeInvalid();
cdaltone2e71c22016-04-07 18:13:29 -0700568 fBufferZeroKnownBound = false;
569 }
Brian Salomonae64c192019-02-05 09:41:37 -0500570 } fHWBufferState[kGrGpuBufferTypeCount];
571
572 auto* hwBufferState(GrGpuBufferType type) {
573 unsigned typeAsUInt = static_cast<unsigned>(type);
574 SkASSERT(typeAsUInt < SK_ARRAY_COUNT(fHWBufferState));
575 return &fHWBufferState[typeAsUInt];
576 }
cdaltonc1613102016-03-16 07:48:20 -0700577
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000578 struct {
cdalton8917d622015-05-06 13:40:21 -0700579 GrBlendEquation fEquation;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000580 GrBlendCoeff fSrcCoeff;
581 GrBlendCoeff fDstCoeff;
Brian Osman422f95b2018-11-05 16:49:04 -0500582 SkPMColor4f fConstColor;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000583 bool fConstColorValid;
584 TriState fEnabled;
585
586 void invalidate() {
Mike Klein36743362018-11-06 08:23:30 -0500587 fEquation = kIllegal_GrBlendEquation;
588 fSrcCoeff = kIllegal_GrBlendCoeff;
589 fDstCoeff = kIllegal_GrBlendCoeff;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000590 fConstColorValid = false;
591 fEnabled = kUnknown_TriState;
592 }
Robert Phillips294870f2016-11-11 12:38:40 -0500593 } fHWBlendState;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000594
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400595 TriState fMSAAEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800596
Robert Phillips294870f2016-11-11 12:38:40 -0500597 GrStencilSettings fHWStencilSettings;
598 TriState fHWStencilTestEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800599
600
Robert Phillips294870f2016-11-11 12:38:40 -0500601 TriState fHWWriteToColor;
602 GrGpuResource::UniqueID fHWBoundRenderTargetUniqueID;
603 TriState fHWSRGBFramebuffer;
Brian Salomond978b902019-02-07 15:09:18 -0500604
605 class TextureUnitBindings {
606 public:
607 TextureUnitBindings() = default;
608 TextureUnitBindings(const TextureUnitBindings&) = delete;
609 TextureUnitBindings& operator=(const TextureUnitBindings&) = delete;
610
611 GrGpuResource::UniqueID boundID(GrGLenum target) const;
Brian Salomon1f05d452019-02-08 12:33:08 -0500612 bool hasBeenModified(GrGLenum target) const;
Brian Salomond978b902019-02-07 15:09:18 -0500613 void setBoundID(GrGLenum target, GrGpuResource::UniqueID);
Brian Salomon1f05d452019-02-08 12:33:08 -0500614 void invalidateForScratchUse(GrGLenum target);
615 void invalidateAllTargets(bool markUnmodified);
Brian Salomond978b902019-02-07 15:09:18 -0500616
617 private:
Brian Salomon1f05d452019-02-08 12:33:08 -0500618 struct TargetBinding {
619 GrGpuResource::UniqueID fBoundResourceID;
620 bool fHasBeenModified = false;
621 };
622 TargetBinding fTargetBindings[3];
Brian Salomond978b902019-02-07 15:09:18 -0500623 };
624 SkAutoTArray<TextureUnitBindings> fHWTextureUnitBindings;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800625
Brian Salomon805cc7a2019-01-28 09:52:34 -0500626 GrGLfloat fHWClearColor[4];
627
Adrienne Walker4ee88512018-05-17 11:37:14 -0700628 GrGLuint fBoundDrawFramebuffer = 0;
629
Brian Salomon57111332018-02-05 15:55:54 -0500630 /** IDs for copy surface program. (3 sampler types) */
bsalomon6df86402015-06-01 10:41:49 -0700631 struct {
Brian Salomon43f8bf02017-10-18 08:33:29 -0400632 GrGLuint fProgram = 0;
633 GrGLint fTextureUniform = 0;
634 GrGLint fTexCoordXformUniform = 0;
635 GrGLint fPosXformUniform = 0;
Brian Salomon57111332018-02-05 15:55:54 -0500636 } fCopyPrograms[3];
Robert Phillips294870f2016-11-11 12:38:40 -0500637 sk_sp<GrGLBuffer> fCopyProgramArrayBuffer;
bsalomon7ea33f52015-11-22 14:51:00 -0800638
brianosman33f6b3f2016-06-02 05:49:21 -0700639 /** IDs for texture mipmap program. (4 filter configurations) */
640 struct {
Brian Salomon43f8bf02017-10-18 08:33:29 -0400641 GrGLuint fProgram = 0;
642 GrGLint fTextureUniform = 0;
643 GrGLint fTexCoordXformUniform = 0;
Robert Phillips294870f2016-11-11 12:38:40 -0500644 } fMipmapPrograms[4];
645 sk_sp<GrGLBuffer> fMipmapProgramArrayBuffer;
brianosman33f6b3f2016-06-02 05:49:21 -0700646
Robert Phillips646e4292017-06-13 12:44:56 -0400647 static int TextureToCopyProgramIdx(GrTexture* texture);
bsalomon6df86402015-06-01 10:41:49 -0700648
brianosman33f6b3f2016-06-02 05:49:21 -0700649 static int TextureSizeToMipmapProgramIdx(int width, int height) {
650 const bool wide = (width > 1) && SkToBool(width & 0x1);
651 const bool tall = (height > 1) && SkToBool(height & 0x1);
652 return (wide ? 0x2 : 0x0) | (tall ? 0x1 : 0x0);
653 }
654
Chris Daltonda40cd22018-04-16 13:19:58 -0600655 GrPrimitiveType fLastPrimitiveType;
ethannicholas28ef4452016-03-25 09:26:03 -0700656
Brian Salomondc829942018-10-23 16:07:24 -0400657 class SamplerObjectCache;
658 std::unique_ptr<SamplerObjectCache> fSamplerObjectCache;
659
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400660 std::unique_ptr<GrGLGpuRTCommandBuffer> fCachedRTCommandBuffer;
661 std::unique_ptr<GrGLGpuTextureCommandBuffer> fCachedTexCommandBuffer;
662
kkinnunenccdaa042014-08-20 01:36:23 -0700663 friend class GrGLPathRendering; // For accessing setTextureUnit.
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400664
665 typedef GrGpu INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000666};
667
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000668#endif