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