blob: fbbf322732dbf65a659ed2685fd2e4469ea053ef [file] [log] [blame]
chaviw618c42d2020-07-24 15:25:08 -07001/*
2 * Copyright 2020 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 <gtest/gtest.h>
18
19#include <binder/Binder.h>
20#include <binder/Parcel.h>
21
22#include <gui/LayerState.h>
23
24namespace android {
Huihong Luof5029222021-12-16 14:33:46 -080025using gui::DisplayCaptureArgs;
26using gui::LayerCaptureArgs;
chaviw0ef7caa2021-01-05 11:04:50 -080027using gui::ScreenCaptureResults;
28
chaviw618c42d2020-07-24 15:25:08 -070029namespace test {
30
31TEST(LayerStateTest, ParcellingDisplayCaptureArgs) {
32 DisplayCaptureArgs args;
33 args.pixelFormat = ui::PixelFormat::RGB_565;
34 args.sourceCrop = Rect(0, 0, 500, 200);
chaviw17ac24b2021-01-28 18:50:05 -080035 args.frameScaleX = 2;
36 args.frameScaleY = 4;
chaviw618c42d2020-07-24 15:25:08 -070037 args.captureSecureLayers = true;
Ady Abrahamd11bade2022-08-01 16:18:03 -070038 args.displayToken = sp<BBinder>::make();
chaviw618c42d2020-07-24 15:25:08 -070039 args.width = 10;
40 args.height = 20;
41 args.useIdentityTransform = true;
chaviw17ac24b2021-01-28 18:50:05 -080042 args.grayscale = true;
chaviw618c42d2020-07-24 15:25:08 -070043
44 Parcel p;
Huihong Luof5029222021-12-16 14:33:46 -080045 args.writeToParcel(&p);
chaviw618c42d2020-07-24 15:25:08 -070046 p.setDataPosition(0);
47
48 DisplayCaptureArgs args2;
Huihong Luof5029222021-12-16 14:33:46 -080049 args2.readFromParcel(&p);
chaviw618c42d2020-07-24 15:25:08 -070050
51 ASSERT_EQ(args.pixelFormat, args2.pixelFormat);
52 ASSERT_EQ(args.sourceCrop, args2.sourceCrop);
chaviw17ac24b2021-01-28 18:50:05 -080053 ASSERT_EQ(args.frameScaleX, args2.frameScaleX);
54 ASSERT_EQ(args.frameScaleY, args2.frameScaleY);
chaviw618c42d2020-07-24 15:25:08 -070055 ASSERT_EQ(args.captureSecureLayers, args2.captureSecureLayers);
56 ASSERT_EQ(args.displayToken, args2.displayToken);
57 ASSERT_EQ(args.width, args2.width);
58 ASSERT_EQ(args.height, args2.height);
59 ASSERT_EQ(args.useIdentityTransform, args2.useIdentityTransform);
chaviw17ac24b2021-01-28 18:50:05 -080060 ASSERT_EQ(args.grayscale, args2.grayscale);
chaviw618c42d2020-07-24 15:25:08 -070061}
62
63TEST(LayerStateTest, ParcellingLayerCaptureArgs) {
64 LayerCaptureArgs args;
65 args.pixelFormat = ui::PixelFormat::RGB_565;
66 args.sourceCrop = Rect(0, 0, 500, 200);
chaviw17ac24b2021-01-28 18:50:05 -080067 args.frameScaleX = 2;
68 args.frameScaleY = 4;
chaviw618c42d2020-07-24 15:25:08 -070069 args.captureSecureLayers = true;
Ady Abrahamd11bade2022-08-01 16:18:03 -070070 args.layerHandle = sp<BBinder>::make();
71 args.excludeHandles = {sp<BBinder>::make(), sp<BBinder>::make()};
chaviw618c42d2020-07-24 15:25:08 -070072 args.childrenOnly = false;
chaviw17ac24b2021-01-28 18:50:05 -080073 args.grayscale = true;
chaviw618c42d2020-07-24 15:25:08 -070074
75 Parcel p;
Huihong Luof5029222021-12-16 14:33:46 -080076 args.writeToParcel(&p);
chaviw618c42d2020-07-24 15:25:08 -070077 p.setDataPosition(0);
78
79 LayerCaptureArgs args2;
Huihong Luof5029222021-12-16 14:33:46 -080080 args2.readFromParcel(&p);
chaviw618c42d2020-07-24 15:25:08 -070081
82 ASSERT_EQ(args.pixelFormat, args2.pixelFormat);
83 ASSERT_EQ(args.sourceCrop, args2.sourceCrop);
chaviw17ac24b2021-01-28 18:50:05 -080084 ASSERT_EQ(args.frameScaleX, args2.frameScaleX);
85 ASSERT_EQ(args.frameScaleY, args2.frameScaleY);
chaviw618c42d2020-07-24 15:25:08 -070086 ASSERT_EQ(args.captureSecureLayers, args2.captureSecureLayers);
87 ASSERT_EQ(args.layerHandle, args2.layerHandle);
88 ASSERT_EQ(args.excludeHandles, args2.excludeHandles);
89 ASSERT_EQ(args.childrenOnly, args2.childrenOnly);
chaviw17ac24b2021-01-28 18:50:05 -080090 ASSERT_EQ(args.grayscale, args2.grayscale);
chaviw618c42d2020-07-24 15:25:08 -070091}
92
93TEST(LayerStateTest, ParcellingScreenCaptureResults) {
94 ScreenCaptureResults results;
Ady Abrahamd11bade2022-08-01 16:18:03 -070095 results.buffer = sp<GraphicBuffer>::make(100u, 200u, PIXEL_FORMAT_RGBA_8888, 1u, 0u);
96 results.fence = sp<Fence>::make(dup(fileno(tmpfile())));
chaviw618c42d2020-07-24 15:25:08 -070097 results.capturedSecureLayers = true;
98 results.capturedDataspace = ui::Dataspace::DISPLAY_P3;
chaviw85bf55a2020-08-17 17:54:24 -070099 results.result = BAD_VALUE;
chaviw618c42d2020-07-24 15:25:08 -0700100
101 Parcel p;
chaviw0ef7caa2021-01-05 11:04:50 -0800102 results.writeToParcel(&p);
chaviw618c42d2020-07-24 15:25:08 -0700103 p.setDataPosition(0);
104
105 ScreenCaptureResults results2;
chaviw0ef7caa2021-01-05 11:04:50 -0800106 results2.readFromParcel(&p);
chaviw618c42d2020-07-24 15:25:08 -0700107
108 // GraphicBuffer object is reallocated so compare the data in the graphic buffer
109 // rather than the object itself
110 ASSERT_EQ(results.buffer->getWidth(), results2.buffer->getWidth());
111 ASSERT_EQ(results.buffer->getHeight(), results2.buffer->getHeight());
112 ASSERT_EQ(results.buffer->getPixelFormat(), results2.buffer->getPixelFormat());
Ady Abraham99599942021-01-27 20:27:23 -0800113 ASSERT_EQ(results.fence->isValid(), results2.fence->isValid());
chaviw618c42d2020-07-24 15:25:08 -0700114 ASSERT_EQ(results.capturedSecureLayers, results2.capturedSecureLayers);
115 ASSERT_EQ(results.capturedDataspace, results2.capturedDataspace);
chaviw85bf55a2020-08-17 17:54:24 -0700116 ASSERT_EQ(results.result, results2.result);
chaviw618c42d2020-07-24 15:25:08 -0700117}
118
chaviw618c42d2020-07-24 15:25:08 -0700119} // namespace test
120} // namespace android