blob: fdc2ebbfa9a79e4e5aec402073f7ebe7f8491558 [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"
Brian Salomonbf7b6202016-11-11 16:08:03 -050020#include "GrTexturePriv.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;
egdaniel0e1853c2016-03-17 11:35:45 -070029class GrNonInstancedMesh;
bsalomon7f9b2e42016-01-12 13:29:26 -080030class GrSwizzle;
egdaniel8dd688b2015-01-22 10:16:09 -080031
csmartdaltona7f29642016-07-07 08:49:11 -070032namespace gr_instanced { class GLInstancedRendering; }
33
djsollenefe46d22016-04-29 06:41:35 -070034#ifdef SK_DEBUG
jvanverth@google.com94878772013-03-12 16:00:54 +000035#define PROGRAM_CACHE_STATS
36#endif
37
cdaltone2e71c22016-04-07 18:13:29 -070038class GrGLGpu final : public GrGpu {
reed@google.comac10a2d2010-12-22 21:39:39 +000039public:
bsalomon682c2692015-05-22 14:01:46 -070040 static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
41 GrContext* context);
mtklein36352bf2015-03-25 18:17:31 -070042 ~GrGLGpu() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000043
bsalomon6e2aad42016-04-01 11:54:31 -070044 void disconnect(DisconnectType) override;
bsalomonc8dc1f72014-08-21 13:02:13 -070045
bsalomon424cc262015-05-22 10:37:30 -070046 const GrGLContext& glContext() const { return *fGLContext; }
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000047
bsalomon424cc262015-05-22 10:37:30 -070048 const GrGLInterface* glInterface() const { return fGLContext->interface(); }
49 const GrGLContextInfo& ctxInfo() const { return *fGLContext; }
50 GrGLStandard glStandard() const { return fGLContext->standard(); }
51 GrGLVersion glVersion() const { return fGLContext->version(); }
52 GrGLSLGeneration glslGeneration() const { return fGLContext->glslGeneration(); }
53 const GrGLCaps& glCaps() const { return *fGLContext->caps(); }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000054
kkinnunenccdaa042014-08-20 01:36:23 -070055 GrGLPathRendering* glPathRendering() {
jvanverthe9c0fc62015-04-29 11:18:05 -070056 SkASSERT(glCaps().shaderCaps()->pathRenderingSupport());
kkinnunenccdaa042014-08-20 01:36:23 -070057 return static_cast<GrGLPathRendering*>(pathRendering());
cdaltonc7103a12014-08-11 14:05:05 -070058 }
59
kkinnunencfe62e32015-07-01 02:58:50 -070060 // Used by GrGLProgram to configure OpenGL state.
Brian Salomon514baff2016-11-17 15:17:07 -050061 void bindTexture(int unitIdx, const GrSamplerParams& params, bool allowSRGBInputs,
brianosmana6359362016-03-21 06:55:37 -070062 GrGLTexture* texture);
kkinnunenccdaa042014-08-20 01:36:23 -070063
csmartdalton1897cfd2016-06-03 08:50:54 -070064 void bindTexelBuffer(int unitIdx, GrPixelConfig, GrGLBuffer*);
cdalton74b8d322016-04-11 14:47:28 -070065
Brian Salomonf9f45122016-11-29 11:59:17 -050066 void bindImageStorage(int unitIdx, GrIOType, GrGLTexture *);
67
Brian Salomon514baff2016-11-17 15:17:07 -050068 void generateMipmaps(const GrSamplerParams& params, bool allowSRGBInputs, GrGLTexture* texture);
brianosman33f6b3f2016-06-02 05:49:21 -070069
bsalomonf0674512015-07-28 13:26:15 -070070 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
71 GrPixelConfig readConfig, DrawPreference*,
72 ReadPixelTempDrawInfo*) override;
bsalomon39826022015-07-23 08:07:21 -070073
bsalomonf0674512015-07-28 13:26:15 -070074 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
cblumeed828002016-02-16 13:00:01 -080075 GrPixelConfig srcConfig, DrawPreference*,
bsalomonf0674512015-07-28 13:26:15 -070076 WritePixelTempDrawInfo*) override;
bsalomon@google.com75f9f252012-01-31 13:35:56 +000077
egdaniel4bcd62e2016-08-31 07:37:31 -070078 bool initDescForDstCopy(const GrRenderTarget* src, GrSurfaceDesc* desc) const override;
bsalomon@google.comeb851172013-04-15 13:51:00 +000079
bsalomon@google.com6918d482013-03-07 19:09:11 +000080 // 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 +000081 // bindings. Making the equivalent glBind calls directly will confuse the state tracking.
bsalomon@google.com6918d482013-03-07 19:09:11 +000082 void bindVertexArray(GrGLuint id) {
cdaltone2e71c22016-04-07 18:13:29 -070083 fHWVertexArrayState.setVertexArrayID(this, id);
bsalomon@google.com6918d482013-03-07 19:09:11 +000084 }
85
86 // These callbacks update state tracking when GL objects are deleted. They are called from
87 // GrGLResource onRelease functions.
88 void notifyVertexArrayDelete(GrGLuint id) {
cdaltone2e71c22016-04-07 18:13:29 -070089 fHWVertexArrayState.notifyVertexArrayDelete(id);
bsalomon@google.com6918d482013-03-07 19:09:11 +000090 }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +000091
cdaltone2e71c22016-04-07 18:13:29 -070092 // Binds a buffer to the GL target corresponding to 'type', updates internal state tracking, and
93 // returns the GL target the buffer was bound to.
94 // When 'type' is kIndex_GrBufferType, this function will also implicitly bind the default VAO.
95 // If the caller wishes to bind an index buffer to a specific VAO, it can call glBind directly.
csmartdalton485a1202016-07-13 10:16:32 -070096 GrGLenum bindBuffer(GrBufferType type, const GrBuffer*);
joshualitt93316b92015-10-23 09:08:08 -070097
cdalton74b8d322016-04-11 14:47:28 -070098 // Called by GrGLBuffer after its buffer object has been destroyed.
99 void notifyBufferReleased(const GrGLBuffer*);
100
egdaniel9cb63402016-06-23 08:37:05 -0700101 // The GrGLGpuCommandBuffer does not buffer up draws before submitting them to the gpu.
102 // Thus this is the implementation of the draw call for the corresponding passthrough function
103 // on GrGLGpuCommandBuffer.
104 void draw(const GrPipeline&,
105 const GrPrimitiveProcessor&,
106 const GrMesh*,
107 int meshCount);
108
109 // The GrGLGpuCommandBuffer does not buffer up draws before submitting them to the gpu.
110 // Thus this is the implementation of the clear call for the corresponding passthrough function
111 // on GrGLGpuCommandBuffer.
csmartdalton29df7602016-08-31 11:55:52 -0700112 void clear(const GrFixedClip&, GrColor, GrRenderTarget*);
egdaniel9cb63402016-06-23 08:37:05 -0700113
114 // The GrGLGpuCommandBuffer does not buffer up draws before submitting them to the gpu.
115 // Thus this is the implementation of the clearStencil call for the corresponding passthrough
116 // function on GrGLGpuCommandBuffer.
csmartdalton29df7602016-08-31 11:55:52 -0700117 void clearStencilClip(const GrFixedClip&, bool insideStencilMask, GrRenderTarget*);
egdaniel9cb63402016-06-23 08:37:05 -0700118
reedf9ad5582015-06-25 21:29:25 -0700119 const GrGLContext* glContextForTesting() const override {
120 return &this->glContext();
bsalomon993a4212015-05-29 11:37:25 -0700121 }
122
egdanielec00d942015-09-14 12:56:10 -0700123 void clearStencil(GrRenderTarget*) override;
124
egdaniel9cb63402016-06-23 08:37:05 -0700125 GrGpuCommandBuffer* createCommandBuffer(
egdaniel9cb63402016-06-23 08:37:05 -0700126 const GrGpuCommandBuffer::LoadAndStoreInfo& colorInfo,
127 const GrGpuCommandBuffer::LoadAndStoreInfo& stencilInfo) override;
egdaniel066df7c2016-06-08 14:02:27 -0700128
egdanielec00d942015-09-14 12:56:10 -0700129 void invalidateBoundRenderTarget() {
Robert Phillips294870f2016-11-11 12:38:40 -0500130 fHWBoundRenderTargetUniqueID.makeInvalid();
egdanielec00d942015-09-14 12:56:10 -0700131 }
132
133 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
134 int width,
135 int height) override;
136
jvanverth88957922015-07-14 11:02:52 -0700137 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
egdaniel0a3a7f72016-06-24 09:22:31 -0700138 GrPixelConfig config,
139 bool isRenderTarget = false) override;
bsalomon67d76202015-11-11 12:40:42 -0800140 bool isTestingOnlyBackendTexture(GrBackendObject) const override;
bsalomone63ffef2016-02-05 07:17:34 -0800141 void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override;
jvanverth672bb7f2015-07-13 07:19:57 -0700142
joshualitt8fd844f2015-12-02 13:36:47 -0800143 void resetShaderCacheForTesting() const override;
144
bsalomon6dea83f2015-12-03 12:58:06 -0800145 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override;
146
Robert Phillipsf2361d22016-10-25 14:20:06 -0400147 void finishOpList() override;
ethannicholas22793252016-01-30 09:59:10 -0800148
jvanverth84741b32016-09-30 08:39:02 -0700149 GrFence SK_WARN_UNUSED_RESULT insertFence() const override;
150 bool waitFence(GrFence, uint64_t timeout) const override;
151 void deleteFence(GrFence) const override;
152
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000153private:
bsalomon424cc262015-05-22 10:37:30 -0700154 GrGLGpu(GrGLContext* ctx, GrContext* context);
155
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000156 // GrGpu overrides
mtklein36352bf2015-03-25 18:17:31 -0700157 void onResetContext(uint32_t resetBits) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000158
bsalomoncb02b382015-08-12 11:14:50 -0700159 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override;
160
kkinnunen2e6055b2016-04-22 01:48:29 -0700161 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800162 const SkTArray<GrMipLevel>& texels) override;
egdanielb0e1be22015-04-22 13:27:39 -0700163 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc,
kkinnunen2e6055b2016-04-22 01:48:29 -0700164 SkBudgeted budgeted,
cblume55f2d2d2016-02-26 13:20:48 -0800165 const SkTArray<GrMipLevel>& texels) override;
166
cdalton1bf3e712016-04-19 10:00:02 -0700167 GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
168 const void* data) override;
bungeman6bd52842016-10-27 09:30:08 -0700169 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
170 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
171 GrWrapOwnership) override;
172 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override;
csmartdaltone0d36292016-07-29 08:14:20 -0700173
174 gr_instanced::InstancedRendering* onCreateInstancedRendering() override;
175
egdanielff1d5472015-09-10 08:37:20 -0700176 // Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a
bsalomon62a627b2015-12-17 09:50:47 -0800177 // compatible stencil format, or negative if there is no compatible stencil format.
egdanielff1d5472015-09-10 08:37:20 -0700178 int getCompatibleStencilIndex(GrPixelConfig config);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000179
bsalomon7e68ab72016-04-13 14:29:25 -0700180
erikchen9a1ed5d2016-02-10 16:32:34 -0800181 // Returns whether the texture is successfully created. On success, the
182 // result is stored in |info|.
cblume55f2d2d2016-02-26 13:20:48 -0800183 // The texture is populated with |texels|, if it exists.
erikchen9a1ed5d2016-02-10 16:32:34 -0800184 // The texture parameters are cached in |initialTexParams|.
185 bool createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info,
cblume55f2d2d2016-02-26 13:20:48 -0800186 bool renderTarget, GrGLTexture::TexParams* initialTexParams,
187 const SkTArray<GrMipLevel>& texels);
erikchen9a1ed5d2016-02-10 16:32:34 -0800188
Brian Salomon514baff2016-11-17 15:17:07 -0500189 bool onMakeCopyForTextureParams(GrTexture*, const GrSamplerParams&,
Robert Phillips67c18d62017-01-20 12:44:06 -0500190 GrTextureProducer::CopyParams*,
191 SkScalar scaleAdjust[2]) const override;
bsalomone179a912016-01-20 06:18:10 -0800192
bsalomon1aa20292016-01-22 08:16:09 -0800193 // Checks whether glReadPixels can be called to get pixel values in readConfig from the
194 // render target.
195 bool readPixelsSupported(GrRenderTarget* target, GrPixelConfig readConfig);
196
197 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
198 // render target that has renderTargetConfig. This may have to create a temporary
199 // render target and thus is less preferable than the variant that takes a render target.
200 bool readPixelsSupported(GrPixelConfig renderTargetConfig, GrPixelConfig readConfig);
201
202 // Checks whether glReadPixels can be called to get pixel values in readConfig from a
203 // render target that has the same config as surfaceForConfig. Calls one of the the two
204 // variations above, depending on whether the surface is a render target or not.
205 bool readPixelsSupported(GrSurface* surfaceForConfig, GrPixelConfig readConfig);
206
bsalomon6cb3cbe2015-07-30 07:34:27 -0700207 bool onReadPixels(GrSurface*,
bsalomond95263c2014-12-16 13:05:12 -0800208 int left, int top,
209 int width, int height,
210 GrPixelConfig,
211 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700212 size_t rowBytes) override;
bsalomond95263c2014-12-16 13:05:12 -0800213
bsalomon6cb3cbe2015-07-30 07:34:27 -0700214 bool onWritePixels(GrSurface*,
215 int left, int top, int width, int height,
cblume55f2d2d2016-02-26 13:20:48 -0800216 GrPixelConfig config,
217 const SkTArray<GrMipLevel>& texels) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000218
jvanverthc3d706f2016-04-20 10:33:27 -0700219 bool onTransferPixels(GrSurface*,
jvanverth17aa0472016-01-05 10:41:27 -0800220 int left, int top, int width, int height,
cdalton397536c2016-03-25 12:15:03 -0700221 GrPixelConfig config, GrBuffer* transferBuffer,
jvanverth17aa0472016-01-05 10:41:27 -0800222 size_t offset, size_t rowBytes) override;
223
mtklein36352bf2015-03-25 18:17:31 -0700224 void onResolveRenderTarget(GrRenderTarget* target) override;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000225
joshualitt1cbdcde2015-08-21 11:53:29 -0700226 bool onCopySurface(GrSurface* dst,
227 GrSurface* src,
228 const SkIRect& srcRect,
229 const SkIPoint& dstPoint) override;
230
csmartdaltonc25c5d72016-11-01 07:03:59 -0700231 void onQueryMultisampleSpecs(GrRenderTarget*, const GrStencilSettings&,
232 int* effectiveSampleCnt, SamplePattern*) override;
cdalton28f45b92016-03-07 13:58:26 -0800233
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000234 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000235 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000236
cdalton74b8d322016-04-11 14:47:28 -0700237 void setTextureSwizzle(int unitIdx, GrGLenum target, const GrGLenum swizzle[]);
238
egdaniel8dd688b2015-01-22 10:16:09 -0800239 // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set.
bsalomon2eda5b32016-09-21 10:53:24 -0700240 // willDrawPoints must be true if point primitives will be rendered after setting the GL state.
241 bool flushGLState(const GrPipeline&, const GrPrimitiveProcessor&, bool willDrawPoints);
bsalomond95263c2014-12-16 13:05:12 -0800242
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000243 // Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset
bsalomoncb8979d2015-05-05 09:51:38 -0700244 // an into the index buffer. It does not account for vertices.startIndex() but rather the start
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000245 // index is relative to the returned offset.
joshualitt873ad0e2015-01-20 09:08:51 -0800246 void setupGeometry(const GrPrimitiveProcessor&,
egdaniel0e1853c2016-03-17 11:35:45 -0700247 const GrNonInstancedMesh& mesh,
joshualittd53a8272014-11-10 16:03:14 -0800248 size_t* indexOffsetInBytes);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000249
bsalomon7f9b2e42016-01-12 13:29:26 -0800250 void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000251
bsalomon424cc262015-05-22 10:37:30 -0700252 bool hasExtension(const char* ext) const { return fGLContext->hasExtension(ext); }
bsalomon@google.com96399942012-02-13 14:39:16 +0000253
cdaltone2e71c22016-04-07 18:13:29 -0700254 bool copySurfaceAsDraw(GrSurface* dst,
bsalomon6df86402015-06-01 10:41:49 -0700255 GrSurface* src,
256 const SkIRect& srcRect,
257 const SkIPoint& dstPoint);
258 void copySurfaceAsCopyTexSubImage(GrSurface* dst,
259 GrSurface* src,
260 const SkIRect& srcRect,
261 const SkIPoint& dstPoint);
262 bool copySurfaceAsBlitFramebuffer(GrSurface* dst,
263 GrSurface* src,
264 const SkIRect& srcRect,
265 const SkIPoint& dstPoint);
brianosman33f6b3f2016-06-02 05:49:21 -0700266 bool generateMipmap(GrGLTexture* texture, bool gammaCorrect);
bsalomon6df86402015-06-01 10:41:49 -0700267
cdaltone2e71c22016-04-07 18:13:29 -0700268 void stampPLSSetupRect(const SkRect& bounds);
ethannicholas22793252016-01-30 09:59:10 -0800269
egdaniel0e1853c2016-03-17 11:35:45 -0700270 void setupPixelLocalStorage(const GrPipeline&, const GrPrimitiveProcessor&);
ethannicholas22793252016-01-30 09:59:10 -0800271
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000272 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
bsalomon@google.com080773c2011-03-15 19:09:25 +0000273
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000274 class ProgramCache : public ::SkNoncopyable {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000275 public:
bsalomon861e1032014-12-16 07:33:49 -0800276 ProgramCache(GrGLGpu* gpu);
jvanverth@google.com94878772013-03-12 16:00:54 +0000277 ~ProgramCache();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000278
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000279 void abandon();
bsalomon2eda5b32016-09-21 10:53:24 -0700280 GrGLProgram* refProgram(const GrGLGpu*, const GrPipeline&, const GrPrimitiveProcessor&,
281 bool hasPointSize);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000282
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000283 private:
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500284 // We may actually have kMaxEntries+1 shaders in the GL context because we create a new
285 // shader before evicting from the cache.
286 static const int kMaxEntries = 128;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000287
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000288 struct Entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000289
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000290 // binary search for entry matching desc. returns index into fEntries that matches desc or ~
291 // of the index of where it should be inserted.
joshualitt79f8fae2014-10-28 17:59:26 -0700292 int search(const GrProgramDesc& desc) const;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000293
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500294 struct DescHash {
295 uint32_t operator()(const GrProgramDesc& desc) const {
296 return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0);
297 }
298 };
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000299
Ethan Nicholas1b9924f2016-12-15 15:28:42 -0500300 SkLRUCache<GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap;
301
bsalomon861e1032014-12-16 07:33:49 -0800302 GrGLGpu* fGpu;
jvanverth@google.com94878772013-03-12 16:00:54 +0000303#ifdef PROGRAM_CACHE_STATS
304 int fTotalRequests;
305 int fCacheMisses;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000306 int fHashMisses; // cache hit but hash table missed
jvanverth@google.com94878772013-03-12 16:00:54 +0000307#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000308 };
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000309
egdaniel080e6732014-12-22 07:35:52 -0800310 void flushColorWrite(bool writeColor);
robertphillips5fa7f302016-07-21 09:21:04 -0700311 void flushDrawFace(GrDrawFace face);
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000312
bsalomon@google.coma3201942012-06-21 19:58:20 +0000313 // flushes the scissor. see the note on flushBoundTextureAndParams about
314 // flushing the scissor after that function is called.
bsalomon3e791242014-12-17 13:43:13 -0800315 void flushScissor(const GrScissorState&,
joshualitt77b13072014-10-27 14:51:01 -0700316 const GrGLIRect& rtViewport,
317 GrSurfaceOrigin rtOrigin);
318
319 // disables the scissor
320 void disableScissor();
bsalomon@google.coma3201942012-06-21 19:58:20 +0000321
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700322 void flushWindowRectangles(const GrWindowRectsState&, const GrGLRenderTarget*);
csmartdalton28341fa2016-08-17 10:00:21 -0700323 void disableWindowRectangles();
324
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000325 void initFSAASupport();
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000326
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000327 // determines valid stencil formats
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000328 void initStencilFormats();
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000329
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000330 // sets a texture unit to use for texture operations other than binding a texture to a program.
331 // ensures that such operations don't negatively interact with tracking bound textures.
332 void setScratchTextureUnit();
reed@google.comac10a2d2010-12-22 21:39:39 +0000333
bsalomon083617b2016-02-12 12:10:14 -0800334 // bounds is region that may be modified.
halcanary96fcdcc2015-08-27 07:41:13 -0700335 // nullptr means whole target. Can be an empty rect.
brianosman64d094d2016-03-25 06:01:59 -0700336 void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds, bool disableSRGB = false);
bsalomon083617b2016-02-12 12:10:14 -0800337
338 // Need not be called if flushRenderTarget is used.
339 void flushViewport(const GrGLIRect&);
bsalomonb0bd4f62014-09-03 07:19:50 -0700340
bsalomon3e791242014-12-17 13:43:13 -0800341 void flushStencil(const GrStencilSettings&);
csmartdaltonc7d85332016-10-26 10:13:46 -0700342 void disableStencil();
bsalomon083617b2016-02-12 12:10:14 -0800343
344 // rt is used only if useHWAA is true.
cdaltonaf8bc7d2016-02-05 09:35:20 -0800345 void flushHWAAState(GrRenderTarget* rt, bool useHWAA, bool stencilEnabled);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000346
ethannicholas28ef4452016-03-25 09:26:03 -0700347 void flushMinSampleShading(float minSampleShading);
348
brianosman33f6b3f2016-06-02 05:49:21 -0700349 void flushFramebufferSRGB(bool enable);
350
bsalomon@google.com6f379512011-11-16 20:36:03 +0000351 // helper for onCreateTexture and writeTexturePixels
jvanverth17aa0472016-01-05 10:41:27 -0800352 enum UploadType {
353 kNewTexture_UploadType, // we are creating a new texture
354 kWrite_UploadType, // we are using TexSubImage2D to copy data to an existing texture
355 kTransfer_UploadType, // we are using a transfer buffer to copy data
356 };
bsalomonb15b4c12014-10-29 12:41:57 -0700357 bool uploadTexData(const GrSurfaceDesc& desc,
jcgregorioe7d7f902016-02-04 19:51:25 -0800358 GrGLenum target,
jvanverth17aa0472016-01-05 10:41:27 -0800359 UploadType uploadType,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000360 int left, int top, int width, int height,
361 GrPixelConfig dataConfig,
cblume55f2d2d2016-02-26 13:20:48 -0800362 const SkTArray<GrMipLevel>& texels);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000363
krajcevski145d48c2014-06-11 16:07:50 -0700364 // helper for onCreateCompressedTexture. If width and height are
365 // set to -1, then this function will use desc.fWidth and desc.fHeight
366 // for the size of the data. The isNewTexture flag should be set to true
367 // whenever a new texture needs to be created. Otherwise, we assume that
368 // the texture is already in GPU memory and that it's going to be updated
369 // with new data.
bsalomonb15b4c12014-10-29 12:41:57 -0700370 bool uploadCompressedTexData(const GrSurfaceDesc& desc,
bsalomon10528f12015-10-14 12:54:52 -0700371 GrGLenum target,
cblume55f2d2d2016-02-26 13:20:48 -0800372 const SkTArray<GrMipLevel>& texels,
jvanverth17aa0472016-01-05 10:41:27 -0800373 UploadType uploadType = kNewTexture_UploadType,
krajcevski145d48c2014-06-11 16:07:50 -0700374 int left = 0, int top = 0,
375 int width = -1, int height = -1);
krajcevski9c0e6292014-06-02 07:38:14 -0700376
kkinnunen2e6055b2016-04-22 01:48:29 -0700377 bool createRenderTargetObjects(const GrSurfaceDesc&, const GrGLTextureInfo& texInfo,
378 GrGLRenderTarget::IDDesc*);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000379
egdanield803f272015-03-18 13:01:52 -0700380 enum TempFBOTarget {
381 kSrc_TempFBOTarget,
382 kDst_TempFBOTarget
383 };
egdaniel0f5f9672015-02-03 11:10:51 -0800384
Brian Salomon71d9d842016-11-03 13:42:00 -0400385 // Binds a surface as a FBO for copying or reading. If the surface already owns an FBO ID then
bsalomon10528f12015-10-14 12:54:52 -0700386 // that ID is bound. If not the surface is temporarily bound to a FBO and that FBO is bound.
Brian Salomon71d9d842016-11-03 13:42:00 -0400387 // This must be paired with a call to unbindSurfaceFBOForPixelOps().
388 void bindSurfaceFBOForPixelOps(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport,
389 TempFBOTarget tempFBOTarget);
egdaniel0f5f9672015-02-03 11:10:51 -0800390
Brian Salomon71d9d842016-11-03 13:42:00 -0400391 // Must be called if bindSurfaceFBOForPixelOps was used to bind a surface for copying.
392 void unbindTextureFBOForPixelOps(GrGLenum fboTarget, GrSurface* surface);
robertphillips754f4e92014-09-18 13:52:08 -0700393
Hal Canary144caf52016-11-07 17:57:18 -0500394 sk_sp<GrGLContext> fGLContext;
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000395
Brian Salomonbf7b6202016-11-11 16:08:03 -0500396 bool createCopyProgram(GrTexture* srcTexture);
brianosman33f6b3f2016-06-02 05:49:21 -0700397 bool createMipmapProgram(int progIdx);
cdaltone2e71c22016-04-07 18:13:29 -0700398 bool createWireRectProgram();
399 bool createPLSSetupProgram();
ethannicholas22793252016-01-30 09:59:10 -0800400
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000401 // GL program-related state
402 ProgramCache* fProgramCache;
bsalomon@google.com49209392012-06-05 15:13:46 +0000403
404 ///////////////////////////////////////////////////////////////////////////
405 ///@name Caching of GL State
406 ///@{
407 int fHWActiveTextureUnitIdx;
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000408 GrGLuint fHWProgramID;
bsalomon@google.com91207482013-02-12 21:45:24 +0000409
bsalomon@google.com49209392012-06-05 15:13:46 +0000410 enum TriState {
411 kNo_TriState,
412 kYes_TriState,
413 kUnknown_TriState
414 };
415
egdanield803f272015-03-18 13:01:52 -0700416 GrGLuint fTempSrcFBOID;
417 GrGLuint fTempDstFBOID;
418
419 GrGLuint fStencilClearFBOID;
bsalomondd3143b2015-02-23 09:27:45 -0800420
bsalomon@google.coma3201942012-06-21 19:58:20 +0000421 // last scissor / viewport scissor state seen by the GL.
422 struct {
423 TriState fEnabled;
424 GrGLIRect fRect;
425 void invalidate() {
426 fEnabled = kUnknown_TriState;
427 fRect.invalidate();
428 }
429 } fHWScissorSettings;
430
csmartdalton28341fa2016-08-17 10:00:21 -0700431 class {
432 public:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700433 bool valid() const { return kInvalidSurfaceOrigin != fRTOrigin; }
434 void invalidate() { fRTOrigin = kInvalidSurfaceOrigin; }
435 bool knownDisabled() const { return this->valid() && !fWindowState.enabled(); }
mtklein8b4a2022016-09-26 08:44:47 -0700436 void setDisabled() {
437 fRTOrigin = kDefault_GrSurfaceOrigin;
438 fWindowState.setDisabled();
439 }
csmartdalton28341fa2016-08-17 10:00:21 -0700440
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700441 void set(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
442 const GrWindowRectsState& windowState) {
443 fRTOrigin = rtOrigin;
444 fViewport = viewport;
445 fWindowState = windowState;
csmartdalton28341fa2016-08-17 10:00:21 -0700446 }
csmartdalton28341fa2016-08-17 10:00:21 -0700447
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700448 bool knownEqualTo(GrSurfaceOrigin rtOrigin, const GrGLIRect& viewport,
449 const GrWindowRectsState& windowState) const {
csmartdalton28341fa2016-08-17 10:00:21 -0700450 if (!this->valid()) {
451 return false;
452 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700453 if (fWindowState.numWindows() && (fRTOrigin != rtOrigin || fViewport != viewport)) {
csmartdalton28341fa2016-08-17 10:00:21 -0700454 return false;
455 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700456 return fWindowState.cheapEqualTo(windowState);
csmartdalton28341fa2016-08-17 10:00:21 -0700457 }
458
459 private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700460 enum { kInvalidSurfaceOrigin = -1 };
csmartdalton28341fa2016-08-17 10:00:21 -0700461
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700462 int fRTOrigin;
csmartdalton28341fa2016-08-17 10:00:21 -0700463 GrGLIRect fViewport;
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700464 GrWindowRectsState fWindowState;
465 } fHWWindowRectsState;
csmartdalton28341fa2016-08-17 10:00:21 -0700466
bsalomon424cc262015-05-22 10:37:30 -0700467 GrGLIRect fHWViewport;
bsalomon@google.coma3201942012-06-21 19:58:20 +0000468
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000469 /**
cdaltone2e71c22016-04-07 18:13:29 -0700470 * Tracks vertex attrib array state.
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000471 */
cdaltone2e71c22016-04-07 18:13:29 -0700472 class HWVertexArrayState {
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000473 public:
cdaltone2e71c22016-04-07 18:13:29 -0700474 HWVertexArrayState() : fCoreProfileVertexArray(nullptr) { this->invalidate(); }
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000475
cdaltone2e71c22016-04-07 18:13:29 -0700476 ~HWVertexArrayState() { delete fCoreProfileVertexArray; }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000477
bsalomon@google.com6918d482013-03-07 19:09:11 +0000478 void invalidate() {
479 fBoundVertexArrayIDIsValid = false;
bsalomon@google.com6918d482013-03-07 19:09:11 +0000480 fDefaultVertexArrayAttribState.invalidate();
cdaltone2e71c22016-04-07 18:13:29 -0700481 if (fCoreProfileVertexArray) {
482 fCoreProfileVertexArray->invalidateCachedState();
commit-bot@chromium.orgce6da4d2013-09-09 14:55:37 +0000483 }
bsalomon@google.com6918d482013-03-07 19:09:11 +0000484 }
485
486 void notifyVertexArrayDelete(GrGLuint id) {
487 if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) {
488 // Does implicit bind to 0
489 fBoundVertexArrayID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000490 }
491 }
492
bsalomon861e1032014-12-16 07:33:49 -0800493 void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000494 if (!gpu->glCaps().vertexArrayObjectSupport()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000495 SkASSERT(0 == arrayID);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000496 return;
497 }
498 if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) {
499 GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID));
500 fBoundVertexArrayIDIsValid = true;
501 fBoundVertexArrayID = arrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000502 }
503 }
504
bsalomon@google.com6918d482013-03-07 19:09:11 +0000505 /**
cdaltone2e71c22016-04-07 18:13:29 -0700506 * Binds the vertex array that should be used for internal draws, and returns its attrib
507 * state. This binds the default VAO (ID=zero) unless we are on a core profile, in which
508 * case we use a dummy array instead.
509 *
510 * If an index buffer is privided, it will be bound to the vertex array. Otherwise the
511 * index buffer binding will be left unchanged.
512 *
513 * The returned GrGLAttribArrayState should be used to set vertex attribute arrays.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000514 */
csmartdalton485a1202016-07-13 10:16:32 -0700515 GrGLAttribArrayState* bindInternalVertexArray(GrGLGpu*, const GrBuffer* ibuff = nullptr);
bsalomon6df86402015-06-01 10:41:49 -0700516
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000517 private:
Robert Phillips294870f2016-11-11 12:38:40 -0500518 GrGLuint fBoundVertexArrayID;
519 bool fBoundVertexArrayIDIsValid;
mtklein044d3c12016-04-06 18:24:34 -0700520
bsalomon@google.com6918d482013-03-07 19:09:11 +0000521 // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
jvanverth39edf762014-12-22 11:44:19 -0800522 // is bound. However, this class is internal to GrGLGpu and this object never leaks out of
523 // GrGLGpu.
Robert Phillips294870f2016-11-11 12:38:40 -0500524 GrGLAttribArrayState fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000525
cdaltone2e71c22016-04-07 18:13:29 -0700526 // This is used when we're using a core profile.
Robert Phillips294870f2016-11-11 12:38:40 -0500527 GrGLVertexArray* fCoreProfileVertexArray;
528 } fHWVertexArrayState;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000529
cdaltone2e71c22016-04-07 18:13:29 -0700530 struct {
Robert Phillips294870f2016-11-11 12:38:40 -0500531 GrGLenum fGLTarget;
532 GrGpuResource::UniqueID fBoundBufferUniqueID;
533 bool fBufferZeroKnownBound;
cdaltone2e71c22016-04-07 18:13:29 -0700534
535 void invalidate() {
Robert Phillips294870f2016-11-11 12:38:40 -0500536 fBoundBufferUniqueID.makeInvalid();
cdaltone2e71c22016-04-07 18:13:29 -0700537 fBufferZeroKnownBound = false;
538 }
Robert Phillips294870f2016-11-11 12:38:40 -0500539 } fHWBufferState[kGrBufferTypeCount];
cdaltonc1613102016-03-16 07:48:20 -0700540
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000541 struct {
cdalton8917d622015-05-06 13:40:21 -0700542 GrBlendEquation fEquation;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000543 GrBlendCoeff fSrcCoeff;
544 GrBlendCoeff fDstCoeff;
545 GrColor fConstColor;
546 bool fConstColorValid;
547 TriState fEnabled;
548
549 void invalidate() {
bsalomonf7cc8772015-05-11 11:21:14 -0700550 fEquation = static_cast<GrBlendEquation>(-1);
551 fSrcCoeff = static_cast<GrBlendCoeff>(-1);
552 fDstCoeff = static_cast<GrBlendCoeff>(-1);
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000553 fConstColorValid = false;
554 fEnabled = kUnknown_TriState;
555 }
Robert Phillips294870f2016-11-11 12:38:40 -0500556 } fHWBlendState;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000557
bsalomon54c6fe82015-12-16 11:51:22 -0800558 TriState fMSAAEnabled;
559
Robert Phillips294870f2016-11-11 12:38:40 -0500560 GrStencilSettings fHWStencilSettings;
561 TriState fHWStencilTestEnabled;
bsalomon54c6fe82015-12-16 11:51:22 -0800562
563
Robert Phillips294870f2016-11-11 12:38:40 -0500564 GrDrawFace fHWDrawFace;
565 TriState fHWWriteToColor;
566 GrGpuResource::UniqueID fHWBoundRenderTargetUniqueID;
567 TriState fHWSRGBFramebuffer;
568 SkTArray<GrGpuResource::UniqueID, true> fHWBoundTextureUniqueIDs;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800569
Brian Salomonf9f45122016-11-29 11:59:17 -0500570 struct Image {
571 GrGpuResource::UniqueID fTextureUniqueID;
572 GrIOType fIOType;
573 };
574 SkTArray<Image, true> fHWBoundImageStorages;
575
cdalton74b8d322016-04-11 14:47:28 -0700576 struct BufferTexture {
577 BufferTexture() : fTextureID(0), fKnownBound(false),
578 fAttachedBufferUniqueID(SK_InvalidUniqueID),
579 fSwizzle(GrSwizzle::RGBA()) {}
580
Robert Phillips294870f2016-11-11 12:38:40 -0500581 GrGLuint fTextureID;
582 bool fKnownBound;
583 GrPixelConfig fTexelConfig;
584 GrGpuResource::UniqueID fAttachedBufferUniqueID;
585 GrSwizzle fSwizzle;
cdalton74b8d322016-04-11 14:47:28 -0700586 };
587
Robert Phillips294870f2016-11-11 12:38:40 -0500588 SkTArray<BufferTexture, true> fHWBufferTextures;
589 int fHWMaxUsedBufferTextureUnit;
cdalton74b8d322016-04-11 14:47:28 -0700590
cdaltonaf8bc7d2016-02-05 09:35:20 -0800591 // EXT_raster_multisample.
Robert Phillips294870f2016-11-11 12:38:40 -0500592 TriState fHWRasterMultisampleEnabled;
593 int fHWNumRasterSamples;
bsalomon54c6fe82015-12-16 11:51:22 -0800594 ///@}
595
Brian Salomonbf7b6202016-11-11 16:08:03 -0500596 /** IDs for copy surface program. (4 sampler types) */
bsalomon6df86402015-06-01 10:41:49 -0700597 struct {
598 GrGLuint fProgram;
599 GrGLint fTextureUniform;
600 GrGLint fTexCoordXformUniform;
601 GrGLint fPosXformUniform;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500602 } fCopyPrograms[4];
Robert Phillips294870f2016-11-11 12:38:40 -0500603 sk_sp<GrGLBuffer> fCopyProgramArrayBuffer;
bsalomon7ea33f52015-11-22 14:51:00 -0800604
brianosman33f6b3f2016-06-02 05:49:21 -0700605 /** IDs for texture mipmap program. (4 filter configurations) */
606 struct {
607 GrGLuint fProgram;
608 GrGLint fTextureUniform;
609 GrGLint fTexCoordXformUniform;
Robert Phillips294870f2016-11-11 12:38:40 -0500610 } fMipmapPrograms[4];
611 sk_sp<GrGLBuffer> fMipmapProgramArrayBuffer;
brianosman33f6b3f2016-06-02 05:49:21 -0700612
bsalomon6dea83f2015-12-03 12:58:06 -0800613 struct {
Robert Phillips294870f2016-11-11 12:38:40 -0500614 GrGLuint fProgram;
615 GrGLint fColorUniform;
616 GrGLint fRectUniform;
617 } fWireRectProgram;
618 sk_sp<GrGLBuffer> fWireRectArrayBuffer;
bsalomon6dea83f2015-12-03 12:58:06 -0800619
Brian Salomonbf7b6202016-11-11 16:08:03 -0500620 static int TextureToCopyProgramIdx(GrTexture* texture) {
621 switch (texture->texturePriv().samplerType()) {
622 case kTexture2DSampler_GrSLType:
bsalomone5286e02016-01-14 09:24:09 -0800623 return 0;
Brian Salomona8f00022016-11-16 12:55:57 -0500624 case kITexture2DSampler_GrSLType:
bsalomone5286e02016-01-14 09:24:09 -0800625 return 1;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500626 case kTexture2DRectSampler_GrSLType:
bsalomone5286e02016-01-14 09:24:09 -0800627 return 2;
Brian Salomonbf7b6202016-11-11 16:08:03 -0500628 case kTextureExternalSampler_GrSLType:
629 return 3;
bsalomone5286e02016-01-14 09:24:09 -0800630 default:
Brian Salomonbf7b6202016-11-11 16:08:03 -0500631 SkFAIL("Unexpected samper type");
bsalomone5286e02016-01-14 09:24:09 -0800632 return 0;
bsalomon7ea33f52015-11-22 14:51:00 -0800633 }
634 }
bsalomon6df86402015-06-01 10:41:49 -0700635
brianosman33f6b3f2016-06-02 05:49:21 -0700636 static int TextureSizeToMipmapProgramIdx(int width, int height) {
637 const bool wide = (width > 1) && SkToBool(width & 0x1);
638 const bool tall = (height > 1) && SkToBool(height & 0x1);
639 return (wide ? 0x2 : 0x0) | (tall ? 0x1 : 0x0);
640 }
641
ethannicholas22793252016-01-30 09:59:10 -0800642 struct {
Robert Phillips294870f2016-11-11 12:38:40 -0500643 GrGLuint fProgram;
644 GrGLint fPosXformUniform;
645 sk_sp<GrGLBuffer> fArrayBuffer;
646 } fPLSSetupProgram;
ethannicholas22793252016-01-30 09:59:10 -0800647
Robert Phillips294870f2016-11-11 12:38:40 -0500648 bool fHWPLSEnabled;
649 bool fPLSHasBeenUsed;
ethannicholas22793252016-01-30 09:59:10 -0800650
Robert Phillips294870f2016-11-11 12:38:40 -0500651 float fHWMinSampleShading;
ethannicholas28ef4452016-03-25 09:26:03 -0700652
reed@google.comac10a2d2010-12-22 21:39:39 +0000653 typedef GrGpu INHERITED;
kkinnunenccdaa042014-08-20 01:36:23 -0700654 friend class GrGLPathRendering; // For accessing setTextureUnit.
csmartdaltona7f29642016-07-07 08:49:11 -0700655 friend class gr_instanced::GLInstancedRendering; // For accessing flushGLState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000656};
657
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000658#endif