First pass at implementing Canvas.drawPosText() in GL
Change-Id: Ia3ac347e95d57eb86c63045156c8dbc0572b03cb
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 656a384..824ab4f 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -60,6 +60,7 @@
"DrawLines",
"DrawPoints",
"DrawText",
+ "DrawPosText",
"ResetShader",
"SetupShader",
"ResetColorFilter",
@@ -482,6 +483,15 @@
text.text(), text.length(), count, x, y, paint, length);
}
break;
+ case DrawPosText: {
+ getText(&text);
+ int count = getInt();
+ int positionsCount = 0;
+ float* positions = getFloats(positionsCount);
+ SkPaint* paint = getPaint();
+ ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op],
+ text.text(), text.length(), count, paint);
+ }
case ResetShader: {
ALOGD("%s%s", (char*) indent, OP_NAMES[op]);
}
@@ -844,6 +854,17 @@
renderer.drawText(text.text(), text.length(), count, x, y, paint, length);
}
break;
+ case DrawPosText: {
+ getText(&text);
+ int count = getInt();
+ int positionsCount = 0;
+ float* positions = getFloats(positionsCount);
+ SkPaint* paint = getPaint();
+ DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent,
+ OP_NAMES[op], text.text(), text.length(), count, paint);
+ renderer.drawPosText(text.text(), text.length(), count, positions, paint);
+ }
+ break;
case ResetShader: {
DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
renderer.resetShader();
@@ -1216,6 +1237,17 @@
addFloat(length < 0.0f ? paint->measureText(text, bytesCount) : length);
}
+void DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
+ const float* positions, SkPaint* paint) {
+ if (count <= 0) return;
+ addOp(DisplayList::DrawPosText);
+ addText(text, bytesCount);
+ addInt(count);
+ addFloats(positions, count * 2);
+ paint->setAntiAlias(true);
+ addPaint(paint);
+}
+
void DisplayListRenderer::resetShader() {
addOp(DisplayList::ResetShader);
}
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index 5d922db..dd7ec4f 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -96,6 +96,7 @@
DrawLines,
DrawPoints,
DrawText,
+ DrawPosText,
ResetShader,
SetupShader,
ResetColorFilter,
@@ -291,6 +292,8 @@
virtual void drawPoints(float* points, int count, SkPaint* paint);
virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
SkPaint* paint, float length = 1.0f);
+ virtual void drawPosText(const char* text, int bytesCount, int count, const float* positions,
+ SkPaint* paint);
virtual void resetShader();
virtual void setupShader(SkiaShader* shader);
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 12ed205..6ec87f3 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -2082,6 +2082,17 @@
}
}
+void OpenGLRenderer::drawPosText(const char* text, int bytesCount, int count,
+ const float* positions, SkPaint* paint) {
+ if (text == NULL || count == 0) {
+ return;
+ }
+ if (mSnapshot->isIgnored()) return;
+
+ // TODO: implement properly
+ drawText(text, bytesCount, count, 0, 0, paint);
+}
+
void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
float x, float y, SkPaint* paint, float length) {
if (text == NULL || count == 0) {
@@ -2120,10 +2131,11 @@
y = (int) floorf(y + mSnapshot->transform->getTranslateY() + 0.5f);
}
- FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
#if DEBUG_GLYPHS
ALOGD("OpenGLRenderer drawText() with FontID=%d", SkTypeface::UniqueID(paint->getTypeface()));
#endif
+
+ FontRenderer& fontRenderer = mCaches.fontRenderer.getFontRenderer(paint);
fontRenderer.setFont(paint, SkTypeface::UniqueID(paint->getTypeface()),
paint->getTextSize());
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 019e9b2..a9cda47 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -124,6 +124,8 @@
virtual void drawPoints(float* points, int count, SkPaint* paint);
virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
SkPaint* paint, float length = -1.0f);
+ virtual void drawPosText(const char* text, int bytesCount, int count, const float* positions,
+ SkPaint* paint);
virtual void resetShader();
virtual void setupShader(SkiaShader* shader);