bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | |
tomhudson@google.com | 6bf38b5 | 2012-02-14 15:11:59 +0000 | [diff] [blame] | 9 | #include "gl/GrGLInterface.h" |
bsalomon@google.com | 91bcc94 | 2012-05-07 17:28:41 +0000 | [diff] [blame] | 10 | #include "GrGLDefines.h" |
bsalomon@google.com | 21cbec4 | 2013-01-07 17:23:00 +0000 | [diff] [blame] | 11 | #include "SkTDArray.h" |
bsalomon@google.com | 8f94361 | 2013-02-26 14:34:43 +0000 | [diff] [blame] | 12 | #include "GrGLNoOpInterface.h" |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 13 | #include "SkTLS.h" |
bsalomon@google.com | 8f94361 | 2013-02-26 14:34:43 +0000 | [diff] [blame] | 14 | |
bsalomon | 7e34007 | 2015-02-11 12:07:31 -0800 | [diff] [blame] | 15 | // TODO: Delete this file after chrome starts using SkNullGLContext. |
| 16 | |
| 17 | // added to suppress 'no previous prototype' warning and because this code is duplicated in |
| 18 | // SkNullGLContext.cpp |
| 19 | namespace { |
| 20 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 21 | class BufferObj { |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 22 | public: |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 23 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 24 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 25 | BufferObj(GrGLuint id) : fID(id), fDataPtr(nullptr), fSize(0), fMapped(false) { |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 26 | } |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 27 | ~BufferObj() { delete[] fDataPtr; } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 28 | |
robertphillips@google.com | ae6b777 | 2013-07-18 18:07:39 +0000 | [diff] [blame] | 29 | void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 30 | if (fDataPtr) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 31 | SkASSERT(0 != fSize); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 32 | delete[] fDataPtr; |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | fSize = size; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 36 | fDataPtr = new char[size]; |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | GrGLuint id() const { return fID; } |
| 40 | GrGLchar* dataPtr() { return fDataPtr; } |
robertphillips@google.com | ae6b777 | 2013-07-18 18:07:39 +0000 | [diff] [blame] | 41 | GrGLsizeiptr size() const { return fSize; } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 42 | |
| 43 | void setMapped(bool mapped) { fMapped = mapped; } |
| 44 | bool mapped() const { return fMapped; } |
| 45 | |
| 46 | private: |
| 47 | GrGLuint fID; |
| 48 | GrGLchar* fDataPtr; |
robertphillips@google.com | ae6b777 | 2013-07-18 18:07:39 +0000 | [diff] [blame] | 49 | GrGLsizeiptr fSize; // size in bytes |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 50 | bool fMapped; |
| 51 | }; |
| 52 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 53 | // This class maintains a sparsely populated array of buffer pointers. |
| 54 | class BufferManager { |
| 55 | public: |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 56 | |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 57 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 58 | BufferManager() : fFreeListHead(kFreeListEnd) {} |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 59 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 60 | ~BufferManager() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 61 | // nullptr out the entries that are really free list links rather than ptrs before deleting. |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 62 | intptr_t curr = fFreeListHead; |
| 63 | while (kFreeListEnd != curr) { |
| 64 | intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 65 | fBuffers[SkToS32(curr)] = nullptr; |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 66 | curr = next; |
| 67 | } |
| 68 | |
| 69 | fBuffers.deleteAll(); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 70 | } |
| 71 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 72 | BufferObj* lookUp(GrGLuint id) { |
| 73 | BufferObj* buffer = fBuffers[id]; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 74 | SkASSERT(buffer && buffer->id() == id); |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 75 | return buffer; |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 76 | } |
| 77 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 78 | BufferObj* create() { |
| 79 | GrGLuint id; |
| 80 | BufferObj* buffer; |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 81 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 82 | if (kFreeListEnd == fFreeListHead) { |
| 83 | // no free slots - create a new one |
| 84 | id = fBuffers.count(); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 85 | buffer = new BufferObj(id); |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 86 | *fBuffers.append() = buffer; |
| 87 | } else { |
| 88 | // grab the head of the free list and advance the head to the next free slot. |
| 89 | id = static_cast<GrGLuint>(fFreeListHead); |
| 90 | fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 91 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 92 | buffer = new BufferObj(id); |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 93 | fBuffers[id] = buffer; |
| 94 | } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 95 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 96 | return buffer; |
| 97 | } |
| 98 | |
| 99 | void free(BufferObj* buffer) { |
| 100 | SkASSERT(fBuffers.count() > 0); |
| 101 | |
| 102 | GrGLuint id = buffer->id(); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 103 | delete buffer; |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 104 | |
| 105 | fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead); |
| 106 | fFreeListHead = id; |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | static const intptr_t kFreeListEnd = -1; |
| 111 | // Index of the first entry of fBuffers in the free list. Free slots in fBuffers are indices to |
| 112 | // the next free slot. The last free slot has a value of kFreeListEnd. |
| 113 | intptr_t fFreeListHead; |
| 114 | SkTDArray<BufferObj*> fBuffers; |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * The global-to-thread state object for the null interface. All null interfaces on the |
| 119 | * same thread currently share one of these. This means two null contexts on the same thread |
| 120 | * can interfere with each other. It may make sense to more integrate this into SkNullGLContext |
| 121 | * and use it's makeCurrent mechanism. |
| 122 | */ |
| 123 | struct ThreadContext { |
| 124 | public: |
mtklein | 2766c00 | 2015-06-26 11:45:03 -0700 | [diff] [blame] | 125 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 126 | |
| 127 | BufferManager fBufferManager; |
| 128 | GrGLuint fCurrArrayBuffer; |
| 129 | GrGLuint fCurrElementArrayBuffer; |
| 130 | GrGLuint fCurrProgramID; |
| 131 | GrGLuint fCurrShaderID; |
| 132 | |
| 133 | static ThreadContext* Get() { |
| 134 | return reinterpret_cast<ThreadContext*>(SkTLS::Get(Create, Delete)); |
| 135 | } |
| 136 | |
| 137 | ThreadContext() |
| 138 | : fCurrArrayBuffer(0) |
| 139 | , fCurrElementArrayBuffer(0) |
| 140 | , fCurrProgramID(0) |
| 141 | , fCurrShaderID(0) {} |
| 142 | |
| 143 | private: |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 144 | static void* Create() { return new ThreadContext; } |
| 145 | static void Delete(void* context) { delete reinterpret_cast<ThreadContext*>(context); } |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | // Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface). |
| 149 | |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 150 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {} |
| 151 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shader) {} |
| 152 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {} |
| 153 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {} |
| 154 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture) {} |
bsalomon@google.com | ecd8484 | 2013-03-01 15:36:02 +0000 | [diff] [blame] | 155 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindVertexArray(GrGLuint id) {} |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 156 | |
| 157 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenBuffers(GrGLsizei n, GrGLuint* ids) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 158 | ThreadContext* ctx = ThreadContext::Get(); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 159 | for (int i = 0; i < n; ++i) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 160 | BufferObj* buffer = ctx->fBufferManager.create(); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 161 | ids[i] = buffer->id(); |
| 162 | } |
| 163 | } |
| 164 | |
commit-bot@chromium.org | cffff79 | 2013-07-26 16:36:04 +0000 | [diff] [blame] | 165 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenerateMipmap(GrGLenum target) {} |
| 166 | |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 167 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target, |
| 168 | GrGLsizeiptr size, |
| 169 | const GrGLvoid* data, |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 170 | GrGLenum usage) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 171 | ThreadContext* ctx = ThreadContext::Get(); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 172 | GrGLuint id = 0; |
| 173 | |
| 174 | switch (target) { |
| 175 | case GR_GL_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 176 | id = ctx->fCurrArrayBuffer; |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 177 | break; |
| 178 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 179 | id = ctx->fCurrElementArrayBuffer; |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 180 | break; |
| 181 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 182 | SkFAIL("Unexpected target to nullGLBufferData"); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 183 | break; |
| 184 | } |
| 185 | |
| 186 | if (id > 0) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 187 | BufferObj* buffer = ctx->fBufferManager.lookUp(id); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 188 | buffer->allocate(size, (const GrGLchar*) data); |
| 189 | } |
| 190 | } |
| 191 | |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 192 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {} |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 193 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {} |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 194 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {} |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 195 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {} |
| 196 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint framebuffer) {} |
| 197 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint renderbuffer) {} |
| 198 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuint *framebuffers) {} |
| 199 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLuint *renderbuffers) {} |
| 200 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {} |
| 201 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {} |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 202 | |
| 203 | GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 204 | return ++ThreadContext::Get()->fCurrProgramID; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 208 | return ++ThreadContext::Get()->fCurrShaderID; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // same delete used for shaders and programs |
| 212 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) { |
| 213 | } |
| 214 | |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 215 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 216 | ThreadContext* ctx = ThreadContext::Get(); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 217 | switch (target) { |
| 218 | case GR_GL_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 219 | ctx->fCurrArrayBuffer = buffer; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 220 | break; |
| 221 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 222 | ctx->fCurrElementArrayBuffer = buffer; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 223 | break; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // deleting a bound buffer has the side effect of binding 0 |
| 228 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* ids) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 229 | ThreadContext* ctx = ThreadContext::Get(); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 230 | for (int i = 0; i < n; ++i) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 231 | if (ids[i] == ctx->fCurrArrayBuffer) { |
| 232 | ctx->fCurrArrayBuffer = 0; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 233 | } |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 234 | if (ids[i] == ctx->fCurrElementArrayBuffer) { |
| 235 | ctx->fCurrElementArrayBuffer = 0; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 236 | } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 237 | |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 238 | BufferObj* buffer = ctx->fBufferManager.lookUp(ids[i]); |
| 239 | ctx->fBufferManager.free(buffer); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 243 | GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBufferRange(GrGLenum target, GrGLintptr offset, |
| 244 | GrGLsizeiptr length, GrGLbitfield access) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 245 | ThreadContext* ctx = ThreadContext::Get(); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 246 | GrGLuint id = 0; |
| 247 | switch (target) { |
| 248 | case GR_GL_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 249 | id = ctx->fCurrArrayBuffer; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 250 | break; |
| 251 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 252 | id = ctx->fCurrElementArrayBuffer; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 253 | break; |
| 254 | } |
djsollen@google.com | 53b614b | 2014-05-02 17:44:34 +0000 | [diff] [blame] | 255 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 256 | if (id > 0) { |
| 257 | // We just ignore the offset and length here. |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 258 | BufferObj* buffer = ctx->fBufferManager.lookUp(id); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 259 | SkASSERT(!buffer->mapped()); |
| 260 | buffer->setMapped(true); |
| 261 | return buffer->dataPtr(); |
| 262 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 263 | return nullptr; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 267 | ThreadContext* ctx = ThreadContext::Get(); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 268 | GrGLuint id = 0; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 269 | switch (target) { |
| 270 | case GR_GL_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 271 | id = ctx->fCurrArrayBuffer; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 272 | break; |
| 273 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 274 | id = ctx->fCurrElementArrayBuffer; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 275 | break; |
| 276 | } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 277 | |
| 278 | if (id > 0) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 279 | BufferObj* buffer = ctx->fBufferManager.lookUp(id); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 280 | SkASSERT(!buffer->mapped()); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 281 | buffer->setMapped(true); |
| 282 | return buffer->dataPtr(); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 283 | } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 284 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 285 | SkASSERT(false); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 286 | return nullptr; // no buffer bound to target |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 287 | } |
| 288 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 289 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLFlushMappedBufferRange(GrGLenum target, |
| 290 | GrGLintptr offset, |
| 291 | GrGLsizeiptr length) {} |
| 292 | |
| 293 | |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 294 | GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 295 | ThreadContext* ctx = ThreadContext::Get(); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 296 | GrGLuint id = 0; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 297 | switch (target) { |
| 298 | case GR_GL_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 299 | id = ctx->fCurrArrayBuffer; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 300 | break; |
| 301 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 302 | id = ctx->fCurrElementArrayBuffer; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 303 | break; |
| 304 | } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 305 | if (id > 0) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 306 | BufferObj* buffer = ctx->fBufferManager.lookUp(id); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 307 | SkASSERT(buffer->mapped()); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 308 | buffer->setMapped(false); |
| 309 | return GR_GL_TRUE; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 310 | } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 311 | |
| 312 | GrAlwaysAssert(false); |
| 313 | return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 317 | ThreadContext* ctx = ThreadContext::Get(); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 318 | switch (pname) { |
| 319 | case GR_GL_BUFFER_MAPPED: { |
| 320 | *params = GR_GL_FALSE; |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 321 | GrGLuint id = 0; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 322 | switch (target) { |
| 323 | case GR_GL_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 324 | id = ctx->fCurrArrayBuffer; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 325 | break; |
| 326 | case GR_GL_ELEMENT_ARRAY_BUFFER: |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 327 | id = ctx->fCurrElementArrayBuffer; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 328 | break; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 329 | } |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 330 | if (id > 0) { |
bsalomon | 776d355 | 2014-08-14 08:13:27 -0700 | [diff] [blame] | 331 | BufferObj* buffer = ctx->fBufferManager.lookUp(id); |
robertphillips@google.com | d6543e5 | 2013-07-18 17:39:14 +0000 | [diff] [blame] | 332 | if (buffer->mapped()) { |
| 333 | *params = GR_GL_TRUE; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | break; } |
| 337 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 338 | SkFAIL("Unexpected pname to GetBufferParamateriv"); |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 339 | break; |
| 340 | } |
| 341 | }; |
| 342 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 343 | } // end anonymous namespace |
| 344 | |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 345 | const GrGLInterface* GrGLCreateNullInterface() { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 346 | GrGLInterface* interface = new GrGLInterface; |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 347 | |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 348 | interface->fStandard = kGL_GrGLStandard; |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 349 | |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 350 | GrGLInterface::Functions* functions = &interface->fFunctions; |
| 351 | functions->fActiveTexture = nullGLActiveTexture; |
| 352 | functions->fAttachShader = nullGLAttachShader; |
| 353 | functions->fBeginQuery = nullGLBeginQuery; |
| 354 | functions->fBindAttribLocation = nullGLBindAttribLocation; |
| 355 | functions->fBindBuffer = nullGLBindBuffer; |
| 356 | functions->fBindFragDataLocation = noOpGLBindFragDataLocation; |
| 357 | functions->fBindTexture = nullGLBindTexture; |
| 358 | functions->fBindVertexArray = nullGLBindVertexArray; |
| 359 | functions->fBlendColor = noOpGLBlendColor; |
cdalton | bae6f6c | 2015-04-22 10:39:03 -0700 | [diff] [blame] | 360 | functions->fBlendEquation = noOpGLBlendEquation; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 361 | functions->fBlendFunc = noOpGLBlendFunc; |
| 362 | functions->fBufferData = nullGLBufferData; |
| 363 | functions->fBufferSubData = noOpGLBufferSubData; |
| 364 | functions->fClear = noOpGLClear; |
| 365 | functions->fClearColor = noOpGLClearColor; |
| 366 | functions->fClearStencil = noOpGLClearStencil; |
| 367 | functions->fColorMask = noOpGLColorMask; |
| 368 | functions->fCompileShader = noOpGLCompileShader; |
| 369 | functions->fCompressedTexImage2D = noOpGLCompressedTexImage2D; |
krajcevski | 37d20f7 | 2014-06-11 10:38:47 -0700 | [diff] [blame] | 370 | functions->fCompressedTexSubImage2D = noOpGLCompressedTexSubImage2D; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 371 | functions->fCopyTexSubImage2D = noOpGLCopyTexSubImage2D; |
| 372 | functions->fCreateProgram = nullGLCreateProgram; |
| 373 | functions->fCreateShader = nullGLCreateShader; |
| 374 | functions->fCullFace = noOpGLCullFace; |
| 375 | functions->fDeleteBuffers = nullGLDeleteBuffers; |
| 376 | functions->fDeleteProgram = nullGLDelete; |
| 377 | functions->fDeleteQueries = noOpGLDeleteIds; |
| 378 | functions->fDeleteShader = nullGLDelete; |
| 379 | functions->fDeleteTextures = noOpGLDeleteIds; |
| 380 | functions->fDeleteVertexArrays = noOpGLDeleteIds; |
| 381 | functions->fDepthMask = noOpGLDepthMask; |
| 382 | functions->fDisable = noOpGLDisable; |
| 383 | functions->fDisableVertexAttribArray = noOpGLDisableVertexAttribArray; |
| 384 | functions->fDrawArrays = noOpGLDrawArrays; |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 385 | functions->fDrawArraysInstanced = noOpGLDrawArraysInstanced; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 386 | functions->fDrawBuffer = noOpGLDrawBuffer; |
| 387 | functions->fDrawBuffers = noOpGLDrawBuffers; |
| 388 | functions->fDrawElements = noOpGLDrawElements; |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 389 | functions->fDrawElementsInstanced = noOpGLDrawElementsInstanced; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 390 | functions->fEnable = noOpGLEnable; |
| 391 | functions->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray; |
| 392 | functions->fEndQuery = noOpGLEndQuery; |
| 393 | functions->fFinish = noOpGLFinish; |
| 394 | functions->fFlush = noOpGLFlush; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 395 | functions->fFlushMappedBufferRange = nullGLFlushMappedBufferRange; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 396 | functions->fFrontFace = noOpGLFrontFace; |
| 397 | functions->fGenBuffers = nullGLGenBuffers; |
| 398 | functions->fGenerateMipmap = nullGLGenerateMipmap; |
| 399 | functions->fGenQueries = noOpGLGenIds; |
| 400 | functions->fGenTextures = noOpGLGenIds; |
| 401 | functions->fGenVertexArrays = noOpGLGenIds; |
| 402 | functions->fGetBufferParameteriv = nullGLGetBufferParameteriv; |
| 403 | functions->fGetError = noOpGLGetError; |
| 404 | functions->fGetIntegerv = noOpGLGetIntegerv; |
| 405 | functions->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v; |
| 406 | functions->fGetQueryObjectiv = noOpGLGetQueryObjectiv; |
| 407 | functions->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v; |
| 408 | functions->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv; |
| 409 | functions->fGetQueryiv = noOpGLGetQueryiv; |
| 410 | functions->fGetProgramInfoLog = noOpGLGetInfoLog; |
| 411 | functions->fGetProgramiv = noOpGLGetShaderOrProgramiv; |
| 412 | functions->fGetShaderInfoLog = noOpGLGetInfoLog; |
| 413 | functions->fGetShaderiv = noOpGLGetShaderOrProgramiv; |
| 414 | functions->fGetString = noOpGLGetString; |
| 415 | functions->fGetStringi = noOpGLGetStringi; |
| 416 | functions->fGetTexLevelParameteriv = noOpGLGetTexLevelParameteriv; |
| 417 | functions->fGetUniformLocation = noOpGLGetUniformLocation; |
| 418 | functions->fInsertEventMarker = noOpGLInsertEventMarker; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 419 | functions->fLineWidth = noOpGLLineWidth; |
| 420 | functions->fLinkProgram = noOpGLLinkProgram; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 421 | functions->fMapBuffer = nullGLMapBuffer; |
| 422 | functions->fMapBufferRange = nullGLMapBufferRange; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 423 | functions->fPixelStorei = nullGLPixelStorei; |
| 424 | functions->fPopGroupMarker = noOpGLPopGroupMarker; |
| 425 | functions->fPushGroupMarker = noOpGLPushGroupMarker; |
| 426 | functions->fQueryCounter = noOpGLQueryCounter; |
| 427 | functions->fReadBuffer = noOpGLReadBuffer; |
| 428 | functions->fReadPixels = nullGLReadPixels; |
| 429 | functions->fScissor = noOpGLScissor; |
| 430 | functions->fShaderSource = noOpGLShaderSource; |
| 431 | functions->fStencilFunc = noOpGLStencilFunc; |
| 432 | functions->fStencilFuncSeparate = noOpGLStencilFuncSeparate; |
| 433 | functions->fStencilMask = noOpGLStencilMask; |
| 434 | functions->fStencilMaskSeparate = noOpGLStencilMaskSeparate; |
| 435 | functions->fStencilOp = noOpGLStencilOp; |
| 436 | functions->fStencilOpSeparate = noOpGLStencilOpSeparate; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 437 | functions->fTexImage2D = noOpGLTexImage2D; |
| 438 | functions->fTexParameteri = noOpGLTexParameteri; |
| 439 | functions->fTexParameteriv = noOpGLTexParameteriv; |
| 440 | functions->fTexSubImage2D = noOpGLTexSubImage2D; |
| 441 | functions->fTexStorage2D = noOpGLTexStorage2D; |
| 442 | functions->fDiscardFramebuffer = noOpGLDiscardFramebuffer; |
| 443 | functions->fUniform1f = noOpGLUniform1f; |
| 444 | functions->fUniform1i = noOpGLUniform1i; |
| 445 | functions->fUniform1fv = noOpGLUniform1fv; |
| 446 | functions->fUniform1iv = noOpGLUniform1iv; |
| 447 | functions->fUniform2f = noOpGLUniform2f; |
| 448 | functions->fUniform2i = noOpGLUniform2i; |
| 449 | functions->fUniform2fv = noOpGLUniform2fv; |
| 450 | functions->fUniform2iv = noOpGLUniform2iv; |
| 451 | functions->fUniform3f = noOpGLUniform3f; |
| 452 | functions->fUniform3i = noOpGLUniform3i; |
| 453 | functions->fUniform3fv = noOpGLUniform3fv; |
| 454 | functions->fUniform3iv = noOpGLUniform3iv; |
| 455 | functions->fUniform4f = noOpGLUniform4f; |
| 456 | functions->fUniform4i = noOpGLUniform4i; |
| 457 | functions->fUniform4fv = noOpGLUniform4fv; |
| 458 | functions->fUniform4iv = noOpGLUniform4iv; |
| 459 | functions->fUniformMatrix2fv = noOpGLUniformMatrix2fv; |
| 460 | functions->fUniformMatrix3fv = noOpGLUniformMatrix3fv; |
| 461 | functions->fUniformMatrix4fv = noOpGLUniformMatrix4fv; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 462 | functions->fUnmapBuffer = nullGLUnmapBuffer; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 463 | functions->fUseProgram = nullGLUseProgram; |
egdaniel | 27c1521 | 2014-10-24 15:00:50 -0700 | [diff] [blame] | 464 | functions->fVertexAttrib1f = noOpGLVertexAttrib1f; |
| 465 | functions->fVertexAttrib2fv = noOpGLVertexAttrib2fv; |
| 466 | functions->fVertexAttrib3fv = noOpGLVertexAttrib3fv; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 467 | functions->fVertexAttrib4fv = noOpGLVertexAttrib4fv; |
| 468 | functions->fVertexAttribPointer = noOpGLVertexAttribPointer; |
cdalton | 626e1ff | 2015-06-12 13:56:46 -0700 | [diff] [blame] | 469 | functions->fVertexAttribDivisor = noOpGLVertexAttribDivisor; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 470 | functions->fViewport = nullGLViewport; |
| 471 | functions->fBindFramebuffer = nullGLBindFramebuffer; |
| 472 | functions->fBindRenderbuffer = nullGLBindRenderbuffer; |
| 473 | functions->fCheckFramebufferStatus = noOpGLCheckFramebufferStatus; |
| 474 | functions->fDeleteFramebuffers = nullGLDeleteFramebuffers; |
| 475 | functions->fDeleteRenderbuffers = nullGLDeleteRenderbuffers; |
| 476 | functions->fFramebufferRenderbuffer = nullGLFramebufferRenderbuffer; |
| 477 | functions->fFramebufferTexture2D = nullGLFramebufferTexture2D; |
| 478 | functions->fGenFramebuffers = noOpGLGenIds; |
| 479 | functions->fGenRenderbuffers = noOpGLGenIds; |
| 480 | functions->fGetFramebufferAttachmentParameteriv = noOpGLGetFramebufferAttachmentParameteriv; |
| 481 | functions->fGetRenderbufferParameteriv = noOpGLGetRenderbufferParameteriv; |
| 482 | functions->fRenderbufferStorage = noOpGLRenderbufferStorage; |
| 483 | functions->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMultisample; |
| 484 | functions->fBlitFramebuffer = noOpGLBlitFramebuffer; |
| 485 | functions->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuffer; |
commit-bot@chromium.org | f669672 | 2014-04-25 06:21:30 +0000 | [diff] [blame] | 486 | functions->fMatrixLoadf = noOpGLMatrixLoadf; |
| 487 | functions->fMatrixLoadIdentity = noOpGLMatrixLoadIdentity; |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 488 | functions->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed; |
| 489 | |
| 490 | interface->fExtensions.init(kGL_GrGLStandard, functions->fGetString, functions->fGetStringi, |
bsalomon | b1a32ad | 2015-11-16 06:48:44 -0800 | [diff] [blame] | 491 | functions->fGetIntegerv, nullptr, GR_EGL_NO_DISPLAY); |
commit-bot@chromium.org | f535561 | 2014-02-28 20:28:50 +0000 | [diff] [blame] | 492 | return interface; |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 493 | } |