194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck/*
294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * Copyright (C) 2014 The Android Open Source Project
394c40fe92117f301c7758de2861ab0c1d6cfded0John Reck *
494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * Licensed under the Apache License, Version 2.0 (the "License");
594c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * you may not use this file except in compliance with the License.
694c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * You may obtain a copy of the License at
794c40fe92117f301c7758de2861ab0c1d6cfded0John Reck *
894c40fe92117f301c7758de2861ab0c1d6cfded0John Reck *      http://www.apache.org/licenses/LICENSE-2.0
994c40fe92117f301c7758de2861ab0c1d6cfded0John Reck *
1094c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * Unless required by applicable law or agreed to in writing, software
1194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * distributed under the License is distributed on an "AS IS" BASIS,
1294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1394c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * See the License for the specific language governing permissions and
1494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * limitations under the License.
1594c40fe92117f301c7758de2861ab0c1d6cfded0John Reck */
1694c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
1727e58b4f54d693ff1db7ab2edb5d47ca296c1278Chris Craik#include "tests/common/TestContext.h"
1894c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
1984e390cc903ae4027276c33371ad5237b550910fJohn Recknamespace android {
2084e390cc903ae4027276c33371ad5237b550910fJohn Recknamespace uirenderer {
2184e390cc903ae4027276c33371ad5237b550910fJohn Recknamespace test {
2294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
2384e390cc903ae4027276c33371ad5237b550910fJohn Reckstatic const int IDENT_DISPLAYEVENT = 1;
2494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
25e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reckstatic android::DisplayInfo DUMMY_DISPLAY {
26e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    1080, //w
27e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    1920, //h
28e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    320.0, // xdpi
29e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    320.0, // ydpi
30e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    60.0, // fps
31e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    2.0, // density
32e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    0, // orientation
33e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    false, // secure?
34e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    0, // appVsyncOffset
35e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    0, // presentationDeadline
36e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    0, // colorTransform
37e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck};
38e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck
39e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn ReckDisplayInfo getBuiltInDisplay() {
40e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck#if !HWUI_NULL_GPU
4184e390cc903ae4027276c33371ad5237b550910fJohn Reck    DisplayInfo display;
4294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
4384e390cc903ae4027276c33371ad5237b550910fJohn Reck            ISurfaceComposer::eDisplayIdMain));
4484e390cc903ae4027276c33371ad5237b550910fJohn Reck    status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display);
4594c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n");
4684e390cc903ae4027276c33371ad5237b550910fJohn Reck    return display;
47e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck#else
48e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck    return DUMMY_DISPLAY;
49e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck#endif
5084e390cc903ae4027276c33371ad5237b550910fJohn Reck}
5184e390cc903ae4027276c33371ad5237b550910fJohn Reck
52e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reck// Initialize to a dummy default
53e702c9cd6a2b9b1378f740a79b0e349a9b02660fJohn Reckandroid::DisplayInfo gDisplay = DUMMY_DISPLAY;
5484e390cc903ae4027276c33371ad5237b550910fJohn Reck
5584e390cc903ae4027276c33371ad5237b550910fJohn ReckTestContext::TestContext() {
5684e390cc903ae4027276c33371ad5237b550910fJohn Reck    mLooper = new Looper(true);
5784e390cc903ae4027276c33371ad5237b550910fJohn Reck    mSurfaceComposerClient = new SurfaceComposerClient();
5884e390cc903ae4027276c33371ad5237b550910fJohn Reck    mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT,
5984e390cc903ae4027276c33371ad5237b550910fJohn Reck            Looper::EVENT_INPUT, nullptr, nullptr);
6094c40fe92117f301c7758de2861ab0c1d6cfded0John Reck}
6194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
6284e390cc903ae4027276c33371ad5237b550910fJohn ReckTestContext::~TestContext() {}
6384e390cc903ae4027276c33371ad5237b550910fJohn Reck
6484e390cc903ae4027276c33371ad5237b550910fJohn Recksp<Surface> TestContext::surface() {
6584e390cc903ae4027276c33371ad5237b550910fJohn Reck    if (!mSurfaceControl.get()) {
6684e390cc903ae4027276c33371ad5237b550910fJohn Reck        mSurfaceControl = mSurfaceComposerClient->createSurface(String8("HwuiTest"),
6784e390cc903ae4027276c33371ad5237b550910fJohn Reck                gDisplay.w, gDisplay.h, PIXEL_FORMAT_RGBX_8888);
6894c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
6984e390cc903ae4027276c33371ad5237b550910fJohn Reck        SurfaceComposerClient::openGlobalTransaction();
7084e390cc903ae4027276c33371ad5237b550910fJohn Reck        mSurfaceControl->setLayer(0x7FFFFFF);
7184e390cc903ae4027276c33371ad5237b550910fJohn Reck        mSurfaceControl->show();
7284e390cc903ae4027276c33371ad5237b550910fJohn Reck        SurfaceComposerClient::closeGlobalTransaction();
7384e390cc903ae4027276c33371ad5237b550910fJohn Reck    }
7494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
7584e390cc903ae4027276c33371ad5237b550910fJohn Reck    return mSurfaceControl->getSurface();
7694c40fe92117f301c7758de2861ab0c1d6cfded0John Reck}
7784e390cc903ae4027276c33371ad5237b550910fJohn Reck
7884e390cc903ae4027276c33371ad5237b550910fJohn Reckvoid TestContext::waitForVsync() {
79c36df952292b69920d4764a8a37361073fcf4f2cJohn Reck#if !HWUI_NULL_GPU
8084e390cc903ae4027276c33371ad5237b550910fJohn Reck    // Request vsync
8184e390cc903ae4027276c33371ad5237b550910fJohn Reck    mDisplayEventReceiver.requestNextVsync();
8284e390cc903ae4027276c33371ad5237b550910fJohn Reck
8384e390cc903ae4027276c33371ad5237b550910fJohn Reck    // Wait
8484e390cc903ae4027276c33371ad5237b550910fJohn Reck    mLooper->pollOnce(-1);
8584e390cc903ae4027276c33371ad5237b550910fJohn Reck
8684e390cc903ae4027276c33371ad5237b550910fJohn Reck    // Drain it
8784e390cc903ae4027276c33371ad5237b550910fJohn Reck    DisplayEventReceiver::Event buf[100];
8884e390cc903ae4027276c33371ad5237b550910fJohn Reck    while (mDisplayEventReceiver.getEvents(buf, 100) > 0) { }
89c36df952292b69920d4764a8a37361073fcf4f2cJohn Reck#endif
9084e390cc903ae4027276c33371ad5237b550910fJohn Reck}
9184e390cc903ae4027276c33371ad5237b550910fJohn Reck
9284e390cc903ae4027276c33371ad5237b550910fJohn Reck} // namespace test
9384e390cc903ae4027276c33371ad5237b550910fJohn Reck} // namespace uirenderer
9484e390cc903ae4027276c33371ad5237b550910fJohn Reck} // namespace android
95