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 | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 25 | static DisplayInfo getBuiltInDisplay() { |
| 26 | DisplayInfo display; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 27 | sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay( |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 28 | ISurfaceComposer::eDisplayIdMain)); |
| 29 | status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 30 | LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n"); |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 31 | return display; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 32 | } |
| 33 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 34 | android::DisplayInfo gDisplay = getBuiltInDisplay(); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 35 | |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 36 | TestContext::TestContext() { |
| 37 | mLooper = new Looper(true); |
| 38 | mSurfaceComposerClient = new SurfaceComposerClient(); |
| 39 | mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT, |
| 40 | Looper::EVENT_INPUT, nullptr, nullptr); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 41 | } |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 42 | |
| 43 | TestContext::~TestContext() {} |
| 44 | |
| 45 | sp<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 | |
| 59 | void 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 | |