blob: d69378cec28f2967cc145c683544d2d917b8cd97 [file] [log] [blame]
chaviw8beb4142019-04-11 13:09:05 -07001/*
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
24namespace android {
25namespace {
26
27class VirtualDisplayTest : public ::testing::Test {
28protected:
29 void SetUp() override {
Jim Shargo6ccc5e82024-07-27 03:42:08 +000030#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
31 mGLConsumer = sp<GLConsumer>::make(GLConsumer::TEXTURE_EXTERNAL, true, false, false);
32 mGLConsumer->setName(String8("Virtual disp consumer"));
33 mGLConsumer->setDefaultBufferSize(100, 100);
34 mProducer = mGLConsumer->getSurface()->getIGraphicBufferProducer();
35#else
chaviw8beb4142019-04-11 13:09:05 -070036 sp<IGraphicBufferConsumer> consumer;
37
38 BufferQueue::createBufferQueue(&mProducer, &consumer);
39 consumer->setConsumerName(String8("Virtual disp consumer"));
40 consumer->setDefaultBufferSize(100, 100);
41
Ady Abrahamd11bade2022-08-01 16:18:03 -070042 mGLConsumer = sp<GLConsumer>::make(consumer, GLConsumer::TEXTURE_EXTERNAL, true, false);
Jim Shargo6ccc5e82024-07-27 03:42:08 +000043#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
chaviw8beb4142019-04-11 13:09:05 -070044 }
45
46 sp<IGraphicBufferProducer> mProducer;
47 sp<GLConsumer> mGLConsumer;
48};
49
50TEST_F(VirtualDisplayTest, VirtualDisplayDestroyedSurfaceReuse) {
Alan Dingd53801c2024-05-08 16:45:29 -070051 static const std::string kDisplayName("VirtualDisplay");
chaviw8beb4142019-04-11 13:09:05 -070052 sp<IBinder> virtualDisplay =
Alan Dingd53801c2024-05-08 16:45:29 -070053 SurfaceComposerClient::createVirtualDisplay(kDisplayName, false /*isSecure*/);
chaviw8beb4142019-04-11 13:09:05 -070054
55 SurfaceComposerClient::Transaction t;
56 t.setDisplaySurface(virtualDisplay, mProducer);
57 t.apply(true);
58
Alan Dingd53801c2024-05-08 16:45:29 -070059 EXPECT_EQ(NO_ERROR, SurfaceComposerClient::destroyVirtualDisplay(virtualDisplay));
chaviw8beb4142019-04-11 13:09:05 -070060 virtualDisplay.clear();
61 // Sync here to ensure the display was completely destroyed in SF
62 t.apply(true);
Vishnu Nairf78589c2020-12-02 18:36:03 -080063 // add another sync since we are deferring the display destruction
64 t.apply(true);
chaviw8beb4142019-04-11 13:09:05 -070065
Ady Abrahamd11bade2022-08-01 16:18:03 -070066 sp<Surface> surface = sp<Surface>::make(mProducer);
chaviw8beb4142019-04-11 13:09:05 -070067 sp<ANativeWindow> window(surface);
68
69 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(), NATIVE_WINDOW_API_EGL));
70}
71
72} // namespace
73} // namespace android