1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package com.skia.sampleapp;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.MotionEvent;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class SampleView extends GLSurfaceView {
private final SampleApp mApp;
public SampleView(SampleApp app) {
super(app);
mApp = app;
setEGLContextClientVersion(2);
setEGLConfigChooser(8,8,8,8,0,8);
setRenderer(new SampleView.Renderer());
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
public void postInval() {
queueEvent(new Runnable() {
@Override
public void run() {
mApp.postInval();
}
});
}
// Called by JNI
@SuppressWarnings("unused")
private void queueSkEvent() {
queueEvent(new Runnable() {
@Override
public void run() {
mApp.processSkEvent();
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int count = event.getPointerCount();
for (int i = 0; i < count; i++) {
final float x = event.getX(i);
final float y = event.getY(i);
final int owner = event.getPointerId(i);
int action = event.getAction() & MotionEvent.ACTION_MASK;
switch (action) {
case MotionEvent.ACTION_POINTER_UP:
action = MotionEvent.ACTION_UP;
break;
case MotionEvent.ACTION_POINTER_DOWN:
action = MotionEvent.ACTION_DOWN;
break;
default:
break;
}
final int finalAction = action;
queueEvent(new Runnable() {
@Override
public void run() {
mApp.handleClick(owner, x, y, finalAction);
}
});
}
return true;
}
private class Renderer implements GLSurfaceView.Renderer {
public void onDrawFrame(GL10 gl) {
mApp.draw();
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
mApp.updateSize(width, height);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearStencil(0);
gl.glClear(gl.GL_STENCIL_BUFFER_BIT);
mApp.init();
mApp.createOSWindow(SampleView.this);
}
}
}
|