| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 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 <WindowSurface.h> | 
|  | 18 |  | 
|  | 19 | #include <gui/SurfaceComposerClient.h> | 
|  | 20 | #include <gui/ISurfaceComposer.h> | 
|  | 21 | #include <gui/Surface.h> | 
|  | 22 | #include <ui/DisplayInfo.h> | 
|  | 23 |  | 
|  | 24 | using namespace android; | 
|  | 25 |  | 
|  | 26 | WindowSurface::WindowSurface() { | 
|  | 27 | status_t err; | 
|  | 28 |  | 
|  | 29 | sp<SurfaceComposerClient> surfaceComposerClient = new SurfaceComposerClient; | 
|  | 30 | err = surfaceComposerClient->initCheck(); | 
|  | 31 | if (err != NO_ERROR) { | 
|  | 32 | fprintf(stderr, "SurfaceComposerClient::initCheck error: %#x\n", err); | 
|  | 33 | return; | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | // Get main display parameters. | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 37 | const auto mainDpy = SurfaceComposerClient::getInternalDisplayToken(); | 
|  | 38 | if (mainDpy == nullptr) { | 
|  | 39 | fprintf(stderr, "ERROR: no display\n"); | 
|  | 40 | return; | 
|  | 41 | } | 
|  | 42 |  | 
| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 43 | DisplayInfo mainDpyInfo; | 
|  | 44 | err = SurfaceComposerClient::getDisplayInfo(mainDpy, &mainDpyInfo); | 
|  | 45 | if (err != NO_ERROR) { | 
|  | 46 | fprintf(stderr, "ERROR: unable to get display characteristics\n"); | 
|  | 47 | return; | 
|  | 48 | } | 
|  | 49 |  | 
| Andy McFadden | 709d7de | 2014-03-12 09:50:15 -0700 | [diff] [blame] | 50 | uint32_t width, height; | 
|  | 51 | if (mainDpyInfo.orientation != DISPLAY_ORIENTATION_0 && | 
|  | 52 | mainDpyInfo.orientation != DISPLAY_ORIENTATION_180) { | 
|  | 53 | // rotated | 
|  | 54 | width = mainDpyInfo.h; | 
|  | 55 | height = mainDpyInfo.w; | 
|  | 56 | } else { | 
|  | 57 | width = mainDpyInfo.w; | 
|  | 58 | height = mainDpyInfo.h; | 
|  | 59 | } | 
|  | 60 |  | 
| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 61 | sp<SurfaceControl> sc = surfaceComposerClient->createSurface( | 
| Andy McFadden | 709d7de | 2014-03-12 09:50:15 -0700 | [diff] [blame] | 62 | String8("Benchmark"), width, height, | 
| Andy McFadden | f3ed9a2 | 2014-03-25 14:59:26 -0700 | [diff] [blame] | 63 | PIXEL_FORMAT_RGBX_8888, ISurfaceComposerClient::eOpaque); | 
| Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 64 | if (sc == nullptr || !sc->isValid()) { | 
| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 65 | fprintf(stderr, "Failed to create SurfaceControl\n"); | 
|  | 66 | return; | 
|  | 67 | } | 
|  | 68 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 69 | SurfaceComposerClient::Transaction{} | 
|  | 70 | .setLayer(sc, 0x7FFFFFFF) | 
|  | 71 | .show(sc) | 
|  | 72 | .apply(); | 
| Andy McFadden | 6ef57d7 | 2014-03-05 15:06:53 -0800 | [diff] [blame] | 73 |  | 
|  | 74 | mSurfaceControl = sc; | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | EGLNativeWindowType WindowSurface::getSurface() const { | 
|  | 78 | sp<ANativeWindow> anw = mSurfaceControl->getSurface(); | 
|  | 79 | return (EGLNativeWindowType) anw.get(); | 
|  | 80 | } | 
|  | 81 |  |