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
1994c40fe92117f301c7758de2861ab0c1d6cfded0John Reck#include <gui/ISurfaceComposer.h>
2094c40fe92117f301c7758de2861ab0c1d6cfded0John Reck#include <gui/SurfaceComposerClient.h>
2194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
2294c40fe92117f301c7758de2861ab0c1d6cfded0John Reckusing namespace android;
2394c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
2494c40fe92117f301c7758de2861ab0c1d6cfded0John ReckDisplayInfo gDisplay;
2594c40fe92117f301c7758de2861ab0c1d6cfded0John Recksp<SurfaceComposerClient> gSession;
2694c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
2794c40fe92117f301c7758de2861ab0c1d6cfded0John Reckvoid createTestEnvironment() {
2894c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    gSession = new SurfaceComposerClient();
2994c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
3094c40fe92117f301c7758de2861ab0c1d6cfded0John Reck                ISurfaceComposer::eDisplayIdMain));
3194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &gDisplay);
3294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n");
3394c40fe92117f301c7758de2861ab0c1d6cfded0John Reck}
3494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
3594c40fe92117f301c7758de2861ab0c1d6cfded0John Recksp<SurfaceControl> createWindow(int width, int height) {
3694c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    sp<SurfaceControl> control = gSession->createSurface(String8("HwuiTest"),
3794c40fe92117f301c7758de2861ab0c1d6cfded0John Reck            width, height, PIXEL_FORMAT_RGBX_8888);
3894c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
3994c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    SurfaceComposerClient::openGlobalTransaction();
4094c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    control->setLayer(0x7FFFFFF);
4194c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    control->show();
4294c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    SurfaceComposerClient::closeGlobalTransaction();
4394c40fe92117f301c7758de2861ab0c1d6cfded0John Reck
4494c40fe92117f301c7758de2861ab0c1d6cfded0John Reck    return control;
4594c40fe92117f301c7758de2861ab0c1d6cfded0John Reck}
46