blob: 542bbaee1605f88a31c391225f355a6c4d66a778 [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 Reck84e390c2015-01-05 09:42:52 -080025static DisplayInfo getBuiltInDisplay() {
26 DisplayInfo display;
John Reck94c40fe2014-10-08 09:28:43 -070027 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
John Reck84e390c2015-01-05 09:42:52 -080028 ISurfaceComposer::eDisplayIdMain));
29 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display);
John Reck94c40fe2014-10-08 09:28:43 -070030 LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n");
John Reck84e390c2015-01-05 09:42:52 -080031 return display;
John Reck94c40fe2014-10-08 09:28:43 -070032}
33
John Reck84e390c2015-01-05 09:42:52 -080034android::DisplayInfo gDisplay = getBuiltInDisplay();
John Reck94c40fe2014-10-08 09:28:43 -070035
John Reck84e390c2015-01-05 09:42:52 -080036TestContext::TestContext() {
37 mLooper = new Looper(true);
38 mSurfaceComposerClient = new SurfaceComposerClient();
39 mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT,
40 Looper::EVENT_INPUT, nullptr, nullptr);
John Reck94c40fe2014-10-08 09:28:43 -070041}
John Reck84e390c2015-01-05 09:42:52 -080042
43TestContext::~TestContext() {}
44
45sp<Surface> TestContext::surface() {
46 if (!mSurfaceControl.get()) {
47 mSurfaceControl = mSurfaceComposerClient->createSurface(String8("HwuiTest"),
48 gDisplay.w, gDisplay.h, PIXEL_FORMAT_RGBX_8888);
49
50 SurfaceComposerClient::openGlobalTransaction();
51 mSurfaceControl->setLayer(0x7FFFFFF);
52 mSurfaceControl->show();
53 SurfaceComposerClient::closeGlobalTransaction();
54 }
55
56 return mSurfaceControl->getSurface();
57}
58
59void TestContext::waitForVsync() {
60 // Request vsync
61 mDisplayEventReceiver.requestNextVsync();
62
63 // Wait
64 mLooper->pollOnce(-1);
65
66 // Drain it
67 DisplayEventReceiver::Event buf[100];
68 while (mDisplayEventReceiver.getEvents(buf, 100) > 0) { }
69}
70
71} // namespace test
72} // namespace uirenderer
73} // namespace android
74