Debian Codegraph @

libs/hwui/tests/common/scenes/GlyphStressAnimation.cpp

raw symbols SCIP
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", "A stress test for both the glyph cache, and glyph rendering.",
29 TestScene::simpleCreateScene<GlyphStressAnimation>});
30
31 class GlyphStressAnimation : public TestScene {
32 public:
33 sp<RenderNode> container;
34 void createContent(int width, int height, Canvas& canvas) override {
35 container = TestUtils::createNode(0, 0, width, height, nullptr);
36 doFrame(0); // update container
37
38 canvas.drawColor(Color::White, SkBlendMode::kSrcOver);
39 canvas.drawRenderNode(container.get());
40 }
41
42 void doFrame(int frameNr) override {
43 const char* text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
44
45 std::unique_ptr<Canvas> canvas(
46 Canvas::create_recording_canvas(container->stagingProperties().getWidth(),
47 container->stagingProperties().getHeight(),
48 container.get()));
49
50 Paint paint;
51 paint.setAntiAlias(true);
52 paint.setColor(Color::Black);
53 for (int i = 0; i < 5; i++) {
54 paint.getSkFont().setSize(10 + (frameNr % 20) + i * 20);
55 TestUtils::drawUtf8ToCanvas(canvas.get(), text, paint, 0, 100 * (i + 2));
56 }
57
58 canvas->finishRecording(container.get());
59 }
60 };