1 /*
2  * Copyright (C) 2023 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 #define private public
18 
19 #include <gui/SurfaceComposerClient.h>
20 #include <gui/SurfaceControl.h>
21 
22 #include "../includes/common.h"
23 
24 using namespace android;
25 
main()26 int main() {
27     constexpr int32_t val = 0;
28     constexpr int32_t width = 100;
29     constexpr int32_t height = 100;
30     std::string layerName = "layerName";
31     constexpr int32_t createFlags =
32             ISurfaceComposerClient::eCursorWindow | ISurfaceComposerClient::eOpaque;
33     constexpr PixelFormat formats[] = {PIXEL_FORMAT_RGBA_1010102, PIXEL_FORMAT_RGBA_FP16,
34                                        PIXEL_FORMAT_RGBA_4444};
35 
36     sp<SurfaceComposerClient> surfaceComposerClient = new SurfaceComposerClient();
37 
38     for (PixelFormat format : formats) {
39         sp<SurfaceControl> surfaceControl =
40                 new SurfaceControl(surfaceComposerClient, nullptr, val, layerName, width, height,
41                                    format, val, createFlags);
42         sp<SurfaceControl> newSurfaceControl = new SurfaceControl(surfaceControl);
43         FAIL_CHECK(newSurfaceControl->mWidth == width);
44         FAIL_CHECK(newSurfaceControl->mHeight == height);
45         FAIL_CHECK(newSurfaceControl->mCreateFlags == createFlags);
46         if (newSurfaceControl->mFormat == format) {
47             return EXIT_SUCCESS;
48         }
49     }
50 
51     return EXIT_VULNERABLE;
52 }
53