| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | namespace android { |
| chaviw | 0ef7caa | 2021-01-05 11:04:50 -0800 | [diff] [blame] | 25 | using gui::ScreenCaptureResults; |
| 26 | |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 27 | namespace test { |
| 28 | |
| 29 | TEST(LayerStateTest, ParcellingDisplayCaptureArgs) { |
| 30 | DisplayCaptureArgs args; |
| 31 | args.pixelFormat = ui::PixelFormat::RGB_565; |
| 32 | args.sourceCrop = Rect(0, 0, 500, 200); |
| 33 | args.frameScale = 2; |
| 34 | args.captureSecureLayers = true; |
| 35 | args.displayToken = new BBinder(); |
| 36 | args.width = 10; |
| 37 | args.height = 20; |
| 38 | args.useIdentityTransform = true; |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 39 | |
| 40 | Parcel p; |
| 41 | args.write(p); |
| 42 | p.setDataPosition(0); |
| 43 | |
| 44 | DisplayCaptureArgs args2; |
| 45 | args2.read(p); |
| 46 | |
| 47 | ASSERT_EQ(args.pixelFormat, args2.pixelFormat); |
| 48 | ASSERT_EQ(args.sourceCrop, args2.sourceCrop); |
| 49 | ASSERT_EQ(args.frameScale, args2.frameScale); |
| 50 | ASSERT_EQ(args.captureSecureLayers, args2.captureSecureLayers); |
| 51 | ASSERT_EQ(args.displayToken, args2.displayToken); |
| 52 | ASSERT_EQ(args.width, args2.width); |
| 53 | ASSERT_EQ(args.height, args2.height); |
| 54 | ASSERT_EQ(args.useIdentityTransform, args2.useIdentityTransform); |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | TEST(LayerStateTest, ParcellingLayerCaptureArgs) { |
| 58 | LayerCaptureArgs args; |
| 59 | args.pixelFormat = ui::PixelFormat::RGB_565; |
| 60 | args.sourceCrop = Rect(0, 0, 500, 200); |
| 61 | args.frameScale = 2; |
| 62 | args.captureSecureLayers = true; |
| 63 | args.layerHandle = new BBinder(); |
| 64 | args.excludeHandles = {new BBinder(), new BBinder()}; |
| 65 | args.childrenOnly = false; |
| 66 | |
| 67 | Parcel p; |
| 68 | args.write(p); |
| 69 | p.setDataPosition(0); |
| 70 | |
| 71 | LayerCaptureArgs args2; |
| 72 | args2.read(p); |
| 73 | |
| 74 | ASSERT_EQ(args.pixelFormat, args2.pixelFormat); |
| 75 | ASSERT_EQ(args.sourceCrop, args2.sourceCrop); |
| 76 | ASSERT_EQ(args.frameScale, args2.frameScale); |
| 77 | ASSERT_EQ(args.captureSecureLayers, args2.captureSecureLayers); |
| 78 | ASSERT_EQ(args.layerHandle, args2.layerHandle); |
| 79 | ASSERT_EQ(args.excludeHandles, args2.excludeHandles); |
| 80 | ASSERT_EQ(args.childrenOnly, args2.childrenOnly); |
| 81 | } |
| 82 | |
| 83 | TEST(LayerStateTest, ParcellingScreenCaptureResults) { |
| 84 | ScreenCaptureResults results; |
| 85 | results.buffer = new GraphicBuffer(100, 200, PIXEL_FORMAT_RGBA_8888, 1, 0); |
| Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 86 | results.fence = new Fence(dup(fileno(tmpfile()))); |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 87 | results.capturedSecureLayers = true; |
| 88 | results.capturedDataspace = ui::Dataspace::DISPLAY_P3; |
| chaviw | 85bf55a | 2020-08-17 17:54:24 -0700 | [diff] [blame] | 89 | results.result = BAD_VALUE; |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 90 | |
| 91 | Parcel p; |
| chaviw | 0ef7caa | 2021-01-05 11:04:50 -0800 | [diff] [blame] | 92 | results.writeToParcel(&p); |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 93 | p.setDataPosition(0); |
| 94 | |
| 95 | ScreenCaptureResults results2; |
| chaviw | 0ef7caa | 2021-01-05 11:04:50 -0800 | [diff] [blame] | 96 | results2.readFromParcel(&p); |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 97 | |
| 98 | // GraphicBuffer object is reallocated so compare the data in the graphic buffer |
| 99 | // rather than the object itself |
| 100 | ASSERT_EQ(results.buffer->getWidth(), results2.buffer->getWidth()); |
| 101 | ASSERT_EQ(results.buffer->getHeight(), results2.buffer->getHeight()); |
| 102 | ASSERT_EQ(results.buffer->getPixelFormat(), results2.buffer->getPixelFormat()); |
| Ady Abraham | 9959994 | 2021-01-27 20:27:23 -0800 | [diff] [blame] | 103 | ASSERT_EQ(results.fence->isValid(), results2.fence->isValid()); |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 104 | ASSERT_EQ(results.capturedSecureLayers, results2.capturedSecureLayers); |
| 105 | ASSERT_EQ(results.capturedDataspace, results2.capturedDataspace); |
| chaviw | 85bf55a | 2020-08-17 17:54:24 -0700 | [diff] [blame] | 106 | ASSERT_EQ(results.result, results2.result); |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame^] | 109 | /** |
| 110 | * Parcel a layer_state_t struct, and then unparcel. Ensure that the object that was parceled |
| 111 | * matches the object that's unparceled. |
| 112 | */ |
| 113 | TEST(LayerStateTest, ParcelUnparcelLayerStateT) { |
| 114 | layer_state_t input; |
| 115 | input.frameTimelineInfo.vsyncId = 1; |
| 116 | input.frameTimelineInfo.inputEventId = 2; |
| 117 | Parcel p; |
| 118 | input.write(p); |
| 119 | layer_state_t output; |
| 120 | p.setDataPosition(0); |
| 121 | output.read(p); |
| 122 | ASSERT_EQ(input.frameTimelineInfo.vsyncId, output.frameTimelineInfo.vsyncId); |
| 123 | ASSERT_EQ(input.frameTimelineInfo.inputEventId, output.frameTimelineInfo.inputEventId); |
| 124 | } |
| 125 | |
| 126 | TEST(LayerStateTest, LayerStateMerge_SelectsValidInputEvent) { |
| 127 | layer_state_t layer1; |
| 128 | layer1.frameTimelineInfo.inputEventId = android::os::IInputConstants::INVALID_INPUT_EVENT_ID; |
| 129 | layer_state_t layer2; |
| 130 | layer2.frameTimelineInfo.inputEventId = 1; |
| 131 | layer2.what |= layer_state_t::eFrameTimelineInfoChanged; |
| 132 | |
| 133 | layer1.merge(layer2); |
| 134 | |
| 135 | ASSERT_EQ(1, layer1.frameTimelineInfo.inputEventId); |
| 136 | } |
| 137 | |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 138 | } // namespace test |
| 139 | } // namespace android |