chaviw | 8beb414 | 2019-04-11 13:09:05 -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 <binder/Binder.h> |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | #include <gui/GLConsumer.h> |
| 21 | #include <gui/Surface.h> |
| 22 | #include <gui/SurfaceComposerClient.h> |
| 23 | |
| 24 | namespace android { |
| 25 | namespace { |
| 26 | |
| 27 | class VirtualDisplayTest : public ::testing::Test { |
| 28 | protected: |
| 29 | void SetUp() override { |
| 30 | sp<IGraphicBufferConsumer> consumer; |
| 31 | |
| 32 | BufferQueue::createBufferQueue(&mProducer, &consumer); |
| 33 | consumer->setConsumerName(String8("Virtual disp consumer")); |
| 34 | consumer->setDefaultBufferSize(100, 100); |
| 35 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 36 | mGLConsumer = sp<GLConsumer>::make(consumer, GLConsumer::TEXTURE_EXTERNAL, true, false); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | sp<IGraphicBufferProducer> mProducer; |
| 40 | sp<GLConsumer> mGLConsumer; |
| 41 | }; |
| 42 | |
| 43 | TEST_F(VirtualDisplayTest, VirtualDisplayDestroyedSurfaceReuse) { |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 44 | static const std::string kDisplayName("VirtualDisplay"); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 45 | sp<IBinder> virtualDisplay = |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 46 | SurfaceComposerClient::createVirtualDisplay(kDisplayName, false /*isSecure*/); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 47 | |
| 48 | SurfaceComposerClient::Transaction t; |
| 49 | t.setDisplaySurface(virtualDisplay, mProducer); |
| 50 | t.apply(true); |
| 51 | |
Alan Ding | d53801c | 2024-05-08 16:45:29 -0700 | [diff] [blame] | 52 | EXPECT_EQ(NO_ERROR, SurfaceComposerClient::destroyVirtualDisplay(virtualDisplay)); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 53 | virtualDisplay.clear(); |
| 54 | // Sync here to ensure the display was completely destroyed in SF |
| 55 | t.apply(true); |
Vishnu Nair | f78589c | 2020-12-02 18:36:03 -0800 | [diff] [blame] | 56 | // add another sync since we are deferring the display destruction |
| 57 | t.apply(true); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 58 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 59 | sp<Surface> surface = sp<Surface>::make(mProducer); |
chaviw | 8beb414 | 2019-04-11 13:09:05 -0700 | [diff] [blame] | 60 | sp<ANativeWindow> window(surface); |
| 61 | |
| 62 | ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(), NATIVE_WINDOW_API_EGL)); |
| 63 | } |
| 64 | |
| 65 | } // namespace |
| 66 | } // namespace android |