OLD | NEW |
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 "GrGLTestInterface.h" | 10 #include "GrGLTestInterface.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 private: | 40 private: |
41 GrGLuint fID; | 41 GrGLuint fID; |
42 GrGLchar* fDataPtr; | 42 GrGLchar* fDataPtr; |
43 GrGLsizeiptr fSize; // size in bytes | 43 GrGLsizeiptr fSize; // size in bytes |
44 bool fMapped; | 44 bool fMapped; |
45 }; | 45 }; |
46 | 46 |
47 // This class maintains a sparsely populated array of buffer pointers. | 47 // This class maintains a sparsely populated array of buffer pointers. |
48 class BufferManager { | 48 class BufferManager { |
49 public: | 49 public: |
50 BufferManager() : fFreeListHead(kFreeListEnd) {} | 50 BufferManager() : fFreeListHead(kFreeListEnd) { |
| 51 *fBuffers.append() = nullptr; // 0 is not a valid GL buffer id. |
| 52 } |
51 | 53 |
52 ~BufferManager() { | 54 ~BufferManager() { |
53 // nullptr out the entries that are really free list links rather than p
trs before deleting. | 55 // nullptr out the entries that are really free list links rather than p
trs before deleting. |
54 intptr_t curr = fFreeListHead; | 56 intptr_t curr = fFreeListHead; |
55 while (kFreeListEnd != curr) { | 57 while (kFreeListEnd != curr) { |
56 intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]); | 58 intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]); |
57 fBuffers[SkToS32(curr)] = nullptr; | 59 fBuffers[SkToS32(curr)] = nullptr; |
58 curr = next; | 60 curr = next; |
59 } | 61 } |
60 | 62 |
(...skipping 21 matching lines...) Expand all Loading... |
82 fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]); | 84 fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]); |
83 | 85 |
84 buffer = new BufferObj(id); | 86 buffer = new BufferObj(id); |
85 fBuffers[id] = buffer; | 87 fBuffers[id] = buffer; |
86 } | 88 } |
87 | 89 |
88 return buffer; | 90 return buffer; |
89 } | 91 } |
90 | 92 |
91 void free(BufferObj* buffer) { | 93 void free(BufferObj* buffer) { |
| 94 SkASSERT(buffer); |
92 SkASSERT(fBuffers.count() > 0); | 95 SkASSERT(fBuffers.count() > 0); |
93 | 96 |
94 GrGLuint id = buffer->id(); | 97 GrGLuint id = buffer->id(); |
95 delete buffer; | 98 delete buffer; |
96 | 99 |
97 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead); | 100 fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead); |
98 fFreeListHead = id; | 101 fFreeListHead = id; |
99 } | 102 } |
100 | 103 |
101 private: | 104 private: |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (ids[i] == fCurrElementArrayBuffer) { | 197 if (ids[i] == fCurrElementArrayBuffer) { |
195 fCurrElementArrayBuffer = 0; | 198 fCurrElementArrayBuffer = 0; |
196 } | 199 } |
197 if (ids[i] == fCurrPixelPackBuffer) { | 200 if (ids[i] == fCurrPixelPackBuffer) { |
198 fCurrPixelPackBuffer = 0; | 201 fCurrPixelPackBuffer = 0; |
199 } | 202 } |
200 if (ids[i] == fCurrPixelUnpackBuffer) { | 203 if (ids[i] == fCurrPixelUnpackBuffer) { |
201 fCurrPixelUnpackBuffer = 0; | 204 fCurrPixelUnpackBuffer = 0; |
202 } | 205 } |
203 | 206 |
204 BufferObj* buffer = fBufferManager.lookUp(ids[i]); | 207 if (ids[i] > 0) { |
205 fBufferManager.free(buffer); | 208 BufferObj* buffer = fBufferManager.lookUp(ids[i]); |
| 209 fBufferManager.free(buffer); |
| 210 } |
206 } | 211 } |
207 } | 212 } |
208 | 213 |
209 GrGLvoid genFramebuffers(GrGLsizei n, GrGLuint *framebuffers) override { | 214 GrGLvoid genFramebuffers(GrGLsizei n, GrGLuint *framebuffers) override { |
210 this->genGenericIds(n, framebuffers); | 215 this->genGenericIds(n, framebuffers); |
211 } | 216 } |
212 | 217 |
213 GrGLvoid genQueries(GrGLsizei n, GrGLuint *ids) override { this->genGenericI
ds(n, ids); } | 218 GrGLvoid genQueries(GrGLsizei n, GrGLuint *ids) override { this->genGenericI
ds(n, ids); } |
214 | 219 |
215 GrGLvoid genRenderbuffers(GrGLsizei n, GrGLuint *renderbuffers) override { | 220 GrGLvoid genRenderbuffers(GrGLsizei n, GrGLuint *renderbuffers) override { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 "GL_ARB_timer_query", | 606 "GL_ARB_timer_query", |
602 "GL_ARB_draw_buffers", | 607 "GL_ARB_draw_buffers", |
603 "GL_ARB_occlusion_query", | 608 "GL_ARB_occlusion_query", |
604 "GL_EXT_stencil_wrap", | 609 "GL_EXT_stencil_wrap", |
605 nullptr, // signifies the end of the array. | 610 nullptr, // signifies the end of the array. |
606 }; | 611 }; |
607 | 612 |
608 } // anonymous namespace | 613 } // anonymous namespace |
609 | 614 |
610 const GrGLInterface* GrGLCreateNullInterface() { return new NullInterface; } | 615 const GrGLInterface* GrGLCreateNullInterface() { return new NullInterface; } |
OLD | NEW |