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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gm/gmmain.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #include "gl/GrGLInterface.h" 9 #include "gl/GrGLInterface.h"
10 #include "GrGLDefines.h" 10 #include "GrGLDefines.h"
11 #include "SkTDArray.h" 11 #include "SkTDArray.h"
12 #include "GrGLNoOpInterface.h" 12 #include "GrGLNoOpInterface.h"
13 13
14 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface). 14 // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface).
15 15
16 namespace { // added to suppress 'no previous prototype' warning 16 namespace { // added to suppress 'no previous prototype' warning
17 17
18 class GrBufferObj {
19 public:
20 GrBufferObj() : fDataPtr(NULL), fSize(0), fMapped(false) {
21 static GrGLuint gNextID = 0; // 0 is reserved
22
23 fID = ++gNextID;
24 }
25 ~GrBufferObj() { SkDELETE_ARRAY(fDataPtr); }
26
27 void allocate(GrGLint size, const GrGLchar *dataPtr) {
tfarina 2013/07/18 16:30:21 nit: GrGLChar*
robertphillips 2013/07/18 16:59:31 Done.
28 if (NULL != fDataPtr) {
29 GrAssert(0 != fSize);
30 SkDELETE_ARRAY(fDataPtr);
31 }
32
33 fSize = size;
34 fDataPtr = SkNEW_ARRAY(char, size);
35 }
36
37 GrGLuint id() const { return fID; }
38 GrGLchar *dataPtr() { return fDataPtr; }
tfarina 2013/07/18 16:30:21 nit: GrGLChar*
robertphillips 2013/07/18 16:59:31 Done.
39 GrGLint size() const { return fSize; }
40
41 void setMapped(bool mapped) { fMapped = mapped; }
42 bool mapped() const { return fMapped; }
43
44 private:
45 GrGLuint fID;
46 GrGLchar* fDataPtr;
47 GrGLint fSize; // size in bytes
48 bool fMapped;
49 };
50
51 // In debug builds we do asserts that ensure we agree with GL about when a buffe r
52 // is mapped.
53 static SkTDArray<GrBufferObj*> gBuffers;
54 static GrGLuint gCurrArrayBuffer;
55 static GrGLuint gCurrElementArrayBuffer;
56
18 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} 57 GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {}
19 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade r) {} 58 GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shade r) {}
20 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {} 59 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {}
21 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {} 60 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {}
22 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture ) {} 61 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture ) {}
23 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {} 62 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {}
24 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target, GrGLsizeiptr size , const GrGLvoid* data, GrGLenum usage) {} 63
64 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenBuffers(GrGLsizei n, GrGLuint* ids) {
65
66 for (int i = 0; i < n; ++i) {
67 GrBufferObj* buffer = SkNEW(GrBufferObj);
68 // This code relies on the id of the buffer being 1 more then its
69 // position in 'gBuffers'
70 GrAssert(gBuffers.count() == (int)buffer->id() - 1);
71 *gBuffers.append() = buffer;
72 ids[i] = buffer->id();
73 }
74 }
75
76 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target,
77 GrGLsizeiptr size,
78 const GrGLvoid* data,
79 GrGLenum usage) {
80 GrGLuint id = 0;
81
82 switch (target) {
83 case GR_GL_ARRAY_BUFFER:
84 id = gCurrArrayBuffer;
85 break;
86 case GR_GL_ELEMENT_ARRAY_BUFFER:
87 id = gCurrElementArrayBuffer;
88 break;
89 default:
90 GrCrash("Unexpected target to nullGLBufferData");
91 break;
92 }
93
94 if (id > 0) {
95 GrBufferObj* buffer = gBuffers[id-1];
96 GrAssert(NULL != buffer && buffer->id() == id);
97
98 buffer->allocate(size, (const GrGLchar*) data);
99 }
100 }
101
25 GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {} 102 GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {}
26 GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei wi dth, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {} 103 GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei wi dth, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {}
27 GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {} 104 GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {}
28 GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei widt h, GrGLsizei height) {} 105 GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei widt h, GrGLsizei height) {}
29 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint fra mebuffer) {} 106 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint fra mebuffer) {}
30 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint re nderbuffer) {} 107 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint re nderbuffer) {}
31 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuin t *framebuffers) {} 108 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuin t *framebuffers) {}
32 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLui nt *renderbuffers) {} 109 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLui nt *renderbuffers) {}
33 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGL enum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {} 110 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGL enum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {}
34 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenu m attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {} 111 GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenu m attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {}
35 112
36 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() { 113 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() {
37 static int gCurrID = 0; 114 static GrGLuint gCurrID = 0;
38 return ++gCurrID; 115 return ++gCurrID;
39 } 116 }
40 117
41 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) { 118 GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) {
42 static int gCurrID = 0; 119 static GrGLuint gCurrID = 0;
43 return ++gCurrID; 120 return ++gCurrID;
44 } 121 }
45 122
46 // same delete used for shaders and programs 123 // same delete used for shaders and programs
47 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) { 124 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) {
48 } 125 }
49 126
50 // In debug builds we do asserts that ensure we agree with GL about when a buffe r
51 // is mapped.
52 static SkTDArray<GrGLuint> gMappedBuffers;
53 static GrGLuint gCurrArrayBuffer;
54 static GrGLuint gCurrElementArrayBuffer;
55
56 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) { 127 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) {
57 switch (target) { 128 switch (target) {
58 case GR_GL_ARRAY_BUFFER: 129 case GR_GL_ARRAY_BUFFER:
59 gCurrArrayBuffer = buffer; 130 gCurrArrayBuffer = buffer;
60 break; 131 break;
61 case GR_GL_ELEMENT_ARRAY_BUFFER: 132 case GR_GL_ELEMENT_ARRAY_BUFFER:
62 gCurrElementArrayBuffer = buffer; 133 gCurrElementArrayBuffer = buffer;
63 break; 134 break;
64 } 135 }
65 } 136 }
66 137
67 // deleting a bound buffer has the side effect of binding 0 138 // deleting a bound buffer has the side effect of binding 0
68 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* id s) { 139 GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* id s) {
69 for (int i = 0; i < n; ++i) { 140 for (int i = 0; i < n; ++i) {
70 if (ids[i] == gCurrArrayBuffer) { 141 if (ids[i] == gCurrArrayBuffer) {
71 gCurrArrayBuffer = 0; 142 gCurrArrayBuffer = 0;
72 } 143 }
73 if (ids[i] == gCurrElementArrayBuffer) { 144 if (ids[i] == gCurrElementArrayBuffer) {
74 gCurrElementArrayBuffer = 0; 145 gCurrElementArrayBuffer = 0;
75 } 146 }
76 for (int j = 0; j < gMappedBuffers.count(); ++j) { 147
77 if (gMappedBuffers[j] == ids[i]) { 148 GrBufferObj* buffer = gBuffers[ids[i]-1];
78 gMappedBuffers.remove(j); 149 GrAssert(NULL != buffer && ids[i] == buffer->id());
79 // don't break b/c we didn't check for dupes on insert 150
80 --j; 151 SkDELETE(buffer);
81 } 152 gBuffers[ids[i]-1] = NULL;
82 }
83 } 153 }
84 } 154 }
85 155
86 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) { 156 GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) {
87 // We just reserve 32MB of RAM for all locks and hope its big enough 157
88 static SkAutoMalloc gBufferData(32 * (1 << 20)); 158 GrGLuint id = 0;
89 GrGLuint buf = 0;
90 switch (target) { 159 switch (target) {
91 case GR_GL_ARRAY_BUFFER: 160 case GR_GL_ARRAY_BUFFER:
92 buf = gCurrArrayBuffer; 161 id = gCurrArrayBuffer;
93 break; 162 break;
94 case GR_GL_ELEMENT_ARRAY_BUFFER: 163 case GR_GL_ELEMENT_ARRAY_BUFFER:
95 buf = gCurrElementArrayBuffer; 164 id = gCurrElementArrayBuffer;
96 break; 165 break;
97 } 166 }
98 if (buf) { 167
99 *gMappedBuffers.append() = buf; 168 if (id > 0) {
169 GrBufferObj* buffer = gBuffers[id-1];
170 GrAssert(NULL != buffer && buffer->id() == id);
171
172 GrAssert(!buffer->mapped());
173 buffer->setMapped(true);
174 return buffer->dataPtr();
100 } 175 }
101 return gBufferData.get(); 176
177 GrAssert(false);
178 return NULL; // no buffer bound to target
102 } 179 }
103 180
104 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { 181 GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) {
105 GrGLuint buf = 0; 182 GrGLuint id = 0;
106 switch (target) { 183 switch (target) {
107 case GR_GL_ARRAY_BUFFER: 184 case GR_GL_ARRAY_BUFFER:
108 buf = gCurrArrayBuffer; 185 id = gCurrArrayBuffer;
109 break; 186 break;
110 case GR_GL_ELEMENT_ARRAY_BUFFER: 187 case GR_GL_ELEMENT_ARRAY_BUFFER:
111 buf = gCurrElementArrayBuffer; 188 id = gCurrElementArrayBuffer;
112 break; 189 break;
113 } 190 }
114 if (buf) { 191 if (id > 0) {
115 for (int i = 0; i < gMappedBuffers.count(); ++i) { 192 GrBufferObj* buffer = gBuffers[id-1];
116 if (gMappedBuffers[i] == buf) { 193 GrAssert(NULL != buffer && buffer->id() == id);
117 gMappedBuffers.remove(i); 194 GrAssert(buffer->mapped());
118 // don't break b/c we didn't check for dupes on insert 195
119 --i; 196 buffer->setMapped(false);
120 } 197 return GR_GL_TRUE;
121 }
122 } 198 }
123 return GR_GL_TRUE; 199
200 GrAlwaysAssert(false);
201 return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
124 } 202 }
125 203
126 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu m pname, GrGLint* params) { 204 GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenu m pname, GrGLint* params) {
127 switch (pname) { 205 switch (pname) {
128 case GR_GL_BUFFER_MAPPED: { 206 case GR_GL_BUFFER_MAPPED: {
129 *params = GR_GL_FALSE; 207 *params = GR_GL_FALSE;
130 GrGLuint buf = 0; 208 GrGLuint id = 0;
131 switch (target) { 209 switch (target) {
132 case GR_GL_ARRAY_BUFFER: 210 case GR_GL_ARRAY_BUFFER:
133 buf = gCurrArrayBuffer; 211 id = gCurrArrayBuffer;
134 break; 212 break;
135 case GR_GL_ELEMENT_ARRAY_BUFFER: 213 case GR_GL_ELEMENT_ARRAY_BUFFER:
136 buf = gCurrElementArrayBuffer; 214 id = gCurrElementArrayBuffer;
137 break; 215 break;
138 } 216 }
139 if (buf) { 217 if (id > 0) {
140 for (int i = 0; i < gMappedBuffers.count(); ++i) { 218 GrBufferObj* buffer = gBuffers[id-1];
141 if (gMappedBuffers[i] == buf) { 219 GrAssert(NULL != buffer && buffer->id() == id);
142 *params = GR_GL_TRUE; 220
143 break; 221 if (buffer->mapped()) {
144 } 222 *params = GR_GL_TRUE;
145 } 223 }
146 } 224 }
147 break; } 225 break; }
148 default: 226 default:
149 GrCrash("Unexpected pname to GetBufferParamateriv"); 227 GrCrash("Unexpected pname to GetBufferParamateriv");
150 break; 228 break;
151 } 229 }
152 }; 230 };
153 231
154 } // end anonymous namespace 232 } // end anonymous namespace
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 interface->fDrawArrays = noOpGLDrawArrays; 273 interface->fDrawArrays = noOpGLDrawArrays;
196 interface->fDrawBuffer = noOpGLDrawBuffer; 274 interface->fDrawBuffer = noOpGLDrawBuffer;
197 interface->fDrawBuffers = noOpGLDrawBuffers; 275 interface->fDrawBuffers = noOpGLDrawBuffers;
198 interface->fDrawElements = noOpGLDrawElements; 276 interface->fDrawElements = noOpGLDrawElements;
199 interface->fEnable = noOpGLEnable; 277 interface->fEnable = noOpGLEnable;
200 interface->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray; 278 interface->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray;
201 interface->fEndQuery = noOpGLEndQuery; 279 interface->fEndQuery = noOpGLEndQuery;
202 interface->fFinish = noOpGLFinish; 280 interface->fFinish = noOpGLFinish;
203 interface->fFlush = noOpGLFlush; 281 interface->fFlush = noOpGLFlush;
204 interface->fFrontFace = noOpGLFrontFace; 282 interface->fFrontFace = noOpGLFrontFace;
205 interface->fGenBuffers = noOpGLGenIds; 283 interface->fGenBuffers = nullGLGenBuffers;
206 interface->fGenQueries = noOpGLGenIds; 284 interface->fGenQueries = noOpGLGenIds;
207 interface->fGenTextures = noOpGLGenIds; 285 interface->fGenTextures = noOpGLGenIds;
208 interface->fGenVertexArrays = noOpGLGenIds; 286 interface->fGenVertexArrays = noOpGLGenIds;
209 interface->fGetBufferParameteriv = nullGLGetBufferParameteriv; 287 interface->fGetBufferParameteriv = nullGLGetBufferParameteriv;
210 interface->fGetError = noOpGLGetError; 288 interface->fGetError = noOpGLGetError;
211 interface->fGetIntegerv = noOpGLGetIntegerv; 289 interface->fGetIntegerv = noOpGLGetIntegerv;
212 interface->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v; 290 interface->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v;
213 interface->fGetQueryObjectiv = noOpGLGetQueryObjectiv; 291 interface->fGetQueryObjectiv = noOpGLGetQueryObjectiv;
214 interface->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v; 292 interface->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v;
215 interface->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv; 293 interface->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 interface->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMu ltisample; 358 interface->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMu ltisample;
281 interface->fBlitFramebuffer = noOpGLBlitFramebuffer; 359 interface->fBlitFramebuffer = noOpGLBlitFramebuffer;
282 interface->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFram ebuffer; 360 interface->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFram ebuffer;
283 interface->fMapBuffer = nullGLMapBuffer; 361 interface->fMapBuffer = nullGLMapBuffer;
284 interface->fUnmapBuffer = nullGLUnmapBuffer; 362 interface->fUnmapBuffer = nullGLUnmapBuffer;
285 interface->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationInde xed; 363 interface->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationInde xed;
286 } 364 }
287 glInterface.get()->ref(); 365 glInterface.get()->ref();
288 return glInterface.get(); 366 return glInterface.get();
289 } 367 }
OLDNEW
« 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