blob: ba763a8def6259814914366b48970c594dbc860a [file] [log] [blame]
John Reck94c40fe2014-10-08 09:28:43 -07001/*
2 * Copyright (C) 2014 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 "TestContext.h"
18
John Reck84e390c2015-01-05 09:42:52 -080019namespace android {
20namespace uirenderer {
21namespace test {
John Reck94c40fe2014-10-08 09:28:43 -070022
John Reck84e390c2015-01-05 09:42:52 -080023static const int IDENT_DISPLAYEVENT = 1;
John Reck94c40fe2014-10-08 09:28:43 -070024
John Recke702c9c2015-10-07 10:26:02 -070025static android::DisplayInfo DUMMY_DISPLAY {
26 1080, //w
27 1920, //h
28 320.0, // xdpi
29 320.0, // ydpi
30 60.0, // fps
31 2.0, // density
32 0, // orientation
33 false, // secure?
34 0, // appVsyncOffset
35 0, // presentationDeadline
36 0, // colorTransform
37};
38
39DisplayInfo getBuiltInDisplay() {
40#if !HWUI_NULL_GPU
John Reck84e390c2015-01-05 09:42:52 -080041 DisplayInfo display;
John Reck94c40fe2014-10-08 09:28:43 -070042 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
John Reck84e390c2015-01-05 09:42:52 -080043 ISurfaceComposer::eDisplayIdMain));
44 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display);
John Reck94c40fe2014-10-08 09:28:43 -070045 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n");
John Reck84e390c2015-01-05 09:42:52 -080046 return display;
John Recke702c9c2015-10-07 10:26:02 -070047#else
48 return DUMMY_DISPLAY;
49#endif
John Reck94c40fe2014-10-08 09:28:43 -070050}
51
John Recke702c9c2015-10-07 10:26:02 -070052// Initialize to a dummy default
53android::DisplayInfo gDisplay = DUMMY_DISPLAY;
John Reck94c40fe2014-10-08 09:28:43 -070054
John Reck84e390c2015-01-05 09:42:52 -080055TestContext::TestContext() {
56 mLooper = new Looper(true);
57 mSurfaceComposerClient = new SurfaceComposerClient();
58 mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT,
59 Looper::EVENT_INPUT, nullptr, nullptr);
John Reck94c40fe2014-10-08 09:28:43 -070060}
John Reck84e390c2015-01-05 09:42:52 -080061
62TestContext::~TestContext() {}
63
64sp<Surface> TestContext::surface() {
65 if (!mSurfaceControl.get()) {
66 mSurfaceControl = mSurfaceComposerClient->createSurface(String8("HwuiTest"),
67 gDisplay.w, gDisplay.h, PIXEL_FORMAT_RGBX_8888);
68
69 SurfaceComposerClient::openGlobalTransaction();
70 mSurfaceControl->setLayer(0x7FFFFFF);
71 mSurfaceControl->show();
72 SurfaceComposerClient::closeGlobalTransaction();
73 }
74
75 return mSurfaceControl->getSurface();
76}
77
78void TestContext::waitForVsync() {
John Reckc36df952015-07-29 10:09:36 -070079#if !HWUI_NULL_GPU
John Reck84e390c2015-01-05 09:42:52 -080080 // Request vsync
81 mDisplayEventReceiver.requestNextVsync();
82
83 // Wait
84 mLooper->pollOnce(-1);
85
86 // Drain it
87 DisplayEventReceiver::Event buf[100];
88 while (mDisplayEventReceiver.getEvents(buf, 100) > 0) { }
John Reckc36df952015-07-29 10:09:36 -070089#endif
John Reck84e390c2015-01-05 09:42:52 -080090}
91
92} // namespace test
93} // namespace uirenderer
94} // namespace android