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 <SkBlendMode.h> 24 25 #include <cstdio> 26 27 class GlyphStressAnimation; 28 29 static TestScene::Registrar _GlyphStress(TestScene::Info{ 30 "glyphstress", "A stress test for both the glyph cache, and glyph rendering.", 31 TestScene::simpleCreateScene<GlyphStressAnimation>}); 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 const char* text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 46 47 std::unique_ptr<Canvas> canvas( 48 Canvas::create_recording_canvas(container->stagingProperties().getWidth(), 49 container->stagingProperties().getHeight(), 50 container.get())); 51 52 Paint paint; 53 paint.setAntiAlias(true); 54 paint.setColor(Color::Black); 55 for (int i = 0; i < 5; i++) { 56 paint.getSkFont().setSize(10 + (frameNr % 20) + i * 20); 57 TestUtils::drawUtf8ToCanvas(canvas.get(), text, paint, 0, 100 * (i + 2)); 58 } 59 60 canvas->finishRecording(container.get()); 61 } 62 }; 63