summaryrefslogtreecommitdiffstats
path: root/libs/hwui/Caches.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/Caches.cpp')
-rw-r--r--libs/hwui/Caches.cpp115
1 files changed, 109 insertions, 6 deletions
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp
index b6b35ea..0ef8469 100644
--- a/libs/hwui/Caches.cpp
+++ b/libs/hwui/Caches.cpp
@@ -55,6 +55,16 @@ Caches::Caches(): Singleton<Caches>(), mInitialized(false) {
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
+ if (extensions.hasDebugMarker()) {
+ eventMark = glInsertEventMarkerEXT;
+ startMark = glPushGroupMarkerEXT;
+ endMark = glPopGroupMarkerEXT;
+ } else {
+ eventMark = eventMarkNull;
+ startMark = startMarkNull;
+ endMark = endMarkNull;
+ }
+
init();
mDebugLevel = readDebugLevel();
@@ -73,6 +83,17 @@ void Caches::init() {
glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW);
mCurrentBuffer = meshBuffer;
+ mCurrentIndicesBuffer = 0;
+ mCurrentPositionPointer = this;
+ mCurrentTexCoordsPointer = this;
+
+ mTexCoordsArrayEnabled = false;
+
+ mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
+
+ glActiveTexture(gTextureUnits[0]);
+ mTextureUnit = 0;
+
mRegionMesh = NULL;
blend = false;
@@ -218,24 +239,106 @@ void Caches::flush(FlushMode mode) {
// VBO
///////////////////////////////////////////////////////////////////////////////
-void Caches::bindMeshBuffer() {
- bindMeshBuffer(meshBuffer);
+bool Caches::bindMeshBuffer() {
+ return bindMeshBuffer(meshBuffer);
}
-void Caches::bindMeshBuffer(const GLuint buffer) {
+bool Caches::bindMeshBuffer(const GLuint buffer) {
if (mCurrentBuffer != buffer) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
mCurrentBuffer = buffer;
+ return true;
}
+ return false;
}
-void Caches::unbindMeshBuffer() {
+bool Caches::unbindMeshBuffer() {
if (mCurrentBuffer) {
glBindBuffer(GL_ARRAY_BUFFER, 0);
mCurrentBuffer = 0;
+ return true;
+ }
+ return false;
+}
+
+bool Caches::bindIndicesBuffer(const GLuint buffer) {
+ if (mCurrentIndicesBuffer != buffer) {
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
+ mCurrentIndicesBuffer = buffer;
+ return true;
+ }
+ return false;
+}
+
+bool Caches::unbindIndicesBuffer() {
+ if (mCurrentIndicesBuffer) {
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+ mCurrentIndicesBuffer = 0;
+ return true;
+ }
+ return false;
+}
+
+void Caches::bindPositionVertexPointer(bool force, GLuint slot, GLvoid* vertices, GLsizei stride) {
+ if (force || vertices != mCurrentPositionPointer) {
+ glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
+ mCurrentPositionPointer = vertices;
+ }
+}
+
+void Caches::bindTexCoordsVertexPointer(bool force, GLuint slot, GLvoid* vertices) {
+ if (force || vertices != mCurrentTexCoordsPointer) {
+ glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, gMeshStride, vertices);
+ mCurrentTexCoordsPointer = vertices;
}
}
+void Caches::resetVertexPointers() {
+ mCurrentPositionPointer = this;
+ mCurrentTexCoordsPointer = this;
+}
+
+void Caches::resetTexCoordsVertexPointer() {
+ mCurrentTexCoordsPointer = this;
+}
+
+void Caches::enableTexCoordsVertexArray() {
+ if (!mTexCoordsArrayEnabled) {
+ glEnableVertexAttribArray(Program::kBindingTexCoords);
+ mCurrentTexCoordsPointer = this;
+ mTexCoordsArrayEnabled = true;
+ }
+}
+
+void Caches::disbaleTexCoordsVertexArray() {
+ if (mTexCoordsArrayEnabled) {
+ glDisableVertexAttribArray(Program::kBindingTexCoords);
+ mTexCoordsArrayEnabled = false;
+ }
+}
+
+void Caches::activeTexture(GLuint textureUnit) {
+ if (mTextureUnit != textureUnit) {
+ glActiveTexture(gTextureUnits[textureUnit]);
+ mTextureUnit = textureUnit;
+ }
+}
+
+void Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
+ if (x != mScissorX || y != mScissorY || width != mScissorWidth || height != mScissorHeight) {
+ glScissor(x, y, width, height);
+
+ mScissorX = x;
+ mScissorY = y;
+ mScissorWidth = width;
+ mScissorHeight = height;
+ }
+}
+
+void Caches::resetScissor() {
+ mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
+}
+
TextureVertex* Caches::getRegionMesh() {
// Create the mesh, 2 triangles and 4 vertices per rectangle in the region
if (!mRegionMesh) {
@@ -254,13 +357,13 @@ TextureVertex* Caches::getRegionMesh() {
}
glGenBuffers(1, &mRegionMeshIndices);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mRegionMeshIndices);
+ bindIndicesBuffer(mRegionMeshIndices);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t),
regionIndices, GL_STATIC_DRAW);
delete[] regionIndices;
} else {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mRegionMeshIndices);
+ bindIndicesBuffer(mRegionMeshIndices);
}
return mRegionMesh;