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 { |
| 25 | namespace test { |
| 26 | |
| 27 | TEST(LayerStateTest, ParcellingDisplayCaptureArgs) { |
| 28 | DisplayCaptureArgs args; |
| 29 | args.pixelFormat = ui::PixelFormat::RGB_565; |
| 30 | args.sourceCrop = Rect(0, 0, 500, 200); |
| 31 | args.frameScale = 2; |
| 32 | args.captureSecureLayers = true; |
| 33 | args.displayToken = new BBinder(); |
| 34 | args.width = 10; |
| 35 | args.height = 20; |
| 36 | args.useIdentityTransform = true; |
| 37 | args.rotation = ui::ROTATION_90; |
| 38 | |
| 39 | Parcel p; |
| 40 | args.write(p); |
| 41 | p.setDataPosition(0); |
| 42 | |
| 43 | DisplayCaptureArgs args2; |
| 44 | args2.read(p); |
| 45 | |
| 46 | ASSERT_EQ(args.pixelFormat, args2.pixelFormat); |
| 47 | ASSERT_EQ(args.sourceCrop, args2.sourceCrop); |
| 48 | ASSERT_EQ(args.frameScale, args2.frameScale); |
| 49 | ASSERT_EQ(args.captureSecureLayers, args2.captureSecureLayers); |
| 50 | ASSERT_EQ(args.displayToken, args2.displayToken); |
| 51 | ASSERT_EQ(args.width, args2.width); |
| 52 | ASSERT_EQ(args.height, args2.height); |
| 53 | ASSERT_EQ(args.useIdentityTransform, args2.useIdentityTransform); |
| 54 | ASSERT_EQ(args.rotation, args2.rotation); |
| 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); |
| 86 | results.capturedSecureLayers = true; |
| 87 | results.capturedDataspace = ui::Dataspace::DISPLAY_P3; |
| 88 | |
| 89 | Parcel p; |
| 90 | results.write(p); |
| 91 | p.setDataPosition(0); |
| 92 | |
| 93 | ScreenCaptureResults results2; |
| 94 | results2.read(p); |
| 95 | |
| 96 | // GraphicBuffer object is reallocated so compare the data in the graphic buffer |
| 97 | // rather than the object itself |
| 98 | ASSERT_EQ(results.buffer->getWidth(), results2.buffer->getWidth()); |
| 99 | ASSERT_EQ(results.buffer->getHeight(), results2.buffer->getHeight()); |
| 100 | ASSERT_EQ(results.buffer->getPixelFormat(), results2.buffer->getPixelFormat()); |
| 101 | ASSERT_EQ(results.capturedSecureLayers, results2.capturedSecureLayers); |
| 102 | ASSERT_EQ(results.capturedDataspace, results2.capturedDataspace); |
| 103 | } |
| 104 | |
| 105 | } // namespace test |
| 106 | } // namespace android |