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