| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | |
| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #ifndef GrGpuGL_DEFINED |
| 11 | #define GrGpuGL_DEFINED |
| 12 | |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 13 | #include "GrBinHashKey.h" |
| tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 14 | #include "GrDrawState.h" |
| 15 | #include "GrGpu.h" |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 16 | #include "GrGLContextInfo.h" |
| bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 17 | #include "GrGLIndexBuffer.h" |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 18 | #include "GrGLIRect.h" |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 19 | #include "GrGLProgram.h" |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 20 | #include "GrGLStencilBuffer.h" |
| 21 | #include "GrGLTexture.h" |
| 22 | #include "GrGLVertexBuffer.h" |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 23 | #include "../GrTHashCache.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
| 25 | class GrGpuGL : public GrGpu { |
| 26 | public: |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 27 | GrGpuGL(const GrGLContextInfo& ctxInfo); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | virtual ~GrGpuGL(); |
| 29 | |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 30 | const GrGLInterface* glInterface() const { |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 31 | return fGLContextInfo.interface(); |
| 32 | } |
| tomhudson@google.com | dd182cb | 2012-02-10 21:01:00 +0000 | [diff] [blame] | 33 | GrGLBinding glBinding() const { return fGLContextInfo.binding(); } |
| 34 | GrGLVersion glVersion() const { return fGLContextInfo.version(); } |
| 35 | GrGLSLGeneration glslGeneration() const { |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 36 | return fGLContextInfo.glslGeneration(); |
| 37 | } |
| bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 38 | |
| bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 39 | // Used by GrGLProgram to bind necessary textures for GrGLEffects. |
| 40 | void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture); |
| 41 | |
| bsalomon@google.com | a45afcf | 2013-02-04 18:46:49 +0000 | [diff] [blame] | 42 | bool programUnitTest(int maxStages); |
| bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 43 | |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 44 | // GrGpu overrides |
| bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 45 | virtual GrPixelConfig preferredReadPixelsConfig(GrPixelConfig config) const SK_OVERRIDE; |
| 46 | virtual GrPixelConfig preferredWritePixelsConfig(GrPixelConfig config) const SK_OVERRIDE; |
| 47 | virtual bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const SK_OVERRIDE; |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 48 | virtual bool readPixelsWillPayForYFlip( |
| 49 | GrRenderTarget* renderTarget, |
| 50 | int left, int top, |
| 51 | int width, int height, |
| 52 | GrPixelConfig config, |
| bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 53 | size_t rowBytes) const SK_OVERRIDE; |
| 54 | virtual bool fullReadPixelsIsFasterThanPartial() const SK_OVERRIDE; |
| bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 55 | |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 56 | virtual void abandonResources() SK_OVERRIDE; |
| 57 | |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 58 | const GrGLCaps& glCaps() const { return fGLContextInfo.caps(); } |
| 59 | |
| bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame^] | 60 | // Callbacks to update state tracking when related GL objects are bound or deleted |
| 61 | void notifyVertexBufferBind(const GrGLVertexBuffer* buffer); |
| 62 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer); |
| 63 | void notifyIndexBufferBind(const GrGLIndexBuffer* buffer); |
| 64 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer); |
| 65 | void notifyTextureDelete(GrGLTexture* texture); |
| 66 | void notifyRenderTargetDelete(GrRenderTarget* renderTarget); |
| 67 | |
| bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 68 | private: |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 69 | // GrGpu overrides |
| bsalomon@google.com | 1bf1c21 | 2011-11-05 12:18:58 +0000 | [diff] [blame] | 70 | virtual void onResetContext() SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 71 | |
| bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 72 | virtual GrTexture* onCreateTexture(const GrTextureDesc& desc, |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 73 | const void* srcData, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 74 | size_t rowBytes) SK_OVERRIDE; |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 75 | virtual GrVertexBuffer* onCreateVertexBuffer(uint32_t size, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 76 | bool dynamic) SK_OVERRIDE; |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 77 | virtual GrIndexBuffer* onCreateIndexBuffer(uint32_t size, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 78 | bool dynamic) SK_OVERRIDE; |
| bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 79 | virtual GrPath* onCreatePath(const SkPath&) SK_OVERRIDE; |
| bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 80 | virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&) SK_OVERRIDE; |
| 81 | virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) SK_OVERRIDE; |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 82 | virtual bool createStencilBufferForRenderTarget(GrRenderTarget* rt, |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 83 | int width, |
| 84 | int height) SK_OVERRIDE; |
| 85 | virtual bool attachStencilBufferToRenderTarget( |
| 86 | GrStencilBuffer* sb, |
| 87 | GrRenderTarget* rt) SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 88 | |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 89 | virtual void onClear(const GrIRect* rect, GrColor color) SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 90 | |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 91 | virtual void onForceRenderTargetFlush() SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 92 | |
| bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 93 | virtual bool onReadPixels(GrRenderTarget* target, |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 94 | int left, int top, |
| bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 95 | int width, int height, |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 96 | GrPixelConfig, |
| bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 97 | void* buffer, |
| senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 98 | size_t rowBytes) SK_OVERRIDE; |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 99 | |
| bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 100 | virtual bool onWriteTexturePixels(GrTexture* texture, |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 101 | int left, int top, int width, int height, |
| 102 | GrPixelConfig config, const void* buffer, |
| 103 | size_t rowBytes) SK_OVERRIDE; |
| 104 | |
| bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 105 | virtual void onResolveRenderTarget(GrRenderTarget* target) SK_OVERRIDE; |
| 106 | |
| bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 107 | virtual void onGpuDraw(const DrawInfo&) SK_OVERRIDE; |
| bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 108 | |
| 109 | virtual void setStencilPathSettings(const GrPath&, |
| sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 110 | SkPath::FillType, |
| bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 111 | GrStencilSettings* settings) |
| 112 | SK_OVERRIDE; |
| sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 113 | virtual void onGpuStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
| robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 114 | |
| bsalomon@google.com | 13f1b6f | 2012-05-31 12:52:43 +0000 | [diff] [blame] | 115 | virtual void clearStencil() SK_OVERRIDE; |
| 116 | virtual void clearStencilClip(const GrIRect& rect, |
| 117 | bool insideClip) SK_OVERRIDE; |
| bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 118 | virtual bool flushGraphicsState(DrawType) SK_OVERRIDE; |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 119 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 120 | // binds texture unit in GL |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 121 | void setTextureUnit(int unitIdx); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 122 | |
| bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame^] | 123 | // Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset |
| 124 | // an into the index buffer. It does not account for drawInfo.startIndex() but rather the start |
| 125 | // index is relative to the returned offset. |
| 126 | void setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes); |
| 127 | // binds appropriate vertex and index buffers. It also returns offsets for the vertex and index |
| 128 | // buffers. These offsets account for placement within a pool buffer or CPU-side addresses for |
| 129 | // use with buffer 0. They do not account for start values in the DrawInfo (which is not passed |
| 130 | // here). The vertex buffer that contains the vertex data is returned. It is not necessarily |
| 131 | // bound. |
| 132 | GrGLVertexBuffer* setBuffers(bool indexed, size_t* vertexOffsetInBytes, size_t* indexOffsetInBytes); |
| bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 133 | |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 134 | // Subclasses should call this to flush the blend state. |
| bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 135 | // The params should be the final coefficients to apply |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 136 | // (after any blending optimizations or dual source blending considerations |
| 137 | // have been accounted for). |
| bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 138 | void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff); |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 139 | |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 140 | bool hasExtension(const char* ext) const { |
| 141 | return fGLContextInfo.hasExtension(ext); |
| bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | const GrGLContextInfo& glContextInfo() const { return fGLContextInfo; } |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 145 | |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 146 | static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |
| bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 147 | |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 148 | class ProgramCache : public ::GrNoncopyable { |
| 149 | public: |
| 150 | ProgramCache(const GrGLContextInfo& gl); |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 151 | |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 152 | void abandon(); |
| bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 153 | GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrEffectStage* stages[]); |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 154 | private: |
| 155 | enum { |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 156 | kKeySize = sizeof(GrGLProgram::Desc), |
| bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 157 | // We may actually have kMaxEntries+1 shaders in the GL context because we create a new |
| 158 | // shader before evicting from the cache. |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 159 | kMaxEntries = 32 |
| 160 | }; |
| 161 | |
| 162 | class Entry; |
| bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 163 | // The value of the hash key is based on the ProgramDesc. |
| 164 | typedef GrTBinHashKey<Entry, kKeySize> ProgramHashKey; |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 165 | |
| 166 | class Entry : public ::GrNoncopyable { |
| 167 | public: |
| bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 168 | Entry() : fProgram(NULL), fLRUStamp(0) {} |
| 169 | Entry& operator = (const Entry& entry) { |
| 170 | GrSafeRef(entry.fProgram.get()); |
| 171 | fProgram.reset(entry.fProgram.get()); |
| 172 | fKey = entry.fKey; |
| 173 | fLRUStamp = entry.fLRUStamp; |
| 174 | return *this; |
| 175 | } |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 176 | int compare(const ProgramHashKey& key) const { |
| 177 | return fKey.compare(key); |
| 178 | } |
| 179 | |
| 180 | public: |
| bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 181 | SkAutoTUnref<GrGLProgram> fProgram; |
| 182 | ProgramHashKey fKey; |
| 183 | unsigned int fLRUStamp; // Move outside entry? |
| bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | GrTHashTable<Entry, ProgramHashKey, 8> fHashCache; |
| 187 | |
| 188 | Entry fEntries[kMaxEntries]; |
| 189 | int fCount; |
| 190 | unsigned int fCurrLRUStamp; |
| 191 | const GrGLContextInfo& fGL; |
| 192 | }; |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 193 | |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 194 | // sets the matrix for path stenciling (uses the GL fixed pipe matrices) |
| 195 | void flushPathStencilMatrix(); |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 196 | |
| bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 197 | // flushes dithering, color-mask, and face culling stat |
| 198 | void flushMiscFixedFunctionState(); |
| 199 | |
| bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 200 | // flushes the scissor. see the note on flushBoundTextureAndParams about |
| 201 | // flushing the scissor after that function is called. |
| 202 | void flushScissor(); |
| 203 | |
| bsalomon@google.com | 67e78c9 | 2012-10-17 13:36:14 +0000 | [diff] [blame] | 204 | // Inits GrDrawTarget::Caps, subclass may enable additional caps. |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 205 | void initCaps(); |
| 206 | |
| 207 | void initFSAASupport(); |
| bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 208 | |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 209 | // determines valid stencil formats |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 210 | void initStencilFormats(); |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 211 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 212 | void setSpareTextureUnit(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 213 | |
| bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 214 | // bound is region that may be modified and therefore has to be resolved. |
| 215 | // NULL means whole target. Can be an empty rect. |
| 216 | void flushRenderTarget(const GrIRect* bound); |
| bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 217 | void flushStencil(DrawType); |
| 218 | void flushAAState(DrawType); |
| bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 219 | |
| bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 220 | bool configToGLFormats(GrPixelConfig config, |
| 221 | bool getSizedInternal, |
| 222 | GrGLenum* internalFormat, |
| 223 | GrGLenum* externalFormat, |
| 224 | GrGLenum* externalType); |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 225 | // helper for onCreateTexture and writeTexturePixels |
| bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 226 | bool uploadTexData(const GrGLTexture::Desc& desc, |
| bsalomon@google.com | 1e0e607 | 2011-11-28 18:49:37 +0000 | [diff] [blame] | 227 | bool isNewTexture, |
| bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 228 | int left, int top, int width, int height, |
| 229 | GrPixelConfig dataConfig, |
| 230 | const void* data, |
| 231 | size_t rowBytes); |
| bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 232 | |
| bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 233 | bool createRenderTargetObjects(int width, int height, |
| 234 | GrGLuint texID, |
| 235 | GrGLRenderTarget::Desc* desc); |
| 236 | |
| robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 237 | void fillInConfigRenderableTable(); |
| 238 | |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 239 | GrGLContextInfo fGLContextInfo; |
| bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 240 | |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 241 | // GL program-related state |
| 242 | ProgramCache* fProgramCache; |
| bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 243 | SkAutoTUnref<GrGLProgram> fCurrentProgram; |
| bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 244 | |
| 245 | /////////////////////////////////////////////////////////////////////////// |
| 246 | ///@name Caching of GL State |
| 247 | ///@{ |
| 248 | int fHWActiveTextureUnitIdx; |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 249 | GrGLuint fHWProgramID; |
| bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 250 | |
| 251 | GrGLProgram::SharedGLState fSharedGLProgramState; |
| bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 252 | |
| bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 253 | enum TriState { |
| 254 | kNo_TriState, |
| 255 | kYes_TriState, |
| 256 | kUnknown_TriState |
| 257 | }; |
| 258 | |
| bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 259 | // last scissor / viewport scissor state seen by the GL. |
| 260 | struct { |
| 261 | TriState fEnabled; |
| 262 | GrGLIRect fRect; |
| 263 | void invalidate() { |
| 264 | fEnabled = kUnknown_TriState; |
| 265 | fRect.invalidate(); |
| 266 | } |
| 267 | } fHWScissorSettings; |
| 268 | |
| 269 | GrGLIRect fHWViewport; |
| 270 | |
| bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame^] | 271 | /** |
| 272 | * Tracks bound vertex and index buffers and vertex attrib array state. |
| 273 | */ |
| 274 | class HWGeometryState { |
| 275 | public: |
| 276 | HWGeometryState() { fAttribArrayCount = 0; this->invalidate();} |
| 277 | |
| 278 | void setMaxAttribArrays(int max) { |
| 279 | fAttribArrayCount = max; |
| 280 | fAttribArrays.reset(max); |
| 281 | for (int i = 0; i < fAttribArrayCount; ++i) { |
| 282 | fAttribArrays[i].invalidate(); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void invalidate() { |
| 287 | fBoundVertexBufferIDIsValid = false; |
| 288 | fBoundIndexBufferIDIsValid = false; |
| 289 | for (int i = 0; i < fAttribArrayCount; ++i) { |
| 290 | fAttribArrays[i].invalidate(); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | void notifyVertexBufferDelete(const GrGLVertexBuffer* buffer) { |
| 295 | GrGLuint id = buffer->bufferID(); |
| 296 | if (0 != id) { |
| 297 | if (this->isVertexBufferIDBound(id)) { |
| 298 | // deleting bound buffer does implied bind to 0 |
| 299 | this->setVertexBufferID(0); |
| 300 | } |
| 301 | for (int i = 0; i < fAttribArrayCount; ++i) { |
| 302 | if (fAttribArrays[i].vertexBufferID() == id) { |
| 303 | fAttribArrays[i].invalidate(); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | void notifyIndexBufferDelete(const GrGLIndexBuffer* buffer) { |
| 310 | GrGLuint id = buffer->bufferID(); |
| 311 | if (0 != id) { |
| 312 | if (this->isIndexBufferIDBound(id)) { |
| 313 | // deleting bound buffer does implied bind to 0 |
| 314 | this->setIndexBufferID(0); |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | void setVertexBufferID(GrGLuint id) { |
| 320 | fBoundVertexBufferIDIsValid = true; |
| 321 | fBoundVertexBufferID = id; |
| 322 | } |
| 323 | |
| 324 | void setIndexBufferID(GrGLuint id) { |
| 325 | fBoundIndexBufferIDIsValid = true; |
| 326 | fBoundIndexBufferID = id; |
| 327 | } |
| 328 | |
| 329 | bool isVertexBufferIDBound(GrGLuint id) const { |
| 330 | return fBoundVertexBufferIDIsValid && id == fBoundVertexBufferID; |
| 331 | } |
| 332 | |
| 333 | bool isIndexBufferIDBound(GrGLuint id) const { |
| 334 | return fBoundIndexBufferIDIsValid && id == fBoundIndexBufferID; |
| 335 | } |
| 336 | |
| 337 | void setAttribArray(const GrGpuGL* gpu, |
| 338 | int index, |
| 339 | GrGLVertexBuffer* vertexBuffer, |
| 340 | GrGLint size, |
| 341 | GrGLenum type, |
| 342 | GrGLboolean normalized, |
| 343 | GrGLsizei stride, |
| 344 | GrGLvoid* offset) { |
| 345 | GrAssert(index >= 0 && index < fAttribArrayCount); |
| 346 | AttribArray* attrib = fAttribArrays.get() + index; |
| 347 | attrib->set(gpu, this, index, vertexBuffer, size, type, normalized, stride, offset); |
| 348 | } |
| 349 | |
| 350 | void disableUnusedAttribArrays(const GrGpuGL* gpu, |
| 351 | uint32_t usedAttribIndexMask) { |
| 352 | for (int i = 0; i < fAttribArrayCount; ++i) { |
| 353 | if (!(usedAttribIndexMask & (1 << i))) { |
| 354 | fAttribArrays[i].disable(gpu, i); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | private: |
| 360 | GrGLuint fBoundVertexBufferID; |
| 361 | GrGLuint fBoundIndexBufferID; |
| 362 | bool fBoundVertexBufferIDIsValid; |
| 363 | bool fBoundIndexBufferIDIsValid; |
| 364 | |
| 365 | struct AttribArray { |
| 366 | public: |
| 367 | void set(const GrGpuGL* gpu, |
| 368 | HWGeometryState* geoState, |
| 369 | int index, |
| 370 | GrGLVertexBuffer* vertexBuffer, |
| 371 | GrGLint size, |
| 372 | GrGLenum type, |
| 373 | GrGLboolean normalized, |
| 374 | GrGLsizei stride, |
| 375 | GrGLvoid* offset); |
| 376 | |
| 377 | void disable(const GrGpuGL* gpu, int index) { |
| 378 | if (!fEnableIsValid || fEnabled) { |
| 379 | GR_GL_CALL(gpu->glInterface(), DisableVertexAttribArray(index)); |
| 380 | fEnableIsValid = true; |
| 381 | fEnabled = false; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | void invalidate() { |
| 386 | fEnableIsValid = false; |
| 387 | fAttribPointerIsValid = false; |
| 388 | } |
| 389 | |
| 390 | GrGLuint vertexBufferID() const { return fVertexBufferID; } |
| 391 | private: |
| 392 | bool fEnableIsValid; |
| 393 | bool fAttribPointerIsValid; |
| 394 | bool fEnabled; |
| 395 | GrGLuint fVertexBufferID; |
| 396 | GrGLint fSize; |
| 397 | GrGLenum fType; |
| 398 | GrGLboolean fNormalized; |
| 399 | GrGLsizei fStride; |
| 400 | GrGLvoid* fOffset; |
| 401 | }; |
| 402 | SkAutoTArray<AttribArray> fAttribArrays; |
| 403 | int fAttribArrayCount; |
| bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 404 | } fHWGeometryState; |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 405 | |
| bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 406 | struct { |
| 407 | GrBlendCoeff fSrcCoeff; |
| 408 | GrBlendCoeff fDstCoeff; |
| 409 | GrColor fConstColor; |
| 410 | bool fConstColorValid; |
| 411 | TriState fEnabled; |
| 412 | |
| 413 | void invalidate() { |
| bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 414 | fSrcCoeff = kInvalid_GrBlendCoeff; |
| 415 | fDstCoeff = kInvalid_GrBlendCoeff; |
| bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 416 | fConstColorValid = false; |
| 417 | fEnabled = kUnknown_TriState; |
| 418 | } |
| 419 | } fHWBlendState; |
| 420 | |
| bsalomon@google.com | 4d5f3fe | 2012-05-21 17:11:44 +0000 | [diff] [blame] | 421 | struct { |
| 422 | TriState fMSAAEnabled; |
| 423 | TriState fSmoothLineEnabled; |
| 424 | void invalidate() { |
| 425 | fMSAAEnabled = kUnknown_TriState; |
| 426 | fSmoothLineEnabled = kUnknown_TriState; |
| 427 | } |
| 428 | } fHWAAState; |
| 429 | |
| bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 430 | |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 431 | GrGLProgram::MatrixState fHWPathStencilMatrixState; |
| bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 432 | |
| bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 433 | GrStencilSettings fHWStencilSettings; |
| 434 | TriState fHWStencilTestEnabled; |
| 435 | |
| 436 | GrDrawState::DrawFace fHWDrawFace; |
| 437 | TriState fHWWriteToColor; |
| 438 | TriState fHWDitherEnabled; |
| 439 | GrRenderTarget* fHWBoundRenderTarget; |
| 440 | GrTexture* fHWBoundTextures[GrDrawState::kNumStages]; |
| bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 441 | ///@} |
| bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 442 | |
| bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 443 | // we record what stencil format worked last time to hopefully exit early |
| 444 | // from our loop that tries stencil formats and calls check fb status. |
| 445 | int fLastSuccessfulStencilFmtIdx; |
| 446 | |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 447 | bool fPrintedCaps; |
| 448 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 449 | typedef GrGpu INHERITED; |
| 450 | }; |
| 451 | |
| bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 452 | #endif |