Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright (C) 2017 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 <hwui/Paint.h>
18 #include <minikin/Layout.h>
19 #include <string>
20 #include "TestSceneBase.h"
21
22 class SaveLayer2Animation;
23
24 static TestScene::Registrar _SaveLayer(TestScene::Info{
25 "savelayer2",
26 "Interleaving 20 drawText/drawRect ops with saveLayer"
27 "Tests the clipped saveLayer performance and FBO switching overhead.",
28 TestScene::simpleCreateScene<SaveLayer2Animation>});
29
30 class SaveLayer2Animation : public TestScene {
31 public:
32 Paint mBluePaint;
33 Paint mGreenPaint;
34
35 void createContent(int width, int height, Canvas& canvas) override {
36 canvas.drawColor(SkColorSetARGB(255, 255, 0, 0), SkBlendMode::kSrcOver);
37 SkIRect bounds = SkIRect::MakeWH(width, height);
38 int regions = 20;
39 int smallRectHeight = (bounds.height() / regions);
40 int padding = smallRectHeight / 4;
41 int top = bounds.fTop;
42
43 mBluePaint.setColor(SkColorSetARGB(255, 0, 0, 255));
44 mBluePaint.getSkFont().setSize(padding);
45 mGreenPaint.setColor(SkColorSetARGB(255, 0, 255, 0));
46 mGreenPaint.getSkFont().setSize(padding);
47
48 // interleave drawText and drawRect with saveLayer ops
49 for (int i = 0; i < regions; i++, top += smallRectHeight) {
50 canvas.saveLayer(bounds.fLeft, top, bounds.fRight, top + padding, &mBluePaint);
51 canvas.drawColor(SkColorSetARGB(255, 255, 255, 0), SkBlendMode::kSrcOver);
52 std::string stri = std::to_string(i);
53 std::string offscreen = "offscreen line " + stri;
54 TestUtils::drawUtf8ToCanvas(&canvas, offscreen.c_str(), mBluePaint, bounds.fLeft,
55 top + padding);
56 canvas.restore();
57
58 canvas.drawRect(bounds.fLeft, top + padding, bounds.fRight,
59 top + smallRectHeight - padding, mBluePaint);
60 std::string onscreen = "onscreen line " + stri;
61 TestUtils::drawUtf8ToCanvas(&canvas, onscreen.c_str(), mGreenPaint, bounds.fLeft,
62 top + smallRectHeight - padding);
63 }
64 }
65 void doFrame(int frameNr) override {}
66 };