summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-02-24 17:54:07 -0800
committerRomain Guy <romainguy@google.com>2012-02-24 17:54:07 -0800
commit03d58520c3eb6bb7efb7235bfd957550533d6725 (patch)
tree97b131fd746d7857a005dc2a93d64469ebbcb7fc
parent325740fb444af8fc7fb0119b2e30ce322c2ae134 (diff)
downloadframeworks_base-03d58520c3eb6bb7efb7235bfd957550533d6725.zip
frameworks_base-03d58520c3eb6bb7efb7235bfd957550533d6725.tar.gz
frameworks_base-03d58520c3eb6bb7efb7235bfd957550533d6725.tar.bz2
More infrastructure for Canvas.drawTextOnPath
Change-Id: Iff42b24e342650d06fa4e2fa9db6c28da820ff01
-rw-r--r--libs/hwui/OpenGLRenderer.cpp68
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/TextOnPathActivity.java22
2 files changed, 86 insertions, 4 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 6f0f836..ebb6d88 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <SkCanvas.h>
+#include <SkPathMeasure.h>
#include <SkTypeface.h>
#include <utils/Log.h>
@@ -2294,7 +2295,72 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
void OpenGLRenderer::drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path,
float hOffset, float vOffset, SkPaint* paint) {
- // TODO: Implement
+ if (text == NULL || count == 0 || mSnapshot->isIgnored() ||
+ (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) {
+ return;
+ }
+
+ float x = 0.0f;
+ float y = 0.0f;
+
+ const bool pureTranslate = mSnapshot->transform->isPureTranslate();
+ if (CC_LIKELY(pureTranslate)) {
+ x = (int) floorf(x + mSnapshot->transform->getTranslateX() + 0.5f);
+ y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);
+ }
+
+ FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
+ fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
+ paint->getTextSize());
+
+ int alpha;
+ SkXfermode::Mode mode;
+ getAlphaAndMode(paint, &alpha, &mode);
+
+ mCaches.activeTexture(0);
+ setupDraw();
+ setupDrawDirtyRegionsDisabled();
+ setupDrawWithTexture(true);
+ setupDrawAlpha8Color(paint->getColor(), alpha);
+ setupDrawColorFilter();
+ setupDrawShader();
+ setupDrawBlending(true, mode);
+ setupDrawProgram();
+ setupDrawModelView(x, y, x, y, pureTranslate, true);
+ setupDrawTexture(fontRenderer.getTexture(true));
+ setupDrawPureColorUniforms();
+ setupDrawColorFilterUniforms();
+ setupDrawShaderUniforms(pureTranslate);
+
+// mat4 pathTransform;
+// pathTransform.loadTranslate(hOffset, vOffset, 0.0f);
+//
+// float offset = 0.0f;
+// SkPathMeasure pathMeasure(*path, false);
+//
+// if (paint->getTextAlign() != SkPaint::kLeft_Align) {
+// SkScalar pathLength = pathMeasure.getLength();
+// if (paint->getTextAlign() == SkPaint::kCenter_Align) {
+// pathLength = SkScalarHalf(pathLength);
+// }
+// offset += SkScalarToFloat(pathLength);
+// }
+
+// SkScalar x;
+// SkPath tmp;
+// SkMatrix m(scaledMatrix);
+//
+// m.postTranslate(xpos + hOffset, 0);
+// if (matrix) {
+// m.postConcat(*matrix);
+// }
+// morphpath(&tmp, *iterPath, meas, m);
+// if (fDevice) {
+// fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true);
+// } else {
+// this->drawPath(tmp, iter.getPaint(), NULL, true);
+// }
+// }
}
void OpenGLRenderer::drawPath(SkPath* path, SkPaint* paint) {
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/TextOnPathActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/TextOnPathActivity.java
index 439d029..b798ee7 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/TextOnPathActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/TextOnPathActivity.java
@@ -64,8 +64,8 @@ public class TextOnPathActivity extends Activity {
mPaint.setAntiAlias(true);
mPaint.setColor(0xff000000);
- StringBuilder builder = new StringBuilder(TEST_STRING.length() * 5);
- for (int i = 0; i < 5; i++) {
+ StringBuilder builder = new StringBuilder(TEST_STRING.length() * 2);
+ for (int i = 0; i < 2; i++) {
builder.append(TEST_STRING);
}
mText = builder.toString();
@@ -77,8 +77,24 @@ public class TextOnPathActivity extends Activity {
canvas.drawARGB(255, 255, 255, 255);
- canvas.translate(550.0f, 60.0f);
+ canvas.save();
+ canvas.translate(400.0f, 350.0f);
+ mPaint.setTextAlign(Paint.Align.LEFT);
+ canvas.drawTextOnPath(mText + mText, mPath, 0.0f, 0.0f, mPaint);
+ canvas.restore();
+
+ canvas.save();
+ canvas.translate(150.0f, 60.0f);
+ canvas.drawTextOnPath(mText, mPath, 0.0f, 0.0f, mPaint);
+
+ canvas.translate(250.0f, 0.0f);
+ mPaint.setTextAlign(Paint.Align.CENTER);
+ canvas.drawTextOnPath(mText, mPath, 0.0f, 0.0f, mPaint);
+
+ canvas.translate(250.0f, 0.0f);
+ mPaint.setTextAlign(Paint.Align.RIGHT);
canvas.drawTextOnPath(mText, mPath, 0.0f, 0.0f, mPaint);
+ canvas.restore();
}
}
}