summaryrefslogtreecommitdiffstats
path: root/libs/hwui/Patch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/Patch.cpp')
-rw-r--r--libs/hwui/Patch.cpp52
1 files changed, 15 insertions, 37 deletions
diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp
index 442e9ba..f673c6a 100644
--- a/libs/hwui/Patch.cpp
+++ b/libs/hwui/Patch.cpp
@@ -24,22 +24,12 @@
#include "Patch.h"
#include "Properties.h"
#include "UvMapper.h"
+#include "utils/MathUtils.h"
namespace android {
namespace uirenderer {
///////////////////////////////////////////////////////////////////////////////
-// Constructors/destructor
-///////////////////////////////////////////////////////////////////////////////
-
-Patch::Patch(): vertices(NULL), verticesCount(0), indexCount(0), hasEmptyQuads(false) {
-}
-
-Patch::~Patch() {
- delete[] vertices;
-}
-
-///////////////////////////////////////////////////////////////////////////////
// Vertices management
///////////////////////////////////////////////////////////////////////////////
@@ -47,19 +37,11 @@ uint32_t Patch::getSize() const {
return verticesCount * sizeof(TextureVertex);
}
-TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeight,
- float width, float height, const Res_png_9patch* patch) {
- UvMapper mapper;
- return createMesh(bitmapWidth, bitmapHeight, width, height, mapper, patch);
-}
-
-TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeight,
- float width, float height, const UvMapper& mapper, const Res_png_9patch* patch) {
- if (vertices) return vertices;
+Patch::Patch(const float bitmapWidth, const float bitmapHeight,
+ float width, float height, const UvMapper& mapper, const Res_png_9patch* patch)
+ : mColors(patch->getColors()) {
int8_t emptyQuads = 0;
- mColors = patch->getColors();
-
const int8_t numColors = patch->numColors;
if (uint8_t(numColors) < sizeof(uint32_t) * 4) {
for (int8_t i = 0; i < numColors; i++) {
@@ -75,10 +57,10 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
uint32_t yCount = patch->numYDivs;
uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 4;
- if (maxVertices == 0) return NULL;
+ if (maxVertices == 0) return;
- TextureVertex* tempVertices = new TextureVertex[maxVertices];
- TextureVertex* vertex = tempVertices;
+ vertices.reset(new TextureVertex[maxVertices]);
+ TextureVertex* vertex = vertices.get();
const int32_t* xDivs = patch->getXDivs();
const int32_t* yDivs = patch->getYDivs();
@@ -157,15 +139,11 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
width, bitmapWidth, quadCount);
}
- if (verticesCount == maxVertices) {
- vertices = tempVertices;
- } else {
- vertices = new TextureVertex[verticesCount];
- memcpy(vertices, tempVertices, verticesCount * sizeof(TextureVertex));
- delete[] tempVertices;
+ if (verticesCount != maxVertices) {
+ std::unique_ptr<TextureVertex[]> reducedVertices(new TextureVertex[verticesCount]);
+ memcpy(reducedVertices.get(), vertices.get(), verticesCount * sizeof(TextureVertex));
+ vertices = std::move(reducedVertices);
}
-
- return vertices;
}
void Patch::generateRow(const int32_t* xDivs, uint32_t xCount, TextureVertex*& vertex,
@@ -213,10 +191,10 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f
const uint32_t oldQuadCount = quadCount;
quadCount++;
- if (x1 < 0.0f) x1 = 0.0f;
- if (x2 < 0.0f) x2 = 0.0f;
- if (y1 < 0.0f) y1 = 0.0f;
- if (y2 < 0.0f) y2 = 0.0f;
+ x1 = MathUtils::max(x1, 0.0f);
+ x2 = MathUtils::max(x2, 0.0f);
+ y1 = MathUtils::max(y1, 0.0f);
+ y2 = MathUtils::max(y2, 0.0f);
// Skip degenerate and transparent (empty) quads
if ((mColors[oldQuadCount] == 0) || x1 >= x2 || y1 >= y2) {