Add drop shadow for drawPosText in hwui renderer.
This patch adds support for drop shadows (setShadowLayer) for
drawPosText in the hwui renderer. In and of itself, it's not very
important, but it's on the critical path for correct mark positioning,
tracked as bug 5443796.
The change itself is fairly straightforward - it basically just adds an
extra "positions" argument to all draw and measure methods on the code
path for drawing drop shadowed text, as well as to the cache key for
cached shadow textures.
Change-Id: Ic1cb63299ba61ccbef31779459ecb82aa4a5e672
diff --git a/libs/hwui/TextDropShadowCache.h b/libs/hwui/TextDropShadowCache.h
index e2bdde1..bae0c49 100644
--- a/libs/hwui/TextDropShadowCache.h
+++ b/libs/hwui/TextDropShadowCache.h
@@ -35,8 +35,9 @@
ShadowText(): radius(0), len(0), textSize(0.0f), typeface(NULL) {
}
- ShadowText(SkPaint* paint, uint32_t radius, uint32_t len, const char* srcText):
- radius(radius), len(len) {
+ ShadowText(SkPaint* paint, uint32_t radius, uint32_t len, const char* srcText,
+ const float* positions):
+ radius(radius), len(len), positions(positions) {
// TODO: Propagate this through the API, we should not cast here
text = (const char16_t*) srcText;
@@ -66,11 +67,18 @@
uint32_t italicStyle;
uint32_t scaleX;
const char16_t* text;
+ const float* positions;
String16 str;
+ Vector<float> positionsCopy;
void copyTextLocally() {
str.setTo((const char16_t*) text, len >> 1);
text = str.string();
+ if (positions != NULL) {
+ positionsCopy.clear();
+ positionsCopy.appendArray(positions, len);
+ positions = positionsCopy.array();
+ }
}
bool operator<(const ShadowText& rhs) const {
@@ -81,7 +89,12 @@
LTE_INT(flags) {
LTE_INT(italicStyle) {
LTE_INT(scaleX) {
- return memcmp(text, rhs.text, len) < 0;
+ int cmp = memcmp(text, rhs.text, len);
+ if (cmp < 0) return true;
+ if (cmp == 0 && rhs.positions != NULL) {
+ if (positions == NULL) return true;
+ return memcmp(positions, rhs.positions, len << 2) < 0;
+ }
}
}
}
@@ -117,7 +130,7 @@
void operator()(ShadowText& text, ShadowTexture*& texture);
ShadowTexture* get(SkPaint* paint, const char* text, uint32_t len,
- int numGlyphs, uint32_t radius);
+ int numGlyphs, uint32_t radius, const float* positions);
/**
* Clears the cache. This causes all textures to be deleted.