Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c8f94b0 authored by Stephen Kiazyk's avatar Stephen Kiazyk
Browse files

Fix DummyNativeWindow to respond to new query

The `NATIVE_WINDOW_IS_VALID` query must now return true in order for
`eglCreateWindowSurface` to succeed. Technically this isn't true for our
dummy window, but we only need it to create the context, it gets dropped
immediately afterwards.

Bug: 36102224
Test: Created a simple test application. Also ran a Vr application with
      these changes applied.

Change-Id: I2d559962d28db4b1cb6ad188269e4e54cf47245d
parent 99295a2b
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -65,15 +65,14 @@ LOCAL_C_INCLUDES := $(includeFiles)
LOCAL_CFLAGS += -DLOG_TAG=\"libdisplay\"
LOCAL_CFLAGS += -DTRACE=0
LOCAL_CFLAGS += -DATRACE_TAG=ATRACE_TAG_GRAPHICS
LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES -g -O0
LOCAL_EXPORT_C_INCLUDE_DIRS := $(includeFiles)
LOCAL_SHARED_LIBRARIES := $(sharedLibraries)
LOCAL_STATIC_LIBRARIES := $(staticLibraries)
LOCAL_MODULE := libdisplay
include $(BUILD_STATIC_LIBRARY)


testFiles := \
graphicsAppTestFiles := \
  tests/graphics_app_tests.cpp

include $(CLEAR_VARS)
@@ -81,7 +80,7 @@ LOCAL_MODULE := graphics_app_tests
LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := \
  $(testFiles) \
  $(graphicsAppTestFiles) \

LOCAL_C_INCLUDES := \
  $(includeFiles) \
@@ -94,3 +93,25 @@ LOCAL_STATIC_LIBRARIES := \
  $(staticLibraries) \

include $(BUILD_NATIVE_TEST)

dummyNativeWindowTestFiles := \
  tests/dummy_native_window_tests.cpp \

include $(CLEAR_VARS)
LOCAL_MODULE := dummy_native_window_tests
LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := \
  $(dummyNativeWindowTestFiles) \

LOCAL_C_INCLUDES := \
  $(includeFiles) \

LOCAL_SHARED_LIBRARIES := \
  $(sharedLibraries) \

LOCAL_STATIC_LIBRARIES := \
  libdisplay \
  $(staticLibraries) \
include $(BUILD_NATIVE_TEST)
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,11 @@ DummyNativeWindow::DummyNativeWindow() {

int DummyNativeWindow::Query(const ANativeWindow*, int what, int* value) {
  switch (what) {
    // This must be 1 in order for eglCreateWindowSurface to not trigger an
    // error
    case NATIVE_WINDOW_IS_VALID:
      *value = 1;
      return NO_ERROR;
    case NATIVE_WINDOW_WIDTH:
    case NATIVE_WINDOW_HEIGHT:
    case NATIVE_WINDOW_FORMAT:
+64 −0
Original line number Diff line number Diff line
#include <private/dvr/dummy_native_window.h>
#include <gtest/gtest.h>

#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>

class DummyNativeWindowTests : public ::testing::Test {
 public:
  EGLDisplay display_;
  bool initialized_;

  DummyNativeWindowTests()
      : display_(nullptr)
      , initialized_(false)
  {
  }

  virtual void SetUp() {
    display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);

    ASSERT_NE(nullptr, display_);
    initialized_ = eglInitialize(display_, nullptr, nullptr);

    ASSERT_TRUE(initialized_);
  }

  virtual void TearDown() {
    if (display_ && initialized_) {
      eglTerminate(display_);
    }
  }
};

// Test that eglCreateWindowSurface works with DummyNativeWindow
TEST_F(DummyNativeWindowTests, TryCreateEglWindow) {
  EGLint attribs[] = {
      EGL_NONE,
  };

  EGLint num_configs;
  EGLConfig config;
  ASSERT_TRUE(eglChooseConfig(display_, attribs, &config, 1, &num_configs));

  std::unique_ptr<android::dvr::DummyNativeWindow> dummy_window(
      new android::dvr::DummyNativeWindow());

  EGLint context_attribs[] = {
    EGL_NONE,
  };

  EGLSurface surface = eglCreateWindowSurface(display_, config,
                                              dummy_window.get(),
                                              context_attribs);

  EXPECT_NE(nullptr, surface);

  bool destroyed = eglDestroySurface(display_, surface);

  EXPECT_TRUE(destroyed);
}