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 | |
| 17 | #include "LayerTransactionTest.h" |
| 18 | |
| 19 | namespace android { |
| 20 | |
| 21 | class SetGeometryTest : public LayerTransactionTest { |
| 22 | protected: |
| 23 | void SetUp() { |
| 24 | LayerTransactionTest::SetUp(); |
| 25 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); |
| 26 | |
| 27 | mLayer = createLayer("Layer", mLayerWidth, mLayerHeight); |
| 28 | fillBufferQueueLayerColor(mLayer, Color::RED, mLayerWidth, mLayerHeight); |
| 29 | asTransaction([&](Transaction& t) { t.setLayer(mLayer, INT32_MAX - 1).show(mLayer); }); |
| 30 | |
| 31 | { |
| 32 | SCOPED_TRACE("init"); |
| 33 | ScreenCapture::captureScreen(&sc); |
| 34 | sc->expectColor(Rect(0, 0, mLayerWidth, mLayerHeight), Color::RED); |
| 35 | sc->expectBorder(Rect(0, 0, mLayerWidth, mLayerHeight), Color::BLACK); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | void TearDown() { |
| 40 | LayerTransactionTest::TearDown(); |
| 41 | sc = 0; |
| 42 | mLayer = 0; |
| 43 | } |
| 44 | |
| 45 | std::unique_ptr<ScreenCapture> sc; |
| 46 | sp<SurfaceControl> mLayer; |
| 47 | const int mLayerWidth = 100; |
| 48 | const int mLayerHeight = 200; |
| 49 | }; |
| 50 | |
| 51 | TEST_F(SetGeometryTest, SourceAtZeroNoScale) { |
| 52 | Rect source = Rect(0, 0, 30, 30); |
| 53 | Rect dest = Rect(60, 60, 90, 90); |
| 54 | Transaction{}.setGeometry(mLayer, source, dest, 0).apply(); |
| 55 | |
| 56 | { |
| 57 | SCOPED_TRACE("geometry applied"); |
| 58 | ScreenCapture::captureScreen(&sc); |
| 59 | sc->expectColor(dest, Color::RED); |
| 60 | sc->expectBorder(dest, Color::BLACK); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | TEST_F(SetGeometryTest, SourceNotAtZero) { |
| 65 | Rect source = Rect(40, 40, 70, 70); |
| 66 | Rect dest = Rect(60, 60, 90, 90); |
| 67 | Transaction{}.setGeometry(mLayer, source, dest, 0).apply(); |
| 68 | |
| 69 | { |
| 70 | SCOPED_TRACE("geometry applied"); |
| 71 | ScreenCapture::captureScreen(&sc); |
| 72 | sc->expectColor(dest, Color::RED); |
| 73 | sc->expectBorder(dest, Color::BLACK); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | TEST_F(SetGeometryTest, Scale) { |
| 78 | Rect source = Rect(0, 0, 100, 200); |
| 79 | Rect dest = Rect(0, 0, 200, 400); |
| 80 | Transaction{}.setGeometry(mLayer, source, dest, 0).apply(); |
| 81 | |
| 82 | { |
| 83 | SCOPED_TRACE("Scaled by 2"); |
| 84 | ScreenCapture::captureScreen(&sc); |
| 85 | sc->expectColor(dest, Color::RED); |
| 86 | sc->expectBorder(dest, Color::BLACK); |
| 87 | } |
| 88 | |
| 89 | dest = Rect(0, 0, 50, 100); |
| 90 | Transaction{}.setGeometry(mLayer, source, dest, 0).apply(); |
| 91 | { |
| 92 | SCOPED_TRACE("Scaled by .5"); |
| 93 | ScreenCapture::captureScreen(&sc); |
| 94 | sc->expectColor(dest, Color::RED); |
| 95 | sc->expectBorder(dest, Color::BLACK); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | } // namespace android |