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
This commit is contained in:
@@ -122,15 +122,19 @@ 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,
|
||||
nullptr);
|
||||
SkPaint glyphPaint(paint);
|
||||
glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
canvas->drawTextOnPath(utf16.get(), strlen(text), minikin::Bidi::LTR, path, 0, 0, glyphPaint,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void TestUtils::TestTask::run() {
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -42,10 +42,8 @@ public:
|
||||
|
||||
mBluePaint.setColor(SkColorSetARGB(255, 0, 0, 255));
|
||||
mBluePaint.setTextSize(padding);
|
||||
mBluePaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
mGreenPaint.setColor(SkColorSetARGB(255, 0, 255, 0));
|
||||
mGreenPaint.setTextSize(padding);
|
||||
mGreenPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
|
||||
// interleave drawText and drawRect with saveLayer ops
|
||||
for (int i = 0; i < regions; i++, top += smallRectHeight) {
|
||||
@@ -54,18 +52,15 @@ public:
|
||||
canvas.drawColor(SkColorSetARGB(255, 255, 255, 0), SkBlendMode::kSrcOver);
|
||||
std::string stri = std::to_string(i);
|
||||
std::string offscreen = "offscreen line " + stri;
|
||||
std::unique_ptr<uint16_t[]> offtext = TestUtils::asciiToUtf16(offscreen.c_str());
|
||||
canvas.drawText(offtext.get(), 0, offscreen.length(), offscreen.length(), bounds.fLeft,
|
||||
top + padding, minikin::Bidi::FORCE_LTR, mBluePaint, nullptr);
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, offscreen.c_str(), mBluePaint, bounds.fLeft,
|
||||
top + padding);
|
||||
canvas.restore();
|
||||
|
||||
canvas.drawRect(bounds.fLeft, top + padding, bounds.fRight,
|
||||
top + smallRectHeight - padding, mBluePaint);
|
||||
std::string onscreen = "onscreen line " + stri;
|
||||
std::unique_ptr<uint16_t[]> ontext = TestUtils::asciiToUtf16(onscreen.c_str());
|
||||
canvas.drawText(ontext.get(), 0, onscreen.length(), onscreen.length(), bounds.fLeft,
|
||||
top + smallRectHeight - padding, minikin::Bidi::FORCE_LTR, mGreenPaint,
|
||||
nullptr);
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, onscreen.c_str(), mGreenPaint, bounds.fLeft,
|
||||
top + smallRectHeight - padding);
|
||||
}
|
||||
}
|
||||
void doFrame(int frameNr) override {}
|
||||
|
||||
@@ -29,7 +29,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);
|
||||
|
||||
|
||||
@@ -117,7 +117,6 @@ private:
|
||||
canvas.drawColor(0xFFFFEEEE, SkBlendMode::kSrcOver);
|
||||
|
||||
SkPaint paint;
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
|
||||
|
||||
@@ -537,7 +537,6 @@ RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, regionClipStopsMerge) {
|
||||
canvas.save(SaveFlags::MatrixClip);
|
||||
canvas.clipPath(&path, SkClipOp::kIntersect);
|
||||
SkPaint paint;
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(50);
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, "Test string1", paint, 100, 100);
|
||||
@@ -569,7 +568,6 @@ RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, textMerging) {
|
||||
auto node = TestUtils::createNode<RecordingCanvas>(0, 0, 400, 400, [](RenderProperties& props,
|
||||
RecordingCanvas& canvas) {
|
||||
SkPaint paint;
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(50);
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, "Test string1", paint, 100, 0); // will be top clipped
|
||||
@@ -603,7 +601,6 @@ RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, textStrikethrough) {
|
||||
textPaint.setAntiAlias(true);
|
||||
textPaint.setTextSize(20);
|
||||
textPaint.setFlags(textPaint.getFlags() | SkPaint::kStrikeThruText_ReserveFlag);
|
||||
textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
for (int i = 0; i < LOOPS; i++) {
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, "test text", textPaint, 10, 100 * (i + 1));
|
||||
}
|
||||
@@ -654,7 +651,6 @@ RENDERTHREAD_OPENGL_PIPELINE_TEST(FrameBuilder, textStyle) {
|
||||
auto node = TestUtils::createNode<RecordingCanvas>(
|
||||
0, 0, 400, 400, [](RenderProperties& props, RecordingCanvas& canvas) {
|
||||
SkPaint paint;
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(50);
|
||||
paint.setStrokeWidth(10);
|
||||
|
||||
@@ -175,7 +175,6 @@ OPENGL_PIPELINE_TEST(RecordingCanvas, drawGlyphs) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(20);
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, "test text", paint, 25, 25);
|
||||
});
|
||||
|
||||
@@ -196,7 +195,6 @@ OPENGL_PIPELINE_TEST(RecordingCanvas, drawGlyphs_strikeThruAndUnderline) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(20);
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
uint32_t flags = paint.getFlags();
|
||||
@@ -238,7 +236,6 @@ OPENGL_PIPELINE_TEST(RecordingCanvas, drawGlyphs_forceAlignLeft) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(20);
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
paint.setTextAlign(SkPaint::kLeft_Align);
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, "test text", paint, 25, 25);
|
||||
paint.setTextAlign(SkPaint::kCenter_Align);
|
||||
@@ -805,9 +802,7 @@ OPENGL_PIPELINE_TEST(RecordingCanvas, drawText) {
|
||||
Paint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(20);
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
std::unique_ptr<uint16_t[]> dst = TestUtils::asciiToUtf16("HELLO");
|
||||
canvas.drawText(dst.get(), 0, 5, 5, 25, 25, minikin::Bidi::FORCE_LTR, paint, NULL);
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, "HELLO", paint, 25, 25);
|
||||
});
|
||||
|
||||
int count = 0;
|
||||
@@ -829,9 +824,7 @@ OPENGL_PIPELINE_TEST(RecordingCanvas, drawTextInHighContrast) {
|
||||
paint.setColor(SK_ColorWHITE);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(20);
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
std::unique_ptr<uint16_t[]> dst = TestUtils::asciiToUtf16("HELLO");
|
||||
canvas.drawText(dst.get(), 0, 5, 5, 25, 25, minikin::Bidi::FORCE_LTR, paint, NULL);
|
||||
TestUtils::drawUtf8ToCanvas(&canvas, "HELLO", paint, 25, 25);
|
||||
});
|
||||
Properties::enableHighContrastText = false;
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ OPENGL_PIPELINE_TEST(SkiaCanvasProxy, drawGlyphsViaPicture) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(20);
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
static const char* text = "testing text bounds";
|
||||
|
||||
// draw text directly into Recording canvas
|
||||
|
||||
@@ -29,6 +29,7 @@ using namespace android::uirenderer;
|
||||
RENDERTHREAD_OPENGL_PIPELINE_TEST(TextDropShadowCache, addRemove) {
|
||||
SkPaint paint;
|
||||
paint.setTextSize(20);
|
||||
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
|
||||
GammaFontRenderer gammaFontRenderer;
|
||||
FontRenderer& fontRenderer = gammaFontRenderer.getFontRenderer();
|
||||
|
||||
Reference in New Issue
Block a user