From 8b559093880112709bd44e92125df60388f83a52 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 25 Aug 2011 22:00:55 +0200 Subject: [PATCH 1/6] emulator: fix the build Change-Id: Id88f488d441f04b10de3bca8ffe5c37763c4e98e --- .../emulator/opengl/host/renderer/Android.mk | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/tools/emulator/opengl/host/renderer/Android.mk b/tools/emulator/opengl/host/renderer/Android.mk index 934931b5f..55fcb8040 100644 --- a/tools/emulator/opengl/host/renderer/Android.mk +++ b/tools/emulator/opengl/host/renderer/Android.mk @@ -1,31 +1,14 @@ LOCAL_PATH:=$(call my-dir) # host renderer process ########################### -include $(CLEAR_VARS) +$(call emugl-begin-host-executable,emulator_renderer) +$(call emugl-import,libOpenglRender) +LOCAL_SRC_FILES := main.cpp +LOCAL_CFLAGS += -O0 -g -emulatorOpengl := $(LOCAL_PATH)/../.. +#ifeq ($(HOST_OS),windows) +#LOCAL_LDLIBS += -lws2_32 +#endif -LOCAL_MODULE := emulator_renderer -LOCAL_MODULE_TAGS := debug +$(call emugl-end-module) -LOCAL_SRC_FILES := \ - main.cpp - -LOCAL_CFLAGS += -g -O0 - -LOCAL_C_INCLUDES := $(emulatorOpengl)/host/include \ - $(emulatorOpengl)/host/include/libOpenglRender \ - $(emulatorOpengl)/shared/OpenglOsUtils \ - $(emulatorOpengl)/shared/OpenglCodecCommon \ - $(emulatorOpengl)/host/libs/libOpenglRender - -ifeq ($(HOST_OS),windows) -LOCAL_LDLIBS += -lws2_32 -endif - -LOCAL_SHARED_LIBRARIES := libOpenglRender \ - libGLESv1_dec \ - libGLESv2_dec \ - lib_renderControl_dec - -include $(BUILD_HOST_EXECUTABLE) From 20d5b0a85701582fb9a68bf32c5d81601534f18b Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 25 Aug 2011 22:14:29 +0200 Subject: [PATCH 2/6] emulator: oops, really fix the build Change-Id: Id8de1b6a069cdc462681cf44bf8ebd84bbd1e6f0 --- tools/emulator/opengl/host/libs/libOpenglRender/Android.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/Android.mk b/tools/emulator/opengl/host/libs/libOpenglRender/Android.mk index 1096e1067..3beee9582 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/Android.mk +++ b/tools/emulator/opengl/host/libs/libOpenglRender/Android.mk @@ -39,6 +39,7 @@ LOCAL_SRC_FILES := \ RenderServer.cpp $(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/host/include) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) # use Translator's egl/gles headers LOCAL_C_INCLUDES += $(EMUGL_PATH)/host/libs/Translator/include From 783cc1bb53dc025a8ca6b08c1e35755e83734d08 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Fri, 26 Aug 2011 17:29:10 +0200 Subject: [PATCH 3/6] emulator: opengl: fallback gralloc module This patch modifies the gralloc.goldfish module to check that the emulator does, indeed, support GPU emulation. If this is not the case, it loads the framebuffer-based fallback module (gralloc.default) explicitely and uses it instead. This is necessary because sometimes the emulator will be started in headless mode in restricted environment, i.e. without access to the display subsystem or GL libraries, which make GPU emulation impossible. We check for ro.kernel.qemu.gles which will be either undefined or set to 0 if the emulator doesn't support GPU emulation, or 1 otherwise. Change-Id: Ib6b143e6dcdfb44ff2c5b889138d0fb4118bb461 --- .../opengl/system/gralloc/gralloc.cpp | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/tools/emulator/opengl/system/gralloc/gralloc.cpp b/tools/emulator/opengl/system/gralloc/gralloc.cpp index 93fe6ac86..258b0db85 100644 --- a/tools/emulator/opengl/system/gralloc/gralloc.cpp +++ b/tools/emulator/opengl/system/gralloc/gralloc.cpp @@ -23,11 +23,12 @@ #include #include #include +#include #include #include "HostConnection.h" #include "glUtils.h" #include - +#include #define DBG_FUNC DBG("%s\n", __FUNCTION__) // @@ -37,6 +38,16 @@ struct private_module_t { gralloc_module_t base; }; +/* If not NULL, this is a pointer to the fallback module. + * This really is gralloc.default, which we'll use if we detect + * that the emulator we're running in does not support GPU emulation. + */ +static gralloc_module_t* sFallback; +static pthread_once_t sFallbackOnce = PTHREAD_ONCE_INIT; + +static void fallback_init(void); // forward + + typedef struct _alloc_list_node { buffer_handle_t handle; _alloc_list_node *next; @@ -401,6 +412,12 @@ static int fb_close(struct hw_device_t *dev) static int gralloc_register_buffer(gralloc_module_t const* module, buffer_handle_t handle) { + pthread_once(&sFallbackOnce, fallback_init); + if (sFallback != NULL) { + return sFallback->registerBuffer(sFallback, handle); + } + + private_module_t *gr = (private_module_t *)module; cb_handle_t *cb = (cb_handle_t *)handle; if (!gr || !cb_handle_t::validate(cb)) { @@ -428,6 +445,10 @@ static int gralloc_register_buffer(gralloc_module_t const* module, static int gralloc_unregister_buffer(gralloc_module_t const* module, buffer_handle_t handle) { + if (sFallback != NULL) { + return sFallback->unregisterBuffer(sFallback, handle); + } + private_module_t *gr = (private_module_t *)module; cb_handle_t *cb = (cb_handle_t *)handle; if (!gr || !cb_handle_t::validate(cb)) { @@ -458,6 +479,10 @@ static int gralloc_lock(gralloc_module_t const* module, int l, int t, int w, int h, void** vaddr) { + if (sFallback != NULL) { + return sFallback->lock(sFallback, handle, usage, l, t, w, h, vaddr); + } + private_module_t *gr = (private_module_t *)module; cb_handle_t *cb = (cb_handle_t *)handle; if (!gr || !cb_handle_t::validate(cb)) { @@ -546,6 +571,10 @@ static int gralloc_lock(gralloc_module_t const* module, static int gralloc_unlock(gralloc_module_t const* module, buffer_handle_t handle) { + if (sFallback != NULL) { + return sFallback->unlock(sFallback, handle); + } + private_module_t *gr = (private_module_t *)module; cb_handle_t *cb = (cb_handle_t *)handle; if (!gr || !cb_handle_t::validate(cb)) { @@ -603,6 +632,7 @@ static int gralloc_unlock(gralloc_module_t const* module, return 0; } + static int gralloc_device_open(const hw_module_t* module, const char* name, hw_device_t** device) @@ -611,6 +641,11 @@ static int gralloc_device_open(const hw_module_t* module, LOGD("gralloc_device_open %s\n", name); + pthread_once( &sFallbackOnce, fallback_init ); + if (sFallback != NULL) { + return sFallback->common.methods->open(&sFallback->common, name, device); + } + if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) { // Create host connection and keep it in the TLS. @@ -731,3 +766,32 @@ struct private_module_t HAL_MODULE_INFO_SYM = { reserved_proc : {NULL, } } }; + +/* This function is called once to detect whether the emulator supports + * GPU emulation (this is done by looking at the qemu.gles kernel + * parameter, which must be > 0 if this is the case). + * + * If not, then load gralloc.default instead as a fallback. + */ +static void +fallback_init(void) +{ + char prop[PROPERTY_VALUE_MAX]; + void* module; + + property_get("ro.kernel.qemu.gles", prop, "0"); + if (atoi(prop) > 0) { + return; + } + LOGD("Emulator without GPU emulation detected."); + module = dlopen("/system/lib/hw/gralloc.default.so", RTLD_LAZY|RTLD_LOCAL); + if (module != NULL) { + sFallback = reinterpret_cast(dlsym(module, HAL_MODULE_INFO_SYM_AS_STR)); + if (sFallback == NULL) { + dlclose(module); + } + } + if (sFallback == NULL) { + LOGE("Could not find software fallback module!?"); + } +} From 2dfb7b549fdac11426a54fe07656f2799db4e976 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Fri, 26 Aug 2011 18:16:53 +0200 Subject: [PATCH 4/6] emulator: opengl: fix the build Change-Id: Ia20d15b63a059ed5d86c9087b827bdfa32c41c86 --- tools/emulator/opengl/system/gralloc/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/emulator/opengl/system/gralloc/Android.mk b/tools/emulator/opengl/system/gralloc/Android.mk index 810f8120a..870560253 100644 --- a/tools/emulator/opengl/system/gralloc/Android.mk +++ b/tools/emulator/opengl/system/gralloc/Android.mk @@ -12,7 +12,7 @@ LOCAL_SRC_FILES := gralloc.cpp # Need to access the special OPENGL TLS Slot LOCAL_C_INCLUDES += bionic/libc/private - +LOCAL_SHARED_LIBRARIES += libdl $(call emugl-end-module) From 34fa5630b7fab21ebd3df462a744ae93da70518f Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 29 Aug 2011 22:20:37 +0200 Subject: [PATCH 5/6] emulator: opengl: Fix the emulator-specific builds. The gralloc.goldfish module cannot build in master because the gralloc interface evolved considerably since gingerbread (which the current code is based on). For now, disable it completely, this will make it impossible to test GPU emulation in the internal master tree for now. We'll have to port this module to the new world-order to solve this. Change-Id: I864217f9c41fd1234f0df497005499800af879e5 --- tools/emulator/opengl/Android.mk | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/emulator/opengl/Android.mk b/tools/emulator/opengl/Android.mk index a67facb3f..939a363ea 100644 --- a/tools/emulator/opengl/Android.mk +++ b/tools/emulator/opengl/Android.mk @@ -9,14 +9,10 @@ # ifeq (true,$(BUILD_EMULATOR_OPENGL)) -# By default, always build the gralloc.goldfish support library to ensure -# that SurfaceFlinger always uses our GLES emulation libraries. If you -# don't want this, explicitely set BUILD_EMULATOR_OPENGL_DRIVER to 'false' -# in your environment or your BoardConfig.mk. For the record, this should -# only be done for debugging specific applications and requires remoting -# the GL window from the emulator UI to be usable. -# -BUILD_EMULATOR_OPENGL_DRIVER ?= true +# By default, NEVER build the gralloc.goldfish support library because +# the code has not been ported to Honeycomb / IceCreamSandwich yet and +# will fail to build properly. +BUILD_EMULATOR_OPENGL_DRIVER ?= false # Top-level for all modules EMUGL_PATH := $(call my-dir) From 648e25f0c79b898c377f50b7dc51e3e7daa7c542 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Mon, 29 Aug 2011 18:39:21 -0700 Subject: [PATCH 6/6] Dang you, TabHost. Change-Id: I937cd0748fe0c44d6cd642637321aa6eb550cf91 --- .../android/supportv4/app/FragmentTabsPager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.java b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.java index 75498fd23..cf734d718 100644 --- a/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.java +++ b/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.java @@ -24,7 +24,9 @@ import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.View; +import android.view.ViewGroup; import android.widget.TabHost; +import android.widget.TabWidget; import java.util.ArrayList; @@ -159,7 +161,16 @@ public class FragmentTabsPager extends FragmentActivity { @Override public void onPageSelected(int position) { + // Unfortunately when TabHost changes the current tab, it kindly + // also takes care of putting focus on it when not in touch mode. + // The jerk. + // This hack tries to prevent this from pulling focus out of our + // ViewPager. + TabWidget widget = mTabHost.getTabWidget(); + int oldFocusability = widget.getDescendantFocusability(); + widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); mTabHost.setCurrentTab(position); + widget.setDescendantFocusability(oldFocusability); } @Override