The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Mathias Agopian | fae5cb2 | 2010-06-04 18:26:32 -0700 | [diff] [blame] | 17 | #define LOG_TAG "Surface" |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 21 | #include "jni.h" |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 22 | #include <nativehelper/JNIHelp.h> |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 23 | #include "android_os_Parcel.h" |
Robert Carr | a35e5de | 2017-03-03 17:04:54 -0800 | [diff] [blame] | 24 | #include "android/graphics/GraphicBuffer.h" |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 25 | #include "android/graphics/GraphicsJNI.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 27 | #include "core_jni_helpers.h" |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 28 | #include <android_runtime/android_view_Surface.h> |
| 29 | #include <android_runtime/android_graphics_SurfaceTexture.h> |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 30 | #include <android_runtime/Log.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 31 | |
Mathias Agopian | 4a05f43 | 2013-03-12 18:43:34 -0700 | [diff] [blame] | 32 | #include <binder/Parcel.h> |
| 33 | |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 34 | #include <gui/Surface.h> |
Mathias Agopian | 7a1e28d | 2017-02-08 17:07:13 -0800 | [diff] [blame] | 35 | #include <gui/view/Surface.h> |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 36 | #include <gui/SurfaceControl.h> |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 37 | #include <gui/GLConsumer.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 38 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | #include <ui/Rect.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 40 | #include <ui/Region.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
| 42 | #include <SkCanvas.h> |
| 43 | #include <SkBitmap.h> |
Leon Scroggins III | 8790be6 | 2013-12-03 16:26:51 -0500 | [diff] [blame] | 44 | #include <SkImage.h> |
Mathias Agopian | 6158b1b | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 45 | #include <SkRegion.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | #include <utils/misc.h> |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 48 | #include <utils/Log.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 50 | #include <nativehelper/ScopedUtfChars.h> |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 51 | |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 52 | #include <AnimationContext.h> |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 53 | #include <FrameInfo.h> |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 54 | #include <RenderNode.h> |
| 55 | #include <renderthread/RenderProxy.h> |
| 56 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | // ---------------------------------------------------------------------------- |
| 58 | |
| 59 | namespace android { |
| 60 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | static const char* const OutOfResourcesException = |
| 62 | "android/view/Surface$OutOfResourcesException"; |
| 63 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 64 | static struct { |
| 65 | jclass clazz; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 66 | jfieldID mNativeObject; |
Jeff Brown | fc0ebd7 | 2013-04-30 16:33:00 -0700 | [diff] [blame] | 67 | jfieldID mLock; |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 68 | jmethodID ctor; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 69 | } gSurfaceClassInfo; |
tedbo | 0503161 | 2011-06-06 16:02:47 -0700 | [diff] [blame] | 70 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 71 | static struct { |
| 72 | jfieldID left; |
| 73 | jfieldID top; |
| 74 | jfieldID right; |
| 75 | jfieldID bottom; |
| 76 | } gRectClassInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 78 | // ---------------------------------------------------------------------------- |
| 79 | |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 80 | // this is just a pointer we use to pass to inc/decStrong |
| 81 | static const void *sRefBaseOwner; |
| 82 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 83 | bool android_view_Surface_isInstanceOf(JNIEnv* env, jobject obj) { |
| 84 | return env->IsInstanceOf(obj, gSurfaceClassInfo.clazz); |
| 85 | } |
| 86 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 87 | sp<ANativeWindow> android_view_Surface_getNativeWindow(JNIEnv* env, jobject surfaceObj) { |
| 88 | return android_view_Surface_getSurface(env, surfaceObj); |
| 89 | } |
| 90 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 91 | sp<Surface> android_view_Surface_getSurface(JNIEnv* env, jobject surfaceObj) { |
Mathias Agopian | 7c116b5 | 2013-03-18 20:27:02 -0700 | [diff] [blame] | 92 | sp<Surface> sur; |
| 93 | jobject lock = env->GetObjectField(surfaceObj, |
Jeff Brown | fc0ebd7 | 2013-04-30 16:33:00 -0700 | [diff] [blame] | 94 | gSurfaceClassInfo.mLock); |
Mathias Agopian | 7c116b5 | 2013-03-18 20:27:02 -0700 | [diff] [blame] | 95 | if (env->MonitorEnter(lock) == JNI_OK) { |
| 96 | sur = reinterpret_cast<Surface *>( |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 97 | env->GetLongField(surfaceObj, gSurfaceClassInfo.mNativeObject)); |
Mathias Agopian | 7c116b5 | 2013-03-18 20:27:02 -0700 | [diff] [blame] | 98 | env->MonitorExit(lock); |
| 99 | } |
Andy McFadden | 5ad3ab8 | 2014-06-11 15:22:32 -0700 | [diff] [blame] | 100 | env->DeleteLocalRef(lock); |
Mathias Agopian | 7c116b5 | 2013-03-18 20:27:02 -0700 | [diff] [blame] | 101 | return sur; |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Jiwen 'Steve' Cai | d28e828 | 2017-03-31 11:19:50 -0700 | [diff] [blame] | 104 | jobject android_view_Surface_createFromSurface(JNIEnv* env, const sp<Surface>& surface) { |
Chong Zhang | af608e8 | 2014-01-29 12:52:15 -0800 | [diff] [blame] | 105 | jobject surfaceObj = env->NewObject(gSurfaceClassInfo.clazz, |
| 106 | gSurfaceClassInfo.ctor, (jlong)surface.get()); |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 107 | if (surfaceObj == NULL) { |
| 108 | if (env->ExceptionCheck()) { |
Andy McFadden | d47f7d8 | 2012-12-18 09:48:38 -0800 | [diff] [blame] | 109 | ALOGE("Could not create instance of Surface from IGraphicBufferProducer."); |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 110 | LOGE_EX(env); |
| 111 | env->ExceptionClear(); |
| 112 | } |
| 113 | return NULL; |
| 114 | } |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 115 | surface->incStrong(&sRefBaseOwner); |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 116 | return surfaceObj; |
| 117 | } |
| 118 | |
Jiwen 'Steve' Cai | d28e828 | 2017-03-31 11:19:50 -0700 | [diff] [blame] | 119 | jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env, |
| 120 | const sp<IGraphicBufferProducer>& bufferProducer) { |
| 121 | if (bufferProducer == NULL) { |
| 122 | return NULL; |
| 123 | } |
| 124 | |
| 125 | sp<Surface> surface(new Surface(bufferProducer, true)); |
| 126 | return android_view_Surface_createFromSurface(env, surface); |
| 127 | } |
| 128 | |
Eino-Ville Talvala | 805f3c9 | 2015-02-26 10:57:55 -0800 | [diff] [blame] | 129 | int android_view_Surface_mapPublicFormatToHalFormat(PublicFormat f) { |
Jooyung Han | 63f5f92 | 2019-02-21 14:43:45 +0900 | [diff] [blame] | 130 | return mapPublicFormatToHalFormat(f); |
Eino-Ville Talvala | 805f3c9 | 2015-02-26 10:57:55 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | android_dataspace android_view_Surface_mapPublicFormatToHalDataspace( |
| 134 | PublicFormat f) { |
Jooyung Han | 63f5f92 | 2019-02-21 14:43:45 +0900 | [diff] [blame] | 135 | return mapPublicFormatToHalDataspace(f); |
Eino-Ville Talvala | 805f3c9 | 2015-02-26 10:57:55 -0800 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | PublicFormat android_view_Surface_mapHalFormatDataspaceToPublicFormat( |
| 139 | int format, android_dataspace dataSpace) { |
Jooyung Han | 63f5f92 | 2019-02-21 14:43:45 +0900 | [diff] [blame] | 140 | return mapHalFormatDataspaceToPublicFormat(format, dataSpace); |
Eino-Ville Talvala | 805f3c9 | 2015-02-26 10:57:55 -0800 | [diff] [blame] | 141 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 142 | // ---------------------------------------------------------------------------- |
| 143 | |
Mathias Agopian | f3d3b4d | 2013-02-19 18:26:15 -0800 | [diff] [blame] | 144 | static inline bool isSurfaceValid(const sp<Surface>& sur) { |
| 145 | return Surface::isValid(sur); |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // ---------------------------------------------------------------------------- |
| 149 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 150 | static jlong nativeCreateFromSurfaceTexture(JNIEnv* env, jclass clazz, |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 151 | jobject surfaceTextureObj) { |
Mathias Agopian | 52a9a10 | 2013-08-02 01:38:38 -0700 | [diff] [blame] | 152 | sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(env, surfaceTextureObj)); |
| 153 | if (producer == NULL) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 154 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 155 | "SurfaceTexture has already been released"); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 156 | return 0; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Mathias Agopian | 52a9a10 | 2013-08-02 01:38:38 -0700 | [diff] [blame] | 159 | sp<Surface> surface(new Surface(producer, true)); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 160 | if (surface == NULL) { |
| 161 | jniThrowException(env, OutOfResourcesException, NULL); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 162 | return 0; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 165 | surface->incStrong(&sRefBaseOwner); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 166 | return jlong(surface.get()); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 169 | static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 170 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject)); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 171 | sur->decStrong(&sRefBaseOwner); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 174 | static jboolean nativeIsValid(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 175 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject)); |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 176 | return isSurfaceValid(sur) ? JNI_TRUE : JNI_FALSE; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 179 | static jboolean nativeIsConsumerRunningBehind(JNIEnv* env, jclass clazz, jlong nativeObject) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 180 | sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject)); |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 181 | if (!isSurfaceValid(sur)) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 182 | doThrowIAE(env); |
| 183 | return JNI_FALSE; |
| 184 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 185 | int value = 0; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 186 | ANativeWindow* anw = static_cast<ANativeWindow*>(sur.get()); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 187 | anw->query(anw, NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND, &value); |
| 188 | return value; |
| 189 | } |
| 190 | |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 191 | static inline SkColorType convertPixelFormat(PixelFormat format) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 192 | /* note: if PIXEL_FORMAT_RGBX_8888 means that all alpha bytes are 0xFF, then |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 193 | we can map to kN32_SkColorType, and optionally call |
Leon Scroggins III | 8790be6 | 2013-12-03 16:26:51 -0500 | [diff] [blame] | 194 | bitmap.setAlphaType(kOpaque_SkAlphaType) on the resulting SkBitmap |
| 195 | (as an accelerator) |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 196 | */ |
| 197 | switch (format) { |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 198 | case PIXEL_FORMAT_RGBX_8888: return kN32_SkColorType; |
| 199 | case PIXEL_FORMAT_RGBA_8888: return kN32_SkColorType; |
Romain Guy | 9505a65 | 2016-12-14 09:43:50 -0800 | [diff] [blame] | 200 | case PIXEL_FORMAT_RGBA_FP16: return kRGBA_F16_SkColorType; |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 201 | case PIXEL_FORMAT_RGB_565: return kRGB_565_SkColorType; |
| 202 | default: return kUnknown_SkColorType; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 206 | static jlong nativeLockCanvas(JNIEnv* env, jclass clazz, |
| 207 | jlong nativeObject, jobject canvasObj, jobject dirtyRectObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 208 | sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject)); |
| 209 | |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 210 | if (!isSurfaceValid(surface)) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 211 | doThrowIAE(env); |
Andy McFadden | ed55c8d | 2013-08-20 10:05:51 -0700 | [diff] [blame] | 212 | return 0; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Pablo Ceballos | 8270292 | 2015-08-07 17:28:03 -0700 | [diff] [blame] | 215 | Rect dirtyRect(Rect::EMPTY_RECT); |
Mathias Agopian | 667809e | 2013-04-17 14:57:41 -0700 | [diff] [blame] | 216 | Rect* dirtyRectPtr = NULL; |
| 217 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 218 | if (dirtyRectObj) { |
Mathias Agopian | 667809e | 2013-04-17 14:57:41 -0700 | [diff] [blame] | 219 | dirtyRect.left = env->GetIntField(dirtyRectObj, gRectClassInfo.left); |
| 220 | dirtyRect.top = env->GetIntField(dirtyRectObj, gRectClassInfo.top); |
| 221 | dirtyRect.right = env->GetIntField(dirtyRectObj, gRectClassInfo.right); |
| 222 | dirtyRect.bottom = env->GetIntField(dirtyRectObj, gRectClassInfo.bottom); |
| 223 | dirtyRectPtr = &dirtyRect; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 226 | ANativeWindow_Buffer outBuffer; |
Mathias Agopian | 667809e | 2013-04-17 14:57:41 -0700 | [diff] [blame] | 227 | status_t err = surface->lock(&outBuffer, dirtyRectPtr); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 228 | if (err < 0) { |
| 229 | const char* const exception = (err == NO_MEMORY) ? |
| 230 | OutOfResourcesException : |
| 231 | "java/lang/IllegalArgumentException"; |
| 232 | jniThrowException(env, exception, NULL); |
Andy McFadden | ed55c8d | 2013-08-20 10:05:51 -0700 | [diff] [blame] | 233 | return 0; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 236 | SkImageInfo info = SkImageInfo::Make(outBuffer.width, outBuffer.height, |
| 237 | convertPixelFormat(outBuffer.format), |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 238 | outBuffer.format == PIXEL_FORMAT_RGBX_8888 |
Derek Sollenberger | b100231 | 2018-08-02 10:15:09 -0400 | [diff] [blame] | 239 | ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 240 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 241 | SkBitmap bitmap; |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 242 | ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format); |
Mike Reed | b933055 | 2014-06-16 17:31:48 -0400 | [diff] [blame] | 243 | bitmap.setInfo(info, bpr); |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 244 | if (outBuffer.width > 0 && outBuffer.height > 0) { |
| 245 | bitmap.setPixels(outBuffer.bits); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 246 | } else { |
| 247 | // be safe with an empty bitmap. |
| 248 | bitmap.setPixels(NULL); |
| 249 | } |
Derek Sollenberger | fc615a0 | 2012-12-20 14:39:57 -0500 | [diff] [blame] | 250 | |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 251 | Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvasObj); |
| 252 | nativeCanvas->setBitmap(bitmap); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 253 | |
Mathias Agopian | 667809e | 2013-04-17 14:57:41 -0700 | [diff] [blame] | 254 | if (dirtyRectPtr) { |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 255 | nativeCanvas->clipRect(dirtyRect.left, dirtyRect.top, |
Mike Reed | 6c67f1d | 2016-12-14 10:29:54 -0500 | [diff] [blame] | 256 | dirtyRect.right, dirtyRect.bottom, SkClipOp::kIntersect); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 259 | if (dirtyRectObj) { |
Mathias Agopian | 667809e | 2013-04-17 14:57:41 -0700 | [diff] [blame] | 260 | env->SetIntField(dirtyRectObj, gRectClassInfo.left, dirtyRect.left); |
| 261 | env->SetIntField(dirtyRectObj, gRectClassInfo.top, dirtyRect.top); |
| 262 | env->SetIntField(dirtyRectObj, gRectClassInfo.right, dirtyRect.right); |
| 263 | env->SetIntField(dirtyRectObj, gRectClassInfo.bottom, dirtyRect.bottom); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 264 | } |
Andy McFadden | ed55c8d | 2013-08-20 10:05:51 -0700 | [diff] [blame] | 265 | |
| 266 | // Create another reference to the surface and return it. This reference |
| 267 | // should be passed to nativeUnlockCanvasAndPost in place of mNativeObject, |
| 268 | // because the latter could be replaced while the surface is locked. |
| 269 | sp<Surface> lockedSurface(surface); |
| 270 | lockedSurface->incStrong(&sRefBaseOwner); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 271 | return (jlong) lockedSurface.get(); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Jeff Brown | fc0ebd7 | 2013-04-30 16:33:00 -0700 | [diff] [blame] | 274 | static void nativeUnlockCanvasAndPost(JNIEnv* env, jclass clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 275 | jlong nativeObject, jobject canvasObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 276 | sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject)); |
Mathias Agopian | 5280061 | 2013-02-14 17:11:20 -0800 | [diff] [blame] | 277 | if (!isSurfaceValid(surface)) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 278 | return; |
| 279 | } |
| 280 | |
| 281 | // detach the canvas from the surface |
John Reck | c1b33d6 | 2015-04-22 09:04:45 -0700 | [diff] [blame] | 282 | Canvas* nativeCanvas = GraphicsJNI::getNativeCanvas(env, canvasObj); |
| 283 | nativeCanvas->setBitmap(SkBitmap()); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 284 | |
| 285 | // unlock surface |
| 286 | status_t err = surface->unlockAndPost(); |
| 287 | if (err < 0) { |
| 288 | doThrowIAE(env); |
| 289 | } |
| 290 | } |
| 291 | |
Dan Stoza | 5795d64 | 2014-06-20 13:01:36 -0700 | [diff] [blame] | 292 | static void nativeAllocateBuffers(JNIEnv* /* env */ , jclass /* clazz */, |
| 293 | jlong nativeObject) { |
| 294 | sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject)); |
| 295 | if (!isSurfaceValid(surface)) { |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | surface->allocateBuffers(); |
| 300 | } |
| 301 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 302 | // ---------------------------------------------------------------------------- |
| 303 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 304 | static jlong nativeCreateFromSurfaceControl(JNIEnv* env, jclass clazz, |
| 305 | jlong surfaceControlNativeObj) { |
Bryce Lee | 02949f1 | 2017-06-16 07:20:34 -0700 | [diff] [blame] | 306 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj)); |
| 307 | sp<Surface> surface(ctrl->createSurface()); |
| 308 | if (surface != NULL) { |
| 309 | surface->incStrong(&sRefBaseOwner); |
| 310 | } |
| 311 | return reinterpret_cast<jlong>(surface.get()); |
| 312 | } |
| 313 | |
| 314 | static jlong nativeGetFromSurfaceControl(JNIEnv* env, jclass clazz, |
Robert Carr | d568672 | 2019-01-25 14:30:52 -0800 | [diff] [blame] | 315 | jlong nativeObject, |
Bryce Lee | 02949f1 | 2017-06-16 07:20:34 -0700 | [diff] [blame] | 316 | jlong surfaceControlNativeObj) { |
Robert Carr | d568672 | 2019-01-25 14:30:52 -0800 | [diff] [blame] | 317 | Surface* self(reinterpret_cast<Surface *>(nativeObject)); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 318 | sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj)); |
Robert Carr | d568672 | 2019-01-25 14:30:52 -0800 | [diff] [blame] | 319 | |
| 320 | // If the underlying IGBP's are the same, we don't need to do anything. |
| 321 | if (self != nullptr && |
| 322 | IInterface::asBinder(self->getIGraphicBufferProducer()) == |
| 323 | IInterface::asBinder(ctrl->getIGraphicBufferProducer())) { |
| 324 | return nativeObject; |
| 325 | } |
| 326 | |
Jeff Brown | fc0ebd7 | 2013-04-30 16:33:00 -0700 | [diff] [blame] | 327 | sp<Surface> surface(ctrl->getSurface()); |
| 328 | if (surface != NULL) { |
| 329 | surface->incStrong(&sRefBaseOwner); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | } |
Robert Carr | d568672 | 2019-01-25 14:30:52 -0800 | [diff] [blame] | 331 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 332 | return reinterpret_cast<jlong>(surface.get()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 335 | static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, |
| 336 | jlong nativeObject, jobject parcelObj) { |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 337 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 338 | if (parcel == NULL) { |
| 339 | doThrowNPE(env); |
| 340 | return 0; |
| 341 | } |
Mathias Agopian | c3b9cd6 | 2013-03-13 16:07:57 -0700 | [diff] [blame] | 342 | |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 343 | android::view::Surface surfaceShim; |
| 344 | |
| 345 | // Calling code in Surface.java has already read the name of the Surface |
| 346 | // from the Parcel |
| 347 | surfaceShim.readFromParcel(parcel, /*nameAlreadyRead*/true); |
| 348 | |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 349 | sp<Surface> self(reinterpret_cast<Surface *>(nativeObject)); |
Mathias Agopian | c3b9cd6 | 2013-03-13 16:07:57 -0700 | [diff] [blame] | 350 | |
| 351 | // update the Surface only if the underlying IGraphicBufferProducer |
| 352 | // has changed. |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 353 | if (self != nullptr |
| 354 | && (IInterface::asBinder(self->getIGraphicBufferProducer()) == |
| 355 | IInterface::asBinder(surfaceShim.graphicBufferProducer))) { |
Mathias Agopian | c3b9cd6 | 2013-03-13 16:07:57 -0700 | [diff] [blame] | 356 | // same IGraphicBufferProducer, return ourselves |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 357 | return jlong(self.get()); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 358 | } |
Mathias Agopian | 4a05f43 | 2013-03-12 18:43:34 -0700 | [diff] [blame] | 359 | |
| 360 | sp<Surface> sur; |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 361 | if (surfaceShim.graphicBufferProducer != nullptr) { |
Mathias Agopian | c3b9cd6 | 2013-03-13 16:07:57 -0700 | [diff] [blame] | 362 | // we have a new IGraphicBufferProducer, create a new Surface for it |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 363 | sur = new Surface(surfaceShim.graphicBufferProducer, true); |
Mathias Agopian | c3b9cd6 | 2013-03-13 16:07:57 -0700 | [diff] [blame] | 364 | // and keep a reference before passing to java |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 365 | sur->incStrong(&sRefBaseOwner); |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 366 | } |
Mathias Agopian | 4a05f43 | 2013-03-12 18:43:34 -0700 | [diff] [blame] | 367 | |
Mathias Agopian | c3b9cd6 | 2013-03-13 16:07:57 -0700 | [diff] [blame] | 368 | if (self != NULL) { |
| 369 | // and loose the java reference to ourselves |
| 370 | self->decStrong(&sRefBaseOwner); |
| 371 | } |
| 372 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 373 | return jlong(sur.get()); |
Dianne Hackborn | 61566cc | 2011-12-02 23:31:52 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Mathias Agopian | 29479eb | 2013-02-14 14:36:04 -0800 | [diff] [blame] | 376 | static void nativeWriteToParcel(JNIEnv* env, jclass clazz, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 377 | jlong nativeObject, jobject parcelObj) { |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 378 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | if (parcel == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 380 | doThrowNPE(env); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | return; |
| 382 | } |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 383 | sp<Surface> self(reinterpret_cast<Surface *>(nativeObject)); |
Eino-Ville Talvala | 5d2d778 | 2015-12-17 16:50:50 -0800 | [diff] [blame] | 384 | android::view::Surface surfaceShim; |
| 385 | if (self != nullptr) { |
| 386 | surfaceShim.graphicBufferProducer = self->getIGraphicBufferProducer(); |
| 387 | } |
| 388 | // Calling code in Surface.java has already written the name of the Surface |
| 389 | // to the Parcel |
| 390 | surfaceShim.writeToParcel(parcel, /*nameAlreadyWritten*/true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | } |
| 392 | |
John Reck | b35c960 | 2014-11-13 16:15:08 -0800 | [diff] [blame] | 393 | static jint nativeGetWidth(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 394 | Surface* surface = reinterpret_cast<Surface*>(nativeObject); |
| 395 | ANativeWindow* anw = static_cast<ANativeWindow*>(surface); |
| 396 | int value = 0; |
| 397 | anw->query(anw, NATIVE_WINDOW_WIDTH, &value); |
| 398 | return value; |
| 399 | } |
| 400 | |
| 401 | static jint nativeGetHeight(JNIEnv* env, jclass clazz, jlong nativeObject) { |
| 402 | Surface* surface = reinterpret_cast<Surface*>(nativeObject); |
| 403 | ANativeWindow* anw = static_cast<ANativeWindow*>(surface); |
| 404 | int value = 0; |
| 405 | anw->query(anw, NATIVE_WINDOW_HEIGHT, &value); |
| 406 | return value; |
| 407 | } |
Robert Carr | cd9a18c | 2015-12-16 18:16:21 -0800 | [diff] [blame] | 408 | |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 409 | static jlong nativeGetNextFrameNumber(JNIEnv *env, jclass clazz, jlong nativeObject) { |
| 410 | Surface* surface = reinterpret_cast<Surface*>(nativeObject); |
| 411 | return surface->getNextFrameNumber(); |
| 412 | } |
John Reck | b35c960 | 2014-11-13 16:15:08 -0800 | [diff] [blame] | 413 | |
Robert Carr | cd9a18c | 2015-12-16 18:16:21 -0800 | [diff] [blame] | 414 | static jint nativeSetScalingMode(JNIEnv *env, jclass clazz, jlong nativeObject, jint scalingMode) { |
| 415 | Surface* surface = reinterpret_cast<Surface*>(nativeObject); |
| 416 | return surface->setScalingMode(scalingMode); |
| 417 | } |
| 418 | |
Robert Carr | 387838b | 2016-09-07 14:12:44 -0700 | [diff] [blame] | 419 | static jint nativeForceScopedDisconnect(JNIEnv *env, jclass clazz, jlong nativeObject) { |
| 420 | Surface* surface = reinterpret_cast<Surface*>(nativeObject); |
| 421 | return surface->disconnect(-1, IGraphicBufferProducer::DisconnectMode::AllLocal); |
| 422 | } |
| 423 | |
Robert Carr | a35e5de | 2017-03-03 17:04:54 -0800 | [diff] [blame] | 424 | static jint nativeAttachAndQueueBuffer(JNIEnv *env, jclass clazz, jlong nativeObject, |
| 425 | jobject graphicBuffer) { |
| 426 | Surface* surface = reinterpret_cast<Surface*>(nativeObject); |
| 427 | sp<GraphicBuffer> bp = graphicBufferForJavaObject(env, graphicBuffer); |
Chavi Weingarten | d7ec64c | 2017-11-30 01:52:01 +0000 | [diff] [blame] | 428 | int err = Surface::attachAndQueueBuffer(surface, bp); |
Robert Carr | a35e5de | 2017-03-03 17:04:54 -0800 | [diff] [blame] | 429 | return err; |
| 430 | } |
| 431 | |
Romain Guy | 0bbf0b4 | 2017-07-20 08:57:07 -0700 | [diff] [blame] | 432 | static jint nativeSetSharedBufferModeEnabled(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 433 | jboolean enabled) { |
| 434 | Surface* surface = reinterpret_cast<Surface*>(nativeObject); |
Adrian Roos | c43dfdf | 2018-01-29 17:55:44 +0100 | [diff] [blame] | 435 | ANativeWindow* anw = static_cast<ANativeWindow*>(surface); |
| 436 | return anw->perform(surface, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE, int(enabled)); |
Romain Guy | 0bbf0b4 | 2017-07-20 08:57:07 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static jint nativeSetAutoRefreshEnabled(JNIEnv* env, jclass clazz, jlong nativeObject, |
| 440 | jboolean enabled) { |
| 441 | Surface* surface = reinterpret_cast<Surface*>(nativeObject); |
Adrian Roos | c43dfdf | 2018-01-29 17:55:44 +0100 | [diff] [blame] | 442 | ANativeWindow* anw = static_cast<ANativeWindow*>(surface); |
| 443 | return anw->perform(surface, NATIVE_WINDOW_SET_AUTO_REFRESH, int(enabled)); |
Romain Guy | 0bbf0b4 | 2017-07-20 08:57:07 -0700 | [diff] [blame] | 444 | } |
| 445 | |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 446 | namespace uirenderer { |
| 447 | |
| 448 | using namespace android::uirenderer::renderthread; |
| 449 | |
| 450 | class ContextFactory : public IContextFactory { |
| 451 | public: |
| 452 | virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) { |
| 453 | return new AnimationContext(clock); |
| 454 | } |
| 455 | }; |
| 456 | |
Peiyong Lin | d8b6871 | 2018-03-06 18:34:21 -0800 | [diff] [blame] | 457 | static jlong create(JNIEnv* env, jclass clazz, jlong rootNodePtr, jlong surfacePtr, |
| 458 | jboolean isWideColorGamut) { |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 459 | RenderNode* rootNode = reinterpret_cast<RenderNode*>(rootNodePtr); |
| 460 | sp<Surface> surface(reinterpret_cast<Surface*>(surfacePtr)); |
| 461 | ContextFactory factory; |
| 462 | RenderProxy* proxy = new RenderProxy(false, rootNode, &factory); |
| 463 | proxy->loadSystemProperties(); |
Peiyong Lin | d8b6871 | 2018-03-06 18:34:21 -0800 | [diff] [blame] | 464 | if (isWideColorGamut) { |
| 465 | proxy->setWideGamut(true); |
| 466 | } |
Stan Iliev | 768e393 | 2016-07-08 21:34:52 -0400 | [diff] [blame] | 467 | proxy->setSwapBehavior(SwapBehavior::kSwap_discardBuffer); |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 468 | proxy->setSurface(surface); |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 469 | // Shadows can't be used via this interface, so just set the light source |
John Reck | ab1080c | 2016-06-21 16:24:20 -0700 | [diff] [blame] | 470 | // to all 0s. |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 471 | proxy->setLightAlpha(0, 0); |
| 472 | proxy->setLightGeometry((Vector3){0, 0, 0}, 0); |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 473 | return (jlong) proxy; |
| 474 | } |
| 475 | |
| 476 | static void setSurface(JNIEnv* env, jclass clazz, jlong rendererPtr, jlong surfacePtr) { |
| 477 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(rendererPtr); |
| 478 | sp<Surface> surface(reinterpret_cast<Surface*>(surfacePtr)); |
John Reck | 8785ceb | 2018-10-29 16:45:58 -0700 | [diff] [blame] | 479 | proxy->setSurface(surface); |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static void draw(JNIEnv* env, jclass clazz, jlong rendererPtr) { |
| 483 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(rendererPtr); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 484 | nsecs_t vsync = systemTime(CLOCK_MONOTONIC); |
| 485 | UiFrameInfoBuilder(proxy->frameInfo()) |
| 486 | .setVsync(vsync, vsync) |
Chris Craik | 1b54fb2 | 2015-06-02 17:40:58 -0700 | [diff] [blame] | 487 | .addFlag(FrameInfoFlags::SurfaceCanvas); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 488 | proxy->syncAndDrawFrame(); |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | static void destroy(JNIEnv* env, jclass clazz, jlong rendererPtr) { |
| 492 | RenderProxy* proxy = reinterpret_cast<RenderProxy*>(rendererPtr); |
| 493 | delete proxy; |
| 494 | } |
| 495 | |
| 496 | } // uirenderer |
| 497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 500 | namespace hwui = android::uirenderer; |
| 501 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 502 | static const JNINativeMethod gSurfaceMethods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 503 | {"nativeCreateFromSurfaceTexture", "(Landroid/graphics/SurfaceTexture;)J", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 504 | (void*)nativeCreateFromSurfaceTexture }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 505 | {"nativeRelease", "(J)V", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 506 | (void*)nativeRelease }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 507 | {"nativeIsValid", "(J)Z", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 508 | (void*)nativeIsValid }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 509 | {"nativeIsConsumerRunningBehind", "(J)Z", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 510 | (void*)nativeIsConsumerRunningBehind }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 511 | {"nativeLockCanvas", "(JLandroid/graphics/Canvas;Landroid/graphics/Rect;)J", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 512 | (void*)nativeLockCanvas }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 513 | {"nativeUnlockCanvasAndPost", "(JLandroid/graphics/Canvas;)V", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 514 | (void*)nativeUnlockCanvasAndPost }, |
Dan Stoza | 5795d64 | 2014-06-20 13:01:36 -0700 | [diff] [blame] | 515 | {"nativeAllocateBuffers", "(J)V", |
| 516 | (void*)nativeAllocateBuffers }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 517 | {"nativeCreateFromSurfaceControl", "(J)J", |
Jeff Brown | fc0ebd7 | 2013-04-30 16:33:00 -0700 | [diff] [blame] | 518 | (void*)nativeCreateFromSurfaceControl }, |
Robert Carr | d568672 | 2019-01-25 14:30:52 -0800 | [diff] [blame] | 519 | {"nativeGetFromSurfaceControl", "(JJ)J", |
Bryce Lee | 02949f1 | 2017-06-16 07:20:34 -0700 | [diff] [blame] | 520 | (void*)nativeGetFromSurfaceControl }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 521 | {"nativeReadFromParcel", "(JLandroid/os/Parcel;)J", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 522 | (void*)nativeReadFromParcel }, |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 523 | {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V", |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 524 | (void*)nativeWriteToParcel }, |
John Reck | b35c960 | 2014-11-13 16:15:08 -0800 | [diff] [blame] | 525 | {"nativeGetWidth", "(J)I", (void*)nativeGetWidth }, |
| 526 | {"nativeGetHeight", "(J)I", (void*)nativeGetHeight }, |
Rob Carr | 64e516f | 2015-10-29 00:20:45 +0000 | [diff] [blame] | 527 | {"nativeGetNextFrameNumber", "(J)J", (void*)nativeGetNextFrameNumber }, |
Robert Carr | cd9a18c | 2015-12-16 18:16:21 -0800 | [diff] [blame] | 528 | {"nativeSetScalingMode", "(JI)I", (void*)nativeSetScalingMode }, |
Robert Carr | 387838b | 2016-09-07 14:12:44 -0700 | [diff] [blame] | 529 | {"nativeForceScopedDisconnect", "(J)I", (void*)nativeForceScopedDisconnect}, |
Robert Carr | a35e5de | 2017-03-03 17:04:54 -0800 | [diff] [blame] | 530 | {"nativeAttachAndQueueBuffer", "(JLandroid/graphics/GraphicBuffer;)I", (void*)nativeAttachAndQueueBuffer}, |
Romain Guy | 0bbf0b4 | 2017-07-20 08:57:07 -0700 | [diff] [blame] | 531 | {"nativeSetSharedBufferModeEnabled", "(JZ)I", (void*)nativeSetSharedBufferModeEnabled}, |
| 532 | {"nativeSetAutoRefreshEnabled", "(JZ)I", (void*)nativeSetAutoRefreshEnabled}, |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 533 | |
| 534 | // HWUI context |
Peiyong Lin | d8b6871 | 2018-03-06 18:34:21 -0800 | [diff] [blame] | 535 | {"nHwuiCreate", "(JJZ)J", (void*) hwui::create }, |
John Reck | bb2d0cc | 2014-10-21 10:09:36 -0700 | [diff] [blame] | 536 | {"nHwuiSetSurface", "(JJ)V", (void*) hwui::setSurface }, |
| 537 | {"nHwuiDraw", "(J)V", (void*) hwui::draw }, |
| 538 | {"nHwuiDestroy", "(J)V", (void*) hwui::destroy }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | }; |
| 540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | int register_android_view_Surface(JNIEnv* env) |
| 542 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 543 | int err = RegisterMethodsOrDie(env, "android/view/Surface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | gSurfaceMethods, NELEM(gSurfaceMethods)); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 545 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 546 | jclass clazz = FindClassOrDie(env, "android/view/Surface"); |
| 547 | gSurfaceClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); |
| 548 | gSurfaceClassInfo.mNativeObject = GetFieldIDOrDie(env, |
| 549 | gSurfaceClassInfo.clazz, "mNativeObject", "J"); |
| 550 | gSurfaceClassInfo.mLock = GetFieldIDOrDie(env, |
| 551 | gSurfaceClassInfo.clazz, "mLock", "Ljava/lang/Object;"); |
| 552 | gSurfaceClassInfo.ctor = GetMethodIDOrDie(env, gSurfaceClassInfo.clazz, "<init>", "(J)V"); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 553 | |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 554 | clazz = FindClassOrDie(env, "android/graphics/Rect"); |
| 555 | gRectClassInfo.left = GetFieldIDOrDie(env, clazz, "left", "I"); |
| 556 | gRectClassInfo.top = GetFieldIDOrDie(env, clazz, "top", "I"); |
| 557 | gRectClassInfo.right = GetFieldIDOrDie(env, clazz, "right", "I"); |
| 558 | gRectClassInfo.bottom = GetFieldIDOrDie(env, clazz, "bottom", "I"); |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | return err; |
| 561 | } |
| 562 | |
| 563 | }; |