Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 484f3bdc authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Add support for non-antialiased text"

parents 92826459 b969a0de
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -814,7 +814,6 @@ status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, i
        SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
    if (!text || count <= 0) return DrawGlInfo::kStatusDone;

    paint->setAntiAlias(true);
    text = refText(text, bytesCount);
    path = refPath(path);
    paint = refPaint(paint);
@@ -833,7 +832,6 @@ status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int
        const float* positions, SkPaint* paint) {
    if (!text || count <= 0) return DrawGlInfo::kStatusDone;

    paint->setAntiAlias(true);
    text = refText(text, bytesCount);
    positions = refBuffer<float>(positions, count * 2);
    paint = refPaint(paint);
@@ -851,14 +849,6 @@ status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int cou
        float x, float y, const float* positions, SkPaint* paint, float length) {
    if (!text || count <= 0) return DrawGlInfo::kStatusDone;

    // TODO: We should probably make a copy of the paint instead of modifying
    //       it; modifying the paint will change its generationID the first
    //       time, which might impact caches. More investigation needed to
    //       see if it matters.
    //       If we make a copy, then drawTextDecorations() should *not* make
    //       its own copy as it does right now.
    // Beware: this needs Glyph encoding (already done on the Paint constructor)
    paint->setAntiAlias(true);
    if (length < 0.0f) length = paint->measureText(text, bytesCount);

    text = refText(text, bytesCount);
+44 −13
Original line number Diff line number Diff line
@@ -218,12 +218,14 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
        cacheTexture->allocateTexture();
    }

    uint8_t* cacheBuffer = cacheTexture->getTexture();
    uint8_t* bitmapBuffer = (uint8_t*) glyph.fImage;
    unsigned int stride = glyph.rowBytes();
    // Tells us whether the glyphs is B&W (1 bit per pixel)
    // or anti-aliased (8 bits per pixel)
    SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat);

    uint8_t* cacheBuffer = cacheTexture->getTexture();
    uint32_t cacheX = 0, bX = 0, cacheY = 0, bY = 0;

    // Zero out the borders
    for (cacheX = startX - TEXTURE_BORDER_SIZE; cacheX < endX + TEXTURE_BORDER_SIZE; cacheX++) {
        cacheBuffer[(startY - TEXTURE_BORDER_SIZE) * cacheWidth + cacheX] = 0;
        cacheBuffer[(endY + TEXTURE_BORDER_SIZE - 1) * cacheWidth + cacheX] = 0;
@@ -235,20 +237,49 @@ void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyp
        cacheBuffer[cacheY * cacheWidth + endX + TEXTURE_BORDER_SIZE - 1] = 0;
    }

    // Copy the glyph image, taking the mask format into account
    uint8_t* bitmapBuffer = (uint8_t*) glyph.fImage;
    int stride = glyph.rowBytes();

    switch (format) {
        case SkMask::kA8_Format: {
            if (mGammaTable) {
                for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += stride) {
                    for (cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) {
            for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY++) {
                uint8_t tempCol = bitmapBuffer[bY * stride + bX];
                        uint8_t tempCol = bitmapBuffer[bY + bX];
                        cacheBuffer[cacheY * cacheWidth + cacheX] = mGammaTable[tempCol];
                    }
                }
            } else {
        for (cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) {
            for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY++) {
                uint8_t tempCol = bitmapBuffer[bY * stride + bX];
                cacheBuffer[cacheY * cacheWidth + cacheX] = tempCol;
                for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += stride) {
                    memcpy(&cacheBuffer[cacheY * cacheWidth + startX], &bitmapBuffer[bY],
                            glyph.fWidth);
                }
            }
            break;
        }
        case SkMask::kBW_Format: {
            static const uint8_t COLORS[2] = { 0, 255 };

            for (cacheY = startY; cacheY < endY; cacheY++) {
                cacheX = startX;
                int rowBytes = stride;
                uint8_t* buffer = bitmapBuffer;

                while (--rowBytes >= 0) {
                    uint8_t b = *buffer++;
                    for (int8_t mask = 7; mask >= 0 && cacheX < endX; mask--) {
                        cacheBuffer[cacheY * cacheWidth + cacheX++] = COLORS[(b >> mask) & 0x1];
                    }
                }

                bitmapBuffer += stride;
            }
            break;
        }
        default:
            ALOGW("Unkown glyph format: 0x%x", format);
            break;
    }

    cachedGlyph->mIsValid = true;
+8 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ Font::FontDescription::FontDescription(const SkPaint* paint, const mat4& matrix)
    mScaleX = paint->getTextScaleX();
    mStyle = paint->getStyle();
    mStrokeWidth = paint->getStrokeWidth();
    mAntiAliasing = paint->isAntiAlias();
}

Font::~Font() {
@@ -68,6 +69,7 @@ hash_t Font::FontDescription::hash() const {
    hash = JenkinsHashMix(hash, android::hash_type(mScaleX));
    hash = JenkinsHashMix(hash, android::hash_type(mStyle));
    hash = JenkinsHashMix(hash, android::hash_type(mStrokeWidth));
    hash = JenkinsHashMix(hash, int(mAntiAliasing));
    return JenkinsHashWhiten(hash);
}

@@ -94,6 +96,9 @@ int Font::FontDescription::compare(const Font::FontDescription& lhs,
    if (lhs.mStrokeWidth < rhs.mStrokeWidth) return -1;
    if (lhs.mStrokeWidth > rhs.mStrokeWidth) return +1;

    deltaInt = int(lhs.mAntiAliasing) - int(rhs.mAntiAliasing);
    if (deltaInt != 0) return deltaInt;

    return 0;
}

@@ -384,7 +389,9 @@ void Font::updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyp
    uint32_t startY = 0;

    // Get the bitmap for the glyph
    if (!skiaGlyph.fImage) {
        paint->findImage(skiaGlyph, NULL);
    }
    mState->cacheBitmap(skiaGlyph, glyph, &startX, &startY, precaching);

    if (!glyph->mIsValid) {
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ public:
        float mScaleX;
        uint8_t mStyle;
        float mStrokeWidth;
        bool mAntiAliasing;
    };

    ~Font();
+9 −0
Original line number Diff line number Diff line
@@ -41,6 +41,15 @@
            </intent-filter>
        </activity>

        <activity
                android:name="NoAATextActivity"
                android:label="_NoAAText">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
                android:name="ScaledPathsActivity"
                android:label="_ScaledPaths">
Loading