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