blob: 29d63fbd4feae7536cc6af633f2ce9bb0e658a9a [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"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000013#include "GrGLIndexBuffer.h"
kkinnunenccdaa042014-08-20 01:36:23 -070014#include "GrGLPathRendering.h"
bsalomon@google.com5739d2c2012-05-31 15:07:19 +000015#include "GrGLProgram.h"
bsalomon37dd3312014-11-03 08:47:23 -080016#include "GrGLRenderTarget.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070017#include "GrGLStencilAttachment.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000018#include "GrGLTexture.h"
bsalomon@google.com6918d482013-03-07 19:09:11 +000019#include "GrGLVertexArray.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000020#include "GrGLVertexBuffer.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000021#include "GrGpu.h"
egdaniel8dd688b2015-01-22 10:16:09 -080022#include "GrPipelineBuilder.h"
egdaniel080e6732014-12-22 07:35:52 -080023#include "GrXferProcessor.h"
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +000024#include "SkTypes.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000025
egdaniel8dd688b2015-01-22 10:16:09 -080026class GrPipeline;
27
commit-bot@chromium.org174db772013-03-21 12:46:01 +000028#ifdef SK_DEVELOPER
jvanverth@google.com94878772013-03-12 16:00:54 +000029#define PROGRAM_CACHE_STATS
30#endif
31
bsalomon861e1032014-12-16 07:33:49 -080032class GrGLGpu : public GrGpu {
reed@google.comac10a2d2010-12-22 21:39:39 +000033public:
bsalomon861e1032014-12-16 07:33:49 -080034 GrGLGpu(const GrGLContext& ctx, GrContext* context);
mtklein36352bf2015-03-25 18:17:31 -070035 ~GrGLGpu() override;
reed@google.comac10a2d2010-12-22 21:39:39 +000036
mtklein36352bf2015-03-25 18:17:31 -070037 void contextAbandoned() override;
bsalomonc8dc1f72014-08-21 13:02:13 -070038
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000039 const GrGLContext& glContext() const { return fGLContext; }
40
robertphillips@google.com6177e692013-02-28 20:16:25 +000041 const GrGLInterface* glInterface() const { return fGLContext.interface(); }
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000042 const GrGLContextInfo& ctxInfo() const { return fGLContext; }
43 GrGLStandard glStandard() const { return fGLContext.standard(); }
44 GrGLVersion glVersion() const { return fGLContext.version(); }
45 GrGLSLGeneration glslGeneration() const { return fGLContext.glslGeneration(); }
46 const GrGLCaps& glCaps() const { return *fGLContext.caps(); }
bsalomon@google.com0b77d682011-08-19 13:28:54 +000047
kkinnunenccdaa042014-08-20 01:36:23 -070048 GrGLPathRendering* glPathRendering() {
cdaltonc7103a12014-08-11 14:05:05 -070049 SkASSERT(glCaps().pathRenderingSupport());
kkinnunenccdaa042014-08-20 01:36:23 -070050 return static_cast<GrGLPathRendering*>(pathRendering());
cdaltonc7103a12014-08-11 14:05:05 -070051 }
52
mtklein36352bf2015-03-25 18:17:31 -070053 void discard(GrRenderTarget*) override;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000054
commit-bot@chromium.org0a6fe712014-04-23 19:26:26 +000055 // Used by GrGLProgram and GrGLPathTexGenProgramEffects to configure OpenGL
56 // state.
bsalomon@google.com34cccde2013-01-04 18:34:30 +000057 void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture);
kkinnunenccdaa042014-08-20 01:36:23 -070058
bsalomon@google.com56d11e02011-11-30 19:59:08 +000059 // GrGpu overrides
bsalomond95263c2014-12-16 13:05:12 -080060 GrPixelConfig preferredReadPixelsConfig(GrPixelConfig readConfig,
mtklein36352bf2015-03-25 18:17:31 -070061 GrPixelConfig surfaceConfig) const override;
bsalomond95263c2014-12-16 13:05:12 -080062 GrPixelConfig preferredWritePixelsConfig(GrPixelConfig writeConfig,
mtklein36352bf2015-03-25 18:17:31 -070063 GrPixelConfig surfaceConfig) const override;
64 bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const override;
bsalomond95263c2014-12-16 13:05:12 -080065 bool readPixelsWillPayForYFlip(GrRenderTarget* renderTarget,
66 int left, int top,
67 int width, int height,
68 GrPixelConfig config,
mtklein36352bf2015-03-25 18:17:31 -070069 size_t rowBytes) const override;
70 bool fullReadPixelsIsFasterThanPartial() const override;
bsalomon@google.com75f9f252012-01-31 13:35:56 +000071
mtklein36352bf2015-03-25 18:17:31 -070072 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) override;
bsalomon@google.comeb851172013-04-15 13:51:00 +000073
bsalomon@google.com6918d482013-03-07 19:09:11 +000074 // 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 +000075 // bindings. Making the equivalent glBind calls directly will confuse the state tracking.
bsalomon@google.com6918d482013-03-07 19:09:11 +000076 void bindVertexArray(GrGLuint id) {
77 fHWGeometryState.setVertexArrayID(this, id);
78 }
79 void bindIndexBufferAndDefaultVertexArray(GrGLuint id) {
80 fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, id);
81 }
82 void bindVertexBuffer(GrGLuint id) {
83 fHWGeometryState.setVertexBufferID(this, id);
84 }
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) {
89 fHWGeometryState.notifyVertexArrayDelete(id);
90 }
91 void notifyVertexBufferDelete(GrGLuint id) {
92 fHWGeometryState.notifyVertexBufferDelete(id);
93 }
94 void notifyIndexBufferDelete(GrGLuint id) {
95 fHWGeometryState.notifyIndexBufferDelete(id);
96 }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +000097
bsalomonf90a02b2014-11-26 12:28:00 -080098 bool copySurface(GrSurface* dst,
99 GrSurface* src,
100 const SkIRect& srcRect,
mtklein36352bf2015-03-25 18:17:31 -0700101 const SkIPoint& dstPoint) override;
joshualitta7024152014-11-03 14:16:35 -0800102
bsalomonf90a02b2014-11-26 12:28:00 -0800103 bool canCopySurface(const GrSurface* dst,
104 const GrSurface* src,
105 const SkIRect& srcRect,
mtklein36352bf2015-03-25 18:17:31 -0700106 const SkIPoint& dstPoint) override;
joshualitta7024152014-11-03 14:16:35 -0800107
joshualitt873ad0e2015-01-20 09:08:51 -0800108 void buildProgramDesc(GrProgramDesc*,
109 const GrPrimitiveProcessor&,
egdaniel8dd688b2015-01-22 10:16:09 -0800110 const GrPipeline&,
mtklein36352bf2015-03-25 18:17:31 -0700111 const GrBatchTracker&) const override;
joshualitt79f8fae2014-10-28 17:59:26 -0700112
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000113private:
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000114 // GrGpu overrides
mtklein36352bf2015-03-25 18:17:31 -0700115 void onResetContext(uint32_t resetBits) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000116
bsalomon5236cf42015-01-14 10:42:08 -0800117 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
mtklein36352bf2015-03-25 18:17:31 -0700118 size_t rowBytes) override;
bsalomon5236cf42015-01-14 10:42:08 -0800119 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, bool budgeted,
mtklein36352bf2015-03-25 18:17:31 -0700120 const void* srcData) override;
121 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override;
122 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override;
123 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) override;
124 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override;
egdaniel8dc7c3a2015-04-16 11:22:42 -0700125 bool createStencilAttachmentForRenderTarget(GrRenderTarget* rt, int width, int height) override;
126 bool attachStencilAttachmentToRenderTarget(GrStencilAttachment* sb,
127 GrRenderTarget* rt) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000128
bsalomond95263c2014-12-16 13:05:12 -0800129 void onClear(GrRenderTarget*, const SkIRect* rect, GrColor color,
mtklein36352bf2015-03-25 18:17:31 -0700130 bool canIgnoreRect) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000131
mtklein36352bf2015-03-25 18:17:31 -0700132 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override;
joshualitt6db519c2014-10-29 08:48:18 -0700133
bsalomond95263c2014-12-16 13:05:12 -0800134 bool onReadPixels(GrRenderTarget* target,
135 int left, int top,
136 int width, int height,
137 GrPixelConfig,
138 void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700139 size_t rowBytes) override;
bsalomond95263c2014-12-16 13:05:12 -0800140
141 bool onWriteTexturePixels(GrTexture* texture,
142 int left, int top, int width, int height,
143 GrPixelConfig config, const void* buffer,
mtklein36352bf2015-03-25 18:17:31 -0700144 size_t rowBytes) override;
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000145
mtklein36352bf2015-03-25 18:17:31 -0700146 void onResolveRenderTarget(GrRenderTarget* target) override;
bsalomon@google.com6f379512011-11-16 20:36:03 +0000147
mtklein36352bf2015-03-25 18:17:31 -0700148 void onDraw(const DrawArgs&, const GrDrawTarget::DrawInfo&) override;
149 void onStencilPath(const GrPath*, const StencilPathState&) override;
150 void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&) override;
joshualitt873ad0e2015-01-20 09:08:51 -0800151 void onDrawPaths(const DrawArgs&,
bsalomond95263c2014-12-16 13:05:12 -0800152 const GrPathRange*,
153 const void* indices,
154 GrDrawTarget::PathIndexType,
155 const float transformValues[],
156 GrDrawTarget::PathTransformType,
157 int count,
mtklein36352bf2015-03-25 18:17:31 -0700158 const GrStencilSettings&) override;
bsalomon@google.com75f9f252012-01-31 13:35:56 +0000159
mtklein36352bf2015-03-25 18:17:31 -0700160 void clearStencil(GrRenderTarget*) override;
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000161
robertphillips754f4e92014-09-18 13:52:08 -0700162 // GrDrawTarget overrides
mtklein36352bf2015-03-25 18:17:31 -0700163 void didAddGpuTraceMarker() override;
164 void didRemoveGpuTraceMarker() override;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000165
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000166 // binds texture unit in GL
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000167 void setTextureUnit(int unitIdx);
reed@google.comac10a2d2010-12-22 21:39:39 +0000168
egdaniel8dd688b2015-01-22 10:16:09 -0800169 // Flushes state from GrPipeline to GL. Returns false if the state couldn't be set.
cdaltond0a840d2015-03-16 17:19:58 -0700170 bool flushGLState(const DrawArgs&);
bsalomond95263c2014-12-16 13:05:12 -0800171
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000172 // Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset
173 // an into the index buffer. It does not account for drawInfo.startIndex() but rather the start
174 // index is relative to the returned offset.
joshualitt873ad0e2015-01-20 09:08:51 -0800175 void setupGeometry(const GrPrimitiveProcessor&,
joshualittd53a8272014-11-10 16:03:14 -0800176 const GrDrawTarget::DrawInfo& info,
177 size_t* indexOffsetInBytes);
bsalomon@google.com7acdb8e2011-02-11 14:07:02 +0000178
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000179 // Subclasses should call this to flush the blend state.
egdaniel080e6732014-12-22 07:35:52 -0800180 void flushBlend(const GrXferProcessor::BlendInfo& blendInfo);
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000181
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000182 bool hasExtension(const char* ext) const { return fGLContext.hasExtension(ext); }
bsalomon@google.com96399942012-02-13 14:39:16 +0000183
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000184 static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
bsalomon@google.com080773c2011-03-15 19:09:25 +0000185
commit-bot@chromium.orga0b40282013-09-18 13:00:55 +0000186 class ProgramCache : public ::SkNoncopyable {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000187 public:
bsalomon861e1032014-12-16 07:33:49 -0800188 ProgramCache(GrGLGpu* gpu);
jvanverth@google.com94878772013-03-12 16:00:54 +0000189 ~ProgramCache();
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000190
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000191 void abandon();
joshualitt873ad0e2015-01-20 09:08:51 -0800192 GrGLProgram* getProgram(const DrawArgs&);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000193
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000194 private:
195 enum {
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000196 // We may actually have kMaxEntries+1 shaders in the GL context because we create a new
197 // shader before evicting from the cache.
commit-bot@chromium.orgb5564222014-03-28 15:52:18 +0000198 kMaxEntries = 128,
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000199 kHashBits = 6,
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000200 };
201
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000202 struct Entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000203
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000204 struct ProgDescLess;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000205
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000206 // binary search for entry matching desc. returns index into fEntries that matches desc or ~
207 // of the index of where it should be inserted.
joshualitt79f8fae2014-10-28 17:59:26 -0700208 int search(const GrProgramDesc& desc) const;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000209
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000210 // sorted array of all the entries
211 Entry* fEntries[kMaxEntries];
212 // hash table based on lowest kHashBits bits of the program key. Used to avoid binary
213 // searching fEntries.
214 Entry* fHashTable[1 << kHashBits];
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000215
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000216 int fCount;
217 unsigned int fCurrLRUStamp;
bsalomon861e1032014-12-16 07:33:49 -0800218 GrGLGpu* fGpu;
jvanverth@google.com94878772013-03-12 16:00:54 +0000219#ifdef PROGRAM_CACHE_STATS
220 int fTotalRequests;
221 int fCacheMisses;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000222 int fHashMisses; // cache hit but hash table missed
jvanverth@google.com94878772013-03-12 16:00:54 +0000223#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000224 };
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000225
bsalomon3e791242014-12-17 13:43:13 -0800226 void flushDither(bool dither);
egdaniel080e6732014-12-22 07:35:52 -0800227 void flushColorWrite(bool writeColor);
egdaniel8dd688b2015-01-22 10:16:09 -0800228 void flushDrawFace(GrPipelineBuilder::DrawFace face);
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000229
bsalomon@google.coma3201942012-06-21 19:58:20 +0000230 // flushes the scissor. see the note on flushBoundTextureAndParams about
231 // flushing the scissor after that function is called.
bsalomon3e791242014-12-17 13:43:13 -0800232 void flushScissor(const GrScissorState&,
joshualitt77b13072014-10-27 14:51:01 -0700233 const GrGLIRect& rtViewport,
234 GrSurfaceOrigin rtOrigin);
235
236 // disables the scissor
237 void disableScissor();
bsalomon@google.coma3201942012-06-21 19:58:20 +0000238
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000239 void initFSAASupport();
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000240
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000241 // determines valid stencil formats
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000242 void initStencilFormats();
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000243
commit-bot@chromium.orga15f7e52013-06-05 23:29:25 +0000244 // sets a texture unit to use for texture operations other than binding a texture to a program.
245 // ensures that such operations don't negatively interact with tracking bound textures.
246 void setScratchTextureUnit();
reed@google.comac10a2d2010-12-22 21:39:39 +0000247
egdanield803f272015-03-18 13:01:52 -0700248 // bounds is region that may be modified and therefore has to be resolved.
249 // NULL means whole target. Can be an empty rect.
250 void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds);
bsalomonb0bd4f62014-09-03 07:19:50 -0700251
bsalomon3e791242014-12-17 13:43:13 -0800252 void flushStencil(const GrStencilSettings&);
cdaltond0a840d2015-03-16 17:19:58 -0700253 void flushHWAAState(GrRenderTarget* rt, bool useHWAA);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000254
bsalomon@google.com280e99f2012-01-05 16:17:38 +0000255 bool configToGLFormats(GrPixelConfig config,
256 bool getSizedInternal,
257 GrGLenum* internalFormat,
258 GrGLenum* externalFormat,
259 GrGLenum* externalType);
bsalomon@google.com6f379512011-11-16 20:36:03 +0000260 // helper for onCreateTexture and writeTexturePixels
bsalomonb15b4c12014-10-29 12:41:57 -0700261 bool uploadTexData(const GrSurfaceDesc& desc,
bsalomon@google.com1e0e6072011-11-28 18:49:37 +0000262 bool isNewTexture,
bsalomon@google.com6f379512011-11-16 20:36:03 +0000263 int left, int top, int width, int height,
264 GrPixelConfig dataConfig,
265 const void* data,
266 size_t rowBytes);
bsalomon@google.com0650e812011-04-08 18:07:53 +0000267
krajcevski145d48c2014-06-11 16:07:50 -0700268 // helper for onCreateCompressedTexture. If width and height are
269 // set to -1, then this function will use desc.fWidth and desc.fHeight
270 // for the size of the data. The isNewTexture flag should be set to true
271 // whenever a new texture needs to be created. Otherwise, we assume that
272 // the texture is already in GPU memory and that it's going to be updated
273 // with new data.
bsalomonb15b4c12014-10-29 12:41:57 -0700274 bool uploadCompressedTexData(const GrSurfaceDesc& desc,
krajcevski145d48c2014-06-11 16:07:50 -0700275 const void* data,
276 bool isNewTexture = true,
277 int left = 0, int top = 0,
278 int width = -1, int height = -1);
krajcevski9c0e6292014-06-02 07:38:14 -0700279
bsalomon5236cf42015-01-14 10:42:08 -0800280 bool createRenderTargetObjects(const GrSurfaceDesc&, bool budgeted, GrGLuint texID,
281 GrGLRenderTarget::IDDesc*);
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000282
egdanield803f272015-03-18 13:01:52 -0700283 enum TempFBOTarget {
284 kSrc_TempFBOTarget,
285 kDst_TempFBOTarget
286 };
egdaniel0f5f9672015-02-03 11:10:51 -0800287
egdanield803f272015-03-18 13:01:52 -0700288 GrGLuint bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport,
289 TempFBOTarget tempFBOTarget);
egdaniel0f5f9672015-02-03 11:10:51 -0800290
egdanield803f272015-03-18 13:01:52 -0700291 void unbindTextureFromFBO(GrGLenum fboTarget);
robertphillips754f4e92014-09-18 13:52:08 -0700292
robertphillips@google.com6177e692013-02-28 20:16:25 +0000293 GrGLContext fGLContext;
bsalomon@google.com2c17fcd2011-07-06 17:47:02 +0000294
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000295 // GL program-related state
296 ProgramCache* fProgramCache;
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000297 SkAutoTUnref<GrGLProgram> fCurrentProgram;
bsalomon@google.com49209392012-06-05 15:13:46 +0000298
299 ///////////////////////////////////////////////////////////////////////////
300 ///@name Caching of GL State
301 ///@{
302 int fHWActiveTextureUnitIdx;
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000303 GrGLuint fHWProgramID;
bsalomon@google.com91207482013-02-12 21:45:24 +0000304
bsalomon@google.com49209392012-06-05 15:13:46 +0000305 enum TriState {
306 kNo_TriState,
307 kYes_TriState,
308 kUnknown_TriState
309 };
310
egdanield803f272015-03-18 13:01:52 -0700311 GrGLuint fTempSrcFBOID;
312 GrGLuint fTempDstFBOID;
313
314 GrGLuint fStencilClearFBOID;
bsalomondd3143b2015-02-23 09:27:45 -0800315
bsalomon@google.coma3201942012-06-21 19:58:20 +0000316 // last scissor / viewport scissor state seen by the GL.
317 struct {
318 TriState fEnabled;
319 GrGLIRect fRect;
320 void invalidate() {
321 fEnabled = kUnknown_TriState;
322 fRect.invalidate();
323 }
324 } fHWScissorSettings;
325
326 GrGLIRect fHWViewport;
327
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000328 /**
329 * Tracks bound vertex and index buffers and vertex attrib array state.
330 */
331 class HWGeometryState {
332 public:
bsalomon@google.com6918d482013-03-07 19:09:11 +0000333 HWGeometryState() { fVBOVertexArray = NULL; this->invalidate(); }
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000334
bsalomon@google.com6918d482013-03-07 19:09:11 +0000335 ~HWGeometryState() { SkSafeUnref(fVBOVertexArray); }
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000336
bsalomon@google.com6918d482013-03-07 19:09:11 +0000337 void invalidate() {
338 fBoundVertexArrayIDIsValid = false;
339 fBoundVertexBufferIDIsValid = false;
340 fDefaultVertexArrayBoundIndexBufferID = false;
341 fDefaultVertexArrayBoundIndexBufferIDIsValid = false;
342 fDefaultVertexArrayAttribState.invalidate();
bsalomon49f085d2014-09-05 13:34:00 -0700343 if (fVBOVertexArray) {
commit-bot@chromium.orgce6da4d2013-09-09 14:55:37 +0000344 fVBOVertexArray->invalidateCachedState();
345 }
bsalomon@google.com6918d482013-03-07 19:09:11 +0000346 }
347
348 void notifyVertexArrayDelete(GrGLuint id) {
349 if (fBoundVertexArrayIDIsValid && fBoundVertexArrayID == id) {
350 // Does implicit bind to 0
351 fBoundVertexArrayID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000352 }
353 }
354
bsalomon861e1032014-12-16 07:33:49 -0800355 void setVertexArrayID(GrGLGpu* gpu, GrGLuint arrayID) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000356 if (!gpu->glCaps().vertexArrayObjectSupport()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000357 SkASSERT(0 == arrayID);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000358 return;
359 }
360 if (!fBoundVertexArrayIDIsValid || arrayID != fBoundVertexArrayID) {
361 GR_GL_CALL(gpu->glInterface(), BindVertexArray(arrayID));
362 fBoundVertexArrayIDIsValid = true;
363 fBoundVertexArrayID = arrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000364 }
365 }
366
bsalomon@google.come49ad452013-02-20 19:33:20 +0000367 void notifyVertexBufferDelete(GrGLuint id) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000368 if (fBoundVertexBufferIDIsValid && id == fBoundVertexBufferID) {
369 fBoundVertexBufferID = 0;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000370 }
bsalomon49f085d2014-09-05 13:34:00 -0700371 if (fVBOVertexArray) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000372 fVBOVertexArray->notifyVertexBufferDelete(id);
373 }
374 fDefaultVertexArrayAttribState.notifyVertexBufferDelete(id);
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000375 }
376
bsalomon@google.come49ad452013-02-20 19:33:20 +0000377 void notifyIndexBufferDelete(GrGLuint id) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000378 if (fDefaultVertexArrayBoundIndexBufferIDIsValid &&
379 id == fDefaultVertexArrayBoundIndexBufferID) {
380 fDefaultVertexArrayBoundIndexBufferID = 0;
381 }
bsalomon49f085d2014-09-05 13:34:00 -0700382 if (fVBOVertexArray) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000383 fVBOVertexArray->notifyIndexBufferDelete(id);
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000384 }
385 }
386
bsalomon861e1032014-12-16 07:33:49 -0800387 void setVertexBufferID(GrGLGpu* gpu, GrGLuint id) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000388 if (!fBoundVertexBufferIDIsValid || id != fBoundVertexBufferID) {
389 GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ARRAY_BUFFER, id));
390 fBoundVertexBufferIDIsValid = true;
391 fBoundVertexBufferID = id;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000392 }
393 }
394
bsalomon@google.com6918d482013-03-07 19:09:11 +0000395 /**
396 * Binds the default vertex array and binds the index buffer. This is used when binding
397 * an index buffer in order to update it.
398 */
bsalomon861e1032014-12-16 07:33:49 -0800399 void setIndexBufferIDOnDefaultVertexArray(GrGLGpu* gpu, GrGLuint id) {
bsalomon@google.com6918d482013-03-07 19:09:11 +0000400 this->setVertexArrayID(gpu, 0);
401 if (!fDefaultVertexArrayBoundIndexBufferIDIsValid ||
402 id != fDefaultVertexArrayBoundIndexBufferID) {
403 GR_GL_CALL(gpu->glInterface(), BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, id));
404 fDefaultVertexArrayBoundIndexBufferIDIsValid = true;
405 fDefaultVertexArrayBoundIndexBufferID = id;
406 }
407 }
408
409 /**
410 * Binds the vertex array object that should be used to render from the vertex buffer.
411 * The vertex array is bound and its attrib array state object is returned. The vertex
412 * buffer is bound. The index buffer (if non-NULL) is bound to the vertex array. The
skia.committer@gmail.com754a3eb2013-03-08 07:01:25 +0000413 * returned GrGLAttribArrayState should be used to set vertex attribute arrays.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000414 */
bsalomon861e1032014-12-16 07:33:49 -0800415 GrGLAttribArrayState* bindArrayAndBuffersToDraw(GrGLGpu* gpu,
bsalomon@google.com6918d482013-03-07 19:09:11 +0000416 const GrGLVertexBuffer* vbuffer,
417 const GrGLIndexBuffer* ibuffer);
418
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000419 private:
bsalomon@google.com6918d482013-03-07 19:09:11 +0000420 GrGLuint fBoundVertexArrayID;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000421 GrGLuint fBoundVertexBufferID;
bsalomon@google.com6918d482013-03-07 19:09:11 +0000422 bool fBoundVertexArrayIDIsValid;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000423 bool fBoundVertexBufferIDIsValid;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000424
bsalomon@google.com6918d482013-03-07 19:09:11 +0000425 GrGLuint fDefaultVertexArrayBoundIndexBufferID;
426 bool fDefaultVertexArrayBoundIndexBufferIDIsValid;
427 // We return a non-const pointer to this from bindArrayAndBuffersToDraw when vertex array 0
jvanverth39edf762014-12-22 11:44:19 -0800428 // is bound. However, this class is internal to GrGLGpu and this object never leaks out of
429 // GrGLGpu.
bsalomon@google.com6918d482013-03-07 19:09:11 +0000430 GrGLAttribArrayState fDefaultVertexArrayAttribState;
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000431
bsalomon@google.com6918d482013-03-07 19:09:11 +0000432 // This is used when we're using a core profile and the vertices are in a VBO.
433 GrGLVertexArray* fVBOVertexArray;
bsalomon@google.com49209392012-06-05 15:13:46 +0000434 } fHWGeometryState;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000435
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000436 struct {
437 GrBlendCoeff fSrcCoeff;
438 GrBlendCoeff fDstCoeff;
439 GrColor fConstColor;
440 bool fConstColorValid;
441 TriState fEnabled;
442
443 void invalidate() {
bsalomon@google.com47059542012-06-06 20:51:20 +0000444 fSrcCoeff = kInvalid_GrBlendCoeff;
445 fDstCoeff = kInvalid_GrBlendCoeff;
bsalomon@google.coma4d8fc22012-05-21 13:21:46 +0000446 fConstColorValid = false;
447 fEnabled = kUnknown_TriState;
448 }
449 } fHWBlendState;
450
egdanielb414f252014-07-29 13:15:47 -0700451 TriState fMSAAEnabled;
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000452
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000453 GrStencilSettings fHWStencilSettings;
454 TriState fHWStencilTestEnabled;
kkinnunenccdaa042014-08-20 01:36:23 -0700455
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000456
egdaniel8dd688b2015-01-22 10:16:09 -0800457 GrPipelineBuilder::DrawFace fHWDrawFace;
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000458 TriState fHWWriteToColor;
459 TriState fHWDitherEnabled;
egdanield803f272015-03-18 13:01:52 -0700460 uint32_t fHWBoundRenderTargetUniqueID;
bsalomon1c63bf62014-07-22 13:09:46 -0700461 SkTArray<uint32_t, true> fHWBoundTextureUniqueIDs;
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000462
bsalomon@google.com49209392012-06-05 15:13:46 +0000463 ///@}
bsalomon@google.com978c8c62012-05-21 14:45:49 +0000464
bsalomon@google.comfe676522011-06-17 18:12:21 +0000465 // we record what stencil format worked last time to hopefully exit early
466 // from our loop that tries stencil formats and calls check fb status.
467 int fLastSuccessfulStencilFmtIdx;
468
reed@google.comac10a2d2010-12-22 21:39:39 +0000469 typedef GrGpu INHERITED;
kkinnunenccdaa042014-08-20 01:36:23 -0700470 friend class GrGLPathRendering; // For accessing setTextureUnit.
reed@google.comac10a2d2010-12-22 21:39:39 +0000471};
472
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000473#endif