• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "tests/common/TestContext.h"
18 
19 namespace android {
20 namespace uirenderer {
21 namespace test {
22 
23 static const int IDENT_DISPLAYEVENT = 1;
24 
25 static 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 };
37 
getBuiltInDisplay()38 DisplayInfo getBuiltInDisplay() {
39 #if !HWUI_NULL_GPU
40     DisplayInfo display;
41     sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
42             ISurfaceComposer::eDisplayIdMain));
43     status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display);
44     LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n");
45     return display;
46 #else
47     return DUMMY_DISPLAY;
48 #endif
49 }
50 
51 // Initialize to a dummy default
52 android::DisplayInfo gDisplay = DUMMY_DISPLAY;
53 
TestContext()54 TestContext::TestContext() {
55     mLooper = new Looper(true);
56     mSurfaceComposerClient = new SurfaceComposerClient();
57     mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT,
58             Looper::EVENT_INPUT, nullptr, nullptr);
59 }
60 
~TestContext()61 TestContext::~TestContext() {}
62 
surface()63 sp<Surface> TestContext::surface() {
64     if (!mSurfaceControl.get()) {
65         mSurfaceControl = mSurfaceComposerClient->createSurface(String8("HwuiTest"),
66                 gDisplay.w, gDisplay.h, PIXEL_FORMAT_RGBX_8888);
67 
68         SurfaceComposerClient::openGlobalTransaction();
69         mSurfaceControl->setLayer(0x7FFFFFF);
70         mSurfaceControl->show();
71         SurfaceComposerClient::closeGlobalTransaction();
72     }
73 
74     return mSurfaceControl->getSurface();
75 }
76 
waitForVsync()77 void TestContext::waitForVsync() {
78 #if !HWUI_NULL_GPU
79     // Request vsync
80     mDisplayEventReceiver.requestNextVsync();
81 
82     // Wait
83     mLooper->pollOnce(-1);
84 
85     // Drain it
86     DisplayEventReceiver::Event buf[100];
87     while (mDisplayEventReceiver.getEvents(buf, 100) > 0) { }
88 #endif
89 }
90 
91 } // namespace test
92 } // namespace uirenderer
93 } // namespace android
94