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