gfx/skia/trunk/src/gpu/gl/debug/GrDebugGL.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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 #include "GrDebugGL.h"
michael@0 10 #include "GrTextureObj.h"
michael@0 11 #include "GrBufferObj.h"
michael@0 12 #include "GrRenderBufferObj.h"
michael@0 13 #include "GrFrameBufferObj.h"
michael@0 14 #include "GrShaderObj.h"
michael@0 15 #include "GrProgramObj.h"
michael@0 16 #include "GrTextureUnitObj.h"
michael@0 17 #include "GrVertexArrayObj.h"
michael@0 18
michael@0 19 GrDebugGL* GrDebugGL::gObj = NULL;
michael@0 20 int GrDebugGL::gStaticRefCount = 0;
michael@0 21 GrDebugGL::Create GrDebugGL::gFactoryFunc[kObjTypeCount] = {
michael@0 22 GrTextureObj::createGrTextureObj,
michael@0 23 GrBufferObj::createGrBufferObj,
michael@0 24 GrRenderBufferObj::createGrRenderBufferObj,
michael@0 25 GrFrameBufferObj::createGrFrameBufferObj,
michael@0 26 GrShaderObj::createGrShaderObj,
michael@0 27 GrProgramObj::createGrProgramObj,
michael@0 28 GrTextureUnitObj::createGrTextureUnitObj,
michael@0 29 GrVertexArrayObj::createGrVertexArrayObj,
michael@0 30 };
michael@0 31
michael@0 32
michael@0 33 GrDebugGL::GrDebugGL()
michael@0 34 : fPackRowLength(0)
michael@0 35 , fUnPackRowLength(0)
michael@0 36 , fCurTextureUnit(0)
michael@0 37 , fArrayBuffer(NULL)
michael@0 38 , fElementArrayBuffer(NULL)
michael@0 39 , fFrameBuffer(NULL)
michael@0 40 , fRenderBuffer(NULL)
michael@0 41 , fProgram(NULL)
michael@0 42 , fTexture(NULL)
michael@0 43 , fVertexArray(NULL) {
michael@0 44
michael@0 45 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) {
michael@0 46
michael@0 47 fTextureUnits[i] = reinterpret_cast<GrTextureUnitObj *>(
michael@0 48 createObj(GrDebugGL::kTextureUnit_ObjTypes));
michael@0 49 fTextureUnits[i]->ref();
michael@0 50
michael@0 51 fTextureUnits[i]->setNumber(i);
michael@0 52 }
michael@0 53 }
michael@0 54
michael@0 55 GrDebugGL::~GrDebugGL() {
michael@0 56 // unref & delete the texture units first so they don't show up on the leak report
michael@0 57 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) {
michael@0 58 fTextureUnits[i]->unref();
michael@0 59 fTextureUnits[i]->deleteAction();
michael@0 60 }
michael@0 61
michael@0 62 this->report();
michael@0 63
michael@0 64 for (int i = 0; i < fObjects.count(); ++i) {
michael@0 65 delete fObjects[i];
michael@0 66 }
michael@0 67 fObjects.reset();
michael@0 68
michael@0 69 fArrayBuffer = NULL;
michael@0 70 fElementArrayBuffer = NULL;
michael@0 71 fFrameBuffer = NULL;
michael@0 72 fRenderBuffer = NULL;
michael@0 73 fProgram = NULL;
michael@0 74 fTexture = NULL;
michael@0 75 fVertexArray = NULL;
michael@0 76 }
michael@0 77
michael@0 78 GrFakeRefObj *GrDebugGL::findObject(GrGLuint ID, GrObjTypes type) {
michael@0 79 for (int i = 0; i < fObjects.count(); ++i) {
michael@0 80 if (fObjects[i]->getID() == ID) { // && fObjects[i]->getType() == type) {
michael@0 81 // The application shouldn't be accessing objects
michael@0 82 // that (as far as OpenGL knows) were already deleted
michael@0 83 GrAlwaysAssert(!fObjects[i]->getDeleted());
michael@0 84 GrAlwaysAssert(!fObjects[i]->getMarkedForDeletion());
michael@0 85 return fObjects[i];
michael@0 86 }
michael@0 87 }
michael@0 88
michael@0 89 return NULL;
michael@0 90 }
michael@0 91
michael@0 92 void GrDebugGL::setArrayBuffer(GrBufferObj *arrayBuffer) {
michael@0 93 if (fArrayBuffer) {
michael@0 94 // automatically break the binding of the old buffer
michael@0 95 GrAlwaysAssert(fArrayBuffer->getBound());
michael@0 96 fArrayBuffer->resetBound();
michael@0 97
michael@0 98 GrAlwaysAssert(!fArrayBuffer->getDeleted());
michael@0 99 fArrayBuffer->unref();
michael@0 100 }
michael@0 101
michael@0 102 fArrayBuffer = arrayBuffer;
michael@0 103
michael@0 104 if (fArrayBuffer) {
michael@0 105 GrAlwaysAssert(!fArrayBuffer->getDeleted());
michael@0 106 fArrayBuffer->ref();
michael@0 107
michael@0 108 GrAlwaysAssert(!fArrayBuffer->getBound());
michael@0 109 fArrayBuffer->setBound();
michael@0 110 }
michael@0 111 }
michael@0 112
michael@0 113 void GrDebugGL::setVertexArray(GrVertexArrayObj* vertexArray) {
michael@0 114 if (NULL != vertexArray) {
michael@0 115 SkASSERT(!vertexArray->getDeleted());
michael@0 116 }
michael@0 117 SkRefCnt_SafeAssign(fVertexArray, vertexArray);
michael@0 118 }
michael@0 119
michael@0 120 void GrDebugGL::setElementArrayBuffer(GrBufferObj *elementArrayBuffer) {
michael@0 121 if (fElementArrayBuffer) {
michael@0 122 // automatically break the binding of the old buffer
michael@0 123 GrAlwaysAssert(fElementArrayBuffer->getBound());
michael@0 124 fElementArrayBuffer->resetBound();
michael@0 125
michael@0 126 GrAlwaysAssert(!fElementArrayBuffer->getDeleted());
michael@0 127 fElementArrayBuffer->unref();
michael@0 128 }
michael@0 129
michael@0 130 fElementArrayBuffer = elementArrayBuffer;
michael@0 131
michael@0 132 if (fElementArrayBuffer) {
michael@0 133 GrAlwaysAssert(!fElementArrayBuffer->getDeleted());
michael@0 134 fElementArrayBuffer->ref();
michael@0 135
michael@0 136 GrAlwaysAssert(!fElementArrayBuffer->getBound());
michael@0 137 fElementArrayBuffer->setBound();
michael@0 138 }
michael@0 139 }
michael@0 140
michael@0 141 void GrDebugGL::setTexture(GrTextureObj *texture) {
michael@0 142 fTextureUnits[fCurTextureUnit]->setTexture(texture);
michael@0 143 }
michael@0 144
michael@0 145 void GrDebugGL::setFrameBuffer(GrFrameBufferObj *frameBuffer) {
michael@0 146 if (fFrameBuffer) {
michael@0 147 GrAlwaysAssert(fFrameBuffer->getBound());
michael@0 148 fFrameBuffer->resetBound();
michael@0 149
michael@0 150 GrAlwaysAssert(!fFrameBuffer->getDeleted());
michael@0 151 fFrameBuffer->unref();
michael@0 152 }
michael@0 153
michael@0 154 fFrameBuffer = frameBuffer;
michael@0 155
michael@0 156 if (fFrameBuffer) {
michael@0 157 GrAlwaysAssert(!fFrameBuffer->getDeleted());
michael@0 158 fFrameBuffer->ref();
michael@0 159
michael@0 160 GrAlwaysAssert(!fFrameBuffer->getBound());
michael@0 161 fFrameBuffer->setBound();
michael@0 162 }
michael@0 163 }
michael@0 164
michael@0 165 void GrDebugGL::setRenderBuffer(GrRenderBufferObj *renderBuffer) {
michael@0 166 if (fRenderBuffer) {
michael@0 167 GrAlwaysAssert(fRenderBuffer->getBound());
michael@0 168 fRenderBuffer->resetBound();
michael@0 169
michael@0 170 GrAlwaysAssert(!fRenderBuffer->getDeleted());
michael@0 171 fRenderBuffer->unref();
michael@0 172 }
michael@0 173
michael@0 174 fRenderBuffer = renderBuffer;
michael@0 175
michael@0 176 if (fRenderBuffer) {
michael@0 177 GrAlwaysAssert(!fRenderBuffer->getDeleted());
michael@0 178 fRenderBuffer->ref();
michael@0 179
michael@0 180 GrAlwaysAssert(!fRenderBuffer->getBound());
michael@0 181 fRenderBuffer->setBound();
michael@0 182 }
michael@0 183 }
michael@0 184
michael@0 185 void GrDebugGL::useProgram(GrProgramObj *program) {
michael@0 186 if (fProgram) {
michael@0 187 GrAlwaysAssert(fProgram->getInUse());
michael@0 188 fProgram->resetInUse();
michael@0 189
michael@0 190 GrAlwaysAssert(!fProgram->getDeleted());
michael@0 191 fProgram->unref();
michael@0 192 }
michael@0 193
michael@0 194 fProgram = program;
michael@0 195
michael@0 196 if (fProgram) {
michael@0 197 GrAlwaysAssert(!fProgram->getDeleted());
michael@0 198 fProgram->ref();
michael@0 199
michael@0 200 GrAlwaysAssert(!fProgram->getInUse());
michael@0 201 fProgram->setInUse();
michael@0 202 }
michael@0 203 }
michael@0 204
michael@0 205 void GrDebugGL::report() const {
michael@0 206 for (int i = 0; i < fObjects.count(); ++i) {
michael@0 207 GrAlwaysAssert(0 == fObjects[i]->getRefCount());
michael@0 208 GrAlwaysAssert(0 < fObjects[i]->getHighRefCount());
michael@0 209 GrAlwaysAssert(fObjects[i]->getDeleted());
michael@0 210 }
michael@0 211 }

mercurial