blob: 3a0ddc9fa825fb6d711e29485a0f945f53889380 [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>
27
Sergei Vasilinetcafbd0f12016-03-21 21:03:40 +000028#include <Paint.h>
John Reck04fc5832014-02-05 16:38:25 -080029#include <SkBitmap.h>
30#include <SkCanvas.h>
31#include <SkMatrix.h>
John Reck04fc5832014-02-05 16:38:25 -080032#include <SkXfermode.h>
33
34#include <DeferredLayerUpdater.h>
John Reck04fc5832014-02-05 16:38:25 -080035#include <LayerRenderer.h>
36#include <SkiaShader.h>
37#include <Rect.h>
John Reck113e0822014-03-18 09:22:59 -070038#include <RenderNode.h>
John Reck04fc5832014-02-05 16:38:25 -080039
40namespace android {
41
42using namespace uirenderer;
43
John Reck04fc5832014-02-05 16:38:25 -080044static jboolean android_view_HardwareLayer_prepare(JNIEnv* env, jobject clazz,
45 jlong layerUpdaterPtr, jint width, jint height, jboolean isOpaque) {
46 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
47 bool changed = false;
48 changed |= layer->setSize(width, height);
49 changed |= layer->setBlend(!isOpaque);
50 return changed;
51}
52
53static void android_view_HardwareLayer_setLayerPaint(JNIEnv* env, jobject clazz,
Derek Sollenberger674554f2014-02-19 16:47:32 +000054 jlong layerUpdaterPtr, jlong paintPtr) {
John Reck04fc5832014-02-05 16:38:25 -080055 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
56 if (layer) {
Behdad Esfahbod6ba30b82014-07-15 16:22:32 -040057 Paint* paint = reinterpret_cast<Paint*>(paintPtr);
John Reck04fc5832014-02-05 16:38:25 -080058 layer->setPaint(paint);
John Reck04fc5832014-02-05 16:38:25 -080059 }
60}
61
62static void android_view_HardwareLayer_setTransform(JNIEnv* env, jobject clazz,
63 jlong layerUpdaterPtr, jlong matrixPtr) {
64 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
65 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
66 layer->setTransform(matrix);
67}
68
69static void android_view_HardwareLayer_setSurfaceTexture(JNIEnv* env, jobject clazz,
70 jlong layerUpdaterPtr, jobject surface, jboolean isAlreadyAttached) {
71 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
72 sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface));
73 layer->setSurfaceTexture(surfaceTexture, !isAlreadyAttached);
74}
75
76static void android_view_HardwareLayer_updateSurfaceTexture(JNIEnv* env, jobject clazz,
77 jlong layerUpdaterPtr) {
78 DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
79 layer->updateTexImage();
80}
81
John Reck04fc5832014-02-05 16:38:25 -080082// ----------------------------------------------------------------------------
83// JNI Glue
84// ----------------------------------------------------------------------------
85
86const char* const kClassPathName = "android/view/HardwareLayer";
87
Daniel Micay76f6a862015-09-19 17:31:01 -040088static const JNINativeMethod gMethods[] = {
John Reck04fc5832014-02-05 16:38:25 -080089 { "nPrepare", "(JIIZ)Z", (void*) android_view_HardwareLayer_prepare },
Derek Sollenberger674554f2014-02-19 16:47:32 +000090 { "nSetLayerPaint", "(JJ)V", (void*) android_view_HardwareLayer_setLayerPaint },
John Reck04fc5832014-02-05 16:38:25 -080091 { "nSetTransform", "(JJ)V", (void*) android_view_HardwareLayer_setTransform },
92 { "nSetSurfaceTexture", "(JLandroid/graphics/SurfaceTexture;Z)V",
93 (void*) android_view_HardwareLayer_setSurfaceTexture },
94 { "nUpdateSurfaceTexture", "(J)V", (void*) android_view_HardwareLayer_updateSurfaceTexture },
John Reck04fc5832014-02-05 16:38:25 -080095};
96
97int register_android_view_HardwareLayer(JNIEnv* env) {
Andreas Gampeed6b9df2014-11-20 22:02:20 -080098 return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
John Reck04fc5832014-02-05 16:38:25 -080099}
100
101};