OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2012 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 package com.skia; | |
9 | |
10 import android.opengl.GLSurfaceView; | |
11 import android.os.Handler; | |
12 import android.util.Log; | |
13 | |
14 import javax.microedition.khronos.egl.EGLConfig; | |
15 import javax.microedition.khronos.opengles.GL10; | |
16 import javax.microedition.khronos.opengles.GL11; | |
17 | |
18 public class SkiaSampleRenderer implements GLSurfaceView.Renderer { | |
19 | |
20 private final SkiaSampleView mSampleView; | |
21 private Handler mHandler = new Handler(); | |
22 private int mMSAASampleCount; | |
23 private String mCmdLineFlags; | |
24 | |
25 SkiaSampleRenderer(SkiaSampleView view, String cmdLineFlags) { | |
26 mSampleView = view; | |
27 mCmdLineFlags = cmdLineFlags; | |
28 } | |
29 | |
30 @Override | |
31 public void onDrawFrame(GL10 gl) { | |
32 draw(); | |
33 } | |
34 | |
35 @Override | |
36 public void onSurfaceChanged(GL10 gl, int width, int height) { | |
37 updateSize(width, height); | |
38 } | |
39 | |
40 @Override | |
41 public void onSurfaceCreated(GL10 gl, EGLConfig config) { | |
42 if (gl instanceof GL11) { | |
43 int value[] = new int[1]; | |
44 ((GL11) gl).glGetIntegerv(GL11.GL_SAMPLES, value, 0); | |
45 if (value[0] == 1) { | |
46 mMSAASampleCount = 0; | |
47 } else { | |
48 mMSAASampleCount = value[0]; | |
49 } | |
50 } | |
51 | |
52 gl.glClearStencil(0); | |
53 gl.glClear(GL10.GL_STENCIL_BUFFER_BIT); | |
54 | |
55 init((SkiaSampleActivity)mSampleView.getContext(), mCmdLineFlags, mMSAAS
ampleCount); | |
56 } | |
57 | |
58 // Called by JNI and the view. | |
59 synchronized public int getMSAASampleCount() { | |
60 return mMSAASampleCount; | |
61 } | |
62 | |
63 // Called by JNI | |
64 private void startTimer(int ms) { | |
65 // After the delay, queue an event to the Renderer's thread | |
66 // to handle the event on the timer queue | |
67 mHandler.postDelayed(new Runnable() { | |
68 @Override | |
69 public void run() { | |
70 mSampleView.queueEvent(new Runnable() { | |
71 @Override | |
72 public void run() { | |
73 serviceQueueTimer(); | |
74 } | |
75 }); | |
76 } | |
77 }, ms); | |
78 } | |
79 | |
80 // Called by JNI | |
81 private void queueSkEvent() { | |
82 mSampleView.queueEvent(new Runnable() { | |
83 @Override | |
84 public void run() { | |
85 processSkEvent(); | |
86 } | |
87 }); | |
88 } | |
89 | |
90 // Called by JNI | |
91 private void requestRender() { | |
92 mSampleView.requestRender(); | |
93 } | |
94 | |
95 native void init(SkiaSampleActivity activity, String flags, int msaaSampleCo
unt); | |
96 native void term(); | |
97 native void draw(); | |
98 native void updateSize(int w, int h); | |
99 native void handleClick(int owner, float x, float y, int state); | |
100 native void showOverview(); | |
101 native void nextSample(); | |
102 native void previousSample(); | |
103 native void goToSample(int position); | |
104 native void toggleRenderingMode(); | |
105 native void toggleSlideshow(); | |
106 native void toggleFPS(); | |
107 native void toggleTiling(); | |
108 native void toggleBBox(); | |
109 native void processSkEvent(); | |
110 native void serviceQueueTimer(); | |
111 native void saveToPDF(); | |
112 native void postInval(); | |
113 } | |
OLD | NEW |