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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/gl/debug/GrDebugGL.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,211 @@
     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 +#include "GrDebugGL.h"
    1.13 +#include "GrTextureObj.h"
    1.14 +#include "GrBufferObj.h"
    1.15 +#include "GrRenderBufferObj.h"
    1.16 +#include "GrFrameBufferObj.h"
    1.17 +#include "GrShaderObj.h"
    1.18 +#include "GrProgramObj.h"
    1.19 +#include "GrTextureUnitObj.h"
    1.20 +#include "GrVertexArrayObj.h"
    1.21 +
    1.22 +GrDebugGL* GrDebugGL::gObj = NULL;
    1.23 +int GrDebugGL::gStaticRefCount = 0;
    1.24 +GrDebugGL::Create GrDebugGL::gFactoryFunc[kObjTypeCount] = {
    1.25 +    GrTextureObj::createGrTextureObj,
    1.26 +    GrBufferObj::createGrBufferObj,
    1.27 +    GrRenderBufferObj::createGrRenderBufferObj,
    1.28 +    GrFrameBufferObj::createGrFrameBufferObj,
    1.29 +    GrShaderObj::createGrShaderObj,
    1.30 +    GrProgramObj::createGrProgramObj,
    1.31 +    GrTextureUnitObj::createGrTextureUnitObj,
    1.32 +    GrVertexArrayObj::createGrVertexArrayObj,
    1.33 +};
    1.34 +
    1.35 +
    1.36 +GrDebugGL::GrDebugGL()
    1.37 +    : fPackRowLength(0)
    1.38 +    , fUnPackRowLength(0)
    1.39 +    , fCurTextureUnit(0)
    1.40 +    , fArrayBuffer(NULL)
    1.41 +    , fElementArrayBuffer(NULL)
    1.42 +    , fFrameBuffer(NULL)
    1.43 +    , fRenderBuffer(NULL)
    1.44 +    , fProgram(NULL)
    1.45 +    , fTexture(NULL)
    1.46 +    , fVertexArray(NULL)  {
    1.47 +
    1.48 +    for (int i = 0; i < kDefaultMaxTextureUnits; ++i) {
    1.49 +
    1.50 +        fTextureUnits[i] = reinterpret_cast<GrTextureUnitObj *>(
    1.51 +                            createObj(GrDebugGL::kTextureUnit_ObjTypes));
    1.52 +        fTextureUnits[i]->ref();
    1.53 +
    1.54 +        fTextureUnits[i]->setNumber(i);
    1.55 +    }
    1.56 +}
    1.57 +
    1.58 +GrDebugGL::~GrDebugGL() {
    1.59 +    // unref & delete the texture units first so they don't show up on the leak report
    1.60 +    for (int i = 0; i < kDefaultMaxTextureUnits; ++i) {
    1.61 +        fTextureUnits[i]->unref();
    1.62 +        fTextureUnits[i]->deleteAction();
    1.63 +    }
    1.64 +
    1.65 +    this->report();
    1.66 +
    1.67 +    for (int i = 0; i < fObjects.count(); ++i) {
    1.68 +        delete fObjects[i];
    1.69 +    }
    1.70 +    fObjects.reset();
    1.71 +
    1.72 +    fArrayBuffer = NULL;
    1.73 +    fElementArrayBuffer = NULL;
    1.74 +    fFrameBuffer = NULL;
    1.75 +    fRenderBuffer = NULL;
    1.76 +    fProgram = NULL;
    1.77 +    fTexture = NULL;
    1.78 +    fVertexArray = NULL;
    1.79 +}
    1.80 +
    1.81 +GrFakeRefObj *GrDebugGL::findObject(GrGLuint ID, GrObjTypes type) {
    1.82 +    for (int i = 0; i < fObjects.count(); ++i) {
    1.83 +        if (fObjects[i]->getID() == ID) { // && fObjects[i]->getType() == type) {
    1.84 +            // The application shouldn't be accessing objects
    1.85 +            // that (as far as OpenGL knows) were already deleted
    1.86 +            GrAlwaysAssert(!fObjects[i]->getDeleted());
    1.87 +            GrAlwaysAssert(!fObjects[i]->getMarkedForDeletion());
    1.88 +            return fObjects[i];
    1.89 +        }
    1.90 +    }
    1.91 +
    1.92 +    return NULL;
    1.93 +}
    1.94 +
    1.95 +void GrDebugGL::setArrayBuffer(GrBufferObj *arrayBuffer) {
    1.96 +    if (fArrayBuffer) {
    1.97 +        // automatically break the binding of the old buffer
    1.98 +        GrAlwaysAssert(fArrayBuffer->getBound());
    1.99 +        fArrayBuffer->resetBound();
   1.100 +
   1.101 +        GrAlwaysAssert(!fArrayBuffer->getDeleted());
   1.102 +        fArrayBuffer->unref();
   1.103 +    }
   1.104 +
   1.105 +    fArrayBuffer = arrayBuffer;
   1.106 +
   1.107 +    if (fArrayBuffer) {
   1.108 +        GrAlwaysAssert(!fArrayBuffer->getDeleted());
   1.109 +        fArrayBuffer->ref();
   1.110 +
   1.111 +        GrAlwaysAssert(!fArrayBuffer->getBound());
   1.112 +        fArrayBuffer->setBound();
   1.113 +    }
   1.114 +}
   1.115 +
   1.116 +void GrDebugGL::setVertexArray(GrVertexArrayObj* vertexArray) {
   1.117 +    if (NULL != vertexArray) {
   1.118 +        SkASSERT(!vertexArray->getDeleted());
   1.119 +    }
   1.120 +    SkRefCnt_SafeAssign(fVertexArray, vertexArray);
   1.121 +}
   1.122 +
   1.123 +void GrDebugGL::setElementArrayBuffer(GrBufferObj *elementArrayBuffer) {
   1.124 +    if (fElementArrayBuffer) {
   1.125 +        // automatically break the binding of the old buffer
   1.126 +        GrAlwaysAssert(fElementArrayBuffer->getBound());
   1.127 +        fElementArrayBuffer->resetBound();
   1.128 +
   1.129 +        GrAlwaysAssert(!fElementArrayBuffer->getDeleted());
   1.130 +        fElementArrayBuffer->unref();
   1.131 +    }
   1.132 +
   1.133 +    fElementArrayBuffer = elementArrayBuffer;
   1.134 +
   1.135 +    if (fElementArrayBuffer) {
   1.136 +        GrAlwaysAssert(!fElementArrayBuffer->getDeleted());
   1.137 +        fElementArrayBuffer->ref();
   1.138 +
   1.139 +        GrAlwaysAssert(!fElementArrayBuffer->getBound());
   1.140 +        fElementArrayBuffer->setBound();
   1.141 +    }
   1.142 +}
   1.143 +
   1.144 +void GrDebugGL::setTexture(GrTextureObj *texture)  {
   1.145 +    fTextureUnits[fCurTextureUnit]->setTexture(texture);
   1.146 +}
   1.147 +
   1.148 +void GrDebugGL::setFrameBuffer(GrFrameBufferObj *frameBuffer)  {
   1.149 +    if (fFrameBuffer) {
   1.150 +        GrAlwaysAssert(fFrameBuffer->getBound());
   1.151 +        fFrameBuffer->resetBound();
   1.152 +
   1.153 +        GrAlwaysAssert(!fFrameBuffer->getDeleted());
   1.154 +        fFrameBuffer->unref();
   1.155 +    }
   1.156 +
   1.157 +    fFrameBuffer = frameBuffer;
   1.158 +
   1.159 +    if (fFrameBuffer) {
   1.160 +        GrAlwaysAssert(!fFrameBuffer->getDeleted());
   1.161 +        fFrameBuffer->ref();
   1.162 +
   1.163 +        GrAlwaysAssert(!fFrameBuffer->getBound());
   1.164 +        fFrameBuffer->setBound();
   1.165 +    }
   1.166 +}
   1.167 +
   1.168 +void GrDebugGL::setRenderBuffer(GrRenderBufferObj *renderBuffer)  {
   1.169 +    if (fRenderBuffer) {
   1.170 +        GrAlwaysAssert(fRenderBuffer->getBound());
   1.171 +        fRenderBuffer->resetBound();
   1.172 +
   1.173 +        GrAlwaysAssert(!fRenderBuffer->getDeleted());
   1.174 +        fRenderBuffer->unref();
   1.175 +    }
   1.176 +
   1.177 +    fRenderBuffer = renderBuffer;
   1.178 +
   1.179 +    if (fRenderBuffer) {
   1.180 +        GrAlwaysAssert(!fRenderBuffer->getDeleted());
   1.181 +        fRenderBuffer->ref();
   1.182 +
   1.183 +        GrAlwaysAssert(!fRenderBuffer->getBound());
   1.184 +        fRenderBuffer->setBound();
   1.185 +    }
   1.186 +}
   1.187 +
   1.188 +void GrDebugGL::useProgram(GrProgramObj *program) {
   1.189 +    if (fProgram) {
   1.190 +        GrAlwaysAssert(fProgram->getInUse());
   1.191 +        fProgram->resetInUse();
   1.192 +
   1.193 +        GrAlwaysAssert(!fProgram->getDeleted());
   1.194 +        fProgram->unref();
   1.195 +    }
   1.196 +
   1.197 +    fProgram = program;
   1.198 +
   1.199 +    if (fProgram) {
   1.200 +        GrAlwaysAssert(!fProgram->getDeleted());
   1.201 +        fProgram->ref();
   1.202 +
   1.203 +        GrAlwaysAssert(!fProgram->getInUse());
   1.204 +        fProgram->setInUse();
   1.205 +    }
   1.206 +}
   1.207 +
   1.208 +void GrDebugGL::report() const {
   1.209 +    for (int i = 0; i < fObjects.count(); ++i) {
   1.210 +        GrAlwaysAssert(0 == fObjects[i]->getRefCount());
   1.211 +        GrAlwaysAssert(0 < fObjects[i]->getHighRefCount());
   1.212 +        GrAlwaysAssert(fObjects[i]->getDeleted());
   1.213 +    }
   1.214 +}

mercurial