summaryrefslogtreecommitdiffstats
path: root/core/jni/android_view_GLES20Canvas.cpp
blob: 8c2a04cb27068f315addcf3ba5263956a89e88e6 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "jni.h"
#include <nativehelper/JNIHelp.h>
#include <android_runtime/AndroidRuntime.h>

#include <SkXfermode.h>

#include <OpenGLRenderer.h>

#define UI ((OpenGLRenderer*) renderer)

namespace android {

// ----------------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------------

static OpenGLRenderer* android_view_GLES20Renderer_createRenderer(JNIEnv* env, jobject canvas) {
    return new OpenGLRenderer;
}

static void android_view_GLES20Renderer_destroyRenderer(JNIEnv* env, jobject canvas, jint renderer) {
    delete UI;
}

// ----------------------------------------------------------------------------
// Setup
// ----------------------------------------------------------------------------

static void android_view_GLES20Renderer_setViewport(JNIEnv* env, jobject canvas, jint renderer,
        jint width, jint height) {

    UI->setViewport(width, height);
}

static void android_view_GLES20Renderer_prepare(JNIEnv* env, jobject canvas, jint renderer) {

    UI->prepare();
}

// ----------------------------------------------------------------------------
// State
// ----------------------------------------------------------------------------

static jint android_view_GLES20Renderer_save(JNIEnv* env, jobject canvas, jint renderer,
        jint flags) {

    return UI->save(flags);
}

static jint android_view_GLES20Renderer_getSaveCount(JNIEnv* env, jobject canvas, jint renderer) {
    return UI->getSaveCount();
}

static void android_view_GLES20Renderer_restore(JNIEnv* env, jobject canvas, jint renderer) {
    UI->restore();
}

static void android_view_GLES20Renderer_restoreToCount(JNIEnv* env, jobject canvas, jint renderer,
        jint saveCount) {

    UI->restoreToCount(saveCount);
}

// ----------------------------------------------------------------------------
// Clipping
// ----------------------------------------------------------------------------

static bool android_view_GLES20Renderer_clipRectF(JNIEnv* env, jobject canvas, jint renderer,
        jfloat left, jfloat top, jfloat right, jfloat bottom) {

    return UI->clipRect(left, top, right, bottom);
}

static bool android_view_GLES20Renderer_clipRect(JNIEnv* env, jobject canvas, jint renderer,
        jint left, jint top, jint right, jint bottom) {

    return UI->clipRect(float(left), float(top), float(right), float(bottom));
}

// ----------------------------------------------------------------------------
// Drawing
// ----------------------------------------------------------------------------

static void android_view_GLES20Renderer_drawColor(JNIEnv* env, jobject canvas, jint renderer,
        jint color, jint mode) {

    UI->drawColor(color, (SkXfermode::Mode) mode);
}

// ----------------------------------------------------------------------------
// JNI Glue
// ----------------------------------------------------------------------------

const char* const kClassPathName = "android/view/GLES20Canvas";

static JNINativeMethod gMethods[] = {
    {   "nCreateRenderer",    "()I",      (void*) android_view_GLES20Renderer_createRenderer },
    {   "nDestroyRenderer",   "(I)V",     (void*) android_view_GLES20Renderer_destroyRenderer },
    {   "nSetViewport",       "(III)V",   (void*) android_view_GLES20Renderer_setViewport },
    {   "nPrepare",           "(I)V",     (void*) android_view_GLES20Renderer_prepare },

    {   "nSave",              "(II)I",    (void*) android_view_GLES20Renderer_save },
    {   "nRestore",           "(I)V",     (void*) android_view_GLES20Renderer_restore },
    {   "nRestoreToCount",    "(II)V",    (void*) android_view_GLES20Renderer_restoreToCount },
    {   "nGetSaveCount",      "(I)I",     (void*) android_view_GLES20Renderer_getSaveCount },

    {   "nClipRect",          "(IFFFF)Z", (void*) android_view_GLES20Renderer_clipRectF },
    {   "nClipRect",          "(IIIII)Z", (void*) android_view_GLES20Renderer_clipRect },

    {   "nDrawColor",         "(III)V",   (void*) android_view_GLES20Renderer_drawColor },
};

int register_android_view_GLES20Canvas(JNIEnv* env) {
    return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
}

};