1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "TestSceneBase.h" 18 #include "utils/Color.h" 19 20 #include <minikin/Layout.h> 21 #include <hwui/Paint.h> 22 23 #include <cstdio> 24 25 class GlyphStressAnimation; 26 27 static TestScene::Registrar _GlyphStress(TestScene::Info{ 28 "glyphstress", 29 "A stress test for both the glyph cache, and glyph rendering.", 30 TestScene::simpleCreateScene<GlyphStressAnimation> 31 }); 32 33 class GlyphStressAnimation : public TestScene { 34 public: 35 sp<RenderNode> container; 36 void createContent(int width, int height, TestCanvas& canvas) override { 37 container = TestUtils::createNode(0, 0, width, height, nullptr); 38 doFrame(0); // update container 39 40 canvas.drawColor(Color::White, SkXfermode::kSrcOver_Mode); 41 canvas.drawRenderNode(container.get()); 42 } 43 44 void doFrame(int frameNr) override { 45 std::unique_ptr<uint16_t[]> text = TestUtils::asciiToUtf16( 46 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); 47 ssize_t textLength = 26 * 2; 48 49 TestCanvas canvas( 50 container->stagingProperties().getWidth(), 51 container->stagingProperties().getHeight()); 52 Paint paint; 53 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 54 paint.setAntiAlias(true); 55 paint.setColor(Color::Black); 56 for (int i = 0; i < 5; i++) { 57 paint.setTextSize(10 + (frameNr % 20) + i * 20); 58 canvas.drawText(text.get(), 0, textLength, textLength, 59 0, 100 * (i + 2), kBidi_Force_LTR, paint, nullptr); 60 } 61 62 container->setStagingDisplayList(canvas.finishRecording(), nullptr); 63 } 64 }; 65