Merge "Cleanup 9patch mesh matching code Bug #7970966"

This commit is contained in:
Romain Guy
2013-01-09 14:39:10 -08:00
committed by Android (Google) Code Review
4 changed files with 27 additions and 29 deletions

View File

@@ -37,7 +37,7 @@ Patch::Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQua
// 2 triangles per patch, 3 vertices per triangle // 2 triangles per patch, 3 vertices per triangle
uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 2 * 3; uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 2 * 3;
mVertices = new TextureVertex[maxVertices]; mVertices = new TextureVertex[maxVertices];
mUploaded = false; mAllocatedVerticesCount = 0;
verticesCount = 0; verticesCount = 0;
hasEmptyQuads = emptyQuads > 0; hasEmptyQuads = emptyQuads > 0;
@@ -68,38 +68,37 @@ void Patch::copy(const int32_t* xDivs, const int32_t* yDivs) {
memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t)); memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t));
} }
void Patch::copy(const int32_t* yDivs) {
memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t));
}
void Patch::updateColorKey(const uint32_t colorKey) { void Patch::updateColorKey(const uint32_t colorKey) {
mColorKey = colorKey; mColorKey = colorKey;
} }
bool Patch::matches(const int32_t* xDivs, const int32_t* yDivs, const uint32_t colorKey) { bool Patch::matches(const int32_t* xDivs, const int32_t* yDivs,
const uint32_t colorKey, const int8_t emptyQuads) {
bool matches = true;
if (mEmptyQuads != emptyQuads) {
mEmptyQuads = emptyQuads;
hasEmptyQuads = emptyQuads > 0;
matches = false;
}
if (mColorKey != colorKey) { if (mColorKey != colorKey) {
updateColorKey(colorKey); updateColorKey(colorKey);
copy(xDivs, yDivs); matches = false;
return false;
} }
for (uint32_t i = 0; i < mXCount; i++) { if (memcmp(mXDivs, xDivs, mXCount * sizeof(int32_t))) {
if (mXDivs[i] != xDivs[i]) { memcpy(mXDivs, xDivs, mXCount * sizeof(int32_t));
// The Y divs may or may not match, copy everything matches = false;
copy(xDivs, yDivs);
return false;
}
} }
for (uint32_t i = 0; i < mYCount; i++) { if (memcmp(mYDivs, yDivs, mYCount * sizeof(int32_t))) {
if (mYDivs[i] != yDivs[i]) { memcpy(mYDivs, yDivs, mYCount * sizeof(int32_t));
// We know all the X divs match, copy only Y divs matches = false;
copy(yDivs);
return false;
}
} }
return true; return matches;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@@ -203,10 +202,10 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
if (verticesCount > 0) { if (verticesCount > 0) {
Caches& caches = Caches::getInstance(); Caches& caches = Caches::getInstance();
caches.bindMeshBuffer(meshBuffer); caches.bindMeshBuffer(meshBuffer);
if (!mUploaded) { if (mAllocatedVerticesCount < verticesCount) {
glBufferData(GL_ARRAY_BUFFER, sizeof(TextureVertex) * verticesCount, glBufferData(GL_ARRAY_BUFFER, sizeof(TextureVertex) * verticesCount,
mVertices, GL_DYNAMIC_DRAW); mVertices, GL_DYNAMIC_DRAW);
mUploaded = true; mAllocatedVerticesCount = verticesCount;
} else { } else {
glBufferSubData(GL_ARRAY_BUFFER, 0, glBufferSubData(GL_ARRAY_BUFFER, 0,
sizeof(TextureVertex) * verticesCount, mVertices); sizeof(TextureVertex) * verticesCount, mVertices);

View File

@@ -45,7 +45,7 @@ namespace uirenderer {
* indices to render the vertices. * indices to render the vertices.
*/ */
struct Patch { struct Patch {
Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads = 0); Patch(const uint32_t xCount, const uint32_t yCount, const int8_t emptyQuads);
~Patch(); ~Patch();
void updateVertices(const float bitmapWidth, const float bitmapHeight, void updateVertices(const float bitmapWidth, const float bitmapHeight,
@@ -53,7 +53,8 @@ struct Patch {
void updateColorKey(const uint32_t colorKey); void updateColorKey(const uint32_t colorKey);
void copy(const int32_t* xDivs, const int32_t* yDivs); void copy(const int32_t* xDivs, const int32_t* yDivs);
bool matches(const int32_t* xDivs, const int32_t* yDivs, const uint32_t colorKey); bool matches(const int32_t* xDivs, const int32_t* yDivs,
const uint32_t colorKey, const int8_t emptyQuads);
GLuint meshBuffer; GLuint meshBuffer;
uint32_t verticesCount; uint32_t verticesCount;
@@ -62,7 +63,7 @@ struct Patch {
private: private:
TextureVertex* mVertices; TextureVertex* mVertices;
bool mUploaded; uint32_t mAllocatedVerticesCount;
int32_t* mXDivs; int32_t* mXDivs;
int32_t* mYDivs; int32_t* mYDivs;
@@ -72,8 +73,6 @@ private:
uint32_t mYCount; uint32_t mYCount;
int8_t mEmptyQuads; int8_t mEmptyQuads;
void copy(const int32_t* yDivs);
void generateRow(TextureVertex*& vertex, float y1, float y2, void generateRow(TextureVertex*& vertex, float y1, float y2,
float v1, float v2, float stretchX, float rescaleX, float v1, float v2, float stretchX, float rescaleX,
float width, float bitmapWidth, uint32_t& quadCount); float width, float bitmapWidth, uint32_t& quadCount);

View File

@@ -97,7 +97,7 @@ Patch* PatchCache::get(const float bitmapWidth, const float bitmapHeight,
} }
mCache.add(description, mesh); mCache.add(description, mesh);
} else if (!mesh->matches(xDivs, yDivs, colorKey)) { } else if (!mesh->matches(xDivs, yDivs, colorKey, transparentQuads)) {
PATCH_LOGD("Patch mesh does not match, refreshing vertices"); PATCH_LOGD("Patch mesh does not match, refreshing vertices");
mesh->updateVertices(bitmapWidth, bitmapHeight, 0.0f, 0.0f, pixelWidth, pixelHeight); mesh->updateVertices(bitmapWidth, bitmapHeight, 0.0f, 0.0f, pixelWidth, pixelHeight);
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB