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 <hwui/Paint.h> 21 #include <minikin/Layout.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; createContent(int width,int height,Canvas & canvas)36 void createContent(int width, int height, Canvas& canvas) override { 37 container = TestUtils::createNode(0, 0, width, height, nullptr); 38 doFrame(0); // update container 39 40 canvas.drawColor(Color::White, SkBlendMode::kSrcOver); 41 canvas.drawRenderNode(container.get()); 42 } 43 doFrame(int frameNr)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 std::unique_ptr<Canvas> canvas(Canvas::create_recording_canvas( 50 container->stagingProperties().getWidth(), 51 container->stagingProperties().getHeight())); 52 53 Paint paint; 54 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 55 paint.setAntiAlias(true); 56 paint.setColor(Color::Black); 57 for (int i = 0; i < 5; i++) { 58 paint.setTextSize(10 + (frameNr % 20) + i * 20); 59 canvas->drawText(text.get(), 0, textLength, textLength, 60 0, 100 * (i + 2), minikin::kBidi_Force_LTR, paint, nullptr); 61 } 62 63 container->setStagingDisplayList(canvas->finishRecording()); 64 } 65 }; 66