Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

device-generic-goldfish-opengl: Commit

device/generic/goldfish-opengl


Commit MetaInfo

Révision596e8dec5700d2976d3b40ae498dbbf479c4abb6 (tree)
l'heure2017-03-23 03:47:28
AuteurLingfeng Yang <lfy@goog...>
CommiterLingfeng Yang

Message de Log

[hwc2] Add surfaceInterface/goldfishHwc2

bug: 36439031
bug: 36375335

When HWC2 is used (even the HWC2on1 adapter), one of the most fundamental
changes is that acquireBuffer/releaseBuffer by BufferQueue consumers
is coarsened, delaying releaseBuffer until the app has finished
with its eglSwapBuffers operation and handling releaseBuffer as part of
a post process (mPendingRelease/releasePendingBuffer/et al).

This would be OK, except for the fact that an acquired, unreleased buffer
takes up a free buffer slot.

Emulator uses GLES composition currently, so each eglSwapBuffers by an app
directly causes another eglSwapBuffers, each of which attempts to
dequeueBuffer, taking up 2 slots right there. This was usually OK, since
releaseBuffer would be interleaved, but now, with the delayed releaseBuffer,
there are no free buffer slots and we have a deadlock situation.

Fortunately, we can set the swapped-to Surface to "async mode", which takes
exactly this situation into account. Async mode, which is for Surfaces but
really affects the BufferQueueCore queue size, makes it so that there
is an extra buffer slot so that dequeueBuffer doesn't have to block.

This CL adds a small static library for setting the swapped-to Surface
to async mode. Note that one does not simply add libgui to the shared
libraries of system/egl/Android.mk, since libgui itself includes EGL/GLES2
as dependencies, putting us into DLL hell and causing all sorts of trouble!

Change-Id: I6ee4f0e6d0b668d60573887751ec6b02839df5c3

Change Summary

Modification

--- a/Android.mk
+++ b/Android.mk
@@ -73,6 +73,7 @@ include $(EMUGL_PATH)/system/GLESv1/Android.mk
7373 include $(EMUGL_PATH)/system/GLESv2/Android.mk
7474
7575 include $(EMUGL_PATH)/system/gralloc/Android.mk
76+include $(EMUGL_PATH)/system/surfaceInterface/Android.mk
7677 include $(EMUGL_PATH)/system/egl/Android.mk
7778
7879 endif # BUILD_EMULATOR_OPENGL == true
--- a/system/OpenglSystemCommon/Android.mk
+++ b/system/OpenglSystemCommon/Android.mk
@@ -5,6 +5,7 @@ $(call emugl-import,libGLESv1_enc libGLESv2_enc lib_renderControl_enc)
55
66 LOCAL_SRC_FILES := \
77 goldfish_dma.cpp \
8+ goldfishHwc2.cpp \
89 FormatConversions.cpp \
910 HostConnection.cpp \
1011 ProcessPipe.cpp \
--- /dev/null
+++ b/system/OpenglSystemCommon/goldfishHwc2.cpp
@@ -0,0 +1,22 @@
1+/*
2+* Copyright (C) 2017 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 "goldfishHwc2.h"
17+
18+// Stub functions if not using HWC2.
19+#ifndef USE_HWC2
20+extern "C" void surfaceInterface_init() { }
21+extern "C" void surfaceInterface_setAsyncModeForWindow(void* window) { }
22+#endif
--- /dev/null
+++ b/system/OpenglSystemCommon/goldfishHwc2.h
@@ -0,0 +1,25 @@
1+/*
2+* Copyright (C) 2017 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+#pragma once
17+
18+// Set of functions that help support HWC2 in the emulator.
19+
20+#ifdef USE_HWC2
21+#include "../surfaceInterface/surfaceInterface.h"
22+#else
23+extern "C" void surfaceInterface_init();
24+extern "C" void surfaceInterface_setAsyncModeForWindow(void* window);
25+#endif
--- a/system/egl/Android.mk
+++ b/system/egl/Android.mk
@@ -13,8 +13,12 @@ LOCAL_SRC_FILES := \
1313 egl.cpp \
1414 ClientAPIExts.cpp
1515
16-LOCAL_SHARED_LIBRARIES += libdl
16+ifeq ($(TARGET_USES_HWC2), true)
17+ LOCAL_CFLAGS += -DUSE_HWC2
18+ LOCAL_STATIC_LIBRARIES += libsurfaceInterface
19+endif
1720
21+LOCAL_SHARED_LIBRARIES += libdl
1822 # Used to access the Bionic private OpenGL TLS slot
1923 LOCAL_C_INCLUDES += bionic/libc/private
2024
--- a/system/egl/egl.cpp
+++ b/system/egl/egl.cpp
@@ -29,6 +29,7 @@
2929 #include "eglContext.h"
3030 #include "ClientAPIExts.h"
3131 #include "EGLImage.h"
32+#include "goldfishHwc2.h"
3233 #include "ProcessPipe.h"
3334
3435 #include "GLEncoder.h"
@@ -367,6 +368,8 @@ EGLBoolean egl_window_surface_t::init()
367368 rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface,
368369 ((cb_handle_t*)(buffer->handle))->hostHandle);
369370
371+ surfaceInterface_setAsyncModeForWindow((void*)nativeWindow);
372+
370373 return EGL_TRUE;
371374 }
372375
--- a/system/egl/eglDisplay.cpp
+++ b/system/egl/eglDisplay.cpp
@@ -15,6 +15,8 @@
1515 */
1616 #include "eglDisplay.h"
1717 #include "HostConnection.h"
18+#include "goldfishHwc2.h"
19+
1820 #include <dlfcn.h>
1921
2022 #include <string>
@@ -70,6 +72,7 @@ eglDisplay::eglDisplay() :
7072 pthread_mutex_init(&m_lock, NULL);
7173 pthread_mutex_init(&m_ctxLock, NULL);
7274 pthread_mutex_init(&m_surfaceLock, NULL);
75+ surfaceInterface_init();
7376 }
7477
7578 eglDisplay::~eglDisplay()
--- /dev/null
+++ b/system/surfaceInterface/Android.mk
@@ -0,0 +1,13 @@
1+ifneq (false,$(BUILD_EMULATOR_OPENGL_DRIVER))
2+
3+LOCAL_PATH := $(call my-dir)
4+
5+$(call emugl-begin-static-library,libsurfaceInterface)
6+$(call emugl-import,libOpenglSystemCommon)
7+
8+LOCAL_SRC_FILES := surfaceInterface.cpp
9+LOCAL_SHARED_LIBRARIES := libgui
10+
11+$(call emugl-end-module)
12+
13+endif # BUILD_EMULATOR_OPENGL_DRIVER != false
--- /dev/null
+++ b/system/surfaceInterface/surfaceInterface.cpp
@@ -0,0 +1,36 @@
1+#include "surfaceInterface.h"
2+
3+#include <cutils/log.h>
4+#include <gui/Surface.h>
5+
6+class SurfaceInterface : public android::ANativeObjectBase<
7+ ANativeWindow,
8+ android::Surface,
9+ android::RefBase> {
10+public:
11+ static SurfaceInterface* get();
12+ void setAsyncMode(ANativeWindow* anw, bool async) {
13+ ALOGD("SurfaceInterface::%s: set async mode %d", __func__, async);
14+ window = anw;
15+ android::Surface* s = android::Surface::getSelf(window);
16+ s->setAsyncMode(async);
17+ window = NULL;
18+ }
19+ ANativeWindow* window;
20+};
21+
22+static SurfaceInterface* sSurfaceInterface = NULL;
23+
24+SurfaceInterface* SurfaceInterface::get() {
25+ if (!sSurfaceInterface)
26+ sSurfaceInterface = new SurfaceInterface;
27+ return sSurfaceInterface;
28+}
29+
30+extern "C" void surfaceInterface_init() {
31+ SurfaceInterface::get();
32+}
33+
34+extern "C" void surfaceInterface_setAsyncModeForWindow(void* window) {
35+ SurfaceInterface::get()->setAsyncMode((ANativeWindow*)window, true);
36+}
--- /dev/null
+++ b/system/surfaceInterface/surfaceInterface.h
@@ -0,0 +1,25 @@
1+/*
2+* Copyright (C) 2017 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+#pragma once
17+
18+#if PLATFORM_SDK_VERSION >= 16
19+#include <system/window.h>
20+#else // PLATFORM_SDK_VERSION >= 16
21+#include <private/ui/android_natives_priv.h>
22+#endif // PLATFORM_SDK_VERSION >= 16
23+
24+extern "C" void surfaceInterface_init();
25+extern "C" void surfaceInterface_setAsyncModeForWindow(void* window);
Afficher sur ancien navigateur de dépôt.