John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 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 "TestContext.h" |
| 18 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 19 | namespace android { |
| 20 | namespace uirenderer { |
| 21 | namespace test { |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 22 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 23 | static const int IDENT_DISPLAYEVENT = 1; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 24 | |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame^] | 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 | 0, // colorTransform |
| 37 | }; |
| 38 | |
| 39 | DisplayInfo getBuiltInDisplay() { |
| 40 | #if !HWUI_NULL_GPU |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 41 | DisplayInfo display; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 42 | sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay( |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 43 | ISurfaceComposer::eDisplayIdMain)); |
| 44 | status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 45 | LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n"); |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 46 | return display; |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame^] | 47 | #else |
| 48 | return DUMMY_DISPLAY; |
| 49 | #endif |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 50 | } |
| 51 | |
John Reck | e702c9c | 2015-10-07 10:26:02 -0700 | [diff] [blame^] | 52 | // Initialize to a dummy default |
| 53 | android::DisplayInfo gDisplay = DUMMY_DISPLAY; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 54 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 55 | TestContext::TestContext() { |
| 56 | mLooper = new Looper(true); |
| 57 | mSurfaceComposerClient = new SurfaceComposerClient(); |
| 58 | mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT, |
| 59 | Looper::EVENT_INPUT, nullptr, nullptr); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 60 | } |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 61 | |
| 62 | TestContext::~TestContext() {} |
| 63 | |
| 64 | sp<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 | |
| 78 | void TestContext::waitForVsync() { |
John Reck | c36df95 | 2015-07-29 10:09:36 -0700 | [diff] [blame] | 79 | #if !HWUI_NULL_GPU |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 80 | // 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 Reck | c36df95 | 2015-07-29 10:09:36 -0700 | [diff] [blame] | 89 | #endif |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | } // namespace test |
| 93 | } // namespace uirenderer |
| 94 | } // namespace android |