robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #ifndef GrDebugGL_DEFINED |
| 10 | #define GrDebugGL_DEFINED |
| 11 | |
| 12 | #include "SkTArray.h" |
| 13 | #include "gl/GrGLInterface.h" |
| 14 | |
bsalomon@google.com | b82c399 | 2013-03-01 15:32:49 +0000 | [diff] [blame] | 15 | class GrBufferObj; |
bsalomon@google.com | ecd8484 | 2013-03-01 15:36:02 +0000 | [diff] [blame] | 16 | class GrFakeRefObj; |
bsalomon@google.com | b82c399 | 2013-03-01 15:32:49 +0000 | [diff] [blame] | 17 | class GrFrameBufferObj; |
bsalomon@google.com | b82c399 | 2013-03-01 15:32:49 +0000 | [diff] [blame] | 18 | class GrProgramObj; |
bsalomon@google.com | ecd8484 | 2013-03-01 15:36:02 +0000 | [diff] [blame] | 19 | class GrRenderBufferObj; |
| 20 | class GrTextureObj; |
| 21 | class GrTextureUnitObj; |
| 22 | class GrVertexArrayObj; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 23 | |
| 24 | //////////////////////////////////////////////////////////////////////////////// |
| 25 | // This is the main debugging object. It is a singleton and keeps track of |
| 26 | // all the other debug objects. |
| 27 | class GrDebugGL { |
| 28 | public: |
| 29 | enum GrObjTypes { |
| 30 | kTexture_ObjTypes = 0, |
| 31 | kBuffer_ObjTypes, |
| 32 | kRenderBuffer_ObjTypes, |
| 33 | kFrameBuffer_ObjTypes, |
| 34 | kShader_ObjTypes, |
| 35 | kProgram_ObjTypes, |
| 36 | kTextureUnit_ObjTypes, |
bsalomon@google.com | ecd8484 | 2013-03-01 15:36:02 +0000 | [diff] [blame] | 37 | kVertexArray_ObjTypes, |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 38 | kObjTypeCount |
| 39 | }; |
| 40 | |
| 41 | GrFakeRefObj *createObj(GrObjTypes type) { |
| 42 | GrFakeRefObj *temp = (*gFactoryFunc[type])(); |
| 43 | |
| 44 | fObjects.push_back(temp); |
| 45 | |
| 46 | return temp; |
| 47 | } |
| 48 | |
| 49 | GrFakeRefObj *findObject(GrGLuint ID, GrObjTypes type); |
| 50 | |
| 51 | GrGLuint getMaxTextureUnits() const { return kDefaultMaxTextureUnits; } |
| 52 | |
| 53 | void setCurTextureUnit(GrGLuint curTextureUnit) { fCurTextureUnit = curTextureUnit; } |
| 54 | GrGLuint getCurTextureUnit() const { return fCurTextureUnit; } |
| 55 | |
| 56 | GrTextureUnitObj *getTextureUnit(int iUnit) { |
| 57 | GrAlwaysAssert(0 <= iUnit && kDefaultMaxTextureUnits > iUnit); |
| 58 | |
| 59 | return fTextureUnits[iUnit]; |
| 60 | } |
| 61 | |
| 62 | void setArrayBuffer(GrBufferObj *arrayBuffer); |
| 63 | GrBufferObj *getArrayBuffer() { return fArrayBuffer; } |
| 64 | |
| 65 | void setElementArrayBuffer(GrBufferObj *elementArrayBuffer); |
| 66 | GrBufferObj *getElementArrayBuffer() { return fElementArrayBuffer; } |
| 67 | |
bsalomon@google.com | ecd8484 | 2013-03-01 15:36:02 +0000 | [diff] [blame] | 68 | void setVertexArray(GrVertexArrayObj* vertexArray); |
| 69 | GrVertexArrayObj* getVertexArray() { return fVertexArray; } |
| 70 | |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 71 | void setTexture(GrTextureObj *texture); |
| 72 | |
| 73 | void setFrameBuffer(GrFrameBufferObj *frameBuffer); |
| 74 | GrFrameBufferObj *getFrameBuffer() { return fFrameBuffer; } |
| 75 | |
| 76 | void setRenderBuffer(GrRenderBufferObj *renderBuffer); |
| 77 | GrRenderBufferObj *getRenderBuffer() { return fRenderBuffer; } |
| 78 | |
| 79 | void useProgram(GrProgramObj *program); |
| 80 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 81 | void setPackRowLength(GrGLint packRowLength) { |
| 82 | fPackRowLength = packRowLength; |
robertphillips@google.com | 670ff9a | 2012-04-12 19:53:31 +0000 | [diff] [blame] | 83 | } |
| 84 | GrGLint getPackRowLength() const { return fPackRowLength; } |
| 85 | |
| 86 | void setUnPackRowLength(GrGLint unPackRowLength) { |
| 87 | fUnPackRowLength = unPackRowLength; |
| 88 | } |
| 89 | GrGLint getUnPackRowLength() const { return fUnPackRowLength; } |
| 90 | |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 91 | static GrDebugGL *getInstance() { |
robertphillips@google.com | 622a170 | 2012-07-31 19:23:02 +0000 | [diff] [blame] | 92 | // someone should admit to actually using this class |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 93 | SkASSERT(0 < gStaticRefCount); |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 94 | |
robertphillips@google.com | 622a170 | 2012-07-31 19:23:02 +0000 | [diff] [blame] | 95 | if (NULL == gObj) { |
| 96 | gObj = SkNEW(GrDebugGL); |
| 97 | } |
| 98 | |
| 99 | return gObj; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void report() const; |
| 103 | |
robertphillips@google.com | 622a170 | 2012-07-31 19:23:02 +0000 | [diff] [blame] | 104 | static void staticRef() { |
| 105 | gStaticRefCount++; |
| 106 | } |
| 107 | |
| 108 | static void staticUnRef() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 109 | SkASSERT(gStaticRefCount > 0); |
robertphillips@google.com | 622a170 | 2012-07-31 19:23:02 +0000 | [diff] [blame] | 110 | gStaticRefCount--; |
| 111 | if (0 == gStaticRefCount) { |
| 112 | SkDELETE(gObj); |
| 113 | gObj = NULL; |
| 114 | } |
| 115 | } |
| 116 | |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 117 | protected: |
| 118 | |
| 119 | private: |
| 120 | // the OpenGLES 2.0 spec says this must be >= 2 |
| 121 | static const GrGLint kDefaultMaxTextureUnits = 8; |
| 122 | |
robertphillips@google.com | 670ff9a | 2012-04-12 19:53:31 +0000 | [diff] [blame] | 123 | GrGLint fPackRowLength; |
| 124 | GrGLint fUnPackRowLength; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 125 | GrGLuint fCurTextureUnit; |
bsalomon@google.com | ecd8484 | 2013-03-01 15:36:02 +0000 | [diff] [blame] | 126 | GrBufferObj* fArrayBuffer; |
| 127 | GrBufferObj* fElementArrayBuffer; |
| 128 | GrFrameBufferObj* fFrameBuffer; |
| 129 | GrRenderBufferObj* fRenderBuffer; |
| 130 | GrProgramObj* fProgram; |
| 131 | GrTextureObj* fTexture; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 132 | GrTextureUnitObj *fTextureUnits[kDefaultMaxTextureUnits]; |
bsalomon@google.com | ecd8484 | 2013-03-01 15:36:02 +0000 | [diff] [blame] | 133 | GrVertexArrayObj *fVertexArray; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 134 | |
| 135 | typedef GrFakeRefObj *(*Create)(); |
| 136 | |
| 137 | static Create gFactoryFunc[kObjTypeCount]; |
| 138 | |
robertphillips@google.com | 622a170 | 2012-07-31 19:23:02 +0000 | [diff] [blame] | 139 | static GrDebugGL* gObj; |
| 140 | static int gStaticRefCount; |
robertphillips@google.com | dd743fe | 2012-04-05 14:40:53 +0000 | [diff] [blame] | 141 | |
| 142 | // global store of all objects |
| 143 | SkTArray<GrFakeRefObj *> fObjects; |
| 144 | |
| 145 | GrDebugGL(); |
| 146 | ~GrDebugGL(); |
| 147 | }; |
| 148 | |
| 149 | //////////////////////////////////////////////////////////////////////////////// |
| 150 | // Helper macro to make creating an object (where you need to get back a derived |
| 151 | // type) easier |
| 152 | #define GR_CREATE(className, classEnum) \ |
| 153 | reinterpret_cast<className *>(GrDebugGL::getInstance()->createObj(classEnum)) |
| 154 | |
| 155 | //////////////////////////////////////////////////////////////////////////////// |
| 156 | // Helper macro to make finding objects less painful |
| 157 | #define GR_FIND(id, className, classEnum) \ |
| 158 | reinterpret_cast<className *>(GrDebugGL::getInstance()->findObject(id, classEnum)) |
| 159 | |
| 160 | #endif // GrDebugGL_DEFINED |