blob: 82612206cac8278acb26ccdec7cf1d064a10cc1d [file] [log] [blame]
John Reck16c9d6a2015-11-17 15:51:08 -08001/*
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 "AnimationContext.h"
John Reck16c9d6a2015-11-17 15:51:08 -080018#include "RenderNode.h"
Chris Craik27e58b42015-12-07 10:01:38 -080019#include "tests/common/TestContext.h"
20#include "tests/common/TestScene.h"
Chris Craik8160f202015-12-02 14:50:25 -080021#include "tests/common/scenes/TestSceneBase.h"
John Reck16c9d6a2015-11-17 15:51:08 -080022#include "renderthread/RenderProxy.h"
23#include "renderthread/RenderTask.h"
24
25#include <cutils/log.h>
26#include <gui/Surface.h>
27#include <ui/PixelFormat.h>
28
29using namespace android;
30using namespace android::uirenderer;
31using namespace android::uirenderer::renderthread;
32using namespace android::uirenderer::test;
33
34class ContextFactory : public IContextFactory {
35public:
36 virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) override {
37 return new AnimationContext(clock);
38 }
39};
40
Chris Craik27e58b42015-12-07 10:01:38 -080041void run(const TestScene::Info& info, const TestScene::Options& opts) {
John Reck16c9d6a2015-11-17 15:51:08 -080042 // Switch to the real display
43 gDisplay = getBuiltInDisplay();
44
45 std::unique_ptr<TestScene> scene(info.createScene(opts));
46
47 TestContext testContext;
48
49 // create the native surface
50 const int width = gDisplay.w;
51 const int height = gDisplay.h;
52 sp<Surface> surface = testContext.surface();
53
54 sp<RenderNode> rootNode = TestUtils::createNode(0, 0, width, height,
55 [&scene, width, height](RenderProperties& props, TestCanvas& canvas) {
56 props.setClipToBounds(false);
57 scene->createContent(width, height, canvas);
58 });
59
60 ContextFactory factory;
61 std::unique_ptr<RenderProxy> proxy(new RenderProxy(false,
62 rootNode.get(), &factory));
63 proxy->loadSystemProperties();
64 proxy->initialize(surface);
65 float lightX = width / 2.0;
66 proxy->setup(width, height, dp(800.0f), 255 * 0.075, 255 * 0.15);
67 proxy->setLightCenter((Vector3){lightX, dp(-200.0f), dp(800.0f)});
68
69 // Do a few cold runs then reset the stats so that the caches are all hot
70 for (int i = 0; i < 3; i++) {
71 testContext.waitForVsync();
72 nsecs_t vsync = systemTime(CLOCK_MONOTONIC);
73 UiFrameInfoBuilder(proxy->frameInfo()).setVsync(vsync, vsync);
74 proxy->syncAndDrawFrame();
75 }
76 proxy->resetProfileInfo();
77
78 for (int i = 0; i < opts.count; i++) {
79 testContext.waitForVsync();
80
81 ATRACE_NAME("UI-Draw Frame");
82 nsecs_t vsync = systemTime(CLOCK_MONOTONIC);
83 UiFrameInfoBuilder(proxy->frameInfo()).setVsync(vsync, vsync);
84 scene->doFrame(i);
85 proxy->syncAndDrawFrame();
86 }
87
88 proxy->dumpProfileInfo(STDOUT_FILENO, 0);
89}