blob: f32d2b72c2ebc7eac21f7b0e2722810c395630ff [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"
Robert Carr788f5742018-07-30 17:46:45 -070022#include "android_hardware_input_InputWindowHandle.h"
John Reckf29ed282015-04-07 07:32:03 -070023#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080024#include "android/graphics/GraphicsJNI.h"
25#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080026#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040027
Tom Cherry8ed74bb2017-07-10 14:31:18 -070028#include <android-base/chrono_utils.h>
Steven Moreland2279b252017-07-19 09:50:45 -070029#include <nativehelper/JNIHelp.h>
30#include <nativehelper/ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080031#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080033#include <gui/Surface.h>
34#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040035#include <jni.h>
36#include <memory>
37#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070038#include <system/graphics.h>
Daniel Solomon10e3b332019-01-20 21:09:11 -080039#include <ui/ConfigStoreTypes.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080040#include <ui/DisplayInfo.h>
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070041#include <ui/DisplayedFrameStats.h>
Svetoslav1376d602014-03-13 11:17:26 -070042#include <ui/FrameStats.h>
Peiyong Linb88549e2018-03-28 12:03:45 -070043#include <ui/GraphicTypes.h>
Peiyong Lin371b98f2018-03-14 17:29:10 -070044#include <ui/HdrCapabilities.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080045#include <ui/Rect.h>
46#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080047#include <utils/Log.h>
48
Mathias Agopian3866f0d2013-02-11 22:08:48 -080049// ----------------------------------------------------------------------------
50
51namespace android {
52
53static const char* const OutOfResourcesException =
54 "android/view/Surface$OutOfResourcesException";
55
56static struct {
Dan Stoza00101052014-05-02 15:23:40 -070057 jclass clazz;
58 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080059 jfieldID width;
60 jfieldID height;
61 jfieldID refreshRate;
62 jfieldID density;
63 jfieldID xDpi;
64 jfieldID yDpi;
65 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070066 jfieldID appVsyncOffsetNanos;
67 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080068} gPhysicalDisplayInfoClassInfo;
69
Dan Stoza9890e3412014-05-22 16:12:54 -070070static struct {
71 jfieldID bottom;
72 jfieldID left;
73 jfieldID right;
74 jfieldID top;
75} gRectClassInfo;
76
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050077// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
78void DeleteScreenshot(void* addr, void* context) {
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050079 delete ((ScreenshotClient*) context);
80}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080081
Svetoslav1376d602014-03-13 11:17:26 -070082static struct {
83 nsecs_t UNDEFINED_TIME_NANO;
84 jmethodID init;
85} gWindowContentFrameStatsClassInfo;
86
87static struct {
88 nsecs_t UNDEFINED_TIME_NANO;
89 jmethodID init;
90} gWindowAnimationFrameStatsClassInfo;
91
Hangyu Kuang54ac2192016-04-25 13:22:02 -070092static struct {
93 jclass clazz;
94 jmethodID ctor;
95} gHdrCapabilitiesClassInfo;
96
Robert Carr6486d312017-01-09 19:48:29 -080097static struct {
98 jclass clazz;
99 jmethodID builder;
100} gGraphicBufferClassInfo;
101
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700102static struct {
103 jclass clazz;
104 jmethodID ctor;
105} gDisplayedContentSampleClassInfo;
106
107static struct {
108 jclass clazz;
109 jmethodID ctor;
110} gDisplayedContentSamplingAttributesClassInfo;
111
Daniel Solomon10e3b332019-01-20 21:09:11 -0800112static struct {
113 jclass clazz;
114 jmethodID ctor;
115 jfieldID X;
116 jfieldID Y;
117 jfieldID Z;
118} gCieXyzClassInfo;
119
120static struct {
121 jclass clazz;
122 jmethodID ctor;
123 jfieldID red;
124 jfieldID green;
125 jfieldID blue;
126 jfieldID white;
127} gDisplayPrimariesClassInfo;
128
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800129// ----------------------------------------------------------------------------
130
Robert Carre13b58e2017-08-31 14:50:44 -0700131static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
132 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
133}
134
135static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
136 delete t;
137}
138
139static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
140 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
141}
142
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000143static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500144 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
Evan Rosky485df202018-12-06 14:11:12 -0800145 jobject metadataParcel) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800146 ScopedUtfChars name(env, nameStr);
Robert Carr76907ee2019-01-11 13:38:19 -0800147 sp<SurfaceComposerClient> client;
148 if (sessionObj != NULL) {
149 client = android_view_SurfaceSession_getClient(env, sessionObj);
150 } else {
151 client = SurfaceComposerClient::getDefault();
152 }
Robert Carr838120c2016-11-01 18:31:12 -0700153 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Robert Carrb0f39362018-03-14 13:52:25 -0700154 sp<SurfaceControl> surface;
Evan Rosky485df202018-12-06 14:11:12 -0800155 LayerMetadata metadata;
156 Parcel* parcel = parcelForJavaObject(env, metadataParcel);
157 if (parcel && !parcel->objectsCount()) {
158 status_t err = metadata.readFromParcel(parcel);
159 if (err != NO_ERROR) {
160 jniThrowException(env, "java/lang/IllegalArgumentException",
161 "Metadata parcel has wrong format");
162 }
163 }
164
Robert Carrb0f39362018-03-14 13:52:25 -0700165 status_t err = client->createSurfaceChecked(
Evan Rosky485df202018-12-06 14:11:12 -0800166 String8(name.c_str()), w, h, format, &surface, flags, parent, std::move(metadata));
Robert Carrb0f39362018-03-14 13:52:25 -0700167 if (err == NAME_NOT_FOUND) {
168 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
169 return 0;
170 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800171 jniThrowException(env, OutOfResourcesException, NULL);
172 return 0;
173 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500174
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800175 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000176 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800177}
178
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000179static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800180 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Robert Carrcc6d4832019-02-04 15:41:12 -0800181 ctrl->release();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800182 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800183}
184
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000185static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800186 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Robert Carrcc6d4832019-02-04 15:41:12 -0800187 ctrl->destroy();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800188 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800189}
190
Chong Zhang47e36a32016-02-29 16:44:33 -0800191static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
192 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
193 if (ctrl != NULL) {
194 ctrl->disconnect();
195 }
196}
197
Robert Carr6486d312017-01-09 19:48:29 -0800198static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
199 int left = env->GetIntField(rectObj, gRectClassInfo.left);
200 int top = env->GetIntField(rectObj, gRectClassInfo.top);
201 int right = env->GetIntField(rectObj, gRectClassInfo.right);
202 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
203 return Rect(left, top, right, bottom);
204}
205
chaviw08520a02018-09-10 16:44:56 -0700206static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800207 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
chaviw08520a02018-09-10 16:44:56 -0700208 bool useIdentityTransform, int rotation) {
Robert Carr6486d312017-01-09 19:48:29 -0800209 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
210 if (displayToken == NULL) {
211 return NULL;
212 }
213 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800214 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700215 status_t res = ScreenshotClient::capture(displayToken, ui::Dataspace::V0_SRGB,
216 ui::PixelFormat::RGBA_8888,
217 sourceCrop, width, height,
218 useIdentityTransform, rotation, &buffer);
Robert Carr6486d312017-01-09 19:48:29 -0800219 if (res != NO_ERROR) {
220 return NULL;
221 }
222
223 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
224 gGraphicBufferClassInfo.builder,
225 buffer->getWidth(),
226 buffer->getHeight(),
227 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700228 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100229 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800230}
231
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000232static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
chaviwfbe47df2017-11-10 16:14:49 -0800233 jobject sourceCropObj, jfloat frameScale) {
234
235 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
236 if (layerHandle == NULL) {
237 return NULL;
238 }
239
240 Rect sourceCrop;
241 if (sourceCropObj != NULL) {
242 sourceCrop = rectFromObj(env, sourceCropObj);
243 }
244
245 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700246 status_t res = ScreenshotClient::captureChildLayers(layerHandle, ui::Dataspace::V0_SRGB,
247 ui::PixelFormat::RGBA_8888, sourceCrop,
248 frameScale, &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800249 if (res != NO_ERROR) {
250 return NULL;
251 }
252
253 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
254 gGraphicBufferClassInfo.builder,
255 buffer->getWidth(),
256 buffer->getHeight(),
257 buffer->getPixelFormat(),
258 (jint)buffer->getUsage(),
259 (jlong)buffer.get());
chaviw1cda84c2017-10-23 16:47:10 -0700260}
261
Robert Carre13b58e2017-08-31 14:50:44 -0700262static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
263 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
264 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800265}
266
Robert Carrb1579c82017-09-05 14:54:47 -0700267static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
268 jlong transactionObj, jlong otherTransactionObj) {
269 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
270 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
271 otherTransactionObj);
272 transaction->merge(std::move(*otherTransaction));
273}
274
Robert Carre13b58e2017-08-31 14:50:44 -0700275static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
276 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
277 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800278}
279
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100280static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
281 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
282 transaction->setEarlyWakeup();
283}
284
Robert Carre13b58e2017-08-31 14:50:44 -0700285static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
286 jlong nativeObject, jint zorder) {
287 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800288
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800289 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700290 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800291}
292
Robert Carre13b58e2017-08-31 14:50:44 -0700293static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
294 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700295 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700296
Robert Carraf422a82017-04-10 18:34:33 -0700297 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
298 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
299
Robert Carre13b58e2017-08-31 14:50:44 -0700300 {
301 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
302 transaction->setRelativeLayer(ctrl, handle, zorder);
303 }
Robert Carraf422a82017-04-10 18:34:33 -0700304}
305
Robert Carre13b58e2017-08-31 14:50:44 -0700306static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
307 jlong nativeObject, jfloat x, jfloat y) {
308 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
309
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800310 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700311 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800312}
313
Robert Carr76907ee2019-01-11 13:38:19 -0800314static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
315 jobject sourceObj, jobject dstObj, jlong orientation) {
316 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
317 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
318
319 Rect source, dst;
320 if (sourceObj != NULL) {
321 source = rectFromObj(env, sourceObj);
322 }
323 if (dstObj != NULL) {
324 dst = rectFromObj(env, dstObj);
325 }
326 transaction->setGeometry(ctrl, source, dst, orientation);
327}
328
Robert Carr6da3cc02016-06-16 15:17:07 -0700329static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700330jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700331 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700332 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
333
Robert Carra9408d42016-06-03 13:28:48 -0700334 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700335 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700336}
337
Robert Carre13b58e2017-08-31 14:50:44 -0700338static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
339 jlong nativeObject, jint w, jint h) {
340 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
341
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800342 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700343 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800344}
345
Robert Carre13b58e2017-08-31 14:50:44 -0700346static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
347 jlong nativeObject, jint flags, jint mask) {
348 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
349
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800350 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700351 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800352}
353
Robert Carre13b58e2017-08-31 14:50:44 -0700354static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
355 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800356 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
357 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
358 if (!region) {
359 doThrowIAE(env);
360 return;
361 }
362
363 const SkIRect& b(region->getBounds());
364 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
365 if (region->isComplex()) {
366 SkRegion::Iterator it(*region);
367 while (!it.done()) {
368 const SkIRect& r(it.rect());
369 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
370 it.next();
371 }
372 }
373
Robert Carre13b58e2017-08-31 14:50:44 -0700374 {
375 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
376 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800377 }
378}
379
Robert Carre13b58e2017-08-31 14:50:44 -0700380static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
381 jlong nativeObject, jfloat alpha) {
382 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
383
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800384 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700385 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800386}
387
Robert Carr788f5742018-07-30 17:46:45 -0700388static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
389 jlong nativeObject, jobject inputWindow) {
390 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
391
Riddle Hsucd958bc2019-01-23 15:40:26 +0800392 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700393 env, inputWindow);
394 handle->updateInfo();
395
396 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
397 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
398}
399
chaviw59f532e2018-12-26 15:34:59 -0800400static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
401 jobject fromTokenObj, jobject toTokenObj) {
402 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
403
404 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
405 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
406 transaction->transferTouchFocus(fromToken, toToken);
407}
408
chaviw319cd0782019-02-14 11:00:23 -0800409static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
410 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
411 transaction->syncInputWindows();
412}
413
Evan Rosky485df202018-12-06 14:11:12 -0800414static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
415 jlong nativeObject, jint id, jobject parcelObj) {
416 Parcel* parcel = parcelForJavaObject(env, parcelObj);
417 if (!parcel) {
418 jniThrowNullPointerException(env, "attribute data");
419 return;
420 }
421 if (parcel->objectsCount()) {
422 jniThrowException(env, "java/lang/RuntimeException",
423 "Tried to marshall a Parcel that contained Binder objects.");
424 return;
425 }
426
427 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
428
429 std::vector<uint8_t> byteData(parcel->dataSize());
430 memcpy(byteData.data(), parcel->data(), parcel->dataSize());
431
432 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
433 transaction->setMetadata(ctrl, id, std::move(byteData));
434}
435
Robert Carre13b58e2017-08-31 14:50:44 -0700436static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
437 jlong nativeObject, jfloatArray fColor) {
438 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700439 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700440
chaviw0dd03f52017-08-25 12:15:26 -0700441 float* floatColors = env->GetFloatArrayElements(fColor, 0);
442 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700443 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700444}
445
Robert Carre13b58e2017-08-31 14:50:44 -0700446static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
447 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800448 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700449 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
450
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800451 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700452 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800453}
454
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700455static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
456 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
457 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
458 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
459 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
460 mat3 matrix(static_cast<float const*>(floatMatrix));
461 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
462 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
463 transaction->setColorTransform(surfaceControl, matrix, translation);
464}
465
Robert Carre13b58e2017-08-31 14:50:44 -0700466static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
467 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800468 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700469 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
470
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800471 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
472 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700473 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800474}
475
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700476static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
477 jlong nativeObject, jfloat cornerRadius) {
478 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
479
480 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
481 transaction->setCornerRadius(ctrl, cornerRadius);
482}
483
Robert Carre13b58e2017-08-31 14:50:44 -0700484static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
485 jlong nativeObject, jint layerStack) {
486 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
487
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800488 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700489 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800490}
491
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800492static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
493 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
494 jlongArray array = env->NewLongArray(displayIds.size());
495 if (array == nullptr) {
496 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
497 return nullptr;
498 }
499
500 if (displayIds.empty()) {
501 return array;
502 }
503
504 jlong* values = env->GetLongArrayElements(array, 0);
505 for (size_t i = 0; i < displayIds.size(); ++i) {
506 values[i] = static_cast<jlong>(displayIds[i]);
507 }
508
509 env->ReleaseLongArrayElements(array, values, 0);
510 return array;
511}
512
513static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
514 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800515 return javaObjectForIBinder(env, token);
516}
517
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700518static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
519 jobject tokenObj) {
520 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
521
522 ui::PixelFormat format;
523 ui::Dataspace dataspace;
524 uint8_t componentMask;
525 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
526 token, &format, &dataspace, &componentMask);
527 if (err != OK) {
528 return nullptr;
529 }
530 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
531 gDisplayedContentSamplingAttributesClassInfo.ctor,
532 format, dataspace, componentMask);
533}
534
535static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
536 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
537 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800538 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700539 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800540 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700541}
542
543static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
544 jlong maxFrames, jlong timestamp) {
545 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
546
547 DisplayedFrameStats stats;
548 status_t err = SurfaceComposerClient::getDisplayedContentSample(
549 token, maxFrames, timestamp, &stats);
550 if (err != OK) {
551 return nullptr;
552 }
553
554 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
555 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
556 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
557 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
558 if ((histogramComponent0 == nullptr) ||
559 (histogramComponent1 == nullptr) ||
560 (histogramComponent2 == nullptr) ||
561 (histogramComponent3 == nullptr)) {
562 return JNI_FALSE;
563 }
564
565 env->SetLongArrayRegion(histogramComponent0, 0,
566 stats.component_0_sample.size(),
567 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
568 env->SetLongArrayRegion(histogramComponent1, 0,
569 stats.component_1_sample.size(),
570 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
571 env->SetLongArrayRegion(histogramComponent2, 0,
572 stats.component_2_sample.size(),
573 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
574 env->SetLongArrayRegion(histogramComponent3, 0,
575 stats.component_3_sample.size(),
576 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
577 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
578 gDisplayedContentSampleClassInfo.ctor,
579 stats.numFrames,
580 histogramComponent0,
581 histogramComponent1,
582 histogramComponent2,
583 histogramComponent3);
584}
585
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800586static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
587 jboolean secure) {
588 ScopedUtfChars name(env, nameObj);
589 sp<IBinder> token(SurfaceComposerClient::createDisplay(
590 String8(name.c_str()), bool(secure)));
591 return javaObjectForIBinder(env, token);
592}
593
Jesse Hall6a6bc212013-08-08 12:15:03 -0700594static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
595 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
596 if (token == NULL) return;
597 SurfaceComposerClient::destroyDisplay(token);
598}
599
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800600static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700601 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000602 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800603 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
604 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800605 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800606 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800607 if (sur != NULL) {
608 bufferProducer = sur->getIGraphicBufferProducer();
609 }
Robert Carre13b58e2017-08-31 14:50:44 -0700610
611
612 status_t err = NO_ERROR;
613 {
614 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
615 err = transaction->setDisplaySurface(token,
616 bufferProducer);
617 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700618 if (err != NO_ERROR) {
619 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
620 " Surface created with singleBufferMode?");
621 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800622}
623
624static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700625 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800626 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700627
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800628 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
629 if (token == NULL) return;
630
Robert Carre13b58e2017-08-31 14:50:44 -0700631 {
632 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
633 transaction->setDisplayLayerStack(token, layerStack);
634 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800635}
636
637static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700638 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800639 jobject tokenObj, jint orientation,
640 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
641 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
642 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
643 if (token == NULL) return;
644 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
645 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700646
647 {
648 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
649 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
650 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800651}
652
Michael Wright01e840f2014-06-26 16:03:25 -0700653static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700654 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700655 jobject tokenObj, jint width, jint height) {
656 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
657 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700658
659 {
660 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
661 transaction->setDisplaySize(token, width, height);
662 }
Michael Wright01e840f2014-06-26 16:03:25 -0700663}
664
Dan Stoza00101052014-05-02 15:23:40 -0700665static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
666 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800667 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700668 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800669
Dan Stoza00101052014-05-02 15:23:40 -0700670 Vector<DisplayInfo> configs;
671 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
672 configs.size() == 0) {
673 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800674 }
675
Dan Stoza00101052014-05-02 15:23:40 -0700676 jobjectArray configArray = env->NewObjectArray(configs.size(),
677 gPhysicalDisplayInfoClassInfo.clazz, NULL);
678
679 for (size_t c = 0; c < configs.size(); ++c) {
680 const DisplayInfo& info = configs[c];
681 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
682 gPhysicalDisplayInfoClassInfo.ctor);
683 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
684 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
685 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
686 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
687 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
688 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
689 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700690 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
691 info.appVsyncOffset);
692 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
693 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700694 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
695 env->DeleteLocalRef(infoObj);
696 }
697
698 return configArray;
699}
700
Ady Abraham6070ce12019-01-24 18:48:58 -0800701static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
702 jobject tokenObj, jintArray configArray) {
703 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
704 if (token == nullptr) return JNI_FALSE;
705
706 std::vector<int32_t> allowedConfigs;
707 jsize configArraySize = env->GetArrayLength(configArray);
708 allowedConfigs.reserve(configArraySize);
709
710 jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
711 for (int i = 0; i < configArraySize; i++) {
712 allowedConfigs.push_back(configArrayElements[i]);
713 }
714 env->ReleaseIntArrayElements(configArray, configArrayElements, 0);
715
716 size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
717 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
718}
719
Dan Stoza00101052014-05-02 15:23:40 -0700720static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
721 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
722 if (token == NULL) return -1;
723 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
724}
725
726static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
727 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
728 if (token == NULL) return JNI_FALSE;
729 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
730 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800731}
732
Michael Wright1c9977b2016-07-12 13:30:10 -0700733static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
734 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
735 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700736 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700737 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
738 colorModes.isEmpty()) {
739 return NULL;
740 }
741
742 jintArray colorModesArray = env->NewIntArray(colorModes.size());
743 if (colorModesArray == NULL) {
744 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
745 return NULL;
746 }
747 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
748 for (size_t i = 0; i < colorModes.size(); i++) {
749 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
750 }
751 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
752 return colorModesArray;
753}
754
Daniel Solomon10e3b332019-01-20 21:09:11 -0800755static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
756 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
757 if (token == NULL) return NULL;
758
759 ui::DisplayPrimaries primaries;
760 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
761 return NULL;
762 }
763
764 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
765 if (jred == NULL) {
766 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
767 return NULL;
768 }
769
770 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
771 if (jgreen == NULL) {
772 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
773 return NULL;
774 }
775
776 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
777 if (jblue == NULL) {
778 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
779 return NULL;
780 }
781
782 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
783 if (jwhite == NULL) {
784 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
785 return NULL;
786 }
787
788 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
789 gDisplayPrimariesClassInfo.ctor);
790 if (jprimaries == NULL) {
791 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
792 return NULL;
793 }
794
795 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
796 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
797 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
798 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
799 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
800 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
801 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
802 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
803 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
804 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
805 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
806 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
807 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
808 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
809 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
810 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
811
812 return jprimaries;
813}
814
Michael Wright1c9977b2016-07-12 13:30:10 -0700815static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
816 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
817 if (token == NULL) return -1;
818 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
819}
820
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800821static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
822 ui::Dataspace defaultDataspace, wcgDataspace;
823 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
824 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
825 &defaultPixelFormat,
826 &wcgDataspace,
827 &wcgPixelFormat) != NO_ERROR) {
828 return nullptr;
829 }
830 jintArray array = env->NewIntArray(2);
831 if (array == nullptr) {
832 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
833 return nullptr;
834 }
835 jint* arrayValues = env->GetIntArrayElements(array, 0);
836 arrayValues[0] = static_cast<jint>(defaultDataspace);
837 arrayValues[1] = static_cast<jint>(wcgDataspace);
838 env->ReleaseIntArrayElements(array, arrayValues, 0);
839 return array;
840}
841
Michael Wright1c9977b2016-07-12 13:30:10 -0700842static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
843 jobject tokenObj, jint colorMode) {
844 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
845 if (token == NULL) return JNI_FALSE;
846 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700847 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700848 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
849}
850
Prashant Malanic55929a2014-05-25 01:59:21 -0700851static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800852 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
853 if (token == NULL) return;
854
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700855 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700856 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700857 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800858}
859
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800860static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
861 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
862}
863
Svetoslav1376d602014-03-13 11:17:26 -0700864static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
865 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
866 status_t err = ctrl->clearLayerFrameStats();
867
868 if (err < 0 && err != NO_INIT) {
869 doThrowIAE(env);
870 }
871
872 // The other end is not ready, just report we failed.
873 if (err == NO_INIT) {
874 return JNI_FALSE;
875 }
876
877 return JNI_TRUE;
878}
879
880static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
881 jobject outStats) {
882 FrameStats stats;
883
884 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
885 status_t err = ctrl->getLayerFrameStats(&stats);
886 if (err < 0 && err != NO_INIT) {
887 doThrowIAE(env);
888 }
889
890 // The other end is not ready, fine just return empty stats.
891 if (err == NO_INIT) {
892 return JNI_FALSE;
893 }
894
895 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
896 size_t frameCount = stats.desiredPresentTimesNano.size();
897
898 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
899 if (postedTimesNanoDst == NULL) {
900 return JNI_FALSE;
901 }
902
903 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
904 if (presentedTimesNanoDst == NULL) {
905 return JNI_FALSE;
906 }
907
908 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
909 if (readyTimesNanoDst == NULL) {
910 return JNI_FALSE;
911 }
912
913 nsecs_t postedTimesNanoSrc[frameCount];
914 nsecs_t presentedTimesNanoSrc[frameCount];
915 nsecs_t readyTimesNanoSrc[frameCount];
916
917 for (size_t i = 0; i < frameCount; i++) {
918 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
919 if (postedTimeNano == INT64_MAX) {
920 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
921 }
922 postedTimesNanoSrc[i] = postedTimeNano;
923
924 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
925 if (presentedTimeNano == INT64_MAX) {
926 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
927 }
928 presentedTimesNanoSrc[i] = presentedTimeNano;
929
930 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
931 if (readyTimeNano == INT64_MAX) {
932 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
933 }
934 readyTimesNanoSrc[i] = readyTimeNano;
935 }
936
937 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
938 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
939 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
940
941 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
942 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
943
944 if (env->ExceptionCheck()) {
945 return JNI_FALSE;
946 }
947
948 return JNI_TRUE;
949}
950
951static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
952 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
953
954 if (err < 0 && err != NO_INIT) {
955 doThrowIAE(env);
956 }
957
958 // The other end is not ready, just report we failed.
959 if (err == NO_INIT) {
960 return JNI_FALSE;
961 }
962
963 return JNI_TRUE;
964}
965
966static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
967 FrameStats stats;
968
969 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
970 if (err < 0 && err != NO_INIT) {
971 doThrowIAE(env);
972 }
973
974 // The other end is not ready, fine just return empty stats.
975 if (err == NO_INIT) {
976 return JNI_FALSE;
977 }
978
979 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
980 size_t frameCount = stats.desiredPresentTimesNano.size();
981
982 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
983 if (presentedTimesNanoDst == NULL) {
984 return JNI_FALSE;
985 }
986
987 nsecs_t presentedTimesNanoSrc[frameCount];
988
989 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700990 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700991 if (presentedTimeNano == INT64_MAX) {
992 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
993 }
994 presentedTimesNanoSrc[i] = presentedTimeNano;
995 }
996
997 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
998
999 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1000 presentedTimesNanoDst);
1001
1002 if (env->ExceptionCheck()) {
1003 return JNI_FALSE;
1004 }
1005
1006 return JNI_TRUE;
1007}
1008
Robert Carre13b58e2017-08-31 14:50:44 -07001009static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
1010 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +00001011 jobject handleObject, jlong frameNumber) {
1012 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1013 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
1014
Robert Carre13b58e2017-08-31 14:50:44 -07001015 {
1016 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001017 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -07001018 }
Rob Carr64e516f2015-10-29 00:20:45 +00001019}
1020
Robert Carre13b58e2017-08-31 14:50:44 -07001021static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1022 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001023 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001024 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1025
Robert Carrd5c7dd62017-03-08 10:39:30 -08001026 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1027 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1028
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001029 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001030}
1031
Robert Carre13b58e2017-08-31 14:50:44 -07001032static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1033 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001034 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001035
Robert Carrd5c7dd62017-03-08 10:39:30 -08001036 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1037 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
1038
Robert Carre13b58e2017-08-31 14:50:44 -07001039 {
1040 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1041 transaction->reparentChildren(ctrl, handle);
1042 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001043}
1044
Robert Carre13b58e2017-08-31 14:50:44 -07001045static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1046 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001047 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001048 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001049 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001050
1051 {
1052 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -08001053 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -07001054 }
chaviw63542382017-08-17 17:39:29 -07001055}
1056
Robert Carre13b58e2017-08-31 14:50:44 -07001057static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1058 jlong nativeObject) {
1059 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1060
Robert Carrd5c7dd62017-03-08 10:39:30 -08001061 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001062 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001063}
1064
Robert Carre13b58e2017-08-31 14:50:44 -07001065static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1066 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001067 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001068 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001069
Robert Carre13b58e2017-08-31 14:50:44 -07001070 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1071 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001072}
1073
Rob Carr64e516f2015-10-29 00:20:45 +00001074static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
1075 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +00001076 return javaObjectForIBinder(env, ctrl->getHandle());
1077}
1078
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001079static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1080 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1081 if (token == NULL) return NULL;
1082
1083 HdrCapabilities capabilities;
1084 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1085
1086 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001087 std::vector<int32_t> intTypes;
1088 for (auto type : types) {
1089 intTypes.push_back(static_cast<int32_t>(type));
1090 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001091 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001092 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001093
Michael Wright9ff94c02016-03-30 18:05:40 -07001094 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001095 typesArray, capabilities.getDesiredMaxLuminance(),
1096 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1097}
1098
Jorim Jaggi06975df2017-12-01 14:52:13 +01001099static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1100 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1101 if (parcel == NULL) {
1102 doThrowNPE(env);
1103 return 0;
1104 }
1105 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1106 if (surface == nullptr) {
1107 return 0;
1108 }
1109 surface->incStrong((void *)nativeCreate);
1110 return reinterpret_cast<jlong>(surface.get());
1111}
1112
chaviwbeb7a0c2018-12-05 13:49:54 -08001113static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1114 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1115 if (surface == nullptr) {
1116 return 0;
1117 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001118
1119 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1120 newSurface->incStrong((void *)nativeCreate);
1121 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001122}
1123
Jorim Jaggi06975df2017-12-01 14:52:13 +01001124static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1125 jlong nativeObject, jobject parcelObj) {
1126 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1127 if (parcel == NULL) {
1128 doThrowNPE(env);
1129 return;
1130 }
1131 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001132 if (self != nullptr) {
1133 self->writeToParcel(parcel);
1134 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001135}
1136
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001137// ----------------------------------------------------------------------------
1138
Daniel Micay76f6a862015-09-19 17:31:01 -04001139static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001140 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001141 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001142 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1143 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001144 {"nativeCopyFromSurfaceControl", "(J)J" ,
1145 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001146 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1147 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001148 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001149 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001150 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001151 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -08001152 {"nativeDisconnect", "(J)V",
1153 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001154 {"nativeCreateTransaction", "()J",
1155 (void*)nativeCreateTransaction },
1156 {"nativeApplyTransaction", "(JZ)V",
1157 (void*)nativeApplyTransaction },
1158 {"nativeGetNativeTransactionFinalizer", "()J",
1159 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001160 {"nativeMergeTransaction", "(JJ)V",
1161 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001162 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001163 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001164 {"nativeSetEarlyWakeup", "(J)V",
1165 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001166 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001167 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001168 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -07001169 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001170 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001171 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001172 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -07001173 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -07001174 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001175 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001176 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001177 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001178 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001179 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001180 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001181 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001182 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001183 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001184 {"nativeSetColorTransform", "(JJ[F[F)V",
1185 (void*)nativeSetColorTransform },
Robert Carre13b58e2017-08-31 14:50:44 -07001186 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001187 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001188 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001189 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001190 {"nativeSetCornerRadius", "(JJF)V",
1191 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001192 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001193 (void*)nativeSetLayerStack },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001194 {"nativeGetPhysicalDisplayIds", "()[J",
1195 (void*)nativeGetPhysicalDisplayIds },
1196 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1197 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001198 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1199 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001200 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1201 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001202 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001203 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001204 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001205 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001206 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001207 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001208 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001209 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001210 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1211 (void*)nativeGetDisplayConfigs },
1212 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1213 (void*)nativeGetActiveConfig },
1214 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1215 (void*)nativeSetActiveConfig },
Ady Abraham6070ce12019-01-24 18:48:58 -08001216 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1217 (void*)nativeSetAllowedDisplayConfigs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001218 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1219 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001220 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1221 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001222 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1223 (void*)nativeGetActiveColorMode},
1224 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1225 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001226 {"nativeGetCompositionDataspaces", "()[I",
1227 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001228 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1229 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001230 {"nativeClearContentFrameStats", "(J)Z",
1231 (void*)nativeClearContentFrameStats },
1232 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1233 (void*)nativeGetContentFrameStats },
1234 {"nativeClearAnimationFrameStats", "()Z",
1235 (void*)nativeClearAnimationFrameStats },
1236 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1237 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001238 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1239 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001240 {"nativeGetProtectedContentSupport", "()Z",
1241 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001242 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001243 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001244 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001245 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001246 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001247 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001248 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001249 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001250 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001251 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001252 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001253 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001254 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001255 (void*)nativeGetHandle },
chaviw08520a02018-09-10 16:44:56 -07001256 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZI)Landroid/graphics/GraphicBuffer;",
1257 (void*)nativeScreenshot },
Chavi Weingartenea2eb5a2017-11-29 21:26:24 +00001258 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001259 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001260 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001261 (void*)nativeSetInputWindowInfo },
1262 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1263 (void*)nativeTransferTouchFocus },
Evan Rosky485df202018-12-06 14:11:12 -08001264 {"nativeSetMetadata", "(JILandroid/os/Parcel;)V",
1265 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001266 {"nativeGetDisplayedContentSamplingAttributes",
1267 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1268 (void*)nativeGetDisplayedContentSamplingAttributes },
1269 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1270 (void*)nativeSetDisplayedContentSamplingEnabled },
1271 {"nativeGetDisplayedContentSample",
1272 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1273 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001274 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001275 (void*)nativeSetGeometry },
1276 {"nativeSyncInputWindows", "(J)V",
1277 (void*)nativeSyncInputWindows }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001278};
1279
1280int register_android_view_SurfaceControl(JNIEnv* env)
1281{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001282 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001283 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1284
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001285 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1286 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1287 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1288 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1289 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1290 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1291 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1292 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1293 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1294 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1295 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1296 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1297 clazz, "appVsyncOffsetNanos", "J");
1298 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1299 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001300
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001301 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1302 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1303 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1304 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1305 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001306
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001307 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1308 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1309 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001310 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1311
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001312 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1313 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1314 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001315 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1316
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001317 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1318 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1319 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001320 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1321
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001322 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1323 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1324 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1325 "([IFFF)V");
1326
Robert Carr6486d312017-01-09 19:48:29 -08001327 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1328 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1329 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1330 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1331
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001332 jclass displayedContentSampleClazz = FindClassOrDie(env,
1333 "android/hardware/display/DisplayedContentSample");
1334 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1335 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1336 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1337
1338 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1339 "android/hardware/display/DisplayedContentSamplingAttributes");
1340 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1341 displayedContentSamplingAttributesClazz);
1342 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1343 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001344
1345 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1346 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1347 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1348 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1349 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1350 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1351
1352 jclass displayPrimariesClazz = FindClassOrDie(env,
1353 "android/view/SurfaceControl$DisplayPrimaries");
1354 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1355 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1356 "<init>", "()V");
1357 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1358 "Landroid/view/SurfaceControl$CieXyz;");
1359 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1360 "Landroid/view/SurfaceControl$CieXyz;");
1361 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1362 "Landroid/view/SurfaceControl$CieXyz;");
1363 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1364 "Landroid/view/SurfaceControl$CieXyz;");
1365
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001366 return err;
1367}
1368
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001369} // namespace android