diff options
author | David 'Digit' Turner <digit@google.com> | 2015-03-20 22:17:12 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-20 22:17:12 +0000 |
commit | c714e27a4ef2f451bd0517de73797405dcdf683b (patch) | |
tree | 33b7e4f6de969d379a823543923d0750da54843a /emulator/opengl | |
parent | fc2a7dfe9350400514c8e21023ea2ef46266f712 (diff) | |
parent | ddb5d875c38022441d4b2e9de3b874b5e1c4df9b (diff) | |
download | sdk-c714e27a4ef2f451bd0517de73797405dcdf683b.zip sdk-c714e27a4ef2f451bd0517de73797405dcdf683b.tar.gz sdk-c714e27a4ef2f451bd0517de73797405dcdf683b.tar.bz2 |
am ddb5d875: am 972e1c6d: Merge "emulator/opengl: Cleanup build files + remove obsolete tests."
* commit 'ddb5d875c38022441d4b2e9de3b874b5e1c4df9b':
emulator/opengl: Cleanup build files + remove obsolete tests.
Diffstat (limited to 'emulator/opengl')
62 files changed, 84 insertions, 6756 deletions
diff --git a/emulator/opengl/Android.mk b/emulator/opengl/Android.mk index 7906fdd..244b874 100644 --- a/emulator/opengl/Android.mk +++ b/emulator/opengl/Android.mk @@ -21,12 +21,6 @@ ifeq ($(BUILD_STANDALONE_EMULATOR),true) EMUGL_COMMON_INCLUDES := $(EMUGL_PATH)/host/libs/Translator/include endif -ifeq ($(BUILD_STANDALONE_EMULATOR),true) -EMUGL_BUILD_64BITS := $(strip $(EMULATOR_BUILD_64BITS)) -else -EMUGL_BUILD_64BITS := true -endif - # common cflags used by several modules # This is always set to a module's LOCAL_CFLAGS # See the definition of emugl-begin-module in common.mk @@ -79,25 +73,12 @@ include $(EMUGL_PATH)/shared/OpenglCodecCommon/Android.mk include $(EMUGL_PATH)/host/libs/GLESv1_dec/Android.mk include $(EMUGL_PATH)/host/libs/GLESv2_dec/Android.mk include $(EMUGL_PATH)/host/libs/renderControl_dec/Android.mk -include $(EMUGL_PATH)/tests/ut_rendercontrol_dec/Android.mk include $(EMUGL_PATH)/host/libs/Translator/GLcommon/Android.mk include $(EMUGL_PATH)/host/libs/Translator/GLES_CM/Android.mk include $(EMUGL_PATH)/host/libs/Translator/GLES_V2/Android.mk include $(EMUGL_PATH)/host/libs/Translator/EGL/Android.mk -# Required to declare SDL-related flags for some host tests. -include $(EMUGL_PATH)/sdl.mk - # Host shared libraries include $(EMUGL_PATH)/host/libs/libOpenglRender/Android.mk -# Host executables -include $(EMUGL_PATH)/host/renderer/Android.mk - -# Host unit-test for the renderer. - -include $(EMUGL_PATH)/tests/translator_tests/MacCommon/Android.mk -include $(EMUGL_PATH)/tests/translator_tests/GLES_CM/Android.mk -include $(EMUGL_PATH)/tests/translator_tests/GLES_V2/Android.mk - endif # BUILD_EMULATOR_HOST_OPENGL == true diff --git a/emulator/opengl/googletest.mk b/emulator/opengl/googletest.mk index 8147874..7531394 100644 --- a/emulator/opengl/googletest.mk +++ b/emulator/opengl/googletest.mk @@ -30,14 +30,12 @@ $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/include) $(call emugl-export,LDLIBS,$(common_LDLIBS)) $(call emugl-end-module) -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-static-library,lib64emugl_gtest) - LOCAL_SRC_FILES := $(common_SRC_FILES) - LOCAL_CFLAGS += $(common_CFLAGS) - LOCAL_C_INCLUDES += $(LOCAL_PATH)/include - LOCAL_CPP_EXTENSION := .cc - $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/include) - $(call emugl-export,CFLAGS,-m64) - $(call emugl-export,LDLIBS,$(common_LDLIBS) -m64) - $(call emugl-end-module) -endif # EMUGL_BUILD_64BITS +$(call emugl-begin-host64-static-library,lib64emugl_gtest) +LOCAL_SRC_FILES := $(common_SRC_FILES) +LOCAL_CFLAGS += $(common_CFLAGS) +LOCAL_C_INCLUDES += $(LOCAL_PATH)/include +LOCAL_CPP_EXTENSION := .cc +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/include) +$(call emugl-export,LDLIBS,$(common_LDLIBS)) +$(call emugl-end-module) + diff --git a/emulator/opengl/host/libs/GLESv1_dec/Android.mk b/emulator/opengl/host/libs/GLESv1_dec/Android.mk index e0eca6e..c9db93e 100644 --- a/emulator/opengl/host/libs/GLESv1_dec/Android.mk +++ b/emulator/opengl/host/libs/GLESv1_dec/Android.mk @@ -24,18 +24,16 @@ $(call emugl-end-module) ### host library, 64-bit #################################### -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-static-library,lib64GLESv1_dec) +$(call emugl-begin-host64-static-library,lib64GLESv1_dec) - $(call emugl-import, lib64OpenglCodecCommon) - $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-import, lib64OpenglCodecCommon) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) - $(call emugl-gen-decoder,$(LOCAL_PATH),gl) +$(call emugl-gen-decoder,$(LOCAL_PATH),gl) - LOCAL_SRC_FILES := GLDecoder.cpp +LOCAL_SRC_FILES := GLDecoder.cpp - $(call emugl-export,CFLAGS,$(host_common_debug_CFLAGS) -m64) - $(call emugl-export,LDLIBS,-lstdc++) +$(call emugl-export,CFLAGS,$(host_common_debug_CFLAGS)) +$(call emugl-export,LDLIBS,-lstdc++) - $(call emugl-end-module) -endif
\ No newline at end of file +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/GLESv2_dec/Android.mk b/emulator/opengl/host/libs/GLESv2_dec/Android.mk index f658f11..0ad6ddb 100644 --- a/emulator/opengl/host/libs/GLESv2_dec/Android.mk +++ b/emulator/opengl/host/libs/GLESv2_dec/Android.mk @@ -22,17 +22,15 @@ LOCAL_SRC_FILES := GL2Decoder.cpp $(call emugl-end-module) ### host library, 64-bit #################################### -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-static-library,lib64GLESv2_dec) - $(call emugl-import, lib64OpenglCodecCommon) - $(call emugl-gen-decoder,$(LOCAL_PATH),gl2) +$(call emugl-begin-host64-static-library,lib64GLESv2_dec) +$(call emugl-import, lib64OpenglCodecCommon) +$(call emugl-gen-decoder,$(LOCAL_PATH),gl2) - # For gl2_types.h ! - $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +# For gl2_types.h ! +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) - $(call emugl-export,CFLAGS,$(host_common_debug_CFLAGS) -m64) +$(call emugl-export,CFLAGS,$(host_common_debug_CFLAGS)) - LOCAL_SRC_FILES := GL2Decoder.cpp +LOCAL_SRC_FILES := GL2Decoder.cpp - $(call emugl-end-module) -endif
\ No newline at end of file +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/Translator/EGL/Android.mk b/emulator/opengl/host/libs/Translator/EGL/Android.mk index 5d1c9b2..298c502 100644 --- a/emulator/opengl/host/libs/Translator/EGL/Android.mk +++ b/emulator/opengl/host/libs/Translator/EGL/Android.mk @@ -47,12 +47,10 @@ LOCAL_SRC_FILES := $(host_common_SRC_FILES) $(call emugl-end-module) ### EGL host implementation, 64-bit ######################## -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-shared-library,lib64EGL_translator) - $(call emugl-import,lib64GLcommon) +$(call emugl-begin-host64-shared-library,lib64EGL_translator) +$(call emugl-import,lib64GLcommon) - LOCAL_LDLIBS += $(host_common_LDLIBS) -m64 - LOCAL_SRC_FILES := $(host_common_SRC_FILES) +LOCAL_LDLIBS += $(host_common_LDLIBS) +LOCAL_SRC_FILES := $(host_common_SRC_FILES) - $(call emugl-end-module) -endif +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk b/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk index c5e7e6d..48cb5c4 100644 --- a/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk +++ b/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk @@ -9,23 +9,13 @@ host_common_SRC_FILES := \ ### GLES_CM host implementation (On top of OpenGL) ######################## $(call emugl-begin-host-shared-library,libGLES_CM_translator) - $(call emugl-import,libGLcommon) - LOCAL_SRC_FILES := $(host_common_SRC_FILES) - $(call emugl-end-module) ### GLES_CM host implementation, 64-bit ######################## -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-shared-library,lib64GLES_CM_translator) - - $(call emugl-import,lib64GLcommon) - - LOCAL_CFLAGS += -fPIC - LOCAL_LDLIBS += -m64 - LOCAL_SRC_FILES := $(host_common_SRC_FILES) - - $(call emugl-end-module) -endif
\ No newline at end of file +$(call emugl-begin-host64-shared-library,lib64GLES_CM_translator) +$(call emugl-import,lib64GLcommon) +LOCAL_SRC_FILES := $(host_common_SRC_FILES) +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk b/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk index 438334a..c96965b 100644 --- a/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk +++ b/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk @@ -18,12 +18,9 @@ $(call emugl-end-module) ### GLES_V2 host implementation, 64-bit ############################## -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-shared-library,lib64GLES_V2_translator) - $(call emugl-import, lib64GLcommon) +$(call emugl-begin-host64-shared-library,lib64GLES_V2_translator) +$(call emugl-import, lib64GLcommon) - LOCAL_LDLIBS += -m64 - LOCAL_SRC_FILES := $(host_common_SRC_FILES) +LOCAL_SRC_FILES := $(host_common_SRC_FILES) - $(call emugl-end-module) -endif
\ No newline at end of file +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/Translator/GLcommon/Android.mk b/emulator/opengl/host/libs/Translator/GLcommon/Android.mk index fdbedad..d1a462d 100644 --- a/emulator/opengl/host/libs/Translator/GLcommon/Android.mk +++ b/emulator/opengl/host/libs/Translator/GLcommon/Android.mk @@ -46,16 +46,13 @@ $(call emugl-end-module) ### EGL host implementation, 64-bit ################ -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-static-library,lib64GLcommon) - - translator_path := $(LOCAL_PATH)/.. - LOCAL_SRC_FILES := $(host_common_SRC_FILES) - LOCAL_CFLAGS += -fPIC - $(call emugl-export,LDLIBS,$(host_common_LDLIBS)) - $(call emugl-export,LDFLAGS,$(host_common_LDFLAGS)) - $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/../include $(EMUGL_PATH)/shared) - $(call emugl-export,STATIC_LIBRARIES, lib64emugl_common) - - $(call emugl-end-module) -endif
\ No newline at end of file +$(call emugl-begin-host64-static-library,lib64GLcommon) + +translator_path := $(LOCAL_PATH)/.. +LOCAL_SRC_FILES := $(host_common_SRC_FILES) +$(call emugl-export,LDLIBS,$(host_common_LDLIBS)) +$(call emugl-export,LDFLAGS,$(host_common_LDFLAGS)) +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/../include $(EMUGL_PATH)/shared) +$(call emugl-export,STATIC_LIBRARIES, lib64emugl_common) + +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/libOpenglRender/Android.mk b/emulator/opengl/host/libs/libOpenglRender/Android.mk index ca5a08a..20567f0 100644 --- a/emulator/opengl/host/libs/libOpenglRender/Android.mk +++ b/emulator/opengl/host/libs/libOpenglRender/Android.mk @@ -62,24 +62,21 @@ $(call emugl-end-module) ### host libOpenglRender, 64-bit ######################################### -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-shared-library,lib64OpenglRender) +$(call emugl-begin-host64-shared-library,lib64OpenglRender) - $(call emugl-import,lib64GLESv1_dec lib64GLESv2_dec lib64_renderControl_dec lib64OpenglCodecCommon) +$(call emugl-import,lib64GLESv1_dec lib64GLESv2_dec lib64_renderControl_dec lib64OpenglCodecCommon) - #LOCAL_LDFLAGS += -m64 # adding -m64 here doesn't work, because it somehow appear BEFORE -m32 in command-line. - LOCAL_LDLIBS += $(host_common_LDLIBS) -m64 # Put -m64 it in LOCAL_LDLIBS instead. +LOCAL_LDLIBS += $(host_common_LDLIBS) - LOCAL_SRC_FILES := $(host_common_SRC_FILES) - $(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/host/include) - $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +LOCAL_SRC_FILES := $(host_common_SRC_FILES) +$(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 +# use Translator's egl/gles headers +LOCAL_C_INCLUDES += $(EMUGL_PATH)/host/libs/Translator/include - LOCAL_STATIC_LIBRARIES += lib64emugl_common +LOCAL_STATIC_LIBRARIES += lib64emugl_common - $(call emugl-export,CFLAGS,$(host_common_CFLAGS) -m64) +$(call emugl-export,CFLAGS,$(host_common_CFLAGS)) - $(call emugl-end-module) -endif
\ No newline at end of file +$(call emugl-end-module) diff --git a/emulator/opengl/host/libs/renderControl_dec/Android.mk b/emulator/opengl/host/libs/renderControl_dec/Android.mk index 4a97a93..f1ba595 100644 --- a/emulator/opengl/host/libs/renderControl_dec/Android.mk +++ b/emulator/opengl/host/libs/renderControl_dec/Android.mk @@ -10,12 +10,9 @@ $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) $(call emugl-end-module) ### host library, 64-bit #################################### -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-static-library,lib64_renderControl_dec) - $(call emugl-import,lib64OpenglCodecCommon) - $(call emugl-gen-decoder,$(LOCAL_PATH),renderControl) - # For renderControl_types.h - $(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) - $(call emugl-export,CFLAGS,-m64) - $(call emugl-end-module) -endif
\ No newline at end of file +$(call emugl-begin-host64-static-library,lib64_renderControl_dec) +$(call emugl-import,lib64OpenglCodecCommon) +$(call emugl-gen-decoder,$(LOCAL_PATH),renderControl) +# For renderControl_types.h +$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) +$(call emugl-end-module) diff --git a/emulator/opengl/host/renderer/Android.mk b/emulator/opengl/host/renderer/Android.mk deleted file mode 100644 index 81dcaf7..0000000 --- a/emulator/opengl/host/renderer/Android.mk +++ /dev/null @@ -1,14 +0,0 @@ -LOCAL_PATH:=$(call my-dir) - -# host renderer process ########################### -$(call emugl-begin-host-executable,emulator_renderer) -$(call emugl-import,libOpenglRender) -LOCAL_SRC_FILES := main.cpp -LOCAL_CFLAGS += -O0 -g - -ifeq ($(HOST_OS),linux) -LOCAL_LDLIBS += -lX11 -endif - -$(call emugl-end-module) - diff --git a/emulator/opengl/host/renderer/main.cpp b/emulator/opengl/host/renderer/main.cpp deleted file mode 100644 index 470e692..0000000 --- a/emulator/opengl/host/renderer/main.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "RenderServer.h" -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include "FrameBuffer.h" - -#include <sys/types.h> -#include <unistd.h> -#include <codec_defs.h> -#ifdef _WIN32 -#include <winsock2.h> -#endif - -#ifdef __linux__ -#include <X11/Xlib.h> -#endif - -static void printUsage(const char *progName) -{ - fprintf(stderr, "Usage: %s -windowid <windowid> [options]\n", progName); - fprintf(stderr, " -windowid <windowid> - window id to render into\n"); - fprintf(stderr, " -x <num> - render subwindow x position\n"); - fprintf(stderr, " -y <num> - render subwindow y position\n"); - fprintf(stderr, " -width <num> - render subwindow width\n"); - fprintf(stderr, " -height <num> - render subwindow height\n"); - exit(-1); -} - -int main(int argc, char *argv[]) -{ - int winX = 0; - int winY = 0; - int winWidth = 320; - int winHeight = 480; - FBNativeWindowType windowId = 0; - int iWindowId = 0; - - // - // Parse command line arguments - // - for (int i=1; i<argc; i++) { - if (!strcmp(argv[i], "-windowid")) { - if (++i >= argc || sscanf(argv[i],"%d", &iWindowId) != 1) { - printUsage(argv[0]); - } - } - else if (!strncmp(argv[i], "-x", 2)) { - if (++i >= argc || sscanf(argv[i],"%d", &winX) != 1) { - printUsage(argv[0]); - } - } - else if (!strncmp(argv[i], "-y", 2)) { - if (++i >= argc || sscanf(argv[i],"%d", &winY) != 1) { - printUsage(argv[0]); - } - } - else if (!strncmp(argv[i], "-width", 6)) { - if (++i >= argc || sscanf(argv[i],"%d", &winWidth) != 1) { - printUsage(argv[0]); - } - } - else if (!strncmp(argv[i], "-height", 7)) { - if (++i >= argc || sscanf(argv[i],"%d", &winHeight) != 1) { - printUsage(argv[0]); - } - } - } - - windowId = (FBNativeWindowType)iWindowId; - if (!windowId) { - // window id must be provided - printUsage(argv[0]); - } - -#if 0 //Enable to attach gdb to renderer on startup - fprintf(stderr, "renderer pid %d , press any key to continue...\n", getpid()); - getchar(); -#else - fprintf(stderr, "renderer pid %d \n", getpid()); -#endif - -#ifdef _WIN32 - WSADATA wsaData; - int rc = WSAStartup( MAKEWORD(2,2), &wsaData); - if (rc != 0) { - printf( "could not initialize Winsock\n" ); - } -#endif - -#ifdef __linux__ - // some OpenGL implementations may call X functions - // it is safer to synchronize all X calls made by all the - // rendering threads. (although the calls we do are locked - // in the FrameBuffer singleton object). - XInitThreads(); -#endif - - // - // initialize Framebuffer - // - bool inited = FrameBuffer::initialize(winWidth, winHeight); - if (!inited) { - fprintf(stderr,"Failed to initialize Framebuffer\n"); - return -1; - } - - inited = FrameBuffer::setupSubWindow(windowId, - winX, winY, winWidth, winHeight, 0.0); - if (!inited) { - fprintf(stderr,"Failed to create subwindow Framebuffer\n"); - return -1; - } - - // - // Create and run a render server listening to the given port number - // - char addr[256]; - RenderServer *server = RenderServer::create(addr, sizeof(addr)); - if (!server) { - fprintf(stderr,"Cannot initialize render server\n"); - return -1; - } - printf("render server listening at '%s'\n", addr); - -#ifndef _WIN32 - // - // run the server listener loop - // - server->main(); -#else - // - // on windows we need to handle messages for the - // created subwindow. So we run the server on a seperate - // thread and running the windows message pump loop - // in this main thread. - // - server->start(); - - // - // Dispatch events for the subwindow - // During termination of the render server, the FrameBuffer - // will be finalized, the Framebuffer subwindow will - // get destroyed and the following loop will exit. - // - MSG msg; - HWND hWnd = FrameBuffer::getFB()->getSubWindow(); - while( GetMessage(&msg, hWnd, 0, 0) > 0 ) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } -#endif - - return 0; -} diff --git a/emulator/opengl/sdl.mk b/emulator/opengl/sdl.mk deleted file mode 100644 index a85ed58..0000000 --- a/emulator/opengl/sdl.mk +++ /dev/null @@ -1,25 +0,0 @@ -# This contains common definitions used to define a host module to -# link SDL with the EmuGL test programs. - -ifeq ($(BUILD_STANDALONE_EMULATOR),true) - -# When using the emulator standalone build, inherit the values from the -# Makefile that included us. -EMUGL_SDL_CFLAGS := $(SDL_CFLAGS) -EMUGL_SDL_LDLIBS := $(SDL_LDLIBS) -EMUGL_SDL_STATIC_LIBRARIES := emulator_libSDL emulator_libSDLmain - -else # BUILD_STANDALONE_EMULATOR != true - -# Otherwise, use the prebuilt libraries that come with the platform. - -EMUGL_SDL_CONFIG ?= prebuilts/tools/$(HOST_PREBUILT_TAG)/sdl/bin/sdl-config -EMUGL_SDL_CFLAGS := $(shell $(EMUGL_SDL_CONFIG) --cflags) -EMUGL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(EMUGL_SDL_CONFIG) --static-libs)) -EMUGL_SDL_STATIC_LIBRARIES := libSDL libSDLmain - -ifeq ($(HOST_OS),windows) -EMUGL_SDL_LDLIBS += -lws2_32 -endif - -endif # BUILD_STANDALONE_EMULATOR != true diff --git a/emulator/opengl/shared/OpenglCodecCommon/Android.mk b/emulator/opengl/shared/OpenglCodecCommon/Android.mk index 0c3f827..ff680eb 100644 --- a/emulator/opengl/shared/OpenglCodecCommon/Android.mk +++ b/emulator/opengl/shared/OpenglCodecCommon/Android.mk @@ -34,14 +34,11 @@ $(call emugl-end-module) ### OpenglCodecCommon host, 64-bit ######################################### -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-static-library,lib64OpenglCodecCommon) +$(call emugl-begin-host64-static-library,lib64OpenglCodecCommon) - LOCAL_SRC_FILES := $(host_commonSources) +LOCAL_SRC_FILES := $(host_commonSources) +$(call emugl-import, lib64emugl_common) +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/host/include/libOpenglRender $(LOCAL_PATH)) +$(call emugl-export,LDLIBS,$(host_commonLdLibs)) +$(call emugl-end-module) - $(call emugl-import, lib64emugl_common) - $(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/host/include/libOpenglRender $(LOCAL_PATH)) - $(call emugl-export,CFLAGS,-m64 -fPIC) - $(call emugl-export,LDLIBS,$(host_commonLdLibs)) - $(call emugl-end-module) -endif diff --git a/emulator/opengl/shared/emugl/common/Android.mk b/emulator/opengl/shared/emugl/common/Android.mk index fb9ab57..6aaa0d9 100644 --- a/emulator/opengl/shared/emugl/common/Android.mk +++ b/emulator/opengl/shared/emugl/common/Android.mk @@ -31,14 +31,11 @@ $(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/shared) $(call emugl-export,LDLIBS,$(host_commonLdLibs)) $(call emugl-end-module) -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-static-library,lib64emugl_common) - LOCAL_SRC_FILES := $(host_commonSources) - $(call emugl-export,CFLAGS,-m64 -fPIC) - $(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/shared) - $(call emugl-export,LDLIBS,$(host_commonLdLibs)) - $(call emugl-end-module) -endif +$(call emugl-begin-host64-static-library,lib64emugl_common) +LOCAL_SRC_FILES := $(host_commonSources) +$(call emugl-export,C_INCLUDES,$(EMUGL_PATH)/shared) +$(call emugl-export,LDLIBS,$(host_commonLdLibs)) +$(call emugl-end-module) ### emugl_common_unittests ############################################## @@ -58,19 +55,16 @@ LOCAL_SRC_FILES := $(host_commonSources) $(call emugl-import,libemugl_common libemugl_gtest) $(call emugl-end-module) -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-executable,emugl64_common_host_unittests) - LOCAL_SRC_FILES := $(host_commonSources) - $(call emugl-import,lib64emugl_common lib64emugl_gtest) - $(call emugl-end-module) -endif +$(call emugl-begin-host64-executable,emugl64_common_host_unittests) +LOCAL_SRC_FILES := $(host_commonSources) +$(call emugl-import,lib64emugl_common lib64emugl_gtest) +$(call emugl-end-module) + $(call emugl-begin-host-shared-library,libemugl_test_shared_library) LOCAL_SRC_FILES := testing/test_shared_library.cpp $(call emugl-end-module) -ifdef EMUGL_BUILD_64BITS - $(call emugl-begin-host64-shared-library,lib64emugl_test_shared_library) - LOCAL_SRC_FILES := testing/test_shared_library.cpp - $(call emugl-end-module) -endif +$(call emugl-begin-host64-shared-library,lib64emugl_test_shared_library) +LOCAL_SRC_FILES := testing/test_shared_library.cpp +$(call emugl-end-module) diff --git a/emulator/opengl/tests/EGL_host_wrapper/Android.mk b/emulator/opengl/tests/EGL_host_wrapper/Android.mk deleted file mode 100644 index 19d8794..0000000 --- a/emulator/opengl/tests/EGL_host_wrapper/Android.mk +++ /dev/null @@ -1,16 +0,0 @@ -ifeq ($(HOST_OS),linux) - -LOCAL_PATH := $(call my-dir) - -$(call emugl-begin-host-static-library,libEGL_host_wrapper) - -LOCAL_SRC_FILES := \ - egl.cpp \ - egl_dispatch.cpp - -$(call emugl-export,LDLIBS,-ldl -pthread) -$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) - -$(call emugl-end-module) - -endif # HOST_OS == linux diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl.cpp b/emulator/opengl/tests/EGL_host_wrapper/egl.cpp deleted file mode 100644 index 6fa27ac..0000000 --- a/emulator/opengl/tests/EGL_host_wrapper/egl.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "egl_dispatch.h" -#include "egl_ftable.h" -#include <pthread.h> - -#define EGL_LIB "ANDROID_EGL_LIB" - -static struct egl_dispatch *s_dispatch = NULL; -static pthread_once_t eglDispatchInitialized = PTHREAD_ONCE_INIT; - -void initEglDispatch() -{ - // - // Load back-end EGL implementation library - // - char *eglLib = (char *) "libEGL.so"; - if (getenv(EGL_LIB) != NULL) { - eglLib = getenv(EGL_LIB); - } - - s_dispatch = loadEGL(eglLib); - if (!s_dispatch) { - fprintf(stderr,"FATAL ERROR: Could not load EGL lib [%s]\n", eglLib); - exit(-1); - } -} - -static struct egl_dispatch *getDispatch() -{ - pthread_once(&eglDispatchInitialized, initEglDispatch); - return s_dispatch; -} - -__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) -{ - for (int i=0; i<egl_num_funcs; i++) { - if (!strcmp(egl_funcs_by_name[i].name, procname)) { - return (__eglMustCastToProperFunctionPointerType)egl_funcs_by_name[i].proc; - } - } - - return getDispatch()->eglGetProcAddress(procname); -} - -//////////////// Path through functions ////////// - -EGLint eglGetError() -{ - return getDispatch()->eglGetError(); -} - -EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) -{ - return getDispatch()->eglGetDisplay(display_id); -} - -EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) -{ - return getDispatch()->eglInitialize(dpy, major, minor); -} - -EGLBoolean eglTerminate(EGLDisplay dpy) -{ - return getDispatch()->eglTerminate(dpy); -} - -const char* eglQueryString(EGLDisplay dpy, EGLint name) -{ - return getDispatch()->eglQueryString(dpy, name); -} - -EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config) -{ - return getDispatch()->eglGetConfigs(dpy, configs, config_size, num_config); -} - -EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) -{ - return getDispatch()->eglChooseConfig(dpy, attrib_list, configs, config_size, num_config); -} - -EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value) -{ - return getDispatch()->eglGetConfigAttrib(dpy, config, attribute, value); -} - -EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list) -{ - return getDispatch()->eglCreateWindowSurface(dpy, config, win, attrib_list); -} - -EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list) -{ - return getDispatch()->eglCreatePbufferSurface(dpy, config, attrib_list); -} - -EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) -{ - return getDispatch()->eglCreatePixmapSurface(dpy, config, pixmap, attrib_list); -} - -EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) -{ - return getDispatch()->eglDestroySurface(dpy, surface); -} - -EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) -{ - return getDispatch()->eglQuerySurface(dpy, surface, attribute, value); -} - -EGLBoolean eglBindAPI(EGLenum api) -{ - return getDispatch()->eglBindAPI(api); -} - -EGLenum eglQueryAPI() -{ - return getDispatch()->eglQueryAPI(); -} - -EGLBoolean eglWaitClient() -{ - return getDispatch()->eglWaitClient(); -} - -EGLBoolean eglReleaseThread() -{ - return getDispatch()->eglReleaseThread(); -} - -EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list) -{ - return getDispatch()->eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config, attrib_list); -} - -EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) -{ - return getDispatch()->eglSurfaceAttrib(dpy, surface, attribute, value); -} - -EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) -{ - return getDispatch()->eglBindTexImage(dpy, surface, buffer); -} - -EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) -{ - return getDispatch()->eglReleaseTexImage(dpy, surface, buffer); -} - -EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) -{ - return getDispatch()->eglSwapInterval(dpy, interval); -} - -EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) -{ - return getDispatch()->eglCreateContext(dpy, config, share_context, attrib_list); -} - -EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) -{ - return getDispatch()->eglDestroyContext(dpy, ctx); -} - -EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) -{ - return getDispatch()->eglMakeCurrent(dpy, draw, read, ctx); -} - -EGLContext eglGetCurrentContext() -{ - return getDispatch()->eglGetCurrentContext(); -} - -EGLSurface eglGetCurrentSurface(EGLint readdraw) -{ - return getDispatch()->eglGetCurrentSurface(readdraw); -} - -EGLDisplay eglGetCurrentDisplay() -{ - return getDispatch()->eglGetCurrentDisplay(); -} - -EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) -{ - return getDispatch()->eglQueryContext(dpy, ctx, attribute, value); -} - -EGLBoolean eglWaitGL() -{ - return getDispatch()->eglWaitGL(); -} - -EGLBoolean eglWaitNative(EGLint engine) -{ - return getDispatch()->eglWaitNative(engine); -} - -EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) -{ - return getDispatch()->eglSwapBuffers(dpy, surface); -} - -EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) -{ - return getDispatch()->eglCopyBuffers(dpy, surface, target); -} - -EGLBoolean eglLockSurfaceKHR(EGLDisplay display, EGLSurface surface, const EGLint *attrib_list) -{ - return getDispatch()->eglLockSurfaceKHR(display, surface, attrib_list); -} - -EGLBoolean eglUnlockSurfaceKHR(EGLDisplay display, EGLSurface surface) -{ - return getDispatch()->eglUnlockSurfaceKHR(display, surface); -} - -EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) -{ - return getDispatch()->eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list); -} - -EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) -{ - return getDispatch()->eglDestroyImageKHR(dpy, image); -} - -EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) -{ - return getDispatch()->eglCreateSyncKHR(dpy, type, attrib_list); -} - -EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) -{ - return getDispatch()->eglDestroySyncKHR(dpy, sync); -} - -EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) -{ - return getDispatch()->eglClientWaitSyncKHR(dpy, sync, flags, timeout); -} - -EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) -{ - return getDispatch()->eglSignalSyncKHR(dpy, sync, mode); -} - -EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value) -{ - return getDispatch()->eglGetSyncAttribKHR(dpy, sync, attribute, value); -} - -EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, EGLint left, EGLint top, EGLint width, EGLint height) -{ - return getDispatch()->eglSetSwapRectangleANDROID(dpy, draw, left, top, width, height); -} diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp deleted file mode 100644 index a9b8214..0000000 --- a/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include <stdio.h> -#include <dlfcn.h> -#include "egl_dispatch.h" - - -egl_dispatch *loadEGL(const char *p_eglPath) -{ - void *libEGL = dlopen(p_eglPath, RTLD_NOW); - if (!libEGL) { - return NULL; - } - - egl_dispatch *disp = new egl_dispatch; - - void *ptr; - ptr = dlsym(libEGL,"eglGetError"); disp->set_eglGetError((eglGetError_t)ptr); - ptr = dlsym(libEGL,"eglGetDisplay"); disp->set_eglGetDisplay((eglGetDisplay_t)ptr); - ptr = dlsym(libEGL,"eglInitialize"); disp->set_eglInitialize((eglInitialize_t)ptr); - ptr = dlsym(libEGL,"eglTerminate"); disp->set_eglTerminate((eglTerminate_t)ptr); - ptr = dlsym(libEGL,"eglQueryString"); disp->set_eglQueryString((eglQueryString_t)ptr); - ptr = dlsym(libEGL,"eglGetConfigs"); disp->set_eglGetConfigs((eglGetConfigs_t)ptr); - ptr = dlsym(libEGL,"eglChooseConfig"); disp->set_eglChooseConfig((eglChooseConfig_t)ptr); - ptr = dlsym(libEGL,"eglGetConfigAttrib"); disp->set_eglGetConfigAttrib((eglGetConfigAttrib_t)ptr); - ptr = dlsym(libEGL,"eglCreateWindowSurface"); disp->set_eglCreateWindowSurface((eglCreateWindowSurface_t)ptr); - ptr = dlsym(libEGL,"eglCreatePbufferSurface"); disp->set_eglCreatePbufferSurface((eglCreatePbufferSurface_t)ptr); - ptr = dlsym(libEGL,"eglCreatePixmapSurface"); disp->set_eglCreatePixmapSurface((eglCreatePixmapSurface_t)ptr); - ptr = dlsym(libEGL,"eglDestroySurface"); disp->set_eglDestroySurface((eglDestroySurface_t)ptr); - ptr = dlsym(libEGL,"eglQuerySurface"); disp->set_eglQuerySurface((eglQuerySurface_t)ptr); - ptr = dlsym(libEGL,"eglBindAPI"); disp->set_eglBindAPI((eglBindAPI_t)ptr); - ptr = dlsym(libEGL,"eglQueryAPI"); disp->set_eglQueryAPI((eglQueryAPI_t)ptr); - ptr = dlsym(libEGL,"eglWaitClient"); disp->set_eglWaitClient((eglWaitClient_t)ptr); - ptr = dlsym(libEGL,"eglReleaseThread"); disp->set_eglReleaseThread((eglReleaseThread_t)ptr); - ptr = dlsym(libEGL,"eglCreatePbufferFromClientBuffer"); disp->set_eglCreatePbufferFromClientBuffer((eglCreatePbufferFromClientBuffer_t)ptr); - ptr = dlsym(libEGL,"eglSurfaceAttrib"); disp->set_eglSurfaceAttrib((eglSurfaceAttrib_t)ptr); - ptr = dlsym(libEGL,"eglBindTexImage"); disp->set_eglBindTexImage((eglBindTexImage_t)ptr); - ptr = dlsym(libEGL,"eglReleaseTexImage"); disp->set_eglReleaseTexImage((eglReleaseTexImage_t)ptr); - ptr = dlsym(libEGL,"eglSwapInterval"); disp->set_eglSwapInterval((eglSwapInterval_t)ptr); - ptr = dlsym(libEGL,"eglCreateContext"); disp->set_eglCreateContext((eglCreateContext_t)ptr); - ptr = dlsym(libEGL,"eglDestroyContext"); disp->set_eglDestroyContext((eglDestroyContext_t)ptr); - ptr = dlsym(libEGL,"eglMakeCurrent"); disp->set_eglMakeCurrent((eglMakeCurrent_t)ptr); - ptr = dlsym(libEGL,"eglGetCurrentContext"); disp->set_eglGetCurrentContext((eglGetCurrentContext_t)ptr); - ptr = dlsym(libEGL,"eglGetCurrentSurface"); disp->set_eglGetCurrentSurface((eglGetCurrentSurface_t)ptr); - ptr = dlsym(libEGL,"eglGetCurrentDisplay"); disp->set_eglGetCurrentDisplay((eglGetCurrentDisplay_t)ptr); - ptr = dlsym(libEGL,"eglQueryContext"); disp->set_eglQueryContext((eglQueryContext_t)ptr); - ptr = dlsym(libEGL,"eglWaitGL"); disp->set_eglWaitGL((eglWaitGL_t)ptr); - ptr = dlsym(libEGL,"eglWaitNative"); disp->set_eglWaitNative((eglWaitNative_t)ptr); - ptr = dlsym(libEGL,"eglSwapBuffers"); disp->set_eglSwapBuffers((eglSwapBuffers_t)ptr); - ptr = dlsym(libEGL,"eglCopyBuffers"); disp->set_eglCopyBuffers((eglCopyBuffers_t)ptr); - ptr = dlsym(libEGL,"eglGetProcAddress"); disp->set_eglGetProcAddress((eglGetProcAddress_t)ptr); - ptr = dlsym(libEGL,"eglLockSurfaceKHR"); disp->set_eglLockSurfaceKHR((eglLockSurfaceKHR_t)ptr); - ptr = dlsym(libEGL,"eglUnlockSurfaceKHR"); disp->set_eglUnlockSurfaceKHR((eglUnlockSurfaceKHR_t)ptr); - ptr = dlsym(libEGL,"eglCreateImageKHR"); disp->set_eglCreateImageKHR((eglCreateImageKHR_t)ptr); - ptr = dlsym(libEGL,"eglDestroyImageKHR"); disp->set_eglDestroyImageKHR((eglDestroyImageKHR_t)ptr); - ptr = dlsym(libEGL,"eglCreateSyncKHR"); disp->set_eglCreateSyncKHR((eglCreateSyncKHR_t)ptr); - ptr = dlsym(libEGL,"eglDestroySyncKHR"); disp->set_eglDestroySyncKHR((eglDestroySyncKHR_t)ptr); - ptr = dlsym(libEGL,"eglClientWaitSyncKHR"); disp->set_eglClientWaitSyncKHR((eglClientWaitSyncKHR_t)ptr); - ptr = dlsym(libEGL,"eglSignalSyncKHR"); disp->set_eglSignalSyncKHR((eglSignalSyncKHR_t)ptr); - ptr = dlsym(libEGL,"eglGetSyncAttribKHR"); disp->set_eglGetSyncAttribKHR((eglGetSyncAttribKHR_t)ptr); - ptr = dlsym(libEGL,"eglSetSwapRectangleANDROID"); disp->set_eglSetSwapRectangleANDROID((eglSetSwapRectangleANDROID_t)ptr); - - return disp; -} diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h b/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h deleted file mode 100644 index e5f67c9..0000000 --- a/emulator/opengl/tests/EGL_host_wrapper/egl_dispatch.h +++ /dev/null @@ -1,115 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _EGL_DISPATCH_H -#define _EGL_DISPATCH_H - -#include "egl_proc.h" - -struct egl_dispatch { - eglGetError_t eglGetError; - eglGetDisplay_t eglGetDisplay; - eglInitialize_t eglInitialize; - eglTerminate_t eglTerminate; - eglQueryString_t eglQueryString; - eglGetConfigs_t eglGetConfigs; - eglChooseConfig_t eglChooseConfig; - eglGetConfigAttrib_t eglGetConfigAttrib; - eglCreateWindowSurface_t eglCreateWindowSurface; - eglCreatePbufferSurface_t eglCreatePbufferSurface; - eglCreatePixmapSurface_t eglCreatePixmapSurface; - eglDestroySurface_t eglDestroySurface; - eglQuerySurface_t eglQuerySurface; - eglBindAPI_t eglBindAPI; - eglQueryAPI_t eglQueryAPI; - eglWaitClient_t eglWaitClient; - eglReleaseThread_t eglReleaseThread; - eglCreatePbufferFromClientBuffer_t eglCreatePbufferFromClientBuffer; - eglSurfaceAttrib_t eglSurfaceAttrib; - eglBindTexImage_t eglBindTexImage; - eglReleaseTexImage_t eglReleaseTexImage; - eglSwapInterval_t eglSwapInterval; - eglCreateContext_t eglCreateContext; - eglDestroyContext_t eglDestroyContext; - eglMakeCurrent_t eglMakeCurrent; - eglGetCurrentContext_t eglGetCurrentContext; - eglGetCurrentSurface_t eglGetCurrentSurface; - eglGetCurrentDisplay_t eglGetCurrentDisplay; - eglQueryContext_t eglQueryContext; - eglWaitGL_t eglWaitGL; - eglWaitNative_t eglWaitNative; - eglSwapBuffers_t eglSwapBuffers; - eglCopyBuffers_t eglCopyBuffers; - eglGetProcAddress_t eglGetProcAddress; - eglLockSurfaceKHR_t eglLockSurfaceKHR; - eglUnlockSurfaceKHR_t eglUnlockSurfaceKHR; - eglCreateImageKHR_t eglCreateImageKHR; - eglDestroyImageKHR_t eglDestroyImageKHR; - eglCreateSyncKHR_t eglCreateSyncKHR; - eglDestroySyncKHR_t eglDestroySyncKHR; - eglClientWaitSyncKHR_t eglClientWaitSyncKHR; - eglSignalSyncKHR_t eglSignalSyncKHR; - eglGetSyncAttribKHR_t eglGetSyncAttribKHR; - eglSetSwapRectangleANDROID_t eglSetSwapRectangleANDROID; - //Accessors - eglGetError_t set_eglGetError(eglGetError_t f) { eglGetError_t retval = eglGetError; eglGetError = f; return retval;} - eglGetDisplay_t set_eglGetDisplay(eglGetDisplay_t f) { eglGetDisplay_t retval = eglGetDisplay; eglGetDisplay = f; return retval;} - eglInitialize_t set_eglInitialize(eglInitialize_t f) { eglInitialize_t retval = eglInitialize; eglInitialize = f; return retval;} - eglTerminate_t set_eglTerminate(eglTerminate_t f) { eglTerminate_t retval = eglTerminate; eglTerminate = f; return retval;} - eglQueryString_t set_eglQueryString(eglQueryString_t f) { eglQueryString_t retval = eglQueryString; eglQueryString = f; return retval;} - eglGetConfigs_t set_eglGetConfigs(eglGetConfigs_t f) { eglGetConfigs_t retval = eglGetConfigs; eglGetConfigs = f; return retval;} - eglChooseConfig_t set_eglChooseConfig(eglChooseConfig_t f) { eglChooseConfig_t retval = eglChooseConfig; eglChooseConfig = f; return retval;} - eglGetConfigAttrib_t set_eglGetConfigAttrib(eglGetConfigAttrib_t f) { eglGetConfigAttrib_t retval = eglGetConfigAttrib; eglGetConfigAttrib = f; return retval;} - eglCreateWindowSurface_t set_eglCreateWindowSurface(eglCreateWindowSurface_t f) { eglCreateWindowSurface_t retval = eglCreateWindowSurface; eglCreateWindowSurface = f; return retval;} - eglCreatePbufferSurface_t set_eglCreatePbufferSurface(eglCreatePbufferSurface_t f) { eglCreatePbufferSurface_t retval = eglCreatePbufferSurface; eglCreatePbufferSurface = f; return retval;} - eglCreatePixmapSurface_t set_eglCreatePixmapSurface(eglCreatePixmapSurface_t f) { eglCreatePixmapSurface_t retval = eglCreatePixmapSurface; eglCreatePixmapSurface = f; return retval;} - eglDestroySurface_t set_eglDestroySurface(eglDestroySurface_t f) { eglDestroySurface_t retval = eglDestroySurface; eglDestroySurface = f; return retval;} - eglQuerySurface_t set_eglQuerySurface(eglQuerySurface_t f) { eglQuerySurface_t retval = eglQuerySurface; eglQuerySurface = f; return retval;} - eglBindAPI_t set_eglBindAPI(eglBindAPI_t f) { eglBindAPI_t retval = eglBindAPI; eglBindAPI = f; return retval;} - eglQueryAPI_t set_eglQueryAPI(eglQueryAPI_t f) { eglQueryAPI_t retval = eglQueryAPI; eglQueryAPI = f; return retval;} - eglWaitClient_t set_eglWaitClient(eglWaitClient_t f) { eglWaitClient_t retval = eglWaitClient; eglWaitClient = f; return retval;} - eglReleaseThread_t set_eglReleaseThread(eglReleaseThread_t f) { eglReleaseThread_t retval = eglReleaseThread; eglReleaseThread = f; return retval;} - eglCreatePbufferFromClientBuffer_t set_eglCreatePbufferFromClientBuffer(eglCreatePbufferFromClientBuffer_t f) { eglCreatePbufferFromClientBuffer_t retval = eglCreatePbufferFromClientBuffer; eglCreatePbufferFromClientBuffer = f; return retval;} - eglSurfaceAttrib_t set_eglSurfaceAttrib(eglSurfaceAttrib_t f) { eglSurfaceAttrib_t retval = eglSurfaceAttrib; eglSurfaceAttrib = f; return retval;} - eglBindTexImage_t set_eglBindTexImage(eglBindTexImage_t f) { eglBindTexImage_t retval = eglBindTexImage; eglBindTexImage = f; return retval;} - eglReleaseTexImage_t set_eglReleaseTexImage(eglReleaseTexImage_t f) { eglReleaseTexImage_t retval = eglReleaseTexImage; eglReleaseTexImage = f; return retval;} - eglSwapInterval_t set_eglSwapInterval(eglSwapInterval_t f) { eglSwapInterval_t retval = eglSwapInterval; eglSwapInterval = f; return retval;} - eglCreateContext_t set_eglCreateContext(eglCreateContext_t f) { eglCreateContext_t retval = eglCreateContext; eglCreateContext = f; return retval;} - eglDestroyContext_t set_eglDestroyContext(eglDestroyContext_t f) { eglDestroyContext_t retval = eglDestroyContext; eglDestroyContext = f; return retval;} - eglMakeCurrent_t set_eglMakeCurrent(eglMakeCurrent_t f) { eglMakeCurrent_t retval = eglMakeCurrent; eglMakeCurrent = f; return retval;} - eglGetCurrentContext_t set_eglGetCurrentContext(eglGetCurrentContext_t f) { eglGetCurrentContext_t retval = eglGetCurrentContext; eglGetCurrentContext = f; return retval;} - eglGetCurrentSurface_t set_eglGetCurrentSurface(eglGetCurrentSurface_t f) { eglGetCurrentSurface_t retval = eglGetCurrentSurface; eglGetCurrentSurface = f; return retval;} - eglGetCurrentDisplay_t set_eglGetCurrentDisplay(eglGetCurrentDisplay_t f) { eglGetCurrentDisplay_t retval = eglGetCurrentDisplay; eglGetCurrentDisplay = f; return retval;} - eglQueryContext_t set_eglQueryContext(eglQueryContext_t f) { eglQueryContext_t retval = eglQueryContext; eglQueryContext = f; return retval;} - eglWaitGL_t set_eglWaitGL(eglWaitGL_t f) { eglWaitGL_t retval = eglWaitGL; eglWaitGL = f; return retval;} - eglWaitNative_t set_eglWaitNative(eglWaitNative_t f) { eglWaitNative_t retval = eglWaitNative; eglWaitNative = f; return retval;} - eglSwapBuffers_t set_eglSwapBuffers(eglSwapBuffers_t f) { eglSwapBuffers_t retval = eglSwapBuffers; eglSwapBuffers = f; return retval;} - eglCopyBuffers_t set_eglCopyBuffers(eglCopyBuffers_t f) { eglCopyBuffers_t retval = eglCopyBuffers; eglCopyBuffers = f; return retval;} - eglGetProcAddress_t set_eglGetProcAddress(eglGetProcAddress_t f) { eglGetProcAddress_t retval = eglGetProcAddress; eglGetProcAddress = f; return retval;} - eglLockSurfaceKHR_t set_eglLockSurfaceKHR(eglLockSurfaceKHR_t f) { eglLockSurfaceKHR_t retval = eglLockSurfaceKHR; eglLockSurfaceKHR = f; return retval;} - eglUnlockSurfaceKHR_t set_eglUnlockSurfaceKHR(eglUnlockSurfaceKHR_t f) { eglUnlockSurfaceKHR_t retval = eglUnlockSurfaceKHR; eglUnlockSurfaceKHR = f; return retval;} - eglCreateImageKHR_t set_eglCreateImageKHR(eglCreateImageKHR_t f) { eglCreateImageKHR_t retval = eglCreateImageKHR; eglCreateImageKHR = f; return retval;} - eglDestroyImageKHR_t set_eglDestroyImageKHR(eglDestroyImageKHR_t f) { eglDestroyImageKHR_t retval = eglDestroyImageKHR; eglDestroyImageKHR = f; return retval;} - eglCreateSyncKHR_t set_eglCreateSyncKHR(eglCreateSyncKHR_t f) { eglCreateSyncKHR_t retval = eglCreateSyncKHR; eglCreateSyncKHR = f; return retval;} - eglDestroySyncKHR_t set_eglDestroySyncKHR(eglDestroySyncKHR_t f) { eglDestroySyncKHR_t retval = eglDestroySyncKHR; eglDestroySyncKHR = f; return retval;} - eglClientWaitSyncKHR_t set_eglClientWaitSyncKHR(eglClientWaitSyncKHR_t f) { eglClientWaitSyncKHR_t retval = eglClientWaitSyncKHR; eglClientWaitSyncKHR = f; return retval;} - eglSignalSyncKHR_t set_eglSignalSyncKHR(eglSignalSyncKHR_t f) { eglSignalSyncKHR_t retval = eglSignalSyncKHR; eglSignalSyncKHR = f; return retval;} - eglGetSyncAttribKHR_t set_eglGetSyncAttribKHR(eglGetSyncAttribKHR_t f) { eglGetSyncAttribKHR_t retval = eglGetSyncAttribKHR; eglGetSyncAttribKHR = f; return retval;} - eglSetSwapRectangleANDROID_t set_eglSetSwapRectangleANDROID(eglSetSwapRectangleANDROID_t f) { eglSetSwapRectangleANDROID_t retval = eglSetSwapRectangleANDROID; eglSetSwapRectangleANDROID = f; return retval;} -}; - -egl_dispatch *loadEGL(const char *p_eglPath); - -#endif diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h b/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h deleted file mode 100644 index ee40585..0000000 --- a/emulator/opengl/tests/EGL_host_wrapper/egl_ftable.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -static struct _egl_funcs_by_name { - const char *name; - void *proc; -} egl_funcs_by_name[] = { - {"eglGetError", (void *)eglGetError}, - {"eglGetDisplay", (void *)eglGetDisplay}, - {"eglInitialize", (void *)eglInitialize}, - {"eglTerminate", (void *)eglTerminate}, - {"eglQueryString", (void *)eglQueryString}, - {"eglGetConfigs", (void *)eglGetConfigs}, - {"eglChooseConfig", (void *)eglChooseConfig}, - {"eglGetConfigAttrib", (void *)eglGetConfigAttrib}, - {"eglCreateWindowSurface", (void *)eglCreateWindowSurface}, - {"eglCreatePbufferSurface", (void *)eglCreatePbufferSurface}, - {"eglCreatePixmapSurface", (void *)eglCreatePixmapSurface}, - {"eglDestroySurface", (void *)eglDestroySurface}, - {"eglQuerySurface", (void *)eglQuerySurface}, - {"eglBindAPI", (void *)eglBindAPI}, - {"eglQueryAPI", (void *)eglQueryAPI}, - {"eglWaitClient", (void *)eglWaitClient}, - {"eglReleaseThread", (void *)eglReleaseThread}, - {"eglCreatePbufferFromClientBuffer", (void *)eglCreatePbufferFromClientBuffer}, - {"eglSurfaceAttrib", (void *)eglSurfaceAttrib}, - {"eglBindTexImage", (void *)eglBindTexImage}, - {"eglReleaseTexImage", (void *)eglReleaseTexImage}, - {"eglSwapInterval", (void *)eglSwapInterval}, - {"eglCreateContext", (void *)eglCreateContext}, - {"eglDestroyContext", (void *)eglDestroyContext}, - {"eglMakeCurrent", (void *)eglMakeCurrent}, - {"eglGetCurrentContext", (void *)eglGetCurrentContext}, - {"eglGetCurrentSurface", (void *)eglGetCurrentSurface}, - {"eglGetCurrentDisplay", (void *)eglGetCurrentDisplay}, - {"eglQueryContext", (void *)eglQueryContext}, - {"eglWaitGL", (void *)eglWaitGL}, - {"eglWaitNative", (void *)eglWaitNative}, - {"eglSwapBuffers", (void *)eglSwapBuffers}, - {"eglCopyBuffers", (void *)eglCopyBuffers}, - {"eglGetProcAddress", (void *)eglGetProcAddress}, - {"eglLockSurfaceKHR", (void *)eglLockSurfaceKHR}, - {"eglUnlockSurfaceKHR", (void *)eglUnlockSurfaceKHR}, - {"eglCreateImageKHR", (void *)eglCreateImageKHR}, - {"eglDestroyImageKHR", (void *)eglDestroyImageKHR}, - {"eglCreateSyncKHR", (void *)eglCreateSyncKHR}, - {"eglDestroySyncKHR", (void *)eglDestroySyncKHR}, - {"eglClientWaitSyncKHR", (void *)eglClientWaitSyncKHR}, - {"eglSignalSyncKHR", (void *)eglSignalSyncKHR}, - {"eglGetSyncAttribKHR", (void *)eglGetSyncAttribKHR}, - {"eglSetSwapRectangleANDROID", (void *)eglSetSwapRectangleANDROID} -}; - -static int egl_num_funcs = sizeof(egl_funcs_by_name) / sizeof(struct _egl_funcs_by_name); diff --git a/emulator/opengl/tests/EGL_host_wrapper/egl_proc.h b/emulator/opengl/tests/EGL_host_wrapper/egl_proc.h deleted file mode 100644 index 140c030..0000000 --- a/emulator/opengl/tests/EGL_host_wrapper/egl_proc.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _EGL_PROC_H -#define _EGL_PROC_H - -#include <EGL/egl.h> -#define EGL_EGLEXT_PROTOTYPES -#include <EGL/eglext.h> - -typedef EGLint (* eglGetError_t) (); -typedef EGLDisplay (* eglGetDisplay_t) (EGLNativeDisplayType); -typedef EGLBoolean (* eglInitialize_t) (EGLDisplay, EGLint*, EGLint*); -typedef EGLBoolean (* eglTerminate_t) (EGLDisplay); -typedef char* (* eglQueryString_t) (EGLDisplay, EGLint); -typedef EGLBoolean (* eglGetConfigs_t) (EGLDisplay, EGLConfig*, EGLint, EGLint*); -typedef EGLBoolean (* eglChooseConfig_t) (EGLDisplay, const EGLint*, EGLConfig*, EGLint, EGLint*); -typedef EGLBoolean (* eglGetConfigAttrib_t) (EGLDisplay, EGLConfig, EGLint, EGLint*); -typedef EGLSurface (* eglCreateWindowSurface_t) (EGLDisplay, EGLConfig, EGLNativeWindowType, const EGLint*); -typedef EGLSurface (* eglCreatePbufferSurface_t) (EGLDisplay, EGLConfig, const EGLint*); -typedef EGLSurface (* eglCreatePixmapSurface_t) (EGLDisplay, EGLConfig, EGLNativePixmapType, const EGLint*); -typedef EGLBoolean (* eglDestroySurface_t) (EGLDisplay, EGLSurface); -typedef EGLBoolean (* eglQuerySurface_t) (EGLDisplay, EGLSurface, EGLint, EGLint*); -typedef EGLBoolean (* eglBindAPI_t) (EGLenum); -typedef EGLenum (* eglQueryAPI_t) (); -typedef EGLBoolean (* eglWaitClient_t) (); -typedef EGLBoolean (* eglReleaseThread_t) (); -typedef EGLSurface (* eglCreatePbufferFromClientBuffer_t) (EGLDisplay, EGLenum, EGLClientBuffer, EGLConfig, const EGLint*); -typedef EGLBoolean (* eglSurfaceAttrib_t) (EGLDisplay, EGLSurface, EGLint, EGLint); -typedef EGLBoolean (* eglBindTexImage_t) (EGLDisplay, EGLSurface, EGLint); -typedef EGLBoolean (* eglReleaseTexImage_t) (EGLDisplay, EGLSurface, EGLint); -typedef EGLBoolean (* eglSwapInterval_t) (EGLDisplay, EGLint); -typedef EGLContext (* eglCreateContext_t) (EGLDisplay, EGLConfig, EGLContext, const EGLint*); -typedef EGLBoolean (* eglDestroyContext_t) (EGLDisplay, EGLContext); -typedef EGLBoolean (* eglMakeCurrent_t) (EGLDisplay, EGLSurface, EGLSurface, EGLContext); -typedef EGLContext (* eglGetCurrentContext_t) (); -typedef EGLSurface (* eglGetCurrentSurface_t) (EGLint); -typedef EGLDisplay (* eglGetCurrentDisplay_t) (); -typedef EGLBoolean (* eglQueryContext_t) (EGLDisplay, EGLContext, EGLint, EGLint*); -typedef EGLBoolean (* eglWaitGL_t) (); -typedef EGLBoolean (* eglWaitNative_t) (EGLint); -typedef EGLBoolean (* eglSwapBuffers_t) (EGLDisplay, EGLSurface); -typedef EGLBoolean (* eglCopyBuffers_t) (EGLDisplay, EGLSurface, EGLNativePixmapType); -typedef __eglMustCastToProperFunctionPointerType (* eglGetProcAddress_t) (const char*); -typedef EGLBoolean (* eglLockSurfaceKHR_t) (EGLDisplay, EGLSurface, const EGLint*); -typedef EGLBoolean (* eglUnlockSurfaceKHR_t) (EGLDisplay, EGLSurface); -typedef EGLImageKHR (* eglCreateImageKHR_t) (EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*); -typedef EGLBoolean (* eglDestroyImageKHR_t) (EGLDisplay, EGLImageKHR image); -typedef EGLSyncKHR (* eglCreateSyncKHR_t) (EGLDisplay, EGLenum, const EGLint*); -typedef EGLBoolean (* eglDestroySyncKHR_t) (EGLDisplay, EGLSyncKHR sync); -typedef EGLint (* eglClientWaitSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLTimeKHR timeout); -typedef EGLBoolean (* eglSignalSyncKHR_t) (EGLDisplay, EGLSyncKHR, EGLenum); -typedef EGLBoolean (* eglGetSyncAttribKHR_t) (EGLDisplay, EGLSyncKHR, EGLint, EGLint*); -typedef EGLBoolean (* eglSetSwapRectangleANDROID_t) (EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint); - -#endif // of _EGL_PROC_H diff --git a/emulator/opengl/tests/emulator_test_renderer/Android.mk b/emulator/opengl/tests/emulator_test_renderer/Android.mk deleted file mode 100644 index d585513..0000000 --- a/emulator/opengl/tests/emulator_test_renderer/Android.mk +++ /dev/null @@ -1,13 +0,0 @@ -LOCAL_PATH:=$(call my-dir) - -$(call emugl-begin-host-executable,emulator_test_renderer) -$(call emugl-import,libOpenglRender event_injector) - -LOCAL_SRC_FILES := main.cpp - -LOCAL_CFLAGS += $(EMUGL_SDL_CFLAGS) -g -O0 -LOCAL_LDLIBS += $(EMUGL_SDL_LDLIBS) - -LOCAL_STATIC_LIBRARIES += libSDL libSDLmain - -$(call emugl-end-module) diff --git a/emulator/opengl/tests/emulator_test_renderer/main.cpp b/emulator/opengl/tests/emulator_test_renderer/main.cpp deleted file mode 100644 index 06abce7..0000000 --- a/emulator/opengl/tests/emulator_test_renderer/main.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#undef HAVE_MALLOC_H -#include <SDL.h> -#include <SDL_syswm.h> -#include <stdio.h> -#include <string.h> -#include "libOpenglRender/render_api.h" -#include <EventInjector.h> - -static int convert_keysym(int sym); // forward - -#ifdef __linux__ -#include <X11/Xlib.h> -#endif -#ifdef _WIN32 - -#include <winsock2.h> -int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) -#else -int main(int argc, char *argv[]) -#endif -{ - int portNum = 22468; - int winWidth = 320; - int winHeight = 480; - int width, height; - int mouseDown = 0; - const char* env = getenv("ANDROID_WINDOW_SIZE"); - FBNativeWindowType windowId = NULL; - EventInjector* injector; - int consolePort = 5554; - - if (env && sscanf(env, "%dx%d", &width, &height) == 2) { - winWidth = width; - winHeight = height; - } - -#ifdef __linux__ - // some OpenGL implementations may call X functions - // it is safer to synchronize all X calls made by all the - // rendering threads. (although the calls we do are locked - // in the FrameBuffer singleton object). - XInitThreads(); -#endif - - // - // Inialize SDL window - // - if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { - fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); - return -1; - } - - SDL_Surface *surface = SDL_SetVideoMode(winWidth, winHeight, 32, SDL_SWSURFACE); - if (surface == NULL) { - fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); - return -1; - } - - SDL_SysWMinfo wminfo; - memset(&wminfo, 0, sizeof(wminfo)); - SDL_GetWMInfo(&wminfo); -#ifdef _WIN32 - windowId = wminfo.window; - WSADATA wsaData; - int rc = WSAStartup( MAKEWORD(2,2), &wsaData); - if (rc != 0) { - printf( "could not initialize Winsock\n" ); - } -#elif __linux__ - windowId = wminfo.info.x11.window; -#elif __APPLE__ - windowId = wminfo.nsWindowPtr; -#endif - - printf("initializing renderer process\n"); - - // - // initialize OpenGL renderer to render in our window - // - bool inited = initOpenGLRenderer(winWidth, winHeight, portNum); - if (!inited) { - return -1; - } - printf("renderer process started\n"); - - float zRot = 0.0f; - inited = createOpenGLSubwindow(windowId, 0, 0, - winWidth, winHeight, zRot); - if (!inited) { - printf("failed to create OpenGL subwindow\n"); - stopOpenGLRenderer(); - return -1; - } - int subwinWidth = winWidth; - int subwinHeight = winHeight; - - injector = new EventInjector(consolePort); - - // Just wait until the window is closed - SDL_Event ev; - - for (;;) { - injector->wait(1000/15); - injector->poll(); - - while (SDL_PollEvent(&ev)) { - switch (ev.type) { - case SDL_MOUSEBUTTONDOWN: - if (!mouseDown) { - injector->sendMouseDown(ev.button.x, ev.button.y); - mouseDown = 1; - } - break; - case SDL_MOUSEBUTTONUP: - if (mouseDown) { - injector->sendMouseUp(ev.button.x,ev.button.y); - mouseDown = 0; - } - break; - case SDL_MOUSEMOTION: - if (mouseDown) - injector->sendMouseMotion(ev.button.x,ev.button.y); - break; - - case SDL_KEYDOWN: -#ifdef __APPLE__ - /* special code to deal with Command-Q properly */ - if (ev.key.keysym.sym == SDLK_q && - ev.key.keysym.mod & KMOD_META) { - goto EXIT; - } -#endif - injector->sendKeyDown(convert_keysym(ev.key.keysym.sym)); - - if (ev.key.keysym.sym == SDLK_KP_MINUS) { - subwinWidth /= 2; - subwinHeight /= 2; - - bool stat = destroyOpenGLSubwindow(); - printf("destroy subwin returned %d\n", stat); - stat = createOpenGLSubwindow(windowId, - (winWidth - subwinWidth) / 2, - (winHeight - subwinHeight) / 2, - subwinWidth, subwinHeight, - zRot); - printf("create subwin returned %d\n", stat); - } - else if (ev.key.keysym.sym == SDLK_KP_PLUS) { - subwinWidth *= 2; - subwinHeight *= 2; - - bool stat = destroyOpenGLSubwindow(); - printf("destroy subwin returned %d\n", stat); - stat = createOpenGLSubwindow(windowId, - (winWidth - subwinWidth) / 2, - (winHeight - subwinHeight) / 2, - subwinWidth, subwinHeight, - zRot); - printf("create subwin returned %d\n", stat); - } - else if (ev.key.keysym.sym == SDLK_KP_MULTIPLY) { - zRot += 10.0f; - setOpenGLDisplayRotation(zRot); - } - else if (ev.key.keysym.sym == SDLK_KP_ENTER) { - repaintOpenGLDisplay(); - } - break; - case SDL_KEYUP: - injector->sendKeyUp(convert_keysym(ev.key.keysym.sym)); - break; - case SDL_QUIT: - goto EXIT; - } - } - } -EXIT: - // - // stop the renderer - // - printf("stopping the renderer process\n"); - stopOpenGLRenderer(); - - return 0; -} - -static int convert_keysym(int sym) -{ -#define EE(x,y) SDLK_##x, EventInjector::KEY_##y, - static const int keymap[] = { - EE(LEFT,LEFT) - EE(RIGHT,RIGHT) - EE(DOWN,DOWN) - EE(UP,UP) - EE(RETURN,ENTER) - EE(F1,SOFT1) - EE(ESCAPE,BACK) - EE(HOME,HOME) - -1 - }; - int nn; - for (nn = 0; keymap[nn] >= 0; nn += 2) { - if (keymap[nn] == sym) - return keymap[nn+1]; - } - return sym; -} diff --git a/emulator/opengl/tests/event_injector/Android.mk b/emulator/opengl/tests/event_injector/Android.mk deleted file mode 100644 index 26eb476..0000000 --- a/emulator/opengl/tests/event_injector/Android.mk +++ /dev/null @@ -1,13 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -$(call emugl-begin-host-static-library,event_injector) - -LOCAL_SRC_FILES := \ - EventInjector.cpp \ - sockets.c \ - emulator-console.c \ - iolooper-select.c - -$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) - -$(call emugl-end-module) diff --git a/emulator/opengl/tests/event_injector/EventInjector.cpp b/emulator/opengl/tests/event_injector/EventInjector.cpp deleted file mode 100644 index 6dade6e..0000000 --- a/emulator/opengl/tests/event_injector/EventInjector.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "EventInjector.h" -#include "emulator-console.h" - -#define PRIVATE EventInjectorPrivate - -class PRIVATE -{ -public: - IoLooper* mLooper; - EmulatorConsole* mConsole; - - EventInjectorPrivate(int port) { - mLooper = iolooper_new(); - mConsole = emulatorConsole_new(port, mLooper); - } -}; - -EventInjector::EventInjector(int consolePort) -{ - mPrivate = new PRIVATE(consolePort); -} - -EventInjector::~EventInjector() -{ - delete mPrivate; -} - -void EventInjector::wait(int timeout_ms) -{ - iolooper_wait(mPrivate->mLooper, timeout_ms); -} - -void EventInjector::poll(void) -{ - emulatorConsole_poll(mPrivate->mConsole); -} - -void EventInjector::sendMouseDown( int x, int y ) -{ - emulatorConsole_sendMouseDown(mPrivate->mConsole, x, y); -} - -void EventInjector::sendMouseUp( int x, int y ) -{ - emulatorConsole_sendMouseUp(mPrivate->mConsole, x, y); -} - -void EventInjector::sendMouseMotion( int x, int y ) -{ - emulatorConsole_sendMouseMotion(mPrivate->mConsole, x, y); -} - -void EventInjector::sendKeyDown( int keycode ) -{ - emulatorConsole_sendKey(mPrivate->mConsole, keycode, 1); -} - -void EventInjector::sendKeyUp( int keycode ) -{ - emulatorConsole_sendKey(mPrivate->mConsole, keycode, 0); -} diff --git a/emulator/opengl/tests/event_injector/EventInjector.h b/emulator/opengl/tests/event_injector/EventInjector.h deleted file mode 100644 index a8fded7..0000000 --- a/emulator/opengl/tests/event_injector/EventInjector.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -/* Event redirector is used to inject user events from a GL window - * into the emulated program. - */ -#ifndef EVENT_INJECTOR_H -#define EVENT_INJECTOR_H - -class EventInjectorPrivate; - -class EventInjector -{ -public: - EventInjector(int consolePort); - virtual ~EventInjector(); - - void wait( int timeout_ms ); - void poll( void ); - - void sendMouseDown( int x, int y ); - void sendMouseUp( int x, int y ); - void sendMouseMotion( int x, int y ); - void sendKeyDown( int keycode ); - void sendKeyUp( int keycode ); - - /* Keycode values expected by the Linux kernel, and the emulator */ - enum { - KEY_BACK = 158, - KEY_HOME = 102, - KEY_SOFT1 = 229, - KEY_LEFT = 105, - KEY_UP = 103, - KEY_DOWN = 108, - KEY_RIGHT = 106, - KEY_VOLUMEUP = 115, - KEY_VOLUMEDOWN = 114, - KEY_SEND = 231, - KEY_END = 107, - KEY_ENTER = 28, - }; - -private: - EventInjectorPrivate* mPrivate; -}; - -#endif /* EVENT_INJECTOR_H */ diff --git a/emulator/opengl/tests/event_injector/emulator-console.c b/emulator/opengl/tests/event_injector/emulator-console.c deleted file mode 100644 index a8c49b2..0000000 --- a/emulator/opengl/tests/event_injector/emulator-console.c +++ /dev/null @@ -1,345 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "emulator-console.h" -#include "sockets.h" -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#define DEBUG 0 -#if DEBUG >= 1 -# define D(...) printf(__VA_ARGS__), printf("\n") -#else -# define D(...) ((void)0) -#endif -#if DEBUG >= 2 -# define DD(...) printf(__VA_ARGS__), printf("\n") -#else -# define DD(...) ((void)0) -#endif - -#define ANEW0(p) (p) = calloc(sizeof(*(p)), 1) - -enum { - STATE_CONNECTING = 0, - STATE_CONNECTED, - STATE_WAITING, - STATE_ERROR = 2 -}; - -typedef struct Msg { - const char* data; // pointer to data - int size; // size of data - int sent; // already sent (so sent..size remain in buffer). - struct Msg* next; // next message in queue. -} Msg; - -static Msg* -msg_alloc( const char* data, int datalen ) -{ - Msg* msg; - - msg = malloc(sizeof(*msg) + datalen); - msg->data = (const char*)(msg + 1); - msg->size = datalen; - msg->sent = 0; - memcpy((char*)msg->data, data, datalen); - msg->next = NULL; - - return msg; -} - -static void -msg_free( Msg* msg ) -{ - free(msg); -} - -struct EmulatorConsole { - int fd; - IoLooper* looper; - int state; - Msg* out_msg; - SockAddress address; - int64_t waitUntil; -}; - -/* Read as much from the input as possible, ignoring it. - */ -static int -emulatorConsole_eatInput( EmulatorConsole* con ) -{ - for (;;) { - char temp[64]; - int ret = socket_recv(con->fd, temp, sizeof temp); - if (ret < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { - return 0; - } - return -1; - } - if (ret == 0) { - return -1; - } - DD("Console received: '%.*s'", ret, temp); - } -} - -static int -emulatorConsole_sendOutput( EmulatorConsole* con ) -{ - if (con->state != STATE_CONNECTED) { - errno = EINVAL; - return -1; - } - - while (con->out_msg != NULL) { - Msg* msg = con->out_msg; - int ret; - - ret = socket_send(con->fd, - msg->data + msg->sent, - msg->size - msg->sent); - if (ret > 0) { - DD("Console sent: '%.*s'", ret, msg->data + msg->sent); - - msg->sent += ret; - if (msg->sent == msg->size) { - con->out_msg = msg->next; - msg_free(msg); - } - continue; - } - if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) { - return 0; - } - con->state = STATE_ERROR; - D("Console error when sending: %s", strerror(errno)); - return -1; - } - iolooper_del_write(con->looper, con->fd); - return 0; -} - -static void -emulatorConsole_completeConnect(EmulatorConsole* con) -{ - D("Console connected!"); - iolooper_add_read(con->looper, con->fd); - iolooper_del_write(con->looper, con->fd); - con->state = STATE_CONNECTED; - if (con->out_msg != NULL) { - iolooper_add_write(con->looper, con->fd); - emulatorConsole_sendOutput(con); - } -} - -static void -emulatorConsole_retry(EmulatorConsole* con) -{ - /* Not possible yet, wait one second */ - D("Could not connect to emulator, waiting 1 second: %s", errno_str); - con->state = STATE_WAITING; - con->waitUntil = iolooper_now() + 5000; -} - -static void -emulatorConsole_connect(EmulatorConsole* con) -{ - D("Trying to connect!"); - if (con->fd < 0) { - con->fd = socket_create_inet( SOCKET_STREAM ); - if (con->fd < 0) { - D("ERROR: Could not create socket: %s", errno_str); - con->state = STATE_ERROR; - return; - } - socket_set_nonblock(con->fd); - } - con->state = STATE_CONNECTING; - if (socket_connect(con->fd, &con->address) < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) { - iolooper_add_write(con->looper, con->fd); - } else { - emulatorConsole_retry(con); - } - return; - } - - emulatorConsole_completeConnect(con); -} - -static void -emulatorConsole_reset( EmulatorConsole* con ) -{ - D("Resetting console connection"); - while (con->out_msg) { - Msg* msg = con->out_msg; - con->out_msg = msg->next; - msg_free(msg); - } - iolooper_del_read(con->looper, con->fd); - iolooper_del_write(con->looper, con->fd); - socket_close(con->fd); - con->fd = -1; - emulatorConsole_connect(con); -} - -/* Create a new EmulatorConsole object to connect asynchronously to - * a given emulator port. Note that this should always succeeds since - * the connection is asynchronous. - */ -EmulatorConsole* -emulatorConsole_new(int port, IoLooper* looper) -{ - EmulatorConsole* con; - SockAddress addr; - - ANEW0(con); - con->looper = looper; - con->fd = -1; - sock_address_init_inet(&con->address, SOCK_ADDRESS_INET_LOOPBACK, port); - - emulatorConsole_connect(con); - return con; -} - -int -emulatorConsole_poll( EmulatorConsole* con ) -{ - int ret; - - if (con->state == STATE_WAITING) { - if (iolooper_now() >= con->waitUntil) - emulatorConsole_connect(con); - return 0; - } - - if (!iolooper_is_read(con->looper, con->fd) && - !iolooper_is_write(con->looper, con->fd)) - { - return 0; - } - -LOOP: - switch (con->state) { - case STATE_ERROR: - return -1; - - case STATE_CONNECTING: - // read socket error to determine success / error. - if (socket_get_error(con->fd) != 0) { - emulatorConsole_retry(con); - } else { - emulatorConsole_completeConnect(con); - } - return 0; - - case STATE_CONNECTED: - /* ignore input, if any */ - if (iolooper_is_read(con->looper, con->fd)) { - if (emulatorConsole_eatInput(con) < 0) { - goto SET_ERROR; - } - } - /* send outgoing data, if any */ - if (iolooper_is_write(con->looper, con->fd)) { - if (emulatorConsole_sendOutput(con) < 0) { - goto SET_ERROR; - } - } - return 0; - - default: - D("UNSUPPORTED STATE!"); - break; - } - -SET_ERROR: - D("Console ERROR!: %s\n", errno_str); - con->state = STATE_ERROR; - emulatorConsole_reset(con); - return -1; -} - -/* Send a message to the console asynchronously. Any answer will be - * ignored. */ -void -emulatorConsole_send( EmulatorConsole* con, const char* command ) -{ - int cmdlen = strlen(command); - Msg* msg; - Msg** plast; - - if (cmdlen == 0) - return; - - /* Append new message at end of outgoing list */ - msg = msg_alloc(command, cmdlen); - plast = &con->out_msg; - while (*plast) { - plast = &(*plast)->next; - } - *plast = msg; - if (con->out_msg == msg) { - iolooper_add_write(con->looper, con->fd); - } - emulatorConsole_sendOutput(con); -} - - -void -emulatorConsole_sendMouseDown( EmulatorConsole* con, int x, int y ) -{ - char temp[128]; - - D("sendMouseDown(%d,%d)", x, y); - snprintf(temp, sizeof temp, - "event send 3:0:%d 3:1:%d 1:330:1 0:0:0\r\n", - x, y); - emulatorConsole_send(con, temp); -} - -void -emulatorConsole_sendMouseMotion( EmulatorConsole* con, int x, int y ) -{ - /* Same as mouse down */ - emulatorConsole_sendMouseDown(con, x, y); -} - -void -emulatorConsole_sendMouseUp( EmulatorConsole* con, int x, int y ) -{ - char temp[128]; - - D("sendMouseUp(%d,%d)", x, y); - snprintf(temp, sizeof temp, - "event send 3:0:%d 3:1:%d 1:330:0 0:0:0\r\n", - x, y); - emulatorConsole_send(con, temp); -} - -#define EE(x,y) if (keycode == x) return y; - -void -emulatorConsole_sendKey( EmulatorConsole* con, int keycode, int down ) -{ - char temp[128]; - - snprintf(temp, sizeof temp, - "event send EV_KEY:%d:%d 0:0:0\r\n", keycode, down); - emulatorConsole_send(con, temp); -} diff --git a/emulator/opengl/tests/event_injector/emulator-console.h b/emulator/opengl/tests/event_injector/emulator-console.h deleted file mode 100644 index 19e9687..0000000 --- a/emulator/opengl/tests/event_injector/emulator-console.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef ANDROID_EMULATOR_CONSOLE_H -#define ANDROID_EMULATOR_CONSOLE_H - -#include "iolooper.h" -#include "sockets.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct EmulatorConsole EmulatorConsole; - -/* Create a new EmulatorConsole object to connect asynchronously to - * a given emulator port. Note that this always succeeds since the - * connection is asynchronous. - */ -EmulatorConsole* emulatorConsole_new(int port, IoLooper* looper); - -/* Call this after an iolooper_poll() or iolooper_wait() to check - * the status of the console's socket and act upon it. - * - * Returns 0 on success, or -1 on error (which indicates disconnection!) - */ -int emulatorConsole_poll( EmulatorConsole* console ); - -/* Send a message to the console asynchronously. Any answer will be - * ignored. */ -void emulatorConsole_send( EmulatorConsole* console, const char* command ); - -void emulatorConsole_sendMouseDown( EmulatorConsole* con, int x, int y ); -void emulatorConsole_sendMouseMotion( EmulatorConsole* con, int x, int y ); -void emulatorConsole_sendMouseUp( EmulatorConsole* con, int x, int y ); - -void emulatorConsole_sendKey( EmulatorConsole* con, int keycode, int down ); - -#ifdef __cplusplus -} -#endif - -#endif /* ANDROID_EMULATOR_CONSOLE_H */ diff --git a/emulator/opengl/tests/event_injector/iolooper-select.c b/emulator/opengl/tests/event_injector/iolooper-select.c deleted file mode 100644 index c5fc7c2..0000000 --- a/emulator/opengl/tests/event_injector/iolooper-select.c +++ /dev/null @@ -1,274 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include <errno.h> -#include <stdlib.h> -#include "iolooper.h" -#include "sockets.h" - -/* An implementation of iolooper.h based on Unix select() */ -#ifdef _WIN32 -# include <winsock2.h> -# include <time.h> -#else -# include <sys/types.h> -# include <sys/select.h> -# include <sys/time.h> -#endif - -struct IoLooper { - fd_set reads[1]; - fd_set writes[1]; - fd_set reads_result[1]; - fd_set writes_result[1]; - int max_fd; - int max_fd_valid; -}; - -IoLooper* -iolooper_new(void) -{ - IoLooper* iol = malloc(sizeof(*iol)); - iolooper_reset(iol); - return iol; -} - -void -iolooper_free( IoLooper* iol ) -{ - free(iol); -} - -void -iolooper_reset( IoLooper* iol ) -{ - FD_ZERO(iol->reads); - FD_ZERO(iol->writes); - iol->max_fd = -1; - iol->max_fd_valid = 1; -} - -static void -iolooper_add_fd( IoLooper* iol, int fd ) -{ - if (iol->max_fd_valid && fd > iol->max_fd) { - iol->max_fd = fd; - } -} - -static void -iolooper_del_fd( IoLooper* iol, int fd ) -{ - if (iol->max_fd_valid && fd == iol->max_fd) - iol->max_fd_valid = 0; -} - -void -iolooper_modify( IoLooper* iol, int fd, int oldflags, int newflags ) -{ - if (fd < 0) - return; - - int changed = oldflags ^ newflags; - - if ((changed & IOLOOPER_READ) != 0) { - if ((newflags & IOLOOPER_READ) != 0) - iolooper_add_read(iol, fd); - else - iolooper_del_read(iol, fd); - } - if ((changed & IOLOOPER_WRITE) != 0) { - if ((newflags & IOLOOPER_WRITE) != 0) - iolooper_add_write(iol, fd); - else - iolooper_del_write(iol, fd); - } -} - - -static int -iolooper_fd_count( IoLooper* iol ) -{ - int max_fd = iol->max_fd; - int fd; - - if (iol->max_fd_valid) - return max_fd + 1; - - /* recompute max fd */ - for (fd = 0; fd < FD_SETSIZE; fd++) { - if (!FD_ISSET(fd, iol->reads) && !FD_ISSET(fd, iol->writes)) - continue; - - max_fd = fd; - } - iol->max_fd = max_fd; - iol->max_fd_valid = 1; - - return max_fd + 1; -} - -void -iolooper_add_read( IoLooper* iol, int fd ) -{ - if (fd >= 0) { - iolooper_add_fd(iol, fd); - FD_SET(fd, iol->reads); - } -} - -void -iolooper_add_write( IoLooper* iol, int fd ) -{ - if (fd >= 0) { - iolooper_add_fd(iol, fd); - FD_SET(fd, iol->writes); - } -} - -void -iolooper_del_read( IoLooper* iol, int fd ) -{ - if (fd >= 0) { - iolooper_del_fd(iol, fd); - FD_CLR(fd, iol->reads); - } -} - -void -iolooper_del_write( IoLooper* iol, int fd ) -{ - if (fd >= 0) { - iolooper_del_fd(iol, fd); - FD_CLR(fd, iol->writes); - } -} - -int -iolooper_poll( IoLooper* iol ) -{ - int count = iolooper_fd_count(iol); - int ret; - fd_set errs; - - if (count == 0) - return 0; - - FD_ZERO(&errs); - - do { - struct timeval tv; - - tv.tv_sec = tv.tv_usec = 0; - - iol->reads_result[0] = iol->reads[0]; - iol->writes_result[0] = iol->writes[0]; - - ret = select( count, iol->reads_result, iol->writes_result, &errs, &tv); - } while (ret < 0 && errno == EINTR); - - return ret; -} - -int -iolooper_wait( IoLooper* iol, int64_t duration ) -{ - int count = iolooper_fd_count(iol); - int ret; - fd_set errs; - struct timeval tm0, *tm = NULL; - - if (count == 0) - return 0; - - if (duration < 0) - tm = NULL; - else { - tm = &tm0; - tm->tv_sec = duration / 1000; - tm->tv_usec = (duration - 1000*tm->tv_sec) * 1000; - } - - FD_ZERO(&errs); - - do { - iol->reads_result[0] = iol->reads[0]; - iol->writes_result[0] = iol->writes[0]; - - ret = select( count, iol->reads_result, iol->writes_result, &errs, tm); - if (ret == 0) { - // Indicates timeout - errno = ETIMEDOUT; - } - } while (ret < 0 && errno == EINTR); - - return ret; -} - - -int -iolooper_is_read( IoLooper* iol, int fd ) -{ - return FD_ISSET(fd, iol->reads_result); -} - -int -iolooper_is_write( IoLooper* iol, int fd ) -{ - return FD_ISSET(fd, iol->writes_result); -} - -int -iolooper_has_operations( IoLooper* iol ) -{ - return iolooper_fd_count(iol) > 0; -} - -int64_t -iolooper_now(void) -{ -#ifdef _WIN32 - FILETIME now; - int64_t now_100ns; - - GetSystemTimeAsFileTime(&now); - - /* Get the time as hundreds of nanosecond intervals since - 12:00 AM January 1t 1601 UTC. We don't really need - to compute the value relative to the Posix epoch */ - now_100ns = ((int64_t)now.dwHighDateTime << 32) | now.dwLowDateTime; - - /* 100 ns == 0.1 us == 0.0001 ms */ - return now_100ns / 10000LL; - -#else /* !_WIN32 */ - struct timeval time_now; - return gettimeofday(&time_now, NULL) ? -1 : (int64_t)time_now.tv_sec * 1000LL + - time_now.tv_usec / 1000; -#endif /* !_WIN32 */ -} - -int -iolooper_wait_absolute(IoLooper* iol, int64_t deadline) -{ - int64_t timeout = deadline - iolooper_now(); - - /* If the deadline has passed, set the timeout to 0, this allows us - * to poll the file descriptor nonetheless */ - if (timeout < 0) - timeout = 0; - - return iolooper_wait(iol, timeout); -} diff --git a/emulator/opengl/tests/event_injector/iolooper.h b/emulator/opengl/tests/event_injector/iolooper.h deleted file mode 100644 index 4aa3db7..0000000 --- a/emulator/opengl/tests/event_injector/iolooper.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef IOLOOPER_H -#define IOLOOPER_H - -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* An IOLooper is an abstraction for select() */ - -typedef struct IoLooper IoLooper; - -IoLooper* iolooper_new(void); -void iolooper_free( IoLooper* iol ); -void iolooper_reset( IoLooper* iol ); - -void iolooper_add_read( IoLooper* iol, int fd ); -void iolooper_add_write( IoLooper* iol, int fd ); -void iolooper_del_read( IoLooper* iol, int fd ); -void iolooper_del_write( IoLooper* iol, int fd ); - -enum { - IOLOOPER_READ = (1<<0), - IOLOOPER_WRITE = (1<<1), -}; -void iolooper_modify( IoLooper* iol, int fd, int oldflags, int newflags); - -int iolooper_poll( IoLooper* iol ); -/* Wrapper around select() - * Return: - * > 0 in case an I/O has occurred, or < 0 on error, or 0 on timeout with - * errno set to ETIMEDOUT. - */ -int iolooper_wait( IoLooper* iol, int64_t duration ); - -int iolooper_is_read( IoLooper* iol, int fd ); -int iolooper_is_write( IoLooper* iol, int fd ); -/* Returns 1 if this IoLooper has one or more file descriptor to interact with */ -int iolooper_has_operations( IoLooper* iol ); -/* Gets current time in milliseconds. - * Return: - * Number of milliseconds corresponded to the current time on success, or -1 - * on failure. - */ -int64_t iolooper_now(void); -/* Waits for an I/O to occur before specific absolute time. - * This routine should be used (instead of iolooper_wait) in cases when multiple - * sequential I/O should be completed within given time interval. For instance, - * consider the scenario, when "server" does two sequential writes, and "client" - * now has to read data transferred with these two distinct writes. It might be - * wasteful to do two reads, each with the same (large) timeout. Instead, it - * would be better to assign a deadline for both reads before the first read, - * and call iolooper_wait_absoulte with the same deadline value: - * int64_t deadline = iolooper_now() + TIMEOUT; - * if (iolooper_wait_absoulte(iol, deadline)) { - * // Process first buffer. - * (iolooper_wait_absoulte(iol, deadline)) { - * // Process second read - * } - * } - * Param: - * iol IoLooper instance for an I/O. - * deadline Deadline (absoulte time in milliseconds) before which an I/O should - * occur. - * Return: - * Number of I/O descriptors set in iol, if an I/O has occurred, 0 if no I/O - * occurred before the deadline, or -1 on error. - */ -int iolooper_wait_absolute(IoLooper* iol, int64_t deadline); - -#ifdef __cplusplus -} -#endif - -#endif /* IOLOOPER_H */ diff --git a/emulator/opengl/tests/event_injector/sockets.c b/emulator/opengl/tests/event_injector/sockets.c deleted file mode 100644 index 33df32b..0000000 --- a/emulator/opengl/tests/event_injector/sockets.c +++ /dev/null @@ -1,1550 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifdef __linux__ /* Recent versions of glibc only define EAI_NODATA, which is an - extension to the POSIX standard, if _GNU_SOURCE is defined. */ -# define _GNU_SOURCE 1 -#endif - -#include "sockets.h" -#include <fcntl.h> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> -#include <limits.h> - -#define D(...) ((void)0) - -#ifdef _WIN32 -# define xxWIN32_LEAN_AND_MEAN -# define _WIN32_WINNT 0x501 -# include <windows.h> -# include <winsock2.h> -# include <ws2tcpip.h> -#else /* !_WIN32 */ -# include <sys/ioctl.h> -# include <sys/socket.h> -# include <netinet/in.h> -# include <netinet/tcp.h> -# include <netdb.h> -# if HAVE_UNIX_SOCKETS -# include <sys/un.h> -# ifndef UNIX_PATH_MAX -# define UNIX_PATH_MAX (sizeof(((struct sockaddr_un*)0)->sun_path)-1) -# endif -# endif -#endif /* !_WIN32 */ - -#define MIN(x,y) ({ typeof(x) _x = (x); typeof(y) _y = (y); _x <= _y ? _x : _y; }) -#define AFREE(p) free(p) -#define AARRAY_NEW(p,count) (p) = malloc(sizeof(*(p))*(count)) -#define AARRAY_NEW0(p,count) (p) = calloc(sizeof(*(p)),(count)) - -/* QSOCKET_CALL is used to deal with the fact that EINTR happens pretty - * easily in QEMU since we use SIGALRM to implement periodic timers - */ -#ifdef _WIN32 -# define QSOCKET_CALL(_ret,_cmd) \ - do { _ret = (_cmd); } while ( _ret < 0 && WSAGetLastError() == WSAEINTR ) -#else -# define QSOCKET_CALL(_ret,_cmd) \ - do { \ - errno = 0; \ - do { _ret = (_cmd); } while ( _ret < 0 && errno == EINTR ); \ - } while (0); -#endif - -#ifdef _WIN32 - -#include <errno.h> - -static int winsock_error; - -#define WINSOCK_ERRORS_LIST \ - EE(WSA_INVALID_HANDLE,EINVAL,"invalid handle") \ - EE(WSA_NOT_ENOUGH_MEMORY,ENOMEM,"not enough memory") \ - EE(WSA_INVALID_PARAMETER,EINVAL,"invalid parameter") \ - EE(WSAEINTR,EINTR,"interrupted function call") \ - EE(WSAEALREADY,EALREADY,"operation already in progress") \ - EE(WSAEBADF,EBADF,"bad file descriptor") \ - EE(WSAEACCES,EACCES,"permission denied") \ - EE(WSAEFAULT,EFAULT,"bad address") \ - EE(WSAEINVAL,EINVAL,"invalid argument") \ - EE(WSAEMFILE,EMFILE,"too many opened files") \ - EE(WSAEWOULDBLOCK,EWOULDBLOCK,"resource temporarily unavailable") \ - EE(WSAEINPROGRESS,EINPROGRESS,"operation now in progress") \ - EE(WSAEALREADY,EAGAIN,"operation already in progress") \ - EE(WSAENOTSOCK,EBADF,"socket operation not on socket") \ - EE(WSAEDESTADDRREQ,EDESTADDRREQ,"destination address required") \ - EE(WSAEMSGSIZE,EMSGSIZE,"message too long") \ - EE(WSAEPROTOTYPE,EPROTOTYPE,"wrong protocol type for socket") \ - EE(WSAENOPROTOOPT,ENOPROTOOPT,"bad protocol option") \ - EE(WSAEADDRINUSE,EADDRINUSE,"address already in use") \ - EE(WSAEADDRNOTAVAIL,EADDRNOTAVAIL,"cannot assign requested address") \ - EE(WSAENETDOWN,ENETDOWN,"network is down") \ - EE(WSAENETUNREACH,ENETUNREACH,"network unreachable") \ - EE(WSAENETRESET,ENETRESET,"network dropped connection on reset") \ - EE(WSAECONNABORTED,ECONNABORTED,"software caused connection abort") \ - EE(WSAECONNRESET,ECONNRESET,"connection reset by peer") \ - EE(WSAENOBUFS,ENOBUFS,"no buffer space available") \ - EE(WSAEISCONN,EISCONN,"socket is already connected") \ - EE(WSAENOTCONN,ENOTCONN,"socket is not connected") \ - EE(WSAESHUTDOWN,ESHUTDOWN,"cannot send after socket shutdown") \ - EE(WSAETOOMANYREFS,ETOOMANYREFS,"too many references") \ - EE(WSAETIMEDOUT,ETIMEDOUT,"connection timed out") \ - EE(WSAECONNREFUSED,ECONNREFUSED,"connection refused") \ - EE(WSAELOOP,ELOOP,"cannot translate name") \ - EE(WSAENAMETOOLONG,ENAMETOOLONG,"name too long") \ - EE(WSAEHOSTDOWN,EHOSTDOWN,"host is down") \ - EE(WSAEHOSTUNREACH,EHOSTUNREACH,"no route to host") \ - -typedef struct { - int winsock; - int unix; - const char* string; -} WinsockError; - -static const WinsockError _winsock_errors[] = { -#define EE(w,u,s) { w, u, s }, - WINSOCK_ERRORS_LIST -#undef EE - { -1, -1, NULL } -}; - -/* this function reads the latest winsock error code and updates - * errno to a matching value. It also returns the new value of - * errno. - */ -static int -_fix_errno( void ) -{ - const WinsockError* werr = _winsock_errors; - int unix = EINVAL; /* generic error code */ - - winsock_error = WSAGetLastError(); - - for ( ; werr->string != NULL; werr++ ) { - if (werr->winsock == winsock_error) { - unix = werr->unix; - break; - } - } - errno = unix; - return -1; -} - -static int -_set_errno( int code ) -{ - winsock_error = -1; - errno = code; - return -1; -} - -/* this function returns a string describing the latest Winsock error */ -const char* -_errno_str(void) -{ - const WinsockError* werr = _winsock_errors; - const char* result = NULL; - - for ( ; werr->string; werr++ ) { - if (werr->winsock == winsock_error) { - result = werr->string; - break; - } - } - - if (result == NULL) { - result = "Unknown socket error"; - } - return result; -} -#else -static int -_fix_errno( void ) -{ - return -1; -} - -static int -_set_errno( int code ) -{ - errno = code; - return -1; -} -#endif - -/* socket types */ - -static int -socket_family_to_bsd( SocketFamily family ) -{ - switch (family) { - case SOCKET_INET: return AF_INET; - case SOCKET_IN6: return AF_INET6; -#if HAVE_UNIX_SOCKETS - case SOCKET_UNIX: return AF_LOCAL; -#endif - default: return -1; - } -} - -static int -socket_type_to_bsd( SocketType type ) -{ - switch (type) { - case SOCKET_DGRAM: return SOCK_DGRAM; - case SOCKET_STREAM: return SOCK_STREAM; - default: return 0; - } -} - -static SocketType -socket_type_from_bsd( int type ) -{ - switch (type) { - case SOCK_DGRAM: return SOCKET_DGRAM; - case SOCK_STREAM: return SOCKET_STREAM; - default: return (SocketType) SOCKET_UNSPEC; - } -} - -#if 0 -static int -socket_type_check( SocketType type ) -{ - return (type == SOCKET_DGRAM || type == SOCKET_STREAM); -} -#endif - -typedef union { - struct sockaddr sa[1]; - struct sockaddr_in in[1]; -#if HAVE_IN6_SOCKETS - struct sockaddr_in6 in6[1]; -#endif -#if HAVE_UNIX_SOCKETS - struct sockaddr_un un[1]; -#endif -} sockaddr_storage; - -/* socket addresses */ - -void -sock_address_init_inet( SockAddress* a, uint32_t ip, uint16_t port ) -{ - a->family = SOCKET_INET; - a->u.inet.port = port; - a->u.inet.address = ip; -} - -void -sock_address_init_in6 ( SockAddress* a, const uint8_t* ip6[16], uint16_t port ) -{ - a->family = SOCKET_IN6; - a->u.in6.port = port; - memcpy( a->u.in6.address, ip6, sizeof(a->u.in6.address) ); -} - -void -sock_address_init_unix( SockAddress* a, const char* path ) -{ - a->family = SOCKET_UNIX; - a->u._unix.path = strdup(path ? path : ""); - a->u._unix.owner = 1; -} - -void sock_address_done( SockAddress* a ) -{ - if (a->family == SOCKET_UNIX && a->u._unix.owner) { - a->u._unix.owner = 0; - free((char*)a->u._unix.path); - } -} - -static char* -format_char( char* buf, char* end, int c ) -{ - if (buf < end) { - if (buf+1 == end) { - *buf++ = 0; - } else { - *buf++ = (char) c; - *buf = 0; - } - } - return buf; -} - -static char* -format_str( char* buf, char* end, const char* str ) -{ - int len = strlen(str); - int avail = end - buf; - - if (len > avail) - len = avail; - - memcpy( buf, str, len ); - buf += len; - - if (buf == end) - buf[-1] = 0; - else - buf[0] = 0; - - return buf; -} - -static char* -format_unsigned( char* buf, char* end, unsigned val ) -{ - char temp[16]; - int nn; - - for ( nn = 0; val != 0; nn++ ) { - int rem = val % 10; - temp[nn] = '0'+rem; - val /= 10; - } - - if (nn == 0) - temp[nn++] = '0'; - - while (nn > 0) - buf = format_char(buf, end, temp[--nn]); - - return buf; -} - -static char* -format_hex( char* buf, char* end, unsigned val, int ndigits ) -{ - int shift = 4*ndigits; - static const char hex[16] = "0123456789abcdef"; - - while (shift >= 0) { - buf = format_char(buf, end, hex[(val >> shift) & 15]); - shift -= 4; - } - return buf; -} - -static char* -format_ip4( char* buf, char* end, uint32_t ip ) -{ - buf = format_unsigned( buf, end, (unsigned)(ip >> 24) ); - buf = format_char( buf, end, '.'); - buf = format_unsigned( buf, end, (unsigned)((ip >> 16) & 255)); - buf = format_char( buf, end, '.'); - buf = format_unsigned( buf, end, (unsigned)((ip >> 8) & 255)); - buf = format_char( buf, end, '.'); - buf = format_unsigned( buf, end, (unsigned)(ip & 255)); - return buf; -} - -static char* -format_ip6( char* buf, char* end, const uint8_t* ip6 ) -{ - int nn; - for (nn = 0; nn < 8; nn++) { - int val = (ip6[0] << 16) | ip6[1]; - ip6 += 2; - if (nn > 0) - buf = format_char(buf, end, ':'); - if (val == 0) - continue; - buf = format_hex(buf, end, val, 4); - } - return buf; -} - -const char* -sock_address_to_string( const SockAddress* a ) -{ - static char buf0[PATH_MAX]; - char *buf = buf0, *end = buf + sizeof(buf0); - - switch (a->family) { - case SOCKET_INET: - buf = format_ip4( buf, end, a->u.inet.address ); - buf = format_char( buf, end, ':' ); - buf = format_unsigned( buf, end, (unsigned) a->u.inet.port ); - break; - - case SOCKET_IN6: - buf = format_ip6( buf, end, a->u.in6.address ); - buf = format_char( buf, end, ':' ); - buf = format_unsigned( buf, end, (unsigned) a->u.in6.port ); - break; - - case SOCKET_UNIX: - buf = format_str( buf, end, a->u._unix.path ); - break; - - default: - return NULL; - } - - return buf0; -} - -int -sock_address_equal( const SockAddress* a, const SockAddress* b ) -{ - if (a->family != b->family) - return 0; - - switch (a->family) { - case SOCKET_INET: - return (a->u.inet.address == b->u.inet.address && - a->u.inet.port == b->u.inet.port); - - case SOCKET_IN6: - return (!memcmp(a->u.in6.address, b->u.in6.address, 16) && - a->u.in6.port == b->u.in6.port); - - case SOCKET_UNIX: - return (!strcmp(a->u._unix.path, b->u._unix.path)); - - default: - return 0; - } -} - -int -sock_address_get_port( const SockAddress* a ) -{ - switch (a->family) { - case SOCKET_INET: - return a->u.inet.port; - case SOCKET_IN6: - return a->u.in6.port; - default: - return -1; - } -} - -void -sock_address_set_port( SockAddress* a, uint16_t port ) -{ - switch (a->family) { - case SOCKET_INET: - a->u.inet.port = port; - break; - case SOCKET_IN6: - a->u.in6.port = port; - break; - default: - ; - } -} - -const char* -sock_address_get_path( const SockAddress* a ) -{ - if (a->family == SOCKET_UNIX) - return a->u._unix.path; - else - return NULL; -} - -int -sock_address_get_ip( const SockAddress* a ) -{ - if (a->family == SOCKET_INET) - return a->u.inet.address; - - return -1; -} - -#if 0 -char* -bufprint_sock_address( char* p, char* end, const SockAddress* a ) -{ - switch (a->family) { - case SOCKET_INET: - { - uint32_t ip = a->u.inet.address; - - return bufprint( p, end, "%d.%d.%d.%d:%d", - (ip >> 24) & 255, (ip >> 16) & 255, - (ip >> 8) & 255, ip & 255, - a->u.inet.port ); - } - case SOCKET_IN6: - { - int nn = 0; - const char* column = ""; - const uint8_t* tab = a->u.in6.address; - for (nn = 0; nn < 16; nn += 2) { - p = bufprint(p, end, "%s%04x", column, (tab[n] << 8) | tab[n+1]); - column = ":"; - } - return bufprint(p, end, ":%d", a->u.in6.port); - } - case SOCKET_UNIX: - { - return bufprint(p, end, "%s", a->u._unix.path); - } - default: - return p; - } -} -#endif - -static int -sock_address_to_bsd( const SockAddress* a, sockaddr_storage* paddress, socklen_t *psize ) -{ - switch (a->family) { - case SOCKET_INET: - { - struct sockaddr_in* dst = paddress->in; - - *psize = sizeof(*dst); - - memset( paddress, 0, *psize ); - - dst->sin_family = AF_INET; - dst->sin_port = htons(a->u.inet.port); - dst->sin_addr.s_addr = htonl(a->u.inet.address); - } - break; - -#if HAVE_IN6_SOCKETS - case SOCKET_IN6: - { - struct sockaddr_in6* dst = paddress->in6; - - *psize = sizeof(*dst); - - memset( paddress, 0, *psize ); - - dst->sin6_family = AF_INET6; - dst->sin6_port = htons(a->u.in6.port); - memcpy( dst->sin6_addr.s6_addr, a->u.in6.address, 16 ); - } - break; -#endif /* HAVE_IN6_SOCKETS */ - -#if HAVE_UNIX_SOCKETS - case SOCKET_UNIX: - { - int slen = strlen(a->u._unix.path); - struct sockaddr_un* dst = paddress->un; - - if (slen >= (int)UNIX_PATH_MAX) - return -1; - - memset( dst, 0, sizeof(*dst) ); - - dst->sun_family = AF_LOCAL; - memcpy( dst->sun_path, a->u._unix.path, slen ); - dst->sun_path[slen] = 0; - - *psize = (char*)&dst->sun_path[slen+1] - (char*)dst; - } - break; -#endif /* HAVE_UNIX_SOCKETS */ - - default: - return _set_errno(EINVAL); - } - - return 0; -} - -static int -sock_address_from_bsd( SockAddress* a, const void* from, size_t fromlen ) -{ - switch (((struct sockaddr *)from)->sa_family) { - case AF_INET: - { - const struct sockaddr_in* src = from; - - if (fromlen < sizeof(*src)) - return _set_errno(EINVAL); - - a->family = SOCKET_INET; - a->u.inet.port = ntohs(src->sin_port); - a->u.inet.address = ntohl(src->sin_addr.s_addr); - } - break; - -#ifdef HAVE_IN6_SOCKETS - case AF_INET6: - { - const struct sockaddr_in6* src = from; - - if (fromlen < sizeof(*src)) - return _set_errno(EINVAL); - - a->family = SOCKET_IN6; - a->u.in6.port = ntohs(src->sin6_port); - memcpy(a->u.in6.address, src->sin6_addr.s6_addr, 16); - } - break; -#endif - -#ifdef HAVE_UNIX_SOCKETS - case AF_LOCAL: - { - const struct sockaddr_un* src = from; - char* end; - - if (fromlen < sizeof(*src)) - return _set_errno(EINVAL); - - /* check that the path is zero-terminated */ - end = memchr(src->sun_path, 0, UNIX_PATH_MAX); - if (end == NULL) - return _set_errno(EINVAL); - - a->family = SOCKET_UNIX; - a->u._unix.owner = 1; - a->u._unix.path = strdup(src->sun_path); - } - break; -#endif - - default: - return _set_errno(EINVAL); - } - return 0; -} - - -int -sock_address_init_resolve( SockAddress* a, const char* hostname, uint16_t port, int preferIn6 ) -{ - struct addrinfo hints[1]; - struct addrinfo* res; - int ret; - - memset(hints, 0, sizeof(hints)); - hints->ai_family = preferIn6 ? AF_INET6 : AF_UNSPEC; - - ret = getaddrinfo(hostname, NULL, hints, &res); - if (ret != 0) { - int err; - - switch (ret) { - case EAI_AGAIN: /* server is down */ - case EAI_FAIL: /* server is sick */ - err = EHOSTDOWN; - break; - -#ifdef EAI_NODATA - case EAI_NODATA: -#endif - case EAI_NONAME: - err = ENOENT; - break; - - case EAI_MEMORY: - err = ENOMEM; - break; - - default: - err = EINVAL; - } - return _set_errno(err); - } - - /* Parse the returned list of addresses. */ - { - struct addrinfo* res_ipv4 = NULL; - struct addrinfo* res_ipv6 = NULL; - struct addrinfo* r; - - /* If preferIn6 is false, we stop on the first IPv4 address, - * otherwise, we stop on the first IPv6 one - */ - for (r = res; r != NULL; r = r->ai_next) { - if (r->ai_family == AF_INET && res_ipv4 == NULL) { - res_ipv4 = r; - if (!preferIn6) - break; - } - else if (r->ai_family == AF_INET6 && res_ipv6 == NULL) { - res_ipv6 = r; - if (preferIn6) - break; - } - } - - /* Select the best address in 'r', which will be NULL - * if there is no corresponding address. - */ - if (preferIn6) { - r = res_ipv6; - if (r == NULL) - r = res_ipv4; - } else { - r = res_ipv4; - if (r == NULL) - r = res_ipv6; - } - - if (r == NULL) { - ret = _set_errno(ENOENT); - goto Exit; - } - - /* Convert to a SockAddress */ - ret = sock_address_from_bsd( a, r->ai_addr, r->ai_addrlen ); - if (ret < 0) - goto Exit; - } - - /* need to set the port */ - switch (a->family) { - case SOCKET_INET: a->u.inet.port = port; break; - case SOCKET_IN6: a->u.in6.port = port; break; - default: ; - } - -Exit: - freeaddrinfo(res); - return ret; -} - -/* The Winsock headers for mingw lack some definitions */ -#ifndef AI_ADDRCONFIG -# define AI_ADDRCONFIG 0 -#endif - -SockAddress** -sock_address_list_create( const char* hostname, - const char* port, - unsigned flags ) -{ - SockAddress** list = NULL; - SockAddress* addr; - int nn, count, ret; - struct addrinfo ai, *res, *e; - - memset(&ai, 0, sizeof(ai)); - ai.ai_flags |= AI_ADDRCONFIG; - ai.ai_family = PF_UNSPEC; - - if (flags & SOCKET_LIST_FORCE_INET) - ai.ai_family = PF_INET; - else if (flags & SOCKET_LIST_FORCE_IN6) - ai.ai_family = PF_INET6; - - if (flags & SOCKET_LIST_PASSIVE) - ai.ai_flags |= AI_PASSIVE; - else - ai.ai_flags |= AI_CANONNAME; - - if (flags & SOCKET_LIST_DGRAM) - ai.ai_socktype = SOCK_DGRAM; - - while (1) { - struct addrinfo hints = ai; - - ret = getaddrinfo(hostname, port, &hints, &res); - if (ret == 0) - break; - - switch (ret) { -#ifdef EAI_ADDRFAMILY - case EAI_ADDRFAMILY: -#endif - case EAI_NODATA: - _set_errno(ENOENT); - break; - case EAI_FAMILY: - _set_errno(EAFNOSUPPORT); - break; - case EAI_AGAIN: - _set_errno(EAGAIN); - break; -#ifdef EAI_SYSTEM - case EAI_SYSTEM: - if (errno == EINTR) - continue; - break; -#endif - default: - _set_errno(EINVAL); - } - return NULL; - } - - /* allocate result list */ - for (count = 0, e = res; e != NULL; e = e->ai_next) - count += 1; - - AARRAY_NEW(list, count+1); - AARRAY_NEW(addr, count); - - for (nn = 0, e = res; e != NULL; e = e->ai_next) { - - ret = sock_address_from_bsd(addr, e->ai_addr, e->ai_addrlen); - if (ret < 0) - continue; - - list[nn++] = addr++; - } - list[nn] = NULL; - freeaddrinfo(res); - return list; -} - -SockAddress** -sock_address_list_create2(const char* host_and_port, unsigned flags ) -{ - char host_name[512]; - const char* actual_host_name = "localhost"; - // Parse host and port name. - const char* port_name = strchr(host_and_port, ':'); - if (port_name != NULL) { - int to_copy = MIN((int)sizeof(host_name)-1, port_name - host_and_port); - if (to_copy != 0) { - memcpy(host_name, host_and_port, to_copy); - host_name[to_copy] = '\0'; - actual_host_name = host_name; - port_name++; - } else { - return NULL; - } - } else { - port_name = host_and_port; - } - // Make sure that port_name is not empty. - if (port_name[0] == '\0') { - return NULL; - } - return sock_address_list_create(actual_host_name, port_name, flags); -} - -void -sock_address_list_free( SockAddress** list ) -{ - int nn; - SockAddress* addr; - - if (list == NULL) - return; - - addr = list[0]; - for (nn = 0; list[nn] != NULL; nn++) { - sock_address_done(list[nn]); - list[nn] = NULL; - } - AFREE(addr); - AFREE(list); -} - -int -sock_address_get_numeric_info( SockAddress* a, - char* host, - size_t hostlen, - char* serv, - size_t servlen ) -{ - struct sockaddr* saddr; - socklen_t slen; - int ret; - - switch (a->family) { - case SOCKET_INET: - saddr = (struct sockaddr*) &a->u.inet.address; - slen = sizeof(a->u.inet.address); - break; - -#if HAVE_IN6_SOCKET - case SOCKET_IN6: - saddr = (struct sockaddr*) &a->u.in6.address; - slen = sizeof(a->u.in6.address); - break; -#endif - default: - return _set_errno(EINVAL); - } - - ret = getnameinfo( saddr, slen, host, hostlen, serv, servlen, - NI_NUMERICHOST | NI_NUMERICSERV ); - - switch (ret) { - case 0: - break; - case EAI_AGAIN: - ret = EAGAIN; - break; - default: - ret = EINVAL; - } - return ret; -} - -int -socket_create( SocketFamily family, SocketType type ) -{ - int ret; - int sfamily = socket_family_to_bsd(family); - int stype = socket_type_to_bsd(type); - - if (sfamily < 0 || stype < 0) { - return _set_errno(EINVAL); - } - - QSOCKET_CALL(ret, socket(sfamily, stype, 0)); - if (ret < 0) - return _fix_errno(); - - return ret; -} - - -int -socket_create_inet( SocketType type ) -{ - return socket_create( SOCKET_INET, type ); -} - -#if HAVE_IN6_SOCKETS -int -socket_create_in6 ( SocketType type ) -{ - return socket_create( SOCKET_IN6, type ); -} -#endif - -#if HAVE_UNIX_SOCKETS -int -socket_create_unix( SocketType type ) -{ - return socket_create( SOCKET_UNIX, type ); -} -#endif - -int socket_can_read(int fd) -{ -#ifdef _WIN32 - unsigned long opt; - - if (ioctlsocket(fd, FIONREAD, &opt) < 0) - return 0; - - return opt; -#else - int opt; - - if (ioctl(fd, FIONREAD, &opt) < 0) - return 0; - - return opt; -#endif -} - -#define SOCKET_CALL(cmd) \ - int ret; \ - QSOCKET_CALL(ret, (cmd)); \ - if (ret < 0) \ - return _fix_errno(); \ - return ret; \ - -int -socket_send(int fd, const void* buf, int buflen) -{ - SOCKET_CALL(send(fd, buf, buflen, 0)) -} - -int -socket_send_oob( int fd, const void* buf, int buflen ) -{ - SOCKET_CALL(send(fd, buf, buflen, MSG_OOB)); -} - -int -socket_sendto(int fd, const void* buf, int buflen, const SockAddress* to) -{ - sockaddr_storage sa; - socklen_t salen; - - if (sock_address_to_bsd(to, &sa, &salen) < 0) - return -1; - - SOCKET_CALL(sendto(fd, buf, buflen, 0, sa.sa, salen)); -} - -int -socket_recv(int fd, void* buf, int len) -{ - SOCKET_CALL(recv(fd, buf, len, 0)); -} - -int -socket_recvfrom(int fd, void* buf, int len, SockAddress* from) -{ - sockaddr_storage sa; - socklen_t salen = sizeof(sa); - int ret; - - QSOCKET_CALL(ret,recvfrom(fd,buf,len,0,sa.sa,&salen)); - if (ret < 0) - return _fix_errno(); - - if (sock_address_from_bsd(from, &sa, salen) < 0) - return -1; - - return ret; -} - -int -socket_connect( int fd, const SockAddress* address ) -{ - sockaddr_storage addr; - socklen_t addrlen; - - if (sock_address_to_bsd(address, &addr, &addrlen) < 0) - return -1; - - SOCKET_CALL(connect(fd,addr.sa,addrlen)); -} - -int -socket_bind( int fd, const SockAddress* address ) -{ - sockaddr_storage addr; - socklen_t addrlen; - - if (sock_address_to_bsd(address, &addr, &addrlen) < 0) - return -1; - - SOCKET_CALL(bind(fd, addr.sa, addrlen)); -} - -int -socket_get_address( int fd, SockAddress* address ) -{ - sockaddr_storage addr; - socklen_t addrlen = sizeof(addr); - int ret; - - QSOCKET_CALL(ret, getsockname(fd, addr.sa, &addrlen)); - if (ret < 0) - return _fix_errno(); - - return sock_address_from_bsd(address, &addr, addrlen); -} - -int -socket_get_peer_address( int fd, SockAddress* address ) -{ - sockaddr_storage addr; - socklen_t addrlen = sizeof(addr); - int ret; - - QSOCKET_CALL(ret, getpeername(fd, addr.sa, &addrlen)); - if (ret < 0) - return _fix_errno(); - - return sock_address_from_bsd(address, &addr, addrlen); -} - -int -socket_listen( int fd, int backlog ) -{ - SOCKET_CALL(listen(fd, backlog)); -} - -int -socket_accept( int fd, SockAddress* address ) -{ - sockaddr_storage addr; - socklen_t addrlen = sizeof(addr); - int ret; - - QSOCKET_CALL(ret, accept(fd, addr.sa, &addrlen)); - if (ret < 0) - return _fix_errno(); - - if (address) { - if (sock_address_from_bsd(address, &addr, addrlen) < 0) { - socket_close(ret); - return -1; - } - } - return ret; -} - -static int -socket_getoption(int fd, int domain, int option, int defaut) -{ - int ret; - while (1) { -#ifdef _WIN32 - DWORD opt = (DWORD)-1; -#else - int opt = -1; -#endif - socklen_t optlen = sizeof(opt); - ret = getsockopt(fd, domain, option, (char*)&opt, &optlen); - if (ret == 0) - return (int)opt; - if (errno != EINTR) - return defaut; - } -#undef OPT_CAST -} - - -SocketType socket_get_type(int fd) -{ - int so_type = socket_getoption(fd, SOL_SOCKET, SO_TYPE, -1); - return socket_type_from_bsd(so_type); -} - -int socket_set_nonblock(int fd) -{ -#ifdef _WIN32 - unsigned long opt = 1; - return ioctlsocket(fd, FIONBIO, &opt); -#else - int flags = fcntl(fd, F_GETFL); - return fcntl(fd, F_SETFL, flags | O_NONBLOCK); -#endif -} - -int socket_set_blocking(int fd) -{ -#ifdef _WIN32 - unsigned long opt = 0; - return ioctlsocket(fd, FIONBIO, &opt); -#else - int flags = fcntl(fd, F_GETFL); - return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); -#endif -} - -static int -socket_setoption(int fd, int domain, int option, int _flag) -{ -#ifdef _WIN32 - DWORD flag = (DWORD) _flag; -#else - int flag = _flag; -#endif - return setsockopt( fd, domain, option, (const char*)&flag, sizeof(flag) ); -} - -int socket_set_xreuseaddr(int fd) -{ -#ifdef _WIN32 - /* on Windows, SO_REUSEADDR is used to indicate that several programs can - * bind to the same port. this is completely different from the Unix - * semantics. instead of SO_EXCLUSIVEADDR to ensure that explicitely prevent - * this. - */ - return socket_setoption(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, 1); -#else - return socket_setoption(fd, SOL_SOCKET, SO_REUSEADDR, 1); -#endif -} - - -int socket_set_oobinline(int fd) -{ - return socket_setoption(fd, SOL_SOCKET, SO_OOBINLINE, 1); -} - - -int socket_set_nodelay(int fd) -{ - return socket_setoption(fd, IPPROTO_TCP, TCP_NODELAY, 1); -} - -int socket_set_ipv6only(int fd) -{ -/* IPV6_ONLY is only supported since Vista on Windows, - * and the Mingw headers lack its definition anyway. - */ -#if defined(_WIN32) && !defined(IPV6_V6ONLY) - return 0; -#else - return socket_setoption(fd, IPPROTO_IPV6, IPV6_V6ONLY, 1); -#endif -} - - -int socket_get_error(int fd) -{ - return socket_getoption(fd, SOL_SOCKET, SO_ERROR, -1); -} - -#ifdef _WIN32 -#include <stdlib.h> - -static void socket_cleanup(void) -{ - WSACleanup(); -} - -int socket_init(void) -{ - WSADATA Data; - int ret, err; - - ret = WSAStartup(MAKEWORD(2,2), &Data); - if (ret != 0) { - err = WSAGetLastError(); - return -1; - } - atexit(socket_cleanup); - return 0; -} - -#else /* !_WIN32 */ - -int socket_init(void) -{ - return 0; /* nothing to do on Unix */ -} - -#endif /* !_WIN32 */ - -#ifdef _WIN32 - -void -socket_close( int fd ) -{ - int old_errno = errno; - - shutdown( fd, SD_BOTH ); - /* we want to drain the socket before closing it */ - //qemu_set_fd_handler( fd, socket_close_handler, NULL, (void*)fd ); - closesocket(fd); - - errno = old_errno; -} - -#else /* !_WIN32 */ - -#include <unistd.h> - -void -socket_close( int fd ) -{ - int old_errno = errno; - - shutdown( fd, SHUT_RDWR ); - close( fd ); - - errno = old_errno; -} - -#endif /* !_WIN32 */ - - -static int -socket_bind_server( int s, const SockAddress* to, SocketType type ) -{ - socket_set_xreuseaddr(s); - - if (socket_bind(s, to) < 0) { - D("could not bind server socket address %s: %s", - sock_address_to_string(to), errno_str); - goto FAIL; - } - - if (type == SOCKET_STREAM) { - if (socket_listen(s, 4) < 0) { - D("could not listen server socket %s: %s", - sock_address_to_string(to), errno_str); - goto FAIL; - } - } - return s; - -FAIL: - socket_close(s); - return -1; -} - - -static int -socket_connect_client( int s, const SockAddress* to ) -{ - if (socket_connect(s, to) < 0) { - D( "could not connect client socket to %s: %s\n", - sock_address_to_string(to), errno_str ); - socket_close(s); - return -1; - } - - socket_set_nonblock( s ); - return s; -} - - -static int -socket_in_server( int address, int port, SocketType type ) -{ - SockAddress addr; - int s; - - sock_address_init_inet( &addr, address, port ); - s = socket_create_inet( type ); - if (s < 0) - return -1; - - return socket_bind_server( s, &addr, type ); -} - - -static int -socket_in_client( SockAddress* to, SocketType type ) -{ - int s; - - s = socket_create_inet( type ); - if (s < 0) return -1; - - return socket_connect_client( s, to ); -} - - -int -socket_loopback_server( int port, SocketType type ) -{ - return socket_in_server( SOCK_ADDRESS_INET_LOOPBACK, port, type ); -} - -int -socket_loopback_client( int port, SocketType type ) -{ - SockAddress addr; - - sock_address_init_inet( &addr, SOCK_ADDRESS_INET_LOOPBACK, port ); - return socket_in_client( &addr, type ); -} - - -int -socket_network_client( const char* host, int port, SocketType type ) -{ - SockAddress addr; - - if (sock_address_init_resolve( &addr, host, port, 0) < 0) - return -1; - - return socket_in_client( &addr, type ); -} - - -int -socket_anyaddr_server( int port, SocketType type ) -{ - return socket_in_server( SOCK_ADDRESS_INET_ANY, port, type ); -} - -int -socket_accept_any( int server_fd ) -{ - int fd; - - QSOCKET_CALL(fd, accept( server_fd, NULL, 0 )); - if (fd < 0) { - D( "could not accept client connection from fd %d: %s", - server_fd, errno_str ); - return -1; - } - - /* set to non-blocking */ - socket_set_nonblock( fd ); - return fd; -} - - -#if HAVE_UNIX_SOCKETS - -int -socket_unix_server( const char* name, SocketType type ) -{ - SockAddress addr; - int s, ret; - - s = socket_create_unix( type ); - if (s < 0) - return -1; - - sock_address_init_unix( &addr, name ); - - do { - ret = unlink( name ); - } while (ret < 0 && errno == EINTR); - - ret = socket_bind_server( s, &addr, type ); - - sock_address_done( &addr ); - return ret; -} - -int -socket_unix_client( const char* name, SocketType type ) -{ - SockAddress addr; - int s, ret; - - s = socket_create_unix(type); - if (s < 0) - return -1; - - sock_address_init_unix( &addr, name ); - - ret = socket_connect_client( s, &addr ); - - sock_address_done( &addr ); - return ret; -} - -#endif /* HAVE_UNIX_SOCKETS */ - - - -int -socket_pair(int *fd1, int *fd2) -{ -#ifndef _WIN32 - int fds[2]; - int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds); - - if (!ret) { - socket_set_nonblock(fds[0]); - socket_set_nonblock(fds[1]); - *fd1 = fds[0]; - *fd2 = fds[1]; - } - return ret; -#else /* _WIN32 */ - /* on Windows, select() only works with network sockets, which - * means we absolutely cannot use Win32 PIPEs to implement - * socket pairs with the current event loop implementation. - * We're going to do like Cygwin: create a random pair - * of localhost TCP sockets and connect them together - */ - int s0, s1, s2, port; - struct sockaddr_in sockin; - socklen_t len; - - /* first, create the 'server' socket. - * a port number of 0 means 'any port between 1024 and 5000. - * see Winsock bind() documentation for details */ - s0 = socket_loopback_server( 0, SOCK_STREAM ); - if (s0 < 0) - return -1; - - /* now connect a client socket to it, we first need to - * extract the server socket's port number */ - len = sizeof sockin; - if (getsockname(s0, (struct sockaddr*) &sockin, &len) < 0) { - closesocket (s0); - return -1; - } - - port = ntohs(sockin.sin_port); - s2 = socket_loopback_client( port, SOCK_STREAM ); - if (s2 < 0) { - closesocket(s0); - return -1; - } - - /* we need to accept the connection on the server socket - * this will create the second socket for the pair - */ - len = sizeof sockin; - s1 = accept(s0, (struct sockaddr*) &sockin, &len); - if (s1 == INVALID_SOCKET) { - closesocket (s0); - closesocket (s2); - return -1; - } - socket_set_nonblock(s1); - - /* close server socket */ - closesocket(s0); - *fd1 = s1; - *fd2 = s2; - return 0; -#endif /* _WIN32 */ -} - - - -int -socket_mcast_inet_add_membership( int s, uint32_t ip ) -{ - struct ip_mreq imr; - - imr.imr_multiaddr.s_addr = htonl(ip); - imr.imr_interface.s_addr = htonl(INADDR_ANY); - - if ( setsockopt( s, IPPROTO_IP, IP_ADD_MEMBERSHIP, - (const char *)&imr, - sizeof(struct ip_mreq)) < 0 ) - { - return _fix_errno(); - } - return 0; -} - -int -socket_mcast_inet_drop_membership( int s, uint32_t ip ) -{ - struct ip_mreq imr; - - imr.imr_multiaddr.s_addr = htonl(ip); - imr.imr_interface.s_addr = htonl(INADDR_ANY); - - if ( setsockopt( s, IPPROTO_IP, IP_DROP_MEMBERSHIP, - (const char *)&imr, - sizeof(struct ip_mreq)) < 0 ) - { - return _fix_errno(); - } - return 0; -} - -int -socket_mcast_inet_set_loop( int s, int enabled ) -{ - return socket_setoption( s, IPPROTO_IP, IP_MULTICAST_LOOP, !!enabled ); -} - -int -socket_mcast_inet_set_ttl( int s, int ttl ) -{ - return socket_setoption( s, IPPROTO_IP, IP_MULTICAST_TTL, ttl ); -} - - -char* -host_name( void ) -{ - static char buf[256]; /* 255 is the max host name length supported by DNS */ - int ret; - - QSOCKET_CALL(ret, gethostname(buf, sizeof(buf))); - - if (ret < 0) - return "localhost"; - else - return buf; -} diff --git a/emulator/opengl/tests/event_injector/sockets.h b/emulator/opengl/tests/event_injector/sockets.h deleted file mode 100644 index ea48c5f..0000000 --- a/emulator/opengl/tests/event_injector/sockets.h +++ /dev/null @@ -1,432 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -/* headers to use the BSD sockets */ -#ifndef ANDROID_SOCKET_H -#define ANDROID_SOCKET_H - -#include <stddef.h> -#include <stdint.h> -#include <errno.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* we're going to hide the implementation details of sockets behind - * a simple wrapper interface declared here. - * - * all socket operations set the global 'errno' variable on error. - * this is unlike Winsock which instead modifies another internal - * variable accessed through WSAGetLastError() and WSASetLastError() - */ - -/* the wrapper will convert any Winsock error message into an errno - * code for you. There are however a few standard Unix error codes - * that are not defined by the MS C library headers, so we add them - * here. We use the official Winsock error codes, which are documented - * even though we don't want to include the Winsock headers - */ -#ifdef _WIN32 -# ifndef EINTR -# define EINTR 10004 -# endif -# ifndef EAGAIN -# define EAGAIN 10035 -# endif -# ifndef EWOULDBLOCK -# define EWOULDBLOCK EAGAIN -# endif -# ifndef EINPROGRESS -# define EINPROGRESS 10036 -# endif -# ifndef EALREADY -# define EALREADY 10037 -# endif -# ifndef EDESTADDRREQ -# define EDESTADDRREQ 10039 -# endif -# ifndef EMSGSIZE -# define EMSGSIZE 10040 -# endif -# ifndef EPROTOTYPE -# define EPROTOTYPE 10041 -# endif -# ifndef ENOPROTOOPT -# define ENOPROTOOPT 10042 -# endif -# ifndef EAFNOSUPPORT -# define EAFNOSUPPORT 10047 -# endif -# ifndef EADDRINUSE -# define EADDRINUSE 10048 -# endif -# ifndef EADDRNOTAVAIL -# define EADDRNOTAVAIL 10049 -# endif -# ifndef ENETDOWN -# define ENETDOWN 10050 -# endif -# ifndef ENETUNREACH -# define ENETUNREACH 10051 -# endif -# ifndef ENETRESET -# define ENETRESET 10052 -# endif -# ifndef ECONNABORTED -# define ECONNABORTED 10053 -# endif -# ifndef ECONNRESET -# define ECONNRESET 10054 -# endif -# ifndef ENOBUFS -# define ENOBUFS 10055 -# endif -# ifndef EISCONN -# define EISCONN 10056 -# endif -# ifndef ENOTCONN -# define ENOTCONN 10057 -# endif -# ifndef ESHUTDOWN -# define ESHUTDOWN 10058 -# endif -# ifndef ETOOMANYREFS -# define ETOOMANYREFS 10059 -# endif -# ifndef ETIMEDOUT -# define ETIMEDOUT 10060 -# endif -# ifndef ECONNREFUSED -# define ECONNREFUSED 10061 -# endif -# ifndef ELOOP -# define ELOOP 10062 -# endif -# ifndef EHOSTDOWN -# define EHOSTDOWN 10064 -# endif -# ifndef EHOSTUNREACH -# define EHOSTUNREACH 10065 -# endif -#endif /* _WIN32 */ - -/* Define 'errno_str' as a handy macro to return the string - * corresponding to a given errno code. On Unix, this is - * equivalent to strerror(errno), but on Windows, this will - * take care of Winsock-originated errors as well. - */ -#ifdef _WIN32 - extern const char* _errno_str(void); -# define errno_str _errno_str() -#else -# define errno_str strerror(errno) -#endif - -/* always enable IPv6 sockets for now. - * the QEMU internal router is not capable of - * supporting them, but we plan to replace it - * with something better in the future. - */ -#define HAVE_IN6_SOCKETS 1 - -/* Unix sockets are not available on Win32 */ -#ifndef _WIN32 -# define HAVE_UNIX_SOCKETS 1 -#endif - -/* initialize the socket sub-system. this must be called before - * using any of the declarations below. - */ -int socket_init( void ); - -/* return the name of the current host */ -char* host_name( void ); - -/* supported socket types */ -typedef enum { - SOCKET_DGRAM = 0, - SOCKET_STREAM -} SocketType; - -/* supported socket families */ -typedef enum { - SOCKET_UNSPEC, - SOCKET_INET, - SOCKET_IN6, - SOCKET_UNIX -} SocketFamily; - -/* Generic socket address structure. Note that for Unix - * sockets, the path is stored in a heap-allocated block, - * unless the 'owner' field is cleared. If this is the case, - */ -typedef struct { - SocketFamily family; - union { - struct { - uint16_t port; - uint32_t address; - } inet; - struct { - uint16_t port; - uint8_t address[16]; - } in6; - struct { - int owner; - const char* path; - } _unix; - } u; -} SockAddress; - -#define SOCK_ADDRESS_INET_ANY 0x00000000 -#define SOCK_ADDRESS_INET_LOOPBACK 0x7f000001 - -/* initialize a new IPv4 socket address, the IP address and port are - * in host endianess. - */ -void sock_address_init_inet( SockAddress* a, uint32_t ip, uint16_t port ); - -/* Initialize an IPv6 socket address, the address is in network order - * and the port in host endianess. - */ -#if HAVE_IN6_SOCKETS -void sock_address_init_in6 ( SockAddress* a, const uint8_t* ip6[16], uint16_t port ); -#endif - -/* Intialize a Unix socket address, this will copy the 'path' string into the - * heap. You need to call sock_address_done() to release the copy - */ -#if HAVE_UNIX_SOCKETS -void sock_address_init_unix( SockAddress* a, const char* path ); -#endif - -/* Finalize a socket address, only needed for now for Unix addresses */ -void sock_address_done( SockAddress* a ); - -int sock_address_equal( const SockAddress* a, const SockAddress* b ); - -/* return a static string describing the address */ -const char* sock_address_to_string( const SockAddress* a ); - -static __inline__ -SocketFamily sock_address_get_family( const SockAddress* a ) -{ - return a->family; -} - -/* return the port number of a given socket address, or -1 if it's a Unix one */ -int sock_address_get_port( const SockAddress* a ); - -/* set the port number of a given socket address, don't do anything for Unix ones */ -void sock_address_set_port( SockAddress* a, uint16_t port ); - -/* return the path of a given Unix socket, returns NULL for non-Unix ones */ -const char* sock_address_get_path( const SockAddress* a ); - -/* return the inet address, or -1 if it's not SOCKET_INET */ -int sock_address_get_ip( const SockAddress* a ); - -/* bufprint a socket address into a human-readable string */ -char* bufprint_sock_address( char* p, char* end, const SockAddress* a ); - -/* resolve a hostname or decimal IPv4/IPv6 address into a socket address. - * returns 0 on success, or -1 on failure. Note that the values or errno - * set by this function are the following: - * - * EINVAL : invalid argument - * EHOSTDOWN : could not reach DNS server - * ENOENT : no host with this name, or host doesn't have any IP address - * ENOMEM : not enough memory to perform request - */ -int sock_address_init_resolve( SockAddress* a, - const char* hostname, - uint16_t port, - int preferIn6 ); - -int sock_address_get_numeric_info( SockAddress* a, - char* host, - size_t hostlen, - char* serv, - size_t servlen ); - -/* Support for listing all socket addresses of a given host */ -enum { - SOCKET_LIST_PASSIVE = (1 << 0), - SOCKET_LIST_FORCE_INET = (1 << 1), - SOCKET_LIST_FORCE_IN6 = (1 << 2), - SOCKET_LIST_DGRAM = (1 << 3), -}; - -/* resolve a host and service/port name into a list of SockAddress objects. - * returns a NULL-terminated array of SockAddress pointers on success, - * or NULL in case of failure, with the value of errno set to one of the - * following: - * - * EINVAL : invalid argument - * EHOSTDOWN : could not reach DNS server - * ENOENT : no host with this name, or host doesn't have IP address - * ENOMEM : not enough memory to perform request - * - * other system-level errors can also be set depending on the host sockets - * implementation. - * - * This function loops on EINTR so the caller shouldn't have to check for it. - */ -SockAddress** sock_address_list_create( const char* hostname, - const char* port, - unsigned flags ); - -/* resolve a string containing host and port name into a list of SockAddress - * objects. Parameter host_and_port should be in format [host:]port, where - * 'host' addresses the machine and must be resolvable into an IP address, and - * 'port' is a decimal numeric value for the port. 'host' is optional, and if - * ommited, localhost will be used. - * returns a NULL-terminated array of SockAddress pointers on success, - * or NULL in case of failure, with the value of errno set to one of the - * following: - * - * EINVAL : invalid argument - * EHOSTDOWN : could not reach DNS server - * ENOENT : no host with this name, or host doesn't have IP address - * ENOMEM : not enough memory to perform request - * - * other system-level errors can also be set depending on the host sockets - * implementation. - * - * This function loops on EINTR so the caller shouldn't have to check for it. - */ -SockAddress** sock_address_list_create2(const char* host_and_port, - unsigned flags ); - -void sock_address_list_free( SockAddress** list ); - -/* create a new socket, return the socket number of -1 on failure */ -int socket_create( SocketFamily family, SocketType type ); - -/* create a new socket intended for IPv4 communication. returns the socket number, - * or -1 on failure. - */ -int socket_create_inet( SocketType type ); - -/* create a new socket intended for IPv6 communication. returns the socket number, - * or -1 on failure. - */ -#if HAVE_IN6_SOCKETS -int socket_create_in6 ( SocketType type ); -#endif - -/* create a unix/local domain socket. returns the socket number, - * or -1 on failure. - */ -#if HAVE_UNIX_SOCKETS -int socket_create_unix( SocketType type ); -#endif - -/* return the type of a given socket */ -SocketType socket_get_type(int fd); - -/* set SO_REUSEADDR on Unix, SO_EXCLUSIVEADDR on Windows */ -int socket_set_xreuseaddr(int fd); - -/* set socket in non-blocking mode */ -int socket_set_nonblock(int fd); - -/* set socket in blocking mode */ -int socket_set_blocking(int fd); - -/* disable the TCP Nagle algorithm for lower latency */ -int socket_set_nodelay(int fd); - -/* send OOB data inline for this socket */ -int socket_set_oobinline(int fd); - -/* force listening to IPv6 interfaces only */ -int socket_set_ipv6only(int fd); - -/* retrieve last socket error code */ -int socket_get_error(int fd); - -/* close an opened socket. Note that this is unlike the Unix 'close' because: - * - it will properly shutdown the socket in the background - * - it does not modify errno - */ -void socket_close( int fd ); - -/* the following functions are equivalent to the BSD sockets ones - */ -int socket_recv ( int fd, void* buf, int buflen ); -int socket_recvfrom( int fd, void* buf, int buflen, SockAddress* from ); - -int socket_send ( int fd, const void* buf, int buflen ); -int socket_send_oob( int fd, const void* buf, int buflen ); -int socket_sendto( int fd, const void* buf, int buflen, const SockAddress* to ); - -int socket_connect( int fd, const SockAddress* address ); -int socket_bind( int fd, const SockAddress* address ); -int socket_get_address( int fd, SockAddress* address ); -int socket_get_peer_address( int fd, SockAddress* address ); -int socket_listen( int fd, int backlog ); -int socket_accept( int fd, SockAddress* address ); - -/* returns the number of bytes that can be read from a socket */ -int socket_can_read( int fd ); - -/* this call creates a pair of non-blocking sockets connected - * to each other. this is equivalent to calling the Unix function: - * socketpair(AF_LOCAL,SOCK_STREAM,0,&fds) - * - * on Windows, this will use a pair of TCP loopback sockets instead - * returns 0 on success, -1 on error. - */ -int socket_pair(int *fd1, int *fd2); - -/* create a server socket listening on the host's loopback interface */ -int socket_loopback_server( int port, SocketType type ); - -/* connect to a port on the host's loopback interface */ -int socket_loopback_client( int port, SocketType type ); - -/* create a server socket listening to a Unix domain path */ -#if HAVE_UNIX_SOCKETS -int socket_unix_server( const char* name, SocketType type ); -#endif - -/* create a Unix sockets and connects it to a Unix server */ -#if HAVE_UNIX_SOCKETS -int socket_unix_client( const char* name, SocketType type ); -#endif - -/* create an IPv4 client socket and connect it to a given host */ -int socket_network_client( const char* host, int port, SocketType type ); - -/* create an IPv4 socket and binds it to a given port of the host's interface */ -int socket_anyaddr_server( int port, SocketType type ); - -/* accept a connection from the host's any interface, return the new socket - * descriptor or -1 */ -int socket_accept_any( int server_fd ); - - -int socket_mcast_inet_add_membership( int s, uint32_t ip ); -int socket_mcast_inet_drop_membership( int s, uint32_t ip ); -int socket_mcast_inet_set_loop( int s, int enabled ); -int socket_mcast_inet_set_ttl( int s, int ttl ); - -#ifdef __cplusplus -} -#endif - -#endif /* ANDROID_SOCKET_H */ diff --git a/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk b/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk deleted file mode 100644 index 1f25a33..0000000 --- a/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk +++ /dev/null @@ -1,28 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -$(call emugl-begin-host-executable,triangleCM) -$(call emugl-import,libEGL_translator libGLES_CM_translator) - -ifeq ($(HOST_OS),darwin) - # SDK 10.6+ deprecates __dyld_func_lookup required by dlcompat_init_func - # in SDL_dlcompat.o this module depends. Instruct linker to resolved it at runtime. - OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2) - OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true) - ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true) - LOCAL_LDLIBS += -Wl,-undefined,dynamic_lookup - endif -endif - -LOCAL_SRC_FILES:= \ - triangleCM.cpp - -LOCAL_CFLAGS += $(EMUGL_SDL_CFLAGS) -g -O0 -LOCAL_LDLIBS += $(EMUGL_SDL_LDLIBS) -lstdc++ - -LOCAL_STATIC_LIBRARIES += $(EMUGL_SDL_STATIC_LIBRARIES) - -ifeq ($(HOST_OS),darwin) -$(call emugl-import,libMac_view) -endif - -$(call emugl-end-module) diff --git a/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp b/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp deleted file mode 100644 index 0e86166..0000000 --- a/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp +++ /dev/null @@ -1,460 +0,0 @@ -/* -* Copyright 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> - -//#define GL_API -//#define GL_APIENTRY - -#undef ANDROID -#include <EGL/egl.h> -#include <GLES/gl.h> - -#ifdef __APPLE__ -extern "C" void * createGLView(void *nsWindowPtr, int x, int y, int width, int height); -#endif - -#undef HAVE_MALLOC_H -#include <SDL.h> -#include <SDL_syswm.h> - - -#define WINDOW_WIDTH 500 -#define WINDOW_HEIGHT 500 - -#define TEX_WIDTH 256 -#define TEX_HEIGHT 256 - - -#define F_to_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ - (d) < -32768.65535 ? -32768 * 65536 + 65535 : \ - ((GLfixed) ((d) * 65536))) -#define X_to_F(x) ((float)(x))/65536.0f - -static EGLint const attribute_list[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_NONE -}; - -unsigned char *genTexture(int width, int height, int comp) -{ - unsigned char *img = new unsigned char[width * height * comp]; - unsigned char *ptr = img; - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; - if (j>(width/2)) col/=2; - for (int c = 0; c < comp; c++) { - *ptr = col; ptr++; - } - } - } - return img; -} - -unsigned char *genRedTexture(int width, int height, int comp) -{ - unsigned char *img = new unsigned char[width * height * comp]; - memset(img,0,width*height*comp); - unsigned char *ptr = img; - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; - *ptr = col; - ptr+=comp; - } - } - return img; -} - -//mip 0; -unsigned char *genPalette4_rgb8(int width, int height,int color) -{ - int size = width*height/2 + 16*3/*palette size*/; - unsigned char *img = new unsigned char[size]; - - memset(img,0,size); - img[0] = 255; img[1] = 0; img[2] = 0; // red - img[3] = 0; img[4] = 0; img[5] = 255; //blue - img[7] = 128; img[8] = 0; img[9] = 128; //fucsia - //rest of the palette is empty - - unsigned char *ptr = img+(16*3); - for (int i = 0; i < (height*width/2); i++) { - ptr[i] = (i%2)?0x0|color:0x11|color; - } - return img; -} - -void usage(const char *progname) -{ - fprintf(stderr, "usage: %s [-n <nframes> -i -h]\n", progname); - fprintf(stderr, "\t-h: this message\n"); - fprintf(stderr, "\t-i: immidate mode\n"); - fprintf(stderr, "\t-n nframes: generate nframes\n"); - fprintf(stderr, "\t-e: use index arrays\n"); - fprintf(stderr, "\t-t: use texture\n"); - fprintf(stderr, "\t-f: use fixed points\n"); - fprintf(stderr, "\t-p: use point size OES extention\n"); -} - -#define SWITCH_SOURCE(add)\ - if(useConvertedType){ \ - if(useFixed){ \ - data = (GLvoid*)(fixedVertices+(add)); \ - } else { \ - data = (GLvoid*)(byteVertices +(add)); \ - } \ - } else { \ - data = (GLvoid*)(afVertices+(add)); \ - } \ - -#ifdef _WIN32 -int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) -#else -int main(int argc, char **argv) -#endif -{ - GLuint ui32Vbo = 0; // Vertex buffer object handle - GLuint ui32IndexVbo; - GLuint ui32Texture; - - int nframes = 100; - bool immidateMode = false; - bool useIndices = true; - bool useTexture = false; - bool useCompTexture = false; - bool useConvertedType = true; - bool useFixed = false; - bool usePoints = false; - bool useCopy = false; - bool useSubCopy = false; - - #ifdef _WIN32 - HWND windowId = NULL; - #elif __linux__ - Window windowId = 0; - #elif __APPLE__ - void* windowId = NULL; - #endif - - // // Inialize SDL window - // - if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { - fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); - return -1; - } - - SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE); - if (surface == NULL) { - fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); - return -1; - } - - SDL_SysWMinfo wminfo; - memset(&wminfo, 0, sizeof(wminfo)); - SDL_GetWMInfo(&wminfo); - #ifdef _WIN32 - windowId = wminfo.window; - #elif __linux__ - windowId = wminfo.info.x11.window; - #elif __APPLE__ - windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT); - - #endif - - int major,minor,num_config; - EGLConfig configs[150]; - EGLSurface egl_surface; - EGLContext ctx; - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - eglInitialize(d,&major,&minor); - printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor); - eglChooseConfig(d, attribute_list, configs, 150, &num_config); - printf("config returned %d\n",num_config); - egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL); - printf("before creating context..\n"); - ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,NULL); - printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx); - if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){ - printf("make current failed\n"); - return false; - } - printf("after make current\n"); - - GLenum err = glGetError(); - if(err != GL_NO_ERROR) { - printf("error before drawing ->>> %d \n",err); - } else { - printf("no error before drawing\n"); - } - - if (useTexture) { - - glEnable(GL_TEXTURE_2D); - ui32Texture = 1; - glBindTexture(GL_TEXTURE_2D, ui32Texture); - GLenum err = glGetError(); - - unsigned char *pixels = NULL; - if(useCompTexture) { - pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,3); - glCompressedTexImage2D(GL_TEXTURE_2D,0,GL_PALETTE4_RGB8_OES,TEX_WIDTH,TEX_HEIGHT,0,3*16+TEX_WIDTH*TEX_HEIGHT/2,pixels); - - } else { - pixels = genTexture(TEX_WIDTH, TEX_HEIGHT, 4); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - } - - delete pixels; - - err = glGetError(); - if(err != GL_NO_ERROR) - printf("error %d after image \n",err); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - err = glGetError(); - if(err != GL_NO_ERROR) - printf("error after min filter \n"); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - err = glGetError(); - if(err != GL_NO_ERROR) - printf("error after mag filter \n"); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - err = glGetError(); - if(err != GL_NO_ERROR) - printf("error after env mode \n"); - - if(useCompTexture) { - pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,1); - glCompressedTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_PALETTE4_RGB8_OES,3*16+(TEX_WIDTH*TEX_HEIGHT/128),pixels); - } else { - pixels = genRedTexture(TEX_WIDTH/8, TEX_HEIGHT/8, 4); - glTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_RGBA,GL_UNSIGNED_BYTE,pixels); - } - err = glGetError(); - if(err != GL_NO_ERROR) - printf("error %d after subimage \n",err); - delete pixels; - - } - - glClearColor(0.6f, 0.8f, 1.0f, 1.0f); // clear blue - - float afVertices[] = { -0.4f,-0.4f,0.0f, // Position - 1.0f,0.0f,0.0f,1.0f, // Color - 0.0f, 0.0f, // texture - 12.f, //point size - - 0.4f,-0.4f,0.0f, - 0.0f,1.0f,0.0f,1.0f, - 1.0f, 0.0f, - 47.0f, - - 0.0f,0.4f,0.0f, - 0.0f,0.0f,1.0f,1.0f, - 0.5f, 1.0f, - 14.0f - }; - -#define MAX_T 1 -#define MID_T 0 -#define MIN_T 0 - - GLbyte byteVertices[] = { -1,-1,0, // Position - (GLbyte)255,0,0,(GLbyte)255, // Color - MIN_T, MIN_T, // texture - 12, //point size - - 1,-1,0, - 0,(GLbyte)255,0,(GLbyte)255, - MAX_T,MIN_T, - 47, - - 0,1,0, - 0,0,(GLbyte)255,(GLbyte)255, - MID_T, MAX_T, - 14 - }; - - GLfixed fixedVertices[] = { F_to_X(-0.4f),F_to_X(-0.4f),F_to_X(0.0f), // Position - F_to_X(1.0f),F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f), // Color - F_to_X(0.0f),F_to_X(0.0f), // texture - F_to_X(12.0f),//points size - - F_to_X(0.4f),F_to_X(-0.4f),F_to_X(0.0f), - F_to_X(0.0f),F_to_X(1.0f),F_to_X(0.0f),F_to_X(1.0f), - F_to_X(1.0f),F_to_X( 0.0f), - F_to_X(30.0f), - - F_to_X(0.0f),F_to_X(0.4f),F_to_X(0.0f), - F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f),F_to_X(1.0f), - F_to_X(0.5f), F_to_X(1.0f), - F_to_X(30.0) - }; - - unsigned short indices[] = { 2, 1, 0 }; - - if (!immidateMode) { - glGenBuffers(1, &ui32Vbo); - ui32Vbo = 1; - printf("ui32Vbo = %d\n", ui32Vbo); - - glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo); - void* data = (void*)afVertices; - unsigned int uiSize = 3*(sizeof(float)*10); - if(useConvertedType){ - if(useFixed){ - data = (void*)fixedVertices; - } else { - data = (void*)byteVertices; - uiSize = 3*(sizeof(GLbyte)*10); - } - } - glBufferData(GL_ARRAY_BUFFER, uiSize,data, GL_STATIC_DRAW); - - ui32IndexVbo = 2; - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); - } - - // Draws a triangle for 800 frames - float angle = 0.0; - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - GLvoid* arr = NULL; - GLenum type; - GLenum drawType; - GLenum colorType; - int size_of; - - if(useConvertedType){ - if(useFixed) - { - arr = fixedVertices; - colorType = type = GL_FIXED; - size_of = sizeof(GLfixed); - } else { - arr = byteVertices; - colorType = GL_UNSIGNED_BYTE; - type = GL_BYTE; - size_of = sizeof(GLbyte); - } - }else { - arr = afVertices; - colorType = type = GL_FLOAT; - size_of = sizeof(float); - } - - if(usePoints) - { - drawType = GL_POINTS; - } - else - drawType = GL_TRIANGLES; - - GLvoid* data = NULL; - for (int i = 0; i < 100; i++) { - - glClear(GL_COLOR_BUFFER_BIT); - glPushMatrix(); - glRotatef(angle, 0.0, 0.0, 1.0); - angle += 360.0 / nframes; - // Enable vertex arrays - glEnableClientState(GL_VERTEX_ARRAY); - if (immidateMode) { - glVertexPointer(3,type, size_of * 10, arr); - } else { - glVertexPointer(3,type, size_of * 10, 0); - } - - // Set color data in the same way - glEnableClientState(GL_COLOR_ARRAY); - if (immidateMode) { - SWITCH_SOURCE(3) - glColorPointer(4, colorType, size_of * 10, data); - } else { - glColorPointer(4,colorType,size_of * 10, (GLvoid*) (size_of * 3) ); - } - if (useTexture) { - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - if (immidateMode) { - SWITCH_SOURCE(7) - glTexCoordPointer(2, type, size_of * 10,data); - } else { - glTexCoordPointer(2, type, size_of * 10, (GLvoid*)(size_of * 7)); - } - } - if(usePoints) - { - glEnableClientState(GL_POINT_SIZE_ARRAY_OES); - if (immidateMode) { - SWITCH_SOURCE(9) - glPointSizePointerOES(type,size_of * 10,data); - } else { - glPointSizePointerOES(type,size_of * 10,(GLvoid*)(size_of * 9)); - } - } - - if (useIndices) { - if (immidateMode) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, indices); - } else { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo); - glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, 0); - } - } else { - glDrawArrays(drawType, 0, 3); - } - - GLenum err = glGetError(); - if(err != GL_NO_ERROR) - printf(" error %d has occured while drawing\n",err); - - - glPopMatrix(); - eglSwapBuffers(d,egl_surface); - - if(useTexture && useCopy) - glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,0,256,256,0); - else if(useTexture && useSubCopy) - glCopyTexSubImage2D(GL_TEXTURE_2D,0,100,100,WINDOW_WIDTH/2,WINDOW_HEIGHT/2,50,50); - } - err = glGetError(); - if(err != GL_NO_ERROR) - printf("error ->>> %d \n",err); - eglDestroySurface(d,egl_surface); - eglDestroyContext(d,ctx); - -// Just wait until the window is closed - SDL_Event ev; - while( SDL_WaitEvent(&ev) ) { - if (ev.type == SDL_QUIT) { - break; - } - } - return 0; -} - - diff --git a/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk b/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk deleted file mode 100644 index 10b3b0c..0000000 --- a/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk +++ /dev/null @@ -1,25 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -$(call emugl-begin-host-executable,triangleV2) -$(call emugl-import,libEGL_translator libGLES_V2_translator) - -LOCAL_SRC_FILES:= \ - triangleV2.cpp - -LOCAL_CFLAGS += $(EMUGL_SDL_CFLAGS) -g -O0 -LOCAL_LDLIBS += $(EMUGL_SDL_LDLIBS) -lstdc++ - -LOCAL_STATIC_LIBRARIES += $(EMUGL_SDL_STATIC_LIBRARIES) - -ifeq ($(HOST_OS),darwin) - # SDK 10.6+ deprecates __dyld_func_lookup required by dlcompat_init_func - # in SDL_dlcompat.o this module depends. Instruct linker to resolved it at runtime. - OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2) - OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true) - ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true) - LOCAL_LDLIBS += -Wl,-undefined,dynamic_lookup - endif - $(call emugl-import,libMac_view) -endif - -$(call emugl-end-module) diff --git a/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp b/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp deleted file mode 100644 index 3a8ff0f..0000000 --- a/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp +++ /dev/null @@ -1,443 +0,0 @@ -/* -* Copyright 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> - -//#define GL_API -//#define GL_APIENTRY - -#undef ANDROID -#include <EGL/egl.h> -#include <GLES2/gl2.h> - -#ifdef __APPLE__ -extern "C" void * createGLView(void *nsWindowPtr, int x, int y, int width, int height); -#endif - -#undef HAVE_MALLOC_H -#include <SDL.h> -#include <SDL_syswm.h> - - -#define WINDOW_WIDTH 500 -#define WINDOW_HEIGHT 500 - -#define TEX_WIDTH 256 -#define TEX_HEIGHT 256 - - -#define F_to_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \ - (d) < -32768.65535 ? -32768 * 65536 + 65535 : \ - ((GLfixed) ((d) * 65536))) -#define X_to_F(x) ((float)(x))/65536.0f - -//#define __FIXED__ - -const char *def_vShaderStr = - "attribute vec4 vPosition; \n" - "void main() \n" - "{ \n" - " gl_Position = vPosition; \n" - "} \n"; - -const char *def_fShaderStr = - "precision mediump float; \n" - "void main() \n" - "{ \n" -#ifndef __FIXED__ - " gl_FragColor = vec4(0.2, 0.5, 0.1, 1.0); \n" -#else - " gl_FragColor = vec4(0.4, 0.3, 0.7, 1.0); \n" -#endif - "} \n"; - -static EGLint const attribute_list[] = { - EGL_RED_SIZE, 1, - EGL_GREEN_SIZE, 1, - EGL_BLUE_SIZE, 1, - EGL_NONE -}; - -unsigned char *genTexture(int width, int height, int comp) -{ - unsigned char *img = new unsigned char[width * height * comp]; - unsigned char *ptr = img; - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; - for (int c = 0; c < comp; c++) { - *ptr = col; ptr++; - } - } - } - return img; -} - -unsigned char *genRedTexture(int width, int height, int comp) -{ - unsigned char *img = new unsigned char[width * height * comp]; - memset(img,0,width*height*comp); - unsigned char *ptr = img; - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - unsigned char col = ((i / 8 + j / 8) % 2) * 255 ; - *ptr = col; - ptr+=comp; - } - } - return img; -} - - -void printUsage(const char *progname) -{ - fprintf(stderr, "usage: %s [options]\n", progname); - fprintf(stderr, "\t-vs <filename> - vertex shader to use\n"); - fprintf(stderr, "\t-fs <filename> - fragment shader to use\n"); -} - - - -GLuint LoadShader(GLenum type,const char *shaderSrc) -{ - GLuint shader; - GLint compiled; - // Create the shader object - shader = glCreateShader(type); - if(shader == 0) - return 0; - // Load the shader source - glShaderSource(shader, 1, &shaderSrc, NULL); - // Compile the shader - glCompileShader(shader); - // Check the compile status - glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(!compiled) - { - GLint infoLen = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); - if(infoLen > 1) - { - char* infoLog = (char*)malloc(sizeof(char) * infoLen); - glGetShaderInfoLog(shader, infoLen, NULL, infoLog); - printf("Error compiling shader:\n%s\n", infoLog); - free(infoLog); - } - glDeleteShader(shader); - return 0; - } - return shader; -} - -const char *readShader(const char *fileName) -{ - FILE *fp = fopen(fileName, "rb"); - if (!fp) return NULL; - - int bSize = 1024; - int nBufs = 1; - char *buf = (char *)malloc(bSize); - int n; - int len = 0; - n = fread(&buf[0], 1, bSize, fp); - while( n == bSize ) { - len += n; - nBufs++; - buf = (char *)realloc(buf, bSize * nBufs); - n = fread(&buf[len], 1, bSize, fp); - } - len += n; - - buf[len] = '\0'; - return (const char *)buf; -} - -void dumpUniforms(GLuint program) -{ - GLint numU; - glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &numU); - printf("==== Program %d has %d active uniforms ===\n", program, numU); - char name[512]; - GLsizei len; - GLint size; - GLenum type; - for (int i=0; i<numU; i++) { - glGetActiveUniform(program, i, - 512, &len, &size, &type, name); - printf("\t%s : type=0x%x size=%d\n", name, type, size); - } -} - -/// -// Initialize the shader and program object -// -int Init(const char *vShaderStr, const char *fShaderStr) -{ - GLuint vertexShader; - GLuint fragmentShader; - GLuint programObject; - GLint linked; - // Load the vertex/fragment shaders - vertexShader = LoadShader(GL_VERTEX_SHADER, vShaderStr); - fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fShaderStr); - // Create the program object - programObject = glCreateProgram(); - if(programObject == 0) - return -1; - glAttachShader(programObject, vertexShader); - glAttachShader(programObject, fragmentShader); - // Bind vPosition to attribute 0 - glBindAttribLocation(programObject, 0, "vPosition"); - // Link the program - glLinkProgram(programObject); - // Check the link status - glGetProgramiv(programObject, GL_LINK_STATUS, &linked); - if(!linked) - { - GLint infoLen = 0; - glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen); - if(infoLen > 1) - { - char* infoLog = (char*)malloc(sizeof(char) * infoLen); - glGetProgramInfoLog(programObject, infoLen, NULL, infoLog); - printf("Error linking program:\n%s\n", infoLog); - free(infoLog); - } - glDeleteProgram(programObject); - return -1; - } - - // dump active uniforms - dumpUniforms(programObject); - - // Store the program object -#ifndef __FIXED__ - glClearColor(0.0f, 0.0f, 1.0f, 1.0f); -#else - glClearColor(1.0f, 0.0f, 0.0f, 1.0f); -#endif - return programObject; -} - - -/// -// Draw a triangle using the shader pair created in Init() -// -void Draw(EGLDisplay display,EGLSurface surface,int width,int height,GLuint program) -{ -#ifndef __FIXED__ - GLfloat vVertices[] = {0.0f, 0.5f, 0.0f, - -0.5f, -0.5f, 0.0f, - 0.5f, -0.5f, 0.0f}; -#else - - GLfixed vVertices[] = {F_to_X(0.0f), F_to_X(0.5f),F_to_X(0.0f), - F_to_X(-0.5f),F_to_X(-0.5f), F_to_X(0.0f), - F_to_X(0.5f),F_to_X(-0.5f),F_to_X(0.0f)}; -#endif - - // Set the viewport - glViewport(0, 0,width,height); - // Clear the color buffer - glClear(GL_COLOR_BUFFER_BIT); - // Use the program object - glUseProgram(program); - // Load the vertex data -#ifndef __FIXED__ - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices); -#else - glVertexAttribPointer(0, 3, GL_FIXED, GL_FALSE, 0, vVertices); -#endif - glEnableVertexAttribArray(0); - glDrawArrays(GL_TRIANGLES, 0, 3); - eglSwapBuffers(display,surface); -} - -#ifdef _WIN32 -char **parseCmdLine(char *cmdLine, int *argc) -{ - int argvSize = 10; - char **argv = (char **)malloc(argvSize * sizeof(char *)); - *argc = 0; - int i=0; - bool prevIsSpace = true; - int argStart = 0; - - argv[(*argc)++] = strdup("playdump"); - - while(cmdLine[i] != '\0') { - bool isSpace = (cmdLine[i] == ' ' || cmdLine[i] == '\t'); - if ( !isSpace && prevIsSpace ) { - argStart = i; - } - else if (isSpace && !prevIsSpace) { - cmdLine[i] = '\0'; - if (*argc >= argvSize) { - argvSize *= 2; - argv = (char **)realloc(argv, argvSize * sizeof(char *)); - } - argv[(*argc)++] = &cmdLine[argStart]; - argStart = i+1; - } - - prevIsSpace = isSpace; - i++; - } - - if (i > argStart) { - argv[(*argc)++] = &cmdLine[argStart]; - } - return argv; -} -#endif - -#ifdef _WIN32 -int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) -#else -int main(int argc, char **argv) -#endif -{ -#ifdef _WIN32 - int argc; - char **argv = parseCmdLine(lpCmdLine, &argc); -#endif - const char *vShader = def_vShaderStr; - const char *fShader = def_fShaderStr; - - for (int i=1; i<argc; i++) { - if (!strcmp(argv[i],"-vs")) { - if (++i >= argc) { - printUsage(argv[0]); - return -1; - } - vShader = readShader(argv[i]); - if (!vShader) { - vShader = def_vShaderStr; - printf("Failed to load vshader %s, using defualt\n", argv[i]); - } - else { - printf("Using vshader %s\n", argv[i]); - } - } - else if (!strcmp(argv[i],"-fs")) { - if (++i >= argc) { - printUsage(argv[0]); - return -1; - } - fShader = readShader(argv[i]); - if (!fShader) { - fShader = def_fShaderStr; - printf("Failed to load fshader %s, using defualt\n", argv[i]); - } - else { - printf("Using fshader %s\n", argv[i]); - } - } - else { - printUsage(argv[0]); - return -1; - } - } - - #ifdef _WIN32 - HWND windowId = NULL; - #elif __linux__ - Window windowId = 0; - #elif __APPLE__ - void* windowId = NULL; - #endif - - // // Inialize SDL window - // - if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) { - fprintf(stderr,"SDL init failed: %s\n", SDL_GetError()); - return -1; - } - - SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE); - if (surface == NULL) { - fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError()); - return -1; - } - - SDL_SysWMinfo wminfo; - memset(&wminfo, 0, sizeof(wminfo)); - SDL_GetWMInfo(&wminfo); - #ifdef _WIN32 - windowId = wminfo.window; - #elif __linux__ - windowId = wminfo.info.x11.window; - #elif __APPLE__ - windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT); - #endif - - int major,minor,num_config; - int attrib_list[] ={ - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - EGLConfig configs[150]; - EGLSurface egl_surface; - EGLContext ctx; - EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY); - eglInitialize(d,&major,&minor); - printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor); - eglChooseConfig(d, attribute_list, configs, 150, &num_config); - printf("config returned %d\n",num_config); - egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL); - ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,attrib_list); - printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx); - if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){ - printf("make current failed\n"); - return false; - } - printf("after make current\n"); - - GLenum err = glGetError(); - if(err != GL_NO_ERROR) { - printf("error before drawing ->>> %d \n",err); - } else { - printf("no error before drawing\n"); - } - - int program = Init(vShader, fShader); - if(program < 0){ - printf("failed init shaders\n"); - return false; - } - - Draw(d,egl_surface,WINDOW_WIDTH,WINDOW_HEIGHT,program); - - err = glGetError(); - if(err != GL_NO_ERROR) - printf("error ->>> %d \n",err); - eglDestroySurface(d,egl_surface); - eglDestroyContext(d,ctx); - -// Just wait until the window is closed - SDL_Event ev; - while( SDL_WaitEvent(&ev) ) { - if (ev.type == SDL_QUIT) { - break; - } - } - return 0; -} - - diff --git a/emulator/opengl/tests/translator_tests/MacCommon/Android.mk b/emulator/opengl/tests/translator_tests/MacCommon/Android.mk deleted file mode 100644 index 4c4ae6b..0000000 --- a/emulator/opengl/tests/translator_tests/MacCommon/Android.mk +++ /dev/null @@ -1,13 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -ifeq ($(HOST_OS),darwin) -$(call emugl-begin-host-static-library,libMac_view) - -LIBMACVIEW_FRAMEWORKS := AppKit AudioToolbox AudioUnit -LIBMACVIEW_PREFIX := -Wl,-framework, - -$(call emugl-export,LDLIBS,$(foreach _framework,$(LIBMACVIEW_FRAMEWORKS),$(LIBMACVIEW_PREFIX)$(_framework))) -LOCAL_SRC_FILES := setup_gl.m -LOCAL_CFLAGS += -g -O0 -$(call emugl-end-module) -endif # HOST_OS == darwin diff --git a/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m b/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m deleted file mode 100644 index a300943..0000000 --- a/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Copyright 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <stdio.h> -#include <Cocoa/Cocoa.h> - - void * createGLView(void *nsWindowPtr, int x, int y, int width, int height) -{ - NSRect contentRect = NSMakeRect(x, y, width, height); - NSView *glView = [[NSView alloc] initWithFrame:contentRect]; - if (glView == nil) { - printf("couldn't create opengl view\n"); - return nil; - } - [glView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - NSWindow *win = (NSWindow *)nsWindowPtr; - [[win contentView] addSubview:glView]; - [win makeKeyAndOrderFront:nil]; - return (void *)glView; -} - - diff --git a/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk b/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk deleted file mode 100644 index b94bd44..0000000 --- a/emulator/opengl/tests/ut_rendercontrol_dec/Android.mk +++ /dev/null @@ -1,6 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -$(call emugl-begin-host-shared-library,libut_rendercontrol_dec) -$(call emugl-import, libOpenglCodecCommon) -$(call emugl-gen-decoder,$(LOCAL_PATH),ut_rendercontrol) -$(call emugl-end-module) diff --git a/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.attrib b/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.attrib deleted file mode 100644 index c47a9f9..0000000 --- a/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.attrib +++ /dev/null @@ -1,4 +0,0 @@ -GLOBAL - base_opcode 10000 - encoder_headers <stdint.h> - diff --git a/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.in b/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.in deleted file mode 100644 index 0d5942f..0000000 --- a/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.in +++ /dev/null @@ -1,11 +0,0 @@ -GL_ENTRY(int, createContext, uint32_t pid, uint32_t handle, uint32_t shareCtx, int version) -GL_ENTRY(int, createSurface, uint32_t pid, uint32_t handle) -GL_ENTRY(int, makeCurrentContext, uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctxHandle) -GL_ENTRY(void, swapBuffers, uint32_t pid, uint32_t surface) -GL_ENTRY(int, destroyContext, uint32_t pid, uint32_t handle) -GL_ENTRY(int, destroySurface, uint32_t pid, uint32_t handle) - - - - - diff --git a/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.types b/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.types deleted file mode 100644 index 9d945ab..0000000 --- a/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol.types +++ /dev/null @@ -1,2 +0,0 @@ -uint32_t 32 0x%08x false - diff --git a/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol_types.h b/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol_types.h deleted file mode 100644 index 9b7864d..0000000 --- a/emulator/opengl/tests/ut_rendercontrol_dec/ut_rendercontrol_types.h +++ /dev/null @@ -1,17 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <stdint.h> diff --git a/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk b/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk deleted file mode 100644 index ae234b2..0000000 --- a/emulator/opengl/tests/ut_rendercontrol_enc/Android.mk +++ /dev/null @@ -1,8 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -$(call emugl-begin-shared-library,libut_rendercontrol_enc) -$(call emugl-import,libOpenglCodecCommon) -$(call emugl-gen-encoder,$(LOCAL_PATH),ut_rendercontrol) -$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)) -$(call emugl-end-module) - diff --git a/emulator/opengl/tests/ut_renderer/Android.mk b/emulator/opengl/tests/ut_renderer/Android.mk deleted file mode 100644 index 91608b2..0000000 --- a/emulator/opengl/tests/ut_renderer/Android.mk +++ /dev/null @@ -1,30 +0,0 @@ -LOCAL_PATH:=$(call my-dir) - -ifeq ($(HOST_OS), linux) - -$(call emugl-begin-host-executable,ut_renderer) -$(call emugl-import,libut_rendercontrol_dec libGLESv1_dec libGLESv2_dec libEGL_host_wrapper libOpenglRender) - -LOCAL_SRC_FILES := ut_renderer.cpp \ - RenderingThread.cpp \ - ReadBuffer.cpp \ - Renderer.cpp \ - RendererContext.cpp \ - RendererSurface.cpp \ - X11Windowing.cpp - -# define PVR_WAR to support imgtec PVR opengl-ES implementation -# -# specifically this MACRO enables code that work arounds a bug -# in the implementation where glTextureParameter(...,GL_TEXTURE_RECT,...) -# is called would cause a crash if the texture dimensions have not been -# defined yet. - -LOCAL_CFLAGS += -DPVR_WAR -#LOCAL_CFLAGS += -g -O0 - -LOCAL_LDLIBS += -lpthread -lX11 -lrt - -$(call emugl-end-module) - -endif # HOST_OS == linux diff --git a/emulator/opengl/tests/ut_renderer/NativeWindowing.h b/emulator/opengl/tests/ut_renderer/NativeWindowing.h deleted file mode 100644 index 9468066..0000000 --- a/emulator/opengl/tests/ut_renderer/NativeWindowing.h +++ /dev/null @@ -1,28 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _NATIVE_WINDOWING_H -#define _NATIVE_WINDOWING_H - -#include <EGL/egl.h> - -class NativeWindowing { -public: - virtual NativeDisplayType getNativeDisplay() = 0; - virtual NativeWindowType createNativeWindow(NativeDisplayType dpy, int width, int height) = 0; - virtual int destroyNativeWindow(NativeDisplayType dpy, NativeWindowType win) = 0; -}; - -#endif diff --git a/emulator/opengl/tests/ut_renderer/ReadBuffer.cpp b/emulator/opengl/tests/ut_renderer/ReadBuffer.cpp deleted file mode 100644 index e0073c0..0000000 --- a/emulator/opengl/tests/ut_renderer/ReadBuffer.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "ReadBuffer.h" -#include <string.h> -#include <assert.h> - -ReadBuffer::ReadBuffer(SocketStream *stream, size_t bufsize) -{ - m_size = bufsize; - m_stream = stream; - m_buf = new unsigned char[m_size]; - m_validData = 0; - m_readPtr = m_buf; -} - -ReadBuffer::~ReadBuffer() -{ - delete m_buf; -} - -int ReadBuffer::getData() -{ - if (m_validData > 0) { - memcpy(m_buf, m_readPtr, m_validData); - } - m_readPtr = m_buf; - // get fresh data into the buffer; - int stat = m_stream->recv(m_buf + m_validData, m_size - m_validData); - if (stat > 0) { - m_validData += (size_t) stat; - } - return stat; -} - -void ReadBuffer::consume(size_t amount) -{ - assert(amount <= m_validData); - m_validData -= amount; - m_readPtr += amount; -} diff --git a/emulator/opengl/tests/ut_renderer/ReadBuffer.h b/emulator/opengl/tests/ut_renderer/ReadBuffer.h deleted file mode 100644 index b039b19..0000000 --- a/emulator/opengl/tests/ut_renderer/ReadBuffer.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _READ_BUFFER_H -#define _READ_BUFFER_H - -#include "SocketStream.h" - -class ReadBuffer { -public: - ReadBuffer(SocketStream *stream, size_t bufSize); - ~ReadBuffer(); - int getData(); // get fresh data from the stream - unsigned char *buf() { return m_readPtr; } // return the next read location - size_t validData() { return m_validData; } // return the amount of valid data in readptr - void consume(size_t amount); // notify that 'amount' data has been consumed; -private: - unsigned char *m_buf; - unsigned char *m_readPtr; - size_t m_size; - size_t m_validData; - SocketStream *m_stream; -}; -#endif diff --git a/emulator/opengl/tests/ut_renderer/Renderer.cpp b/emulator/opengl/tests/ut_renderer/Renderer.cpp deleted file mode 100644 index 1102014..0000000 --- a/emulator/opengl/tests/ut_renderer/Renderer.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <assert.h> -#include "RenderingThread.h" -#include "Renderer.h" - -// include operating-system dependent windowing system impelemntation -#ifdef _WIN32 -# error "WINDOWS IS NOT SUPPORTED AT THE MOMENT" -#elif defined __APPLE__ -# error "Apple OS-X IS NOT SUPPORTED" -#elif defined (__unix__) -# include "X11Windowing.h" -#endif - - - - - -Renderer * Renderer::m_instance = NULL; - -Renderer * Renderer::instance() -{ - if (m_instance == NULL) m_instance = new Renderer; - return m_instance; -} - -Renderer::Renderer() -{ - // Unix specific, use your platform specific windowing implementation -#ifdef __unix__ - m_nw = new X11Windowing; -#endif - - m_dpy = eglGetDisplay(m_nw->getNativeDisplay()); - EGLint major, minor; - eglInitialize(m_dpy, &major, &minor); - fprintf(stderr, "egl initialized : %d.%d\n", major, minor); -} - -int Renderer::createSurface(RenderingThread *thread, const ClientHandle & handle) -{ - emugl::Mutex::AutoLock(this->m_mutex); - - assert(m_surfaces.find(handle) == m_surfaces.end()); - if (handle.handle == 0) { - fprintf(stderr, "trying to create surface for EGL_NO_SURFACE !!!\n"); - return -1; - } else { - RendererSurface *surface = RendererSurface::create(m_dpy, RendererSurface::CONFIG_DEPTH, m_nw); - if (surface == NULL) { - printf("failed to create surface !!\n"); - return -1; - } - m_surfaces.insert(SurfaceMap::value_type(handle, surface)); - } - return 0; -} - -int Renderer::destroySurface(RenderingThread *thread, const ClientHandle &handle) -{ - emugl::Mutex::AutoLock(this->m_mutex); - - SurfaceMap::iterator i = m_surfaces.find(handle); - if (i == m_surfaces.end()) { - printf("removing surface that doesn't exists\n"); - return -1; - } - if (i->second->destroy(m_nw)) { - m_surfaces.erase(handle); - } - return 0; -} - -int Renderer::createContext(RenderingThread *thread, const ClientHandle &handle, ClientHandle shareCtx, int version) -{ - emugl::Mutex::AutoLock(this->m_mutex); - - assert(m_ctxs.find(handle) == m_ctxs.end()); - RendererContext *shared = NULL; - if (shareCtx.handle != 0) { - ContextMap::iterator sctx = m_ctxs.find(shareCtx); - if (sctx != m_ctxs.end()) { - shared = sctx->second; - } - } - - RendererContext *ctx = - RendererContext::create(m_dpy, - RendererSurface::getEglConfig(m_dpy, RendererSurface::CONFIG_DEPTH), - shared, version); - if (ctx == NULL) { - fprintf(stderr, "failed to create context\n"); - return -1; - } - m_ctxs.insert(ContextMap::value_type(handle, ctx)); - return 0; -} - -int Renderer::destroyContext(RenderingThread *thread, const ClientHandle &handle) -{ - emugl::Mutex::AutoLock(this->m_mutex); - - ContextMap::iterator i = m_ctxs.find(handle); - if (i == m_ctxs.end()) { - printf("removing context that doesn't exists\n"); - return -1; - } - if (i->second->destroy()) { - m_ctxs.erase(handle); - } - return 0; -} - -int Renderer::makeCurrent(RenderingThread *thread, - const ClientHandle &drawSurface, - const ClientHandle &readSurface, - const ClientHandle & ctx) -{ - emugl::Mutex::AutoLock(this->m_mutex); - - RendererContext *currentContext = thread->currentContext(); - - ContextMap::iterator c = m_ctxs.find(ctx); - EGLContext eglContext; - if (ctx.handle != 0 && c != m_ctxs.end()) { - if (c->second != currentContext) { - // new context is set - if (currentContext != NULL) currentContext->unref(); - c->second->ref(); - eglContext = c->second->eglContext(); - thread->setCurrentContext(c->second); - thread->glDecoder().setContextData(&c->second->decoderContextData()); - thread->gl2Decoder().setContextData(&c->second->decoderContextData()); - } else { - // same context is already set - eglContext = c->second->eglContext(); - } - } else { - eglContext = EGL_NO_CONTEXT; - if (currentContext != NULL) currentContext->unref(); - thread->setCurrentContext(NULL); - thread->glDecoder().setContextData(NULL); - thread->gl2Decoder().setContextData(NULL); - } - - EGLSurface draw = EGL_NO_SURFACE; - EGLSurface read = EGL_NO_SURFACE; - SurfaceMap::iterator i; - i = m_surfaces.find(drawSurface); if (i != m_surfaces.end()) draw = i->second->eglSurface(); - i = m_surfaces.find(readSurface); if (i != m_surfaces.end()) read = i->second->eglSurface(); - - return eglMakeCurrent(m_dpy, draw, read, eglContext); -} - -int Renderer::swapBuffers(RenderingThread *thread, - const ClientHandle &surface) -{ - emugl::Mutex::AutoLock(this->m_mutex); - - SurfaceMap::iterator s = m_surfaces.find(surface); - if (s == m_surfaces.end()) { - fprintf(stderr, "swapping buffers for non existing surface\n"); - return -1; - } - return eglSwapBuffers(m_dpy, s->second->eglSurface()); -} diff --git a/emulator/opengl/tests/ut_renderer/Renderer.h b/emulator/opengl/tests/ut_renderer/Renderer.h deleted file mode 100644 index 81f4077..0000000 --- a/emulator/opengl/tests/ut_renderer/Renderer.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _RENDERER_H_ -#define _RENDERER_H_ -#include <map> -#include "RendererSurface.h" -#include "RendererContext.h" -#include "NativeWindowing.h" -#include "emugl/common/mutex.h" - -class RenderingThread; - -class Renderer { -public: - - class ClientHandle { - public: - unsigned int pid; - unsigned int handle; - ClientHandle(unsigned int _pid, unsigned int _handle) : pid(_pid), handle(_handle) {} - - bool operator< (const ClientHandle & p) const { - bool val = (pid == p.pid) ? handle < p.handle : pid < p.pid; - return val; - } - }; - - static Renderer *instance(); - int createSurface(RenderingThread *thread, const ClientHandle & handle); - int destroySurface(RenderingThread *thread, const ClientHandle &handle); - int createContext(RenderingThread *thread, const ClientHandle & ctx, const ClientHandle shareCtx, int version); - int destroyContext(RenderingThread *thread,const ClientHandle & ctx); - int makeCurrent(RenderingThread *thread, - const ClientHandle & drawSurface, const ClientHandle & readSurface, const ClientHandle & ctx); - int swapBuffers(RenderingThread *thread, const ClientHandle & surface); - -private: - typedef std::map<ClientHandle, RendererSurface *> SurfaceMap; - typedef std::map<ClientHandle, RendererContext *> ContextMap; - static Renderer *m_instance; - Renderer(); - SurfaceMap m_surfaces; - ContextMap m_ctxs; - NativeWindowing *m_nw; - EGLDisplay m_dpy; - - emugl::Mutex m_mutex; // single global mutex for the renderer class; -}; -#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererContext.cpp b/emulator/opengl/tests/ut_renderer/RendererContext.cpp deleted file mode 100644 index 0f93acd..0000000 --- a/emulator/opengl/tests/ut_renderer/RendererContext.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "RendererContext.h" -#include <stdio.h> -#include <stdlib.h> - -RendererContext * RendererContext::create(EGLDisplay dpy, EGLConfig config, RendererContext *shareCtx, int version) -{ - EGLContext ctx; - EGLContext shared = shareCtx == NULL ? EGL_NO_CONTEXT : shareCtx->eglContext(); - - EGLint context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE }; - context_attributes[1] = version; - - ctx = eglCreateContext(dpy, config, shared, context_attributes); - if (eglGetError() != EGL_SUCCESS) return NULL; - - return new RendererContext(dpy, ctx, version); -} - -int RendererContext::destroy() -{ - if (count() <= 0) { - eglDestroyContext(m_dpy, m_ctx); - return 1; - } - return 0; -} - -#ifdef PVR_WAR -void RendererContext::setActiveTexture(GLenum texture) -{ - m_activeTexture = texture - GL_TEXTURE0; -} - -void RendererContext::setTex2DBind(GLuint texture) -{ - m_tex2DBind[m_activeTexture] = texture; -} - -GLuint RendererContext::getTex2DBind() -{ - return m_tex2DBind[m_activeTexture]; -} - -void RendererContext::addPendingCropRect(const int *rect) -{ - PendingCropRect *r = new PendingCropRect; - r->texture = m_tex2DBind[m_activeTexture]; - memcpy(r->rect, rect, 4*sizeof(int)); - m_pendingCropRects.insert(r); -} -#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererContext.h b/emulator/opengl/tests/ut_renderer/RendererContext.h deleted file mode 100644 index bb24a2e..0000000 --- a/emulator/opengl/tests/ut_renderer/RendererContext.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _RENDERER_CONTEXT_H_ -#define _RENDERER_CONTEXT_H_ - -#include "RendererObject.h" -#include "GLDecoderContextData.h" - -#include <EGL/egl.h> -#define GL_API -#define GL_APIENTRY -#include <GLES/gl.h> -#include <string.h> - -#ifdef PVR_WAR -#include <set> -struct PendingCropRect -{ - GLuint texture; - int rect[4]; -}; - -typedef std::set<PendingCropRect *> PendingCropRectSet; -#endif - -class RendererContext : public RendererObject { -public: - static RendererContext *create(EGLDisplay dpy, EGLConfig config, RendererContext *shareCtx, int version); - EGLContext eglContext() { return m_ctx; } - int destroy(); - GLDecoderContextData & decoderContextData() { return m_contextData; } -#ifdef PVR_WAR - void setActiveTexture(GLenum texture); - GLenum getActiveTexture() { return GL_TEXTURE0 + m_activeTexture; } - void setTex2DBind(GLuint texture); - void setTex2DEnable(bool enable) { - m_tex2DEnable[m_activeTexture] = enable; - } - bool isTex2DEnable(int texunit) { return m_tex2DEnable[texunit]; } - GLuint getTex2DBind(); - void addPendingCropRect(const int *rect); - PendingCropRectSet &getPendingCropRects() { return m_pendingCropRects; } - - void setClientActiveTexture(GLenum texture) { m_clientActiveTexture = texture - GL_TEXTURE0; } - GLenum getClientActiveTexture() { return m_clientActiveTexture + GL_TEXTURE0; } - void enableClientState(GLenum cap, bool enable) { - switch(cap) { - case GL_VERTEX_ARRAY: - m_clientStateEnable[0] = enable; - break; - case GL_NORMAL_ARRAY: - m_clientStateEnable[1] = enable; - break; - case GL_COLOR_ARRAY: - m_clientStateEnable[2] = enable; - break; - case GL_POINT_SIZE_ARRAY_OES: - m_clientStateEnable[3] = enable; - break; - case GL_TEXTURE_COORD_ARRAY: - m_clientStateEnable[4 + m_clientActiveTexture] = enable; - break; - } - } - - bool getClientState(GLenum cap, int texUnit) { - switch(cap) { - case GL_VERTEX_ARRAY: - return m_clientStateEnable[0]; - case GL_NORMAL_ARRAY: - return m_clientStateEnable[1]; - case GL_COLOR_ARRAY: - return m_clientStateEnable[2]; - case GL_POINT_SIZE_ARRAY_OES: - return m_clientStateEnable[3]; - break; - case GL_TEXTURE_COORD_ARRAY: - return m_clientStateEnable[4 + texUnit]; - break; - } - return false; - } -#endif - -private: - EGLDisplay m_dpy; - EGLContext m_ctx; - GLDecoderContextData m_contextData; - int m_version; - - RendererContext(EGLDisplay dpy, EGLContext ctx, int version) : - m_dpy(dpy), - m_ctx(ctx), - m_version(version) - { -#ifdef PVR_WAR - m_activeTexture = 0; - m_clientActiveTexture = 0; - memset(m_tex2DBind, 0, 8*sizeof(GLuint)); - memset(m_tex2DEnable, 0, 8*sizeof(bool)); - memset(m_clientStateEnable, 0, 16*sizeof(bool)); -#endif - } - -#ifdef PVR_WAR - int m_tex2DBind[8]; - bool m_tex2DEnable[8]; - int m_activeTexture; - int m_clientActiveTexture; - bool m_clientStateEnable[16]; - PendingCropRectSet m_pendingCropRects; -#endif -}; -#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererObject.h b/emulator/opengl/tests/ut_renderer/RendererObject.h deleted file mode 100644 index 18c89be..0000000 --- a/emulator/opengl/tests/ut_renderer/RendererObject.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _RENDERER_OBJECT_H_ -#define _RENDERER_OBJECT_H_ - -class RendererObject { -public: - RendererObject() { m_count = 0; } - - int count() { return m_count; } - void ref() { m_count++; } - void unref() { m_count--; } -private: - int m_count; -}; -#endif diff --git a/emulator/opengl/tests/ut_renderer/RendererSurface.cpp b/emulator/opengl/tests/ut_renderer/RendererSurface.cpp deleted file mode 100644 index 7d8d8c6..0000000 --- a/emulator/opengl/tests/ut_renderer/RendererSurface.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "RendererSurface.h" -#include <stdio.h> -#include <stdlib.h> - -#include "NativeWindowing.h" - -#define MAX_ATTRIB 100 - - -EGLConfig RendererSurface::getEglConfig(EGLDisplay eglDisplay, SurfaceConfig config) -{ - EGLConfig eglConfig; - int nConfigs; - - EGLint attrib[MAX_ATTRIB]; - int pos =0; - - attrib[pos++] = EGL_SURFACE_TYPE; attrib[pos++] = EGL_WINDOW_BIT; - if (config & CONFIG_DEPTH) {attrib[pos++] = EGL_DEPTH_SIZE; attrib[pos++] = 1;} - attrib[pos++] = EGL_NONE; - - if (!eglChooseConfig(eglDisplay, attrib, &eglConfig, 1, &nConfigs)) { - return 0; - } - /***/ - int ibuf; - if (eglGetConfigAttrib(eglDisplay, eglConfig, EGL_BUFFER_SIZE, &ibuf)) { - fprintf(stderr, "EGL COLOR Buffer size: %d\n", ibuf); - } else { - fprintf(stderr, "eglGetConfigAttrib error: %d\n", eglGetError()); - } - if (eglGetConfigAttrib(eglDisplay, eglConfig, EGL_DEPTH_SIZE, &ibuf)) { - fprintf(stderr, "EGL DEPTH Buffer size: %d\n", ibuf); - } else { - fprintf(stderr, "eglGetConfigAttrib error: %d\n", eglGetError()); - } - /***/ - - - if (nConfigs != 1) { - return 0; - } - return eglConfig; -} - -RendererSurface * RendererSurface::create(EGLDisplay eglDisplay, SurfaceConfig config, NativeWindowing *nw) -{ - int width = 0, height = 0; - const char* env; - - env = getenv("ANDROID_WINDOW_WIDTH"); - if (env && *env) { - width = atoi(env); - } - env = getenv("ANDROID_WINDOW_HEIGHT"); - if (env && *env) { - height = atoi(env); - } - if (width <= 160) - width = DEFAULT_WIDTH; - if (height <= 160) - height = DEFAULT_HEIGHT; - - printf("%s: Using width=%d height=%d\n", __FUNCTION__, width, height); - - EGLConfig eglConfig = getEglConfig(eglDisplay, config); - if (eglConfig == 0) { - return NULL; - } - - NativeWindowType window = nw->createNativeWindow(nw->getNativeDisplay(), width, height); - if (window == 0) { - return NULL; - } - - EGLSurface eglSurface = eglCreateWindowSurface(eglDisplay, - eglConfig, - window, NULL); - - if (eglGetError() != EGL_SUCCESS) { - return NULL; - } - - return new RendererSurface(eglDisplay, window, eglSurface, eglConfig); -} - -int RendererSurface::destroy(NativeWindowing *nw) -{ - eglDestroySurface(m_eglDisplay, m_eglSurface); - nw->destroyNativeWindow(nw->getNativeDisplay(), m_window); - return 1; -} - diff --git a/emulator/opengl/tests/ut_renderer/RendererSurface.h b/emulator/opengl/tests/ut_renderer/RendererSurface.h deleted file mode 100644 index 4f6709c..0000000 --- a/emulator/opengl/tests/ut_renderer/RendererSurface.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _RENDERER_SURFACE_H_ -#define _RENDERER_SURFACE_H_ - -#include <EGL/egl.h> -#include "NativeWindowing.h" -#include "RendererObject.h" - -#define DEFAULT_HEIGHT 480 -#define DEFAULT_WIDTH 320 - -class RendererSurface : public RendererObject { -public: - typedef enum { CONFIG_DEPTH = 1 << 0 } SurfaceConfig; - - EGLSurface eglSurface() { return m_eglSurface; } - EGLConfig eglConfig() { return m_config; } - EGLDisplay eglDisplay() { return m_eglDisplay; } - - static RendererSurface * create(EGLDisplay eglDisplay, SurfaceConfig config, NativeWindowing *nw); - static EGLConfig getEglConfig(EGLDisplay eglDisplay, SurfaceConfig config); - - int destroy(NativeWindowing *nw); - -private: - RendererSurface(EGLDisplay display, NativeWindowType window, EGLSurface surface, EGLConfig config) : - m_eglDisplay(display), - m_config(config), - m_window(window), - m_eglSurface(surface) - {} - - EGLDisplay m_eglDisplay; - EGLConfig m_config; - NativeWindowType m_window; - EGLSurface m_eglSurface; -}; -#endif diff --git a/emulator/opengl/tests/ut_renderer/RenderingThread.cpp b/emulator/opengl/tests/ut_renderer/RenderingThread.cpp deleted file mode 100644 index 70eee20..0000000 --- a/emulator/opengl/tests/ut_renderer/RenderingThread.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "RenderingThread.h" -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <pthread.h> -#include "ReadBuffer.h" -#include "Renderer.h" -#include "TimeUtils.h" - -#include <GLES/glext.h> - -__thread RenderingThread * RenderingThread::m_tls; - -#ifdef PVR_WAR -void RenderingThread::s_glTexParameteriv(GLenum target, GLenum param, const int *p) -{ - if (target == GL_TEXTURE_2D && param == GL_TEXTURE_CROP_RECT_OES) { - m_tls->m_currentContext->addPendingCropRect(p); - } else { - m_tls->m_glTexParameteriv(target, param, p); - } -} - -void RenderingThread::s_glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h) -{ - m_tls->applyPendingCropRects(); - m_tls->m_glDrawTexfOES(x, y, z, w, h); - m_tls->fixTextureEnable(); -} - -void RenderingThread::s_glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort w, GLshort h) -{ - m_tls->applyPendingCropRects(); - m_tls->m_glDrawTexsOES(x, y, z, w, h); - m_tls->fixTextureEnable(); -} - -void RenderingThread::s_glDrawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h) -{ - m_tls->applyPendingCropRects(); - m_tls->m_glDrawTexiOES(x, y, z, w, h); - m_tls->fixTextureEnable(); -} - -void RenderingThread::s_glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h) -{ - m_tls->applyPendingCropRects(); - m_tls->m_glDrawTexxOES(x, y, z, w, h); - m_tls->fixTextureEnable(); -} - -void RenderingThread::s_glDrawTexfvOES(const GLfloat *coords) -{ - m_tls->applyPendingCropRects(); - m_tls->m_glDrawTexfvOES(coords); - m_tls->fixTextureEnable(); -} - -void RenderingThread::s_glDrawTexsvOES(const GLshort *coords) -{ - m_tls->applyPendingCropRects(); - m_tls->m_glDrawTexsvOES(coords); - m_tls->fixTextureEnable(); -} - -void RenderingThread::s_glDrawTexivOES(const GLint *coords) -{ - m_tls->applyPendingCropRects(); - m_tls->m_glDrawTexivOES(coords); - m_tls->fixTextureEnable(); -} - -void RenderingThread::s_glDrawTexxvOES(const GLfixed *coords) -{ - m_tls->applyPendingCropRects(); - m_tls->m_glDrawTexxvOES(coords); - m_tls->fixTextureEnable(); -} - - -void RenderingThread::s_glActiveTexture(GLenum texture) -{ - if (texture - GL_TEXTURE0 >= m_tls->m_backendCaps.maxTextureUnits) return; - - m_tls->m_currentContext->setActiveTexture(texture); - m_tls->m_glActiveTexture(texture); -} - -void RenderingThread::s_glBindTexture(GLenum target, GLuint texture) -{ - if (target == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DBind(texture); - m_tls->m_glBindTexture(target, texture); -} - -void RenderingThread::s_glEnable(GLenum cap) -{ - if (cap == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DEnable(true); - m_tls->m_glEnable(cap); -} - -void RenderingThread::s_glDisable(GLenum cap) -{ - if (cap == GL_TEXTURE_2D) m_tls->m_currentContext->setTex2DEnable(false); - m_tls->m_glDisable(cap); -} - -void RenderingThread::s_glClientActiveTexture(GLenum texture) -{ - if (texture - GL_TEXTURE0 >= m_tls->m_backendCaps.maxTextureUnits) return; - m_tls->m_currentContext->setClientActiveTexture(texture); - m_tls->m_glClientActiveTexture(texture); -} - -void RenderingThread::s_glEnableClientState(GLenum cap) -{ - m_tls->m_currentContext->enableClientState(cap, true); - m_tls->m_glEnableClientState(cap); -} - -void RenderingThread::s_glDisableClientState(GLenum cap) -{ - m_tls->m_currentContext->enableClientState(cap, false); - m_tls->m_glDisableClientState(cap); -} - -void RenderingThread::applyPendingCropRects() -{ - PendingCropRectSet &rset = m_currentContext->getPendingCropRects(); - if (rset.size() > 0) { - GLuint currBindedTex = m_currentContext->getTex2DBind(); - for (PendingCropRectSet::iterator i = rset.begin(); - i != rset.end(); - i++) { - m_glBindTexture(GL_TEXTURE_2D, (*i)->texture); - m_glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, (int *)(*i)->rect); - delete (*i); - } - m_glBindTexture(GL_TEXTURE_2D, currBindedTex); - rset.clear(); - } -} - -void RenderingThread::fixTextureEnable() -{ - // restore texture units enable state - for (unsigned int i=0; i<m_backendCaps.maxTextureUnits; i++) { - m_glActiveTexture(GL_TEXTURE0 + i); - if (m_currentContext->isTex2DEnable(i)) { - m_glEnable(GL_TEXTURE_2D); - } - else { - m_glDisable(GL_TEXTURE_2D); - } - m_glClientActiveTexture(GL_TEXTURE0 + i); - if (m_currentContext->getClientState(GL_TEXTURE_COORD_ARRAY, i)) { - m_glEnableClientState(GL_TEXTURE_COORD_ARRAY); - } - else { - m_glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - } - // restore current active texture - m_glActiveTexture(m_currentContext->getActiveTexture()); - m_glClientActiveTexture(m_currentContext->getClientActiveTexture()); - - // restore other client state enable bits - if (m_currentContext->getClientState(GL_VERTEX_ARRAY, 0)) { - m_glEnableClientState(GL_VERTEX_ARRAY); - } - else { - m_glDisableClientState(GL_VERTEX_ARRAY); - } - - if (m_currentContext->getClientState(GL_NORMAL_ARRAY, 0)) { - m_glEnableClientState(GL_NORMAL_ARRAY); - } - else { - m_glDisableClientState(GL_NORMAL_ARRAY); - } - - if (m_currentContext->getClientState(GL_COLOR_ARRAY, 0)) { - m_glEnableClientState(GL_COLOR_ARRAY); - } - else { - m_glDisableClientState(GL_COLOR_ARRAY); - } - - if (m_currentContext->getClientState(GL_POINT_SIZE_ARRAY_OES, 0)) { - m_glEnableClientState(GL_POINT_SIZE_ARRAY_OES); - } - else { - m_glDisableClientState(GL_POINT_SIZE_ARRAY_OES); - } -} -#endif - - -int RenderingThread::s_createContext(uint32_t pid, uint32_t handle, uint32_t shareCtx, int version) -{ - return Renderer::instance()->createContext(m_tls, Renderer::ClientHandle(pid, handle), - Renderer::ClientHandle(pid, shareCtx), - version); - -} - - -int RenderingThread::s_createSurface(uint32_t pid, uint32_t handle) -{ - return Renderer::instance()->createSurface(m_tls, Renderer::ClientHandle(pid, handle)); -} - -int RenderingThread::s_destroySurface(uint32_t pid, uint32_t handle) -{ - return Renderer::instance()->destroySurface(m_tls, Renderer::ClientHandle(pid, handle)); -} - -int RenderingThread::s_destroyContext(uint32_t pid, uint32_t handle) -{ - return Renderer::instance()->destroyContext(m_tls, Renderer::ClientHandle(pid, handle)); -} - - -int RenderingThread::s_makeCurrent(uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctx) -{ - int ret = Renderer::instance()->makeCurrent(m_tls, - Renderer::ClientHandle(pid, drawSurface), - Renderer::ClientHandle(pid, readSurface), - Renderer::ClientHandle(pid, ctx)); - - if (ret && ctx) { - m_tls->initBackendCaps(); - } - - return ret; -} - -void RenderingThread::s_swapBuffers(uint32_t pid, uint32_t surface) -{ - Renderer::instance()->swapBuffers(m_tls, Renderer::ClientHandle(pid, surface)); -} - - -RenderingThread::RenderingThread(SocketStream *stream) : - m_stream(stream), - m_currentContext(NULL) -{ - m_backendCaps.initialized = false; -} - -int RenderingThread::start(void) -{ - if (pthread_create(&m_thread, NULL, s_thread, this) < 0) { - perror("pthread_create"); - return -1; - } - return 0; -} - - -void * RenderingThread::s_thread(void *data) -{ - RenderingThread *self = (RenderingThread *)data; - m_tls = self; - return self->thread(); -} - -void RenderingThread::initBackendCaps() -{ - if (m_backendCaps.initialized) return; - - m_glDec.glGetIntegerv(GL_MAX_TEXTURE_UNITS, (GLint *)&m_backendCaps.maxTextureUnits); - m_backendCaps.initialized = true; -} - -void *RenderingThread::thread() -{ - - // initialize our decoders; - m_glDec.initGL(); - -#ifdef PVR_WAR - m_glTexParameteriv = m_glDec.set_glTexParameteriv(s_glTexParameteriv); - m_glDrawTexfOES = m_glDec.set_glDrawTexfOES(s_glDrawTexfOES); - m_glDrawTexsOES = m_glDec.set_glDrawTexsOES(s_glDrawTexsOES); - m_glDrawTexiOES = m_glDec.set_glDrawTexiOES(s_glDrawTexiOES); - m_glDrawTexxOES = m_glDec.set_glDrawTexxOES(s_glDrawTexxOES); - m_glDrawTexfvOES = m_glDec.set_glDrawTexfvOES(s_glDrawTexfvOES); - m_glDrawTexsvOES = m_glDec.set_glDrawTexsvOES(s_glDrawTexsvOES); - m_glDrawTexivOES = m_glDec.set_glDrawTexivOES(s_glDrawTexivOES); - m_glDrawTexxvOES = m_glDec.set_glDrawTexxvOES(s_glDrawTexxvOES); - m_glActiveTexture = m_glDec.set_glActiveTexture(s_glActiveTexture); - m_glBindTexture = m_glDec.set_glBindTexture(s_glBindTexture); - m_glEnable = m_glDec.set_glEnable(s_glEnable); - m_glDisable = m_glDec.set_glDisable(s_glDisable); - m_glClientActiveTexture = m_glDec.set_glClientActiveTexture(s_glClientActiveTexture); - m_glEnableClientState = m_glDec.set_glEnableClientState(s_glEnableClientState); - m_glDisableClientState = m_glDec.set_glDisableClientState(s_glDisableClientState); -#endif - - m_gl2Dec.initGL(); - - m_utDec.set_swapBuffers(s_swapBuffers); - m_utDec.set_createContext(s_createContext); - m_utDec.set_destroyContext(s_destroyContext); - m_utDec.set_createSurface(s_createSurface); - m_utDec.set_destroySurface(s_destroySurface); - m_utDec.set_makeCurrentContext(s_makeCurrent); - - ReadBuffer readBuf(m_stream, DECODER_BUF_SIZE); - - int stats_totalBytes = 0; - long long stats_t0 = GetCurrentTimeMS(); - - while (1) { - - int stat = readBuf.getData(); - if (stat == 0) { - fprintf(stderr, "client shutdown\n"); - break; - } else if (stat < 0) { - perror("getData"); - break; - } - - // - // log received bandwidth statistics - // - stats_totalBytes += readBuf.validData(); - long long dt = GetCurrentTimeMS() - stats_t0; - if (dt > 1000) { - float dts = (float)dt / 1000.0f; - printf("Used Bandwidth %5.3f MB/s\n", ((float)stats_totalBytes / dts) / (1024.0f*1024.0f)); - stats_totalBytes = 0; - stats_t0 = GetCurrentTimeMS(); - } - - bool progress = true; - while (progress) { - progress = false; - // we need at least one header (8 bytes) in our buffer - if (readBuf.validData() >= 8) { - size_t last = m_glDec.decode(readBuf.buf(), readBuf.validData(), m_stream); - if (last > 0) { - progress = true; - readBuf.consume(last); - } - } - - if (readBuf.validData() >= 8) { - size_t last = m_gl2Dec.decode(readBuf.buf(), readBuf.validData(), m_stream); - if (last > 0) { - readBuf.consume(last); - progress = true; - } - } - - if (readBuf.validData() >= 8) { - size_t last = m_utDec.decode(readBuf.buf(), readBuf.validData(), m_stream); - if (last > 0) { - readBuf.consume(last); - progress = true; - } - } - } - } - // shutdown - if (m_currentContext != NULL) { - m_currentContext->unref(); - } - - return NULL; -} diff --git a/emulator/opengl/tests/ut_renderer/RenderingThread.h b/emulator/opengl/tests/ut_renderer/RenderingThread.h deleted file mode 100644 index 0b4ebe6..0000000 --- a/emulator/opengl/tests/ut_renderer/RenderingThread.h +++ /dev/null @@ -1,117 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _RENDERING_THREAD_H_ -#define _RENDERING_THREAD_H_ - -#include "SocketStream.h" -#include "GLDecoder.h" -#include "GL2Decoder.h" -#include "ut_rendercontrol_dec.h" -#include <pthread.h> - -#define GL_API -#define GL_APIENTRY - -#include <GLES/egl.h> -#include <GLES/gl.h> - - -#define WINDOW_WIDTH 320 -#define WINDOW_HEIGHT 480 - -#define DECODER_BUF_SIZE (4 * 1024 * 1024) - -class RendererContext; - -class RenderingThread { -public: - RenderingThread(SocketStream *stream); - int start(); - void *thread(); - RendererContext *currentContext() { return m_currentContext; } - void setCurrentContext(RendererContext *ctx) { m_currentContext = ctx; } - GLDecoder & glDecoder() { return m_glDec; } - GL2Decoder & gl2Decoder() { return m_gl2Dec; } - -private: - void initBackendCaps(); - -private: - GLDecoder m_glDec; - ut_rendercontrol_decoder_context_t m_utDec; - GL2Decoder m_gl2Dec; - - SocketStream *m_stream; - pthread_t m_thread; - RendererContext * m_currentContext; - - struct BackendCaps { - bool initialized; - GLuint maxTextureUnits; - } m_backendCaps; - - static void * s_thread(void *data); - static __thread RenderingThread *m_tls; - - static int s_createContext(uint32_t pid, uint32_t handle, uint32_t shareCtx, int version); - static int s_createSurface(uint32_t pid, uint32_t handle); - static int s_destroySurface(uint32_t pid, uint32_t handle); - static int s_destroyContext(uint32_t pid, uint32_t handle); - static int s_makeCurrent(uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctx); - static void s_swapBuffers(uint32_t pid, uint32_t surface); -#ifdef PVR_WAR - static void s_glTexParameteriv(GLenum target, GLenum param, const int *p); - static void s_glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h); - static void s_glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort w, GLshort h); - static void s_glDrawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h); - static void s_glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h); - static void s_glDrawTexfvOES(const GLfloat *coords); - static void s_glDrawTexsvOES(const GLshort *coords); - static void s_glDrawTexivOES(const GLint *coords); - static void s_glDrawTexxvOES(const GLfixed *coords); - - static void s_glActiveTexture(GLenum texture); - static void s_glBindTexture(GLenum target, GLuint texture); - static void s_glEnable(GLenum cap); - static void s_glDisable(GLenum cap); - static void s_glClientActiveTexture(GLenum texture); - static void s_glEnableClientState(GLenum cap); - static void s_glDisableClientState(GLenum cap); - - void applyPendingCropRects(); - void fixTextureEnable(); - - glTexParameteriv_server_proc_t m_glTexParameteriv; - glDrawTexfOES_server_proc_t m_glDrawTexfOES; - glDrawTexiOES_server_proc_t m_glDrawTexiOES; - glDrawTexsOES_server_proc_t m_glDrawTexsOES; - glDrawTexxOES_server_proc_t m_glDrawTexxOES; - glDrawTexfvOES_server_proc_t m_glDrawTexfvOES; - glDrawTexivOES_server_proc_t m_glDrawTexivOES; - glDrawTexsvOES_server_proc_t m_glDrawTexsvOES; - glDrawTexxvOES_server_proc_t m_glDrawTexxvOES; - glActiveTexture_server_proc_t m_glActiveTexture; - glBindTexture_server_proc_t m_glBindTexture; - glEnable_server_proc_t m_glEnable; - glDisable_server_proc_t m_glDisable; - glClientActiveTexture_server_proc_t m_glClientActiveTexture; - glEnableClientState_server_proc_t m_glEnableClientState; - glDisableClientState_server_proc_t m_glDisableClientState; -#endif - -}; - -#endif diff --git a/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp b/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp deleted file mode 100644 index 121ee87..0000000 --- a/emulator/opengl/tests/ut_renderer/X11RendererSurface.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "X11RendererSurface.h" - -NativeDisplayType X11RendererSurface::getNativeDisplay() -{ - if (m_display == NULL) { - m_display = XOpenDisplay(NULL); - } - return NativeDisplayType(m_display); -} - -int X11RendererSurface::destoryNativeWindow(NativeWindowType win) -{ - if (m_display == NULL) return -1; - - Window x11Window = (Window)(win); - return XDestroyWindow(m_display, x11Window); -} - -NativeWindowType GlesX11Win::createNativeWindow() -{ - - getNativeDisplay(); - if (m_display == NULL) { - return -1; - } - - long defaultScreen = DefaultScreen( dpy ); - Window rootWindow = RootWindow(dpy, defaultScreen); - int depth = DefaultDepth(dpy, defaultScreen); - XVisualInfo *visualInfo = new XVisualInfo; - - XMatchVisualInfo(m_display, defaultScreen, , dpeth, TrueColor, visualInfo); - if (visualInfo == NULL) { - fprintf(stderr, "couldn't find matching visual\n"); - return -1; - } - - Colormap x11Colormap = XCreateColormap(m_display, rootWindow, visualInfo->visual, AllocNone); - XSetWindowAttributes sWA; - sWA.Colormap = x11Colormap; - sWA.event_mask = StructureNotifyMask | ExposureMask; - unsigned int eventMask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; - - Window win = XCreateWindow( m_display, - rootWindow, - 0, 0, width, height, - 0, CopyFromParent, InputOutput, - CopyFromParent, eventMask, &sWA); - - XMapWindow(m_display, win); - XFlush(m_display); - return NativeWindowType(win); -} - diff --git a/emulator/opengl/tests/ut_renderer/X11RendererSurface.h b/emulator/opengl/tests/ut_renderer/X11RendererSurface.h deleted file mode 100644 index be9bcec..0000000 --- a/emulator/opengl/tests/ut_renderer/X11RendererSurface.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _X11_RENDERER_SURFACE_H_ -#define _X11_RENDERER_SURFACE_H_ - -#include <X11/Xutil.h> -#include <X11/Xlib.h> -#include <EGL/egl.h> - -include "RendererSurface.h" - -class X11RendererSurface : public RendererSurface -{ -public: - X11RendererSurface() : RendererSurface() { - m_display = NULL; - } - NativeDisplayType getNativeDisplay(); - NativeWindowType createNativeWindow(); - int destroyNativeWindow(NativeWindowType win); -private: - Display m_display; -}; -#endif diff --git a/emulator/opengl/tests/ut_renderer/X11Windowing.cpp b/emulator/opengl/tests/ut_renderer/X11Windowing.cpp deleted file mode 100644 index cc94fdd..0000000 --- a/emulator/opengl/tests/ut_renderer/X11Windowing.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include "X11Windowing.h" - -#include <stdio.h> -#include <stdlib.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> - -#define DEBUG 0 -#if DEBUG -# define D(...) printf(__VA_ARGS__), printf("\n") -#else -# define D(...) ((void)0) -#endif - -/* Try to remember the window position between creates/destroys */ -static int X11_wmXPos = 100; -static int X11_wmYPos = 100; - -static int X11_wmXAdjust = 0; -static int X11_wmYAdjust = 0; - -static void -get_window_pos( Display *disp, Window win, int *px, int *py ) -{ - Window child; - - XTranslateCoordinates( disp, win, DefaultRootWindow(disp), 0, 0, px, py, &child ); -} - - -static void -set_window_pos(Display *disp, Window win, int x, int y) -{ - int xNew, yNew; - int xAdjust = X11_wmXAdjust; - int yAdjust = X11_wmYAdjust; - - /* this code is tricky because some window managers, but not all, - * will translate the final window position by a given offset - * corresponding to the frame decoration. - * - * so we first try to move the window, get the position that the - * window manager has set, and if they are different, re-position the - * window again with an adjustment. - * - * this causes a slight flicker since the window 'jumps' very - * quickly from one position to the other. - */ - - D("%s: move to [%d,%d] adjusted to [%d,%d]", __FUNCTION__, - x, y, x+xAdjust, y+yAdjust); - XMoveWindow(disp, win, x + xAdjust, y + yAdjust); - XSync(disp, True); - get_window_pos(disp, win, &xNew, &yNew); - if (xNew != x || yNew != y) { - X11_wmXAdjust = xAdjust = x - xNew; - X11_wmYAdjust = yAdjust = y - yNew; - D("%s: read pos [%d,%d], recomputing adjust=[%d,%d] moving to [%d,%d]\n", - __FUNCTION__, xNew, yNew, xAdjust, yAdjust, x+xAdjust, y+yAdjust); - XMoveWindow(disp, win, x + xAdjust, y + yAdjust ); - } - XSync(disp, False); -} - - -NativeDisplayType X11Windowing::getNativeDisplay() -{ - Display *dpy = XOpenDisplay(NULL); - return (NativeDisplayType)dpy; -} - -NativeWindowType X11Windowing::createNativeWindow(NativeDisplayType _dpy, int width, int height) -{ - Display *dpy = (Display *) _dpy; - - long defaultScreen = DefaultScreen( dpy ); - Window rootWindow = RootWindow(dpy, defaultScreen); - int depth = DefaultDepth(dpy, defaultScreen); - XVisualInfo *visualInfo = new XVisualInfo; - - XMatchVisualInfo(dpy, defaultScreen, depth, TrueColor, visualInfo); - if (visualInfo == NULL) { - fprintf(stderr, "couldn't find matching visual\n"); - return NULL; - } - - Colormap x11Colormap = XCreateColormap(dpy, rootWindow, visualInfo->visual, AllocNone); - XSetWindowAttributes sWA; - sWA.colormap = x11Colormap; - sWA.event_mask = StructureNotifyMask | ExposureMask; - sWA.background_pixel = 0; - sWA.border_pixel = 0; - unsigned int attributes_mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; - - Window win = XCreateWindow( dpy, - rootWindow, - X11_wmXPos, X11_wmYPos, width, height, - 0, CopyFromParent, InputOutput, - CopyFromParent, attributes_mask, &sWA); - - XMapWindow(dpy, win); - XFlush(dpy); - set_window_pos(dpy, win, X11_wmXPos, X11_wmYPos); - return NativeWindowType(win); -} - -int X11Windowing::destroyNativeWindow(NativeDisplayType _dpy, NativeWindowType _win) -{ - Display *dpy = (Display *)_dpy; - Window win = (Window)_win; - get_window_pos(dpy, win, &X11_wmXPos, &X11_wmYPos); - D("%s: Saved window position [%d, %d]\n", __FUNCTION__, X11_wmXPos, X11_wmYPos); - XDestroyWindow(dpy, win); - XFlush(dpy); - return 0; -} diff --git a/emulator/opengl/tests/ut_renderer/X11Windowing.h b/emulator/opengl/tests/ut_renderer/X11Windowing.h deleted file mode 100644 index 0f0c76b..0000000 --- a/emulator/opengl/tests/ut_renderer/X11Windowing.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#ifndef _X11WINDOWING_H_ -#define _X11WINDOWING_H_ - -#include "NativeWindowing.h" - -class X11Windowing : public NativeWindowing { - NativeDisplayType getNativeDisplay(); - NativeWindowType createNativeWindow(NativeDisplayType _dpy, int width, int height); - int destroyNativeWindow(NativeDisplayType dpy, NativeWindowType win); -}; - -#endif diff --git a/emulator/opengl/tests/ut_renderer/ut_renderer.cpp b/emulator/opengl/tests/ut_renderer/ut_renderer.cpp deleted file mode 100644 index f2b2bc3..0000000 --- a/emulator/opengl/tests/ut_renderer/ut_renderer.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* -* Copyright (C) 2011 The Android Open Source Project -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include "codec_defs.h" -#include "RenderingThread.h" -#include "TcpStream.h" -#ifndef _WIN32 -#include "UnixStream.h" -#endif - - -int main(int argc, char **argv) -{ -#ifdef _WIN32 - TcpStream *socket = new TcpStream(); - - if (socket->listen(CODEC_SERVER_PORT) < 0) { - perror("listen"); - exit(1); - } -#else - UnixStream *socket = new UnixStream(); - - if (socket->listen(CODEC_SERVER_PORT) < 0) { - perror("listen"); - exit(1); - } -#endif - - printf("waiting for client connection on port: %d\n", CODEC_SERVER_PORT); - while (1) { - // wait for client connection - SocketStream *glStream = socket->accept(); - if (glStream == NULL) { - printf("failed to get client.. aborting\n"); - exit(3); - } - printf("Got client connection, creating a rendering thread;\n"); - // create a thread to handle this connection - RenderingThread *rt = new RenderingThread(glStream); - rt->start(); - } - - return 0; -} - - |