194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck/* 294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * Copyright (C) 2014 The Android Open Source Project 394c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * 494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 594c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * you may not use this file except in compliance with the License. 694c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * You may obtain a copy of the License at 794c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * 894c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * http://www.apache.org/licenses/LICENSE-2.0 994c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * 1094c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * Unless required by applicable law or agreed to in writing, software 1194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * distributed under the License is distributed on an "AS IS" BASIS, 1294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1394c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * See the License for the specific language governing permissions and 1494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck * limitations under the License. 1594c40fe92117f301c7758de2861ab0c1d6cfded0John Reck */ 1694c40fe92117f301c7758de2861ab0c1d6cfded0John Reck 1794c40fe92117f301c7758de2861ab0c1d6cfded0John Reck#include "TestContext.h" 1894c40fe92117f301c7758de2861ab0c1d6cfded0John Reck 1984e390cc903ae4027276c33371ad5237b550910fJohn Recknamespace android { 2084e390cc903ae4027276c33371ad5237b550910fJohn Recknamespace uirenderer { 2184e390cc903ae4027276c33371ad5237b550910fJohn Recknamespace test { 2294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck 2384e390cc903ae4027276c33371ad5237b550910fJohn Reckstatic const int IDENT_DISPLAYEVENT = 1; 2494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck 2584e390cc903ae4027276c33371ad5237b550910fJohn Reckstatic DisplayInfo getBuiltInDisplay() { 2684e390cc903ae4027276c33371ad5237b550910fJohn Reck DisplayInfo display; 2794c40fe92117f301c7758de2861ab0c1d6cfded0John Reck sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay( 2884e390cc903ae4027276c33371ad5237b550910fJohn Reck ISurfaceComposer::eDisplayIdMain)); 2984e390cc903ae4027276c33371ad5237b550910fJohn Reck status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display); 3094c40fe92117f301c7758de2861ab0c1d6cfded0John Reck LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n"); 3184e390cc903ae4027276c33371ad5237b550910fJohn Reck return display; 3284e390cc903ae4027276c33371ad5237b550910fJohn Reck} 3384e390cc903ae4027276c33371ad5237b550910fJohn Reck 3484e390cc903ae4027276c33371ad5237b550910fJohn Reckandroid::DisplayInfo gDisplay = getBuiltInDisplay(); 3584e390cc903ae4027276c33371ad5237b550910fJohn Reck 3684e390cc903ae4027276c33371ad5237b550910fJohn ReckTestContext::TestContext() { 3784e390cc903ae4027276c33371ad5237b550910fJohn Reck mLooper = new Looper(true); 3884e390cc903ae4027276c33371ad5237b550910fJohn Reck mSurfaceComposerClient = new SurfaceComposerClient(); 3984e390cc903ae4027276c33371ad5237b550910fJohn Reck mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT, 4084e390cc903ae4027276c33371ad5237b550910fJohn Reck Looper::EVENT_INPUT, nullptr, nullptr); 4194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck} 4294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck 4384e390cc903ae4027276c33371ad5237b550910fJohn ReckTestContext::~TestContext() {} 4484e390cc903ae4027276c33371ad5237b550910fJohn Reck 4584e390cc903ae4027276c33371ad5237b550910fJohn Recksp<Surface> TestContext::surface() { 4684e390cc903ae4027276c33371ad5237b550910fJohn Reck if (!mSurfaceControl.get()) { 4784e390cc903ae4027276c33371ad5237b550910fJohn Reck mSurfaceControl = mSurfaceComposerClient->createSurface(String8("HwuiTest"), 4884e390cc903ae4027276c33371ad5237b550910fJohn Reck gDisplay.w, gDisplay.h, PIXEL_FORMAT_RGBX_8888); 4994c40fe92117f301c7758de2861ab0c1d6cfded0John Reck 5084e390cc903ae4027276c33371ad5237b550910fJohn Reck SurfaceComposerClient::openGlobalTransaction(); 5184e390cc903ae4027276c33371ad5237b550910fJohn Reck mSurfaceControl->setLayer(0x7FFFFFF); 5284e390cc903ae4027276c33371ad5237b550910fJohn Reck mSurfaceControl->show(); 5384e390cc903ae4027276c33371ad5237b550910fJohn Reck SurfaceComposerClient::closeGlobalTransaction(); 5484e390cc903ae4027276c33371ad5237b550910fJohn Reck } 5594c40fe92117f301c7758de2861ab0c1d6cfded0John Reck 5684e390cc903ae4027276c33371ad5237b550910fJohn Reck return mSurfaceControl->getSurface(); 5794c40fe92117f301c7758de2861ab0c1d6cfded0John Reck} 5884e390cc903ae4027276c33371ad5237b550910fJohn Reck 5984e390cc903ae4027276c33371ad5237b550910fJohn Reckvoid TestContext::waitForVsync() { 607f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck#if HWUI_NULL_GPU 617f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck return; 627f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck#endif 637f2e5e3cea6af1f1dff35842aa13d46c47315b91John Reck 6484e390cc903ae4027276c33371ad5237b550910fJohn Reck // Request vsync 6584e390cc903ae4027276c33371ad5237b550910fJohn Reck mDisplayEventReceiver.requestNextVsync(); 6684e390cc903ae4027276c33371ad5237b550910fJohn Reck 6784e390cc903ae4027276c33371ad5237b550910fJohn Reck // Wait 6884e390cc903ae4027276c33371ad5237b550910fJohn Reck mLooper->pollOnce(-1); 6984e390cc903ae4027276c33371ad5237b550910fJohn Reck 7084e390cc903ae4027276c33371ad5237b550910fJohn Reck // Drain it 7184e390cc903ae4027276c33371ad5237b550910fJohn Reck DisplayEventReceiver::Event buf[100]; 7284e390cc903ae4027276c33371ad5237b550910fJohn Reck while (mDisplayEventReceiver.getEvents(buf, 100) > 0) { } 7384e390cc903ae4027276c33371ad5237b550910fJohn Reck} 7484e390cc903ae4027276c33371ad5237b550910fJohn Reck 7584e390cc903ae4027276c33371ad5237b550910fJohn Reck} // namespace test 7684e390cc903ae4027276c33371ad5237b550910fJohn Reck} // namespace uirenderer 7784e390cc903ae4027276c33371ad5237b550910fJohn Reck} // namespace android 78