chaviw | 76f5f2f | 2019-09-23 10:15:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
chaviw | 76f5f2f | 2019-09-23 10:15:51 -0700 | [diff] [blame] | 21 | #include "LayerTransactionTest.h" |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | class SetGeometryTest : public LayerTransactionTest { |
| 26 | protected: |
| 27 | void SetUp() { |
| 28 | LayerTransactionTest::SetUp(); |
| 29 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); |
| 30 | |
| 31 | mLayer = createLayer("Layer", mLayerWidth, mLayerHeight); |
| 32 | fillBufferQueueLayerColor(mLayer, Color::RED, mLayerWidth, mLayerHeight); |
| 33 | asTransaction([&](Transaction& t) { t.setLayer(mLayer, INT32_MAX - 1).show(mLayer); }); |
| 34 | |
| 35 | { |
| 36 | SCOPED_TRACE("init"); |
| 37 | ScreenCapture::captureScreen(&sc); |
| 38 | sc->expectColor(Rect(0, 0, mLayerWidth, mLayerHeight), Color::RED); |
| 39 | sc->expectBorder(Rect(0, 0, mLayerWidth, mLayerHeight), Color::BLACK); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void TearDown() { |
| 44 | LayerTransactionTest::TearDown(); |
| 45 | sc = 0; |
| 46 | mLayer = 0; |
| 47 | } |
| 48 | |
| 49 | std::unique_ptr<ScreenCapture> sc; |
| 50 | sp<SurfaceControl> mLayer; |
| 51 | const int mLayerWidth = 100; |
| 52 | const int mLayerHeight = 200; |
| 53 | }; |
| 54 | |
| 55 | TEST_F(SetGeometryTest, SourceAtZeroNoScale) { |
| 56 | Rect source = Rect(0, 0, 30, 30); |
| 57 | Rect dest = Rect(60, 60, 90, 90); |
| 58 | Transaction{}.setGeometry(mLayer, source, dest, 0).apply(); |
| 59 | |
| 60 | { |
| 61 | SCOPED_TRACE("geometry applied"); |
| 62 | ScreenCapture::captureScreen(&sc); |
| 63 | sc->expectColor(dest, Color::RED); |
| 64 | sc->expectBorder(dest, Color::BLACK); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | TEST_F(SetGeometryTest, SourceNotAtZero) { |
| 69 | Rect source = Rect(40, 40, 70, 70); |
| 70 | Rect dest = Rect(60, 60, 90, 90); |
| 71 | Transaction{}.setGeometry(mLayer, source, dest, 0).apply(); |
| 72 | |
| 73 | { |
| 74 | SCOPED_TRACE("geometry applied"); |
| 75 | ScreenCapture::captureScreen(&sc); |
| 76 | sc->expectColor(dest, Color::RED); |
| 77 | sc->expectBorder(dest, Color::BLACK); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | TEST_F(SetGeometryTest, Scale) { |
| 82 | Rect source = Rect(0, 0, 100, 200); |
| 83 | Rect dest = Rect(0, 0, 200, 400); |
| 84 | Transaction{}.setGeometry(mLayer, source, dest, 0).apply(); |
| 85 | |
| 86 | { |
| 87 | SCOPED_TRACE("Scaled by 2"); |
| 88 | ScreenCapture::captureScreen(&sc); |
| 89 | sc->expectColor(dest, Color::RED); |
| 90 | sc->expectBorder(dest, Color::BLACK); |
| 91 | } |
| 92 | |
| 93 | dest = Rect(0, 0, 50, 100); |
| 94 | Transaction{}.setGeometry(mLayer, source, dest, 0).apply(); |
| 95 | { |
| 96 | SCOPED_TRACE("Scaled by .5"); |
| 97 | ScreenCapture::captureScreen(&sc); |
| 98 | sc->expectColor(dest, Color::RED); |
| 99 | sc->expectBorder(dest, Color::BLACK); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 104 | |
| 105 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 106 | #pragma clang diagnostic pop // ignored "-Wconversion" |