blob: 87f452fc98dd35ff6dc5d5218f55ad1a93e87e6b [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 Salomon930f9392018-06-20 16:25:26 -040059 void bindTexture(int unitIdx, const 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.
csmartdalton485a1202016-07-13 10:16:32 -070077 GrGLenum bindBuffer(GrBufferType 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.
Brian Salomonff168d92018-06-23 15:17:27 -040082 void draw(const GrPrimitiveProcessor&,
83 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -040084 const GrPipeline::FixedDynamicState*,
85 const GrPipeline::DynamicStateArrays*,
Chris Dalton46983b72017-06-06 12:27:16 -060086 const GrMesh[],
egdaniel9cb63402016-06-23 08:37:05 -070087 int meshCount);
88
Chris Dalton114a3c02017-05-26 15:17:19 -060089 // GrMesh::SendToGpuImpl methods. These issue the actual GL draw calls.
90 // Marked final as a hint to the compiler to not use virtual dispatch.
Brian Salomon802cb312018-06-08 18:05:20 -040091 void sendMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount,
92 int baseVertex) final;
Chris Dalton114a3c02017-05-26 15:17:19 -060093
Brian Salomon802cb312018-06-08 18:05:20 -040094 void sendIndexedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount,
95 int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue,
96 const GrBuffer* vertexBuffer, int baseVertex,
97 GrPrimitiveRestart) final;
Chris Dalton114a3c02017-05-26 15:17:19 -060098
Brian Salomon802cb312018-06-08 18:05:20 -040099 void sendInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* vertexBuffer, int vertexCount,
100 int baseVertex, const GrBuffer* instanceBuffer, int instanceCount,
Chris Dalton1d616352017-05-31 12:51:23 -0600101 int baseInstance) final;
102
Brian Salomon802cb312018-06-08 18:05:20 -0400103 void sendIndexedInstancedMeshToGpu(GrPrimitiveType, const GrBuffer* indexBuffer, int indexCount,
104 int baseIndex, const GrBuffer* vertexBuffer, int baseVertex,
Chris Dalton1d616352017-05-31 12:51:23 -0600105 const GrBuffer* instanceBuffer, int instanceCount,
Brian Salomon802cb312018-06-08 18:05:20 -0400106 int baseInstance, GrPrimitiveRestart) final;
Chris Dalton1d616352017-05-31 12:51:23 -0600107
Greg Daniel500d58b2017-08-24 15:59:33 -0400108 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700109 // Thus this is the implementation of the clear call for the corresponding passthrough function
Greg Daniel500d58b2017-08-24 15:59:33 -0400110 // on GrGLGpuRTCommandBuffer.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400111 void clear(const GrFixedClip&, GrColor, GrRenderTarget*, GrSurfaceOrigin);
Brian Salomon43f8bf02017-10-18 08:33:29 -0400112 void clearColorAsDraw(const GrFixedClip&, GrGLfloat r, GrGLfloat g, GrGLfloat b, GrGLfloat a,
113 GrRenderTarget*, GrSurfaceOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700114
Greg Daniel500d58b2017-08-24 15:59:33 -0400115 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700116 // Thus this is the implementation of the clearStencil call for the corresponding passthrough
Greg Daniel500d58b2017-08-24 15:59:33 -0400117 // function on GrGLGpuRTCommandBuffer.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400118 void clearStencilClip(const GrFixedClip&, bool insideStencilMask,
119 GrRenderTarget*, GrSurfaceOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700120
Greg Danielcfa39352018-10-05 12:01:59 -0400121 void clearStencil(GrRenderTarget*, int clearValue);
egdanielec00d942015-09-14 12:56:10 -0700122
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400123 GrGpuRTCommandBuffer* getCommandBuffer(
Ethan Nicholas56d19a52018-10-15 11:26:20 -0400124 GrRenderTarget*, GrSurfaceOrigin, const SkRect&,
Greg Daniel500d58b2017-08-24 15:59:33 -0400125 const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
126 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
127
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400128 GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
egdaniel066df7c2016-06-08 14:02:27 -0700129
egdanielec00d942015-09-14 12:56:10 -0700130 void invalidateBoundRenderTarget() {
Robert Phillips294870f2016-11-11 12:38:40 -0500131 fHWBoundRenderTargetUniqueID.makeInvalid();
egdanielec00d942015-09-14 12:56:10 -0700132 }
133
134 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
135 int width,
136 int height) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500137#if GR_TEST_UTILS
Brian Salomon52e943a2018-03-13 09:32:39 -0400138 GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
Robert Phillips646f6372018-09-25 09:31:10 -0400139 GrColorType colorType, bool isRenderTarget,
140 GrMipMapped mipMapped,
141 size_t rowBytes = 0) override;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500142 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Brian Salomon26102cb2018-03-09 09:33:19 -0500143 void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
jvanverth672bb7f2015-07-13 07:19:57 -0700144
Brian Osman2d010b62018-08-09 10:55:09 -0400145 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500146
147 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
148
149 const GrGLContext* glContextForTesting() const override { return &this->glContext(); }
150
151 void resetShaderCacheForTesting() const override { fProgramCache->abandon(); }
joshualitt8fd844f2015-12-02 13:36:47 -0800152
Greg Daniel26b50a42018-03-08 09:49:58 -0500153 void testingOnly_flushGpuAndSync() override;
Brian Salomonf865b052018-03-09 09:01:53 -0500154#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500155
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400156 void submit(GrGpuCommandBuffer* buffer) override;
157
Greg Daniel6be35232017-03-01 17:01:09 -0500158 GrFence SK_WARN_UNUSED_RESULT insertFence() override;
159 bool waitFence(GrFence, uint64_t timeout) override;
jvanverth84741b32016-09-30 08:39:02 -0700160 void deleteFence(GrFence) const override;
161
Greg Daniela5cb7812017-06-16 09:45:32 -0400162 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override;
Greg Daniel48661b82018-01-22 16:11:35 -0500163 sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
164 GrResourceProvider::SemaphoreWrapType wrapType,
165 GrWrapOwnership ownership) override;
166 void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override;
167 void waitSemaphore(sk_sp<GrSemaphore> semaphore) override;
Greg Daniel6be35232017-03-01 17:01:09 -0500168
Brian Osman13dddce2017-05-09 13:19:50 -0400169 sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
170
Greg Daniel6be35232017-03-01 17:01:09 -0500171 void deleteSync(GrGLsync) const;
172
Robert Phillips65a88fa2017-08-08 08:36:22 -0400173 void insertEventMarker(const char*);
174
Adrienne Walker4ee88512018-05-17 11:37:14 -0700175 void bindFramebuffer(GrGLenum fboTarget, GrGLuint fboid);
176 void deleteFramebuffer(GrGLuint fboid);
Adrienne Walker3ed33992018-05-15 11:44:34 -0700177
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000178private:
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500179 GrGLGpu(std::unique_ptr<GrGLContext>, GrContext*);
bsalomon424cc262015-05-22 10:37:30 -0700180
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000181 // GrGpu overrides
mtklein36352bf2015-03-25 18:17:31 -0700182 void onResetContext(uint32_t resetBits) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000183
bsalomoncb02b382015-08-12 11:14:50 -0700184 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
185
Robert Phillips67d52cf2017-06-05 13:38:13 -0400186 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
Brian Salomon58389b92018-03-07 13:01:25 -0500187 const GrMipLevel texels[], int mipLevelCount) override;
cblume55f2d2d2016-02-26 13:20:48 -0800188
cdalton1bf3e712016-04-19 10:00:02 -0700189 GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
190 const void* data) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000191
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400192 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override;
Brian Salomond17f6582017-07-19 18:28:58 -0400193 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -0400194 int sampleCnt,
195 GrWrapOwnership) override;
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400196 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000197 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Greg Daniel7ef28f32017-04-20 16:41:55 +0000198 int sampleCnt) override;
csmartdaltone0d36292016-07-29 08:14:20 -0700199
egdanielff1d5472015-09-10 08:37:20 -0700200 // Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a
bsalomon62a627b2015-12-17 09:50:47 -0800201 // compatible stencil format, or negative if there is no compatible stencil format.
egdanielff1d5472015-09-10 08:37:20 -0700202 int getCompatibleStencilIndex(GrPixelConfig config);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000203
Adrienne Walkerca0cdef2018-08-20 13:49:40 -0700204 void onFBOChanged();
bsalomon7e68ab72016-04-13 14:29:25 -0700205
erikchen9a1ed5d2016-02-10 16:32:34 -0800206 // Returns whether the texture is successfully created. On success, the
207 // result is stored in |info|.
cblume55f2d2d2016-02-26 13:20:48 -0800208 // The texture is populated with |texels|, if it exists.
erikchen9a1ed5d2016-02-10 16:32:34 -0800209 // The texture parameters are cached in |initialTexParams|.
Brian Salomon2a4f9832018-03-03 22:43:43 -0500210 bool createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info, bool renderTarget,
Brian Salomon58389b92018-03-07 13:01:25 -0500211 GrGLTexture::TexParams* initialTexParams, const GrMipLevel texels[],
212 int mipLevelCount, GrMipMapsStatus* mipMapsStatus);
erikchen9a1ed5d2016-02-10 16:32:34 -0800213
bsalomon1aa20292016-01-22 08:16:09 -0800214 // Checks whether glReadPixels can be called to get pixel values in readConfig from the
215 // render target.
216 bool readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConfig);
217
218 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
219 // render target that has renderTargetConfig. This may have to create a temporary
220 // render target and thus is less preferable than the variant that takes a render target.
221 bool readPixelsSupported(GrPixelConfig renderTargetConfig, GrPixelConfig readConfig);
222
223 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
224 // render target that has the same config as surfaceForConfig. Calls one of the the two
225 // variations above, depending on whether the surface is a render target or not.
226 bool readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig readConfig);
227
Brian Salomona6948702018-06-01 15:33:20 -0400228 bool onReadPixels(GrSurface*, int left, int top, int width, int height, GrColorType,
229 void* buffer, size_t rowBytes) override;
bsalomond95263c2014-12-16 13:05:12 -0800230
Brian Salomona9b04b92018-06-01 15:04:28 -0400231 bool onWritePixels(GrSurface*, int left, int top, int width, int height, GrColorType,
232 const GrMipLevel texels[], int mipLevelCount) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000233
Brian Salomonc320b152018-02-20 14:05:36 -0500234 bool onTransferPixels(GrTexture*, int left, int top, int width, int height, GrColorType,
235 GrBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
jvanverth17aa0472016-01-05 10:41:27 -0800236
Brian Osman9b560242017-09-05 15:34:52 -0400237 // Before calling any variation of TexImage, TexSubImage, etc..., call this to ensure that the
238 // PIXEL_UNPACK_BUFFER is unbound.
239 void unbindCpuToGpuXferBuffer();
240
Brian Salomon1fabd512018-02-09 09:54:25 -0500241 void onResolveRenderTarget(GrRenderTarget* target) override;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000242
Brian Salomon930f9392018-06-20 16:25:26 -0400243 bool onRegenerateMipMapLevels(GrTexture*) override;
244
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400245 bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin,
246 GrSurface* src, GrSurfaceOrigin srcOrigin,
Greg Daniel55fa6472018-03-16 16:13:10 -0400247 const SkIRect& srcRect, const SkIPoint& dstPoint,
248 bool canDiscardOutsideDstRect) override;
joshualitt1cbdcde2015-08-21 11:53:29 -0700249
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000250 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000251 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000252
cdalton74b8d322016-04-11 14:47:28 -0700253 void setTextureSwizzle(int unitIdx, GrGLenum target, const GrGLenum swizzle[]);
254
Brian Salomonf7232642018-09-19 08:58:08 -0400255 /**
256 * primitiveProcessorTextures must contain GrPrimitiveProcessor::numTextureSamplers() *
257 * numPrimitiveProcessorTextureSets entries.
258 */
259 void resolveAndGenerateMipMapsForProcessorTextures(
Brian Salomon7eae3e02018-08-07 14:02:38 +0000260 const GrPrimitiveProcessor&, const GrPipeline&,
Brian Salomonf7232642018-09-19 08:58:08 -0400261 const GrTextureProxy* const primitiveProcessorTextures[],
262 int numPrimitiveProcessorTextureSets);
Brian Salomondfec99f2018-08-02 10:40:05 -0400263
egdaniel8dd688b2015-01-22 10:16:09 -0800264 // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set.
bsalomon2eda5b32016-09-21 10:53:24 -0700265 // willDrawPoints must be true if point primitives will be rendered after setting the GL state.
Brian Salomonf7232642018-09-19 08:58:08 -0400266 // If DynamicStateArrays is not null then dynamicStateArraysLength is the number of dynamic
267 // state entries in each array.
Brian Salomon49348902018-06-26 09:12:38 -0400268 bool flushGLState(const GrPrimitiveProcessor&, const GrPipeline&,
Brian Salomonf7232642018-09-19 08:58:08 -0400269 const GrPipeline::FixedDynamicState*, const GrPipeline::DynamicStateArrays*,
270 int dynamicStateArraysLength, bool willDrawPoints);
bsalomond95263c2014-12-16 13:05:12 -0800271
Brian Salomon802cb312018-06-08 18:05:20 -0400272 void flushProgram(sk_sp<GrGLProgram>);
273
274 // Version for programs that aren't GrGLProgram.
275 void flushProgram(GrGLuint);
276
Chris Dalton114a3c02017-05-26 15:17:19 -0600277 // Sets up vertex/instance attribute pointers and strides.
Brian Salomon802cb312018-06-08 18:05:20 -0400278 void setupGeometry(const GrBuffer* indexBuffer,
Chris Daltonff926502017-05-03 14:36:54 -0400279 const GrBuffer* vertexBuffer,
Chris Dalton1d616352017-05-31 12:51:23 -0600280 int baseVertex,
281 const GrBuffer* instanceBuffer,
Brian Salomon802cb312018-06-08 18:05:20 -0400282 int baseInstance,
283 GrPrimitiveRestart);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000284
bsalomon7f9b2e42016-01-12 13:29:26 -0800285 void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000286
Greg Daniel51316782017-08-02 15:10:09 +0000287 void onFinishFlush(bool insertedSemaphores) override;
288
bsalomon424cc262015-05-22 10:37:30 -0700289 bool hasExtension(const char* ext) const { return fGLContext->hasExtension(ext); }
bsalomon@google.com96399942012-02-13 14:39:16 +0000290
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);
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400300 void clearStencilClipAsDraw(const GrFixedClip&, bool insideStencilMask,
301 GrRenderTarget*, GrSurfaceOrigin);
bsalomon6df86402015-06-01 10:41:49 -0700302
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000303 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
bsalomon@google.com080773c2011-03-15 19:09:25 +0000304
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000305 class ProgramCache : public ::SkNoncopyable {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000306 public:
bsalomon861e1032014-12-16 07:33:49 -0800307 ProgramCache(GrGLGpu* gpu);
jvanverth@google.com94878772013-03-12 16:00:54 +0000308 ~ProgramCache();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000309
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000310 void abandon();
Brian Salomonff168d92018-06-23 15:17:27 -0400311 GrGLProgram* refProgram(const GrGLGpu*, const GrPrimitiveProcessor&, const GrPipeline&,
bsalomon2eda5b32016-09-21 10:53:24 -0700312 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);
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000342
Brian Salomond818ebf2018-07-02 14:08:49 +0000343 // flushes the scissor. see the note on flushBoundTextureAndParams about
344 // flushing the scissor after that function is called.
345 void flushScissor(const GrScissorState&,
346 const GrGLIRect& rtViewport,
347 GrSurfaceOrigin rtOrigin);
348
349 // disables the scissor
350 void disableScissor();
bsalomon@google.coma3201942012-06-21 19:58:20 +0000351
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400352 void flushWindowRectangles(const GrWindowRectsState&, const GrGLRenderTarget*, GrSurfaceOrigin);
csmartdalton28341fa2016-08-17 10:00:21 -0700353 void disableWindowRectangles();
354
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000355 // sets a texture unit to use for texture operations other than binding a texture to a program.
356 // ensures that such operations don't negatively interact with tracking bound textures.
357 void setScratchTextureUnit();
reed@google.comac10a2d2010-12-22 21:39:39 +0000358
Brian Salomon1fabd512018-02-09 09:54:25 -0500359 // The passed bounds contains the render target's color values that will subsequently be
360 // written.
Chris Daltonc8ece3d2018-07-30 15:03:45 -0600361 void flushRenderTarget(GrGLRenderTarget*, GrSurfaceOrigin, const SkIRect& bounds);
362 // This version has an implicit bounds of the entire render target.
363 void flushRenderTarget(GrGLRenderTarget*);
Brian Salomon1fabd512018-02-09 09:54:25 -0500364 // This version can be used when the render target's colors will not be written.
Brian Osman9aa30c62018-07-02 15:21:46 -0400365 void flushRenderTargetNoColorWrites(GrGLRenderTarget*);
bsalomon083617b2016-02-12 12:10:14 -0800366
367 // Need not be called if flushRenderTarget is used.
368 void flushViewport(const GrGLIRect&);
bsalomonb0bd4f62014-09-03 07:19:50 -0700369
bsalomon3e791242014-12-17 13:43:13 -0800370 void flushStencil(const GrStencilSettings&);
csmartdaltonc7d85332016-10-26 10:13:46 -0700371 void disableStencil();
bsalomon083617b2016-02-12 12:10:14 -0800372
373 // rt is used only if useHWAA is true.
cdaltonaf8bc7d2016-02-05 09:35:20 -0800374 void flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabled);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000375
ethannicholas28ef4452016-03-25 09:26:03 -0700376 void flushMinSampleShading(float minSampleShading);
377
brianosman33f6b3f2016-06-02 05:49:21 -0700378 void flushFramebufferSRGB(bool enable);
379
bsalomon@google.com6f379512011-11-16 20:36:03 +0000380 // helper for onCreateTexture and writeTexturePixels
jvanverth17aa0472016-01-05 10:41:27 -0800381 enum UploadType {
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400382 kNewTexture_UploadType, // we are creating a new texture
383 kWrite_UploadType, // we are using TexSubImage2D to copy data to an existing texture
jvanverth17aa0472016-01-05 10:41:27 -0800384 };
Brian Salomona9b04b92018-06-01 15:04:28 -0400385 bool uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight, GrGLenum target,
386 UploadType uploadType, int left, int top, int width, int height,
387 GrPixelConfig dataConfig, const GrMipLevel texels[], int mipLevelCount,
Greg Daniel0fc4d2d2017-10-12 11:23:36 -0400388 GrMipMapsStatus* mipMapsStatus = nullptr);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000389
kkinnunen2e6055b2016-04-22 01:48:29 -0700390 bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo,
391 GrGLRenderTarget::IDDesc*);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000392
egdanield803f272015-03-18 13:01:52 -0700393 enum TempFBOTarget {
394 kSrc_TempFBOTarget,
395 kDst_TempFBOTarget
396 };
egdaniel0f5f9672015-02-03 11:10:51 -0800397
Brian Salomond17b4a62017-05-23 16:53:47 -0400398 // Binds a surface as a FBO for copying, reading, or clearing. If the surface already owns an
399 // FBO ID then that ID is bound. If not the surface is temporarily bound to a FBO and that FBO
400 // is bound. This must be paired with a call to unbindSurfaceFBOForPixelOps().
Brian Salomon71d9d842016-11-03 13:42:00 -0400401 void bindSurfaceFBOForPixelOps(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport,
402 TempFBOTarget tempFBOTarget);
egdaniel0f5f9672015-02-03 11:10:51 -0800403
Brian Salomon71d9d842016-11-03 13:42:00 -0400404 // Must be called if bindSurfaceFBOForPixelOps was used to bind a surface for copying.
405 void unbindTextureFBOForPixelOps(GrGLenum fboTarget, GrSurface* surface);
robertphillips754f4e92014-09-18 13:52:08 -0700406
Kevin Lubickf4def342018-10-04 12:52:50 -0400407#ifdef SK_ENABLE_DUMP_GPU
Brian Osman71a18892017-08-10 10:23:25 -0400408 void onDumpJSON(SkJSONWriter*) const override;
Kevin Lubickf4def342018-10-04 12:52:50 -0400409#endif
Brian Osman71a18892017-08-10 10:23:25 -0400410
Brian Salomonbf7b6202016-11-11 16:08:03 -0500411 bool createCopyProgram(GrTexture* srcTexture);
brianosman33f6b3f2016-06-02 05:49:21 -0700412 bool createMipmapProgram(int progIdx);
Mike Klein31550db2017-06-06 23:29:53 +0000413 bool createStencilClipClearProgram();
Brian Salomon43f8bf02017-10-18 08:33:29 -0400414 bool createClearColorProgram();
ethannicholas22793252016-01-30 09:59:10 -0800415
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500416 std::unique_ptr<GrGLContext> fGLContext;
417
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000418 // GL program-related state
419 ProgramCache* fProgramCache;
bsalomon@google.com49209392012-06-05 15:13:46 +0000420
421 ///////////////////////////////////////////////////////////////////////////
422 ///@name Caching of GL State
423 ///@{
424 int fHWActiveTextureUnitIdx;
Brian Salomon802cb312018-06-08 18:05:20 -0400425
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000426 GrGLuint fHWProgramID;
Brian Salomon802cb312018-06-08 18:05:20 -0400427 sk_sp<GrGLProgram> fHWProgram;
bsalomon@google.com91207482013-02-12 21:45:24 +0000428
bsalomon@google.com49209392012-06-05 15:13:46 +0000429 enum TriState {
430 kNo_TriState,
431 kYes_TriState,
432 kUnknown_TriState
433 };
434
egdanield803f272015-03-18 13:01:52 -0700435 GrGLuint fTempSrcFBOID;
436 GrGLuint fTempDstFBOID;
437
438 GrGLuint fStencilClearFBOID;
bsalomondd3143b2015-02-23 09:27:45 -0800439
bsalomon@google.coma3201942012-06-21 19:58:20 +0000440 // last scissor / viewport scissor state seen by the GL.
441 struct {
442 TriState fEnabled;
443 GrGLIRect fRect;
444 void invalidate() {
445 fEnabled = kUnknown_TriState;
446 fRect.invalidate();
447 }
448 } fHWScissorSettings;
449
csmartdalton28341fa2016-08-17 10:00:21 -0700450 class {
451 public:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700452 bool valid() const { return kInvalidSurfaceOrigin != fRTOrigin; }
453 void invalidate() { fRTOrigin = kInvalidSurfaceOrigin; }
454 bool knownDisabled() const { return this->valid() && !fWindowState.enabled(); }
mtklein8b4a2022016-09-26 08:44:47 -0700455 void setDisabled() {
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400456 fRTOrigin = kTopLeft_GrSurfaceOrigin;
mtklein8b4a2022016-09-26 08:44:47 -0700457 fWindowState.setDisabled();
458 }
csmartdalton28341fa2016-08-17 10:00:21 -0700459
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700460 void set(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
461 const GrWindowRectsState& windowState) {
462 fRTOrigin = rtOrigin;
463 fViewport = viewport;
464 fWindowState = windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700465 }
csmartdalton28341fa2016-08-17 10:00:21 -0700466
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700467 bool knownEqualTo(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
468 const GrWindowRectsState& windowState) const {
csmartdalton28341fa2016-08-17 10:00:21 -0700469 if (!this->valid()) {
470 return false;
471 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700472 if (fWindowState.numWindows() && (fRTOrigin != rtOrigin || fViewport != viewport)) {
csmartdalton28341fa2016-08-17 10:00:21 -0700473 return false;
474 }
Brian Salomon9a767722017-03-13 17:57:28 -0400475 return fWindowState == windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700476 }
477
478 private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700479 enum { kInvalidSurfaceOrigin = -1 };
csmartdalton28341fa2016-08-17 10:00:21 -0700480
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700481 int fRTOrigin;
csmartdalton28341fa2016-08-17 10:00:21 -0700482 GrGLIRect fViewport;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700483 GrWindowRectsState fWindowState;
484 } fHWWindowRectsState;
csmartdalton28341fa2016-08-17 10:00:21 -0700485
bsalomon424cc262015-05-22 10:37:30 -0700486 GrGLIRect fHWViewport;
bsalomon@google.coma3201942012-06-21 19:58:20 +0000487
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000488 /**
cdaltone2e71c22016-04-07 18:13:29 -0700489 * Tracks vertex attrib array state.
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000490 */
cdaltone2e71c22016-04-07 18:13:29 -0700491 class HWVertexArrayState {
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000492 public:
cdaltone2e71c22016-04-07 18:13:29 -0700493 HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); }
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000494
cdaltone2e71c22016-04-07 18:13:29 -0700495 ~HWVertexArrayState() { delete fCoreProfileVertexArray; }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000496
bsalomon@google.com6918d482013-03-07 19:09:11 +0000497 void invalidate() {
498 fBoundVertexArrayIDIsValid = false;
bsalomon@google.com6918d482013-03-07 19:09:11 +0000499 fDefaultVertexArrayAttribState.invalidate();
cdaltone2e71c22016-04-07 18:13:29 -0700500 if (fCoreProfileVertexArray) {
501 fCoreProfileVertexArray->invalidateCachedState();
commit-bot@chromium.orgce6da4d2013-09-09 14:55:37 +0000502 }
bsalomon@google.com6918d482013-03-07 19:09:11 +0000503 }
504
505 void notifyVertexArrayDelete(GrGLuint id) {
506 if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) {
507 // Does implicit bind to 0
508 fBoundVertexArrayID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000509 }
510 }
511
bsalomon861e1032014-12-16 07:33:49 -0800512 void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000513 if (!gpu->glCaps().vertexArrayObjectSupport()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000514 SkASSERT(0 == arrayID);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000515 return;
516 }
517 if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) {
518 GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID));
519 fBoundVertexArrayIDIsValid = true;
520 fBoundVertexArrayID = arrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000521 }
522 }
523
bsalomon@google.com6918d482013-03-07 19:09:11 +0000524 /**
cdaltone2e71c22016-04-07 18:13:29 -0700525 * Binds the vertex array that should be used for internal draws, and returns its attrib
526 * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which
527 * case we use a dummy array instead.
528 *
529 * If an index buffer is privided, it will be bound to the vertex array. Otherwise the
530 * index buffer binding will be left unchanged.
531 *
532 * The returned GrGLAttribArrayState should be used to set vertex attribute arrays.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000533 */
csmartdalton485a1202016-07-13 10:16:32 -0700534 GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrBuffer* ibuff = nullptr);
bsalomon6df86402015-06-01 10:41:49 -0700535
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000536 private:
Robert Phillips294870f2016-11-11 12:38:40 -0500537 GrGLuint fBoundVertexArrayID;
538 bool fBoundVertexArrayIDIsValid;
mtklein044d3c12016-04-06 18:24:34 -0700539
bsalomon@google.com6918d482013-03-07 19:09:11 +0000540 // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
jvanverth39edf762014-12-22 11:44:19 -0800541 // is bound. However, this class is internal to GrGLGpu and this object never leaks out of
542 // GrGLGpu.
Robert Phillips294870f2016-11-11 12:38:40 -0500543 GrGLAttribArrayState fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000544
cdaltone2e71c22016-04-07 18:13:29 -0700545 // This is used when we're using a core profile.
Robert Phillips294870f2016-11-11 12:38:40 -0500546 GrGLVertexArray* fCoreProfileVertexArray;
547 } fHWVertexArrayState;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000548
cdaltone2e71c22016-04-07 18:13:29 -0700549 struct {
Robert Phillips294870f2016-11-11 12:38:40 -0500550 GrGLenum fGLTarget;
551 GrGpuResource::UniqueID fBoundBufferUniqueID;
552 bool fBufferZeroKnownBound;
cdaltone2e71c22016-04-07 18:13:29 -0700553
554 void invalidate() {
Robert Phillips294870f2016-11-11 12:38:40 -0500555 fBoundBufferUniqueID.makeInvalid();
cdaltone2e71c22016-04-07 18:13:29 -0700556 fBufferZeroKnownBound = false;
557 }
Robert Phillips294870f2016-11-11 12:38:40 -0500558 } fHWBufferState[kGrBufferTypeCount];
cdaltonc1613102016-03-16 07:48:20 -0700559
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000560 struct {
cdalton8917d622015-05-06 13:40:21 -0700561 GrBlendEquation fEquation;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000562 GrBlendCoeff fSrcCoeff;
563 GrBlendCoeff fDstCoeff;
564 GrColor fConstColor;
565 bool fConstColorValid;
566 TriState fEnabled;
567
568 void invalidate() {
Mike Kleinab5fec92018-08-16 19:43:31 +0000569 fEquation = static_cast<GrBlendEquation>(-1);
570 fSrcCoeff = static_cast<GrBlendCoeff>(-1);
571 fDstCoeff = static_cast<GrBlendCoeff>(-1);
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000572 fConstColorValid = false;
573 fEnabled = kUnknown_TriState;
574 }
Robert Phillips294870f2016-11-11 12:38:40 -0500575 } fHWBlendState;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000576
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400577 TriState fMSAAEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800578
Robert Phillips294870f2016-11-11 12:38:40 -0500579 GrStencilSettings fHWStencilSettings;
580 TriState fHWStencilTestEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800581
582
Robert Phillips294870f2016-11-11 12:38:40 -0500583 TriState fHWWriteToColor;
584 GrGpuResource::UniqueID fHWBoundRenderTargetUniqueID;
585 TriState fHWSRGBFramebuffer;
586 SkTArray<GrGpuResource::UniqueID, true> fHWBoundTextureUniqueIDs;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800587
Adrienne Walker4ee88512018-05-17 11:37:14 -0700588 GrGLuint fBoundDrawFramebuffer = 0;
589
cdaltonaf8bc7d2016-02-05 09:35:20 -0800590 // EXT_raster_multisample.
Robert Phillips294870f2016-11-11 12:38:40 -0500591 TriState fHWRasterMultisampleEnabled;
592 int fHWNumRasterSamples;
bsalomon54c6fe82015-12-16 11:51:22 -0800593 ///@}
594
Brian Salomon57111332018-02-05 15:55:54 -0500595 /** IDs for copy surface program. (3 sampler types) */
bsalomon6df86402015-06-01 10:41:49 -0700596 struct {
Brian Salomon43f8bf02017-10-18 08:33:29 -0400597 GrGLuint fProgram = 0;
598 GrGLint fTextureUniform = 0;
599 GrGLint fTexCoordXformUniform = 0;
600 GrGLint fPosXformUniform = 0;
Brian Salomon57111332018-02-05 15:55:54 -0500601 } fCopyPrograms[3];
Robert Phillips294870f2016-11-11 12:38:40 -0500602 sk_sp<GrGLBuffer> fCopyProgramArrayBuffer;
bsalomon7ea33f52015-11-22 14:51:00 -0800603
brianosman33f6b3f2016-06-02 05:49:21 -0700604 /** IDs for texture mipmap program. (4 filter configurations) */
605 struct {
Brian Salomon43f8bf02017-10-18 08:33:29 -0400606 GrGLuint fProgram = 0;
607 GrGLint fTextureUniform = 0;
608 GrGLint fTexCoordXformUniform = 0;
Robert Phillips294870f2016-11-11 12:38:40 -0500609 } fMipmapPrograms[4];
610 sk_sp<GrGLBuffer> fMipmapProgramArrayBuffer;
brianosman33f6b3f2016-06-02 05:49:21 -0700611
Brian Salomon43f8bf02017-10-18 08:33:29 -0400612 GrGLuint fStencilClipClearProgram = 0;
Mike Klein31550db2017-06-06 23:29:53 +0000613 sk_sp<GrGLBuffer> fStencilClipClearArrayBuffer;
bsalomon6dea83f2015-12-03 12:58:06 -0800614
Brian Salomon43f8bf02017-10-18 08:33:29 -0400615 /** IDs for clear render target color program. */
616 struct {
617 GrGLuint fProgram = 0;
618 GrGLint fColorUniform = 0;
619 } fClearColorProgram;
620 sk_sp<GrGLBuffer> fClearProgramArrayBuffer;
621
Robert Phillips646e4292017-06-13 12:44:56 -0400622 static int TextureToCopyProgramIdx(GrTexture* texture);
bsalomon6df86402015-06-01 10:41:49 -0700623
brianosman33f6b3f2016-06-02 05:49:21 -0700624 static int TextureSizeToMipmapProgramIdx(int width, int height) {
625 const bool wide = (width > 1) && SkToBool(width & 0x1);
626 const bool tall = (height > 1) && SkToBool(height & 0x1);
627 return (wide ? 0x2 : 0x0) | (tall ? 0x1 : 0x0);
628 }
629
Chris Daltonda40cd22018-04-16 13:19:58 -0600630 float fHWMinSampleShading;
631 GrPrimitiveType fLastPrimitiveType;
632 bool fRequiresFlushBeforeNextInstancedDraw = false;
ethannicholas28ef4452016-03-25 09:26:03 -0700633
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400634 std::unique_ptr<GrGLGpuRTCommandBuffer> fCachedRTCommandBuffer;
635 std::unique_ptr<GrGLGpuTextureCommandBuffer> fCachedTexCommandBuffer;
636
kkinnunenccdaa042014-08-20 01:36:23 -0700637 friend class GrGLPathRendering; // For accessing setTextureUnit.
Robert Phillips5b5d84c2018-08-09 15:12:18 -0400638
639 typedef GrGpu INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000640};
641
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000642#endif