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