From 0dd84a399ae8903784eac1c361c08449f822307f Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Mon, 16 Apr 2012 16:24:35 +0000 Subject: [PATCH] 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 --- gyp/gpu.gyp | 1 - src/gpu/gl/debug/GrBufferObj.cpp | 22 +++++++++++++ src/gpu/gl/debug/GrBufferObj.h | 45 ++++++++------------------ src/gpu/gl/debug/GrFakeRefObj.cpp | 9 ------ src/gpu/gl/debug/GrFakeRefObj.h | 24 +++++++------- src/gpu/gl/debug/GrProgramObj.h | 54 +++++++++++++++---------------- src/gpu/gl/debug/GrShaderObj.cpp | 5 +++ src/gpu/gl/debug/GrShaderObj.h | 11 +++---- src/gpu/gl/debug/GrTextureObj.cpp | 7 +++- src/gpu/gl/debug/GrTextureObj.h | 5 +-- 10 files changed, 92 insertions(+), 91 deletions(-) delete mode 100644 src/gpu/gl/debug/GrFakeRefObj.cpp diff --git a/gyp/gpu.gyp b/gyp/gpu.gyp index df8fb7bba..026f3b937 100644 --- a/gyp/gpu.gyp +++ b/gyp/gpu.gyp @@ -302,7 +302,6 @@ '../src/gpu/gl/debug/GrGLCreateDebugInterface.cpp', '../src/gpu/gl/debug/GrFakeRefObj.h', - '../src/gpu/gl/debug/GrFakeRefObj.cpp', '../src/gpu/gl/debug/GrBufferObj.h', '../src/gpu/gl/debug/GrBufferObj.cpp', '../src/gpu/gl/debug/GrFBBindableObj.h', diff --git a/src/gpu/gl/debug/GrBufferObj.cpp b/src/gpu/gl/debug/GrBufferObj.cpp index 0cd4fc806..7d605ebef 100644 --- a/src/gpu/gl/debug/GrBufferObj.cpp +++ b/src/gpu/gl/debug/GrBufferObj.cpp @@ -7,3 +7,25 @@ */ #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(); +} diff --git a/src/gpu/gl/debug/GrBufferObj.h b/src/gpu/gl/debug/GrBufferObj.h index e4cfee2a0..c41cb1fe1 100644 --- a/src/gpu/gl/debug/GrBufferObj.h +++ b/src/gpu/gl/debug/GrBufferObj.h @@ -33,41 +33,22 @@ public: GrAlwaysAssert(!fMapped); } - void setMapped() { fMapped = true; } - void resetMapped() { fMapped = false; } - bool getMapped() const { return fMapped; } + void setMapped() { fMapped = true; } + void resetMapped() { fMapped = false; } + bool getMapped() const { return fMapped; } - void setBound() { fBound = true; } - void resetBound() { fBound = false; } - bool getBound() const { return fBound; } + void setBound() { fBound = true; } + void resetBound() { fBound = false; } + bool getBound() const { return fBound; } - void allocate(GrGLint size, const GrGLchar *dataPtr) { - GrAlwaysAssert(size >= 0); + void allocate(GrGLint size, const GrGLchar *dataPtr); + 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; } + GrGLint getUsage() const { return fUsage; } - virtual void deleteAction() SK_OVERRIDE { - - // buffers are automatically unmapped when deleted - this->resetMapped(); - - this->INHERITED::deleteAction(); - } - + virtual void deleteAction() SK_OVERRIDE; protected: private: @@ -76,7 +57,9 @@ private: bool fMapped; // is the buffer object mapped via "glMapBuffer"? bool fBound; // is the buffer object bound via "glBindBuffer"? 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; }; diff --git a/src/gpu/gl/debug/GrFakeRefObj.cpp b/src/gpu/gl/debug/GrFakeRefObj.cpp deleted file mode 100644 index 508f5c34a..000000000 --- a/src/gpu/gl/debug/GrFakeRefObj.cpp +++ /dev/null @@ -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" \ No newline at end of file diff --git a/src/gpu/gl/debug/GrFakeRefObj.h b/src/gpu/gl/debug/GrFakeRefObj.h index 8dbef9cb5..81fb90c4d 100644 --- a/src/gpu/gl/debug/GrFakeRefObj.h +++ b/src/gpu/gl/debug/GrFakeRefObj.h @@ -10,6 +10,7 @@ #define GrFakeRefObj_DEFINED #include "gl/GrGLInterface.h" +#include "GrNoncopyable.h" //////////////////////////////////////////////////////////////////////////////// // 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 // not "ours" // Each object also gets a unique globally identifying ID -class GrFakeRefObj { +class GrFakeRefObj : public GrNoncopyable { public: GrFakeRefObj() : fRef(0) @@ -26,7 +27,8 @@ public: , fMarkedForDeletion(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; } @@ -49,15 +51,15 @@ public: this->deleteAction(); } } - int getRefCount() const { return fRef; } - int getHighRefCount() const { return fHighRefCount; } + int getRefCount() const { return fRef; } + int getHighRefCount() const { return fHighRefCount; } - GrGLuint getID() const { return fID; } + GrGLuint getID() const { return fID; } - void setMarkedForDeletion() { fMarkedForDeletion = true; } - bool getMarkedForDeletion() const { return fMarkedForDeletion; } + void setMarkedForDeletion() { fMarkedForDeletion = true; } + 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 // couldn't be deleted earlier due to refs @@ -67,16 +69,16 @@ public: protected: private: - int fRef; + int fRef; // ref count int fHighRefCount; // high water mark of the ref count - GrGLuint fID; + GrGLuint fID; // globally unique ID bool fMarkedForDeletion; // The deleted flag is only set when OpenGL thinks the object is deleted // It is obviously still allocated w/in this framework bool fDeleted; // setDeleted should only ever appear in the deleteAction method! - void setDeleted() { fDeleted = true; } + void setDeleted() { fDeleted = true; } }; //////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/gl/debug/GrProgramObj.h b/src/gpu/gl/debug/GrProgramObj.h index d83eab880..eebcc8885 100644 --- a/src/gpu/gl/debug/GrProgramObj.h +++ b/src/gpu/gl/debug/GrProgramObj.h @@ -13,31 +13,31 @@ #include "GrFakeRefObj.h" class GrShaderObj; -//////////////////////////////////////////////////////////////////////////////// -class GrProgramObj : public GrFakeRefObj { - GR_DEFINE_CREATOR(GrProgramObj); - -public: - GrProgramObj() - : GrFakeRefObj() - , fInUse(false) {} - - void AttachShader(GrShaderObj *shader); - - virtual void deleteAction() SK_OVERRIDE; - - // TODO: this flag system won't work w/ multiple contexts! - void setInUse() { fInUse = true; } - void resetInUse() { fInUse = false; } - bool getInUse() const { return fInUse; } - -protected: - -private: - SkTArray fShaders; - bool fInUse; // has this program been activated by a glUseProgram call? - - typedef GrFakeRefObj INHERITED; -}; - +//////////////////////////////////////////////////////////////////////////////// +class GrProgramObj : public GrFakeRefObj { + GR_DEFINE_CREATOR(GrProgramObj); + +public: + GrProgramObj() + : GrFakeRefObj() + , fInUse(false) {} + + void AttachShader(GrShaderObj *shader); + + virtual void deleteAction() SK_OVERRIDE; + + // TODO: this flag system won't work w/ multiple contexts! + void setInUse() { fInUse = true; } + void resetInUse() { fInUse = false; } + bool getInUse() const { return fInUse; } + +protected: + +private: + SkTArray fShaders; + bool fInUse; // has this program been activated by a glUseProgram call? + + typedef GrFakeRefObj INHERITED; +}; + #endif // GrProgramObj_DEFINED diff --git a/src/gpu/gl/debug/GrShaderObj.cpp b/src/gpu/gl/debug/GrShaderObj.cpp index 60c6903ec..8d3caa1e3 100644 --- a/src/gpu/gl/debug/GrShaderObj.cpp +++ b/src/gpu/gl/debug/GrShaderObj.cpp @@ -7,3 +7,8 @@ */ #include "GrShaderObj.h" + +void GrShaderObj::deleteAction() { + + this->INHERITED::deleteAction(); +} diff --git a/src/gpu/gl/debug/GrShaderObj.h b/src/gpu/gl/debug/GrShaderObj.h index ca6ccdc04..200c8b650 100644 --- a/src/gpu/gl/debug/GrShaderObj.h +++ b/src/gpu/gl/debug/GrShaderObj.h @@ -18,15 +18,12 @@ class GrShaderObj : public GrFakeRefObj { public: GrShaderObj() : GrFakeRefObj() - , fType(GR_GL_VERTEX_SHADER) {} + , fType(GR_GL_VERTEX_SHADER) {} - void setType(GrGLenum type) { fType = type; } - GrGLenum getType() { return fType; } + void setType(GrGLenum type) { fType = type; } + GrGLenum getType() { return fType; } - virtual void deleteAction() SK_OVERRIDE { - - this->INHERITED::deleteAction(); - } + virtual void deleteAction() SK_OVERRIDE; protected: private: diff --git a/src/gpu/gl/debug/GrTextureObj.cpp b/src/gpu/gl/debug/GrTextureObj.cpp index 24284d43b..86063fbc9 100644 --- a/src/gpu/gl/debug/GrTextureObj.cpp +++ b/src/gpu/gl/debug/GrTextureObj.cpp @@ -6,4 +6,9 @@ * found in the LICENSE file. */ -#include "GrTextureObj.h" \ No newline at end of file +#include "GrTextureObj.h" + +void GrTextureObj::deleteAction() { + + this->INHERITED::deleteAction(); +} diff --git a/src/gpu/gl/debug/GrTextureObj.h b/src/gpu/gl/debug/GrTextureObj.h index 922c9853c..0443ab7c7 100644 --- a/src/gpu/gl/debug/GrTextureObj.h +++ b/src/gpu/gl/debug/GrTextureObj.h @@ -43,10 +43,7 @@ public: return 0 != fTextureUnitReferees.count(); } - virtual void deleteAction() SK_OVERRIDE { - - this->INHERITED::deleteAction(); - } + virtual void deleteAction() SK_OVERRIDE; protected: