blob: 20758c382c412055b70c347c9de84f852ff8f031 [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
csmartdaltona7f29642016-07-07 08:49:11 -070031namespace gr_instanced { class GLInstancedRendering; }
32
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:
bsalomon682c2692015-05-22 14:01:46 -070039 static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
40 GrContext* context);
Greg Daniel02611d92017-07-25 10:05:01 -040041 static GrGpu* Create(const GrGLInterface*, const GrContextOptions& options,
42 GrContext* context);
mtklein36352bf2015-03-25 18:17:31 -070043 ~GrGLGpu() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000044
bsalomon6e2aad42016-04-01 11:54:31 -070045 void disconnect(DisconnectType) override;
bsalomonc8dc1f72014-08-21 13:02:13 -070046
bsalomon424cc262015-05-22 10:37:30 -070047 const GrGLContext& glContext() const { return *fGLContext; }
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000048
bsalomon424cc262015-05-22 10:37:30 -070049 const GrGLInterface* glInterface() const { return fGLContext->interface(); }
50 const GrGLContextInfo& ctxInfo() const { return *fGLContext; }
51 GrGLStandard glStandard() const { return fGLContext->standard(); }
52 GrGLVersion glVersion() const { return fGLContext->version(); }
53 GrGLSLGeneration glslGeneration() const { return fGLContext->glslGeneration(); }
54 const GrGLCaps& glCaps() const { return *fGLContext->caps(); }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000055
kkinnunenccdaa042014-08-20 01:36:23 -070056 GrGLPathRendering* glPathRendering() {
jvanverthe9c0fc62015-04-29 11:18:05 -070057 SkASSERT(glCaps().shaderCaps()->pathRenderingSupport());
kkinnunenccdaa042014-08-20 01:36:23 -070058 return static_cast<GrGLPathRendering*>(pathRendering());
cdaltonc7103a12014-08-11 14:05:05 -070059 }
60
kkinnunencfe62e32015-07-01 02:58:50 -070061 // Used by GrGLProgram to configure OpenGL state.
Brian Salomon2bbdcc42017-09-07 12:36:34 -040062 void bindTexture(int unitIdx, const GrSamplerState& samplerState, bool allowSRGBInputs,
Robert Phillipsb0e93a22017-08-29 08:26:54 -040063 GrGLTexture* texture, GrSurfaceOrigin textureOrigin);
kkinnunenccdaa042014-08-20 01:36:23 -070064
csmartdalton1897cfd2016-06-03 08:50:54 -070065 void bindTexelBuffer(int unitIdx, GrPixelConfig, GrGLBuffer*);
cdalton74b8d322016-04-11 14:47:28 -070066
Brian Salomonf9f45122016-11-29 11:59:17 -050067 void bindImageStorage(int unitIdx, GrIOType, GrGLTexture *);
68
Brian Salomon2bbdcc42017-09-07 12:36:34 -040069 void generateMipmaps(const GrSamplerState& params, bool allowSRGBInputs, GrGLTexture* texture,
70 GrSurfaceOrigin textureOrigin);
brianosman33f6b3f2016-06-02 05:49:21 -070071
Robert Phillipsb0e93a22017-08-29 08:26:54 -040072 bool onGetReadPixelsInfo(GrSurface* srcSurface, GrSurfaceOrigin srcOrigin,
73 int readWidth, int readHeight, size_t rowBytes,
bsalomonf0674512015-07-28 13:26:15 -070074 GrPixelConfig readConfig, DrawPreference*,
75 ReadPixelTempDrawInfo*) override;
bsalomon39826022015-07-23 08:07:21 -070076
Robert Phillipsb0e93a22017-08-29 08:26:54 -040077 bool onGetWritePixelsInfo(GrSurface* dstSurface, GrSurfaceOrigin dstOrigin,
78 int width, int height,
cblumeed828002016-02-16 13:00:01 -080079 GrPixelConfig srcConfig, DrawPreference*,
bsalomonf0674512015-07-28 13:26:15 -070080 WritePixelTempDrawInfo*) override;
bsalomon@google.com75f9f252012-01-31 13:35:56 +000081
bsalomon@google.com6918d482013-03-07 19:09:11 +000082 // 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 +000083 // bindings. Making the equivalent glBind calls directly will confuse the state tracking.
bsalomon@google.com6918d482013-03-07 19:09:11 +000084 void bindVertexArray(GrGLuint id) {
cdaltone2e71c22016-04-07 18:13:29 -070085 fHWVertexArrayState.setVertexArrayID(this, id);
bsalomon@google.com6918d482013-03-07 19:09:11 +000086 }
87
88 // These callbacks update state tracking when GL objects are deleted. They are called from
89 // GrGLResource onRelease functions.
90 void notifyVertexArrayDelete(GrGLuint id) {
cdaltone2e71c22016-04-07 18:13:29 -070091 fHWVertexArrayState.notifyVertexArrayDelete(id);
bsalomon@google.com6918d482013-03-07 19:09:11 +000092 }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +000093
cdaltone2e71c22016-04-07 18:13:29 -070094 // Binds a buffer to the GL target corresponding to 'type', updates internal state tracking, and
95 // returns the GL target the buffer was bound to.
96 // When 'type' is kIndex_GrBufferType, this function will also implicitly bind the default VAO.
97 // If the caller wishes to bind an index buffer to a specific VAO, it can call glBind directly.
csmartdalton485a1202016-07-13 10:16:32 -070098 GrGLenum bindBuffer(GrBufferType type, const GrBuffer*);
joshualitt93316b92015-10-23 09:08:08 -070099
cdalton74b8d322016-04-11 14:47:28 -0700100 // Called by GrGLBuffer after its buffer object has been destroyed.
101 void notifyBufferReleased(const GrGLBuffer*);
102
Greg Daniel500d58b2017-08-24 15:59:33 -0400103 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700104 // Thus this is the implementation of the draw call for the corresponding passthrough function
Greg Daniel500d58b2017-08-24 15:59:33 -0400105 // on GrGLRTGpuCommandBuffer.
egdaniel9cb63402016-06-23 08:37:05 -0700106 void draw(const GrPipeline&,
107 const GrPrimitiveProcessor&,
Chris Dalton46983b72017-06-06 12:27:16 -0600108 const GrMesh[],
109 const GrPipeline::DynamicState[],
egdaniel9cb63402016-06-23 08:37:05 -0700110 int meshCount);
111
Chris Dalton114a3c02017-05-26 15:17:19 -0600112
113 // GrMesh::SendToGpuImpl methods. These issue the actual GL draw calls.
114 // Marked final as a hint to the compiler to not use virtual dispatch.
115 void sendMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType,
116 const GrBuffer* vertexBuffer, int vertexCount, int baseVertex) final;
117
118 void sendIndexedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType,
119 const GrBuffer* indexBuffer, int indexCount, int baseIndex,
120 uint16_t minIndexValue, uint16_t maxIndexValue,
121 const GrBuffer* vertexBuffer, int baseVertex) final;
122
Chris Dalton1d616352017-05-31 12:51:23 -0600123 void sendInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType,
124 const GrBuffer* vertexBuffer, int vertexCount, int baseVertex,
125 const GrBuffer* instanceBuffer, int instanceCount,
126 int baseInstance) final;
127
128 void sendIndexedInstancedMeshToGpu(const GrPrimitiveProcessor&, GrPrimitiveType,
129 const GrBuffer* indexBuffer, int indexCount, int baseIndex,
130 const GrBuffer* vertexBuffer, int baseVertex,
131 const GrBuffer* instanceBuffer, int instanceCount,
132 int baseInstance) final;
133
Greg Daniel500d58b2017-08-24 15:59:33 -0400134 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700135 // Thus this is the implementation of the clear call for the corresponding passthrough function
Greg Daniel500d58b2017-08-24 15:59:33 -0400136 // on GrGLGpuRTCommandBuffer.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400137 void clear(const GrFixedClip&, GrColor, GrRenderTarget*, GrSurfaceOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700138
Greg Daniel500d58b2017-08-24 15:59:33 -0400139 // The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
egdaniel9cb63402016-06-23 08:37:05 -0700140 // Thus this is the implementation of the clearStencil call for the corresponding passthrough
Greg Daniel500d58b2017-08-24 15:59:33 -0400141 // function on GrGLGpuRTCommandBuffer.
Robert Phillips19e51dc2017-08-09 09:30:51 -0400142 void clearStencilClip(const GrFixedClip&, bool insideStencilMask,
143 GrRenderTarget*, GrSurfaceOrigin);
egdaniel9cb63402016-06-23 08:37:05 -0700144
reedf9ad5582015-06-25 21:29:25 -0700145 const GrGLContext* glContextForTesting() const override {
146 return &this->glContext();
bsalomon993a4212015-05-29 11:37:25 -0700147 }
148
Robert Phillips95214472017-08-08 18:00:03 -0400149 void clearStencil(GrRenderTarget*, int clearValue) override;
egdanielec00d942015-09-14 12:56:10 -0700150
Greg Daniel500d58b2017-08-24 15:59:33 -0400151 GrGpuRTCommandBuffer* createCommandBuffer(
Robert Phillips95214472017-08-08 18:00:03 -0400152 GrRenderTarget*, GrSurfaceOrigin,
Greg Daniel500d58b2017-08-24 15:59:33 -0400153 const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
154 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
155
156 GrGpuTextureCommandBuffer* createCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
egdaniel066df7c2016-06-08 14:02:27 -0700157
egdanielec00d942015-09-14 12:56:10 -0700158 void invalidateBoundRenderTarget() {
Robert Phillips294870f2016-11-11 12:38:40 -0500159 fHWBoundRenderTargetUniqueID.makeInvalid();
egdanielec00d942015-09-14 12:56:10 -0700160 }
161
162 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
163 int width,
164 int height) override;
165
jvanverth88957922015-07-14 11:02:52 -0700166 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
egdaniel0a3a7f72016-06-24 09:22:31 -0700167 GrPixelConfig config,
168 bool isRenderTarget = false) override;
bsalomon67d76202015-11-11 12:40:42 -0800169 bool isTestingOnlyBackendTexture(GrBackendObject) const override;
bsalomone63ffef2016-02-05 07:17:34 -0800170 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override;
jvanverth672bb7f2015-07-13 07:19:57 -0700171
joshualitt8fd844f2015-12-02 13:36:47 -0800172 void resetShaderCacheForTesting() const override;
173
Greg Daniel6be35232017-03-01 17:01:09 -0500174 GrFence SK_WARN_UNUSED_RESULT insertFence() override;
175 bool waitFence(GrFence, uint64_t timeout) override;
jvanverth84741b32016-09-30 08:39:02 -0700176 void deleteFence(GrFence) const override;
177
Greg Daniela5cb7812017-06-16 09:45:32 -0400178 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override;
179 sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
180 GrWrapOwnership ownership) override;
Brian Osmandc87c952017-04-28 13:57:38 -0400181 void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override;
Greg Daniel6be35232017-03-01 17:01:09 -0500182 void waitSemaphore(sk_sp<GrSemaphore> semaphore) override;
183
Brian Osman13dddce2017-05-09 13:19:50 -0400184 sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
185
Greg Daniel6be35232017-03-01 17:01:09 -0500186 void deleteSync(GrGLsync) const;
187
Robert Phillips65a88fa2017-08-08 08:36:22 -0400188 void insertEventMarker(const char*);
189
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000190private:
bsalomon424cc262015-05-22 10:37:30 -0700191 GrGLGpu(GrGLContext* ctx, GrContext* context);
192
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000193 // GrGpu overrides
mtklein36352bf2015-03-25 18:17:31 -0700194 void onResetContext(uint32_t resetBits) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000195
bsalomoncb02b382015-08-12 11:14:50 -0700196 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
197
Robert Phillips67d52cf2017-06-05 13:38:13 -0400198 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
Robert Phillips590533f2017-07-11 14:22:35 -0400199 const GrMipLevel texels[],
200 int mipLevelCount) override;
cblume55f2d2d2016-02-26 13:20:48 -0800201
cdalton1bf3e712016-04-19 10:00:02 -0700202 GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
203 const void* data) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000204
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400205 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override;
Brian Salomond17f6582017-07-19 18:28:58 -0400206 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -0400207 int sampleCnt,
208 GrWrapOwnership) override;
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400209 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Greg Daniel7ef28f32017-04-20 16:41:55 +0000210 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Greg Daniel7ef28f32017-04-20 16:41:55 +0000211 int sampleCnt) override;
csmartdaltone0d36292016-07-29 08:14:20 -0700212
Robert Phillipse3302df2017-04-24 07:31:02 -0400213 std::unique_ptr<gr_instanced::OpAllocator> onCreateInstancedRenderingAllocator() override;
csmartdaltone0d36292016-07-29 08:14:20 -0700214 gr_instanced::InstancedRendering* onCreateInstancedRendering() override;
215
egdanielff1d5472015-09-10 08:37:20 -0700216 // Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a
bsalomon62a627b2015-12-17 09:50:47 -0800217 // compatible stencil format, or negative if there is no compatible stencil format.
egdanielff1d5472015-09-10 08:37:20 -0700218 int getCompatibleStencilIndex(GrPixelConfig config);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000219
bsalomon7e68ab72016-04-13 14:29:25 -0700220
erikchen9a1ed5d2016-02-10 16:32:34 -0800221 // Returns whether the texture is successfully created. On success, the
222 // result is stored in |info|.
cblume55f2d2d2016-02-26 13:20:48 -0800223 // The texture is populated with |texels|, if it exists.
erikchen9a1ed5d2016-02-10 16:32:34 -0800224 // The texture parameters are cached in |initialTexParams|.
225 bool createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info,
cblume55f2d2d2016-02-26 13:20:48 -0800226 bool renderTarget, GrGLTexture::TexParams* initialTexParams,
Greg Daniel834f1202017-10-09 15:06:20 -0400227 const GrMipLevel texels[], int mipLevelCount,
228 bool* wasFullMipMapDataProvided);
erikchen9a1ed5d2016-02-10 16:32:34 -0800229
Brian Salomon2bbdcc42017-09-07 12:36:34 -0400230 bool onIsACopyNeededForTextureParams(GrTextureProxy*, const GrSamplerState&,
Robert Phillips81444fb2017-03-21 09:14:35 -0400231 GrTextureProducer::CopyParams*,
232 SkScalar scaleAdjust[2]) const override;
bsalomone179a912016-01-20 06:18:10 -0800233
bsalomon1aa20292016-01-22 08:16:09 -0800234 // Checks whether glReadPixels can be called to get pixel values in readConfig from the
235 // render target.
236 bool readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConfig);
237
238 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
239 // render target that has renderTargetConfig. This may have to create a temporary
240 // render target and thus is less preferable than the variant that takes a render target.
241 bool readPixelsSupported(GrPixelConfig renderTargetConfig, GrPixelConfig readConfig);
242
243 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
244 // render target that has the same config as surfaceForConfig. Calls one of the the two
245 // variations above, depending on whether the surface is a render target or not.
246 bool readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig readConfig);
247
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400248 bool onReadPixels(GrSurface*, GrSurfaceOrigin,
bsalomond95263c2014-12-16 13:05:12 -0800249 int left, int top,
250 int width, int height,
251 GrPixelConfig,
252 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700253 size_t rowBytes) override;
bsalomond95263c2014-12-16 13:05:12 -0800254
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400255 bool onWritePixels(GrSurface*, GrSurfaceOrigin,
bsalomon6cb3cbe2015-07-30 07:34:27 -0700256 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800257 GrPixelConfig config,
Robert Phillips590533f2017-07-11 14:22:35 -0400258 const GrMipLevel texels[], int mipLevelCount) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000259
Jim Van Verth2e5eaf02017-06-21 15:55:46 -0400260 bool onTransferPixels(GrTexture*,
jvanverth17aa0472016-01-05 10:41:27 -0800261 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700262 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800263 size_t offset, size_t rowBytes) override;
264
Brian Osman9b560242017-09-05 15:34:52 -0400265 // Before calling any variation of TexImage, TexSubImage, etc..., call this to ensure that the
266 // PIXEL_UNPACK_BUFFER is unbound.
267 void unbindCpuToGpuXferBuffer();
268
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400269 void onResolveRenderTarget(GrRenderTarget* target, GrSurfaceOrigin) override;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000270
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400271 bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin,
272 GrSurface* src, GrSurfaceOrigin srcOrigin,
273 const SkIRect& srcRect, const SkIPoint& dstPoint) override;
joshualitt1cbdcde2015-08-21 11:53:29 -0700274
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400275 void onQueryMultisampleSpecs(GrRenderTarget*, GrSurfaceOrigin, const GrStencilSettings&,
csmartdaltonc25c5d72016-11-01 07:03:59 -0700276 int* effectiveSampleCnt, SamplePattern*) override;
cdalton28f45b92016-03-07 13:58:26 -0800277
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000278 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000279 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000280
cdalton74b8d322016-04-11 14:47:28 -0700281 void setTextureSwizzle(int unitIdx, GrGLenum target, const GrGLenum swizzle[]);
282
egdaniel8dd688b2015-01-22 10:16:09 -0800283 // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set.
bsalomon2eda5b32016-09-21 10:53:24 -0700284 // willDrawPoints must be true if point primitives will be rendered after setting the GL state.
285 bool flushGLState(const GrPipeline&, const GrPrimitiveProcessor&, bool willDrawPoints);
bsalomond95263c2014-12-16 13:05:12 -0800286
Chris Dalton114a3c02017-05-26 15:17:19 -0600287 // Sets up vertex/instance attribute pointers and strides.
joshualitt873ad0e2015-01-20 09:08:51 -0800288 void setupGeometry(const GrPrimitiveProcessor&,
Chris Daltonff926502017-05-03 14:36:54 -0400289 const GrBuffer* indexBuffer,
290 const GrBuffer* vertexBuffer,
Chris Dalton1d616352017-05-31 12:51:23 -0600291 int baseVertex,
292 const GrBuffer* instanceBuffer,
293 int baseInstance);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000294
bsalomon7f9b2e42016-01-12 13:29:26 -0800295 void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000296
Greg Daniel51316782017-08-02 15:10:09 +0000297 void onFinishFlush(bool insertedSemaphores) override;
298
bsalomon424cc262015-05-22 10:37:30 -0700299 bool hasExtension(const char* ext) const { return fGLContext->hasExtension(ext); }
bsalomon@google.com96399942012-02-13 14:39:16 +0000300
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400301 bool copySurfaceAsDraw(GrSurface* dst, GrSurfaceOrigin dstOrigin,
302 GrSurface* src, GrSurfaceOrigin srcOrigin,
303 const SkIRect& srcRect, const SkIPoint& dstPoint);
304 void copySurfaceAsCopyTexSubImage(GrSurface* dst, GrSurfaceOrigin dstOrigin,
305 GrSurface* src, GrSurfaceOrigin srcOrigin,
306 const SkIRect& srcRect, const SkIPoint& dstPoint);
307 bool copySurfaceAsBlitFramebuffer(GrSurface* dst, GrSurfaceOrigin dstOrigin,
308 GrSurface* src, GrSurfaceOrigin srcOrigin,
309 const SkIRect& srcRect, const SkIPoint& dstPoint);
310 bool generateMipmap(GrGLTexture* texture, GrSurfaceOrigin textureOrigin, bool gammaCorrect);
311 void clearStencilClipAsDraw(const GrFixedClip&, bool insideStencilMask,
312 GrRenderTarget*, GrSurfaceOrigin);
bsalomon6df86402015-06-01 10:41:49 -0700313
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000314 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
bsalomon@google.com080773c2011-03-15 19:09:25 +0000315
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000316 class ProgramCache : public ::SkNoncopyable {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000317 public:
bsalomon861e1032014-12-16 07:33:49 -0800318 ProgramCache(GrGLGpu* gpu);
jvanverth@google.com94878772013-03-12 16:00:54 +0000319 ~ProgramCache();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000320
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000321 void abandon();
bsalomon2eda5b32016-09-21 10:53:24 -0700322 GrGLProgram* refProgram(const GrGLGpu*, const GrPipeline&, const GrPrimitiveProcessor&,
323 bool hasPointSize);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000324
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000325 private:
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500326 // We may actually have kMaxEntries+1 shaders in the GL context because we create a new
327 // shader before evicting from the cache.
328 static const int kMaxEntries = 128;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000329
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000330 struct Entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000331
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000332 // binary search for entry matching desc. returns index into fEntries that matches desc or ~
333 // of the index of where it should be inserted.
joshualitt79f8fae2014-10-28 17:59:26 -0700334 int search(const GrProgramDesc& desc) const;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000335
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500336 struct DescHash {
337 uint32_t operator()(const GrProgramDesc& desc) const {
338 return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);
339 }
340 };
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000341
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500342 SkLRUCache<GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap;
343
bsalomon861e1032014-12-16 07:33:49 -0800344 GrGLGpu* fGpu;
jvanverth@google.com94878772013-03-12 16:00:54 +0000345#ifdef PROGRAM_CACHE_STATS
346 int fTotalRequests;
347 int fCacheMisses;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000348 int fHashMisses; // cache hit but hash table missed
jvanverth@google.com94878772013-03-12 16:00:54 +0000349#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000350 };
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000351
egdaniel080e6732014-12-22 07:35:52 -0800352 void flushColorWrite(bool writeColor);
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000353
bsalomon@google.coma3201942012-06-21 19:58:20 +0000354 // flushes the scissor. see the note on flushBoundTextureAndParams about
355 // flushing the scissor after that function is called.
bsalomon3e791242014-12-17 13:43:13 -0800356 void flushScissor(const GrScissorState&,
joshualitt77b13072014-10-27 14:51:01 -0700357 const GrGLIRect& rtViewport,
358 GrSurfaceOrigin rtOrigin);
359
360 // disables the scissor
361 void disableScissor();
bsalomon@google.coma3201942012-06-21 19:58:20 +0000362
Robert Phillipsb0e93a22017-08-29 08:26:54 -0400363 void flushWindowRectangles(const GrWindowRectsState&, const GrGLRenderTarget*, GrSurfaceOrigin);
csmartdalton28341fa2016-08-17 10:00:21 -0700364 void disableWindowRectangles();
365
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000366 // sets a texture unit to use for texture operations other than binding a texture to a program.
367 // ensures that such operations don't negatively interact with tracking bound textures.
368 void setScratchTextureUnit();
reed@google.comac10a2d2010-12-22 21:39:39 +0000369
bsalomon083617b2016-02-12 12:10:14 -0800370 // bounds is region that may be modified.
halcanary96fcdcc2015-08-27 07:41:13 -0700371 // nullptr means whole target. Can be an empty rect.
brianosman64d094d2016-03-25 06:01:59 -0700372 void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds, bool disableSRGB = false);
bsalomon083617b2016-02-12 12:10:14 -0800373
374 // Need not be called if flushRenderTarget is used.
375 void flushViewport(const GrGLIRect&);
bsalomonb0bd4f62014-09-03 07:19:50 -0700376
bsalomon3e791242014-12-17 13:43:13 -0800377 void flushStencil(const GrStencilSettings&);
csmartdaltonc7d85332016-10-26 10:13:46 -0700378 void disableStencil();
bsalomon083617b2016-02-12 12:10:14 -0800379
380 // rt is used only if useHWAA is true.
cdaltonaf8bc7d2016-02-05 09:35:20 -0800381 void flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabled);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000382
ethannicholas28ef4452016-03-25 09:26:03 -0700383 void flushMinSampleShading(float minSampleShading);
384
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 Salomond1eaf492017-05-18 10:02:08 -0400392 bool uploadTexData(GrPixelConfig texConfig, int texWidth, int texHeight,
393 GrSurfaceOrigin texOrigin, GrGLenum target, UploadType uploadType, int left,
394 int top, int width, int height, GrPixelConfig dataConfig,
Greg Daniel834f1202017-10-09 15:06:20 -0400395 const GrMipLevel texels[], int mipLevelCount,
396 bool* wasFullMipMapDataProvided = nullptr);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000397
kkinnunen2e6055b2016-04-22 01:48:29 -0700398 bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo,
399 GrGLRenderTarget::IDDesc*);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000400
egdanield803f272015-03-18 13:01:52 -0700401 enum TempFBOTarget {
402 kSrc_TempFBOTarget,
403 kDst_TempFBOTarget
404 };
egdaniel0f5f9672015-02-03 11:10:51 -0800405
Brian Salomond17b4a62017-05-23 16:53:47 -0400406 // Binds a surface as a FBO for copying, reading, or clearing. If the surface already owns an
407 // FBO ID then that ID is bound. If not the surface is temporarily bound to a FBO and that FBO
408 // is bound. This must be paired with a call to unbindSurfaceFBOForPixelOps().
Brian Salomon71d9d842016-11-03 13:42:00 -0400409 void bindSurfaceFBOForPixelOps(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport,
410 TempFBOTarget tempFBOTarget);
egdaniel0f5f9672015-02-03 11:10:51 -0800411
Brian Salomon71d9d842016-11-03 13:42:00 -0400412 // Must be called if bindSurfaceFBOForPixelOps was used to bind a surface for copying.
413 void unbindTextureFBOForPixelOps(GrGLenum fboTarget, GrSurface* surface);
robertphillips754f4e92014-09-18 13:52:08 -0700414
Brian Osman71a18892017-08-10 10:23:25 -0400415 void onDumpJSON(SkJSONWriter*) const override;
416
Hal Canary144caf52016-11-07 17:57:18 -0500417 sk_sp<GrGLContext> fGLContext;
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000418
Brian Salomonbf7b6202016-11-11 16:08:03 -0500419 bool createCopyProgram(GrTexture* srcTexture);
brianosman33f6b3f2016-06-02 05:49:21 -0700420 bool createMipmapProgram(int progIdx);
Mike Klein31550db2017-06-06 23:29:53 +0000421 bool createStencilClipClearProgram();
ethannicholas22793252016-01-30 09:59:10 -0800422
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000423 // GL program-related state
424 ProgramCache* fProgramCache;
bsalomon@google.com49209392012-06-05 15:13:46 +0000425
426 ///////////////////////////////////////////////////////////////////////////
427 ///@name Caching of GL State
428 ///@{
429 int fHWActiveTextureUnitIdx;
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000430 GrGLuint fHWProgramID;
bsalomon@google.com91207482013-02-12 21:45:24 +0000431
bsalomon@google.com49209392012-06-05 15:13:46 +0000432 enum TriState {
433 kNo_TriState,
434 kYes_TriState,
435 kUnknown_TriState
436 };
437
egdanield803f272015-03-18 13:01:52 -0700438 GrGLuint fTempSrcFBOID;
439 GrGLuint fTempDstFBOID;
440
441 GrGLuint fStencilClearFBOID;
bsalomondd3143b2015-02-23 09:27:45 -0800442
bsalomon@google.coma3201942012-06-21 19:58:20 +0000443 // last scissor / viewport scissor state seen by the GL.
444 struct {
445 TriState fEnabled;
446 GrGLIRect fRect;
447 void invalidate() {
448 fEnabled = kUnknown_TriState;
449 fRect.invalidate();
450 }
451 } fHWScissorSettings;
452
csmartdalton28341fa2016-08-17 10:00:21 -0700453 class {
454 public:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700455 bool valid() const { return kInvalidSurfaceOrigin != fRTOrigin; }
456 void invalidate() { fRTOrigin = kInvalidSurfaceOrigin; }
457 bool knownDisabled() const { return this->valid() && !fWindowState.enabled(); }
mtklein8b4a2022016-09-26 08:44:47 -0700458 void setDisabled() {
Robert Phillipsfb4a20c2017-08-29 14:46:43 -0400459 fRTOrigin = kTopLeft_GrSurfaceOrigin;
mtklein8b4a2022016-09-26 08:44:47 -0700460 fWindowState.setDisabled();
461 }
csmartdalton28341fa2016-08-17 10:00:21 -0700462
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700463 void set(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
464 const GrWindowRectsState& windowState) {
465 fRTOrigin = rtOrigin;
466 fViewport = viewport;
467 fWindowState = windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700468 }
csmartdalton28341fa2016-08-17 10:00:21 -0700469
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700470 bool knownEqualTo(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
471 const GrWindowRectsState& windowState) const {
csmartdalton28341fa2016-08-17 10:00:21 -0700472 if (!this->valid()) {
473 return false;
474 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700475 if (fWindowState.numWindows() && (fRTOrigin != rtOrigin || fViewport != viewport)) {
csmartdalton28341fa2016-08-17 10:00:21 -0700476 return false;
477 }
Brian Salomon9a767722017-03-13 17:57:28 -0400478 return fWindowState == windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700479 }
480
481 private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700482 enum { kInvalidSurfaceOrigin = -1 };
csmartdalton28341fa2016-08-17 10:00:21 -0700483
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700484 int fRTOrigin;
csmartdalton28341fa2016-08-17 10:00:21 -0700485 GrGLIRect fViewport;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700486 GrWindowRectsState fWindowState;
487 } fHWWindowRectsState;
csmartdalton28341fa2016-08-17 10:00:21 -0700488
bsalomon424cc262015-05-22 10:37:30 -0700489 GrGLIRect fHWViewport;
bsalomon@google.coma3201942012-06-21 19:58:20 +0000490
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000491 /**
cdaltone2e71c22016-04-07 18:13:29 -0700492 * Tracks vertex attrib array state.
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000493 */
cdaltone2e71c22016-04-07 18:13:29 -0700494 class HWVertexArrayState {
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000495 public:
cdaltone2e71c22016-04-07 18:13:29 -0700496 HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); }
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000497
cdaltone2e71c22016-04-07 18:13:29 -0700498 ~HWVertexArrayState() { delete fCoreProfileVertexArray; }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000499
bsalomon@google.com6918d482013-03-07 19:09:11 +0000500 void invalidate() {
501 fBoundVertexArrayIDIsValid = false;
bsalomon@google.com6918d482013-03-07 19:09:11 +0000502 fDefaultVertexArrayAttribState.invalidate();
cdaltone2e71c22016-04-07 18:13:29 -0700503 if (fCoreProfileVertexArray) {
504 fCoreProfileVertexArray->invalidateCachedState();
commit-bot@chromium.orgce6da4d2013-09-09 14:55:37 +0000505 }
bsalomon@google.com6918d482013-03-07 19:09:11 +0000506 }
507
508 void notifyVertexArrayDelete(GrGLuint id) {
509 if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) {
510 // Does implicit bind to 0
511 fBoundVertexArrayID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000512 }
513 }
514
bsalomon861e1032014-12-16 07:33:49 -0800515 void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000516 if (!gpu->glCaps().vertexArrayObjectSupport()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000517 SkASSERT(0 == arrayID);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000518 return;
519 }
520 if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) {
521 GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID));
522 fBoundVertexArrayIDIsValid = true;
523 fBoundVertexArrayID = arrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000524 }
525 }
526
bsalomon@google.com6918d482013-03-07 19:09:11 +0000527 /**
cdaltone2e71c22016-04-07 18:13:29 -0700528 * Binds the vertex array that should be used for internal draws, and returns its attrib
529 * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which
530 * case we use a dummy array instead.
531 *
532 * If an index buffer is privided, it will be bound to the vertex array. Otherwise the
533 * index buffer binding will be left unchanged.
534 *
535 * The returned GrGLAttribArrayState should be used to set vertex attribute arrays.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000536 */
csmartdalton485a1202016-07-13 10:16:32 -0700537 GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrBuffer* ibuff = nullptr);
bsalomon6df86402015-06-01 10:41:49 -0700538
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000539 private:
Robert Phillips294870f2016-11-11 12:38:40 -0500540 GrGLuint fBoundVertexArrayID;
541 bool fBoundVertexArrayIDIsValid;
mtklein044d3c12016-04-06 18:24:34 -0700542
bsalomon@google.com6918d482013-03-07 19:09:11 +0000543 // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
jvanverth39edf762014-12-22 11:44:19 -0800544 // is bound. However, this class is internal to GrGLGpu and this object never leaks out of
545 // GrGLGpu.
Robert Phillips294870f2016-11-11 12:38:40 -0500546 GrGLAttribArrayState fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000547
cdaltone2e71c22016-04-07 18:13:29 -0700548 // This is used when we're using a core profile.
Robert Phillips294870f2016-11-11 12:38:40 -0500549 GrGLVertexArray* fCoreProfileVertexArray;
550 } fHWVertexArrayState;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000551
cdaltone2e71c22016-04-07 18:13:29 -0700552 struct {
Robert Phillips294870f2016-11-11 12:38:40 -0500553 GrGLenum fGLTarget;
554 GrGpuResource::UniqueID fBoundBufferUniqueID;
555 bool fBufferZeroKnownBound;
cdaltone2e71c22016-04-07 18:13:29 -0700556
557 void invalidate() {
Robert Phillips294870f2016-11-11 12:38:40 -0500558 fBoundBufferUniqueID.makeInvalid();
cdaltone2e71c22016-04-07 18:13:29 -0700559 fBufferZeroKnownBound = false;
560 }
Robert Phillips294870f2016-11-11 12:38:40 -0500561 } fHWBufferState[kGrBufferTypeCount];
cdaltonc1613102016-03-16 07:48:20 -0700562
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000563 struct {
cdalton8917d622015-05-06 13:40:21 -0700564 GrBlendEquation fEquation;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000565 GrBlendCoeff fSrcCoeff;
566 GrBlendCoeff fDstCoeff;
567 GrColor fConstColor;
568 bool fConstColorValid;
569 TriState fEnabled;
570
571 void invalidate() {
bsalomonf7cc8772015-05-11 11:21:14 -0700572 fEquation = static_cast<GrBlendEquation>(-1);
573 fSrcCoeff = static_cast<GrBlendCoeff>(-1);
574 fDstCoeff = static_cast<GrBlendCoeff>(-1);
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000575 fConstColorValid = false;
576 fEnabled = kUnknown_TriState;
577 }
Robert Phillips294870f2016-11-11 12:38:40 -0500578 } fHWBlendState;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000579
bsalomon54c6fe82015-12-16 11:51:22 -0800580 TriState fMSAAEnabled;
581
Robert Phillips294870f2016-11-11 12:38:40 -0500582 GrStencilSettings fHWStencilSettings;
583 TriState fHWStencilTestEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800584
585
Robert Phillips294870f2016-11-11 12:38:40 -0500586 TriState fHWWriteToColor;
587 GrGpuResource::UniqueID fHWBoundRenderTargetUniqueID;
588 TriState fHWSRGBFramebuffer;
589 SkTArray<GrGpuResource::UniqueID, true> fHWBoundTextureUniqueIDs;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800590
Brian Salomonf9f45122016-11-29 11:59:17 -0500591 struct Image {
592 GrGpuResource::UniqueID fTextureUniqueID;
593 GrIOType fIOType;
594 };
595 SkTArray<Image, true> fHWBoundImageStorages;
596
cdalton74b8d322016-04-11 14:47:28 -0700597 struct BufferTexture {
598 BufferTexture() : fTextureID(0), fKnownBound(false),
599 fAttachedBufferUniqueID(SK_InvalidUniqueID),
600 fSwizzle(GrSwizzle::RGBA()) {}
601
Robert Phillips294870f2016-11-11 12:38:40 -0500602 GrGLuint fTextureID;
603 bool fKnownBound;
604 GrPixelConfig fTexelConfig;
605 GrGpuResource::UniqueID fAttachedBufferUniqueID;
606 GrSwizzle fSwizzle;
cdalton74b8d322016-04-11 14:47:28 -0700607 };
608
Robert Phillips294870f2016-11-11 12:38:40 -0500609 SkTArray<BufferTexture, true> fHWBufferTextures;
610 int fHWMaxUsedBufferTextureUnit;
cdalton74b8d322016-04-11 14:47:28 -0700611
cdaltonaf8bc7d2016-02-05 09:35:20 -0800612 // EXT_raster_multisample.
Robert Phillips294870f2016-11-11 12:38:40 -0500613 TriState fHWRasterMultisampleEnabled;
614 int fHWNumRasterSamples;
bsalomon54c6fe82015-12-16 11:51:22 -0800615 ///@}
616
Brian Salomonbf7b6202016-11-11 16:08:03 -0500617 /** IDs for copy surface program. (4 sampler types) */
bsalomon6df86402015-06-01 10:41:49 -0700618 struct {
619 GrGLuint fProgram;
620 GrGLint fTextureUniform;
621 GrGLint fTexCoordXformUniform;
622 GrGLint fPosXformUniform;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500623 } fCopyPrograms[4];
Robert Phillips294870f2016-11-11 12:38:40 -0500624 sk_sp<GrGLBuffer> fCopyProgramArrayBuffer;
bsalomon7ea33f52015-11-22 14:51:00 -0800625
brianosman33f6b3f2016-06-02 05:49:21 -0700626 /** IDs for texture mipmap program. (4 filter configurations) */
627 struct {
628 GrGLuint fProgram;
629 GrGLint fTextureUniform;
630 GrGLint fTexCoordXformUniform;
Robert Phillips294870f2016-11-11 12:38:40 -0500631 } fMipmapPrograms[4];
632 sk_sp<GrGLBuffer> fMipmapProgramArrayBuffer;
brianosman33f6b3f2016-06-02 05:49:21 -0700633
Mike Klein31550db2017-06-06 23:29:53 +0000634 GrGLuint fStencilClipClearProgram;
635 sk_sp<GrGLBuffer> fStencilClipClearArrayBuffer;
bsalomon6dea83f2015-12-03 12:58:06 -0800636
Robert Phillips646e4292017-06-13 12:44:56 -0400637 static int TextureToCopyProgramIdx(GrTexture* texture);
bsalomon6df86402015-06-01 10:41:49 -0700638
brianosman33f6b3f2016-06-02 05:49:21 -0700639 static int TextureSizeToMipmapProgramIdx(int width, int height) {
640 const bool wide = (width > 1) && SkToBool(width & 0x1);
641 const bool tall = (height > 1) && SkToBool(height & 0x1);
642 return (wide ? 0x2 : 0x0) | (tall ? 0x1 : 0x0);
643 }
644
Robert Phillips294870f2016-11-11 12:38:40 -0500645 float fHWMinSampleShading;
Brian Salomonaf971de2017-06-08 16:11:33 -0400646 GrPrimitiveType fLastPrimitiveType;
ethannicholas28ef4452016-03-25 09:26:03 -0700647
reed@google.comac10a2d2010-12-22 21:39:39 +0000648 typedef GrGpu INHERITED;
kkinnunenccdaa042014-08-20 01:36:23 -0700649 friend class GrGLPathRendering; // For accessing setTextureUnit.
csmartdaltona7f29642016-07-07 08:49:11 -0700650 friend class gr_instanced::GLInstancedRendering; // For accessing flushGLState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000651};
652
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000653#endif