blob: 1ccb6a8f610c57915a2b16e7e8f4bbacc611c033 [file] [log] [blame]
John Reck04fc5832014-02-05 16:38:25 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
19#include "jni.h"
20#include "GraphicsJNI.h"
21#include <nativehelper/JNIHelp.h>
22
Andreas Gampeed6b9df2014-11-20 22:02:20 -080023#include "core_jni_helpers.h"
John Reck04fc5832014-02-05 16:38:25 -080024#include <android_runtime/android_graphics_SurfaceTexture.h>
25
26#include <gui/GLConsumer.h>
sergeyvdccca442016-03-21 15:38:21 -070027#include <hwui/Paint.h>
John Reck04fc5832014-02-05 16:38:25 -080028
29#include <SkBitmap.h>
30#include <SkCanvas.h>
31#include <SkMatrix.h>
Mike Reedc2f31df2016-10-28 17:21:45 -040032#include <SkBlendMode.h>
John Reck04fc5832014-02-05 16:38:25 -080033
34#include <DeferredLayerUpdater.h>
John Reck04fc5832014-02-05 16:38:25 -080035#include <Rect.h>
John Reck113e0822014-03-18 09:22:59 -070036#include <RenderNode.h>
John Reck04fc5832014-02-05 16:38:25 -080037
38namespace android {
39
40using namespace uirenderer;
41
John Reck9d8d99d2018-02-21 12:55:41 -080042static jboolean TextureLayer_prepare(JNIEnv* env, jobject clazz,
John Reck04fc5832014-02-05 16:38:25 -080043 jlong layerUpdaterPtr, jint width, jint height, jboolean isOpaque) {
44 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
45 bool changed = false;
46 changed |= layer->setSize(width, height);
47 changed |= layer->setBlend(!isOpaque);
48 return changed;
49}
50
John Reck9d8d99d2018-02-21 12:55:41 -080051static void TextureLayer_setLayerPaint(JNIEnv* env, jobject clazz,
Derek Sollenberger674554f2014-02-19 16:47:32 +000052 jlong layerUpdaterPtr, jlong paintPtr) {
John Reck04fc5832014-02-05 16:38:25 -080053 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
54 if (layer) {
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040055 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
John Reck04fc5832014-02-05 16:38:25 -080056 layer->setPaint(paint);
John Reck04fc5832014-02-05 16:38:25 -080057 }
58}
59
John Reck9d8d99d2018-02-21 12:55:41 -080060static void TextureLayer_setTransform(JNIEnv* env, jobject clazz,
John Reck04fc5832014-02-05 16:38:25 -080061 jlong layerUpdaterPtr, jlong matrixPtr) {
62 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
63 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
64 layer->setTransform(matrix);
65}
66
John Reck9d8d99d2018-02-21 12:55:41 -080067static void TextureLayer_setSurfaceTexture(JNIEnv* env, jobject clazz,
sergeyv00eb43d2017-02-13 14:34:15 -080068 jlong layerUpdaterPtr, jobject surface) {
John Reck04fc5832014-02-05 16:38:25 -080069 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
Stan Iliev564ca3e2018-09-04 22:00:00 +000070 layer->setSurfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface));
John Reck04fc5832014-02-05 16:38:25 -080071}
72
John Reck9d8d99d2018-02-21 12:55:41 -080073static void TextureLayer_updateSurfaceTexture(JNIEnv* env, jobject clazz,
John Reck04fc5832014-02-05 16:38:25 -080074 jlong layerUpdaterPtr) {
75 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
76 layer->updateTexImage();
77}
78
John Reck04fc5832014-02-05 16:38:25 -080079// ----------------------------------------------------------------------------
80// JNI Glue
81// ----------------------------------------------------------------------------
82
John Reck9d8d99d2018-02-21 12:55:41 -080083const char* const kClassPathName = "android/view/TextureLayer";
John Reck04fc5832014-02-05 16:38:25 -080084
Daniel Micay76f6a862015-09-19 17:31:01 -040085static const JNINativeMethod gMethods[] = {
John Reck9d8d99d2018-02-21 12:55:41 -080086 { "nPrepare", "(JIIZ)Z", (void*) TextureLayer_prepare },
87 { "nSetLayerPaint", "(JJ)V", (void*) TextureLayer_setLayerPaint },
88 { "nSetTransform", "(JJ)V", (void*) TextureLayer_setTransform },
sergeyv00eb43d2017-02-13 14:34:15 -080089 { "nSetSurfaceTexture", "(JLandroid/graphics/SurfaceTexture;)V",
John Reck9d8d99d2018-02-21 12:55:41 -080090 (void*) TextureLayer_setSurfaceTexture },
91 { "nUpdateSurfaceTexture", "(J)V", (void*) TextureLayer_updateSurfaceTexture },
John Reck04fc5832014-02-05 16:38:25 -080092};
93
John Reck9d8d99d2018-02-21 12:55:41 -080094int register_android_view_TextureLayer(JNIEnv* env) {
Andreas Gampeed6b9df2014-11-20 22:02:20 -080095 return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
John Reck04fc5832014-02-05 16:38:25 -080096}
97
98};