summaryrefslogtreecommitdiff
path: root/libs/hwui/OpenGLRenderer.cpp
diff options
context:
space:
mode:
author Romain Guy <romainguy@google.com> 2011-01-20 19:09:30 -0800
committer Romain Guy <romainguy@google.com> 2011-01-20 19:09:30 -0800
commit5a7b466a2b4b7ced739bd5c31e022de61650545a (patch)
tree1eef540913ce3a131019586f9187bc8e66f59caa /libs/hwui/OpenGLRenderer.cpp
parentc8219299b0003793cee8049b96a3bf7530765eea (diff)
Add support for drawBitmapMesh().
Change-Id: Ic77f9c534bb90dc7b9458299544bd50b8b6ae6a5
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
-rw-r--r--libs/hwui/OpenGLRenderer.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 9528dbbfdafb..b06bbd0aa543 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1077,6 +1077,61 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* pai
restore();
}
+void OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
+ float* vertices, int* colors, SkPaint* paint) {
+ // TODO: Do a quickReject
+ if (!vertices || mSnapshot->isIgnored()) {
+ return;
+ }
+
+ glActiveTexture(gTextureUnits[0]);
+ Texture* texture = mCaches.textureCache.get(bitmap);
+ if (!texture) return;
+ const AutoTexture autoCleanup(texture);
+ setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+
+ int alpha;
+ SkXfermode::Mode mode;
+ getAlphaAndMode(paint, &alpha, &mode);
+
+ // TODO: Support the colors array
+ const uint32_t count = meshWidth * meshHeight * 6;
+ TextureVertex mesh[count];
+
+ TextureVertex* vertex = mesh;
+ for (int32_t y = 0; y < meshHeight; y++) {
+ for (int32_t x = 0; x < meshWidth; x++) {
+ uint32_t i = (y * (meshWidth + 1) + x) * 2;
+
+ float u1 = float(x) / meshWidth;
+ float u2 = float(x + 1) / meshWidth;
+ float v1 = float(y) / meshHeight;
+ float v2 = float(y + 1) / meshHeight;
+
+ int ax = i + (meshWidth + 1) * 2;
+ int ay = ax + 1;
+ int bx = i;
+ int by = bx + 1;
+ int cx = i + 2;
+ int cy = cx + 1;
+ int dx = i + (meshWidth + 1) * 2 + 2;
+ int dy = dx + 1;
+
+ TextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2);
+ TextureVertex::set(vertex++, vertices[bx], vertices[by], u1, v1);
+ TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
+
+ TextureVertex::set(vertex++, vertices[ax], vertices[ay], u1, v2);
+ TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
+ TextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2);
+ }
+ }
+
+ drawTextureMesh(0.0f, 0.0f, 1.0f, 1.0f, texture->id, alpha / 255.0f,
+ mode, texture->blend, &mesh[0].position[0], &mesh[0].texture[0],
+ GL_TRIANGLES, count);
+}
+
void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
float srcLeft, float srcTop, float srcRight, float srcBottom,
float dstLeft, float dstTop, float dstRight, float dstBottom,