1 /* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * xscreensaver, Copyright (c) 2016 Jamie Zawinski <jwz@jwz.org>
3 * and Dennis Sheil <dennis@panaceasupplies.com>
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation. No representations are made about the suitability of this
10 * software for any purpose. It is provided "as is" without express or
14 package org.jwz.xscreensaver;
17 import java.lang.RuntimeException;
18 import android.view.Display;
19 import android.view.WindowManager;
20 import android.view.Surface;
21 import android.view.KeyEvent;
22 import android.content.Context;
23 import android.graphics.Bitmap;
24 import android.opengl.GLSurfaceView;
25 import javax.microedition.khronos.egl.EGLConfig;
26 import javax.microedition.khronos.opengles.GL10;
27 import org.jwz.xscreensaver.jwxyz;
28 import android.os.Message;
29 import android.os.Handler;
30 import android.util.Log;
33 public class XScreenSaverRenderer implements GLSurfaceView.Renderer {
35 boolean initTried = false;
36 jwxyz jwxyz_obj = null;
40 Handler.Callback abort_callback;
42 Iterable<Map.Entry<String, String>> prefs;
47 private void LOG (String fmt, Object... args) {
48 Log.d ("xscreensaver",
49 this.getClass().getSimpleName() + ": " +
50 String.format (fmt, args));
53 private void except(Exception e) {
55 Message m = Message.obtain (null, 0, (Object) e);
56 abort_callback.handleMessage (m);
59 public XScreenSaverRenderer (String hack, int api,
60 Context app, WindowManager wm,
62 Handler.Callback abort_callback) {
69 this.screenshot = screenshot;
70 this.abort_callback = abort_callback;
71 LOG ("init %s %d", hack, api);
74 public void onDrawFrame (GL10 gl) {
76 if (jwxyz_obj != null)
77 jwxyz_obj.nativeRender();
78 } catch (RuntimeException e) {
83 public void onSurfaceChanged(GL10 gl, int w, int h) {
85 if (jwxyz_obj == null)
86 jwxyz_obj = new jwxyz (hack, api, app, screenshot, w, h);
90 Display d = wm.getDefaultDisplay();
92 switch (d.getRotation()) {
93 case Surface.ROTATION_90: r = 90; break;
94 case Surface.ROTATION_180: r = 180; break;
95 case Surface.ROTATION_270: r = 270; break;
96 default: r = 0; break;
99 jwxyz_obj.nativeResize (w, h, r);
101 } catch (RuntimeException e) {
106 public void onSurfaceCreated (GL10 gl, EGLConfig config) {
108 LOG ("onSurfaceCreated %s / %s / %s",
109 gl.glGetString (GL10.GL_VENDOR),
110 gl.glGetString (GL10.GL_RENDERER),
111 gl.glGetString (GL10.GL_VERSION));
116 if (jwxyz_obj != null) {
117 jwxyz_obj.nativeDone();
121 } catch (RuntimeException e) {
126 public void release() {
128 if (jwxyz_obj != null) {
129 jwxyz_obj.nativeDone();
132 } catch (RuntimeException e) {
137 public void sendButtonEvent (int x, int y, boolean down) {
139 jwxyz_obj.sendButtonEvent (x, y, down);
140 } catch (RuntimeException e) {
145 public void sendMotionEvent (int x, int y) {
147 jwxyz_obj.sendMotionEvent (x, y);
148 } catch (RuntimeException e) {
153 public void sendKeyEvent (KeyEvent event) {
155 jwxyz_obj.sendKeyEvent (event);
156 } catch (RuntimeException e) {
164 System.loadLibrary ("xscreensaver");