aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleRenderer.java
blob: 55257094cdd090415a2a0e02ebb75cbdc0626e24 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright 2012 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;

import android.opengl.GLSurfaceView;
import android.os.Handler;
import android.util.Log;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;

public class SkiaSampleRenderer implements GLSurfaceView.Renderer {

    private final SkiaSampleView mSampleView;
    private Handler mHandler = new Handler();
    private int mMSAASampleCount;
    private String mCmdLineFlags;

    SkiaSampleRenderer(SkiaSampleView view, String cmdLineFlags) {
        mSampleView = view;
        mCmdLineFlags = cmdLineFlags;
    }

    @Override
    public void onDrawFrame(GL10 gl) {
        draw();
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        updateSize(width, height);
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        if (gl instanceof GL11) {
            int value[] = new int[1];
            ((GL11) gl).glGetIntegerv(GL11.GL_SAMPLES, value, 0);
            if (value[0] == 1) {
                mMSAASampleCount = 0;
            } else {
                mMSAASampleCount = value[0];
            }
        }

        gl.glClearStencil(0);
        gl.glClear(GL10.GL_STENCIL_BUFFER_BIT);

        init((SkiaSampleActivity)mSampleView.getContext(), mCmdLineFlags, mMSAASampleCount);
    }

    // Called by JNI and the view.
    synchronized public int getMSAASampleCount() {
        return mMSAASampleCount;
    }

    // Called by JNI
    private void startTimer(int ms) {
        // After the delay, queue an event to the Renderer's thread
        // to handle the event on the timer queue
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mSampleView.queueEvent(new Runnable() {
                    @Override
                    public void run() {
                        serviceQueueTimer();
                    }
                });
            }
        }, ms);
    }

    // Called by JNI
    private void queueSkEvent() {
        mSampleView.queueEvent(new Runnable() {
            @Override
            public void run() {
                processSkEvent();
            }
        });
    }

    // Called by JNI
    private void requestRender() {
        mSampleView.requestRender();
    }

    native void init(SkiaSampleActivity activity, String flags, int msaaSampleCount);
    native void term();
    native void draw();
    native void updateSize(int w, int h);
    native void handleClick(int owner, float x, float y, int state);
    native void showOverview();
    native void nextSample();
    native void previousSample();
    native void goToSample(int position);
    native void toggleRenderingMode();
    native void toggleSlideshow();
    native void toggleFPS();
    native void toggleTiling();
    native void toggleBBox();
    native void processSkEvent();
    native void serviceQueueTimer();
    native void saveToPDF();
    native void postInval();
}