1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/gl/debug/GrDebugGL.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,160 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2012 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 +#ifndef GrDebugGL_DEFINED 1.13 +#define GrDebugGL_DEFINED 1.14 + 1.15 +#include "SkTArray.h" 1.16 +#include "gl/GrGLInterface.h" 1.17 + 1.18 +class GrBufferObj; 1.19 +class GrFakeRefObj; 1.20 +class GrFrameBufferObj; 1.21 +class GrProgramObj; 1.22 +class GrRenderBufferObj; 1.23 +class GrTextureObj; 1.24 +class GrTextureUnitObj; 1.25 +class GrVertexArrayObj; 1.26 + 1.27 +//////////////////////////////////////////////////////////////////////////////// 1.28 +// This is the main debugging object. It is a singleton and keeps track of 1.29 +// all the other debug objects. 1.30 +class GrDebugGL { 1.31 +public: 1.32 + enum GrObjTypes { 1.33 + kTexture_ObjTypes = 0, 1.34 + kBuffer_ObjTypes, 1.35 + kRenderBuffer_ObjTypes, 1.36 + kFrameBuffer_ObjTypes, 1.37 + kShader_ObjTypes, 1.38 + kProgram_ObjTypes, 1.39 + kTextureUnit_ObjTypes, 1.40 + kVertexArray_ObjTypes, 1.41 + kObjTypeCount 1.42 + }; 1.43 + 1.44 + GrFakeRefObj *createObj(GrObjTypes type) { 1.45 + GrFakeRefObj *temp = (*gFactoryFunc[type])(); 1.46 + 1.47 + fObjects.push_back(temp); 1.48 + 1.49 + return temp; 1.50 + } 1.51 + 1.52 + GrFakeRefObj *findObject(GrGLuint ID, GrObjTypes type); 1.53 + 1.54 + GrGLuint getMaxTextureUnits() const { return kDefaultMaxTextureUnits; } 1.55 + 1.56 + void setCurTextureUnit(GrGLuint curTextureUnit) { fCurTextureUnit = curTextureUnit; } 1.57 + GrGLuint getCurTextureUnit() const { return fCurTextureUnit; } 1.58 + 1.59 + GrTextureUnitObj *getTextureUnit(int iUnit) { 1.60 + GrAlwaysAssert(0 <= iUnit && kDefaultMaxTextureUnits > iUnit); 1.61 + 1.62 + return fTextureUnits[iUnit]; 1.63 + } 1.64 + 1.65 + void setArrayBuffer(GrBufferObj *arrayBuffer); 1.66 + GrBufferObj *getArrayBuffer() { return fArrayBuffer; } 1.67 + 1.68 + void setElementArrayBuffer(GrBufferObj *elementArrayBuffer); 1.69 + GrBufferObj *getElementArrayBuffer() { return fElementArrayBuffer; } 1.70 + 1.71 + void setVertexArray(GrVertexArrayObj* vertexArray); 1.72 + GrVertexArrayObj* getVertexArray() { return fVertexArray; } 1.73 + 1.74 + void setTexture(GrTextureObj *texture); 1.75 + 1.76 + void setFrameBuffer(GrFrameBufferObj *frameBuffer); 1.77 + GrFrameBufferObj *getFrameBuffer() { return fFrameBuffer; } 1.78 + 1.79 + void setRenderBuffer(GrRenderBufferObj *renderBuffer); 1.80 + GrRenderBufferObj *getRenderBuffer() { return fRenderBuffer; } 1.81 + 1.82 + void useProgram(GrProgramObj *program); 1.83 + 1.84 + void setPackRowLength(GrGLint packRowLength) { 1.85 + fPackRowLength = packRowLength; 1.86 + } 1.87 + GrGLint getPackRowLength() const { return fPackRowLength; } 1.88 + 1.89 + void setUnPackRowLength(GrGLint unPackRowLength) { 1.90 + fUnPackRowLength = unPackRowLength; 1.91 + } 1.92 + GrGLint getUnPackRowLength() const { return fUnPackRowLength; } 1.93 + 1.94 + static GrDebugGL *getInstance() { 1.95 + // someone should admit to actually using this class 1.96 + SkASSERT(0 < gStaticRefCount); 1.97 + 1.98 + if (NULL == gObj) { 1.99 + gObj = SkNEW(GrDebugGL); 1.100 + } 1.101 + 1.102 + return gObj; 1.103 + } 1.104 + 1.105 + void report() const; 1.106 + 1.107 + static void staticRef() { 1.108 + gStaticRefCount++; 1.109 + } 1.110 + 1.111 + static void staticUnRef() { 1.112 + SkASSERT(gStaticRefCount > 0); 1.113 + gStaticRefCount--; 1.114 + if (0 == gStaticRefCount) { 1.115 + SkDELETE(gObj); 1.116 + gObj = NULL; 1.117 + } 1.118 + } 1.119 + 1.120 +protected: 1.121 + 1.122 +private: 1.123 + // the OpenGLES 2.0 spec says this must be >= 2 1.124 + static const GrGLint kDefaultMaxTextureUnits = 8; 1.125 + 1.126 + GrGLint fPackRowLength; 1.127 + GrGLint fUnPackRowLength; 1.128 + GrGLuint fCurTextureUnit; 1.129 + GrBufferObj* fArrayBuffer; 1.130 + GrBufferObj* fElementArrayBuffer; 1.131 + GrFrameBufferObj* fFrameBuffer; 1.132 + GrRenderBufferObj* fRenderBuffer; 1.133 + GrProgramObj* fProgram; 1.134 + GrTextureObj* fTexture; 1.135 + GrTextureUnitObj *fTextureUnits[kDefaultMaxTextureUnits]; 1.136 + GrVertexArrayObj *fVertexArray; 1.137 + 1.138 + typedef GrFakeRefObj *(*Create)(); 1.139 + 1.140 + static Create gFactoryFunc[kObjTypeCount]; 1.141 + 1.142 + static GrDebugGL* gObj; 1.143 + static int gStaticRefCount; 1.144 + 1.145 + // global store of all objects 1.146 + SkTArray<GrFakeRefObj *> fObjects; 1.147 + 1.148 + GrDebugGL(); 1.149 + ~GrDebugGL(); 1.150 +}; 1.151 + 1.152 +//////////////////////////////////////////////////////////////////////////////// 1.153 +// Helper macro to make creating an object (where you need to get back a derived 1.154 +// type) easier 1.155 +#define GR_CREATE(className, classEnum) \ 1.156 + reinterpret_cast<className *>(GrDebugGL::getInstance()->createObj(classEnum)) 1.157 + 1.158 +//////////////////////////////////////////////////////////////////////////////// 1.159 +// Helper macro to make finding objects less painful 1.160 +#define GR_FIND(id, className, classEnum) \ 1.161 + reinterpret_cast<className *>(GrDebugGL::getInstance()->findObject(id, classEnum)) 1.162 + 1.163 +#endif // GrDebugGL_DEFINED