blob: 531207c560df0cd8423bb9220fbb0f0928699cc5 [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;
egdaniel8dd688b2015-01-22 10:16:09 -080028class GrPipeline;
bsalomon7f9b2e42016-01-12 13:29:26 -080029class GrSwizzle;
egdaniel8dd688b2015-01-22 10:16:09 -080030
djsollenefe46d22016-04-29 06:41:35 -070031#ifdef SK_DEBUG
jvanverth@google.com94878772013-03-12 16:00:54 +000032#define PROGRAM_CACHE_STATS
33#endif
34
Chris Dalton114a3c02017-05-26 15:17:19 -060035class GrGLGpu final : public GrGpu, private GrMesh::SendToGpuImpl {
reed@google.comac10a2d2010-12-22 21:39:39 +000036public:
Robert Phillipse42edcc2017-12-13 11:50:22 -050037 static sk_sp<GrGpu> Make(sk_sp<const GrGLInterface>, const GrContextOptions&, GrContext*);
mtklein36352bf2015-03-25 18:17:31 -070038 ~GrGLGpu() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000039
bsalomon6e2aad42016-04-01 11:54:31 -070040 void disconnect(DisconnectType) override;
bsalomonc8dc1f72014-08-21 13:02:13 -070041
bsalomon424cc262015-05-22 10:37:30 -070042 const GrGLContext& glContext() const { return *fGLContext; }
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000043
bsalomon424cc262015-05-22 10:37:30 -070044 const GrGLInterface* glInterface() const { return fGLContext->interface(); }
45 const GrGLContextInfo& ctxInfo() const { return *fGLContext; }
46 GrGLStandard glStandard() const { return fGLContext->standard(); }
47 GrGLVersion glVersion() const { return fGLContext->version(); }
48 GrGLSLGeneration glslGeneration() const { return fGLContext->glslGeneration(); }
49 const GrGLCaps& glCaps() const { return *fGLContext->caps(); }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000050
kkinnunenccdaa042014-08-20 01:36:23 -070051 GrGLPathRendering* glPathRendering() {
jvanverthe9c0fc62015-04-29 11:18:05 -070052 SkASSERT(glCaps().shaderCaps()->pathRenderingSupport());
kkinnunenccdaa042014-08-20 01:36:23 -070053 return static_cast<GrGLPathRendering*>(pathRendering());
cdaltonc7103a12014-08-11 14:05:05 -070054 }
55
kkinnunencfe62e32015-07-01 02:58:50 -070056 // Used by GrGLProgram to configure OpenGL state.
Brian Salomon930f9392018-06-20 16:25:26 -040057 void bindTexture(int unitIdx, const GrSamplerState& samplerState, GrGLTexture* texture);
kkinnunenccdaa042014-08-20 01:36:23 -070058
bsalomon@google.com6918d482013-03-07 19:09:11 +000059 // 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 +000060 // bindings. Making the equivalent glBind calls directly will confuse the state tracking.
bsalomon@google.com6918d482013-03-07 19:09:11 +000061 void bindVertexArray(GrGLuint id) {
cdaltone2e71c22016-04-07 18:13:29 -070062 fHWVertexArrayState.setVertexArrayID(this, id);
bsalomon@google.com6918d482013-03-07 19:09:11 +000063 }
64
65 // These callbacks update state tracking when GL objects are deleted. They are called from
66 // GrGLResource onRelease functions.
67 void notifyVertexArrayDelete(GrGLuint id) {
cdaltone2e71c22016-04-07 18:13:29 -070068 fHWVertexArrayState.notifyVertexArrayDelete(id);
bsalomon@google.com6918d482013-03-07 19:09:11 +000069 }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +000070
cdaltone2e71c22016-04-07 18:13:29 -070071 // Binds a buffer to the GL target corresponding to 'type', updates internal state tracking, and
72 // returns the GL target the buffer was bound to.
73 // When 'type' is kIndex_GrBufferType, this function will also implicitly bind the default VAO.
74 // If the caller wishes to bind an index buffer to a specific VAO, it can call glBind directly.
csmartdalton485a1202016-07-13 10:16:32 -070075 GrGLenum bindBuffer(GrBufferType type, const GrBuffer*);
joshualitt93316b92015-10-23 09:08:08 -070076
Greg Daniel500d58b2017-08-24 15:59:33 -040077 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -070078 // Thus this is the implementation of the draw call for the corresponding passthrough function
Greg Daniel500d58b2017-08-24 15:59:33 -040079 // on GrGLRTGpuCommandBuffer.
Brian Salomonff168d92018-06-23 15:17:27 -040080 void draw(const GrPrimitiveProcessor&,
81 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -040082 const GrPipeline::FixedDynamicState*,
83 const GrPipeline::DynamicStateArrays*,
Chris Dalton46983b72017-06-06 12:27:16 -060084 const GrMesh[],
egdaniel9cb63402016-06-23 08:37:05 -070085 int meshCount);
86
Chris Dalton114a3c02017-05-26 15:17:19 -060087 // GrMesh::SendToGpuImpl methods. These issue the actual GL draw calls.
88 // Marked final as a hint to the compiler to not use virtual dispatch.
Brian Salomon802cb312018-06-08 18:05:20 -040089 void sendMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount,
90 int baseVertex) final;
Chris Dalton114a3c02017-05-26 15:17:19 -060091
Brian Salomon802cb312018-06-08 18:05:20 -040092 void sendIndexedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount,
93 int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue,
94 const GrBuffer* vertexBuffer, int baseVertex,
95 GrPrimitiveRestart) final;
Chris Dalton114a3c02017-05-26 15:17:19 -060096
Brian Salomon802cb312018-06-08 18:05:20 -040097 void sendInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount,
98 int baseVertex, const GrBuffer* instanceBuffer, int instanceCount,
Chris Dalton1d616352017-05-31 12:51:23 -060099 int baseInstance) final;
100
Brian Salomon802cb312018-06-08 18:05:20 -0400101 void sendIndexedInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount,
102 int baseIndex, const GrBuffer* vertexBuffer, int baseVertex,
Chris Dalton1d616352017-05-31 12:51:23 -0600103 const GrBuffer* instanceBuffer, int instanceCount,
Brian Salomon802cb312018-06-08 18:05:20 -0400104 int baseInstance, GrPrimitiveRestart) final;
Chris Dalton1d616352017-05-31 12:51:23 -0600105
Greg Daniel500d58b2017-08-24 15:59:33 -0400106 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700107 // Thus this is the implementation of the clear call for the corresponding passthrough function
Greg Daniel500d58b2017-08-24 15:59:33 -0400108 // on GrGLGpuRTCommandBuffer.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400109 void clear(const GrFixedClip&, GrColor, GrRenderTarget*, GrSurfaceOrigin);
Brian Salomon43f8bf02017-10-18 08:33:29 -0400110 void clearColorAsDraw(const GrFixedClip&, GrGLfloat r, GrGLfloat g, GrGLfloat b, GrGLfloat a,
111 GrRenderTarget*, GrSurfaceOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700112
Greg Daniel500d58b2017-08-24 15:59:33 -0400113 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700114 // Thus this is the implementation of the clearStencil call for the corresponding passthrough
Greg Daniel500d58b2017-08-24 15:59:33 -0400115 // function on GrGLGpuRTCommandBuffer.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400116 void clearStencilClip(const GrFixedClip&, bool insideStencilMask,
117 GrRenderTarget*, GrSurfaceOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700118
Robert Phillips95214472017-08-08 18:00:03 -0400119 void clearStencil(GrRenderTarget*, int clearValue) override;
egdanielec00d942015-09-14 12:56:10 -0700120
Greg Daniel500d58b2017-08-24 15:59:33 -0400121 GrGpuRTCommandBuffer* createCommandBuffer(
Robert Phillips95214472017-08-08 18:00:03 -0400122 GrRenderTarget*, GrSurfaceOrigin,
Greg Daniel500d58b2017-08-24 15:59:33 -0400123 const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
124 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
125
126 GrGpuTextureCommandBuffer* createCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
egdaniel066df7c2016-06-08 14:02:27 -0700127
egdanielec00d942015-09-14 12:56:10 -0700128 void invalidateBoundRenderTarget() {
Robert Phillips294870f2016-11-11 12:38:40 -0500129 fHWBoundRenderTargetUniqueID.makeInvalid();
egdanielec00d942015-09-14 12:56:10 -0700130 }
131
132 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
133 int width,
134 int height) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500135#if GR_TEST_UTILS
Brian Salomon52e943a2018-03-13 09:32:39 -0400136 GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
137 GrPixelConfig config, bool isRenderTarget,
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500138 GrMipMapped mipMapped) override;
139 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Brian Salomon26102cb2018-03-09 09:33:19 -0500140 void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
jvanverth672bb7f2015-07-13 07:19:57 -0700141
Brian Osman2d010b62018-08-09 10:55:09 -0400142 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500143
144 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
145
146 const GrGLContext* glContextForTesting() const override { return &this->glContext(); }
147
148 void resetShaderCacheForTesting() const override { fProgramCache->abandon(); }
joshualitt8fd844f2015-12-02 13:36:47 -0800149
Greg Daniel26b50a42018-03-08 09:49:58 -0500150 void testingOnly_flushGpuAndSync() override;
Brian Salomonf865b052018-03-09 09:01:53 -0500151#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500152
Greg Daniel6be35232017-03-01 17:01:09 -0500153 GrFence SK_WARN_UNUSED_RESULT insertFence() override;
154 bool waitFence(GrFence, uint64_t timeout) override;
jvanverth84741b32016-09-30 08:39:02 -0700155 void deleteFence(GrFence) const override;
156
Greg Daniela5cb7812017-06-16 09:45:32 -0400157 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override;
Greg Daniel48661b82018-01-22 16:11:35 -0500158 sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
159 GrResourceProvider::SemaphoreWrapType wrapType,
160 GrWrapOwnership ownership) override;
161 void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override;
162 void waitSemaphore(sk_sp<GrSemaphore> semaphore) override;
Greg Daniel6be35232017-03-01 17:01:09 -0500163
Brian Osman13dddce2017-05-09 13:19:50 -0400164 sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
165
Greg Daniel6be35232017-03-01 17:01:09 -0500166 void deleteSync(GrGLsync) const;
167
Robert Phillips65a88fa2017-08-08 08:36:22 -0400168 void insertEventMarker(const char*);
169
Adrienne Walker4ee88512018-05-17 11:37:14 -0700170 void bindFramebuffer(GrGLenum fboTarget, GrGLuint fboid);
171 void deleteFramebuffer(GrGLuint fboid);
Adrienne Walker3ed33992018-05-15 11:44:34 -0700172
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000173private:
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500174 GrGLGpu(std::unique_ptr<GrGLContext>, GrContext*);
bsalomon424cc262015-05-22 10:37:30 -0700175
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000176 // GrGpu overrides
mtklein36352bf2015-03-25 18:17:31 -0700177 void onResetContext(uint32_t resetBits) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000178
bsalomoncb02b382015-08-12 11:14:50 -0700179 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
180
Robert Phillips67d52cf2017-06-05 13:38:13 -0400181 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
Brian Salomon58389b92018-03-07 13:01:25 -0500182 const GrMipLevel texels[], int mipLevelCount) override;
cblume55f2d2d2016-02-26 13:20:48 -0800183
cdalton1bf3e712016-04-19 10:00:02 -0700184 GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
185 const void* data) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000186
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400187 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override;
Brian Salomond17f6582017-07-19 18:28:58 -0400188 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -0400189 int sampleCnt,
190 GrWrapOwnership) override;
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400191 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000192 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Greg Daniel7ef28f32017-04-20 16:41:55 +0000193 int sampleCnt) override;
csmartdaltone0d36292016-07-29 08:14:20 -0700194
egdanielff1d5472015-09-10 08:37:20 -0700195 // Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a
bsalomon62a627b2015-12-17 09:50:47 -0800196 // compatible stencil format, or negative if there is no compatible stencil format.
egdanielff1d5472015-09-10 08:37:20 -0700197 int getCompatibleStencilIndex(GrPixelConfig config);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000198
bsalomon7e68ab72016-04-13 14:29:25 -0700199
erikchen9a1ed5d2016-02-10 16:32:34 -0800200 // Returns whether the texture is successfully created. On success, the
201 // result is stored in |info|.
cblume55f2d2d2016-02-26 13:20:48 -0800202 // The texture is populated with |texels|, if it exists.
erikchen9a1ed5d2016-02-10 16:32:34 -0800203 // The texture parameters are cached in |initialTexParams|.
Brian Salomon2a4f9832018-03-03 22:43:43 -0500204 bool createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info, bool renderTarget,
Brian Salomon58389b92018-03-07 13:01:25 -0500205 GrGLTexture::TexParams* initialTexParams, const GrMipLevel texels[],
206 int mipLevelCount, GrMipMapsStatus* mipMapsStatus);
erikchen9a1ed5d2016-02-10 16:32:34 -0800207
bsalomon1aa20292016-01-22 08:16:09 -0800208 // Checks whether glReadPixels can be called to get pixel values in readConfig from the
209 // render target.
210 bool readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConfig);
211
212 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
213 // render target that has renderTargetConfig. This may have to create a temporary
214 // render target and thus is less preferable than the variant that takes a render target.
215 bool readPixelsSupported(GrPixelConfig renderTargetConfig, GrPixelConfig readConfig);
216
217 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
218 // render target that has the same config as surfaceForConfig. Calls one of the the two
219 // variations above, depending on whether the surface is a render target or not.
220 bool readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig readConfig);
221
Brian Salomona6948702018-06-01 15:33:20 -0400222 bool onReadPixels(GrSurface*, int left, int top, int width, int height, GrColorType,
223 void* buffer, size_t rowBytes) override;
bsalomond95263c2014-12-16 13:05:12 -0800224
Brian Salomona9b04b92018-06-01 15:04:28 -0400225 bool onWritePixels(GrSurface*, int left, int top, int width, int height, GrColorType,
226 const GrMipLevel texels[], int mipLevelCount) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000227
Brian Salomonc320b152018-02-20 14:05:36 -0500228 bool onTransferPixels(GrTexture*, int left, int top, int width, int height, GrColorType,
229 GrBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
jvanverth17aa0472016-01-05 10:41:27 -0800230
Brian Osman9b560242017-09-05 15:34:52 -0400231 // Before calling any variation of TexImage, TexSubImage, etc..., call this to ensure that the
232 // PIXEL_UNPACK_BUFFER is unbound.
233 void unbindCpuToGpuXferBuffer();
234
Brian Salomon1fabd512018-02-09 09:54:25 -0500235 void onResolveRenderTarget(GrRenderTarget* target) override;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000236
Brian Salomon930f9392018-06-20 16:25:26 -0400237 bool onRegenerateMipMapLevels(GrTexture*) override;
238
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400239 bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin,
240 GrSurface* src, GrSurfaceOrigin srcOrigin,
Greg Daniel55fa6472018-03-16 16:13:10 -0400241 const SkIRect& srcRect, const SkIPoint& dstPoint,
242 bool canDiscardOutsideDstRect) override;
joshualitt1cbdcde2015-08-21 11:53:29 -0700243
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000244 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000245 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000246
cdalton74b8d322016-04-11 14:47:28 -0700247 void setTextureSwizzle(int unitIdx, GrGLenum target, const GrGLenum swizzle[]);
248
Brian Salomond1b8a162018-08-08 13:22:05 -0400249 /**
250 * primitiveProcessorTextures must contain GrPrimitiveProcessor::numTextureSamplers() *
251 * numPrimitiveProcessorTextureSets entries.
252 */
253 void resolveAndGenerateMipMapsForProcessorTextures(
Brian Salomon7eae3e02018-08-07 14:02:38 +0000254 const GrPrimitiveProcessor&, const GrPipeline&,
Brian Salomond1b8a162018-08-08 13:22:05 -0400255 const GrTextureProxy* const primitiveProcessorTextures[],
256 int numPrimitiveProcessorTextureSets);
Brian Salomondfec99f2018-08-02 10:40:05 -0400257
egdaniel8dd688b2015-01-22 10:16:09 -0800258 // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set.
bsalomon2eda5b32016-09-21 10:53:24 -0700259 // willDrawPoints must be true if point primitives will be rendered after setting the GL state.
Brian Salomond1b8a162018-08-08 13:22:05 -0400260 // If DynamicStateArrays is not null then dynamicStateArraysLength is the number of dynamic
261 // state entries in each array.
Brian Salomon49348902018-06-26 09:12:38 -0400262 bool flushGLState(const GrPrimitiveProcessor&, const GrPipeline&,
Brian Salomond1b8a162018-08-08 13:22:05 -0400263 const GrPipeline::FixedDynamicState*, const GrPipeline::DynamicStateArrays*,
264 int dynamicStateArraysLength, bool willDrawPoints);
bsalomond95263c2014-12-16 13:05:12 -0800265
Brian Salomon802cb312018-06-08 18:05:20 -0400266 void flushProgram(sk_sp<GrGLProgram>);
267
268 // Version for programs that aren't GrGLProgram.
269 void flushProgram(GrGLuint);
270
Chris Dalton114a3c02017-05-26 15:17:19 -0600271 // Sets up vertex/instance attribute pointers and strides.
Brian Salomon802cb312018-06-08 18:05:20 -0400272 void setupGeometry(const GrBuffer* indexBuffer,
Chris Daltonff926502017-05-03 14:36:54 -0400273 const GrBuffer* vertexBuffer,
Chris Dalton1d616352017-05-31 12:51:23 -0600274 int baseVertex,
275 const GrBuffer* instanceBuffer,
Brian Salomon802cb312018-06-08 18:05:20 -0400276 int baseInstance,
277 GrPrimitiveRestart);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000278
bsalomon7f9b2e42016-01-12 13:29:26 -0800279 void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000280
Greg Daniel51316782017-08-02 15:10:09 +0000281 void onFinishFlush(bool insertedSemaphores) override;
282
bsalomon424cc262015-05-22 10:37:30 -0700283 bool hasExtension(const char* ext) const { return fGLContext->hasExtension(ext); }
bsalomon@google.com96399942012-02-13 14:39:16 +0000284
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400285 bool copySurfaceAsDraw(GrSurface* dst, GrSurfaceOrigin dstOrigin,
286 GrSurface* src, GrSurfaceOrigin srcOrigin,
287 const SkIRect& srcRect, const SkIPoint& dstPoint);
288 void copySurfaceAsCopyTexSubImage(GrSurface* dst, GrSurfaceOrigin dstOrigin,
289 GrSurface* src, GrSurfaceOrigin srcOrigin,
290 const SkIRect& srcRect, const SkIPoint& dstPoint);
291 bool copySurfaceAsBlitFramebuffer(GrSurface* dst, GrSurfaceOrigin dstOrigin,
292 GrSurface* src, GrSurfaceOrigin srcOrigin,
293 const SkIRect& srcRect, const SkIPoint& dstPoint);
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400294 void clearStencilClipAsDraw(const GrFixedClip&, bool insideStencilMask,
295 GrRenderTarget*, GrSurfaceOrigin);
bsalomon6df86402015-06-01 10:41:49 -0700296
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000297 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
bsalomon@google.com080773c2011-03-15 19:09:25 +0000298
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000299 class ProgramCache : public ::SkNoncopyable {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000300 public:
bsalomon861e1032014-12-16 07:33:49 -0800301 ProgramCache(GrGLGpu* gpu);
jvanverth@google.com94878772013-03-12 16:00:54 +0000302 ~ProgramCache();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000303
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000304 void abandon();
Brian Salomonff168d92018-06-23 15:17:27 -0400305 GrGLProgram* refProgram(const GrGLGpu*, const GrPrimitiveProcessor&, const GrPipeline&,
bsalomon2eda5b32016-09-21 10:53:24 -0700306 bool hasPointSize);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000307
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000308 private:
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500309 // We may actually have kMaxEntries+1 shaders in the GL context because we create a new
310 // shader before evicting from the cache.
311 static const int kMaxEntries = 128;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000312
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000313 struct Entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000314
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000315 // binary search for entry matching desc. returns index into fEntries that matches desc or ~
316 // of the index of where it should be inserted.
joshualitt79f8fae2014-10-28 17:59:26 -0700317 int search(const GrProgramDesc& desc) const;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000318
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500319 struct DescHash {
320 uint32_t operator()(const GrProgramDesc& desc) const {
321 return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);
322 }
323 };
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000324
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500325 SkLRUCache<GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap;
326
bsalomon861e1032014-12-16 07:33:49 -0800327 GrGLGpu* fGpu;
jvanverth@google.com94878772013-03-12 16:00:54 +0000328#ifdef PROGRAM_CACHE_STATS
329 int fTotalRequests;
330 int fCacheMisses;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000331 int fHashMisses; // cache hit but hash table missed
jvanverth@google.com94878772013-03-12 16:00:54 +0000332#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000333 };
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000334
egdaniel080e6732014-12-22 07:35:52 -0800335 void flushColorWrite(bool writeColor);
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000336
Brian Salomond818ebf2018-07-02 14:08:49 +0000337 // flushes the scissor. see the note on flushBoundTextureAndParams about
338 // flushing the scissor after that function is called.
339 void flushScissor(const GrScissorState&,
340 const GrGLIRect& rtViewport,
341 GrSurfaceOrigin rtOrigin);
342
343 // disables the scissor
344 void disableScissor();
bsalomon@google.coma3201942012-06-21 19:58:20 +0000345
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400346 void flushWindowRectangles(const GrWindowRectsState&, const GrGLRenderTarget*, GrSurfaceOrigin);
csmartdalton28341fa2016-08-17 10:00:21 -0700347 void disableWindowRectangles();
348
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000349 // sets a texture unit to use for texture operations other than binding a texture to a program.
350 // ensures that such operations don't negatively interact with tracking bound textures.
351 void setScratchTextureUnit();
reed@google.comac10a2d2010-12-22 21:39:39 +0000352
Brian Salomon1fabd512018-02-09 09:54:25 -0500353 // The passed bounds contains the render target's color values that will subsequently be
354 // written.
Chris Daltonc8ece3d2018-07-30 15:03:45 -0600355 void flushRenderTarget(GrGLRenderTarget*, GrSurfaceOrigin, const SkIRect& bounds);
356 // This version has an implicit bounds of the entire render target.
357 void flushRenderTarget(GrGLRenderTarget*);
Brian Salomon1fabd512018-02-09 09:54:25 -0500358 // This version can be used when the render target's colors will not be written.
Brian Osman9aa30c62018-07-02 15:21:46 -0400359 void flushRenderTargetNoColorWrites(GrGLRenderTarget*);
bsalomon083617b2016-02-12 12:10:14 -0800360
361 // Need not be called if flushRenderTarget is used.
362 void flushViewport(const GrGLIRect&);
bsalomonb0bd4f62014-09-03 07:19:50 -0700363
bsalomon3e791242014-12-17 13:43:13 -0800364 void flushStencil(const GrStencilSettings&);
csmartdaltonc7d85332016-10-26 10:13:46 -0700365 void disableStencil();
bsalomon083617b2016-02-12 12:10:14 -0800366
367 // rt is used only if useHWAA is true.
cdaltonaf8bc7d2016-02-05 09:35:20 -0800368 void flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabled);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000369
ethannicholas28ef4452016-03-25 09:26:03 -0700370 void flushMinSampleShading(float minSampleShading);
371
brianosman33f6b3f2016-06-02 05:49:21 -0700372 void flushFramebufferSRGB(bool enable);
373
bsalomon@google.com6f379512011-11-16 20:36:03 +0000374 // helper for onCreateTexture and writeTexturePixels
jvanverth17aa0472016-01-05 10:41:27 -0800375 enum UploadType {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400376 kNewTexture_UploadType, // we are creating a new texture
377 kWrite_UploadType, // we are using TexSubImage2D to copy data to an existing texture
jvanverth17aa0472016-01-05 10:41:27 -0800378 };
Brian Salomona9b04b92018-06-01 15:04:28 -0400379 bool uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight, GrGLenum target,
380 UploadType uploadType, int left, int top, int width, int height,
381 GrPixelConfig dataConfig, const GrMipLevel texels[], int mipLevelCount,
Greg Daniel0fc4d2d2017-10-12 11:23:36 -0400382 GrMipMapsStatus* mipMapsStatus = nullptr);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000383
kkinnunen2e6055b2016-04-22 01:48:29 -0700384 bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo,
385 GrGLRenderTarget::IDDesc*);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000386
egdanield803f272015-03-18 13:01:52 -0700387 enum TempFBOTarget {
388 kSrc_TempFBOTarget,
389 kDst_TempFBOTarget
390 };
egdaniel0f5f9672015-02-03 11:10:51 -0800391
Brian Salomond17b4a62017-05-23 16:53:47 -0400392 // Binds a surface as a FBO for copying, reading, or clearing. If the surface already owns an
393 // FBO ID then that ID is bound. If not the surface is temporarily bound to a FBO and that FBO
394 // is bound. This must be paired with a call to unbindSurfaceFBOForPixelOps().
Brian Salomon71d9d842016-11-03 13:42:00 -0400395 void bindSurfaceFBOForPixelOps(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport,
396 TempFBOTarget tempFBOTarget);
egdaniel0f5f9672015-02-03 11:10:51 -0800397
Brian Salomon71d9d842016-11-03 13:42:00 -0400398 // Must be called if bindSurfaceFBOForPixelOps was used to bind a surface for copying.
399 void unbindTextureFBOForPixelOps(GrGLenum fboTarget, GrSurface* surface);
robertphillips754f4e92014-09-18 13:52:08 -0700400
Brian Osman71a18892017-08-10 10:23:25 -0400401 void onDumpJSON(SkJSONWriter*) const override;
402
Brian Salomonbf7b6202016-11-11 16:08:03 -0500403 bool createCopyProgram(GrTexture* srcTexture);
brianosman33f6b3f2016-06-02 05:49:21 -0700404 bool createMipmapProgram(int progIdx);
Mike Klein31550db2017-06-06 23:29:53 +0000405 bool createStencilClipClearProgram();
Brian Salomon43f8bf02017-10-18 08:33:29 -0400406 bool createClearColorProgram();
ethannicholas22793252016-01-30 09:59:10 -0800407
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500408 std::unique_ptr<GrGLContext> fGLContext;
409
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000410 // GL program-related state
411 ProgramCache* fProgramCache;
bsalomon@google.com49209392012-06-05 15:13:46 +0000412
413 ///////////////////////////////////////////////////////////////////////////
414 ///@name Caching of GL State
415 ///@{
416 int fHWActiveTextureUnitIdx;
Brian Salomon802cb312018-06-08 18:05:20 -0400417
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000418 GrGLuint fHWProgramID;
Brian Salomon802cb312018-06-08 18:05:20 -0400419 sk_sp<GrGLProgram> fHWProgram;
bsalomon@google.com91207482013-02-12 21:45:24 +0000420
bsalomon@google.com49209392012-06-05 15:13:46 +0000421 enum TriState {
422 kNo_TriState,
423 kYes_TriState,
424 kUnknown_TriState
425 };
426
egdanield803f272015-03-18 13:01:52 -0700427 GrGLuint fTempSrcFBOID;
428 GrGLuint fTempDstFBOID;
429
430 GrGLuint fStencilClearFBOID;
bsalomondd3143b2015-02-23 09:27:45 -0800431
bsalomon@google.coma3201942012-06-21 19:58:20 +0000432 // last scissor / viewport scissor state seen by the GL.
433 struct {
434 TriState fEnabled;
435 GrGLIRect fRect;
436 void invalidate() {
437 fEnabled = kUnknown_TriState;
438 fRect.invalidate();
439 }
440 } fHWScissorSettings;
441
csmartdalton28341fa2016-08-17 10:00:21 -0700442 class {
443 public:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700444 bool valid() const { return kInvalidSurfaceOrigin != fRTOrigin; }
445 void invalidate() { fRTOrigin = kInvalidSurfaceOrigin; }
446 bool knownDisabled() const { return this->valid() && !fWindowState.enabled(); }
mtklein8b4a2022016-09-26 08:44:47 -0700447 void setDisabled() {
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400448 fRTOrigin = kTopLeft_GrSurfaceOrigin;
mtklein8b4a2022016-09-26 08:44:47 -0700449 fWindowState.setDisabled();
450 }
csmartdalton28341fa2016-08-17 10:00:21 -0700451
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700452 void set(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
453 const GrWindowRectsState& windowState) {
454 fRTOrigin = rtOrigin;
455 fViewport = viewport;
456 fWindowState = windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700457 }
csmartdalton28341fa2016-08-17 10:00:21 -0700458
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700459 bool knownEqualTo(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
460 const GrWindowRectsState& windowState) const {
csmartdalton28341fa2016-08-17 10:00:21 -0700461 if (!this->valid()) {
462 return false;
463 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700464 if (fWindowState.numWindows() && (fRTOrigin != rtOrigin || fViewport != viewport)) {
csmartdalton28341fa2016-08-17 10:00:21 -0700465 return false;
466 }
Brian Salomon9a767722017-03-13 17:57:28 -0400467 return fWindowState == windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700468 }
469
470 private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700471 enum { kInvalidSurfaceOrigin = -1 };
csmartdalton28341fa2016-08-17 10:00:21 -0700472
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700473 int fRTOrigin;
csmartdalton28341fa2016-08-17 10:00:21 -0700474 GrGLIRect fViewport;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700475 GrWindowRectsState fWindowState;
476 } fHWWindowRectsState;
csmartdalton28341fa2016-08-17 10:00:21 -0700477
bsalomon424cc262015-05-22 10:37:30 -0700478 GrGLIRect fHWViewport;
bsalomon@google.coma3201942012-06-21 19:58:20 +0000479
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000480 /**
cdaltone2e71c22016-04-07 18:13:29 -0700481 * Tracks vertex attrib array state.
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000482 */
cdaltone2e71c22016-04-07 18:13:29 -0700483 class HWVertexArrayState {
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000484 public:
cdaltone2e71c22016-04-07 18:13:29 -0700485 HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); }
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000486
cdaltone2e71c22016-04-07 18:13:29 -0700487 ~HWVertexArrayState() { delete fCoreProfileVertexArray; }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000488
bsalomon@google.com6918d482013-03-07 19:09:11 +0000489 void invalidate() {
490 fBoundVertexArrayIDIsValid = false;
bsalomon@google.com6918d482013-03-07 19:09:11 +0000491 fDefaultVertexArrayAttribState.invalidate();
cdaltone2e71c22016-04-07 18:13:29 -0700492 if (fCoreProfileVertexArray) {
493 fCoreProfileVertexArray->invalidateCachedState();
commit-bot@chromium.orgce6da4d2013-09-09 14:55:37 +0000494 }
bsalomon@google.com6918d482013-03-07 19:09:11 +0000495 }
496
497 void notifyVertexArrayDelete(GrGLuint id) {
498 if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) {
499 // Does implicit bind to 0
500 fBoundVertexArrayID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000501 }
502 }
503
bsalomon861e1032014-12-16 07:33:49 -0800504 void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000505 if (!gpu->glCaps().vertexArrayObjectSupport()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000506 SkASSERT(0 == arrayID);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000507 return;
508 }
509 if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) {
510 GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID));
511 fBoundVertexArrayIDIsValid = true;
512 fBoundVertexArrayID = arrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000513 }
514 }
515
bsalomon@google.com6918d482013-03-07 19:09:11 +0000516 /**
cdaltone2e71c22016-04-07 18:13:29 -0700517 * Binds the vertex array that should be used for internal draws, and returns its attrib
518 * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which
519 * case we use a dummy array instead.
520 *
521 * If an index buffer is privided, it will be bound to the vertex array. Otherwise the
522 * index buffer binding will be left unchanged.
523 *
524 * The returned GrGLAttribArrayState should be used to set vertex attribute arrays.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000525 */
csmartdalton485a1202016-07-13 10:16:32 -0700526 GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrBuffer* ibuff = nullptr);
bsalomon6df86402015-06-01 10:41:49 -0700527
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000528 private:
Robert Phillips294870f2016-11-11 12:38:40 -0500529 GrGLuint fBoundVertexArrayID;
530 bool fBoundVertexArrayIDIsValid;
mtklein044d3c12016-04-06 18:24:34 -0700531
bsalomon@google.com6918d482013-03-07 19:09:11 +0000532 // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
jvanverth39edf762014-12-22 11:44:19 -0800533 // is bound. However, this class is internal to GrGLGpu and this object never leaks out of
534 // GrGLGpu.
Robert Phillips294870f2016-11-11 12:38:40 -0500535 GrGLAttribArrayState fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000536
cdaltone2e71c22016-04-07 18:13:29 -0700537 // This is used when we're using a core profile.
Robert Phillips294870f2016-11-11 12:38:40 -0500538 GrGLVertexArray* fCoreProfileVertexArray;
539 } fHWVertexArrayState;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000540
cdaltone2e71c22016-04-07 18:13:29 -0700541 struct {
Robert Phillips294870f2016-11-11 12:38:40 -0500542 GrGLenum fGLTarget;
543 GrGpuResource::UniqueID fBoundBufferUniqueID;
544 bool fBufferZeroKnownBound;
cdaltone2e71c22016-04-07 18:13:29 -0700545
546 void invalidate() {
Robert Phillips294870f2016-11-11 12:38:40 -0500547 fBoundBufferUniqueID.makeInvalid();
cdaltone2e71c22016-04-07 18:13:29 -0700548 fBufferZeroKnownBound = false;
549 }
Robert Phillips294870f2016-11-11 12:38:40 -0500550 } fHWBufferState[kGrBufferTypeCount];
cdaltonc1613102016-03-16 07:48:20 -0700551
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000552 struct {
cdalton8917d622015-05-06 13:40:21 -0700553 GrBlendEquation fEquation;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000554 GrBlendCoeff fSrcCoeff;
555 GrBlendCoeff fDstCoeff;
556 GrColor fConstColor;
557 bool fConstColorValid;
558 TriState fEnabled;
559
560 void invalidate() {
bsalomonf7cc8772015-05-11 11:21:14 -0700561 fEquation = static_cast<GrBlendEquation>(-1);
562 fSrcCoeff = static_cast<GrBlendCoeff>(-1);
563 fDstCoeff = static_cast<GrBlendCoeff>(-1);
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000564 fConstColorValid = false;
565 fEnabled = kUnknown_TriState;
566 }
Robert Phillips294870f2016-11-11 12:38:40 -0500567 } fHWBlendState;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000568
bsalomon54c6fe82015-12-16 11:51:22 -0800569 TriState fMSAAEnabled;
570
Robert Phillips294870f2016-11-11 12:38:40 -0500571 GrStencilSettings fHWStencilSettings;
572 TriState fHWStencilTestEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800573
574
Robert Phillips294870f2016-11-11 12:38:40 -0500575 TriState fHWWriteToColor;
576 GrGpuResource::UniqueID fHWBoundRenderTargetUniqueID;
577 TriState fHWSRGBFramebuffer;
578 SkTArray<GrGpuResource::UniqueID, true> fHWBoundTextureUniqueIDs;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800579
Adrienne Walker4ee88512018-05-17 11:37:14 -0700580 GrGLuint fBoundDrawFramebuffer = 0;
581
cdaltonaf8bc7d2016-02-05 09:35:20 -0800582 // EXT_raster_multisample.
Robert Phillips294870f2016-11-11 12:38:40 -0500583 TriState fHWRasterMultisampleEnabled;
584 int fHWNumRasterSamples;
bsalomon54c6fe82015-12-16 11:51:22 -0800585 ///@}
586
Brian Salomon57111332018-02-05 15:55:54 -0500587 /** IDs for copy surface program. (3 sampler types) */
bsalomon6df86402015-06-01 10:41:49 -0700588 struct {
Brian Salomon43f8bf02017-10-18 08:33:29 -0400589 GrGLuint fProgram = 0;
590 GrGLint fTextureUniform = 0;
591 GrGLint fTexCoordXformUniform = 0;
592 GrGLint fPosXformUniform = 0;
Brian Salomon57111332018-02-05 15:55:54 -0500593 } fCopyPrograms[3];
Robert Phillips294870f2016-11-11 12:38:40 -0500594 sk_sp<GrGLBuffer> fCopyProgramArrayBuffer;
bsalomon7ea33f52015-11-22 14:51:00 -0800595
brianosman33f6b3f2016-06-02 05:49:21 -0700596 /** IDs for texture mipmap program. (4 filter configurations) */
597 struct {
Brian Salomon43f8bf02017-10-18 08:33:29 -0400598 GrGLuint fProgram = 0;
599 GrGLint fTextureUniform = 0;
600 GrGLint fTexCoordXformUniform = 0;
Robert Phillips294870f2016-11-11 12:38:40 -0500601 } fMipmapPrograms[4];
602 sk_sp<GrGLBuffer> fMipmapProgramArrayBuffer;
brianosman33f6b3f2016-06-02 05:49:21 -0700603
Brian Salomon43f8bf02017-10-18 08:33:29 -0400604 GrGLuint fStencilClipClearProgram = 0;
Mike Klein31550db2017-06-06 23:29:53 +0000605 sk_sp<GrGLBuffer> fStencilClipClearArrayBuffer;
bsalomon6dea83f2015-12-03 12:58:06 -0800606
Brian Salomon43f8bf02017-10-18 08:33:29 -0400607 /** IDs for clear render target color program. */
608 struct {
609 GrGLuint fProgram = 0;
610 GrGLint fColorUniform = 0;
611 } fClearColorProgram;
612 sk_sp<GrGLBuffer> fClearProgramArrayBuffer;
613
Robert Phillips646e4292017-06-13 12:44:56 -0400614 static int TextureToCopyProgramIdx(GrTexture* texture);
bsalomon6df86402015-06-01 10:41:49 -0700615
brianosman33f6b3f2016-06-02 05:49:21 -0700616 static int TextureSizeToMipmapProgramIdx(int width, int height) {
617 const bool wide = (width > 1) && SkToBool(width & 0x1);
618 const bool tall = (height > 1) && SkToBool(height & 0x1);
619 return (wide ? 0x2 : 0x0) | (tall ? 0x1 : 0x0);
620 }
621
Chris Daltonda40cd22018-04-16 13:19:58 -0600622 float fHWMinSampleShading;
623 GrPrimitiveType fLastPrimitiveType;
624 bool fRequiresFlushBeforeNextInstancedDraw = false;
ethannicholas28ef4452016-03-25 09:26:03 -0700625
reed@google.comac10a2d2010-12-22 21:39:39 +0000626 typedef GrGpu INHERITED;
kkinnunenccdaa042014-08-20 01:36:23 -0700627 friend class GrGLPathRendering; // For accessing setTextureUnit.
reed@google.comac10a2d2010-12-22 21:39:39 +0000628};
629
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000630#endif