Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "GrGLVertexArray.h" |
michael@0 | 9 | #include "GrGpuGL.h" |
michael@0 | 10 | |
michael@0 | 11 | #define GPUGL static_cast<GrGpuGL*>(this->getGpu()) |
michael@0 | 12 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X); |
michael@0 | 13 | |
michael@0 | 14 | void GrGLAttribArrayState::set(const GrGpuGL* gpu, |
michael@0 | 15 | int index, |
michael@0 | 16 | GrGLVertexBuffer* buffer, |
michael@0 | 17 | GrGLint size, |
michael@0 | 18 | GrGLenum type, |
michael@0 | 19 | GrGLboolean normalized, |
michael@0 | 20 | GrGLsizei stride, |
michael@0 | 21 | GrGLvoid* offset) { |
michael@0 | 22 | SkASSERT(index >= 0 && index < fAttribArrayStates.count()); |
michael@0 | 23 | AttribArrayState* array = &fAttribArrayStates[index]; |
michael@0 | 24 | if (!array->fEnableIsValid || !array->fEnabled) { |
michael@0 | 25 | GR_GL_CALL(gpu->glInterface(), EnableVertexAttribArray(index)); |
michael@0 | 26 | array->fEnableIsValid = true; |
michael@0 | 27 | array->fEnabled = true; |
michael@0 | 28 | } |
michael@0 | 29 | if (!array->fAttribPointerIsValid || |
michael@0 | 30 | array->fVertexBufferID != buffer->bufferID() || |
michael@0 | 31 | array->fSize != size || |
michael@0 | 32 | array->fNormalized != normalized || |
michael@0 | 33 | array->fStride != stride || |
michael@0 | 34 | array->fOffset != offset) { |
michael@0 | 35 | |
michael@0 | 36 | buffer->bind(); |
michael@0 | 37 | GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index, |
michael@0 | 38 | size, |
michael@0 | 39 | type, |
michael@0 | 40 | normalized, |
michael@0 | 41 | stride, |
michael@0 | 42 | offset)); |
michael@0 | 43 | array->fAttribPointerIsValid = true; |
michael@0 | 44 | array->fVertexBufferID = buffer->bufferID(); |
michael@0 | 45 | array->fSize = size; |
michael@0 | 46 | array->fNormalized = normalized; |
michael@0 | 47 | array->fStride = stride; |
michael@0 | 48 | array->fOffset = offset; |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | void GrGLAttribArrayState::disableUnusedArrays(const GrGpuGL* gpu, uint64_t usedMask) { |
michael@0 | 53 | int count = fAttribArrayStates.count(); |
michael@0 | 54 | for (int i = 0; i < count; ++i) { |
michael@0 | 55 | if (!(usedMask & 0x1)) { |
michael@0 | 56 | if (!fAttribArrayStates[i].fEnableIsValid || fAttribArrayStates[i].fEnabled) { |
michael@0 | 57 | GR_GL_CALL(gpu->glInterface(), DisableVertexAttribArray(i)); |
michael@0 | 58 | fAttribArrayStates[i].fEnableIsValid = true; |
michael@0 | 59 | fAttribArrayStates[i].fEnabled = false; |
michael@0 | 60 | } |
michael@0 | 61 | } else { |
michael@0 | 62 | SkASSERT(fAttribArrayStates[i].fEnableIsValid && fAttribArrayStates[i].fEnabled); |
michael@0 | 63 | } |
michael@0 | 64 | // if the count is greater than 64 then this will become 0 and we will disable arrays 64+. |
michael@0 | 65 | usedMask >>= 1; |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
michael@0 | 70 | |
michael@0 | 71 | GrGLVertexArray::GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount) |
michael@0 | 72 | : GrResource(gpu, false) |
michael@0 | 73 | , fID(id) |
michael@0 | 74 | , fAttribArrays(attribCount) |
michael@0 | 75 | , fIndexBufferIDIsValid(false) { |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | void GrGLVertexArray::onAbandon() { |
michael@0 | 79 | fID = 0; |
michael@0 | 80 | INHERITED::onAbandon(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | void GrGLVertexArray::onRelease() { |
michael@0 | 84 | if (0 != fID) { |
michael@0 | 85 | GL_CALL(DeleteVertexArrays(1, &fID)); |
michael@0 | 86 | GPUGL->notifyVertexArrayDelete(fID); |
michael@0 | 87 | fID = 0; |
michael@0 | 88 | } |
michael@0 | 89 | INHERITED::onRelease(); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | GrGLAttribArrayState* GrGLVertexArray::bind() { |
michael@0 | 93 | if (0 == fID) { |
michael@0 | 94 | return NULL; |
michael@0 | 95 | } |
michael@0 | 96 | GPUGL->bindVertexArray(fID); |
michael@0 | 97 | return &fAttribArrays; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | GrGLAttribArrayState* GrGLVertexArray::bindWithIndexBuffer(const GrGLIndexBuffer* buffer) { |
michael@0 | 101 | GrGLAttribArrayState* state = this->bind(); |
michael@0 | 102 | if (NULL != state && NULL != buffer) { |
michael@0 | 103 | GrGLuint bufferID = buffer->bufferID(); |
michael@0 | 104 | if (!fIndexBufferIDIsValid || bufferID != fIndexBufferID) { |
michael@0 | 105 | GL_CALL(BindBuffer(GR_GL_ELEMENT_ARRAY_BUFFER, bufferID)); |
michael@0 | 106 | fIndexBufferIDIsValid = true; |
michael@0 | 107 | fIndexBufferID = bufferID; |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | return state; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | void GrGLVertexArray::notifyIndexBufferDelete(GrGLuint bufferID) { |
michael@0 | 114 | if (fIndexBufferIDIsValid && bufferID == fIndexBufferID) { |
michael@0 | 115 | fIndexBufferID = 0; |
michael@0 | 116 | } |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | void GrGLVertexArray::invalidateCachedState() { |
michael@0 | 120 | fAttribArrays.invalidate(); |
michael@0 | 121 | fIndexBufferIDIsValid = false; |
michael@0 | 122 | } |