[DEV] first java files for android liveWallpapers

This commit is contained in:
Edouard DUPIN 2013-08-26 21:28:04 +02:00
parent bffa93d136
commit 010586a0fa
12 changed files with 1718 additions and 622 deletions

2
build

@ -1 +1 @@
Subproject commit 6465630a70c8e025f1bfa93cc5b40f16d4dc2e16 Subproject commit d1fe3fe6c3a3e128dc5aa5515980f0367a8c5ab4

2
external/etk vendored

@ -1 +1 @@
Subproject commit 2ad4975a4551f338b2020835c875390c33fc7f0e Subproject commit bb085be53d88d727686a5e23aa7c3e2cb2caf7f5

2
external/exml vendored

@ -1 +1 @@
Subproject commit 0e6c60afb75423ad1450b145e631a4a457e1e7c3 Subproject commit 75ef4d184ade2791d1db3b3d0f40b8ae46aa7f45

View File

@ -9,56 +9,58 @@
package org.ewol; package org.ewol;
import android.app.Activity; import android.app.Activity;
import android.service.wallpaper.WallpaperService;
import android.service.wallpaper.WallpaperService.Engine;
public class Ewol { public class Ewol {
public static final Ewol EWOL = getInstance(); public static final Ewol EWOL = getInstance();
private static Ewol instance = null; private static Ewol instance = null;
/* Default constructor (why not ?)*/
private Ewol() {}
/* Use singleton */
public static Ewol getInstance() {
if(instance == null)
instance = new Ewol();
return instance;
}
public static native <T extends Activity & EwolCallback> void setJavaVirtualMachineStart(T activityInstance);
public static native void setJavaVirtualMachineStop();
public static native void paramSetArchiveDir(int mode, String myString);
public native void touchEvent();
// activity status
public native void onCreate();
public native void onStart();
public native void onReStart();
public native void onResume();
public native void onPause();
public native void onStop();
public native void onDestroy();
// set display properties :
public native void displayPropertyMetrics(float ratioX, float ratioY);
// IO native function :
// Specific for the type of input : TOOL_TYPE_FINGER and TOOL_TYPE_STYLUS (work as the same)
public native void inputEventMotion(int pointerID, float x, float y);
public native void inputEventState(int pointerID, boolean isDown, float x, float y);
// Specific for the type of input : TOOL_TYPE_MOUSE
public native void mouseEventMotion(int pointerID, float x, float y);
public native void mouseEventState(int pointerID, boolean isDown, float x, float y);
// other unknow event ...
public native void unknowEvent(int eventID);
public native void keyboardEventMove(int type, boolean isDown); /* Default constructor (why not ?)*/
public native void keyboardEventKey(int uniChar, boolean isDown); private Ewol() {}
/* Use singleton */
public static Ewol getInstance() {
if(instance == null)
instance = new Ewol();
return instance;
}
// Audio section ... public static native <T extends Activity & EwolCallback> void setJavaVirtualMachineStart(T activityInstance);
public native void audioPlayback(short[] bufferData, int frames, int nbChannels); public static native <T extends Engine & EwolCallback> void setJavaVirtualMachineStartWallpaperEngine(T serviceInstance);
public static native void setJavaVirtualMachineStop();
public static native void paramSetArchiveDir(int mode, String myString);
public native void keyboardEventKeySystem(int keyVal, boolean isDown); public native void touchEvent();
// renderer Event : // activity status
public native void renderInit(); public native void onCreate();
public native void renderResize(int w, int h); public native void onStart();
public native void renderDraw(); public native void onReStart();
public native void onResume();
public native void onPause();
public native void onStop();
public native void onDestroy();
// set display properties :
public native void displayPropertyMetrics(float ratioX, float ratioY);
// IO native function :
// Specific for the type of input : TOOL_TYPE_FINGER and TOOL_TYPE_STYLUS (work as the same)
public native void inputEventMotion(int pointerID, float x, float y);
public native void inputEventState(int pointerID, boolean isDown, float x, float y);
// Specific for the type of input : TOOL_TYPE_MOUSE
public native void mouseEventMotion(int pointerID, float x, float y);
public native void mouseEventState(int pointerID, boolean isDown, float x, float y);
// other unknow event ...
public native void unknowEvent(int eventID);
public native void keyboardEventMove(int type, boolean isDown);
public native void keyboardEventKey(int uniChar, boolean isDown);
// Audio section ...
public native void audioPlayback(short[] bufferData, int frames, int nbChannels);
public native void keyboardEventKeySystem(int keyVal, boolean isDown);
// renderer Event :
public native void renderInit();
public native void renderResize(int w, int h);
public native void renderDraw();
} }

View File

@ -9,8 +9,6 @@
package org.ewol; package org.ewol;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
@ -49,170 +47,170 @@ import static org.ewol.Ewol.EWOL;
*/ */
public abstract class EwolActivity extends Activity implements EwolCallback, EwolConstants{ public abstract class EwolActivity extends Activity implements EwolCallback, EwolConstants{
private EwolSurfaceViewGL mGLView; private EwolSurfaceViewGL mGLView;
private EwolAudioTask mStreams; private EwolAudioTask mStreams;
private Thread mAudioThread; private Thread mAudioThread;
static { static {
System.loadLibrary("ewol"); System.loadLibrary("ewol");
}
protected void initApkPath(String org, String vendor, String project) {
StringBuilder sb = new StringBuilder();
sb.append(org).append(".");
sb.append(vendor).append(".");
sb.append(project);
String apkFilePath = null;
ApplicationInfo appInfo = null;
PackageManager packMgmr = getPackageManager();
try {
appInfo = packMgmr.getApplicationInfo(sb.toString(), 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("Unable to locate assets, aborting...");
} }
apkFilePath = appInfo.sourceDir;
Ewol.paramSetArchiveDir(0, apkFilePath);
}
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// set the java evironement in the C sources :
Ewol.setJavaVirtualMachineStart(this);
// Load the application directory
Ewol.paramSetArchiveDir(1, getFilesDir().toString());
Ewol.paramSetArchiveDir(2, getCacheDir().toString());
// to enable extarnal storage: add in the manifest the restriction needed ...
//packageManager.checkPermission("android.permission.READ_SMS", myPackage) == PERMISSION_GRANTED;
//Ewol.paramSetArchiveDir(3, getExternalCacheDir().toString());
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
EWOL.displayPropertyMetrics(metrics.xdpi, metrics.ydpi);
// call C init ...
EWOL.onCreate();
// Remove the title of the current display :
requestWindowFeature(Window.FEATURE_NO_TITLE);
// set full screen Mode :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// display keyboard:
//getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
// hide keyboard :
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
// create bsurface system
mGLView = new EwolSurfaceViewGL(this, 2);
// create element audio ...
mStreams = new EwolAudioTask();
setContentView(mGLView);
}
@Override protected void onStart()
{
super.onStart();
// call C
EWOL.onStart();
}
@Override protected void onRestart() protected void initApkPath(String org, String vendor, String project) {
{ StringBuilder sb = new StringBuilder();
super.onRestart(); sb.append(org).append(".");
// call C sb.append(vendor).append(".");
EWOL.onReStart(); sb.append(project);
} String apkFilePath = null;
ApplicationInfo appInfo = null;
@Override protected void onResume() PackageManager packMgmr = getPackageManager();
{ try {
super.onResume(); appInfo = packMgmr.getApplicationInfo(sb.toString(), 0);
mGLView.onResume(); } catch (NameNotFoundException e) {
mAudioThread = new Thread(mStreams); e.printStackTrace();
if (mAudioThread != null) { throw new RuntimeException("Unable to locate assets, aborting...");
mAudioThread.start(); }
apkFilePath = appInfo.sourceDir;
Ewol.paramSetArchiveDir(0, apkFilePath);
} }
// call C
EWOL.onResume();
}
@Override protected void onPause() @Override protected void onCreate(Bundle savedInstanceState)
{ {
super.onPause(); super.onCreate(savedInstanceState);
mGLView.onPause();
if (mAudioThread != null) { // set the java evironement in the C sources :
// request audio stop Ewol.setJavaVirtualMachineStart(this);
mStreams.AutoStop();
// wait the thread ended ... // Load the application directory
try { Ewol.paramSetArchiveDir(1, getFilesDir().toString());
mAudioThread.join(); Ewol.paramSetArchiveDir(2, getCacheDir().toString());
} catch(InterruptedException e) { } // to enable extarnal storage: add in the manifest the restriction needed ...
//packageManager.checkPermission("android.permission.READ_SMS", myPackage) == PERMISSION_GRANTED;
//Ewol.paramSetArchiveDir(3, getExternalCacheDir().toString());
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
EWOL.displayPropertyMetrics(metrics.xdpi, metrics.ydpi);
// call C init ...
EWOL.onCreate();
// Remove the title of the current display :
requestWindowFeature(Window.FEATURE_NO_TITLE);
// set full screen Mode :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// display keyboard:
//getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
// hide keyboard :
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
// create bsurface system
mGLView = new EwolSurfaceViewGL(this, 2);
// create element audio ...
mStreams = new EwolAudioTask();
setContentView(mGLView);
} }
// call C
EWOL.onPause();
}
@Override protected void onStop() @Override protected void onStart()
{ {
super.onStop(); super.onStart();
// call C // call C
EWOL.onStop(); EWOL.onStart();
}
@Override protected void onDestroy()
{
super.onDestroy();
// call C
EWOL.onDestroy();
// Remove the java Virtual machine pointer form the C code
Ewol.setJavaVirtualMachineStop();
}
@Override protected void finalize() throws Throwable
{
super.finalize();
// cleanup your object here
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
public void keyboardUpdate(boolean show)
{
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if(show) {
//EWOL.touchEvent();
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
} else {
imm.toggleSoftInput(0 ,InputMethodManager.HIDE_IMPLICIT_ONLY + InputMethodManager.HIDE_NOT_ALWAYS);
//imm.hideSoftInputFromWindow(view.getWindowToken(),0);
} }
}
public void eventNotifier(String[] args) @Override protected void onRestart()
{ {
// just for the test ... super.onRestart();
EWOL.touchEvent(); // call C
} EWOL.onReStart();
}
public void orientationUpdate(int screenMode)
{ @Override protected void onResume()
if (screenMode == EWOL_ORIENTATION_LANDSCAPE) { {
//Force landscape super.onResume();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); mGLView.onResume();
} else if (screenMode == EWOL_ORIENTATION_PORTRAIT) { mAudioThread = new Thread(mStreams);
//Force portrait if (mAudioThread != null) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mAudioThread.start();
} else { }
//Force auto Rotation // call C
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); EWOL.onResume();
}
@Override protected void onPause()
{
super.onPause();
mGLView.onPause();
if (mAudioThread != null) {
// request audio stop
mStreams.AutoStop();
// wait the thread ended ...
try {
mAudioThread.join();
} catch(InterruptedException e) { }
}
// call C
EWOL.onPause();
}
@Override protected void onStop()
{
super.onStop();
// call C
EWOL.onStop();
}
@Override protected void onDestroy()
{
super.onDestroy();
// call C
EWOL.onDestroy();
// Remove the java Virtual machine pointer form the C code
Ewol.setJavaVirtualMachineStop();
}
@Override protected void finalize() throws Throwable
{
super.finalize();
// cleanup your object here
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
public void keyboardUpdate(boolean show)
{
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if(show) {
//EWOL.touchEvent();
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
} else {
imm.toggleSoftInput(0 ,InputMethodManager.HIDE_IMPLICIT_ONLY + InputMethodManager.HIDE_NOT_ALWAYS);
//imm.hideSoftInputFromWindow(view.getWindowToken(),0);
}
}
public void eventNotifier(String[] args)
{
// just for the test ...
EWOL.touchEvent();
}
public void orientationUpdate(int screenMode)
{
if (screenMode == EWOL_ORIENTATION_LANDSCAPE) {
//Force landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (screenMode == EWOL_ORIENTATION_PORTRAIT) {
//Force portrait
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
//Force auto Rotation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
} }
}
} }

View File

@ -23,18 +23,17 @@ import static org.ewol.Ewol.EWOL;
* @brief Class : * @brief Class :
* *
*/ */
public class EwolRendererGL implements GLSurfaceView.Renderer { public class EwolRendererGL implements GLSurfaceView.Renderer
{
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
EWOL.renderInit();
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) { public void onSurfaceChanged(GL10 gl, int w, int h) {
EWOL.renderResize(w, h);
EWOL.renderInit(); }
}
public void onSurfaceChanged(GL10 gl, int w, int h) { public void onDrawFrame(GL10 gl) {
EWOL.renderResize(w, h); EWOL.renderDraw();
} }
public void onDrawFrame(GL10 gl) {
EWOL.renderDraw();
}
} }

View File

@ -0,0 +1,231 @@
/**
* @author Edouard DUPIN, Kevin BILLONNEAU
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
package org.ewol;
import android.service.wallpaper.WallpaperService;
//import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.KeyEvent;
// For No Title :
import android.view.Window;
// For the full screen :
import android.view.WindowManager;
// for the keyboard event :
import android.view.inputmethod.InputMethodManager;
import java.io.File;
import android.content.Context;
import android.content.res.Configuration;
// For the getting apk name :
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.util.DisplayMetrics;
import android.view.SurfaceHolder;
import java.io.IOException;
import static org.ewol.Ewol.EWOL;
/**
* @brief Class :
*
*/
public abstract class EwolWallpaper extends WallpaperService
{
private TestPatternEngine tmpEngine;
static {
System.loadLibrary("ewol");
}
@Override public void onCreate()
{
super.onCreate();
}
@Override public void onDestroy()
{
super.onDestroy();
}
@Override public Engine onCreateEngine()
{
tmpEngine = new TestPatternEngine();
return tmpEngine;
}
protected void initApkPath(String org, String vendor, String project)
{
tmpEngine.initApkPath(org, vendor, project);
}
class TestPatternEngine extends Engine implements EwolCallback, EwolConstants // implements SharedPreferences.OnSharedPreferenceChangeListener
{
private EwolSurfaceViewGL mGLView;
public void initApkPath(String org, String vendor, String project) {
StringBuilder sb = new StringBuilder();
sb.append(org).append(".");
sb.append(vendor).append(".");
sb.append(project);
String apkFilePath = null;
ApplicationInfo appInfo = null;
PackageManager packMgmr = getPackageManager();
try {
appInfo = packMgmr.getApplicationInfo(sb.toString(), 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("Unable to locate assets, aborting...");
}
apkFilePath = appInfo.sourceDir;
Ewol.paramSetArchiveDir(0, apkFilePath);
}
@Override public void onCreate(SurfaceHolder surfaceHolder)
{
super.onCreate(surfaceHolder);
// set the java evironement in the C sources :
Ewol.setJavaVirtualMachineStartWallpaperEngine(this);
// Load the application directory
Ewol.paramSetArchiveDir(1, getFilesDir().toString());
Ewol.paramSetArchiveDir(2, getCacheDir().toString());
// to enable extarnal storage: add in the manifest the restriction needed ...
//packageManager.checkPermission("android.permission.READ_SMS", myPackage) == PERMISSION_GRANTED;
//Ewol.paramSetArchiveDir(3, getExternalCacheDir().toString());
DisplayMetrics metrics = new DisplayMetrics();
//!getWindowManager().getDefaultDisplay().getMetrics(metrics);
//!EWOL.displayPropertyMetrics(metrics.xdpi, metrics.ydpi);
// call C init ...
EWOL.onCreate();
// Remove the title of the current display :
//!requestWindowFeature(Window.FEATURE_NO_TITLE);
// set full screen Mode :
//!getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// display keyboard:
//getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
// hide keyboard :
//!getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
// create bsurface system
mGLView = new EwolSurfaceViewGL(this, 2);
setContentView(mGLView);
}
@Override public void onStart()
{
super.onStart();
// call C
EWOL.onStart();
}
@Override public void onRestart()
{
super.onRestart();
// call C
EWOL.onReStart();
}
@Override public void onResume()
{
super.onResume();
mGLView.onResume();
// call C
EWOL.onResume();
}
@Override public void onPause()
{
super.onPause();
mGLView.onPause();
// call C
EWOL.onPause();
}
@Override public void onStop()
{
super.onStop();
// call C
EWOL.onStop();
}
@Override public void onDestroy()
{
super.onDestroy();
// call C
EWOL.onDestroy();
// Remove the java Virtual machine pointer form the C code
Ewol.setJavaVirtualMachineStop();
}
@Override protected void finalize() throws Throwable
{
super.finalize();
// cleanup your object here
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
public void keyboardUpdate(boolean show)
{
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if(show) {
//EWOL.touchEvent();
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
} else {
imm.toggleSoftInput(0 ,InputMethodManager.HIDE_IMPLICIT_ONLY + InputMethodManager.HIDE_NOT_ALWAYS);
//imm.hideSoftInputFromWindow(view.getWindowToken(),0);
}
}
public void eventNotifier(String[] args)
{
// just for the test ...
EWOL.touchEvent();
}
public void orientationUpdate(int screenMode)
{
/*
if (screenMode == EWOL_ORIENTATION_LANDSCAPE) {
//Force landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (screenMode == EWOL_ORIENTATION_PORTRAIT) {
//Force portrait
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
//Force auto Rotation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
*/
}
}
}

View File

@ -0,0 +1,123 @@
package org.ewol;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Build;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.SurfaceHolder;
//import com.learnopengles.android.util.LoggerConfig;
public abstract class EwolWallpaperService extends WallpaperService
{
private EwolSurfaceViewGL mGLView;
/*
// moi ...
@Override
public abstract Engine onCreateEngine(Context context) {
return new GLEngine(Context context);
}
*/
/*
static {
System.loadLibrary("ewol");
}
protected void initApkPath(String org, String vendor, String project) {
StringBuilder sb = new StringBuilder();
sb.append(org).append(".");
sb.append(vendor).append(".");
sb.append(project);
String apkFilePath = null;
ApplicationInfo appInfo = null;
PackageManager packMgmr = getPackageManager();
try {
appInfo = packMgmr.getApplicationInfo(sb.toString(), 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("Unable to locate assets, aborting...");
}
apkFilePath = appInfo.sourceDir;
Ewol.paramSetArchiveDir(0, apkFilePath);
}
*/
public class GLEngine extends Engine
{
class WallpaperGLSurfaceView extends GLSurfaceView
{
private static final String TAG = "WallpaperGLSurfaceView";
WallpaperGLSurfaceView(Context context)
{
super(context);
Log.d(TAG, "WallpaperGLSurfaceView(" + context + ")");
}
@Override
public SurfaceHolder getHolder()
{
Log.d(TAG, "getHolder(): returning " + getSurfaceHolder());
return getSurfaceHolder();
}
public void onDestroy()
{
Log.d(TAG, "onDestroy()");
super.onDetachedFromWindow();
}
}
private static final String TAG = "GLEngine";
private WallpaperGLSurfaceView glSurfaceView;
private boolean rendererHasBeenSet;
@Override
public void onCreate(SurfaceHolder surfaceHolder)
{
Log.d(TAG, "onCreate(" + surfaceHolder + ")");
super.onCreate(surfaceHolder);
glSurfaceView = new WallpaperGLSurfaceView(EwolWallpaperService.this);
}
@Override
public void onVisibilityChanged(boolean visible)
{
Log.d(TAG, "onVisibilityChanged(" + visible + ")");
super.onVisibilityChanged(visible);
if (rendererHasBeenSet) {
if (visible) {
glSurfaceView.onResume();
} else {
glSurfaceView.onPause();
}
}
}
@Override
public void onDestroy()
{
Log.d(TAG, "onDestroy()");
super.onDestroy();
glSurfaceView.onDestroy();
}
protected void setRenderer(Renderer renderer)
{
Log.d(TAG, "setRenderer(" + renderer + ")");
glSurfaceView.setRenderer(renderer);
rendererHasBeenSet = true;
}
protected void setPreserveEGLContextOnPause(boolean preserve)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Log.d(TAG, "setPreserveEGLContextOnPause(" + preserve + ")");
glSurfaceView.setPreserveEGLContextOnPause(preserve);
}
}
protected void setEGLContextClientVersion(int version)
{
Log.d(TAG, "setEGLContextClientVersion(" + version + ")");
glSurfaceView.setEGLContextClientVersion(version);
}
}
}

View File

@ -0,0 +1,73 @@
package org.ewol;
import org.ewol.LessonTwoRenderer;
/**
* This class implements our custom renderer. Note that the GL10 parameter passed in is unused for OpenGL ES 2.0
* renderers -- the static class GLES20 is used instead.
*/
public class LessonThreeRenderer extends LessonTwoRenderer
{
protected String getVertexShader()
{
// Define our per-pixel lighting shader.
final String perPixelVertexShader =
"uniform mat4 u_MVPMatrix; \n" // A constant representing the combined model/view/projection matrix.
+ "uniform mat4 u_MVMatrix; \n" // A constant representing the combined model/view matrix.
+ "attribute vec4 a_Position; \n" // Per-vertex position information we will pass in.
+ "attribute vec4 a_Color; \n" // Per-vertex color information we will pass in.
+ "attribute vec3 a_Normal; \n" // Per-vertex normal information we will pass in.
+ "varying vec3 v_Position; \n" // This will be passed into the fragment shader.
+ "varying vec4 v_Color; \n" // This will be passed into the fragment shader.
+ "varying vec3 v_Normal; \n" // This will be passed into the fragment shader.
// The entry point for our vertex shader.
+ "void main() \n"
+ "{ \n"
// Transform the vertex into eye space.
+ " v_Position = vec3(u_MVMatrix * a_Position); \n"
// Pass through the color.
+ " v_Color = a_Color; \n"
// Transform the normal's orientation into eye space.
+ " v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); \n"
// gl_Position is a special variable used to store the final position.
// Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
+ " gl_Position = u_MVPMatrix * a_Position; \n"
+ "} \n";
return perPixelVertexShader;
}
protected String getFragmentShader()
{
final String perPixelFragmentShader =
"precision mediump float; \n" // Set the default precision to medium. We don't need as high of a
// precision in the fragment shader.
+ "uniform vec3 u_LightPos; \n" // The position of the light in eye space.
+ "varying vec3 v_Position; \n" // Interpolated position for this fragment.
+ "varying vec4 v_Color; \n" // This is the color from the vertex shader interpolated across the
// triangle per fragment.
+ "varying vec3 v_Normal; \n" // Interpolated normal for this fragment.
// The entry point for our fragment shader.
+ "void main() \n"
+ "{ \n"
// Will be used for attenuation.
+ " float distance = length(u_LightPos - v_Position); \n"
// Get a lighting direction vector from the light to the vertex.
+ " vec3 lightVector = normalize(u_LightPos - v_Position); \n"
// Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
// pointing in the same direction then it will get max illumination.
+ " float diffuse = max(dot(v_Normal, lightVector), 0.1); \n"
// Add attenuation.
+ " diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance * distance))); \n"
// Multiply the color by the diffuse illumination level to get final output color.
+ " gl_FragColor = v_Color * diffuse; \n"
+ "} \n";
return perPixelFragmentShader;
}
}

View File

@ -0,0 +1,12 @@
package com.learnopengles.android.livewallpaper;
import android.opengl.GLSurfaceView.Renderer;
import com.learnopengles.android.lesson3.LessonThreeRenderer;
public class LessonThreeWallpaperService extends OpenGLES2WallpaperService {
@Override
Renderer getNewRenderer() {
return new LessonThreeRenderer();
}
}

View File

@ -0,0 +1,642 @@
package org.ewol;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.SystemClock;
import android.util.Log;
/**
* This class implements our custom renderer. Note that the GL10 parameter passed in is unused for OpenGL ES 2.0
* renderers -- the static class GLES20 is used instead.
*/
public class LessonTwoRenderer implements GLSurfaceView.Renderer
{
/** Used for debug logs. */
private static final String TAG = "LessonTwoRenderer";
/**
* Store the model matrix. This matrix is used to move models from object space (where each model can be thought
* of being located at the center of the universe) to world space.
*/
private float[] mModelMatrix = new float[16];
/**
* Store the view matrix. This can be thought of as our camera. This matrix transforms world space to eye space;
* it positions things relative to our eye.
*/
private float[] mViewMatrix = new float[16];
/** Store the projection matrix. This is used to project the scene onto a 2D viewport. */
private float[] mProjectionMatrix = new float[16];
/** Allocate storage for the final combined matrix. This will be passed into the shader program. */
private float[] mMVPMatrix = new float[16];
/**
* Stores a copy of the model matrix specifically for the light position.
*/
private float[] mLightModelMatrix = new float[16];
/** Store our model data in a float buffer. */
private final FloatBuffer mCubePositions;
private final FloatBuffer mCubeColors;
private final FloatBuffer mCubeNormals;
/** This will be used to pass in the transformation matrix. */
private int mMVPMatrixHandle;
/** This will be used to pass in the modelview matrix. */
private int mMVMatrixHandle;
/** This will be used to pass in the light position. */
private int mLightPosHandle;
/** This will be used to pass in model position information. */
private int mPositionHandle;
/** This will be used to pass in model color information. */
private int mColorHandle;
/** This will be used to pass in model normal information. */
private int mNormalHandle;
/** How many bytes per float. */
private final int mBytesPerFloat = 4;
/** Size of the position data in elements. */
private final int mPositionDataSize = 3;
/** Size of the color data in elements. */
private final int mColorDataSize = 4;
/** Size of the normal data in elements. */
private final int mNormalDataSize = 3;
/** Used to hold a light centered on the origin in model space. We need a 4th coordinate so we can get translations to work when
* we multiply this by our transformation matrices. */
private final float[] mLightPosInModelSpace = new float[] {0.0f, 0.0f, 0.0f, 1.0f};
/** Used to hold the current position of the light in world space (after transformation via model matrix). */
private final float[] mLightPosInWorldSpace = new float[4];
/** Used to hold the transformed position of the light in eye space (after transformation via modelview matrix) */
private final float[] mLightPosInEyeSpace = new float[4];
/** This is a handle to our per-vertex cube shading program. */
private int mPerVertexProgramHandle;
/** This is a handle to our light point program. */
private int mPointProgramHandle;
/**
* Initialize the model data.
*/
public LessonTwoRenderer()
{
// Define points for a cube.
// X, Y, Z
final float[] cubePositionData =
{
// In OpenGL counter-clockwise winding is default. This means that when we look at a triangle,
// if the points are counter-clockwise we are looking at the "front". If not we are looking at
// the back. OpenGL has an optimization where all back-facing triangles are culled, since they
// usually represent the backside of an object and aren't visible anyways.
// Front face
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
// Right face
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
// Back face
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
// Left face
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
// Top face
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
// Bottom face
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
};
// R, G, B, A
final float[] cubeColorData =
{
// Front face (red)
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
// Right face (green)
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
// Back face (blue)
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f,
// Left face (yellow)
1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f,
// Top face (cyan)
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f, 1.0f,
// Bottom face (magenta)
1.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f
};
// X, Y, Z
// The normal is used in light calculations and is a vector which points
// orthogonal to the plane of the surface. For a cube model, the normals
// should be orthogonal to the points of each face.
final float[] cubeNormalData =
{
// Front face
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
// Right face
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
// Back face
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -1.0f,
// Left face
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
// Top face
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
// Bottom face
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 0.0f
};
// Initialize the buffers.
mCubePositions = ByteBuffer.allocateDirect(cubePositionData.length * mBytesPerFloat)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
mCubePositions.put(cubePositionData).position(0);
mCubeColors = ByteBuffer.allocateDirect(cubeColorData.length * mBytesPerFloat)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
mCubeColors.put(cubeColorData).position(0);
mCubeNormals = ByteBuffer.allocateDirect(cubeNormalData.length * mBytesPerFloat)
.order(ByteOrder.nativeOrder()).asFloatBuffer();
mCubeNormals.put(cubeNormalData).position(0);
}
protected String getVertexShader()
{
// TODO: Explain why we normalize the vectors, explain some of the vector math behind it all. Explain what is eye space.
final String vertexShader =
"uniform mat4 u_MVPMatrix; \n" // A constant representing the combined model/view/projection matrix.
+ "uniform mat4 u_MVMatrix; \n" // A constant representing the combined model/view matrix.
+ "uniform vec3 u_LightPos; \n" // The position of the light in eye space.
+ "attribute vec4 a_Position; \n" // Per-vertex position information we will pass in.
+ "attribute vec4 a_Color; \n" // Per-vertex color information we will pass in.
+ "attribute vec3 a_Normal; \n" // Per-vertex normal information we will pass in.
+ "varying vec4 v_Color; \n" // This will be passed into the fragment shader.
+ "void main() \n" // The entry point for our vertex shader.
+ "{ \n"
// Transform the vertex into eye space.
+ " vec3 modelViewVertex = vec3(u_MVMatrix * a_Position); \n"
// Transform the normal's orientation into eye space.
+ " vec3 modelViewNormal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); \n"
// Will be used for attenuation.
+ " float distance = length(u_LightPos - modelViewVertex); \n"
// Get a lighting direction vector from the light to the vertex.
+ " vec3 lightVector = normalize(u_LightPos - modelViewVertex); \n"
// Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
// pointing in the same direction then it will get max illumination.
+ " float diffuse = max(dot(modelViewNormal, lightVector), 0.1); \n"
// Attenuate the light based on distance.
+ " diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance * distance))); \n"
// Multiply the color by the illumination level. It will be interpolated across the triangle.
+ " v_Color = a_Color * diffuse; \n"
// gl_Position is a special variable used to store the final position.
// Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
+ " gl_Position = u_MVPMatrix * a_Position; \n"
+ "} \n";
return vertexShader;
}
protected String getFragmentShader()
{
final String fragmentShader =
"precision mediump float; \n" // Set the default precision to medium. We don't need as high of a
// precision in the fragment shader.
+ "varying vec4 v_Color; \n" // This is the color from the vertex shader interpolated across the
// triangle per fragment.
+ "void main() \n" // The entry point for our fragment shader.
+ "{ \n"
+ " gl_FragColor = v_Color; \n" // Pass the color directly through the pipeline.
+ "} \n";
return fragmentShader;
}
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
{
// Set the background clear color to black.
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Use culling to remove back faces.
GLES20.glEnable(GLES20.GL_CULL_FACE);
// Enable depth testing
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
// Position the eye in front of the origin.
final float eyeX = 0.0f;
final float eyeY = 0.0f;
final float eyeZ = -0.5f;
// We are looking toward the distance
final float lookX = 0.0f;
final float lookY = 0.0f;
final float lookZ = -5.0f;
// Set our up vector. This is where our head would be pointing were we holding the camera.
final float upX = 0.0f;
final float upY = 1.0f;
final float upZ = 0.0f;
// Set the view matrix. This matrix can be said to represent the camera position.
// NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
// view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
final String vertexShader = getVertexShader();
final String fragmentShader = getFragmentShader();
final int vertexShaderHandle = compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
final int fragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);
mPerVertexProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle,
new String[] {"a_Position", "a_Color", "a_Normal"});
// Define a simple shader program for our point.
final String pointVertexShader =
"uniform mat4 u_MVPMatrix; \n"
+ "attribute vec4 a_Position; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = u_MVPMatrix \n"
+ " * a_Position; \n"
+ " gl_PointSize = 5.0; \n"
+ "} \n";
final String pointFragmentShader =
"precision mediump float; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vec4(1.0, \n"
+ " 1.0, 1.0, 1.0); \n"
+ "} \n";
final int pointVertexShaderHandle = compileShader(GLES20.GL_VERTEX_SHADER, pointVertexShader);
final int pointFragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, pointFragmentShader);
mPointProgramHandle = createAndLinkProgram(pointVertexShaderHandle, pointFragmentShaderHandle,
new String[] {"a_Position"});
}
public void onSurfaceChanged(GL10 glUnused, int width, int height)
{
// Set the OpenGL viewport to the same size as the surface.
GLES20.glViewport(0, 0, width, height);
// Create a new perspective projection matrix. The height will stay the same
// while the width will vary as per aspect ratio.
final float ratio = (float) width / height;
final float left = -ratio;
final float right = ratio;
final float bottom = -1.0f;
final float top = 1.0f;
final float near = 1.0f;
final float far = 10.0f;
Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
}
public void onDrawFrame(GL10 glUnused)
{
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Do a complete rotation every 10 seconds.
long time = SystemClock.uptimeMillis() % 10000L;
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
// Set our per-vertex lighting program.
GLES20.glUseProgram(mPerVertexProgramHandle);
// Set program handles for cube drawing.
mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
// Calculate position of the light. Rotate and then push into the distance.
Matrix.setIdentityM(mLightModelMatrix, 0);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
// Draw some cubes.
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
drawCube();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
drawCube();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
drawCube();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
drawCube();
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
drawCube();
// Draw a point to indicate the light.
GLES20.glUseProgram(mPointProgramHandle);
drawLight();
}
/**
* Draws a cube.
*/
private void drawCube()
{
// Pass in the position information
mCubePositions.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
0, mCubePositions);
GLES20.glEnableVertexAttribArray(mPositionHandle);
// Pass in the color information
mCubeColors.position(0);
GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false,
0, mCubeColors);
GLES20.glEnableVertexAttribArray(mColorHandle);
// Pass in the normal information
mCubeNormals.position(0);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
0, mCubeNormals);
GLES20.glEnableVertexAttribArray(mNormalHandle);
// This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
// (which currently contains model * view).
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
// Pass in the modelview matrix.
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
// This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
// (which now contains model * view * projection).
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
// Pass in the combined matrix.
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Pass in the light position in eye space.
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
// Draw the cube.
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
}
/**
* Draws a point representing the position of the light.
*/
private void drawLight()
{
final int pointMVPMatrixHandle = GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");
// Pass in the position.
GLES20.glVertexAttrib3f(pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);
// Since we are not using a buffer object, disable vertex arrays for this attribute.
GLES20.glDisableVertexAttribArray(pointPositionHandle);
// Pass in the transformation matrix.
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Draw the point.
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
/**
* Helper function to compile a shader.
*
* @param shaderType The shader type.
* @param shaderSource The shader source code.
* @return An OpenGL handle to the shader.
*/
private int compileShader(final int shaderType, final String shaderSource)
{
int shaderHandle = GLES20.glCreateShader(shaderType);
if (shaderHandle != 0)
{
// Pass in the shader source.
GLES20.glShaderSource(shaderHandle, shaderSource);
// Compile the shader.
GLES20.glCompileShader(shaderHandle);
// Get the compilation status.
final int[] compileStatus = new int[1];
GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
// If the compilation failed, delete the shader.
if (compileStatus[0] == 0)
{
Log.e(TAG, "Error compiling shader: " + GLES20.glGetShaderInfoLog(shaderHandle));
GLES20.glDeleteShader(shaderHandle);
shaderHandle = 0;
}
}
if (shaderHandle == 0)
{
throw new RuntimeException("Error creating shader.");
}
return shaderHandle;
}
/**
* Helper function to compile and link a program.
*
* @param vertexShaderHandle An OpenGL handle to an already-compiled vertex shader.
* @param fragmentShaderHandle An OpenGL handle to an already-compiled fragment shader.
* @param attributes Attributes that need to be bound to the program.
* @return An OpenGL handle to the program.
*/
private int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes)
{
int programHandle = GLES20.glCreateProgram();
if (programHandle != 0)
{
// Bind the vertex shader to the program.
GLES20.glAttachShader(programHandle, vertexShaderHandle);
// Bind the fragment shader to the program.
GLES20.glAttachShader(programHandle, fragmentShaderHandle);
// Bind attributes
if (attributes != null)
{
final int size = attributes.length;
for (int i = 0; i < size; i++)
{
GLES20.glBindAttribLocation(programHandle, i, attributes[i]);
}
}
// Link the two shaders together into a program.
GLES20.glLinkProgram(programHandle);
// Get the link status.
final int[] linkStatus = new int[1];
GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, linkStatus, 0);
// If the link failed, delete the program.
if (linkStatus[0] == 0)
{
Log.e(TAG, "Error compiling program: " + GLES20.glGetProgramInfoLog(programHandle));
GLES20.glDeleteProgram(programHandle);
programHandle = 0;
}
}
if (programHandle == 0)
{
throw new RuntimeException("Error creating program.");
}
return programHandle;
}
}

View File

@ -20,17 +20,17 @@
#include <ewol/renderer/os/org_ewol_EwolConstants.h> #include <ewol/renderer/os/org_ewol_EwolConstants.h>
// get a resources from the java environement : // get a resources from the java environement :
static JNIEnv* JavaVirtualMachinePointer = NULL; // the JVM static JNIEnv* JavaVirtualMachinePointer = NULL; // the JVM
static jclass javaClassEwol = 0; // main activity class (android ...) static jclass javaClassEwol = 0; // main activity class (android ...)
static jclass javaClassEwolCallbackAndActivity = 0; static jclass javaClassEwolCallbackAndActivity = 0;
static jobject javaObjectEwolCallbackAndActivity = 0; static jobject javaObjectEwolCallbackAndActivity = 0;
static jmethodID javaMethodEwolCallbackEventNotifier = 0; // basic methode to call ... static jmethodID javaMethodEwolCallbackEventNotifier = 0; // basic methode to call ...
static jmethodID javaMethodEwolCallbackKeyboardUpdate = 0; // basic methode to call ... static jmethodID javaMethodEwolCallbackKeyboardUpdate = 0; // basic methode to call ...
static jmethodID javaMethodEwolCallbackOrientationUpdate = 0; static jmethodID javaMethodEwolCallbackOrientationUpdate = 0;
static jmethodID javaMethodEwolActivitySetTitle = 0; static jmethodID javaMethodEwolActivitySetTitle = 0;
// generic classes // generic classes
static jclass javaDefaultClassString = 0; // default string class static jclass javaDefaultClassString = 0; // default string class
static int32_t m_currentHeight = 0; static int32_t m_currentHeight = 0;
@ -43,408 +43,424 @@ static ewol::SpecialKey guiKeyBoardSpecialKeyMode;
// jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include // jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include
#define __jni_safe_init_method_id(mid, cls, name, sign) ({ \ #define __jni_safe_init_method_id(mid, cls, name, sign) ({ \
mid = JavaVirtualMachinePointer->GetMethodID(cls, name, sign); \ mid = JavaVirtualMachinePointer->GetMethodID(cls, name, sign); \
if(mid == NULL) { \ if(mid == NULL) { \
EWOL_ERROR("C->java : Can't find the method " << name); \ EWOL_ERROR("C->java : Can't find the method " << name); \
/* remove access on the virtual machine : */ \ /* remove access on the virtual machine : */ \
JavaVirtualMachinePointer = NULL; \ JavaVirtualMachinePointer = NULL; \
return; \ return; \
} \ } \
}) })
static void java_check_exception(JNIEnv* env) { static void java_check_exception(JNIEnv* env) {
if (env->ExceptionOccurred()) { if (env->ExceptionOccurred()) {
EWOL_ERROR("C->java : EXEPTION ..."); EWOL_ERROR("C->java : EXEPTION ...");
env->ExceptionDescribe(); env->ExceptionDescribe();
env->ExceptionClear(); env->ExceptionClear();
} }
} }
static bool java_attach_current_thread(int *rstatus) { static bool java_attach_current_thread(int *rstatus) {
EWOL_DEBUG("C->java : call java"); EWOL_DEBUG("C->java : call java");
if (NULL == g_JavaVM) { if (NULL == g_JavaVM) {
EWOL_ERROR("C->java : JVM not initialised"); EWOL_ERROR("C->java : JVM not initialised");
return false; return false;
} }
JNIEnv *JavaVirtualMachinePointer_tmp; JNIEnv *JavaVirtualMachinePointer_tmp;
*rstatus = g_JavaVM->GetEnv((void **) &JavaVirtualMachinePointer_tmp, JNI_VERSION_1_6); *rstatus = g_JavaVM->GetEnv((void **) &JavaVirtualMachinePointer_tmp, JNI_VERSION_1_6);
if (*rstatus == JNI_EDETACHED) { if (*rstatus == JNI_EDETACHED) {
JavaVMAttachArgs lJavaVMAttachArgs; JavaVMAttachArgs lJavaVMAttachArgs;
lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.version = JNI_VERSION_1_6;
lJavaVMAttachArgs.name = "EwolNativeThread"; lJavaVMAttachArgs.name = "EwolNativeThread";
lJavaVMAttachArgs.group = NULL; lJavaVMAttachArgs.group = NULL;
int status = g_JavaVM->AttachCurrentThread(&JavaVirtualMachinePointer_tmp, &lJavaVMAttachArgs); int status = g_JavaVM->AttachCurrentThread(&JavaVirtualMachinePointer_tmp, &lJavaVMAttachArgs);
java_check_exception(JavaVirtualMachinePointer); java_check_exception(JavaVirtualMachinePointer);
if (status != JNI_OK) { if (status != JNI_OK) {
EWOL_ERROR("C->java : AttachCurrentThread failed : " << status); EWOL_ERROR("C->java : AttachCurrentThread failed : " << status);
return false; return false;
} }
} }
return true; return true;
} }
static void java_detach_current_thread(int status) { static void java_detach_current_thread(int status) {
if(status == JNI_EDETACHED) g_JavaVM->DetachCurrentThread(); if(status == JNI_EDETACHED) g_JavaVM->DetachCurrentThread();
} }
void SendJavaKeyboardUpdate(bool showIt) void SendJavaKeyboardUpdate(bool showIt)
{ {
int status; int status;
if(!java_attach_current_thread(&status)) return; if(!java_attach_current_thread(&status)) return;
//Call java ... //Call java ...
JavaVirtualMachinePointer->CallVoidMethod(javaObjectEwolCallbackAndActivity, javaMethodEwolCallbackKeyboardUpdate, showIt ? JNI_TRUE : JNI_FALSE); JavaVirtualMachinePointer->CallVoidMethod(javaObjectEwolCallbackAndActivity, javaMethodEwolCallbackKeyboardUpdate, showIt ? JNI_TRUE : JNI_FALSE);
// manage execption : // manage execption :
java_check_exception(JavaVirtualMachinePointer); java_check_exception(JavaVirtualMachinePointer);
java_detach_current_thread(status); java_detach_current_thread(status);
} }
// mode 0 : auto; 1 landscape, 2 portrait // mode 0 : auto; 1 landscape, 2 portrait
void SendJavaOrientationUpdate(int32_t mode) void SendJavaOrientationUpdate(int32_t mode)
{ {
#ifndef __ANDROID_PERMISSION__SET_ORIENTATION__ #ifndef __ANDROID_PERMISSION__SET_ORIENTATION__
EWOL_ERROR("C->java : call set orientation without Allow application to do it ... Break..."); EWOL_ERROR("C->java : call set orientation without Allow application to do it ... Break...");
return; return;
#else #else
int status; int status;
if(!java_attach_current_thread(&status)) return; if(!java_attach_current_thread(&status)) {
jint param = mode; return;
}
//Call java ... jint param = mode;
JavaVirtualMachinePointer->CallVoidMethod(javaObjectEwolCallbackAndActivity, javaMethodEwolCallbackOrientationUpdate, param);
// manage execption : //Call java ...
java_check_exception(JavaVirtualMachinePointer); JavaVirtualMachinePointer->CallVoidMethod(javaObjectEwolCallbackAndActivity, javaMethodEwolCallbackOrientationUpdate, param);
java_detach_current_thread(status);
// manage execption :
java_check_exception(JavaVirtualMachinePointer);
java_detach_current_thread(status);
#endif #endif
} }
void SendJavaSetTitle(const char * dataString) void SendJavaSetTitle(const char * dataString)
{ {
EWOL_DEBUG("C->java : send message to the java : \"" << dataString << "\""); EWOL_DEBUG("C->java : send message to the java : \"" << dataString << "\"");
int status; int status;
if(!java_attach_current_thread(&status)) return; if(!java_attach_current_thread(&status)) {
EWOL_DEBUG("C->java : 222"); return;
if (NULL == dataString) { }
EWOL_ERROR("C->java : No data to send ..."); EWOL_DEBUG("C->java : 222");
return; if (NULL == dataString) {
} EWOL_ERROR("C->java : No data to send ...");
return;
}
//Call java ... //Call java ...
jstring title = JavaVirtualMachinePointer->NewStringUTF(dataString); jstring title = JavaVirtualMachinePointer->NewStringUTF(dataString);
JavaVirtualMachinePointer->CallVoidMethod(javaObjectEwolCallbackAndActivity, javaMethodEwolActivitySetTitle, title); JavaVirtualMachinePointer->CallVoidMethod(javaObjectEwolCallbackAndActivity, javaMethodEwolActivitySetTitle, title);
JavaVirtualMachinePointer->DeleteLocalRef(title); JavaVirtualMachinePointer->DeleteLocalRef(title);
// manage execption : // manage execption :
java_check_exception(JavaVirtualMachinePointer); java_check_exception(JavaVirtualMachinePointer);
java_detach_current_thread(status); java_detach_current_thread(status);
} }
void SendSystemMessage(const char * dataString) void SendSystemMessage(const char * dataString)
{ {
EWOL_DEBUG("C->java : send message to the java : \"" << dataString << "\""); EWOL_DEBUG("C->java : send message to the java : \"" << dataString << "\"");
int status; int status;
if(!java_attach_current_thread(&status)) return; if(!java_attach_current_thread(&status)) {
EWOL_DEBUG("C->java : 222"); return;
if (NULL == dataString) { }
EWOL_ERROR("C->java : No data to send ..."); EWOL_DEBUG("C->java : 222");
return; if (NULL == dataString) {
} EWOL_ERROR("C->java : No data to send ...");
EWOL_DEBUG("C->java : 333"); return;
// create the string to the java }
jstring jstr = JavaVirtualMachinePointer->NewStringUTF(dataString); EWOL_DEBUG("C->java : 333");
if (jstr == 0) { // create the string to the java
EWOL_ERROR("C->java : Out of memory" ); jstring jstr = JavaVirtualMachinePointer->NewStringUTF(dataString);
return; if (jstr == 0) {
} EWOL_ERROR("C->java : Out of memory" );
EWOL_DEBUG("C->java : 444"); return;
// create argument list }
jobjectArray args = JavaVirtualMachinePointer->NewObjectArray(1, javaDefaultClassString, jstr); EWOL_DEBUG("C->java : 444");
if (args == 0) { // create argument list
EWOL_ERROR("C->java : Out of memory" ); jobjectArray args = JavaVirtualMachinePointer->NewObjectArray(1, javaDefaultClassString, jstr);
return; if (args == 0) {
} EWOL_ERROR("C->java : Out of memory" );
EWOL_DEBUG("C->java : 555"); return;
//Call java ... }
JavaVirtualMachinePointer->CallVoidMethod(javaObjectEwolCallbackAndActivity, javaMethodEwolCallbackEventNotifier, args); EWOL_DEBUG("C->java : 555");
//Call java ...
JavaVirtualMachinePointer->CallVoidMethod(javaObjectEwolCallbackAndActivity, javaMethodEwolCallbackEventNotifier, args);
EWOL_DEBUG("C->java : 666"); EWOL_DEBUG("C->java : 666");
java_check_exception(JavaVirtualMachinePointer); java_check_exception(JavaVirtualMachinePointer);
java_detach_current_thread(status); java_detach_current_thread(status);
} }
namespace guiAbstraction { namespace guiAbstraction {
void SendKeyboardEvent(bool isDown, uniChar_t keyInput); void SendKeyboardEvent(bool isDown, uniChar_t keyInput);
}; };
extern "C" extern "C"
{ {
// JNI OnLoad // JNI OnLoad
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* jvm, void* reserved) JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* jvm, void* reserved)
{ {
// get the java virtual machine handle ... // get the java virtual machine handle ...
g_JavaVM = jvm; g_JavaVM = jvm;
EWOL_DEBUG("JNI-> load the jvm ..." ); EWOL_DEBUG("JNI-> load the jvm ..." );
return JNI_VERSION_1_6; return JNI_VERSION_1_6;
} }
// JNI OnUnLoad // JNI OnUnLoad
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
{ {
g_JavaVM = NULL; g_JavaVM = NULL;
EWOL_DEBUG("JNI-> Un-load the jvm ..." ); EWOL_DEBUG("JNI-> Un-load the jvm ..." );
} }
/* Call to initialize the graphics state */ /* Call to initialize the graphics state */
void Java_org_ewol_Ewol_paramSetArchiveDir(JNIEnv* env, jclass cls, jint mode, jstring myString) void Java_org_ewol_Ewol_paramSetArchiveDir(JNIEnv* env, jclass cls, jint mode, jstring myString)
{ {
// direct setting of the date in the string system ... // direct setting of the date in the string system ...
jboolean isCopy; jboolean isCopy;
const char* str = env->GetStringUTFChars(myString, &isCopy); const char* str = env->GetStringUTFChars(myString, &isCopy);
eSystem::SetArchiveDir(mode, str); eSystem::SetArchiveDir(mode, str);
if (isCopy == JNI_TRUE) { if (isCopy == JNI_TRUE) {
// from here str is reset ... // from here str is reset ...
env->ReleaseStringUTFChars(myString, str); env->ReleaseStringUTFChars(myString, str);
str = NULL; str = NULL;
} }
} }
void Java_org_ewol_Ewol_setJavaVirtualMachineStart(JNIEnv* env, jclass classBase, jobject objCallback) static void setJavaVirtualMachineStart(JNIEnv* env, jclass classBase, jobject objCallback)
{ {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Set JVM Pointer **"); EWOL_DEBUG("** Set JVM Pointer **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
JavaVirtualMachinePointer = env; JavaVirtualMachinePointer = env;
// get default needed all time elements : // get default needed all time elements :
if (NULL != JavaVirtualMachinePointer) { if (NULL != JavaVirtualMachinePointer) {
EWOL_DEBUG("C->java : try load org/ewol/Ewol class"); EWOL_DEBUG("C->java : try load org/ewol/Ewol class");
javaClassEwol = JavaVirtualMachinePointer->FindClass("org/ewol/Ewol" ); javaClassEwol = JavaVirtualMachinePointer->FindClass("org/ewol/Ewol" );
if (javaClassEwol == 0) { if (javaClassEwol == 0) {
EWOL_ERROR("C->java : Can't find org/ewol/Ewol class"); EWOL_ERROR("C->java : Can't find org/ewol/Ewol class");
// remove access on the virtual machine : // remove access on the virtual machine :
JavaVirtualMachinePointer = NULL; JavaVirtualMachinePointer = NULL;
return; return;
} }
/* The object field extends Activity and implement EwolCallback */ /* The object field extends Activity and implement EwolCallback */
javaClassEwolCallbackAndActivity = JavaVirtualMachinePointer->GetObjectClass(objCallback); javaClassEwolCallbackAndActivity = JavaVirtualMachinePointer->GetObjectClass(objCallback);
if(javaClassEwolCallbackAndActivity == NULL) { if(javaClassEwolCallbackAndActivity == NULL) {
EWOL_ERROR("C->java : Can't find org/ewol/EwolCallback class"); EWOL_ERROR("C->java : Can't find org/ewol/EwolCallback class");
// remove access on the virtual machine : // remove access on the virtual machine :
JavaVirtualMachinePointer = NULL; JavaVirtualMachinePointer = NULL;
return; return;
} }
__jni_safe_init_method_id(
javaMethodEwolActivitySetTitle,
javaClassEwolCallbackAndActivity,
"setTitle", "(Ljava/lang/CharSequence;)V");
__jni_safe_init_method_id(
javaMethodEwolCallbackEventNotifier,
javaClassEwolCallbackAndActivity,
"eventNotifier", "([Ljava/lang/String;)V");
__jni_safe_init_method_id(
javaMethodEwolCallbackKeyboardUpdate,
javaClassEwolCallbackAndActivity,
"keyboardUpdate", "(Z)V");
__jni_safe_init_method_id(
javaMethodEwolCallbackOrientationUpdate,
javaClassEwolCallbackAndActivity,
"orientationUpdate", "(I)V");
javaObjectEwolCallbackAndActivity = env->NewGlobalRef(objCallback); __jni_safe_init_method_id(
//javaObjectEwolCallbackAndActivity = objCallback; javaMethodEwolActivitySetTitle,
javaClassEwolCallbackAndActivity,
"setTitle", "(Ljava/lang/CharSequence;)V");
javaDefaultClassString = JavaVirtualMachinePointer->FindClass("java/lang/String" ); __jni_safe_init_method_id(
if (javaDefaultClassString == 0) { javaMethodEwolCallbackEventNotifier,
EWOL_ERROR("C->java : Can't find java/lang/String" ); javaClassEwolCallbackAndActivity,
// remove access on the virtual machine : "eventNotifier", "([Ljava/lang/String;)V");
JavaVirtualMachinePointer = NULL;
return; __jni_safe_init_method_id(
} javaMethodEwolCallbackKeyboardUpdate,
} javaClassEwolCallbackAndActivity,
} "keyboardUpdate", "(Z)V");
void Java_org_ewol_Ewol_setJavaVirtualMachineStop(JNIEnv* env, jclass cls) {
EWOL_DEBUG("*******************************************"); __jni_safe_init_method_id(
EWOL_DEBUG("** Remove JVM Pointer **"); javaMethodEwolCallbackOrientationUpdate,
EWOL_DEBUG("*******************************************"); javaClassEwolCallbackAndActivity,
env->DeleteGlobalRef(javaObjectEwolCallbackAndActivity); "orientationUpdate", "(I)V");
JavaVirtualMachinePointer = NULL;
} javaObjectEwolCallbackAndActivity = env->NewGlobalRef(objCallback);
void Java_org_ewol_Ewol_touchEvent( JNIEnv* env, jobject thiz ) //javaObjectEwolCallbackAndActivity = objCallback;
{
EWOL_DEBUG(" ==> Touch Event"); javaDefaultClassString = JavaVirtualMachinePointer->FindClass("java/lang/String" );
java_check_exception(env); if (javaDefaultClassString == 0) {
} EWOL_ERROR("C->java : Can't find java/lang/String" );
// remove access on the virtual machine :
JavaVirtualMachinePointer = NULL;
return;
}
}
}
void Java_org_ewol_Ewol_onCreate( JNIEnv* env, jobject thiz ) void Java_org_ewol_Ewol_setJavaVirtualMachineStart(JNIEnv* _env, jclass _classBase, jobject _objCallback)
{ {
EWOL_DEBUG("*******************************************"); setJavaVirtualMachineStart(_env, _classBase, _objCallback);
EWOL_DEBUG("** Activity On Create **"); }
EWOL_DEBUG("*******************************************");
eSystem::Init(); void Java_org_ewol_Ewol_setJavaVirtualMachineStartWallpaperEngine(JNIEnv* _env, jclass _classBase, jobject _objCallback)
} {
setJavaVirtualMachineStart(_env, _classBase, _objCallback);
void Java_org_ewol_Ewol_onStart(JNIEnv* env, jobject thiz) }
{
EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity On Start **"); void Java_org_ewol_Ewol_setJavaVirtualMachineStop(JNIEnv* env, jclass cls) {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
//SendSystemMessage(" testmessages ... "); EWOL_DEBUG("** Remove JVM Pointer **");
} EWOL_DEBUG("*******************************************");
void Java_org_ewol_Ewol_onReStart(JNIEnv* env, jobject thiz) env->DeleteGlobalRef(javaObjectEwolCallbackAndActivity);
{ JavaVirtualMachinePointer = NULL;
EWOL_DEBUG("*******************************************"); }
EWOL_DEBUG("** Activity On Re-Start **"); void Java_org_ewol_Ewol_touchEvent( JNIEnv* env, jobject thiz )
EWOL_DEBUG("*******************************************"); {
} EWOL_DEBUG(" ==> Touch Event");
void Java_org_ewol_Ewol_onResume(JNIEnv* env, jobject thiz) java_check_exception(env);
{ }
EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity On Resume **"); void Java_org_ewol_Ewol_onCreate( JNIEnv* env, jobject thiz )
EWOL_DEBUG("*******************************************"); {
} EWOL_DEBUG("*******************************************");
void Java_org_ewol_Ewol_onPause(JNIEnv* env, jobject thiz) EWOL_DEBUG("** Activity On Create **");
{ EWOL_DEBUG("*******************************************");
EWOL_DEBUG("*******************************************"); eSystem::Init();
EWOL_DEBUG("** Activity On Pause **"); }
EWOL_DEBUG("*******************************************");
// All the openGl has been destroyed ... void Java_org_ewol_Ewol_onStart(JNIEnv* env, jobject thiz)
eSystem::OpenGlContextDestroy(); {
} EWOL_DEBUG("*******************************************");
void Java_org_ewol_Ewol_onStop(JNIEnv* env, jobject thiz) EWOL_DEBUG("** Activity On Start **");
{ EWOL_DEBUG("*******************************************");
EWOL_DEBUG("*******************************************"); //SendSystemMessage(" testmessages ... ");
EWOL_DEBUG("** Activity On Stop **"); }
EWOL_DEBUG("*******************************************"); void Java_org_ewol_Ewol_onReStart(JNIEnv* env, jobject thiz)
} {
void Java_org_ewol_Ewol_onDestroy(JNIEnv* env, jobject thiz) EWOL_DEBUG("*******************************************");
{ EWOL_DEBUG("** Activity On Re-Start **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity On Destroy **"); }
EWOL_DEBUG("*******************************************"); void Java_org_ewol_Ewol_onResume(JNIEnv* env, jobject thiz)
eSystem::UnInit(); {
} EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity On Resume **");
EWOL_DEBUG("*******************************************");
}
void Java_org_ewol_Ewol_onPause(JNIEnv* env, jobject thiz)
{
EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity On Pause **");
EWOL_DEBUG("*******************************************");
// All the openGl has been destroyed ...
eSystem::OpenGlContextDestroy();
}
void Java_org_ewol_Ewol_onStop(JNIEnv* env, jobject thiz)
{
EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity On Stop **");
EWOL_DEBUG("*******************************************");
}
void Java_org_ewol_Ewol_onDestroy(JNIEnv* env, jobject thiz)
{
EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Activity On Destroy **");
EWOL_DEBUG("*******************************************");
eSystem::UnInit();
}
/* ********************************************************************************************** /* **********************************************************************************************
* ** IO section : * ** IO section :
* ********************************************************************************************** */ * ********************************************************************************************** */
void Java_org_ewol_Ewol_inputEventMotion( JNIEnv* env, jobject thiz, jint pointerID, jfloat x, jfloat y ) void Java_org_ewol_Ewol_inputEventMotion( JNIEnv* env, jobject thiz, jint pointerID, jfloat x, jfloat y )
{ {
eSystem::SetInputMotion(pointerID+1, x, m_currentHeight-y); eSystem::SetInputMotion(pointerID+1, x, m_currentHeight-y);
} }
void Java_org_ewol_Ewol_inputEventState( JNIEnv* env, jobject thiz, jint pointerID, jboolean isUp, jfloat x, jfloat y ) void Java_org_ewol_Ewol_inputEventState( JNIEnv* env, jobject thiz, jint pointerID, jboolean isUp, jfloat x, jfloat y )
{ {
eSystem::SetInputState(pointerID+1, isUp, x, m_currentHeight-y); eSystem::SetInputState(pointerID+1, isUp, x, m_currentHeight-y);
} }
void Java_org_ewol_Ewol_mouseEventMotion( JNIEnv* env, jobject thiz, jint pointerID, jfloat x, jfloat y ) void Java_org_ewol_Ewol_mouseEventMotion( JNIEnv* env, jobject thiz, jint pointerID, jfloat x, jfloat y )
{ {
eSystem::SetMouseMotion(pointerID+1, x, m_currentHeight-y); eSystem::SetMouseMotion(pointerID+1, x, m_currentHeight-y);
} }
void Java_org_ewol_Ewol_mouseEventState( JNIEnv* env, jobject thiz, jint pointerID, jboolean isUp, jfloat x, jfloat y ) void Java_org_ewol_Ewol_mouseEventState( JNIEnv* env, jobject thiz, jint pointerID, jboolean isUp, jfloat x, jfloat y )
{ {
eSystem::SetMouseState(pointerID+1, isUp, x, m_currentHeight-y); eSystem::SetMouseState(pointerID+1, isUp, x, m_currentHeight-y);
} }
void Java_org_ewol_Ewol_unknowEvent( JNIEnv* env, jobject thiz, jint pointerID) void Java_org_ewol_Ewol_unknowEvent( JNIEnv* env, jobject thiz, jint pointerID)
{ {
EWOL_DEBUG("Unknown IO event : " << pointerID << " ???"); EWOL_DEBUG("Unknown IO event : " << pointerID << " ???");
} }
void Java_org_ewol_Ewol_keyboardEventMove( JNIEnv* env, jobject thiz, jint type, jboolean isdown) void Java_org_ewol_Ewol_keyboardEventMove( JNIEnv* env, jobject thiz, jint type, jboolean isdown)
{ {
EWOL_DEBUG("IO keyboard Move event : \"" << type << "\" is down=" << isdown); EWOL_DEBUG("IO keyboard Move event : \"" << type << "\" is down=" << isdown);
} }
void Java_org_ewol_Ewol_keyboardEventKey( JNIEnv* env, jobject thiz, jint uniChar, jboolean isdown) void Java_org_ewol_Ewol_keyboardEventKey( JNIEnv* env, jobject thiz, jint uniChar, jboolean isdown)
{ {
EWOL_DEBUG("IO keyboard Key event : \"" << uniChar << "\" is down=" << isdown); EWOL_DEBUG("IO keyboard Key event : \"" << uniChar << "\" is down=" << isdown);
eSystem::SetKeyboard(guiKeyBoardSpecialKeyMode, uniChar, isdown); eSystem::SetKeyboard(guiKeyBoardSpecialKeyMode, uniChar, isdown);
} }
void Java_org_ewol_Ewol_displayPropertyMetrics( JNIEnv* env, jobject thiz, jfloat ratioX, jfloat ratioY) void Java_org_ewol_Ewol_displayPropertyMetrics( JNIEnv* env, jobject thiz, jfloat ratioX, jfloat ratioY)
{ {
// set the internal system ratio properties ... // set the internal system ratio properties ...
ewol::dimension::SetPixelRatio(vec2(ratioX,ratioY), ewol::Dimension::Inch); ewol::dimension::SetPixelRatio(vec2(ratioX,ratioY), ewol::Dimension::Inch);
} }
// TODO : Set a return true or false if we want to grep this event ... // TODO : Set a return true or false if we want to grep this event ...
void Java_org_ewol_Ewol_keyboardEventKeySystem( JNIEnv* env, jobject thiz, jint keyVal, jboolean isdown) void Java_org_ewol_Ewol_keyboardEventKeySystem( JNIEnv* env, jobject thiz, jint keyVal, jboolean isdown)
{ {
switch (keyVal) switch (keyVal) {
{ case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_VOLUME_UP:
case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_VOLUME_UP: EWOL_DEBUG("IO keyboard Key System \"VOLUME_UP\" is down=" << isdown);
EWOL_DEBUG("IO keyboard Key System \"VOLUME_UP\" is down=" << isdown); break;
break; case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_VOLUME_DOWN:
case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_VOLUME_DOWN: EWOL_DEBUG("IO keyboard Key System \"VOLUME_DOWN\" is down=" << isdown);
EWOL_DEBUG("IO keyboard Key System \"VOLUME_DOWN\" is down=" << isdown); break;
break; case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_MENU:
case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_MENU: EWOL_DEBUG("IO keyboard Key System \"MENU\" is down=" << isdown);
EWOL_DEBUG("IO keyboard Key System \"MENU\" is down=" << isdown); break;
break; case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_CAMERA:
case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_CAMERA: EWOL_DEBUG("IO keyboard Key System \"CAMERA\" is down=" << isdown);
EWOL_DEBUG("IO keyboard Key System \"CAMERA\" is down=" << isdown); break;
break; case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_HOME:
case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_HOME: EWOL_DEBUG("IO keyboard Key System \"HOME\" is down=" << isdown);
EWOL_DEBUG("IO keyboard Key System \"HOME\" is down=" << isdown); break;
break; case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_POWER:
case org_ewol_EwolConstants_EWOL_SYSTEM_KEY_POWER: EWOL_DEBUG("IO keyboard Key System \"POWER\" is down=" << isdown);
EWOL_DEBUG("IO keyboard Key System \"POWER\" is down=" << isdown); break;
break; default:
default: EWOL_DEBUG("IO keyboard Key System event : \"" << keyVal << "\" is down=" << isdown);
EWOL_DEBUG("IO keyboard Key System event : \"" << keyVal << "\" is down=" << isdown); break;
break; }
} }
}
/* ********************************************************************************************** /* **********************************************************************************************
* ** Renderer section : * ** Renderer section :
* ********************************************************************************************** */ * ********************************************************************************************** */
void Java_org_ewol_Ewol_renderInit(JNIEnv* env, jobject thiz) void Java_org_ewol_Ewol_renderInit(JNIEnv* env, jobject thiz)
{ {
} }
void Java_org_ewol_Ewol_renderResize( JNIEnv* env, jobject thiz, jint w, jint h ) void Java_org_ewol_Ewol_renderResize( JNIEnv* env, jobject thiz, jint w, jint h )
{ {
m_currentHeight = h; m_currentHeight = h;
eSystem::Resize(w, h); eSystem::Resize(w, h);
} }
void Java_org_ewol_Ewol_renderDraw(JNIEnv* env, jobject thiz) void Java_org_ewol_Ewol_renderDraw(JNIEnv* env, jobject thiz)
{ {
eSystem::Draw(true); eSystem::Draw(true);
} }
void Java_org_ewol_Ewol_audioPlayback(JNIEnv* env, void* reserved, jshortArray location, jint frameRate, jint nbChannels) void Java_org_ewol_Ewol_audioPlayback(JNIEnv* env, void* reserved, jshortArray location, jint frameRate, jint nbChannels)
{ {
// Get the short* pointer from the Java array // Get the short* pointer from the Java array
jboolean isCopy; jboolean isCopy;
jshort* dst = env->GetShortArrayElements(location, &isCopy); jshort* dst = env->GetShortArrayElements(location, &isCopy);
if (NULL != dst) { if (NULL != dst) {
ewol::audio::GetData(dst, frameRate, nbChannels); ewol::audio::GetData(dst, frameRate, nbChannels);
} }
//APPL_DEBUG("IO Audio event request: Frames=" << frameRate << " channels=" << nbChannels); //APPL_DEBUG("IO Audio event request: Frames=" << frameRate << " channels=" << nbChannels);
// TODO : Understand why it did not work corectly ... // TODO : Understand why it did not work corectly ...
//if (isCopy == JNI_TRUE) { //if (isCopy == JNI_TRUE) {
// Release the short* pointer // Release the short* pointer
env->ReleaseShortArrayElements(location, dst, 0); env->ReleaseShortArrayElements(location, dst, 0);
//} //}
} }
}; };
@ -455,81 +471,81 @@ extern "C"
int guiInterface::main(int argc, const char *argv[]) int guiInterface::main(int argc, const char *argv[])
{ {
// unneeded fuction, all is controlled by android java ... // unneeded fuction, all is controlled by android java ...
return 0; return 0;
} }
int64_t guiInterface::GetTime(void) int64_t guiInterface::GetTime(void)
{ {
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
//EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us"); //EWOL_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us");
return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_usec); return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_usec);
} }
void guiInterface::SetTitle(etk::UString& title) void guiInterface::SetTitle(etk::UString& title)
{ {
SendJavaSetTitle(title.c_str()); SendJavaSetTitle(title.c_str());
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// ClipBoard AREA : // ClipBoard AREA :
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool l_clipBoardOwnerStd = false; bool l_clipBoardOwnerStd = false;
void guiInterface::ClipBoardGet(ewol::clipBoard::clipboardListe_te clipboardID) void guiInterface::ClipBoardGet(ewol::clipBoard::clipboardListe_te clipboardID)
{ {
// this is to force the local system to think we have the buffer // this is to force the local system to think we have the buffer
// TODO : Remove this 2 Line when code will be writen // TODO : Remove this 2 Line when code will be writen
l_clipBoardOwnerStd = true; l_clipBoardOwnerStd = true;
switch (clipboardID) switch (clipboardID)
{ {
case ewol::clipBoard::clipboardSelection: case ewol::clipBoard::clipboardSelection:
// NOTE : Windows does not support the middle button the we do it internaly // NOTE : Windows does not support the middle button the we do it internaly
// just transmit an event , we have the data in the system // just transmit an event , we have the data in the system
eSystem::ClipBoardArrive(clipboardID); eSystem::ClipBoardArrive(clipboardID);
break; break;
case ewol::clipBoard::clipboardStd: case ewol::clipBoard::clipboardStd:
if (false == l_clipBoardOwnerStd) { if (false == l_clipBoardOwnerStd) {
// Generate a request TO the OS // Generate a request TO the OS
// TODO : Send the message to the OS "We disire to receive the copy buffer ... // TODO : Send the message to the OS "We disire to receive the copy buffer ...
} else { } else {
// just transmit an event , we have the data in the system // just transmit an event , we have the data in the system
eSystem::ClipBoardArrive(clipboardID); eSystem::ClipBoardArrive(clipboardID);
} }
break; break;
default: default:
EWOL_ERROR("Request an unknow ClipBoard ..."); EWOL_ERROR("Request an unknow ClipBoard ...");
break; break;
} }
} }
void guiInterface::ClipBoardSet(ewol::clipBoard::clipboardListe_te clipboardID) void guiInterface::ClipBoardSet(ewol::clipBoard::clipboardListe_te clipboardID)
{ {
switch (clipboardID) switch (clipboardID)
{ {
case ewol::clipBoard::clipboardSelection: case ewol::clipBoard::clipboardSelection:
// NOTE : nothing to do : Windows deas ot supported Middle button // NOTE : nothing to do : Windows deas ot supported Middle button
break; break;
case ewol::clipBoard::clipboardStd: case ewol::clipBoard::clipboardStd:
// Request the clipBoard : // Request the clipBoard :
if (false == l_clipBoardOwnerStd) { if (false == l_clipBoardOwnerStd) {
// TODO : Inform the OS that we have the current buffer of copy ... // TODO : Inform the OS that we have the current buffer of copy ...
l_clipBoardOwnerStd = true; l_clipBoardOwnerStd = true;
} }
break; break;
default: default:
EWOL_ERROR("Request an unknow ClipBoard ..."); EWOL_ERROR("Request an unknow ClipBoard ...");
break; break;
} }
} }
void guiInterface::Stop(void) void guiInterface::Stop(void)
{ {
// TODO : send a message to the android system to stop ... // TODO : send a message to the android system to stop ...
} }
// java system to send message : // java system to send message :
@ -538,49 +554,49 @@ void SendJavaKeyboardUpdate(bool showIt);
void guiInterface::KeyboardShow(void) void guiInterface::KeyboardShow(void)
{ {
// send a message at the java : // send a message at the java :
SendJavaKeyboardUpdate(true); SendJavaKeyboardUpdate(true);
} }
void guiInterface::KeyboardHide(void) void guiInterface::KeyboardHide(void)
{ {
// send a message at the java : // send a message at the java :
SendJavaKeyboardUpdate(false); SendJavaKeyboardUpdate(false);
} }
void guiInterface::ChangeSize(ivec2 size) void guiInterface::ChangeSize(ivec2 size)
{ {
// The size can not be change on android platform // The size can not be change on android platform
} }
void guiInterface::ChangePos(ivec2 size) void guiInterface::ChangePos(ivec2 size)
{ {
// The position can not be change on Android platform // The position can not be change on Android platform
} }
void guiInterface::GetAbsPos(ivec2& size) void guiInterface::GetAbsPos(ivec2& size)
{ {
size.setValue(0,0); size.setValue(0,0);
} }
void guiInterface::ForceOrientation(ewol::orientation_te orientation) void guiInterface::ForceOrientation(ewol::orientation_te orientation)
{ {
SendJavaOrientationUpdate((int32_t)orientation); SendJavaOrientationUpdate((int32_t)orientation);
} }
void guiInterface::GrabPointerEvents(bool isGrabbed, vec2 forcedPosition) void guiInterface::GrabPointerEvents(bool isGrabbed, vec2 forcedPosition)
{ {
// nothing to do ... // nothing to do ...
} }
void guiInterface::SetCursor(ewol::cursorDisplay_te newCursor) void guiInterface::SetCursor(ewol::cursorDisplay_te newCursor)
{ {
// nothing to do ... // nothing to do ...
} }
void guiInterface::SetIcon(etk::UString inputFile) void guiInterface::SetIcon(etk::UString inputFile)
{ {
// nothing to do ... // nothing to do ...
} }