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

Commit ec083812 authored by Stan Iliev's avatar Stan Iliev
Browse files

Refactor TestUtils::drawUtf8ToCanvas usage in macrobench tests

Set text encoding inside TestUtils::drawUtf8ToCanvas and use
TestUtils::drawUtf8ToCanvas instead Canvas::drawText.
This CL is a follow-up of ag/3287411.

Test: Ran macrobench tests
Change-Id: I1b2f014d17f26ccc8fbdae9cfeea4ac25fd4c51f
parent c80114c8
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -122,14 +122,18 @@ void TestUtils::layoutTextUnscaled(const SkPaint& paint, const char* text,
void TestUtils::drawUtf8ToCanvas(Canvas* canvas, const char* text, const SkPaint& paint, float x,
                                 float y) {
    auto utf16 = asciiToUtf16(text);
    canvas->drawText(utf16.get(), 0, strlen(text), strlen(text), x, y, minikin::Bidi::LTR, paint,
                     nullptr);
    SkPaint glyphPaint(paint);
    glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    canvas->drawText(utf16.get(), 0, strlen(text), strlen(text), x, y, minikin::Bidi::LTR,
            glyphPaint, nullptr);
}

void TestUtils::drawUtf8ToCanvas(Canvas* canvas, const char* text, const SkPaint& paint,
                                 const SkPath& path) {
    auto utf16 = asciiToUtf16(text);
    canvas->drawTextOnPath(utf16.get(), strlen(text), minikin::Bidi::LTR, path, 0, 0, paint,
    SkPaint glyphPaint(paint);
    glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
    canvas->drawTextOnPath(utf16.get(), strlen(text), minikin::Bidi::LTR, path, 0, 0, glyphPaint,
            nullptr);
}

+2 −6
Original line number Diff line number Diff line
@@ -40,22 +40,18 @@ public:
    }

    void doFrame(int frameNr) override {
        std::unique_ptr<uint16_t[]> text =
                TestUtils::asciiToUtf16("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
        ssize_t textLength = 26 * 2;
        const char* text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

        std::unique_ptr<Canvas> canvas(
                Canvas::create_recording_canvas(container->stagingProperties().getWidth(),
                                                container->stagingProperties().getHeight()));

        Paint paint;
        paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
        paint.setAntiAlias(true);
        paint.setColor(Color::Black);
        for (int i = 0; i < 5; i++) {
            paint.setTextSize(10 + (frameNr % 20) + i * 20);
            canvas->drawText(text.get(), 0, textLength, textLength, 0, 100 * (i + 2),
                             minikin::Bidi::FORCE_LTR, paint, nullptr);
            TestUtils::drawUtf8ToCanvas(canvas.get(), text, paint, 0, 100 * (i + 2));
        }

        container->setStagingDisplayList(canvas->finishRecording());
+0 −1
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ class ListOfFadedTextAnimation : public TestListViewSceneBase {
        SkPaint textPaint;
        textPaint.setTextSize(dp(20));
        textPaint.setAntiAlias(true);
        textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
        TestUtils::drawUtf8ToCanvas(&canvas, "not that long long text", textPaint, dp(10), dp(30));

        SkPoint pts[2];
+0 −1
Original line number Diff line number Diff line
@@ -83,7 +83,6 @@ class ListViewAnimation : public TestListViewSceneBase {
        canvas.drawRoundRect(0, 0, itemWidth, itemHeight, dp(6), dp(6), roundRectPaint);

        SkPaint textPaint;
        textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
        textPaint.setColor(rand() % 2 ? Color::Black : Color::Grey_500);
        textPaint.setTextSize(dp(20));
        textPaint.setAntiAlias(true);
+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ public:
        card = TestUtils::createNode(
                0, 0, width, height, [&](RenderProperties& props, Canvas& canvas) {
                    SkPaint paint;
                    paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
                    paint.setAntiAlias(true);
                    paint.setTextSize(50);

Loading