VirtualDisplay_test.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include <binder/Binder.h>
  17. #include <gtest/gtest.h>
  18. #include <gui/GLConsumer.h>
  19. #include <gui/Surface.h>
  20. #include <gui/SurfaceComposerClient.h>
  21. namespace android {
  22. namespace {
  23. class VirtualDisplayTest : public ::testing::Test {
  24. protected:
  25. void SetUp() override {
  26. sp<IGraphicBufferConsumer> consumer;
  27. BufferQueue::createBufferQueue(&mProducer, &consumer);
  28. consumer->setConsumerName(String8("Virtual disp consumer"));
  29. consumer->setDefaultBufferSize(100, 100);
  30. mGLConsumer = new GLConsumer(consumer, GLConsumer::TEXTURE_EXTERNAL, true, false);
  31. }
  32. sp<IGraphicBufferProducer> mProducer;
  33. sp<GLConsumer> mGLConsumer;
  34. };
  35. TEST_F(VirtualDisplayTest, VirtualDisplayDestroyedSurfaceReuse) {
  36. sp<IBinder> virtualDisplay =
  37. SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), false /*secure*/);
  38. SurfaceComposerClient::Transaction t;
  39. t.setDisplaySurface(virtualDisplay, mProducer);
  40. t.apply(true);
  41. SurfaceComposerClient::destroyDisplay(virtualDisplay);
  42. virtualDisplay.clear();
  43. // Sync here to ensure the display was completely destroyed in SF
  44. t.apply(true);
  45. sp<Surface> surface = new Surface(mProducer);
  46. sp<ANativeWindow> window(surface);
  47. ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(), NATIVE_WINDOW_API_EGL));
  48. }
  49. } // namespace
  50. } // namespace android