blob: ad06862bd7ea5c0fc4d326524757c3a07f596be7 [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)
bsalomon944bcf02014-07-29 08:01:52 -070043 , fVertexArray(NULL)
44 , fAbandoned(false) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000045
46 for (int i = 0; i < kDefaultMaxTextureUnits; ++i) {
robertphillips@google.com622a1702012-07-31 19:23:02 +000047
48 fTextureUnits[i] = reinterpret_cast<GrTextureUnitObj *>(
49 createObj(GrDebugGL::kTextureUnit_ObjTypes));
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000050 fTextureUnits[i]->ref();
51
52 fTextureUnits[i]->setNumber(i);
53 }
54}
55
56GrDebugGL::~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
70 fArrayBuffer = NULL;
71 fElementArrayBuffer = NULL;
72 fFrameBuffer = NULL;
73 fRenderBuffer = NULL;
74 fProgram = NULL;
75 fTexture = NULL;
bsalomon@google.comecd84842013-03-01 15:36:02 +000076 fVertexArray = NULL;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000077}
78
79GrFakeRefObj *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.comfbfcd562012-08-23 18:09:54 +000083 // that (as far as OpenGL knows) were already deleted
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000084 GrAlwaysAssert(!fObjects[i]->getDeleted());
85 GrAlwaysAssert(!fObjects[i]->getMarkedForDeletion());
86 return fObjects[i];
87 }
88 }
89
90 return NULL;
91}
92
rmistry@google.comfbfcd562012-08-23 18:09:54 +000093void GrDebugGL::setArrayBuffer(GrBufferObj *arrayBuffer) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +000094 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.comfbfcd562012-08-23 18:09:54 +0000103 fArrayBuffer = arrayBuffer;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000104
105 if (fArrayBuffer) {
106 GrAlwaysAssert(!fArrayBuffer->getDeleted());
107 fArrayBuffer->ref();
108
109 GrAlwaysAssert(!fArrayBuffer->getBound());
110 fArrayBuffer->setBound();
111 }
112}
113
bsalomon@google.comecd84842013-03-01 15:36:02 +0000114void GrDebugGL::setVertexArray(GrVertexArrayObj* vertexArray) {
bsalomon49f085d2014-09-05 13:34:00 -0700115 if (vertexArray) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000116 SkASSERT(!vertexArray->getDeleted());
bsalomon@google.comecd84842013-03-01 15:36:02 +0000117 }
118 SkRefCnt_SafeAssign(fVertexArray, vertexArray);
119}
120
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000121void GrDebugGL::setElementArrayBuffer(GrBufferObj *elementArrayBuffer) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000122 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.comfbfcd562012-08-23 18:09:54 +0000131 fElementArrayBuffer = elementArrayBuffer;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000132
133 if (fElementArrayBuffer) {
134 GrAlwaysAssert(!fElementArrayBuffer->getDeleted());
135 fElementArrayBuffer->ref();
136
137 GrAlwaysAssert(!fElementArrayBuffer->getBound());
138 fElementArrayBuffer->setBound();
139 }
140}
141
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000142void GrDebugGL::setTexture(GrTextureObj *texture) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000143 fTextureUnits[fCurTextureUnit]->setTexture(texture);
144}
145
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000146void GrDebugGL::setFrameBuffer(GrFrameBufferObj *frameBuffer) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000147 if (fFrameBuffer) {
148 GrAlwaysAssert(fFrameBuffer->getBound());
149 fFrameBuffer->resetBound();
150
151 GrAlwaysAssert(!fFrameBuffer->getDeleted());
152 fFrameBuffer->unref();
153 }
154
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000155 fFrameBuffer = frameBuffer;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000156
157 if (fFrameBuffer) {
158 GrAlwaysAssert(!fFrameBuffer->getDeleted());
159 fFrameBuffer->ref();
160
161 GrAlwaysAssert(!fFrameBuffer->getBound());
162 fFrameBuffer->setBound();
163 }
164}
165
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000166void GrDebugGL::setRenderBuffer(GrRenderBufferObj *renderBuffer) {
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000167 if (fRenderBuffer) {
168 GrAlwaysAssert(fRenderBuffer->getBound());
169 fRenderBuffer->resetBound();
170
171 GrAlwaysAssert(!fRenderBuffer->getDeleted());
172 fRenderBuffer->unref();
173 }
174
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000175 fRenderBuffer = renderBuffer;
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000176
177 if (fRenderBuffer) {
178 GrAlwaysAssert(!fRenderBuffer->getDeleted());
179 fRenderBuffer->ref();
180
181 GrAlwaysAssert(!fRenderBuffer->getBound());
182 fRenderBuffer->setBound();
183 }
184}
185
186void 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
206void GrDebugGL::report() const {
207 for (int i = 0; i < fObjects.count(); ++i) {
bsalomon944bcf02014-07-29 08:01:52 -0700208 if (!fAbandoned) {
209 GrAlwaysAssert(0 == fObjects[i]->getRefCount());
210 GrAlwaysAssert(fObjects[i]->getDeleted());
211 }
robertphillips@google.comdd743fe2012-04-05 14:40:53 +0000212 }
213}