Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: src/gpu/gl/GrGLCreateNullInterface.cpp

Issue 19678010: Improve null gpu's memory handling (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: fix compiler warning Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/gmmain.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLCreateNullInterface.cpp
===================================================================
--- src/gpu/gl/GrGLCreateNullInterface.cpp (revision 10138)
+++ src/gpu/gl/GrGLCreateNullInterface.cpp (working copy)
@@ -15,13 +15,90 @@
namespace { // added to suppress 'no previous prototype' warning
+class GrBufferObj {
+public:
+ GrBufferObj() : fDataPtr(NULL), fSize(0), fMapped(false) {
+ static GrGLuint gNextID = 0; // 0 is reserved
+
+ fID = ++gNextID;
+ }
+ ~GrBufferObj() { SkDELETE_ARRAY(fDataPtr); }
+
+ void allocate(GrGLint size, const GrGLchar *dataPtr) {
tfarina 2013/07/18 16:30:21 nit: GrGLChar*
robertphillips 2013/07/18 16:59:31 Done.
+ if (NULL != fDataPtr) {
+ GrAssert(0 != fSize);
+ SkDELETE_ARRAY(fDataPtr);
+ }
+
+ fSize = size;
+ fDataPtr = SkNEW_ARRAY(char, size);
+ }
+
+ GrGLuint id() const { return fID; }
+ GrGLchar *dataPtr() { return fDataPtr; }
tfarina 2013/07/18 16:30:21 nit: GrGLChar*
robertphillips 2013/07/18 16:59:31 Done.
+ GrGLint size() const { return fSize; }
+
+ void setMapped(bool mapped) { fMapped = mapped; }
+ bool mapped() const { return fMapped; }
+
+private:
+ GrGLuint fID;
+ GrGLchar* fDataPtr;
+ GrGLint fSize; // size in bytes
+ bool fMapped;
+};
+
+// In debug builds we do asserts that ensure we agree with GL about when a buffer
+// is mapped.
+static SkTDArray<GrBufferObj*> gBuffers;
+static GrGLuint gCurrArrayBuffer;
+static GrGLuint gCurrElementArrayBuffer;
+
GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {}
GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shader) {}
GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {}
GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {}
GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture) {}
GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {}
-GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage) {}
+
+GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenBuffers(GrGLsizei n, GrGLuint* ids) {
+
+ for (int i = 0; i < n; ++i) {
+ GrBufferObj* buffer = SkNEW(GrBufferObj);
+ // This code relies on the id of the buffer being 1 more then its
+ // position in 'gBuffers'
+ GrAssert(gBuffers.count() == (int)buffer->id() - 1);
+ *gBuffers.append() = buffer;
+ ids[i] = buffer->id();
+ }
+}
+
+GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target,
+ GrGLsizeiptr size,
+ const GrGLvoid* data,
+ GrGLenum usage) {
+ GrGLuint id = 0;
+
+ switch (target) {
+ case GR_GL_ARRAY_BUFFER:
+ id = gCurrArrayBuffer;
+ break;
+ case GR_GL_ELEMENT_ARRAY_BUFFER:
+ id = gCurrElementArrayBuffer;
+ break;
+ default:
+ GrCrash("Unexpected target to nullGLBufferData");
+ break;
+ }
+
+ if (id > 0) {
+ GrBufferObj* buffer = gBuffers[id-1];
+ GrAssert(NULL != buffer && buffer->id() == id);
+
+ buffer->allocate(size, (const GrGLchar*) data);
+ }
+}
+
GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {}
GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {}
GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {}
@@ -34,12 +111,12 @@
GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {}
GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() {
- static int gCurrID = 0;
+ static GrGLuint gCurrID = 0;
return ++gCurrID;
}
GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) {
- static int gCurrID = 0;
+ static GrGLuint gCurrID = 0;
return ++gCurrID;
}
@@ -47,12 +124,6 @@
GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) {
}
-// In debug builds we do asserts that ensure we agree with GL about when a buffer
-// is mapped.
-static SkTDArray<GrGLuint> gMappedBuffers;
-static GrGLuint gCurrArrayBuffer;
-static GrGLuint gCurrElementArrayBuffer;
-
GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) {
switch (target) {
case GR_GL_ARRAY_BUFFER:
@@ -73,75 +144,82 @@
if (ids[i] == gCurrElementArrayBuffer) {
gCurrElementArrayBuffer = 0;
}
- for (int j = 0; j < gMappedBuffers.count(); ++j) {
- if (gMappedBuffers[j] == ids[i]) {
- gMappedBuffers.remove(j);
- // don't break b/c we didn't check for dupes on insert
- --j;
- }
- }
+
+ GrBufferObj* buffer = gBuffers[ids[i]-1];
+ GrAssert(NULL != buffer && ids[i] == buffer->id());
+
+ SkDELETE(buffer);
+ gBuffers[ids[i]-1] = NULL;
}
}
GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) {
- // We just reserve 32MB of RAM for all locks and hope its big enough
- static SkAutoMalloc gBufferData(32 * (1 << 20));
- GrGLuint buf = 0;
+
+ GrGLuint id = 0;
switch (target) {
case GR_GL_ARRAY_BUFFER:
- buf = gCurrArrayBuffer;
+ id = gCurrArrayBuffer;
break;
case GR_GL_ELEMENT_ARRAY_BUFFER:
- buf = gCurrElementArrayBuffer;
+ id = gCurrElementArrayBuffer;
break;
}
- if (buf) {
- *gMappedBuffers.append() = buf;
+
+ if (id > 0) {
+ GrBufferObj* buffer = gBuffers[id-1];
+ GrAssert(NULL != buffer && buffer->id() == id);
+
+ GrAssert(!buffer->mapped());
+ buffer->setMapped(true);
+ return buffer->dataPtr();
}
- return gBufferData.get();
+
+ GrAssert(false);
+ return NULL; // no buffer bound to target
}
GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) {
- GrGLuint buf = 0;
+ GrGLuint id = 0;
switch (target) {
case GR_GL_ARRAY_BUFFER:
- buf = gCurrArrayBuffer;
+ id = gCurrArrayBuffer;
break;
case GR_GL_ELEMENT_ARRAY_BUFFER:
- buf = gCurrElementArrayBuffer;
+ id = gCurrElementArrayBuffer;
break;
}
- if (buf) {
- for (int i = 0; i < gMappedBuffers.count(); ++i) {
- if (gMappedBuffers[i] == buf) {
- gMappedBuffers.remove(i);
- // don't break b/c we didn't check for dupes on insert
- --i;
- }
- }
+ if (id > 0) {
+ GrBufferObj* buffer = gBuffers[id-1];
+ GrAssert(NULL != buffer && buffer->id() == id);
+ GrAssert(buffer->mapped());
+
+ buffer->setMapped(false);
+ return GR_GL_TRUE;
}
- return GR_GL_TRUE;
+
+ GrAlwaysAssert(false);
+ return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
}
GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) {
switch (pname) {
case GR_GL_BUFFER_MAPPED: {
*params = GR_GL_FALSE;
- GrGLuint buf = 0;
+ GrGLuint id = 0;
switch (target) {
case GR_GL_ARRAY_BUFFER:
- buf = gCurrArrayBuffer;
+ id = gCurrArrayBuffer;
break;
case GR_GL_ELEMENT_ARRAY_BUFFER:
- buf = gCurrElementArrayBuffer;
+ id = gCurrElementArrayBuffer;
break;
}
- if (buf) {
- for (int i = 0; i < gMappedBuffers.count(); ++i) {
- if (gMappedBuffers[i] == buf) {
- *params = GR_GL_TRUE;
- break;
- }
+ if (id > 0) {
+ GrBufferObj* buffer = gBuffers[id-1];
+ GrAssert(NULL != buffer && buffer->id() == id);
+
+ if (buffer->mapped()) {
+ *params = GR_GL_TRUE;
}
}
break; }
@@ -202,7 +280,7 @@
interface->fFinish = noOpGLFinish;
interface->fFlush = noOpGLFlush;
interface->fFrontFace = noOpGLFrontFace;
- interface->fGenBuffers = noOpGLGenIds;
+ interface->fGenBuffers = nullGLGenBuffers;
interface->fGenQueries = noOpGLGenIds;
interface->fGenTextures = noOpGLGenIds;
interface->fGenVertexArrays = noOpGLGenIds;
« no previous file with comments | « gm/gmmain.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698