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

Commit 2bffd268 authored by Romain Guy's avatar Romain Guy
Browse files

Fix text rendering issue with text scaling.

Change-Id: I1f3ae40025697e8f8ca0616ee6550fe215cadcc8
parent eb851c4e
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -198726,6 +198726,17 @@
 visibility="public"
>
</method>
<method name="isHardwareAccelerated"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="isHorizontalFadingEdgeEnabled"
 return="boolean"
 abstract="false"
+21 −0
Original line number Diff line number Diff line
@@ -7689,6 +7689,25 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
        return 0;
    }

    /**
     * <p>Indicates whether this view is attached to an hardware accelerated
     * window or not.</p>
     * 
     * <p>Even if this method returns true, it does not mean that every call
     * to {@link #draw(android.graphics.Canvas)} will be made with an hardware
     * accelerated {@link android.graphics.Canvas}. For instance, if this view
     * is drawn onto an offscren {@link android.graphics.Bitmap} and its
     * window is hardware accelerated,
     * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely
     * return false, and this method will return true.</p>
     * 
     * @return True if the view is attached to a window and the window is
     *         hardware accelerated; false in any other case.
     */
    public boolean isHardwareAccelerated() {
        return mAttachInfo != null && mAttachInfo.mHardwareAccelerated;
    }
    
    /**
     * Manually render this view (and all of its children) to the given Canvas.
     * The view must have already done a full layout before this function is
@@ -10057,6 +10076,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
        IBinder mPanelParentWindowToken;
        Surface mSurface;

        boolean mHardwareAccelerated;        
        
        /**
         * Scale factor used by the compatibility mode
         */
+2 −0
Original line number Diff line number Diff line
@@ -455,6 +455,7 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
                    mHwRenderer.destroy(true);
                }                
                mHwRenderer = HardwareRenderer.createGlRenderer(2, translucent);
                mAttachInfo.mHardwareAccelerated = true;
            }
        }
    }
@@ -1586,6 +1587,7 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
        if (mHwRenderer != null) {
            mHwRenderer.destroy(true);
            mHwRenderer = null;
            mAttachInfo.mHardwareAccelerated = false;
        }

        mSurface.release();
+2 −0
Original line number Diff line number Diff line
@@ -5118,6 +5118,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    }

    private boolean compressText(float width) {
        if (isHardwareAccelerated()) return false;
        
        // Only compress the text if it hasn't been compressed by the previous pass
        if (width > 0.0f && mLayout != null && getLineCount() == 1 && !mUserSetTextScaleX &&
                mTextPaint.getTextScaleX() == 1.0f) {
+17 −7
Original line number Diff line number Diff line
@@ -166,6 +166,8 @@ void Font::measureUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t
    renderUTF(paint, text, start, len, numGlyphs, 0, 0, MEASURE, NULL, 0, 0, bounds);
}

#define SkAutoKern_AdjustF(prev, next)    (((next) - (prev) + 32) >> 6 << 16)

void Font::renderUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t len,
        int numGlyphs, int x, int y, RenderMode mode, uint8_t *bitmap,
        uint32_t bitmapW, uint32_t bitmapH,Rect *bounds) {
@@ -173,12 +175,16 @@ void Font::renderUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t
        return;
    }

    int penX = x, penY = y;
    SkFixed penX = SkIntToFixed(x);
    int penY = y;
    int glyphsLeft = 1;
    if (numGlyphs > 0) {
        glyphsLeft = numGlyphs;
    }

    SkFixed prevRsbDelta = 0;
    penX += SK_Fixed1 / 2;

    text += start;

    while (glyphsLeft > 0) {
@@ -190,23 +196,25 @@ void Font::renderUTF(SkPaint* paint, const char* text, uint32_t start, uint32_t
        }

        CachedGlyphInfo* cachedGlyph = getCachedUTFChar(paint, utfChar);
        penX += SkAutoKern_AdjustF(prevRsbDelta, cachedGlyph->mLsbDelta);
        prevRsbDelta = cachedGlyph->mRsbDelta;

        // If it's still not valid, we couldn't cache it, so we shouldn't draw garbage
        if (cachedGlyph->mIsValid) {
            switch(mode) {
            case FRAMEBUFFER:
                drawCachedGlyph(cachedGlyph, penX, penY);
                drawCachedGlyph(cachedGlyph, SkFixedFloor(penX), penY);
                break;
            case BITMAP:
                drawCachedGlyph(cachedGlyph, penX, penY, bitmap, bitmapW, bitmapH);
                drawCachedGlyph(cachedGlyph, SkFixedFloor(penX), penY, bitmap, bitmapW, bitmapH);
                break;
            case MEASURE:
                measureCachedGlyph(cachedGlyph, penX, penY, bounds);
                measureCachedGlyph(cachedGlyph, SkFixedFloor(penX), penY, bounds);
                break;
            }
        }

        penX += SkFixedFloor(cachedGlyph->mAdvanceX);
        penX += cachedGlyph->mAdvanceX;

        // If we were given a specific number of glyphs, decrement
        if (numGlyphs > 0) {
@@ -220,6 +228,8 @@ void Font::updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyp
    glyph->mAdvanceY = skiaGlyph.fAdvanceY;
    glyph->mBitmapLeft = skiaGlyph.fLeft;
    glyph->mBitmapTop = skiaGlyph.fTop;
    glyph->mLsbDelta = skiaGlyph.fLsbDelta;
    glyph->mRsbDelta = skiaGlyph.fRsbDelta;

    uint32_t startX = 0;
    uint32_t startY = 0;
@@ -352,7 +362,7 @@ void FontRenderer::flushAllAndInvalidate() {

bool FontRenderer::cacheBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY) {
    // If the glyph is too tall, don't cache it
    if (glyph.fWidth > mCacheLines[mCacheLines.size() - 1]->mMaxHeight) {
    if (glyph.fHeight > mCacheLines[mCacheLines.size() - 1]->mMaxHeight) {
        LOGE("Font size to large to fit in cache. width, height = %i, %i",
                (int) glyph.fWidth, (int) glyph.fHeight);
        return false;
Loading