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