blob: 03ff36daf2789c8aafcefbcbe7c5d7c6d7a4849e [file] [log] [blame]
robertphillips@google.comdd743fe2012-04-05 14:40:53 +00001
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.comecd84842013-03-01 15:36:02 +000017#include "GrVertexArrayObj.h"
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000018
robertphillips@google.com622a1702012-07-31 19:23:02 +000019GrDebugGL* GrDebugGL::gObj = NULL;
20int GrDebugGL::gStaticRefCount = 0;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000021GrDebugGL::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.comecd84842013-03-01 15:36:02 +000029 GrVertexArrayObj::createGrVertexArrayObj,
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000030};
31
32
rmistry@google.comfbfcd562012-08-23 18:09:54 +000033GrDebugGL::GrDebugGL()
robertphillips@google.com670ff9a2012-04-12 19:53:31 +000034 : fPackRowLength(0)
35 , fUnPackRowLength(0)
36 , fCurTextureUnit(0)
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000037 , fArrayBuffer(NULL)
38 , fElementArrayBuffer(NULL)
39 , fFrameBuffer(NULL)
40 , fRenderBuffer(NULL)
41 , fProgram(NULL)
bsalomon@google.comecd84842013-03-01 15:36:02 +000042 , fTexture(NULL)
43 , fVertexArray(NULL) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000044
45 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) {
robertphillips@google.com622a1702012-07-31 19:23:02 +000046
47 fTextureUnits[i] = reinterpret_cast<GrTextureUnitObj *>(
48 createObj(GrDebugGL::kTextureUnit_ObjTypes));
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000049 fTextureUnits[i]->ref();
50
51 fTextureUnits[i]->setNumber(i);
52 }
53}
54
55GrDebugGL::~GrDebugGL() {
56 // unref & delete the texture units first so they don't show up on the leak report
57 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) {
58 fTextureUnits[i]->unref();
59 fTextureUnits[i]->deleteAction();
60 }
61
62 this->report();
63
64 for (int i = 0; i < fObjects.count(); ++i) {
65 delete fObjects[i];
66 }
67 fObjects.reset();
68
69 fArrayBuffer = NULL;
70 fElementArrayBuffer = NULL;
71 fFrameBuffer = NULL;
72 fRenderBuffer = NULL;
73 fProgram = NULL;
74 fTexture = NULL;
bsalomon@google.comecd84842013-03-01 15:36:02 +000075 fVertexArray = NULL;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000076}
77
78GrFakeRefObj *GrDebugGL::findObject(GrGLuint ID, GrObjTypes type) {
79 for (int i = 0; i < fObjects.count(); ++i) {
80 if (fObjects[i]->getID() == ID) { // && fObjects[i]->getType() == type) {
81 // The application shouldn't be accessing objects
rmistry@google.comfbfcd562012-08-23 18:09:54 +000082 // that (as far as OpenGL knows) were already deleted
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000083 GrAlwaysAssert(!fObjects[i]->getDeleted());
84 GrAlwaysAssert(!fObjects[i]->getMarkedForDeletion());
85 return fObjects[i];
86 }
87 }
88
89 return NULL;
90}
91
rmistry@google.comfbfcd562012-08-23 18:09:54 +000092void GrDebugGL::setArrayBuffer(GrBufferObj *arrayBuffer) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000093 if (fArrayBuffer) {
94 // automatically break the binding of the old buffer
95 GrAlwaysAssert(fArrayBuffer->getBound());
96 fArrayBuffer->resetBound();
97
98 GrAlwaysAssert(!fArrayBuffer->getDeleted());
99 fArrayBuffer->unref();
100 }
101
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000102 fArrayBuffer = arrayBuffer;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000103
104 if (fArrayBuffer) {
105 GrAlwaysAssert(!fArrayBuffer->getDeleted());
106 fArrayBuffer->ref();
107
108 GrAlwaysAssert(!fArrayBuffer->getBound());
109 fArrayBuffer->setBound();
110 }
111}
112
bsalomon@google.comecd84842013-03-01 15:36:02 +0000113void GrDebugGL::setVertexArray(GrVertexArrayObj* vertexArray) {
114 if (NULL != vertexArray) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000115 SkASSERT(!vertexArray->getDeleted());
bsalomon@google.comecd84842013-03-01 15:36:02 +0000116 }
117 SkRefCnt_SafeAssign(fVertexArray, vertexArray);
118}
119
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000120void GrDebugGL::setElementArrayBuffer(GrBufferObj *elementArrayBuffer) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000121 if (fElementArrayBuffer) {
122 // automatically break the binding of the old buffer
123 GrAlwaysAssert(fElementArrayBuffer->getBound());
124 fElementArrayBuffer->resetBound();
125
126 GrAlwaysAssert(!fElementArrayBuffer->getDeleted());
127 fElementArrayBuffer->unref();
128 }
129
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000130 fElementArrayBuffer = elementArrayBuffer;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000131
132 if (fElementArrayBuffer) {
133 GrAlwaysAssert(!fElementArrayBuffer->getDeleted());
134 fElementArrayBuffer->ref();
135
136 GrAlwaysAssert(!fElementArrayBuffer->getBound());
137 fElementArrayBuffer->setBound();
138 }
139}
140
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000141void GrDebugGL::setTexture(GrTextureObj *texture) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000142 fTextureUnits[fCurTextureUnit]->setTexture(texture);
143}
144
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000145void GrDebugGL::setFrameBuffer(GrFrameBufferObj *frameBuffer) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000146 if (fFrameBuffer) {
147 GrAlwaysAssert(fFrameBuffer->getBound());
148 fFrameBuffer->resetBound();
149
150 GrAlwaysAssert(!fFrameBuffer->getDeleted());
151 fFrameBuffer->unref();
152 }
153
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000154 fFrameBuffer = frameBuffer;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000155
156 if (fFrameBuffer) {
157 GrAlwaysAssert(!fFrameBuffer->getDeleted());
158 fFrameBuffer->ref();
159
160 GrAlwaysAssert(!fFrameBuffer->getBound());
161 fFrameBuffer->setBound();
162 }
163}
164
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000165void GrDebugGL::setRenderBuffer(GrRenderBufferObj *renderBuffer) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000166 if (fRenderBuffer) {
167 GrAlwaysAssert(fRenderBuffer->getBound());
168 fRenderBuffer->resetBound();
169
170 GrAlwaysAssert(!fRenderBuffer->getDeleted());
171 fRenderBuffer->unref();
172 }
173
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000174 fRenderBuffer = renderBuffer;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000175
176 if (fRenderBuffer) {
177 GrAlwaysAssert(!fRenderBuffer->getDeleted());
178 fRenderBuffer->ref();
179
180 GrAlwaysAssert(!fRenderBuffer->getBound());
181 fRenderBuffer->setBound();
182 }
183}
184
185void GrDebugGL::useProgram(GrProgramObj *program) {
186 if (fProgram) {
187 GrAlwaysAssert(fProgram->getInUse());
188 fProgram->resetInUse();
189
190 GrAlwaysAssert(!fProgram->getDeleted());
191 fProgram->unref();
192 }
193
194 fProgram = program;
195
196 if (fProgram) {
197 GrAlwaysAssert(!fProgram->getDeleted());
198 fProgram->ref();
199
200 GrAlwaysAssert(!fProgram->getInUse());
201 fProgram->setInUse();
202 }
203}
204
205void GrDebugGL::report() const {
206 for (int i = 0; i < fObjects.count(); ++i) {
207 GrAlwaysAssert(0 == fObjects[i]->getRefCount());
208 GrAlwaysAssert(0 < fObjects[i]->getHighRefCount());
209 GrAlwaysAssert(fObjects[i]->getDeleted());
210 }
211}