blob: e14c46f8b1c12d5e313bb22d72274d551a76f3d1 [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 <SkiaShader.h>
36#include <Rect.h>
John Reck113e0822014-03-18 09:22:59 -070037#include <RenderNode.h>
John Reck04fc5832014-02-05 16:38:25 -080038
39namespace android {
40
41using namespace uirenderer;
42
John Reck9d8d99d2018-02-21 12:55:41 -080043static jboolean TextureLayer_prepare(JNIEnv* env, jobject clazz,
John Reck04fc5832014-02-05 16:38:25 -080044 jlong layerUpdaterPtr, jint width, jint height, jboolean isOpaque) {
45 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
46 bool changed = false;
47 changed |= layer->setSize(width, height);
48 changed |= layer->setBlend(!isOpaque);
49 return changed;
50}
51
John Reck9d8d99d2018-02-21 12:55:41 -080052static void TextureLayer_setLayerPaint(JNIEnv* env, jobject clazz,
Derek Sollenberger674554f2014-02-19 16:47:32 +000053 jlong layerUpdaterPtr, jlong paintPtr) {
John Reck04fc5832014-02-05 16:38:25 -080054 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
55 if (layer) {
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040056 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
John Reck04fc5832014-02-05 16:38:25 -080057 layer->setPaint(paint);
John Reck04fc5832014-02-05 16:38:25 -080058 }
59}
60
John Reck9d8d99d2018-02-21 12:55:41 -080061static void TextureLayer_setTransform(JNIEnv* env, jobject clazz,
John Reck04fc5832014-02-05 16:38:25 -080062 jlong layerUpdaterPtr, jlong matrixPtr) {
63 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
64 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
65 layer->setTransform(matrix);
66}
67
John Reck9d8d99d2018-02-21 12:55:41 -080068static void TextureLayer_setSurfaceTexture(JNIEnv* env, jobject clazz,
sergeyv00eb43d2017-02-13 14:34:15 -080069 jlong layerUpdaterPtr, jobject surface) {
John Reck04fc5832014-02-05 16:38:25 -080070 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
71 sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface));
sergeyv00eb43d2017-02-13 14:34:15 -080072 layer->setSurfaceTexture(surfaceTexture);
John Reck04fc5832014-02-05 16:38:25 -080073}
74
John Reck9d8d99d2018-02-21 12:55:41 -080075static void TextureLayer_updateSurfaceTexture(JNIEnv* env, jobject clazz,
John Reck04fc5832014-02-05 16:38:25 -080076 jlong layerUpdaterPtr) {
77 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
78 layer->updateTexImage();
79}
80
John Reck04fc5832014-02-05 16:38:25 -080081// ----------------------------------------------------------------------------
82// JNI Glue
83// ----------------------------------------------------------------------------
84
John Reck9d8d99d2018-02-21 12:55:41 -080085const char* const kClassPathName = "android/view/TextureLayer";
John Reck04fc5832014-02-05 16:38:25 -080086
Daniel Micay76f6a862015-09-19 17:31:01 -040087static const JNINativeMethod gMethods[] = {
John Reck9d8d99d2018-02-21 12:55:41 -080088 { "nPrepare", "(JIIZ)Z", (void*) TextureLayer_prepare },
89 { "nSetLayerPaint", "(JJ)V", (void*) TextureLayer_setLayerPaint },
90 { "nSetTransform", "(JJ)V", (void*) TextureLayer_setTransform },
sergeyv00eb43d2017-02-13 14:34:15 -080091 { "nSetSurfaceTexture", "(JLandroid/graphics/SurfaceTexture;)V",
John Reck9d8d99d2018-02-21 12:55:41 -080092 (void*) TextureLayer_setSurfaceTexture },
93 { "nUpdateSurfaceTexture", "(J)V", (void*) TextureLayer_updateSurfaceTexture },
John Reck04fc5832014-02-05 16:38:25 -080094};
95
John Reck9d8d99d2018-02-21 12:55:41 -080096int register_android_view_TextureLayer(JNIEnv* env) {
Andreas Gampeed6b9df2014-11-20 22:02:20 -080097 return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
John Reck04fc5832014-02-05 16:38:25 -080098}
99
100};