From f2f0f6e3082799584ea851ef737d9cf7e4e2efec Mon Sep 17 00:00:00 2001 From: ExMix Date: Thu, 2 May 2013 14:06:45 +0300 Subject: [PATCH] lineending fix --- 3party/zlib/contrib/dotzlib/readme.txt | 116 +- 3party/zlib/contrib/masmx64/inffas8664.c | 372 ++--- 3party/zlib/contrib/testzlib/testzlib.c | 550 +++---- 3party/zlib/contrib/vstudio/readme.txt | 120 +- android/jni/nv_event/nv_event.cpp | 1886 +++++++++++----------- android/jni/nv_event/nv_event_queue.hpp | 184 +-- android/jni/nv_time/nv_time.hpp | 68 +- data/styles/symbols/placemark-red.svg | 52 +- 8 files changed, 1674 insertions(+), 1674 deletions(-) diff --git a/3party/zlib/contrib/dotzlib/readme.txt b/3party/zlib/contrib/dotzlib/readme.txt index b2395720d4..4d8c2dd932 100644 --- a/3party/zlib/contrib/dotzlib/readme.txt +++ b/3party/zlib/contrib/dotzlib/readme.txt @@ -1,58 +1,58 @@ -This directory contains a .Net wrapper class library for the ZLib1.dll - -The wrapper includes support for inflating/deflating memory buffers, -.Net streaming wrappers for the gz streams part of zlib, and wrappers -for the checksum parts of zlib. See DotZLib/UnitTests.cs for examples. - -Directory structure: --------------------- - -LICENSE_1_0.txt - License file. -readme.txt - This file. -DotZLib.chm - Class library documentation -DotZLib.build - NAnt build file -DotZLib.sln - Microsoft Visual Studio 2003 solution file - -DotZLib\*.cs - Source files for the class library - -Unit tests: ------------ -The file DotZLib/UnitTests.cs contains unit tests for use with NUnit 2.1 or higher. -To include unit tests in the build, define nunit before building. - - -Build instructions: -------------------- - -1. Using Visual Studio.Net 2003: - Open DotZLib.sln in VS.Net and build from there. Output file (DotZLib.dll) - will be found ./DotZLib/bin/release or ./DotZLib/bin/debug, depending on - you are building the release or debug version of the library. Check - DotZLib/UnitTests.cs for instructions on how to include unit tests in the - build. - -2. Using NAnt: - Open a command prompt with access to the build environment and run nant - in the same directory as the DotZLib.build file. - You can define 2 properties on the nant command-line to control the build: - debug={true|false} to toggle between release/debug builds (default=true). - nunit={true|false} to include or esclude unit tests (default=true). - Also the target clean will remove binaries. - Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release - or ./DotZLib/bin/debug, depending on whether you are building the release - or debug version of the library. - - Examples: - nant -D:debug=false -D:nunit=false - will build a release mode version of the library without unit tests. - nant - will build a debug version of the library with unit tests - nant clean - will remove all previously built files. - - ---------------------------------- -Copyright (c) Henrik Ravn 2004 - -Use, modification and distribution are subject to the Boost Software License, Version 1.0. -(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +This directory contains a .Net wrapper class library for the ZLib1.dll + +The wrapper includes support for inflating/deflating memory buffers, +.Net streaming wrappers for the gz streams part of zlib, and wrappers +for the checksum parts of zlib. See DotZLib/UnitTests.cs for examples. + +Directory structure: +-------------------- + +LICENSE_1_0.txt - License file. +readme.txt - This file. +DotZLib.chm - Class library documentation +DotZLib.build - NAnt build file +DotZLib.sln - Microsoft Visual Studio 2003 solution file + +DotZLib\*.cs - Source files for the class library + +Unit tests: +----------- +The file DotZLib/UnitTests.cs contains unit tests for use with NUnit 2.1 or higher. +To include unit tests in the build, define nunit before building. + + +Build instructions: +------------------- + +1. Using Visual Studio.Net 2003: + Open DotZLib.sln in VS.Net and build from there. Output file (DotZLib.dll) + will be found ./DotZLib/bin/release or ./DotZLib/bin/debug, depending on + you are building the release or debug version of the library. Check + DotZLib/UnitTests.cs for instructions on how to include unit tests in the + build. + +2. Using NAnt: + Open a command prompt with access to the build environment and run nant + in the same directory as the DotZLib.build file. + You can define 2 properties on the nant command-line to control the build: + debug={true|false} to toggle between release/debug builds (default=true). + nunit={true|false} to include or esclude unit tests (default=true). + Also the target clean will remove binaries. + Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release + or ./DotZLib/bin/debug, depending on whether you are building the release + or debug version of the library. + + Examples: + nant -D:debug=false -D:nunit=false + will build a release mode version of the library without unit tests. + nant + will build a debug version of the library with unit tests + nant clean + will remove all previously built files. + + +--------------------------------- +Copyright (c) Henrik Ravn 2004 + +Use, modification and distribution are subject to the Boost Software License, Version 1.0. +(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/3party/zlib/contrib/masmx64/inffas8664.c b/3party/zlib/contrib/masmx64/inffas8664.c index e8af06fa02..aa861a3339 100644 --- a/3party/zlib/contrib/masmx64/inffas8664.c +++ b/3party/zlib/contrib/masmx64/inffas8664.c @@ -1,186 +1,186 @@ -/* inffas8664.c is a hand tuned assembler version of inffast.c - fast decoding - * version for AMD64 on Windows using Microsoft C compiler - * - * Copyright (C) 1995-2003 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Copyright (C) 2003 Chris Anderson - * Please use the copyright conditions above. - * - * 2005 - Adaptation to Microsoft C Compiler for AMD64 by Gilles Vollant - * - * inffas8664.c call function inffas8664fnc in inffasx64.asm - * inffasx64.asm is automatically convert from AMD64 portion of inffas86.c - * - * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also - * slightly quicker on x86 systems because, instead of using rep movsb to copy - * data, it uses rep movsw, which moves data in 2-byte chunks instead of single - * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates - * from http://fedora.linux.duke.edu/fc1_x86_64 - * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with - * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, - * when decompressing mozilla-source-1.3.tar.gz. - * - * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from - * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at - * the moment. I have successfully compiled and tested this code with gcc2.96, - * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S - * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX - * enabled. I will attempt to merge the MMX code into this version. Newer - * versions of this and inffast.S can be found at - * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ - * - */ - -#include -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -/* Mark Adler's comments from inffast.c: */ - -/* - Decode literal, length, and distance codes and write out the resulting - literal and match bytes until either not enough input or output is - available, an end-of-block is encountered, or a data error is encountered. - When large enough input and output buffers are supplied to inflate(), for - example, a 16K input buffer and a 64K output buffer, more than 95% of the - inflate execution time is spent in this routine. - - Entry assumptions: - - state->mode == LEN - strm->avail_in >= 6 - strm->avail_out >= 258 - start >= strm->avail_out - state->bits < 8 - - On return, state->mode is one of: - - LEN -- ran out of enough output space or enough available input - TYPE -- reached end of block code, inflate() to interpret next block - BAD -- error in block data - - Notes: - - - The maximum input bits used by a length/distance pair is 15 bits for the - length code, 5 bits for the length extra, 15 bits for the distance code, - and 13 bits for the distance extra. This totals 48 bits, or six bytes. - Therefore if strm->avail_in >= 6, then there is enough input to avoid - checking for available input while decoding. - - - The maximum bytes that a single length/distance pair can output is 258 - bytes, which is the maximum length that can be coded. inflate_fast() - requires strm->avail_out >= 258 for each loop to avoid checking for - output space. - */ - - - - typedef struct inffast_ar { -/* 64 32 x86 x86_64 */ -/* ar offset register */ -/* 0 0 */ void *esp; /* esp save */ -/* 8 4 */ void *ebp; /* ebp save */ -/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ -/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ -/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ -/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ -/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ -/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ -/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ -/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ -/* 80 40 */ size_t /*unsigned long */hold; /* edx rdx local strm->hold */ -/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ -/* 92 48 */ unsigned wsize; /* window size */ -/* 96 52 */ unsigned write; /* window write index */ -/*100 56 */ unsigned lmask; /* r12 mask for lcode */ -/*104 60 */ unsigned dmask; /* r13 mask for dcode */ -/*108 64 */ unsigned len; /* r14 match length */ -/*112 68 */ unsigned dist; /* r15 match distance */ -/*116 72 */ unsigned status; /* set when state chng*/ - } type_ar; -#ifdef ASMINF - -void inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ -{ - struct inflate_state FAR *state; - type_ar ar; - void inffas8664fnc(struct inffast_ar * par); - - - -#if (defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )) || (defined(_MSC_VER) && defined(_M_AMD64)) -#define PAD_AVAIL_IN 6 -#define PAD_AVAIL_OUT 258 -#else -#define PAD_AVAIL_IN 5 -#define PAD_AVAIL_OUT 257 -#endif - - /* copy state to local variables */ - state = (struct inflate_state FAR *)strm->state; - - ar.in = strm->next_in; - ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); - ar.out = strm->next_out; - ar.beg = ar.out - (start - strm->avail_out); - ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); - ar.wsize = state->wsize; - ar.write = state->wnext; - ar.window = state->window; - ar.hold = state->hold; - ar.bits = state->bits; - ar.lcode = state->lencode; - ar.dcode = state->distcode; - ar.lmask = (1U << state->lenbits) - 1; - ar.dmask = (1U << state->distbits) - 1; - - /* decode literals and length/distances until end-of-block or not enough - input data or output space */ - - /* align in on 1/2 hold size boundary */ - while (((size_t)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { - ar.hold += (unsigned long)*ar.in++ << ar.bits; - ar.bits += 8; - } - - inffas8664fnc(&ar); - - if (ar.status > 1) { - if (ar.status == 2) - strm->msg = "invalid literal/length code"; - else if (ar.status == 3) - strm->msg = "invalid distance code"; - else - strm->msg = "invalid distance too far back"; - state->mode = BAD; - } - else if ( ar.status == 1 ) { - state->mode = TYPE; - } - - /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ - ar.len = ar.bits >> 3; - ar.in -= ar.len; - ar.bits -= ar.len << 3; - ar.hold &= (1U << ar.bits) - 1; - - /* update state and return */ - strm->next_in = ar.in; - strm->next_out = ar.out; - strm->avail_in = (unsigned)(ar.in < ar.last ? - PAD_AVAIL_IN + (ar.last - ar.in) : - PAD_AVAIL_IN - (ar.in - ar.last)); - strm->avail_out = (unsigned)(ar.out < ar.end ? - PAD_AVAIL_OUT + (ar.end - ar.out) : - PAD_AVAIL_OUT - (ar.out - ar.end)); - state->hold = (unsigned long)ar.hold; - state->bits = ar.bits; - return; -} - -#endif +/* inffas8664.c is a hand tuned assembler version of inffast.c - fast decoding + * version for AMD64 on Windows using Microsoft C compiler + * + * Copyright (C) 1995-2003 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + * + * Copyright (C) 2003 Chris Anderson + * Please use the copyright conditions above. + * + * 2005 - Adaptation to Microsoft C Compiler for AMD64 by Gilles Vollant + * + * inffas8664.c call function inffas8664fnc in inffasx64.asm + * inffasx64.asm is automatically convert from AMD64 portion of inffas86.c + * + * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also + * slightly quicker on x86 systems because, instead of using rep movsb to copy + * data, it uses rep movsw, which moves data in 2-byte chunks instead of single + * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates + * from http://fedora.linux.duke.edu/fc1_x86_64 + * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with + * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, + * when decompressing mozilla-source-1.3.tar.gz. + * + * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from + * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at + * the moment. I have successfully compiled and tested this code with gcc2.96, + * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S + * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX + * enabled. I will attempt to merge the MMX code into this version. Newer + * versions of this and inffast.S can be found at + * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ + * + */ + +#include +#include "zutil.h" +#include "inftrees.h" +#include "inflate.h" +#include "inffast.h" + +/* Mark Adler's comments from inffast.c: */ + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state->mode == LEN + strm->avail_in >= 6 + strm->avail_out >= 258 + start >= strm->avail_out + state->bits < 8 + + On return, state->mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm->avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm->avail_out >= 258 for each loop to avoid checking for + output space. + */ + + + + typedef struct inffast_ar { +/* 64 32 x86 x86_64 */ +/* ar offset register */ +/* 0 0 */ void *esp; /* esp save */ +/* 8 4 */ void *ebp; /* ebp save */ +/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ +/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ +/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ +/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ +/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ +/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ +/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ +/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ +/* 80 40 */ size_t /*unsigned long */hold; /* edx rdx local strm->hold */ +/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ +/* 92 48 */ unsigned wsize; /* window size */ +/* 96 52 */ unsigned write; /* window write index */ +/*100 56 */ unsigned lmask; /* r12 mask for lcode */ +/*104 60 */ unsigned dmask; /* r13 mask for dcode */ +/*108 64 */ unsigned len; /* r14 match length */ +/*112 68 */ unsigned dist; /* r15 match distance */ +/*116 72 */ unsigned status; /* set when state chng*/ + } type_ar; +#ifdef ASMINF + +void inflate_fast(strm, start) +z_streamp strm; +unsigned start; /* inflate()'s starting value for strm->avail_out */ +{ + struct inflate_state FAR *state; + type_ar ar; + void inffas8664fnc(struct inffast_ar * par); + + + +#if (defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )) || (defined(_MSC_VER) && defined(_M_AMD64)) +#define PAD_AVAIL_IN 6 +#define PAD_AVAIL_OUT 258 +#else +#define PAD_AVAIL_IN 5 +#define PAD_AVAIL_OUT 257 +#endif + + /* copy state to local variables */ + state = (struct inflate_state FAR *)strm->state; + + ar.in = strm->next_in; + ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); + ar.out = strm->next_out; + ar.beg = ar.out - (start - strm->avail_out); + ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); + ar.wsize = state->wsize; + ar.write = state->wnext; + ar.window = state->window; + ar.hold = state->hold; + ar.bits = state->bits; + ar.lcode = state->lencode; + ar.dcode = state->distcode; + ar.lmask = (1U << state->lenbits) - 1; + ar.dmask = (1U << state->distbits) - 1; + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + + /* align in on 1/2 hold size boundary */ + while (((size_t)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { + ar.hold += (unsigned long)*ar.in++ << ar.bits; + ar.bits += 8; + } + + inffas8664fnc(&ar); + + if (ar.status > 1) { + if (ar.status == 2) + strm->msg = "invalid literal/length code"; + else if (ar.status == 3) + strm->msg = "invalid distance code"; + else + strm->msg = "invalid distance too far back"; + state->mode = BAD; + } + else if ( ar.status == 1 ) { + state->mode = TYPE; + } + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + ar.len = ar.bits >> 3; + ar.in -= ar.len; + ar.bits -= ar.len << 3; + ar.hold &= (1U << ar.bits) - 1; + + /* update state and return */ + strm->next_in = ar.in; + strm->next_out = ar.out; + strm->avail_in = (unsigned)(ar.in < ar.last ? + PAD_AVAIL_IN + (ar.last - ar.in) : + PAD_AVAIL_IN - (ar.in - ar.last)); + strm->avail_out = (unsigned)(ar.out < ar.end ? + PAD_AVAIL_OUT + (ar.end - ar.out) : + PAD_AVAIL_OUT - (ar.out - ar.end)); + state->hold = (unsigned long)ar.hold; + state->bits = ar.bits; + return; +} + +#endif diff --git a/3party/zlib/contrib/testzlib/testzlib.c b/3party/zlib/contrib/testzlib/testzlib.c index 135888eb10..f559a36461 100644 --- a/3party/zlib/contrib/testzlib/testzlib.c +++ b/3party/zlib/contrib/testzlib/testzlib.c @@ -1,275 +1,275 @@ -#include -#include -#include - -#include "zlib.h" - - -void MyDoMinus64(LARGE_INTEGER *R,LARGE_INTEGER A,LARGE_INTEGER B) -{ - R->HighPart = A.HighPart - B.HighPart; - if (A.LowPart >= B.LowPart) - R->LowPart = A.LowPart - B.LowPart; - else - { - R->LowPart = A.LowPart - B.LowPart; - R->HighPart --; - } -} - -#ifdef _M_X64 -// see http://msdn2.microsoft.com/library/twchhe95(en-us,vs.80).aspx for __rdtsc -unsigned __int64 __rdtsc(void); -void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) -{ - // printf("rdtsc = %I64x\n",__rdtsc()); - pbeginTime64->QuadPart=__rdtsc(); -} - -LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) -{ - LARGE_INTEGER LIres; - unsigned _int64 res=__rdtsc()-((unsigned _int64)(beginTime64.QuadPart)); - LIres.QuadPart=res; - // printf("rdtsc = %I64x\n",__rdtsc()); - return LIres; -} -#else -#ifdef _M_IX86 -void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) -{ - DWORD dwEdx,dwEax; - _asm - { - rdtsc - mov dwEax,eax - mov dwEdx,edx - } - pbeginTime64->LowPart=dwEax; - pbeginTime64->HighPart=dwEdx; -} - -void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) -{ - myGetRDTSC32(pbeginTime64); -} - -LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) -{ - LARGE_INTEGER LIres,endTime64; - myGetRDTSC32(&endTime64); - - LIres.LowPart=LIres.HighPart=0; - MyDoMinus64(&LIres,endTime64,beginTime64); - return LIres; -} -#else -void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) -{ -} - -void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) -{ -} - -LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) -{ - LARGE_INTEGER lr; - lr.QuadPart=0; - return lr; -} -#endif -#endif - -void BeginCountPerfCounter(LARGE_INTEGER * pbeginTime64,BOOL fComputeTimeQueryPerf) -{ - if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(pbeginTime64))) - { - pbeginTime64->LowPart = GetTickCount(); - pbeginTime64->HighPart = 0; - } -} - -DWORD GetMsecSincePerfCounter(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) -{ - LARGE_INTEGER endTime64,ticksPerSecond,ticks; - DWORDLONG ticksShifted,tickSecShifted; - DWORD dwLog=16+0; - DWORD dwRet; - if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(&endTime64))) - dwRet = (GetTickCount() - beginTime64.LowPart)*1; - else - { - MyDoMinus64(&ticks,endTime64,beginTime64); - QueryPerformanceFrequency(&ticksPerSecond); - - - { - ticksShifted = Int64ShrlMod32(*(DWORDLONG*)&ticks,dwLog); - tickSecShifted = Int64ShrlMod32(*(DWORDLONG*)&ticksPerSecond,dwLog); - - } - - dwRet = (DWORD)((((DWORD)ticksShifted)*1000)/(DWORD)(tickSecShifted)); - dwRet *=1; - } - return dwRet; -} - -int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr) -{ - FILE* stream; - void* ptr; - int retVal=1; - stream=fopen(filename, "rb"); - if (stream==NULL) - return 0; - - fseek(stream,0,SEEK_END); - - *plFileSize=ftell(stream); - fseek(stream,0,SEEK_SET); - ptr=malloc((*plFileSize)+1); - if (ptr==NULL) - retVal=0; - else - { - if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize)) - retVal=0; - } - fclose(stream); - *pFilePtr=ptr; - return retVal; -} - -int main(int argc, char *argv[]) -{ - int BlockSizeCompress=0x8000; - int BlockSizeUncompress=0x8000; - int cprLevel=Z_DEFAULT_COMPRESSION ; - long lFileSize; - unsigned char* FilePtr; - long lBufferSizeCpr; - long lBufferSizeUncpr; - long lCompressedSize=0; - unsigned char* CprPtr; - unsigned char* UncprPtr; - long lSizeCpr,lSizeUncpr; - DWORD dwGetTick,dwMsecQP; - LARGE_INTEGER li_qp,li_rdtsc,dwResRdtsc; - - if (argc<=1) - { - printf("run TestZlib [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n"); - return 0; - } - - if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0) - { - printf("error reading %s\n",argv[1]); - return 1; - } - else printf("file %s read, %u bytes\n",argv[1],lFileSize); - - if (argc>=3) - BlockSizeCompress=atol(argv[2]); - - if (argc>=4) - BlockSizeUncompress=atol(argv[3]); - - if (argc>=5) - cprLevel=(int)atol(argv[4]); - - lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200; - lBufferSizeUncpr = lBufferSizeCpr; - - CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress); - - BeginCountPerfCounter(&li_qp,TRUE); - dwGetTick=GetTickCount(); - BeginCountRdtsc(&li_rdtsc); - { - z_stream zcpr; - int ret=Z_OK; - long lOrigToDo = lFileSize; - long lOrigDone = 0; - int step=0; - memset(&zcpr,0,sizeof(z_stream)); - deflateInit(&zcpr,cprLevel); - - zcpr.next_in = FilePtr; - zcpr.next_out = CprPtr; - - - do - { - long all_read_before = zcpr.total_in; - zcpr.avail_in = min(lOrigToDo,BlockSizeCompress); - zcpr.avail_out = BlockSizeCompress; - ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH); - lOrigDone += (zcpr.total_in-all_read_before); - lOrigToDo -= (zcpr.total_in-all_read_before); - step++; - } while (ret==Z_OK); - - lSizeCpr=zcpr.total_out; - deflateEnd(&zcpr); - dwGetTick=GetTickCount()-dwGetTick; - dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); - dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); - printf("total compress size = %u, in %u step\n",lSizeCpr,step); - printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); - printf("defcpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); - printf("defcpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); - } - - CprPtr=(unsigned char*)realloc(CprPtr,lSizeCpr); - UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress); - - BeginCountPerfCounter(&li_qp,TRUE); - dwGetTick=GetTickCount(); - BeginCountRdtsc(&li_rdtsc); - { - z_stream zcpr; - int ret=Z_OK; - long lOrigToDo = lSizeCpr; - long lOrigDone = 0; - int step=0; - memset(&zcpr,0,sizeof(z_stream)); - inflateInit(&zcpr); - - zcpr.next_in = CprPtr; - zcpr.next_out = UncprPtr; - - - do - { - long all_read_before = zcpr.total_in; - zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress); - zcpr.avail_out = BlockSizeUncompress; - ret=inflate(&zcpr,Z_SYNC_FLUSH); - lOrigDone += (zcpr.total_in-all_read_before); - lOrigToDo -= (zcpr.total_in-all_read_before); - step++; - } while (ret==Z_OK); - - lSizeUncpr=zcpr.total_out; - inflateEnd(&zcpr); - dwGetTick=GetTickCount()-dwGetTick; - dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); - dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); - printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step); - printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); - printf("uncpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); - printf("uncpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); - } - - if (lSizeUncpr==lFileSize) - { - if (memcmp(FilePtr,UncprPtr,lFileSize)==0) - printf("compare ok\n"); - - } - - return 0; -} +#include +#include +#include + +#include "zlib.h" + + +void MyDoMinus64(LARGE_INTEGER *R,LARGE_INTEGER A,LARGE_INTEGER B) +{ + R->HighPart = A.HighPart - B.HighPart; + if (A.LowPart >= B.LowPart) + R->LowPart = A.LowPart - B.LowPart; + else + { + R->LowPart = A.LowPart - B.LowPart; + R->HighPart --; + } +} + +#ifdef _M_X64 +// see http://msdn2.microsoft.com/library/twchhe95(en-us,vs.80).aspx for __rdtsc +unsigned __int64 __rdtsc(void); +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) +{ + // printf("rdtsc = %I64x\n",__rdtsc()); + pbeginTime64->QuadPart=__rdtsc(); +} + +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) +{ + LARGE_INTEGER LIres; + unsigned _int64 res=__rdtsc()-((unsigned _int64)(beginTime64.QuadPart)); + LIres.QuadPart=res; + // printf("rdtsc = %I64x\n",__rdtsc()); + return LIres; +} +#else +#ifdef _M_IX86 +void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) +{ + DWORD dwEdx,dwEax; + _asm + { + rdtsc + mov dwEax,eax + mov dwEdx,edx + } + pbeginTime64->LowPart=dwEax; + pbeginTime64->HighPart=dwEdx; +} + +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) +{ + myGetRDTSC32(pbeginTime64); +} + +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) +{ + LARGE_INTEGER LIres,endTime64; + myGetRDTSC32(&endTime64); + + LIres.LowPart=LIres.HighPart=0; + MyDoMinus64(&LIres,endTime64,beginTime64); + return LIres; +} +#else +void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) +{ +} + +void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) +{ +} + +LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) +{ + LARGE_INTEGER lr; + lr.QuadPart=0; + return lr; +} +#endif +#endif + +void BeginCountPerfCounter(LARGE_INTEGER * pbeginTime64,BOOL fComputeTimeQueryPerf) +{ + if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(pbeginTime64))) + { + pbeginTime64->LowPart = GetTickCount(); + pbeginTime64->HighPart = 0; + } +} + +DWORD GetMsecSincePerfCounter(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) +{ + LARGE_INTEGER endTime64,ticksPerSecond,ticks; + DWORDLONG ticksShifted,tickSecShifted; + DWORD dwLog=16+0; + DWORD dwRet; + if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(&endTime64))) + dwRet = (GetTickCount() - beginTime64.LowPart)*1; + else + { + MyDoMinus64(&ticks,endTime64,beginTime64); + QueryPerformanceFrequency(&ticksPerSecond); + + + { + ticksShifted = Int64ShrlMod32(*(DWORDLONG*)&ticks,dwLog); + tickSecShifted = Int64ShrlMod32(*(DWORDLONG*)&ticksPerSecond,dwLog); + + } + + dwRet = (DWORD)((((DWORD)ticksShifted)*1000)/(DWORD)(tickSecShifted)); + dwRet *=1; + } + return dwRet; +} + +int ReadFileMemory(const char* filename,long* plFileSize,void** pFilePtr) +{ + FILE* stream; + void* ptr; + int retVal=1; + stream=fopen(filename, "rb"); + if (stream==NULL) + return 0; + + fseek(stream,0,SEEK_END); + + *plFileSize=ftell(stream); + fseek(stream,0,SEEK_SET); + ptr=malloc((*plFileSize)+1); + if (ptr==NULL) + retVal=0; + else + { + if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize)) + retVal=0; + } + fclose(stream); + *pFilePtr=ptr; + return retVal; +} + +int main(int argc, char *argv[]) +{ + int BlockSizeCompress=0x8000; + int BlockSizeUncompress=0x8000; + int cprLevel=Z_DEFAULT_COMPRESSION ; + long lFileSize; + unsigned char* FilePtr; + long lBufferSizeCpr; + long lBufferSizeUncpr; + long lCompressedSize=0; + unsigned char* CprPtr; + unsigned char* UncprPtr; + long lSizeCpr,lSizeUncpr; + DWORD dwGetTick,dwMsecQP; + LARGE_INTEGER li_qp,li_rdtsc,dwResRdtsc; + + if (argc<=1) + { + printf("run TestZlib [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n"); + return 0; + } + + if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0) + { + printf("error reading %s\n",argv[1]); + return 1; + } + else printf("file %s read, %u bytes\n",argv[1],lFileSize); + + if (argc>=3) + BlockSizeCompress=atol(argv[2]); + + if (argc>=4) + BlockSizeUncompress=atol(argv[3]); + + if (argc>=5) + cprLevel=(int)atol(argv[4]); + + lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200; + lBufferSizeUncpr = lBufferSizeCpr; + + CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress); + + BeginCountPerfCounter(&li_qp,TRUE); + dwGetTick=GetTickCount(); + BeginCountRdtsc(&li_rdtsc); + { + z_stream zcpr; + int ret=Z_OK; + long lOrigToDo = lFileSize; + long lOrigDone = 0; + int step=0; + memset(&zcpr,0,sizeof(z_stream)); + deflateInit(&zcpr,cprLevel); + + zcpr.next_in = FilePtr; + zcpr.next_out = CprPtr; + + + do + { + long all_read_before = zcpr.total_in; + zcpr.avail_in = min(lOrigToDo,BlockSizeCompress); + zcpr.avail_out = BlockSizeCompress; + ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH); + lOrigDone += (zcpr.total_in-all_read_before); + lOrigToDo -= (zcpr.total_in-all_read_before); + step++; + } while (ret==Z_OK); + + lSizeCpr=zcpr.total_out; + deflateEnd(&zcpr); + dwGetTick=GetTickCount()-dwGetTick; + dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); + dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); + printf("total compress size = %u, in %u step\n",lSizeCpr,step); + printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); + printf("defcpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); + printf("defcpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); + } + + CprPtr=(unsigned char*)realloc(CprPtr,lSizeCpr); + UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress); + + BeginCountPerfCounter(&li_qp,TRUE); + dwGetTick=GetTickCount(); + BeginCountRdtsc(&li_rdtsc); + { + z_stream zcpr; + int ret=Z_OK; + long lOrigToDo = lSizeCpr; + long lOrigDone = 0; + int step=0; + memset(&zcpr,0,sizeof(z_stream)); + inflateInit(&zcpr); + + zcpr.next_in = CprPtr; + zcpr.next_out = UncprPtr; + + + do + { + long all_read_before = zcpr.total_in; + zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress); + zcpr.avail_out = BlockSizeUncompress; + ret=inflate(&zcpr,Z_SYNC_FLUSH); + lOrigDone += (zcpr.total_in-all_read_before); + lOrigToDo -= (zcpr.total_in-all_read_before); + step++; + } while (ret==Z_OK); + + lSizeUncpr=zcpr.total_out; + inflateEnd(&zcpr); + dwGetTick=GetTickCount()-dwGetTick; + dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); + dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); + printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step); + printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); + printf("uncpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); + printf("uncpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); + } + + if (lSizeUncpr==lFileSize) + { + if (memcmp(FilePtr,UncprPtr,lFileSize)==0) + printf("compare ok\n"); + + } + + return 0; +} diff --git a/3party/zlib/contrib/vstudio/readme.txt b/3party/zlib/contrib/vstudio/readme.txt index 904888ba39..ebe13bf1d8 100644 --- a/3party/zlib/contrib/vstudio/readme.txt +++ b/3party/zlib/contrib/vstudio/readme.txt @@ -1,60 +1,60 @@ -Building instructions for the DLL versions of Zlib 1.2.4 -======================================================== - -This directory contains projects that build zlib and minizip using -Microsoft Visual C++ 9.0/10.0, and Visual C++ . - -You don't need to build these projects yourself. You can download the -binaries from: - http://www.winimage.com/zLibDll - -More information can be found at this site. - -first compile assembly code by running -bld_ml64.bat in contrib\masmx64 -bld_ml32.bat in contrib\masmx86 - - - - -Build instructions for Visual Studio 2008 (32 bits or 64 bits) --------------------------------------------------------------- -- Uncompress current zlib, including all contrib/* files -- Open contrib\vstudio\vc9\zlibvc.sln with Microsoft Visual C++ 2008.0 -- Or run: vcbuild /rebuild contrib\vstudio\vc9\zlibvc.sln "Release|Win32" - -Build instructions for Visual Studio 2010 (32 bits or 64 bits) --------------------------------------------------------------- -- Uncompress current zlib, including all contrib/* files -- Open contrib\vstudio\vc10\zlibvc.sln with Microsoft Visual C++ 2010.0 - - -Important ---------- -- To use zlibwapi.dll in your application, you must define the - macro ZLIB_WINAPI when compiling your application's source files. - - -Additional notes ----------------- -- This DLL, named zlibwapi.dll, is compatible to the old zlib.dll built - by Gilles Vollant from the zlib 1.1.x sources, and distributed at - http://www.winimage.com/zLibDll - It uses the WINAPI calling convention for the exported functions, and - includes the minizip functionality. If your application needs that - particular build of zlib.dll, you can rename zlibwapi.dll to zlib.dll. - -- The new DLL was renamed because there exist several incompatible - versions of zlib.dll on the Internet. - -- There is also an official DLL build of zlib, named zlib1.dll. This one - is exporting the functions using the CDECL convention. See the file - win32\DLL_FAQ.txt found in this zlib distribution. - -- There used to be a ZLIB_DLL macro in zlib 1.1.x, but now this symbol - has a slightly different effect. To avoid compatibility problems, do - not define it here. - - -Gilles Vollant -info@winimage.com +Building instructions for the DLL versions of Zlib 1.2.4 +======================================================== + +This directory contains projects that build zlib and minizip using +Microsoft Visual C++ 9.0/10.0, and Visual C++ . + +You don't need to build these projects yourself. You can download the +binaries from: + http://www.winimage.com/zLibDll + +More information can be found at this site. + +first compile assembly code by running +bld_ml64.bat in contrib\masmx64 +bld_ml32.bat in contrib\masmx86 + + + + +Build instructions for Visual Studio 2008 (32 bits or 64 bits) +-------------------------------------------------------------- +- Uncompress current zlib, including all contrib/* files +- Open contrib\vstudio\vc9\zlibvc.sln with Microsoft Visual C++ 2008.0 +- Or run: vcbuild /rebuild contrib\vstudio\vc9\zlibvc.sln "Release|Win32" + +Build instructions for Visual Studio 2010 (32 bits or 64 bits) +-------------------------------------------------------------- +- Uncompress current zlib, including all contrib/* files +- Open contrib\vstudio\vc10\zlibvc.sln with Microsoft Visual C++ 2010.0 + + +Important +--------- +- To use zlibwapi.dll in your application, you must define the + macro ZLIB_WINAPI when compiling your application's source files. + + +Additional notes +---------------- +- This DLL, named zlibwapi.dll, is compatible to the old zlib.dll built + by Gilles Vollant from the zlib 1.1.x sources, and distributed at + http://www.winimage.com/zLibDll + It uses the WINAPI calling convention for the exported functions, and + includes the minizip functionality. If your application needs that + particular build of zlib.dll, you can rename zlibwapi.dll to zlib.dll. + +- The new DLL was renamed because there exist several incompatible + versions of zlib.dll on the Internet. + +- There is also an official DLL build of zlib, named zlib1.dll. This one + is exporting the functions using the CDECL convention. See the file + win32\DLL_FAQ.txt found in this zlib distribution. + +- There used to be a ZLIB_DLL macro in zlib 1.1.x, but now this symbol + has a slightly different effect. To avoid compatibility problems, do + not define it here. + + +Gilles Vollant +info@winimage.com diff --git a/android/jni/nv_event/nv_event.cpp b/android/jni/nv_event/nv_event.cpp index dfaf5c833d..eb359d2cfa 100644 --- a/android/jni/nv_event/nv_event.cpp +++ b/android/jni/nv_event/nv_event.cpp @@ -1,943 +1,943 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_event\nv_event.cpp -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIAŽ Corporation -// -// 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. -// -//---------------------------------------------------------------------------------- - -#define MODULE "NVEvent" -#define DBG_DETAILED 0 - -#include "nv_event.hpp" - -#include -#include -#include -#include -#include -//#include - -#include "../nv_time/nv_time.hpp" -#include "../nv_thread/nv_thread.hpp" -#include "../nv_debug/nv_debug.hpp" -#include "scoped_profiler.hpp" -#include "nv_keycode_mapping.hpp" -#include "nv_event_queue.hpp" - -// TODO TBD - this should be done in NVTimeInit(), but we use a different -// class than most apps. Need to clean this up, as it is fragile w.r.t. -// changes in nv_time -extern void nvAcquireTimeExtensionJNI(JNIEnv*, jobject); -extern jlong nvGetSystemTimeJNI(JNIEnv*, jobject); - -#define CT_ASSERT(tag,cond) \ -enum { COMPILE_TIME_ASSERT__ ## tag = 1/(cond) } - -enum -{ - // Android lifecycle status flags. Not app-specific - // Set between onCreate and onDestroy - NVEVENT_STATUS_RUNNING = 0x00000001, - // Set between onResume and onPause - NVEVENT_STATUS_ACTIVE = 0x00000002, - // Set between onWindowFocusChanged(true) and (false) - NVEVENT_STATUS_FOCUSED = 0x00000004, - // Set when the app's SurfaceHolder points to a - // valid, nonzero-sized surface - NVEVENT_STATUS_HAS_REAL_SURFACE = 0x00000008, - - // Mask of all app lifecycle status flags, useful for checking when is it - // a reasonable time to be setting up EGL and rendering - NVEVENT_STATUS_INTERACTABLE = 0x0000000f, - - // NvEvent EGL status flags. Not app-specific - // Set between calls to NVEventInitEGL and NVEventCleanupEGL - NVEVENT_STATUS_EGL_INITIALIZED = 0x00000010, - // Set when the EGL surface is allocated - NVEVENT_STATUS_EGL_HAS_SURFACE = 0x00000020, - // Set when a surface and context are available and bound - NVEVENT_STATUS_EGL_BOUND = 0x00000040, -}; - -static unsigned int s_appStatus = 0; - -static void ZeroAppFlags() -{ - s_appStatus = 0; -} - -static void SetAppFlag(unsigned int status) -{ - s_appStatus |= status; -} - -static void ClearAppFlag(unsigned int status) -{ - s_appStatus &= ~status; -} - -static bool QueryAppFlag(unsigned int status) -{ - return (s_appStatus & status) ? true : false; -} - -static bool QueryAppFlagsEqualMasked(unsigned int status, unsigned int mask) -{ - return ((s_appStatus & mask) == status) ? true : false; -} - -static NVKeyCodeMapping s_keyMapping; -static NVEventQueue s_eventQueue; -static jobject s_globalThiz; -static jfieldID s_lengthId; -static jfieldID s_dataId; -static jfieldID s_widthId; -static jfieldID s_heightId; -static jfieldID s_texDataId; -static pthread_t s_mainThread; -static bool s_appThreadExited = false; -static bool s_javaPostedQuit = false; - -static int NVEVENT_ACTION_DOWN = 0; -static int NVEVENT_ACTION_UP = 0; -static int NVEVENT_ACTION_CANCEL = 0; -static int NVEVENT_ACTION_POINTER_INDEX_MASK = 0; -static int NVEVENT_ACTION_POINTER_INDEX_SHIFT = 0; -static int NVEVENT_ACTION_KEY_UP = 0; - -class MethodRef -{ -public: - MethodRef(const char* name, - const char* signature) : - m_name(name), - m_signature(signature), - m_index(NULL) - {} - - bool QueryID(JNIEnv *env, jclass k) - { - m_index = env->GetMethodID(k, m_name, m_signature); - return true; - } - - bool CallBoolean() - { - JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); - - if (!jniEnv || !s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); - return false; - } - if (!m_index) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); - return false; - } -// __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Calling JNI up to %s", m_name); - return jniEnv->CallBooleanMethod(s_globalThiz, m_index); - } - - bool CallInt() - { - JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); - - if (!jniEnv || !s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); - return 0; - } - - if (!m_index) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); - return false; - } - - return (int)jniEnv->CallIntMethod(s_globalThiz, m_index); - } - - void CallVoid() - { - JNIEnv * jniEnv = NVThreadGetCurrentJNIEnv(); - - if (!jniEnv || !s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); - return; - } - - if (!m_index) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); - return; - } - - return jniEnv->CallVoidMethod(s_globalThiz, m_index); - } - - const char* m_name; - const char* m_signature; - jmethodID m_index; - -}; - -static MethodRef s_InitEGL("InitEGL", "()Z"); -static MethodRef s_CleanupEGL("CleanupEGL", "()Z"); -static MethodRef s_CreateSurfaceEGL("CreateSurfaceEGL", "()Z"); -static MethodRef s_DestroySurfaceEGL("DestroySurfaceEGL", "()Z"); -static MethodRef s_SwapBuffersEGL("SwapBuffersEGL", "()Z"); -static MethodRef s_BindSurfaceAndContextEGL("BindSurfaceAndContextEGL", "()Z"); -static MethodRef s_UnbindSurfaceAndContextEGL("UnbindSurfaceAndContextEGL", "()Z"); -static MethodRef s_GetErrorEGL("GetErrorEGL", "()I"); -static MethodRef s_finish("finish", "()V"); -static MethodRef s_ReportUnsupported("ReportUnsupported", "()V"); -static MethodRef s_OnRenderingInitialized("OnRenderingInitialized", "()V"); - -// True between onCreate and onDestroy -bool NVEventStatusIsRunning() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_RUNNING); -} - -// True between onResume and onPause -bool NVEventStatusIsActive() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_ACTIVE); -} - -// True between onWindowFocusChanged(true) and (false) -bool NVEventStatusIsFocused() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_FOCUSED); -} - -// True when the app's SurfaceHolder points to a -// valid, nonzero-sized window -bool NVEventStatusHasRealSurface() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); -} - -// True when all of IsRunning, IsActive, IsFocused, HasRealSurface are true -// useful for checking when is it a reasonable time to be setting up EGL and rendering -bool NVEventStatusIsInteractable() -{ - // TBD - need to lock a mutex? - return QueryAppFlagsEqualMasked(NVEVENT_STATUS_INTERACTABLE, NVEVENT_STATUS_INTERACTABLE); -} - -// True between calls to NVEventInitEGL and NVEventCleanupEGL -bool NVEventStatusEGLInitialized() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); -} - -// True when the EGL surface is allocated -bool NVEventStatusEGLHasSurface() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); -} - -// True when a surface and context are available and bound -bool NVEventStatusEGLIsBound() -{ - // TBD - need to lock a mutex? - return QueryAppFlag(NVEVENT_STATUS_EGL_BOUND); -} - -static void NVEventInitInputFields(JNIEnv *env) -{ - jclass Motion_class = env->FindClass("android/view/MotionEvent"); - jfieldID ACTION_DOWN_id = env->GetStaticFieldID(Motion_class, "ACTION_DOWN", "I"); - jfieldID ACTION_UP_id = env->GetStaticFieldID(Motion_class, "ACTION_UP", "I"); - jfieldID ACTION_CANCEL_id = env->GetStaticFieldID(Motion_class, "ACTION_CANCEL", "I"); - jfieldID ACTION_POINTER_INDEX_SHIFT_id = env->GetStaticFieldID(Motion_class, "ACTION_POINTER_ID_SHIFT", "I"); - jfieldID ACTION_POINTER_INDEX_MASK_id = env->GetStaticFieldID(Motion_class, "ACTION_POINTER_ID_MASK", "I"); - NVEVENT_ACTION_DOWN = env->GetStaticIntField(Motion_class, ACTION_DOWN_id); - NVEVENT_ACTION_UP = env->GetStaticIntField(Motion_class, ACTION_UP_id); - NVEVENT_ACTION_CANCEL = env->GetStaticIntField(Motion_class, ACTION_CANCEL_id); - NVEVENT_ACTION_POINTER_INDEX_MASK = env->GetStaticIntField(Motion_class, ACTION_POINTER_INDEX_MASK_id); - NVEVENT_ACTION_POINTER_INDEX_SHIFT = env->GetStaticIntField(Motion_class, ACTION_POINTER_INDEX_SHIFT_id); - - jclass KeyCode_class = env->FindClass("android/view/KeyEvent"); - jfieldID ACTION_KEY_UP_id = env->GetStaticFieldID(KeyCode_class, "ACTION_UP", "I"); - NVEVENT_ACTION_KEY_UP = env->GetStaticIntField(KeyCode_class, ACTION_KEY_UP_id); -} - -static void* NVEventMainLoopThreadFunc(void*) -{ - NVEventAppMain(0, NULL); - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "NvEvent native app Main returned"); - - // signal the condition variable to unblock - // java from waiting on pause or quit - s_eventQueue.UnblockProducer(); - - s_appThreadExited = true; - - // IF that app main returned because we posted a QUIT, then Java knows what to - // do regarding lifecycle. But, if the app returned from main of its own accord, - // we need to call finish. - if (!s_javaPostedQuit) - { - JNIEnv* env = NVThreadGetCurrentJNIEnv(); - env->CallVoidMethod(s_globalThiz, s_finish.m_index); - } - - return NULL; -} - -NVEventPlatformAppHandle NVEventGetPlatformAppHandle() -{ - return s_globalThiz; -} - -/////////////////////////////////////////////////////////////////////////////// -// Native event-handling functions - -const char* NVEventGetEventStr(NVEventType eventType) -{ - switch(eventType) - { - case NV_EVENT_KEY: return "NV_EVENT_KEY"; - case NV_EVENT_CHAR: return "NV_EVENT_CHAR"; - case NV_EVENT_TOUCH: return "NV_EVENT_TOUCH"; - case NV_EVENT_MULTITOUCH: return "NV_EVENT_MULTITOUCH"; - case NV_EVENT_ACCEL: return "NV_EVENT_ACCEL"; - case NV_EVENT_START: return "NV_EVENT_START"; - case NV_EVENT_RESTART: return "NV_EVENT_RESTART"; - case NV_EVENT_RESUME: return "NV_EVENT_RESUME"; - case NV_EVENT_FOCUS_GAINED: return "NV_EVENT_FOCUS_GAINED"; - case NV_EVENT_SURFACE_CREATED: return "NV_EVENT_SURFACE_CREATED"; - case NV_EVENT_SURFACE_SIZE: return "NV_EVENT_SURFACE_SIZE"; - case NV_EVENT_SURFACE_DESTROYED: return "NV_EVENT_SURFACE_DESTROYED"; - case NV_EVENT_FOCUS_LOST: return "NV_EVENT_FOCUS_LOST"; - case NV_EVENT_PAUSE: return "NV_EVENT_PAUSE"; - case NV_EVENT_STOP: return "NV_EVENT_STOP"; - case NV_EVENT_QUIT: return "NV_EVENT_QUIT"; - case NV_EVENT_USER: return "NV_EVENT_USER"; - case NV_EVENT_LONG_CLICK: return "NV_EVENT_LONG_CLICK"; - } - - // update this if you end up having to edit something. - CT_ASSERT(NEED_TO_ADD_STRING_HERE, NV_EVENT_NUM_EVENTS == 18); - return "unknown event type!"; -} - -const NVEvent* NVEventGetNextEvent(int waitMSecs) -{ - return s_eventQueue.RemoveOldest(waitMSecs); -} - -void NVEventDoneWithEvent(bool handled) -{ - return s_eventQueue.DoneWithEvent(handled); -} - -static void NVEventInsert(NVEvent* ev) -{ - if(!s_appThreadExited) - s_eventQueue.Insert(ev); -} - -static bool NVEventInsertBlocking(NVEvent* ev) -{ - if(!s_appThreadExited) - return s_eventQueue.InsertBlocking(ev); - - return false; -} - -/////////////////////////////////////////////////////////////////////////////// -// Native to Java EGL call-up functions - -bool NVEventInitEGL() -{ - if(s_InitEGL.CallBoolean()) - { - SetAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); - return true; - } - else - return false; -} - -bool NVEventCleanupEGL() -{ - ClearAppFlag(NVEVENT_STATUS_EGL_BOUND); - ClearAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); - ClearAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); - return s_CleanupEGL.CallBoolean(); -} - -bool NVEventCreateSurfaceEGL() -{ - if (s_CreateSurfaceEGL.CallBoolean()) - { - SetAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); - return true; - } - else - return false; -} - -bool NVEventDestroySurfaceEGL() -{ - if (!QueryAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE)) - return true; - - if (QueryAppFlag(NVEVENT_STATUS_EGL_BOUND)) - NVEventUnbindSurfaceAndContextEGL(); - - ClearAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); - return s_DestroySurfaceEGL.CallBoolean(); -} - -bool NVEventBindSurfaceAndContextEGL() -{ - if (s_BindSurfaceAndContextEGL.CallBoolean()) - { - SetAppFlag(NVEVENT_STATUS_EGL_BOUND); - return true; - } - else - return false; -} - -bool NVEventUnbindSurfaceAndContextEGL() -{ - ClearAppFlag(NVEVENT_STATUS_EGL_BOUND); - return s_UnbindSurfaceAndContextEGL.CallBoolean(); -} - -bool NVEventSwapBuffersEGL() -{ - if (!s_SwapBuffersEGL.CallBoolean()) - return false; - RESET_PROFILING(); - return true; -} - -int NVEventGetErrorEGL() -{ - return s_GetErrorEGL.CallInt(); -} - -bool NVEventReadyToRenderEGL(bool allocateIfNeeded) -{ - // If we have a bound context and surface, then EGL is ready - if (!NVEventStatusEGLIsBound()) - { - if (!allocateIfNeeded) - return false; - - // If we have not bound the context and surface, do we even _have_ a surface? - if (!NVEventStatusEGLHasSurface()) - { - // No surface, so we need to check if EGL is set up at all - if (!NVEventStatusEGLInitialized()) - { - if (!NVEventInitEGL()) - return false; - } - - // Create the rendering surface now that we have a context - if (!NVEventCreateSurfaceEGL()) - return false; - - } - - // We have a surface and context, so bind them - if (NVEventBindSurfaceAndContextEGL()) - return false; - } - - return true; -} - -bool NVEventRepaint() -{ - NVEvent ev; - ev.m_type = NV_EVENT_USER; - ev.m_data.m_user.m_u0 = 1; - NVEventInsert(&ev); - - return true; -} - -void NVEventReportUnsupported() -{ - /// to prevent from rendering - ClearAppFlag(NVEVENT_STATUS_FOCUSED); - s_ReportUnsupported.CallVoid(); -} - -void NVEventOnRenderingInitialized() -{ - s_OnRenderingInitialized.CallVoid(); -} - -/////////////////////////////////////////////////////////////////////////////// -// Input event-related Java to Native callback functions - -static jboolean NVEventTouchEvent(JNIEnv* env, jobject thiz, jint action, jint mx, jint my) -{ - { - NVEvent ev; - ev.m_type = NV_EVENT_TOUCH; - ev.m_data.m_touch.m_action = (NVEVENT_ACTION_UP == action) - ? NV_TOUCHACTION_UP : ( - (NVEVENT_ACTION_DOWN == action) ? NV_TOUCHACTION_DOWN : NV_TOUCHACTION_MOVE); - ev.m_data.m_touch.m_x = mx; - ev.m_data.m_touch.m_y = my; - NVEventInsert(&ev); - } - - return JNI_TRUE; -} - -static jboolean NVEventLongClickEvent(JNIEnv * env, jobject thiz, jint x, jint y) -{ - NVEvent ev; - ev.m_type = NV_EVENT_LONG_CLICK; - ev.m_data.m_multi.m_x1 = x; - ev.m_data.m_multi.m_y1 = y; - NVEventInsert(&ev); - return JNI_TRUE; -} - -static jboolean NVEventMultiTouchEvent(JNIEnv* env, jobject thiz, jint action, - jboolean hasFirst, jboolean hasSecond, jint mx1, jint my1, jint mx2, jint my2) -{ - { - NVEvent ev; - - int actionOnly = action & (~NVEVENT_ACTION_POINTER_INDEX_MASK); - - int maskOnly = 0; - - if (hasFirst) - maskOnly |= 0x1; - if (hasSecond) - maskOnly |= 0x2; - - ev.m_type = NV_EVENT_MULTITOUCH; - - if (actionOnly == NVEVENT_ACTION_UP) - { - ev.m_data.m_multi.m_action = NV_MULTITOUCH_UP; - } - else if (actionOnly == NVEVENT_ACTION_DOWN) - { - ev.m_data.m_multi.m_action = NV_MULTITOUCH_DOWN; - } - else if (actionOnly == NVEVENT_ACTION_CANCEL) - { - ev.m_data.m_multi.m_action = NV_MULTITOUCH_CANCEL; - } - else - { - ev.m_data.m_multi.m_action = NV_MULTITOUCH_MOVE; - } - ev.m_data.m_multi.m_action = - (NVMultiTouchEventType)(ev.m_data.m_multi.m_action | (maskOnly << NV_MULTITOUCH_POINTER_SHIFT)); - ev.m_data.m_multi.m_x1 = mx1; - ev.m_data.m_multi.m_y1 = my1; - ev.m_data.m_multi.m_x2 = mx2; - ev.m_data.m_multi.m_y2 = my2; - NVEventInsert(&ev); - } - - return JNI_TRUE; -} - -static jboolean NVEventKeyEvent(JNIEnv* env, jobject thiz, jint action, jint keycode, jint unichar) -{ - // TBD - remove these or make them resettable for safety... - static int lastKeyAction = 0; - static int lastKeyCode = 0; - bool ret = false; - - NVKeyCode code = NV_KEYCODE_NULL; - - if (s_keyMapping.MapKey((int)keycode, code)) - { - if ((code != NV_KEYCODE_NULL) && - ((code != lastKeyCode) || (action != lastKeyAction))) - { - NVEvent ev; - ev.m_type = NV_EVENT_KEY; - ev.m_data.m_key.m_action = (NVEVENT_ACTION_UP == action) - ? NV_KEYACTION_UP : NV_KEYACTION_DOWN; - ev.m_data.m_key.m_code = code; - ret = NVEventInsertBlocking(&ev); - } - - lastKeyAction = action; - lastKeyCode = code; - } - - if (unichar && (NVEVENT_ACTION_UP != action)) - { - NVEvent ev; - ev.m_type = NV_EVENT_CHAR; - ev.m_data.m_char.m_unichar = unichar; - NVEventInsert(&ev); - } - - return ret; -} - -static jboolean NVEventAccelerometerEvent(JNIEnv* env, jobject thiz, jfloat values0, jfloat values1, jfloat values2) -{ - NVEvent ev; - ev.m_type = NV_EVENT_ACCEL; - ev.m_data.m_accel.m_x = values0; - ev.m_data.m_accel.m_y = values1; - ev.m_data.m_accel.m_z = values2; - NVEventInsert(&ev); - return JNI_TRUE; -} - -/////////////////////////////////////////////////////////////////////////////// -// Java to Native app lifecycle callback functions - -static jboolean onDestroyNative(JNIEnv* env, jobject thiz); - - - -static jboolean onCreateNative(JNIEnv* env, jobject thiz) -{ - if (s_globalThiz) - onDestroyNative(env, thiz); - - ZeroAppFlags(); - - if (!s_globalThiz) - { - s_globalThiz = env->NewGlobalRef(thiz); - if (!s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: Thiz NewGlobalRef failed!"); - } - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Thiz NewGlobalRef: 0x%p", s_globalThiz); - } - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Init KeyCode Map"); - s_keyMapping.Init(env, thiz); - - NVEventInitInputFields(env); - - s_eventQueue.Init(); - - s_javaPostedQuit = false; - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Calling NVEventAppInit"); - - if (NVEventAppInit(0, NULL)) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "NVEventAppInit error"); - return JNI_FALSE; - } - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "spawning thread"); - - s_appThreadExited = false; - SetAppFlag(NVEVENT_STATUS_RUNNING); - - /* Launch thread with main loop */ - NVThreadSpawnJNIThread(&s_mainThread, NULL, NVEventMainLoopThreadFunc, NULL); - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "thread spawned"); - - return JNI_TRUE; -} - -static jboolean onStartNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_START; - return NVEventInsertBlocking(&ev); -} - -static jboolean onRestartNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_RESTART; - return NVEventInsertBlocking(&ev); -} - -static jboolean onResumeNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_RESUME; - SetAppFlag(NVEVENT_STATUS_ACTIVE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onSurfaceCreatedNative(JNIEnv* env, jobject thiz, int w, int h, int density) -{ - NVEvent ev; - ev.m_type = NV_EVENT_SURFACE_CREATED; - ev.m_data.m_size.m_w = w; - ev.m_data.m_size.m_h = h; - ev.m_data.m_size.m_density = density; - if ((w > 0) && (h > 0)) - SetAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - else - ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onFocusChangedNative(JNIEnv* env, jobject thiz, jboolean focused) -{ - NVEvent ev; - ev.m_type = (focused == JNI_TRUE) ? NV_EVENT_FOCUS_GAINED : NV_EVENT_FOCUS_LOST; - if (focused) - SetAppFlag(NVEVENT_STATUS_FOCUSED); - else - ClearAppFlag(NVEVENT_STATUS_FOCUSED); - return NVEventInsertBlocking(&ev); -} - -static jboolean onSurfaceChangedNative(JNIEnv* env, jobject thiz, int w, int h, int density) -{ - NVEvent ev; - ev.m_type = NV_EVENT_SURFACE_SIZE; - ev.m_data.m_size.m_w = w; - ev.m_data.m_size.m_h = h; - ev.m_data.m_size.m_density = density; - if (w * h) - SetAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - else - ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onSurfaceDestroyedNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_SURFACE_DESTROYED; - ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onPauseNative(JNIEnv* env, jobject thiz) -{ - // TODO: we could selectively flush here to - // improve responsiveness to the pause - s_eventQueue.Flush(); - NVEvent ev; - ev.m_type = NV_EVENT_PAUSE; - ClearAppFlag(NVEVENT_STATUS_ACTIVE); - return NVEventInsertBlocking(&ev); -} - -static jboolean onStopNative(JNIEnv* env, jobject thiz) -{ - NVEvent ev; - ev.m_type = NV_EVENT_STOP; - return NVEventInsertBlocking(&ev); -} - -static jboolean onDestroyNative(JNIEnv* env, jobject thiz) -{ - if (!env || !s_globalThiz) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: DestroyingRegisteredObjectInstance no TLS data!"); - } - - if (!s_appThreadExited) - { - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Posting quit event"); - - // flush ALL events - s_eventQueue.Flush(); - - NVEvent ev; - ev.m_type = NV_EVENT_QUIT; - ClearAppFlag(NVEVENT_STATUS_RUNNING); - - // We're posting quit, so we need to mark that; when the main loop - // thread exits, we check this flag to ensure that we only call "finish" - // if the app returned of its own accord, not if we posted it - s_javaPostedQuit = true; - NVEventInsert(&ev); - - // ensure that the native side - // isn't blocked waiting for an event -- since we've flushed - // all the events save quit, we must artificially unblock native - s_eventQueue.UnblockConsumer(); - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Waiting for main loop exit"); - pthread_join(s_mainThread, NULL); - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Main loop exited"); - } - - env->DeleteGlobalRef(s_globalThiz); - s_globalThiz = NULL; - - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Released global thiz!"); - - s_eventQueue.Shutdown(); - - return JNI_TRUE; -} - -static jboolean postUserEvent(JNIEnv* env, jobject thiz, - jint u0, jint u1, jint u2, jint u3, - jboolean blocking) -{ - NVEvent ev; - ev.m_type = NV_EVENT_USER; - ev.m_data.m_user.m_u0 = u0; - ev.m_data.m_user.m_u1 = u1; - ev.m_data.m_user.m_u2 = u2; - ev.m_data.m_user.m_u3 = u3; - if (blocking == JNI_TRUE) - { - return NVEventInsertBlocking(&ev); - } - else - { - NVEventInsert(&ev); - return true; - } -} - -/////////////////////////////////////////////////////////////////////////////// -// File and APK handling functions - -char* NVEventLoadFile(const char* file) -{ - __android_log_print(ANDROID_LOG_DEBUG, MODULE, "loadFile is not implemented"); - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// JVM Initialization functions - -void InitNVEvent(JavaVM* vm) -{ - JNIEnv *env; - - NVThreadInit(vm); - - NVDEBUG("InitNVEvent called"); - - if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) - { - NVDEBUG("Failed to get the environment using GetEnv()"); - return; - } - - JNINativeMethod methods[] = - { - { - "onCreateNative", - "()Z", - (void *) onCreateNative - }, - { - "onStartNative", - "()Z", - (void *) onStartNative - }, - { - "onRestartNative", - "()Z", - (void *) onRestartNative - }, - { - "onResumeNative", - "()Z", - (void *) onResumeNative - }, - { - "onSurfaceCreatedNative", - "(III)Z", - (void *) onSurfaceCreatedNative - }, - { - "onFocusChangedNative", - "(Z)Z", - (void *) onFocusChangedNative - }, - { - "onSurfaceChangedNative", - "(III)Z", - (void *) onSurfaceChangedNative - }, - { - "onSurfaceDestroyedNative", - "()Z", - (void *) onSurfaceDestroyedNative - }, - { - "onPauseNative", - "()Z", - (void *) onPauseNative - }, - { - "onStopNative", - "()Z", - (void *) onStopNative - }, - { - "onDestroyNative", - "()Z", - (void *) onDestroyNative - }, - { - "multiTouchEvent", - "(IZZIIIILandroid/view/MotionEvent;)Z", - (void *) NVEventMultiTouchEvent - }/*, - { - "onLongClickNative", - "(II)Z", - (void *) NVEventLongClickEvent - }*/ - }; - - jclass k; - k = (env)->FindClass ("com/nvidia/devtech/NvEventQueueActivity"); - (env)->RegisterNatives(k, methods, dimof(methods)); - - s_InitEGL.QueryID(env, k); - s_CleanupEGL.QueryID(env, k); - s_CreateSurfaceEGL.QueryID(env, k); - s_DestroySurfaceEGL.QueryID(env, k); - s_SwapBuffersEGL.QueryID(env, k); - s_BindSurfaceAndContextEGL.QueryID(env, k); - s_UnbindSurfaceAndContextEGL.QueryID(env, k); - s_GetErrorEGL.QueryID(env, k); - s_finish.QueryID(env, k); - s_ReportUnsupported.QueryID(env, k); - s_OnRenderingInitialized.QueryID(env, k); -} - +//---------------------------------------------------------------------------------- +// File: libs\jni\nv_event\nv_event.cpp +// Samples Version: NVIDIA Android Lifecycle samples 1_0beta +// Email: tegradev@nvidia.com +// Web: http://developer.nvidia.com/category/zone/mobile-development +// +// Copyright 2009-2011 NVIDIAŽ Corporation +// +// 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. +// +//---------------------------------------------------------------------------------- + +#define MODULE "NVEvent" +#define DBG_DETAILED 0 + +#include "nv_event.hpp" + +#include +#include +#include +#include +#include +//#include + +#include "../nv_time/nv_time.hpp" +#include "../nv_thread/nv_thread.hpp" +#include "../nv_debug/nv_debug.hpp" +#include "scoped_profiler.hpp" +#include "nv_keycode_mapping.hpp" +#include "nv_event_queue.hpp" + +// TODO TBD - this should be done in NVTimeInit(), but we use a different +// class than most apps. Need to clean this up, as it is fragile w.r.t. +// changes in nv_time +extern void nvAcquireTimeExtensionJNI(JNIEnv*, jobject); +extern jlong nvGetSystemTimeJNI(JNIEnv*, jobject); + +#define CT_ASSERT(tag,cond) \ +enum { COMPILE_TIME_ASSERT__ ## tag = 1/(cond) } + +enum +{ + // Android lifecycle status flags. Not app-specific + // Set between onCreate and onDestroy + NVEVENT_STATUS_RUNNING = 0x00000001, + // Set between onResume and onPause + NVEVENT_STATUS_ACTIVE = 0x00000002, + // Set between onWindowFocusChanged(true) and (false) + NVEVENT_STATUS_FOCUSED = 0x00000004, + // Set when the app's SurfaceHolder points to a + // valid, nonzero-sized surface + NVEVENT_STATUS_HAS_REAL_SURFACE = 0x00000008, + + // Mask of all app lifecycle status flags, useful for checking when is it + // a reasonable time to be setting up EGL and rendering + NVEVENT_STATUS_INTERACTABLE = 0x0000000f, + + // NvEvent EGL status flags. Not app-specific + // Set between calls to NVEventInitEGL and NVEventCleanupEGL + NVEVENT_STATUS_EGL_INITIALIZED = 0x00000010, + // Set when the EGL surface is allocated + NVEVENT_STATUS_EGL_HAS_SURFACE = 0x00000020, + // Set when a surface and context are available and bound + NVEVENT_STATUS_EGL_BOUND = 0x00000040, +}; + +static unsigned int s_appStatus = 0; + +static void ZeroAppFlags() +{ + s_appStatus = 0; +} + +static void SetAppFlag(unsigned int status) +{ + s_appStatus |= status; +} + +static void ClearAppFlag(unsigned int status) +{ + s_appStatus &= ~status; +} + +static bool QueryAppFlag(unsigned int status) +{ + return (s_appStatus & status) ? true : false; +} + +static bool QueryAppFlagsEqualMasked(unsigned int status, unsigned int mask) +{ + return ((s_appStatus & mask) == status) ? true : false; +} + +static NVKeyCodeMapping s_keyMapping; +static NVEventQueue s_eventQueue; +static jobject s_globalThiz; +static jfieldID s_lengthId; +static jfieldID s_dataId; +static jfieldID s_widthId; +static jfieldID s_heightId; +static jfieldID s_texDataId; +static pthread_t s_mainThread; +static bool s_appThreadExited = false; +static bool s_javaPostedQuit = false; + +static int NVEVENT_ACTION_DOWN = 0; +static int NVEVENT_ACTION_UP = 0; +static int NVEVENT_ACTION_CANCEL = 0; +static int NVEVENT_ACTION_POINTER_INDEX_MASK = 0; +static int NVEVENT_ACTION_POINTER_INDEX_SHIFT = 0; +static int NVEVENT_ACTION_KEY_UP = 0; + +class MethodRef +{ +public: + MethodRef(const char* name, + const char* signature) : + m_name(name), + m_signature(signature), + m_index(NULL) + {} + + bool QueryID(JNIEnv *env, jclass k) + { + m_index = env->GetMethodID(k, m_name, m_signature); + return true; + } + + bool CallBoolean() + { + JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); + + if (!jniEnv || !s_globalThiz) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); + return false; + } + if (!m_index) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); + return false; + } +// __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Calling JNI up to %s", m_name); + return jniEnv->CallBooleanMethod(s_globalThiz, m_index); + } + + bool CallInt() + { + JNIEnv* jniEnv = NVThreadGetCurrentJNIEnv(); + + if (!jniEnv || !s_globalThiz) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); + return 0; + } + + if (!m_index) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); + return false; + } + + return (int)jniEnv->CallIntMethod(s_globalThiz, m_index); + } + + void CallVoid() + { + JNIEnv * jniEnv = NVThreadGetCurrentJNIEnv(); + + if (!jniEnv || !s_globalThiz) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid JNI env in %s", m_name); + return; + } + + if (!m_index) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: No valid function pointer in %s", m_name); + return; + } + + return jniEnv->CallVoidMethod(s_globalThiz, m_index); + } + + const char* m_name; + const char* m_signature; + jmethodID m_index; + +}; + +static MethodRef s_InitEGL("InitEGL", "()Z"); +static MethodRef s_CleanupEGL("CleanupEGL", "()Z"); +static MethodRef s_CreateSurfaceEGL("CreateSurfaceEGL", "()Z"); +static MethodRef s_DestroySurfaceEGL("DestroySurfaceEGL", "()Z"); +static MethodRef s_SwapBuffersEGL("SwapBuffersEGL", "()Z"); +static MethodRef s_BindSurfaceAndContextEGL("BindSurfaceAndContextEGL", "()Z"); +static MethodRef s_UnbindSurfaceAndContextEGL("UnbindSurfaceAndContextEGL", "()Z"); +static MethodRef s_GetErrorEGL("GetErrorEGL", "()I"); +static MethodRef s_finish("finish", "()V"); +static MethodRef s_ReportUnsupported("ReportUnsupported", "()V"); +static MethodRef s_OnRenderingInitialized("OnRenderingInitialized", "()V"); + +// True between onCreate and onDestroy +bool NVEventStatusIsRunning() +{ + // TBD - need to lock a mutex? + return QueryAppFlag(NVEVENT_STATUS_RUNNING); +} + +// True between onResume and onPause +bool NVEventStatusIsActive() +{ + // TBD - need to lock a mutex? + return QueryAppFlag(NVEVENT_STATUS_ACTIVE); +} + +// True between onWindowFocusChanged(true) and (false) +bool NVEventStatusIsFocused() +{ + // TBD - need to lock a mutex? + return QueryAppFlag(NVEVENT_STATUS_FOCUSED); +} + +// True when the app's SurfaceHolder points to a +// valid, nonzero-sized window +bool NVEventStatusHasRealSurface() +{ + // TBD - need to lock a mutex? + return QueryAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); +} + +// True when all of IsRunning, IsActive, IsFocused, HasRealSurface are true +// useful for checking when is it a reasonable time to be setting up EGL and rendering +bool NVEventStatusIsInteractable() +{ + // TBD - need to lock a mutex? + return QueryAppFlagsEqualMasked(NVEVENT_STATUS_INTERACTABLE, NVEVENT_STATUS_INTERACTABLE); +} + +// True between calls to NVEventInitEGL and NVEventCleanupEGL +bool NVEventStatusEGLInitialized() +{ + // TBD - need to lock a mutex? + return QueryAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); +} + +// True when the EGL surface is allocated +bool NVEventStatusEGLHasSurface() +{ + // TBD - need to lock a mutex? + return QueryAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); +} + +// True when a surface and context are available and bound +bool NVEventStatusEGLIsBound() +{ + // TBD - need to lock a mutex? + return QueryAppFlag(NVEVENT_STATUS_EGL_BOUND); +} + +static void NVEventInitInputFields(JNIEnv *env) +{ + jclass Motion_class = env->FindClass("android/view/MotionEvent"); + jfieldID ACTION_DOWN_id = env->GetStaticFieldID(Motion_class, "ACTION_DOWN", "I"); + jfieldID ACTION_UP_id = env->GetStaticFieldID(Motion_class, "ACTION_UP", "I"); + jfieldID ACTION_CANCEL_id = env->GetStaticFieldID(Motion_class, "ACTION_CANCEL", "I"); + jfieldID ACTION_POINTER_INDEX_SHIFT_id = env->GetStaticFieldID(Motion_class, "ACTION_POINTER_ID_SHIFT", "I"); + jfieldID ACTION_POINTER_INDEX_MASK_id = env->GetStaticFieldID(Motion_class, "ACTION_POINTER_ID_MASK", "I"); + NVEVENT_ACTION_DOWN = env->GetStaticIntField(Motion_class, ACTION_DOWN_id); + NVEVENT_ACTION_UP = env->GetStaticIntField(Motion_class, ACTION_UP_id); + NVEVENT_ACTION_CANCEL = env->GetStaticIntField(Motion_class, ACTION_CANCEL_id); + NVEVENT_ACTION_POINTER_INDEX_MASK = env->GetStaticIntField(Motion_class, ACTION_POINTER_INDEX_MASK_id); + NVEVENT_ACTION_POINTER_INDEX_SHIFT = env->GetStaticIntField(Motion_class, ACTION_POINTER_INDEX_SHIFT_id); + + jclass KeyCode_class = env->FindClass("android/view/KeyEvent"); + jfieldID ACTION_KEY_UP_id = env->GetStaticFieldID(KeyCode_class, "ACTION_UP", "I"); + NVEVENT_ACTION_KEY_UP = env->GetStaticIntField(KeyCode_class, ACTION_KEY_UP_id); +} + +static void* NVEventMainLoopThreadFunc(void*) +{ + NVEventAppMain(0, NULL); + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "NvEvent native app Main returned"); + + // signal the condition variable to unblock + // java from waiting on pause or quit + s_eventQueue.UnblockProducer(); + + s_appThreadExited = true; + + // IF that app main returned because we posted a QUIT, then Java knows what to + // do regarding lifecycle. But, if the app returned from main of its own accord, + // we need to call finish. + if (!s_javaPostedQuit) + { + JNIEnv* env = NVThreadGetCurrentJNIEnv(); + env->CallVoidMethod(s_globalThiz, s_finish.m_index); + } + + return NULL; +} + +NVEventPlatformAppHandle NVEventGetPlatformAppHandle() +{ + return s_globalThiz; +} + +/////////////////////////////////////////////////////////////////////////////// +// Native event-handling functions + +const char* NVEventGetEventStr(NVEventType eventType) +{ + switch(eventType) + { + case NV_EVENT_KEY: return "NV_EVENT_KEY"; + case NV_EVENT_CHAR: return "NV_EVENT_CHAR"; + case NV_EVENT_TOUCH: return "NV_EVENT_TOUCH"; + case NV_EVENT_MULTITOUCH: return "NV_EVENT_MULTITOUCH"; + case NV_EVENT_ACCEL: return "NV_EVENT_ACCEL"; + case NV_EVENT_START: return "NV_EVENT_START"; + case NV_EVENT_RESTART: return "NV_EVENT_RESTART"; + case NV_EVENT_RESUME: return "NV_EVENT_RESUME"; + case NV_EVENT_FOCUS_GAINED: return "NV_EVENT_FOCUS_GAINED"; + case NV_EVENT_SURFACE_CREATED: return "NV_EVENT_SURFACE_CREATED"; + case NV_EVENT_SURFACE_SIZE: return "NV_EVENT_SURFACE_SIZE"; + case NV_EVENT_SURFACE_DESTROYED: return "NV_EVENT_SURFACE_DESTROYED"; + case NV_EVENT_FOCUS_LOST: return "NV_EVENT_FOCUS_LOST"; + case NV_EVENT_PAUSE: return "NV_EVENT_PAUSE"; + case NV_EVENT_STOP: return "NV_EVENT_STOP"; + case NV_EVENT_QUIT: return "NV_EVENT_QUIT"; + case NV_EVENT_USER: return "NV_EVENT_USER"; + case NV_EVENT_LONG_CLICK: return "NV_EVENT_LONG_CLICK"; + } + + // update this if you end up having to edit something. + CT_ASSERT(NEED_TO_ADD_STRING_HERE, NV_EVENT_NUM_EVENTS == 18); + return "unknown event type!"; +} + +const NVEvent* NVEventGetNextEvent(int waitMSecs) +{ + return s_eventQueue.RemoveOldest(waitMSecs); +} + +void NVEventDoneWithEvent(bool handled) +{ + return s_eventQueue.DoneWithEvent(handled); +} + +static void NVEventInsert(NVEvent* ev) +{ + if(!s_appThreadExited) + s_eventQueue.Insert(ev); +} + +static bool NVEventInsertBlocking(NVEvent* ev) +{ + if(!s_appThreadExited) + return s_eventQueue.InsertBlocking(ev); + + return false; +} + +/////////////////////////////////////////////////////////////////////////////// +// Native to Java EGL call-up functions + +bool NVEventInitEGL() +{ + if(s_InitEGL.CallBoolean()) + { + SetAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); + return true; + } + else + return false; +} + +bool NVEventCleanupEGL() +{ + ClearAppFlag(NVEVENT_STATUS_EGL_BOUND); + ClearAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); + ClearAppFlag(NVEVENT_STATUS_EGL_INITIALIZED); + return s_CleanupEGL.CallBoolean(); +} + +bool NVEventCreateSurfaceEGL() +{ + if (s_CreateSurfaceEGL.CallBoolean()) + { + SetAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); + return true; + } + else + return false; +} + +bool NVEventDestroySurfaceEGL() +{ + if (!QueryAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE)) + return true; + + if (QueryAppFlag(NVEVENT_STATUS_EGL_BOUND)) + NVEventUnbindSurfaceAndContextEGL(); + + ClearAppFlag(NVEVENT_STATUS_EGL_HAS_SURFACE); + return s_DestroySurfaceEGL.CallBoolean(); +} + +bool NVEventBindSurfaceAndContextEGL() +{ + if (s_BindSurfaceAndContextEGL.CallBoolean()) + { + SetAppFlag(NVEVENT_STATUS_EGL_BOUND); + return true; + } + else + return false; +} + +bool NVEventUnbindSurfaceAndContextEGL() +{ + ClearAppFlag(NVEVENT_STATUS_EGL_BOUND); + return s_UnbindSurfaceAndContextEGL.CallBoolean(); +} + +bool NVEventSwapBuffersEGL() +{ + if (!s_SwapBuffersEGL.CallBoolean()) + return false; + RESET_PROFILING(); + return true; +} + +int NVEventGetErrorEGL() +{ + return s_GetErrorEGL.CallInt(); +} + +bool NVEventReadyToRenderEGL(bool allocateIfNeeded) +{ + // If we have a bound context and surface, then EGL is ready + if (!NVEventStatusEGLIsBound()) + { + if (!allocateIfNeeded) + return false; + + // If we have not bound the context and surface, do we even _have_ a surface? + if (!NVEventStatusEGLHasSurface()) + { + // No surface, so we need to check if EGL is set up at all + if (!NVEventStatusEGLInitialized()) + { + if (!NVEventInitEGL()) + return false; + } + + // Create the rendering surface now that we have a context + if (!NVEventCreateSurfaceEGL()) + return false; + + } + + // We have a surface and context, so bind them + if (NVEventBindSurfaceAndContextEGL()) + return false; + } + + return true; +} + +bool NVEventRepaint() +{ + NVEvent ev; + ev.m_type = NV_EVENT_USER; + ev.m_data.m_user.m_u0 = 1; + NVEventInsert(&ev); + + return true; +} + +void NVEventReportUnsupported() +{ + /// to prevent from rendering + ClearAppFlag(NVEVENT_STATUS_FOCUSED); + s_ReportUnsupported.CallVoid(); +} + +void NVEventOnRenderingInitialized() +{ + s_OnRenderingInitialized.CallVoid(); +} + +/////////////////////////////////////////////////////////////////////////////// +// Input event-related Java to Native callback functions + +static jboolean NVEventTouchEvent(JNIEnv* env, jobject thiz, jint action, jint mx, jint my) +{ + { + NVEvent ev; + ev.m_type = NV_EVENT_TOUCH; + ev.m_data.m_touch.m_action = (NVEVENT_ACTION_UP == action) + ? NV_TOUCHACTION_UP : ( + (NVEVENT_ACTION_DOWN == action) ? NV_TOUCHACTION_DOWN : NV_TOUCHACTION_MOVE); + ev.m_data.m_touch.m_x = mx; + ev.m_data.m_touch.m_y = my; + NVEventInsert(&ev); + } + + return JNI_TRUE; +} + +static jboolean NVEventLongClickEvent(JNIEnv * env, jobject thiz, jint x, jint y) +{ + NVEvent ev; + ev.m_type = NV_EVENT_LONG_CLICK; + ev.m_data.m_multi.m_x1 = x; + ev.m_data.m_multi.m_y1 = y; + NVEventInsert(&ev); + return JNI_TRUE; +} + +static jboolean NVEventMultiTouchEvent(JNIEnv* env, jobject thiz, jint action, + jboolean hasFirst, jboolean hasSecond, jint mx1, jint my1, jint mx2, jint my2) +{ + { + NVEvent ev; + + int actionOnly = action & (~NVEVENT_ACTION_POINTER_INDEX_MASK); + + int maskOnly = 0; + + if (hasFirst) + maskOnly |= 0x1; + if (hasSecond) + maskOnly |= 0x2; + + ev.m_type = NV_EVENT_MULTITOUCH; + + if (actionOnly == NVEVENT_ACTION_UP) + { + ev.m_data.m_multi.m_action = NV_MULTITOUCH_UP; + } + else if (actionOnly == NVEVENT_ACTION_DOWN) + { + ev.m_data.m_multi.m_action = NV_MULTITOUCH_DOWN; + } + else if (actionOnly == NVEVENT_ACTION_CANCEL) + { + ev.m_data.m_multi.m_action = NV_MULTITOUCH_CANCEL; + } + else + { + ev.m_data.m_multi.m_action = NV_MULTITOUCH_MOVE; + } + ev.m_data.m_multi.m_action = + (NVMultiTouchEventType)(ev.m_data.m_multi.m_action | (maskOnly << NV_MULTITOUCH_POINTER_SHIFT)); + ev.m_data.m_multi.m_x1 = mx1; + ev.m_data.m_multi.m_y1 = my1; + ev.m_data.m_multi.m_x2 = mx2; + ev.m_data.m_multi.m_y2 = my2; + NVEventInsert(&ev); + } + + return JNI_TRUE; +} + +static jboolean NVEventKeyEvent(JNIEnv* env, jobject thiz, jint action, jint keycode, jint unichar) +{ + // TBD - remove these or make them resettable for safety... + static int lastKeyAction = 0; + static int lastKeyCode = 0; + bool ret = false; + + NVKeyCode code = NV_KEYCODE_NULL; + + if (s_keyMapping.MapKey((int)keycode, code)) + { + if ((code != NV_KEYCODE_NULL) && + ((code != lastKeyCode) || (action != lastKeyAction))) + { + NVEvent ev; + ev.m_type = NV_EVENT_KEY; + ev.m_data.m_key.m_action = (NVEVENT_ACTION_UP == action) + ? NV_KEYACTION_UP : NV_KEYACTION_DOWN; + ev.m_data.m_key.m_code = code; + ret = NVEventInsertBlocking(&ev); + } + + lastKeyAction = action; + lastKeyCode = code; + } + + if (unichar && (NVEVENT_ACTION_UP != action)) + { + NVEvent ev; + ev.m_type = NV_EVENT_CHAR; + ev.m_data.m_char.m_unichar = unichar; + NVEventInsert(&ev); + } + + return ret; +} + +static jboolean NVEventAccelerometerEvent(JNIEnv* env, jobject thiz, jfloat values0, jfloat values1, jfloat values2) +{ + NVEvent ev; + ev.m_type = NV_EVENT_ACCEL; + ev.m_data.m_accel.m_x = values0; + ev.m_data.m_accel.m_y = values1; + ev.m_data.m_accel.m_z = values2; + NVEventInsert(&ev); + return JNI_TRUE; +} + +/////////////////////////////////////////////////////////////////////////////// +// Java to Native app lifecycle callback functions + +static jboolean onDestroyNative(JNIEnv* env, jobject thiz); + + + +static jboolean onCreateNative(JNIEnv* env, jobject thiz) +{ + if (s_globalThiz) + onDestroyNative(env, thiz); + + ZeroAppFlags(); + + if (!s_globalThiz) + { + s_globalThiz = env->NewGlobalRef(thiz); + if (!s_globalThiz) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: Thiz NewGlobalRef failed!"); + } + + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Thiz NewGlobalRef: 0x%p", s_globalThiz); + } + + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Init KeyCode Map"); + s_keyMapping.Init(env, thiz); + + NVEventInitInputFields(env); + + s_eventQueue.Init(); + + s_javaPostedQuit = false; + + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Calling NVEventAppInit"); + + if (NVEventAppInit(0, NULL)) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "NVEventAppInit error"); + return JNI_FALSE; + } + + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "spawning thread"); + + s_appThreadExited = false; + SetAppFlag(NVEVENT_STATUS_RUNNING); + + /* Launch thread with main loop */ + NVThreadSpawnJNIThread(&s_mainThread, NULL, NVEventMainLoopThreadFunc, NULL); + + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "thread spawned"); + + return JNI_TRUE; +} + +static jboolean onStartNative(JNIEnv* env, jobject thiz) +{ + NVEvent ev; + ev.m_type = NV_EVENT_START; + return NVEventInsertBlocking(&ev); +} + +static jboolean onRestartNative(JNIEnv* env, jobject thiz) +{ + NVEvent ev; + ev.m_type = NV_EVENT_RESTART; + return NVEventInsertBlocking(&ev); +} + +static jboolean onResumeNative(JNIEnv* env, jobject thiz) +{ + NVEvent ev; + ev.m_type = NV_EVENT_RESUME; + SetAppFlag(NVEVENT_STATUS_ACTIVE); + return NVEventInsertBlocking(&ev); +} + +static jboolean onSurfaceCreatedNative(JNIEnv* env, jobject thiz, int w, int h, int density) +{ + NVEvent ev; + ev.m_type = NV_EVENT_SURFACE_CREATED; + ev.m_data.m_size.m_w = w; + ev.m_data.m_size.m_h = h; + ev.m_data.m_size.m_density = density; + if ((w > 0) && (h > 0)) + SetAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); + else + ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); + return NVEventInsertBlocking(&ev); +} + +static jboolean onFocusChangedNative(JNIEnv* env, jobject thiz, jboolean focused) +{ + NVEvent ev; + ev.m_type = (focused == JNI_TRUE) ? NV_EVENT_FOCUS_GAINED : NV_EVENT_FOCUS_LOST; + if (focused) + SetAppFlag(NVEVENT_STATUS_FOCUSED); + else + ClearAppFlag(NVEVENT_STATUS_FOCUSED); + return NVEventInsertBlocking(&ev); +} + +static jboolean onSurfaceChangedNative(JNIEnv* env, jobject thiz, int w, int h, int density) +{ + NVEvent ev; + ev.m_type = NV_EVENT_SURFACE_SIZE; + ev.m_data.m_size.m_w = w; + ev.m_data.m_size.m_h = h; + ev.m_data.m_size.m_density = density; + if (w * h) + SetAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); + else + ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); + return NVEventInsertBlocking(&ev); +} + +static jboolean onSurfaceDestroyedNative(JNIEnv* env, jobject thiz) +{ + NVEvent ev; + ev.m_type = NV_EVENT_SURFACE_DESTROYED; + ClearAppFlag(NVEVENT_STATUS_HAS_REAL_SURFACE); + return NVEventInsertBlocking(&ev); +} + +static jboolean onPauseNative(JNIEnv* env, jobject thiz) +{ + // TODO: we could selectively flush here to + // improve responsiveness to the pause + s_eventQueue.Flush(); + NVEvent ev; + ev.m_type = NV_EVENT_PAUSE; + ClearAppFlag(NVEVENT_STATUS_ACTIVE); + return NVEventInsertBlocking(&ev); +} + +static jboolean onStopNative(JNIEnv* env, jobject thiz) +{ + NVEvent ev; + ev.m_type = NV_EVENT_STOP; + return NVEventInsertBlocking(&ev); +} + +static jboolean onDestroyNative(JNIEnv* env, jobject thiz) +{ + if (!env || !s_globalThiz) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Error: DestroyingRegisteredObjectInstance no TLS data!"); + } + + if (!s_appThreadExited) + { + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Posting quit event"); + + // flush ALL events + s_eventQueue.Flush(); + + NVEvent ev; + ev.m_type = NV_EVENT_QUIT; + ClearAppFlag(NVEVENT_STATUS_RUNNING); + + // We're posting quit, so we need to mark that; when the main loop + // thread exits, we check this flag to ensure that we only call "finish" + // if the app returned of its own accord, not if we posted it + s_javaPostedQuit = true; + NVEventInsert(&ev); + + // ensure that the native side + // isn't blocked waiting for an event -- since we've flushed + // all the events save quit, we must artificially unblock native + s_eventQueue.UnblockConsumer(); + + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Waiting for main loop exit"); + pthread_join(s_mainThread, NULL); + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Main loop exited"); + } + + env->DeleteGlobalRef(s_globalThiz); + s_globalThiz = NULL; + + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "Released global thiz!"); + + s_eventQueue.Shutdown(); + + return JNI_TRUE; +} + +static jboolean postUserEvent(JNIEnv* env, jobject thiz, + jint u0, jint u1, jint u2, jint u3, + jboolean blocking) +{ + NVEvent ev; + ev.m_type = NV_EVENT_USER; + ev.m_data.m_user.m_u0 = u0; + ev.m_data.m_user.m_u1 = u1; + ev.m_data.m_user.m_u2 = u2; + ev.m_data.m_user.m_u3 = u3; + if (blocking == JNI_TRUE) + { + return NVEventInsertBlocking(&ev); + } + else + { + NVEventInsert(&ev); + return true; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// File and APK handling functions + +char* NVEventLoadFile(const char* file) +{ + __android_log_print(ANDROID_LOG_DEBUG, MODULE, "loadFile is not implemented"); + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// +// JVM Initialization functions + +void InitNVEvent(JavaVM* vm) +{ + JNIEnv *env; + + NVThreadInit(vm); + + NVDEBUG("InitNVEvent called"); + + if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) + { + NVDEBUG("Failed to get the environment using GetEnv()"); + return; + } + + JNINativeMethod methods[] = + { + { + "onCreateNative", + "()Z", + (void *) onCreateNative + }, + { + "onStartNative", + "()Z", + (void *) onStartNative + }, + { + "onRestartNative", + "()Z", + (void *) onRestartNative + }, + { + "onResumeNative", + "()Z", + (void *) onResumeNative + }, + { + "onSurfaceCreatedNative", + "(III)Z", + (void *) onSurfaceCreatedNative + }, + { + "onFocusChangedNative", + "(Z)Z", + (void *) onFocusChangedNative + }, + { + "onSurfaceChangedNative", + "(III)Z", + (void *) onSurfaceChangedNative + }, + { + "onSurfaceDestroyedNative", + "()Z", + (void *) onSurfaceDestroyedNative + }, + { + "onPauseNative", + "()Z", + (void *) onPauseNative + }, + { + "onStopNative", + "()Z", + (void *) onStopNative + }, + { + "onDestroyNative", + "()Z", + (void *) onDestroyNative + }, + { + "multiTouchEvent", + "(IZZIIIILandroid/view/MotionEvent;)Z", + (void *) NVEventMultiTouchEvent + }/*, + { + "onLongClickNative", + "(II)Z", + (void *) NVEventLongClickEvent + }*/ + }; + + jclass k; + k = (env)->FindClass ("com/nvidia/devtech/NvEventQueueActivity"); + (env)->RegisterNatives(k, methods, dimof(methods)); + + s_InitEGL.QueryID(env, k); + s_CleanupEGL.QueryID(env, k); + s_CreateSurfaceEGL.QueryID(env, k); + s_DestroySurfaceEGL.QueryID(env, k); + s_SwapBuffersEGL.QueryID(env, k); + s_BindSurfaceAndContextEGL.QueryID(env, k); + s_UnbindSurfaceAndContextEGL.QueryID(env, k); + s_GetErrorEGL.QueryID(env, k); + s_finish.QueryID(env, k); + s_ReportUnsupported.QueryID(env, k); + s_OnRenderingInitialized.QueryID(env, k); +} + diff --git a/android/jni/nv_event/nv_event_queue.hpp b/android/jni/nv_event/nv_event_queue.hpp index 5b75276e9b..4c08b8ba01 100644 --- a/android/jni/nv_event/nv_event_queue.hpp +++ b/android/jni/nv_event/nv_event_queue.hpp @@ -1,92 +1,92 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_event\nv_event_queue.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIAŽ Corporation -// -// 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 NV_EVENT_QUEUE -#define NV_EVENT_QUEUE - -#include "nv_event.hpp" -#include - -class NVEventSync -{ -public: - pthread_cond_t m_cond; - bool m_block; -}; - -class NVEventQueue { -public: - void Init(); - void Shutdown(); - void Flush(); - void UnblockConsumer(); - void UnblockProducer(); - // Events are copied, so caller can reuse ev immediately - void Insert(const NVEvent* ev); - // Waits until the event is consumed. Returns whether the - // consumer indicates handling the event or ignoring it - bool InsertBlocking(const NVEvent* ev); - - // Returned event is valid only until the next call to - // RemoveOldest or until a call to DoneWithEvent - // Calling RemoveOldest again without calling DoneWithEvent - // indicates that the last event returned was NOT handled, and - // thus InsertNewestAndWait for that even would return false - const NVEvent* RemoveOldest(int waitMSecs); - - // Indicates that all processing of the last event returned - // from RemoveOldest is complete. Also allows the app to indicate - // whether it handled the event or not. - // Do not dereference the last event pointer after calling this function - void DoneWithEvent(bool ret); - -protected: - bool insert(const NVEvent* ev); - - enum { QUEUE_ELEMS = 256 }; - enum { QUEUE_MASK = 0x000000ff }; - - int32_t m_nextInsertIndex; - int32_t m_headIndex; - - pthread_mutex_t m_accessLock; - - NVEventSync m_blockerSync; - NVEventSync m_consumerSync; - - NVEvent m_events[QUEUE_ELEMS]; - const NVEvent* m_blocker; - enum BlockerState - { - NO_BLOCKER, - PENDING_BLOCKER, - PROCESSING_BLOCKER, - RETURNED_BLOCKER - }; - BlockerState m_blockerState; - bool m_blockerReturnVal; -}; - - - - -#endif // #ifndef NV_EVENT_QUEUE +//---------------------------------------------------------------------------------- +// File: libs\jni\nv_event\nv_event_queue.h +// Samples Version: NVIDIA Android Lifecycle samples 1_0beta +// Email: tegradev@nvidia.com +// Web: http://developer.nvidia.com/category/zone/mobile-development +// +// Copyright 2009-2011 NVIDIAŽ Corporation +// +// 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 NV_EVENT_QUEUE +#define NV_EVENT_QUEUE + +#include "nv_event.hpp" +#include + +class NVEventSync +{ +public: + pthread_cond_t m_cond; + bool m_block; +}; + +class NVEventQueue { +public: + void Init(); + void Shutdown(); + void Flush(); + void UnblockConsumer(); + void UnblockProducer(); + // Events are copied, so caller can reuse ev immediately + void Insert(const NVEvent* ev); + // Waits until the event is consumed. Returns whether the + // consumer indicates handling the event or ignoring it + bool InsertBlocking(const NVEvent* ev); + + // Returned event is valid only until the next call to + // RemoveOldest or until a call to DoneWithEvent + // Calling RemoveOldest again without calling DoneWithEvent + // indicates that the last event returned was NOT handled, and + // thus InsertNewestAndWait for that even would return false + const NVEvent* RemoveOldest(int waitMSecs); + + // Indicates that all processing of the last event returned + // from RemoveOldest is complete. Also allows the app to indicate + // whether it handled the event or not. + // Do not dereference the last event pointer after calling this function + void DoneWithEvent(bool ret); + +protected: + bool insert(const NVEvent* ev); + + enum { QUEUE_ELEMS = 256 }; + enum { QUEUE_MASK = 0x000000ff }; + + int32_t m_nextInsertIndex; + int32_t m_headIndex; + + pthread_mutex_t m_accessLock; + + NVEventSync m_blockerSync; + NVEventSync m_consumerSync; + + NVEvent m_events[QUEUE_ELEMS]; + const NVEvent* m_blocker; + enum BlockerState + { + NO_BLOCKER, + PENDING_BLOCKER, + PROCESSING_BLOCKER, + RETURNED_BLOCKER + }; + BlockerState m_blockerState; + bool m_blockerReturnVal; +}; + + + + +#endif // #ifndef NV_EVENT_QUEUE diff --git a/android/jni/nv_time/nv_time.hpp b/android/jni/nv_time/nv_time.hpp index 7f47f35cb4..88a01d2a37 100644 --- a/android/jni/nv_time/nv_time.hpp +++ b/android/jni/nv_time/nv_time.hpp @@ -1,34 +1,34 @@ -//---------------------------------------------------------------------------------- -// File: libs\jni\nv_time\nv_time.h -// Samples Version: NVIDIA Android Lifecycle samples 1_0beta -// Email: tegradev@nvidia.com -// Web: http://developer.nvidia.com/category/zone/mobile-development -// -// Copyright 2009-2011 NVIDIAŽ Corporation -// -// 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 __INCLUDED_NV_TIME_H -#define __INCLUDED_NV_TIME_H - -#include - -void NVTimeInit(); - -void nvAcquireTimeExtension(); -bool nvValidTimeExtension(); -long nvGetSystemTime(); - -#endif +//---------------------------------------------------------------------------------- +// File: libs\jni\nv_time\nv_time.h +// Samples Version: NVIDIA Android Lifecycle samples 1_0beta +// Email: tegradev@nvidia.com +// Web: http://developer.nvidia.com/category/zone/mobile-development +// +// Copyright 2009-2011 NVIDIAŽ Corporation +// +// 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 __INCLUDED_NV_TIME_H +#define __INCLUDED_NV_TIME_H + +#include + +void NVTimeInit(); + +void nvAcquireTimeExtension(); +bool nvValidTimeExtension(); +long nvGetSystemTime(); + +#endif diff --git a/data/styles/symbols/placemark-red.svg b/data/styles/symbols/placemark-red.svg index 60a48888f5..65fc93a68b 100644 --- a/data/styles/symbols/placemark-red.svg +++ b/data/styles/symbols/placemark-red.svg @@ -1,26 +1,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + +