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