aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java
blob: 1479c9239659832120105eb7081f2535c0f79c11 (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
/*
 * 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 javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class SkiaSampleRenderer implements GLSurfaceView.Renderer {

    private final SkiaSampleView mSampleView;
    private Handler mHandler = new Handler();

    SkiaSampleRenderer(SkiaSampleView view) {
        mSampleView = view;
    }

    @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) {
        gl.glClearStencil(0);
        gl.glClear(GL10.GL_STENCIL_BUFFER_BIT);
        init((SkiaSampleActivity)mSampleView.getContext());
    }

    // 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);
    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();
}