Minor code cleanup of Debug GL Interface

http://codereview.appspot.com/6032043/



git-svn-id: http://skia.googlecode.com/svn/trunk@3690 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
robertphillips@google.com 2012-04-16 16:24:35 +00:00
Родитель 6853e808a4
Коммит 0dd84a399a
10 изменённых файлов: 92 добавлений и 91 удалений

Просмотреть файл

@ -302,7 +302,6 @@
'../src/gpu/gl/debug/GrGLCreateDebugInterface.cpp', '../src/gpu/gl/debug/GrGLCreateDebugInterface.cpp',
'../src/gpu/gl/debug/GrFakeRefObj.h', '../src/gpu/gl/debug/GrFakeRefObj.h',
'../src/gpu/gl/debug/GrFakeRefObj.cpp',
'../src/gpu/gl/debug/GrBufferObj.h', '../src/gpu/gl/debug/GrBufferObj.h',
'../src/gpu/gl/debug/GrBufferObj.cpp', '../src/gpu/gl/debug/GrBufferObj.cpp',
'../src/gpu/gl/debug/GrFBBindableObj.h', '../src/gpu/gl/debug/GrFBBindableObj.h',

Просмотреть файл

@ -7,3 +7,25 @@
*/ */
#include "GrBufferObj.h" #include "GrBufferObj.h"
void GrBufferObj::allocate(GrGLint size, const GrGLchar *dataPtr) {
GrAlwaysAssert(size >= 0);
// delete pre-existing data
delete[] fDataPtr;
fSize = size;
fDataPtr = new GrGLchar[size];
if (dataPtr) {
memcpy(fDataPtr, dataPtr, fSize);
}
// TODO: w/ no dataPtr the data is unitialized - this could be tracked
}
void GrBufferObj::deleteAction() {
// buffers are automatically unmapped when deleted
this->resetMapped();
this->INHERITED::deleteAction();
}

Просмотреть файл

@ -33,41 +33,22 @@ public:
GrAlwaysAssert(!fMapped); GrAlwaysAssert(!fMapped);
} }
void setMapped() { fMapped = true; } void setMapped() { fMapped = true; }
void resetMapped() { fMapped = false; } void resetMapped() { fMapped = false; }
bool getMapped() const { return fMapped; } bool getMapped() const { return fMapped; }
void setBound() { fBound = true; } void setBound() { fBound = true; }
void resetBound() { fBound = false; } void resetBound() { fBound = false; }
bool getBound() const { return fBound; } bool getBound() const { return fBound; }
void allocate(GrGLint size, const GrGLchar *dataPtr) { void allocate(GrGLint size, const GrGLchar *dataPtr);
GrAlwaysAssert(size >= 0); GrGLint getSize() const { return fSize; }
GrGLchar *getDataPtr() { return fDataPtr; }
// delete pre-existing data
delete[] fDataPtr;
fSize = size;
fDataPtr = new GrGLchar[size];
if (dataPtr) {
memcpy(fDataPtr, dataPtr, fSize);
}
// TODO: w/ no dataPtr the data is unitialized - this could be tracked
}
GrGLint getSize() const { return fSize; }
GrGLchar *getDataPtr() { return fDataPtr; }
GrGLint getUsage() const { return fUsage; }
void setUsage(GrGLint usage) { fUsage = usage; } void setUsage(GrGLint usage) { fUsage = usage; }
GrGLint getUsage() const { return fUsage; }
virtual void deleteAction() SK_OVERRIDE { virtual void deleteAction() SK_OVERRIDE;
// buffers are automatically unmapped when deleted
this->resetMapped();
this->INHERITED::deleteAction();
}
protected: protected:
private: private:
@ -76,7 +57,9 @@ private:
bool fMapped; // is the buffer object mapped via "glMapBuffer"? bool fMapped; // is the buffer object mapped via "glMapBuffer"?
bool fBound; // is the buffer object bound via "glBindBuffer"? bool fBound; // is the buffer object bound via "glBindBuffer"?
GrGLint fSize; // size in bytes GrGLint fSize; // size in bytes
GrGLint fUsage; // one of: GL_STREAM_DRAW, GL_STATIC_DRAW, GL_DYNAMIC_DRAW GrGLint fUsage; // one of: GL_STREAM_DRAW,
// GL_STATIC_DRAW,
// GL_DYNAMIC_DRAW
typedef GrFakeRefObj INHERITED; typedef GrFakeRefObj INHERITED;
}; };

Просмотреть файл

@ -1,9 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrFakeRefObj.h"

Просмотреть файл

@ -10,6 +10,7 @@
#define GrFakeRefObj_DEFINED #define GrFakeRefObj_DEFINED
#include "gl/GrGLInterface.h" #include "gl/GrGLInterface.h"
#include "GrNoncopyable.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// This object is used to track the OpenGL objects. We don't use real // This object is used to track the OpenGL objects. We don't use real
@ -18,7 +19,7 @@
// are tracking in this class are actually OpenGL's references to the objects // are tracking in this class are actually OpenGL's references to the objects
// not "ours" // not "ours"
// Each object also gets a unique globally identifying ID // Each object also gets a unique globally identifying ID
class GrFakeRefObj { class GrFakeRefObj : public GrNoncopyable {
public: public:
GrFakeRefObj() GrFakeRefObj()
: fRef(0) : fRef(0)
@ -26,7 +27,8 @@ public:
, fMarkedForDeletion(false) , fMarkedForDeletion(false)
, fDeleted(false) { , fDeleted(false) {
static int fNextID = 0; // source for globally unique IDs - 0 is reserved! // source for globally unique IDs - 0 is reserved!
static int fNextID = 0;
fID = ++fNextID; fID = ++fNextID;
} }
@ -49,15 +51,15 @@ public:
this->deleteAction(); this->deleteAction();
} }
} }
int getRefCount() const { return fRef; } int getRefCount() const { return fRef; }
int getHighRefCount() const { return fHighRefCount; } int getHighRefCount() const { return fHighRefCount; }
GrGLuint getID() const { return fID; } GrGLuint getID() const { return fID; }
void setMarkedForDeletion() { fMarkedForDeletion = true; } void setMarkedForDeletion() { fMarkedForDeletion = true; }
bool getMarkedForDeletion() const { return fMarkedForDeletion; } bool getMarkedForDeletion() const { return fMarkedForDeletion; }
bool getDeleted() const { return fDeleted; } bool getDeleted() const { return fDeleted; }
// The deleteAction fires if the object has been marked for deletion but // The deleteAction fires if the object has been marked for deletion but
// couldn't be deleted earlier due to refs // couldn't be deleted earlier due to refs
@ -67,16 +69,16 @@ public:
protected: protected:
private: private:
int fRef; int fRef; // ref count
int fHighRefCount; // high water mark of the ref count int fHighRefCount; // high water mark of the ref count
GrGLuint fID; GrGLuint fID; // globally unique ID
bool fMarkedForDeletion; bool fMarkedForDeletion;
// The deleted flag is only set when OpenGL thinks the object is deleted // The deleted flag is only set when OpenGL thinks the object is deleted
// It is obviously still allocated w/in this framework // It is obviously still allocated w/in this framework
bool fDeleted; bool fDeleted;
// setDeleted should only ever appear in the deleteAction method! // setDeleted should only ever appear in the deleteAction method!
void setDeleted() { fDeleted = true; } void setDeleted() { fDeleted = true; }
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -13,31 +13,31 @@
#include "GrFakeRefObj.h" #include "GrFakeRefObj.h"
class GrShaderObj; class GrShaderObj;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class GrProgramObj : public GrFakeRefObj { class GrProgramObj : public GrFakeRefObj {
GR_DEFINE_CREATOR(GrProgramObj); GR_DEFINE_CREATOR(GrProgramObj);
public: public:
GrProgramObj() GrProgramObj()
: GrFakeRefObj() : GrFakeRefObj()
, fInUse(false) {} , fInUse(false) {}
void AttachShader(GrShaderObj *shader); void AttachShader(GrShaderObj *shader);
virtual void deleteAction() SK_OVERRIDE; virtual void deleteAction() SK_OVERRIDE;
// TODO: this flag system won't work w/ multiple contexts! // TODO: this flag system won't work w/ multiple contexts!
void setInUse() { fInUse = true; } void setInUse() { fInUse = true; }
void resetInUse() { fInUse = false; } void resetInUse() { fInUse = false; }
bool getInUse() const { return fInUse; } bool getInUse() const { return fInUse; }
protected: protected:
private: private:
SkTArray<GrShaderObj *> fShaders; SkTArray<GrShaderObj *> fShaders;
bool fInUse; // has this program been activated by a glUseProgram call? bool fInUse; // has this program been activated by a glUseProgram call?
typedef GrFakeRefObj INHERITED; typedef GrFakeRefObj INHERITED;
}; };
#endif // GrProgramObj_DEFINED #endif // GrProgramObj_DEFINED

Просмотреть файл

@ -7,3 +7,8 @@
*/ */
#include "GrShaderObj.h" #include "GrShaderObj.h"
void GrShaderObj::deleteAction() {
this->INHERITED::deleteAction();
}

Просмотреть файл

@ -18,15 +18,12 @@ class GrShaderObj : public GrFakeRefObj {
public: public:
GrShaderObj() GrShaderObj()
: GrFakeRefObj() : GrFakeRefObj()
, fType(GR_GL_VERTEX_SHADER) {} , fType(GR_GL_VERTEX_SHADER) {}
void setType(GrGLenum type) { fType = type; } void setType(GrGLenum type) { fType = type; }
GrGLenum getType() { return fType; } GrGLenum getType() { return fType; }
virtual void deleteAction() SK_OVERRIDE { virtual void deleteAction() SK_OVERRIDE;
this->INHERITED::deleteAction();
}
protected: protected:
private: private:

Просмотреть файл

@ -6,4 +6,9 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "GrTextureObj.h" #include "GrTextureObj.h"
void GrTextureObj::deleteAction() {
this->INHERITED::deleteAction();
}

Просмотреть файл

@ -43,10 +43,7 @@ public:
return 0 != fTextureUnitReferees.count(); return 0 != fTextureUnitReferees.count();
} }
virtual void deleteAction() SK_OVERRIDE { virtual void deleteAction() SK_OVERRIDE;
this->INHERITED::deleteAction();
}
protected: protected: