blob: b0f68cde14866ac3e261ef991ef984c71edd5a66 [file] [log] [blame]
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceControl"
Robert Carr6486d312017-01-09 19:48:29 -080018#define LOG_NDEBUG 0
Mathias Agopian3866f0d2013-02-11 22:08:48 -080019
Mathias Agopian3866f0d2013-02-11 22:08:48 -080020#include "android_os_Parcel.h"
21#include "android_util_Binder.h"
John Reckf29ed282015-04-07 07:32:03 -070022#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080023#include "android/graphics/GraphicsJNI.h"
24#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080025#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040026
Tom Cherry8ed74bb2017-07-10 14:31:18 -070027#include <android-base/chrono_utils.h>
Steven Moreland2279b252017-07-19 09:50:45 -070028#include <nativehelper/JNIHelp.h>
29#include <nativehelper/ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080030#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080031#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032#include <gui/Surface.h>
33#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040034#include <jni.h>
35#include <memory>
36#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070037#include <system/graphics.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080038#include <ui/DisplayInfo.h>
Svetoslav1376d602014-03-13 11:17:26 -070039#include <ui/FrameStats.h>
Peiyong Linb88549e2018-03-28 12:03:45 -070040#include <ui/GraphicTypes.h>
Peiyong Lin371b98f2018-03-14 17:29:10 -070041#include <ui/HdrCapabilities.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080042#include <ui/Rect.h>
43#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080044#include <utils/Log.h>
45
Mathias Agopian3866f0d2013-02-11 22:08:48 -080046// ----------------------------------------------------------------------------
47
48namespace android {
49
50static const char* const OutOfResourcesException =
51 "android/view/Surface$OutOfResourcesException";
52
53static struct {
Dan Stoza00101052014-05-02 15:23:40 -070054 jclass clazz;
55 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080056 jfieldID width;
57 jfieldID height;
58 jfieldID refreshRate;
59 jfieldID density;
60 jfieldID xDpi;
61 jfieldID yDpi;
62 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070063 jfieldID appVsyncOffsetNanos;
64 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080065} gPhysicalDisplayInfoClassInfo;
66
Dan Stoza9890e3412014-05-22 16:12:54 -070067static struct {
68 jfieldID bottom;
69 jfieldID left;
70 jfieldID right;
71 jfieldID top;
72} gRectClassInfo;
73
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050074// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
75void DeleteScreenshot(void* addr, void* context) {
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050076 delete ((ScreenshotClient*) context);
77}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080078
Svetoslav1376d602014-03-13 11:17:26 -070079static struct {
80 nsecs_t UNDEFINED_TIME_NANO;
81 jmethodID init;
82} gWindowContentFrameStatsClassInfo;
83
84static struct {
85 nsecs_t UNDEFINED_TIME_NANO;
86 jmethodID init;
87} gWindowAnimationFrameStatsClassInfo;
88
Hangyu Kuang54ac2192016-04-25 13:22:02 -070089static struct {
90 jclass clazz;
91 jmethodID ctor;
92} gHdrCapabilitiesClassInfo;
93
Robert Carr6486d312017-01-09 19:48:29 -080094static struct {
95 jclass clazz;
96 jmethodID builder;
97} gGraphicBufferClassInfo;
98
Mathias Agopian3866f0d2013-02-11 22:08:48 -080099// ----------------------------------------------------------------------------
100
Robert Carre13b58e2017-08-31 14:50:44 -0700101static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
102 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
103}
104
105static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
106 delete t;
107}
108
109static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
110 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
111}
112
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000113static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500114 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
115 jint windowType, jint ownerUid) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800116 ScopedUtfChars name(env, nameStr);
117 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
Robert Carr838120c2016-11-01 18:31:12 -0700118 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Robert Carrb0f39362018-03-14 13:52:25 -0700119 sp<SurfaceControl> surface;
120 status_t err = client->createSurfaceChecked(
121 String8(name.c_str()), w, h, format, &surface, flags, parent, windowType, ownerUid);
122 if (err == NAME_NOT_FOUND) {
123 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
124 return 0;
125 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800126 jniThrowException(env, OutOfResourcesException, NULL);
127 return 0;
128 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500129
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800130 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000131 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800132}
133
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000134static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800135 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800136 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800137}
138
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000139static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800140 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
141 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800142 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800143}
144
Chong Zhang47e36a32016-02-29 16:44:33 -0800145static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
146 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
147 if (ctrl != NULL) {
148 ctrl->disconnect();
149 }
150}
151
Robert Carr6486d312017-01-09 19:48:29 -0800152static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
153 int left = env->GetIntField(rectObj, gRectClassInfo.left);
154 int top = env->GetIntField(rectObj, gRectClassInfo.top);
155 int right = env->GetIntField(rectObj, gRectClassInfo.right);
156 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
157 return Rect(left, top, right, bottom);
158}
159
160static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz,
161 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
162 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
163 int rotation) {
164 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
165 if (displayToken == NULL) {
166 return NULL;
167 }
168 Rect sourceCrop = rectFromObj(env, sourceCropObj);
169 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800170 minLayer = INT32_MIN;
171 maxLayer = INT32_MAX;
Robert Carr6486d312017-01-09 19:48:29 -0800172 }
173 sp<GraphicBuffer> buffer;
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000174 status_t res = ScreenshotClient::capture(displayToken,
Robert Carr6486d312017-01-09 19:48:29 -0800175 sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform,
176 rotation, &buffer);
177 if (res != NO_ERROR) {
178 return NULL;
179 }
180
181 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
182 gGraphicBufferClassInfo.builder,
183 buffer->getWidth(),
184 buffer->getHeight(),
185 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700186 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100187 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800188}
189
Dan Stoza9890e3412014-05-22 16:12:54 -0700190static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
191 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700192 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
193 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800194 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
195 if (displayToken == NULL) {
196 return NULL;
197 }
198
Robert Carr6486d312017-01-09 19:48:29 -0800199 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Dan Stoza9890e3412014-05-22 16:12:54 -0700200
Ben Wagner60126ef2015-08-07 12:13:48 -0400201 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500202 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700203 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800204 minLayer = INT32_MIN;
205 maxLayer = INT32_MAX;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500206 }
Riley Andrews1d134062014-08-21 15:47:07 -0700207
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000208 sp<GraphicBuffer> buffer;
209 res = ScreenshotClient::capture(displayToken, sourceCrop, width, height,
210 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation), &buffer);
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500211 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800212 return NULL;
213 }
214
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400215 SkColorType colorType;
216 SkAlphaType alphaType;
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000217
218 PixelFormat format = buffer->getPixelFormat();
219 switch (format) {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500220 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400221 colorType = kRGBA_8888_SkColorType;
222 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500223 break;
224 }
225 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400226 colorType = kRGBA_8888_SkColorType;
227 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500228 break;
229 }
Romain Guy9505a652016-12-14 09:43:50 -0800230 case PIXEL_FORMAT_RGBA_FP16: {
231 colorType = kRGBA_F16_SkColorType;
232 alphaType = kPremul_SkAlphaType;
233 break;
234 }
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500235 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400236 colorType = kRGB_565_SkColorType;
237 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500238 break;
239 }
240 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500241 return NULL;
242 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800243 }
Romain Guy26a2b972017-04-17 09:39:51 -0700244
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000245 SkImageInfo info = SkImageInfo::Make(buffer->getWidth(), buffer->getHeight(),
246 colorType, alphaType,
247 SkColorSpace::MakeSRGB());
Romain Guy26a2b972017-04-17 09:39:51 -0700248
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000249 auto bitmap = sk_sp<Bitmap>(new Bitmap(buffer.get(), info));
250 return bitmap::createBitmap(env, bitmap.release(),
251 android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800252}
253
Dan Stoza9890e3412014-05-22 16:12:54 -0700254static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
255 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
256 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800257 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000258 if (displayToken == NULL) {
chaviw1cda84c2017-10-23 16:47:10 -0700259 return;
260 }
261
262 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
263 if (consumer == NULL) {
264 return;
265 }
266
chaviwfbe47df2017-11-10 16:14:49 -0800267 Rect sourceCrop;
268 if (sourceCropObj != NULL) {
269 sourceCrop = rectFromObj(env, sourceCropObj);
270 }
271
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000272 if (allLayers) {
273 minLayer = INT32_MIN;
274 maxLayer = INT32_MAX;
275 }
276
277 sp<GraphicBuffer> buffer;
278 ScreenshotClient::capture(displayToken, sourceCrop, width, height, minLayer, maxLayer,
279 useIdentityTransform, 0, &buffer);
280
281 Surface::attachAndQueueBuffer(consumer.get(), buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800282}
283
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000284static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
chaviwfbe47df2017-11-10 16:14:49 -0800285 jobject sourceCropObj, jfloat frameScale) {
286
287 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
288 if (layerHandle == NULL) {
289 return NULL;
290 }
291
292 Rect sourceCrop;
293 if (sourceCropObj != NULL) {
294 sourceCrop = rectFromObj(env, sourceCropObj);
295 }
296
297 sp<GraphicBuffer> buffer;
Robert Carrd87f3cf2018-03-07 14:08:09 -0800298 status_t res = ScreenshotClient::captureChildLayers(layerHandle, sourceCrop, frameScale, &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800299 if (res != NO_ERROR) {
300 return NULL;
301 }
302
303 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
304 gGraphicBufferClassInfo.builder,
305 buffer->getWidth(),
306 buffer->getHeight(),
307 buffer->getPixelFormat(),
308 (jint)buffer->getUsage(),
309 (jlong)buffer.get());
chaviw1cda84c2017-10-23 16:47:10 -0700310}
311
Robert Carre13b58e2017-08-31 14:50:44 -0700312static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
313 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
314 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800315}
316
Robert Carrb1579c82017-09-05 14:54:47 -0700317static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
318 jlong transactionObj, jlong otherTransactionObj) {
319 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
320 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
321 otherTransactionObj);
322 transaction->merge(std::move(*otherTransaction));
323}
324
Robert Carre13b58e2017-08-31 14:50:44 -0700325static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
326 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
327 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800328}
329
Robert Carre13b58e2017-08-31 14:50:44 -0700330static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
331 jlong nativeObject, jint zorder) {
332 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800333
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800334 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700335 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800336}
337
Robert Carre13b58e2017-08-31 14:50:44 -0700338static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
339 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700340 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700341
Robert Carraf422a82017-04-10 18:34:33 -0700342 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
343 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
344
Robert Carre13b58e2017-08-31 14:50:44 -0700345 {
346 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
347 transaction->setRelativeLayer(ctrl, handle, zorder);
348 }
Robert Carraf422a82017-04-10 18:34:33 -0700349}
350
Robert Carre13b58e2017-08-31 14:50:44 -0700351static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
352 jlong nativeObject, jfloat x, jfloat y) {
353 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
354
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800355 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700356 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800357}
358
Robert Carr6da3cc02016-06-16 15:17:07 -0700359static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700360jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700361 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700362 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
363
Robert Carra9408d42016-06-03 13:28:48 -0700364 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700365 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700366}
367
Robert Carre13b58e2017-08-31 14:50:44 -0700368static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
369 jlong nativeObject, jint w, jint h) {
370 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
371
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800372 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700373 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800374}
375
Robert Carre13b58e2017-08-31 14:50:44 -0700376static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
377 jlong nativeObject, jint flags, jint mask) {
378 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
379
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800380 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700381 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800382}
383
Robert Carre13b58e2017-08-31 14:50:44 -0700384static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
385 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800386 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
387 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
388 if (!region) {
389 doThrowIAE(env);
390 return;
391 }
392
393 const SkIRect& b(region->getBounds());
394 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
395 if (region->isComplex()) {
396 SkRegion::Iterator it(*region);
397 while (!it.done()) {
398 const SkIRect& r(it.rect());
399 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
400 it.next();
401 }
402 }
403
Robert Carre13b58e2017-08-31 14:50:44 -0700404 {
405 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
406 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800407 }
408}
409
Robert Carre13b58e2017-08-31 14:50:44 -0700410static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
411 jlong nativeObject, jfloat alpha) {
412 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
413
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800414 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700415 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800416}
417
Robert Carre13b58e2017-08-31 14:50:44 -0700418static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
419 jlong nativeObject, jfloatArray fColor) {
420 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700421 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700422
chaviw0dd03f52017-08-25 12:15:26 -0700423 float* floatColors = env->GetFloatArrayElements(fColor, 0);
424 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700425 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700426}
427
Robert Carre13b58e2017-08-31 14:50:44 -0700428static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
429 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800430 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700431 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
432
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800433 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700434 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800435}
436
Robert Carre13b58e2017-08-31 14:50:44 -0700437static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
438 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800439 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700440 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
441
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800442 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
443 Rect crop(l, t, r, b);
Robert Carre13b58e2017-08-31 14:50:44 -0700444 transaction->setCrop(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800445}
446
Robert Carre13b58e2017-08-31 14:50:44 -0700447static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
448 jlong nativeObject,
Pablo Ceballos27982e62016-03-09 10:50:45 -0800449 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700450 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
451
Pablo Ceballos27982e62016-03-09 10:50:45 -0800452 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
453 Rect crop(l, t, r, b);
Robert Carre13b58e2017-08-31 14:50:44 -0700454 transaction->setFinalCrop(ctrl, crop);
Pablo Ceballos27982e62016-03-09 10:50:45 -0800455}
456
Robert Carre13b58e2017-08-31 14:50:44 -0700457static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
458 jlong nativeObject, jint layerStack) {
459 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
460
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800461 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700462 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800463}
464
465static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
466 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
467 return javaObjectForIBinder(env, token);
468}
469
470static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
471 jboolean secure) {
472 ScopedUtfChars name(env, nameObj);
473 sp<IBinder> token(SurfaceComposerClient::createDisplay(
474 String8(name.c_str()), bool(secure)));
475 return javaObjectForIBinder(env, token);
476}
477
Jesse Hall6a6bc212013-08-08 12:15:03 -0700478static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
479 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
480 if (token == NULL) return;
481 SurfaceComposerClient::destroyDisplay(token);
482}
483
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800484static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700485 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000486 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800487 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
488 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800489 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800490 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800491 if (sur != NULL) {
492 bufferProducer = sur->getIGraphicBufferProducer();
493 }
Robert Carre13b58e2017-08-31 14:50:44 -0700494
495
496 status_t err = NO_ERROR;
497 {
498 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
499 err = transaction->setDisplaySurface(token,
500 bufferProducer);
501 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700502 if (err != NO_ERROR) {
503 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
504 " Surface created with singleBufferMode?");
505 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800506}
507
508static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700509 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800510 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700511
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800512 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
513 if (token == NULL) return;
514
Robert Carre13b58e2017-08-31 14:50:44 -0700515 {
516 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
517 transaction->setDisplayLayerStack(token, layerStack);
518 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800519}
520
521static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700522 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800523 jobject tokenObj, jint orientation,
524 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
525 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
526 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
527 if (token == NULL) return;
528 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
529 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700530
531 {
532 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
533 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
534 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800535}
536
Michael Wright01e840f2014-06-26 16:03:25 -0700537static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700538 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700539 jobject tokenObj, jint width, jint height) {
540 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
541 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700542
543 {
544 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
545 transaction->setDisplaySize(token, width, height);
546 }
Michael Wright01e840f2014-06-26 16:03:25 -0700547}
548
Dan Stoza00101052014-05-02 15:23:40 -0700549static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
550 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800551 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700552 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800553
Dan Stoza00101052014-05-02 15:23:40 -0700554 Vector<DisplayInfo> configs;
555 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
556 configs.size() == 0) {
557 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800558 }
559
Dan Stoza00101052014-05-02 15:23:40 -0700560 jobjectArray configArray = env->NewObjectArray(configs.size(),
561 gPhysicalDisplayInfoClassInfo.clazz, NULL);
562
563 for (size_t c = 0; c < configs.size(); ++c) {
564 const DisplayInfo& info = configs[c];
565 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
566 gPhysicalDisplayInfoClassInfo.ctor);
567 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
568 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
569 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
570 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
571 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
572 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
573 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700574 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
575 info.appVsyncOffset);
576 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
577 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700578 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
579 env->DeleteLocalRef(infoObj);
580 }
581
582 return configArray;
583}
584
585static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
586 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
587 if (token == NULL) return -1;
588 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
589}
590
591static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
592 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
593 if (token == NULL) return JNI_FALSE;
594 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
595 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800596}
597
Michael Wright1c9977b2016-07-12 13:30:10 -0700598static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
599 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
600 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700601 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700602 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
603 colorModes.isEmpty()) {
604 return NULL;
605 }
606
607 jintArray colorModesArray = env->NewIntArray(colorModes.size());
608 if (colorModesArray == NULL) {
609 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
610 return NULL;
611 }
612 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
613 for (size_t i = 0; i < colorModes.size(); i++) {
614 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
615 }
616 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
617 return colorModesArray;
618}
619
620static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
621 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
622 if (token == NULL) return -1;
623 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
624}
625
626static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
627 jobject tokenObj, jint colorMode) {
628 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
629 if (token == NULL) return JNI_FALSE;
630 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700631 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700632 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
633}
634
Prashant Malanic55929a2014-05-25 01:59:21 -0700635static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800636 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
637 if (token == NULL) return;
638
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700639 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700640 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700641 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800642}
643
Svetoslav1376d602014-03-13 11:17:26 -0700644static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
645 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
646 status_t err = ctrl->clearLayerFrameStats();
647
648 if (err < 0 && err != NO_INIT) {
649 doThrowIAE(env);
650 }
651
652 // The other end is not ready, just report we failed.
653 if (err == NO_INIT) {
654 return JNI_FALSE;
655 }
656
657 return JNI_TRUE;
658}
659
660static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
661 jobject outStats) {
662 FrameStats stats;
663
664 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
665 status_t err = ctrl->getLayerFrameStats(&stats);
666 if (err < 0 && err != NO_INIT) {
667 doThrowIAE(env);
668 }
669
670 // The other end is not ready, fine just return empty stats.
671 if (err == NO_INIT) {
672 return JNI_FALSE;
673 }
674
675 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
676 size_t frameCount = stats.desiredPresentTimesNano.size();
677
678 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
679 if (postedTimesNanoDst == NULL) {
680 return JNI_FALSE;
681 }
682
683 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
684 if (presentedTimesNanoDst == NULL) {
685 return JNI_FALSE;
686 }
687
688 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
689 if (readyTimesNanoDst == NULL) {
690 return JNI_FALSE;
691 }
692
693 nsecs_t postedTimesNanoSrc[frameCount];
694 nsecs_t presentedTimesNanoSrc[frameCount];
695 nsecs_t readyTimesNanoSrc[frameCount];
696
697 for (size_t i = 0; i < frameCount; i++) {
698 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
699 if (postedTimeNano == INT64_MAX) {
700 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
701 }
702 postedTimesNanoSrc[i] = postedTimeNano;
703
704 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
705 if (presentedTimeNano == INT64_MAX) {
706 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
707 }
708 presentedTimesNanoSrc[i] = presentedTimeNano;
709
710 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
711 if (readyTimeNano == INT64_MAX) {
712 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
713 }
714 readyTimesNanoSrc[i] = readyTimeNano;
715 }
716
717 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
718 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
719 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
720
721 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
722 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
723
724 if (env->ExceptionCheck()) {
725 return JNI_FALSE;
726 }
727
728 return JNI_TRUE;
729}
730
731static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
732 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
733
734 if (err < 0 && err != NO_INIT) {
735 doThrowIAE(env);
736 }
737
738 // The other end is not ready, just report we failed.
739 if (err == NO_INIT) {
740 return JNI_FALSE;
741 }
742
743 return JNI_TRUE;
744}
745
746static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
747 FrameStats stats;
748
749 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
750 if (err < 0 && err != NO_INIT) {
751 doThrowIAE(env);
752 }
753
754 // The other end is not ready, fine just return empty stats.
755 if (err == NO_INIT) {
756 return JNI_FALSE;
757 }
758
759 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
760 size_t frameCount = stats.desiredPresentTimesNano.size();
761
762 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
763 if (presentedTimesNanoDst == NULL) {
764 return JNI_FALSE;
765 }
766
767 nsecs_t presentedTimesNanoSrc[frameCount];
768
769 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700770 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700771 if (presentedTimeNano == INT64_MAX) {
772 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
773 }
774 presentedTimesNanoSrc[i] = presentedTimeNano;
775 }
776
777 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
778
779 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
780 presentedTimesNanoDst);
781
782 if (env->ExceptionCheck()) {
783 return JNI_FALSE;
784 }
785
786 return JNI_TRUE;
787}
788
Robert Carre13b58e2017-08-31 14:50:44 -0700789static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
790 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +0000791 jobject handleObject, jlong frameNumber) {
792 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
793 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
794
Robert Carre13b58e2017-08-31 14:50:44 -0700795 {
796 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
797 transaction->deferTransactionUntil(ctrl, handle, frameNumber);
798 }
Rob Carr64e516f2015-10-29 00:20:45 +0000799}
800
Robert Carre13b58e2017-08-31 14:50:44 -0700801static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
802 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800803 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -0700804 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
805
Robert Carrd5c7dd62017-03-08 10:39:30 -0800806 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
807 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
808
Robert Carre13b58e2017-08-31 14:50:44 -0700809 transaction->deferTransactionUntil(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800810}
811
Robert Carre13b58e2017-08-31 14:50:44 -0700812static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
813 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800814 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700815
Robert Carrd5c7dd62017-03-08 10:39:30 -0800816 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
817 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
818
Robert Carre13b58e2017-08-31 14:50:44 -0700819 {
820 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
821 transaction->reparentChildren(ctrl, handle);
822 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800823}
824
Robert Carre13b58e2017-08-31 14:50:44 -0700825static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
826 jlong nativeObject,
chaviw76431402017-09-18 16:50:05 -0700827 jobject newParentObject) {
chaviw63542382017-08-17 17:39:29 -0700828 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
829 sp<IBinder> parentHandle = ibinderForJavaObject(env, newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700830
831 {
832 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
833 transaction->reparent(ctrl, parentHandle);
834 }
chaviw63542382017-08-17 17:39:29 -0700835}
836
Robert Carre13b58e2017-08-31 14:50:44 -0700837static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
838 jlong nativeObject) {
839 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
840
Robert Carrd5c7dd62017-03-08 10:39:30 -0800841 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700842 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800843}
844
Robert Carre13b58e2017-08-31 14:50:44 -0700845static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
846 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -0700847 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -0700848 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -0700849
Robert Carre13b58e2017-08-31 14:50:44 -0700850 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
851 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -0700852}
853
Chavi Weingartenb736e322018-02-23 00:27:54 +0000854static void nativeDestroyInTransaction(JNIEnv* env, jclass clazz,
855 jlong transactionObj,
856 jlong nativeObject) {
857 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
858 auto ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
859 transaction->destroySurface(ctrl);
860}
861
Rob Carr64e516f2015-10-29 00:20:45 +0000862static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
863 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +0000864 return javaObjectForIBinder(env, ctrl->getHandle());
865}
866
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700867static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
868 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
869 if (token == NULL) return NULL;
870
871 HdrCapabilities capabilities;
872 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
873
874 const auto& types = capabilities.getSupportedHdrTypes();
875 auto typesArray = env->NewIntArray(types.size());
876 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
877
Michael Wright9ff94c02016-03-30 18:05:40 -0700878 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700879 typesArray, capabilities.getDesiredMaxLuminance(),
880 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
881}
882
Jorim Jaggi06975df2017-12-01 14:52:13 +0100883static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
884 Parcel* parcel = parcelForJavaObject(env, parcelObj);
885 if (parcel == NULL) {
886 doThrowNPE(env);
887 return 0;
888 }
889 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
890 if (surface == nullptr) {
891 return 0;
892 }
893 surface->incStrong((void *)nativeCreate);
894 return reinterpret_cast<jlong>(surface.get());
895}
896
897static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
898 jlong nativeObject, jobject parcelObj) {
899 Parcel* parcel = parcelForJavaObject(env, parcelObj);
900 if (parcel == NULL) {
901 doThrowNPE(env);
902 return;
903 }
904 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
905 self->writeToParcel(parcel);
906}
907
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800908// ----------------------------------------------------------------------------
909
Daniel Micay76f6a862015-09-19 17:31:01 -0400910static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500911 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800912 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +0100913 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
914 (void*)nativeReadFromParcel },
915 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
916 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000917 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800918 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000919 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800920 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800921 {"nativeDisconnect", "(J)V",
922 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700923 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800924 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700925 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800926 (void*)nativeScreenshot },
Robert Carre13b58e2017-08-31 14:50:44 -0700927 {"nativeCreateTransaction", "()J",
928 (void*)nativeCreateTransaction },
929 {"nativeApplyTransaction", "(JZ)V",
930 (void*)nativeApplyTransaction },
931 {"nativeGetNativeTransactionFinalizer", "()J",
932 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -0700933 {"nativeMergeTransaction", "(JJ)V",
934 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -0700935 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800936 (void*)nativeSetAnimationTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -0700937 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800938 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -0700939 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -0700940 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -0700941 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800942 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -0700943 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -0700944 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -0700945 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800946 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -0700947 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800948 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -0700949 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800950 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -0700951 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -0700952 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -0700953 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800954 (void*)nativeSetMatrix },
Robert Carre13b58e2017-08-31 14:50:44 -0700955 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800956 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -0700957 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800958 (void*)nativeSetWindowCrop },
Robert Carre13b58e2017-08-31 14:50:44 -0700959 {"nativeSetFinalCrop", "(JJIIII)V",
Pablo Ceballos27982e62016-03-09 10:50:45 -0800960 (void*)nativeSetFinalCrop },
Robert Carre13b58e2017-08-31 14:50:44 -0700961 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800962 (void*)nativeSetLayerStack },
963 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
964 (void*)nativeGetBuiltInDisplay },
965 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
966 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700967 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
968 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -0700969 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800970 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -0700971 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800972 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -0700973 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800974 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -0700975 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -0700976 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700977 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
978 (void*)nativeGetDisplayConfigs },
979 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
980 (void*)nativeGetActiveConfig },
981 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
982 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700983 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
984 (void*)nativeGetDisplayColorModes},
985 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
986 (void*)nativeGetActiveColorMode},
987 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
988 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700989 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
990 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700991 {"nativeClearContentFrameStats", "(J)Z",
992 (void*)nativeClearContentFrameStats },
993 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
994 (void*)nativeGetContentFrameStats },
995 {"nativeClearAnimationFrameStats", "()Z",
996 (void*)nativeClearAnimationFrameStats },
997 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
998 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700999 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1000 (void*)nativeSetDisplayPowerMode },
Robert Carre13b58e2017-08-31 14:50:44 -07001001 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001002 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001003 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001004 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001005 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001006 (void*)nativeReparentChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001007 {"nativeReparent", "(JJLandroid/os/IBinder;)V",
chaviw76431402017-09-18 16:50:05 -07001008 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001009 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001010 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001011 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001012 (void*)nativeSetOverrideScalingMode },
Chavi Weingartenb736e322018-02-23 00:27:54 +00001013 {"nativeDestroy", "(JJ)V",
1014 (void*)nativeDestroyInTransaction },
Rob Carr64e516f2015-10-29 00:20:45 +00001015 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001016 (void*)nativeGetHandle },
Robert Carr6486d312017-01-09 19:48:29 -08001017 {"nativeScreenshotToBuffer",
1018 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
1019 (void*)nativeScreenshotToBuffer },
Chavi Weingartenea2eb5a2017-11-29 21:26:24 +00001020 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001021 (void*)nativeCaptureLayers },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001022};
1023
1024int register_android_view_SurfaceControl(JNIEnv* env)
1025{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001026 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001027 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1028
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001029 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1030 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1031 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1032 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1033 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1034 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1035 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1036 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1037 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1038 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1039 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1040 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1041 clazz, "appVsyncOffsetNanos", "J");
1042 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1043 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001044
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001045 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1046 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1047 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1048 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1049 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001050
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001051 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1052 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1053 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001054 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1055
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001056 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1057 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1058 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001059 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1060
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001061 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1062 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1063 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001064 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1065
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001066 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1067 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1068 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1069 "([IFFF)V");
1070
Robert Carr6486d312017-01-09 19:48:29 -08001071 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1072 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1073 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1074 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1075
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001076 return err;
1077}
1078
1079};