Scott Randolph | 150c580 | 2017-04-12 11:45:09 -0700 | [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. |
| 37 | sp<IBinder> mainDpy = SurfaceComposerClient::getBuiltInDisplay( |
| 38 | ISurfaceComposer::eDisplayIdMain); |
| 39 | DisplayInfo mainDpyInfo; |
| 40 | err = SurfaceComposerClient::getDisplayInfo(mainDpy, &mainDpyInfo); |
| 41 | if (err != NO_ERROR) { |
| 42 | fprintf(stderr, "ERROR: unable to get display characteristics\n"); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | uint32_t width, height; |
| 47 | if (mainDpyInfo.orientation != DISPLAY_ORIENTATION_0 && |
| 48 | mainDpyInfo.orientation != DISPLAY_ORIENTATION_180) { |
| 49 | // rotated |
| 50 | width = mainDpyInfo.h; |
| 51 | height = mainDpyInfo.w; |
| 52 | } else { |
| 53 | width = mainDpyInfo.w; |
| 54 | height = mainDpyInfo.h; |
| 55 | } |
| 56 | |
| 57 | sp<SurfaceControl> sc = surfaceComposerClient->createSurface( |
| 58 | String8("Benchmark"), width, height, |
| 59 | PIXEL_FORMAT_RGBX_8888, ISurfaceComposerClient::eOpaque); |
| 60 | if (sc == NULL || !sc->isValid()) { |
| 61 | fprintf(stderr, "Failed to create SurfaceControl\n"); |
| 62 | return; |
| 63 | } |
| 64 | |
Robert Carr | 1055344 | 2017-10-11 09:27:56 -0700 | [diff] [blame] | 65 | SurfaceComposerClient::Transaction{} |
| 66 | .setLayer(sc, 0x7FFFFFFF) // always on top |
| 67 | .show(sc) |
| 68 | .apply(); |
Scott Randolph | 150c580 | 2017-04-12 11:45:09 -0700 | [diff] [blame] | 69 | |
| 70 | mSurfaceControl = sc; |
| 71 | } |
| 72 | |
| 73 | EGLNativeWindowType WindowSurface::getSurface() const { |
| 74 | sp<ANativeWindow> anw = mSurfaceControl->getSurface(); |
| 75 | return (EGLNativeWindowType) anw.get(); |
| 76 | } |
| 77 | |