blob: 89d908b31aa012a4269b44198fab634abd40ea33 [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,
Robert Carr5c52b132019-02-15 15:48:11 -0800208 bool useIdentityTransform, int rotation, bool captureSecureLayers) {
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,
Robert Carr5c52b132019-02-15 15:48:11 -0800216 ui::PixelFormat::RGBA_8888,
217 sourceCrop, width, height,
218 useIdentityTransform, rotation, captureSecureLayers, &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
Peiyong Linf4f0f642019-03-01 14:36:05 -0800466static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
467 jlong nativeObject, jboolean agnostic) {
468 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
469 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
470 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
471}
472
Robert Carre13b58e2017-08-31 14:50:44 -0700473static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
474 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800475 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700476 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
477
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800478 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
479 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700480 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800481}
482
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700483static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
484 jlong nativeObject, jfloat cornerRadius) {
485 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
486
487 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
488 transaction->setCornerRadius(ctrl, cornerRadius);
489}
490
Robert Carre13b58e2017-08-31 14:50:44 -0700491static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
492 jlong nativeObject, jint layerStack) {
493 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
494
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800495 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700496 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800497}
498
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800499static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
500 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
501 jlongArray array = env->NewLongArray(displayIds.size());
502 if (array == nullptr) {
503 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
504 return nullptr;
505 }
506
507 if (displayIds.empty()) {
508 return array;
509 }
510
511 jlong* values = env->GetLongArrayElements(array, 0);
512 for (size_t i = 0; i < displayIds.size(); ++i) {
513 values[i] = static_cast<jlong>(displayIds[i]);
514 }
515
516 env->ReleaseLongArrayElements(array, values, 0);
517 return array;
518}
519
520static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
521 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800522 return javaObjectForIBinder(env, token);
523}
524
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700525static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
526 jobject tokenObj) {
527 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
528
529 ui::PixelFormat format;
530 ui::Dataspace dataspace;
531 uint8_t componentMask;
532 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
533 token, &format, &dataspace, &componentMask);
534 if (err != OK) {
535 return nullptr;
536 }
537 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
538 gDisplayedContentSamplingAttributesClassInfo.ctor,
539 format, dataspace, componentMask);
540}
541
542static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
543 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
544 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800545 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700546 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800547 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700548}
549
550static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
551 jlong maxFrames, jlong timestamp) {
552 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
553
554 DisplayedFrameStats stats;
555 status_t err = SurfaceComposerClient::getDisplayedContentSample(
556 token, maxFrames, timestamp, &stats);
557 if (err != OK) {
558 return nullptr;
559 }
560
561 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
562 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
563 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
564 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
565 if ((histogramComponent0 == nullptr) ||
566 (histogramComponent1 == nullptr) ||
567 (histogramComponent2 == nullptr) ||
568 (histogramComponent3 == nullptr)) {
569 return JNI_FALSE;
570 }
571
572 env->SetLongArrayRegion(histogramComponent0, 0,
573 stats.component_0_sample.size(),
574 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
575 env->SetLongArrayRegion(histogramComponent1, 0,
576 stats.component_1_sample.size(),
577 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
578 env->SetLongArrayRegion(histogramComponent2, 0,
579 stats.component_2_sample.size(),
580 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
581 env->SetLongArrayRegion(histogramComponent3, 0,
582 stats.component_3_sample.size(),
583 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
584 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
585 gDisplayedContentSampleClassInfo.ctor,
586 stats.numFrames,
587 histogramComponent0,
588 histogramComponent1,
589 histogramComponent2,
590 histogramComponent3);
591}
592
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800593static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
594 jboolean secure) {
595 ScopedUtfChars name(env, nameObj);
596 sp<IBinder> token(SurfaceComposerClient::createDisplay(
597 String8(name.c_str()), bool(secure)));
598 return javaObjectForIBinder(env, token);
599}
600
Jesse Hall6a6bc212013-08-08 12:15:03 -0700601static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
602 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
603 if (token == NULL) return;
604 SurfaceComposerClient::destroyDisplay(token);
605}
606
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800607static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700608 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000609 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800610 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
611 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800612 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800613 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800614 if (sur != NULL) {
615 bufferProducer = sur->getIGraphicBufferProducer();
616 }
Robert Carre13b58e2017-08-31 14:50:44 -0700617
618
619 status_t err = NO_ERROR;
620 {
621 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
622 err = transaction->setDisplaySurface(token,
623 bufferProducer);
624 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700625 if (err != NO_ERROR) {
626 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
627 " Surface created with singleBufferMode?");
628 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800629}
630
631static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700632 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800633 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700634
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800635 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
636 if (token == NULL) return;
637
Robert Carre13b58e2017-08-31 14:50:44 -0700638 {
639 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
640 transaction->setDisplayLayerStack(token, layerStack);
641 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800642}
643
644static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700645 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800646 jobject tokenObj, jint orientation,
647 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
648 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
649 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
650 if (token == NULL) return;
651 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
652 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700653
654 {
655 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
656 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
657 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800658}
659
Michael Wright01e840f2014-06-26 16:03:25 -0700660static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700661 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700662 jobject tokenObj, jint width, jint height) {
663 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
664 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700665
666 {
667 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
668 transaction->setDisplaySize(token, width, height);
669 }
Michael Wright01e840f2014-06-26 16:03:25 -0700670}
671
Dan Stoza00101052014-05-02 15:23:40 -0700672static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
673 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800674 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700675 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800676
Dan Stoza00101052014-05-02 15:23:40 -0700677 Vector<DisplayInfo> configs;
678 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
679 configs.size() == 0) {
680 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800681 }
682
Dan Stoza00101052014-05-02 15:23:40 -0700683 jobjectArray configArray = env->NewObjectArray(configs.size(),
684 gPhysicalDisplayInfoClassInfo.clazz, NULL);
685
686 for (size_t c = 0; c < configs.size(); ++c) {
687 const DisplayInfo& info = configs[c];
688 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
689 gPhysicalDisplayInfoClassInfo.ctor);
690 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
691 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
692 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
693 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
694 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
695 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
696 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700697 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
698 info.appVsyncOffset);
699 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
700 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700701 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
702 env->DeleteLocalRef(infoObj);
703 }
704
705 return configArray;
706}
707
Ady Abraham6070ce12019-01-24 18:48:58 -0800708static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
709 jobject tokenObj, jintArray configArray) {
710 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
711 if (token == nullptr) return JNI_FALSE;
712
713 std::vector<int32_t> allowedConfigs;
714 jsize configArraySize = env->GetArrayLength(configArray);
715 allowedConfigs.reserve(configArraySize);
716
717 jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
718 for (int i = 0; i < configArraySize; i++) {
719 allowedConfigs.push_back(configArrayElements[i]);
720 }
721 env->ReleaseIntArrayElements(configArray, configArrayElements, 0);
722
723 size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
724 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
725}
726
Ady Abraham42f9a2fb2019-02-26 14:13:39 -0800727static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
728 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
729 if (token == nullptr) return JNI_FALSE;
730
731 std::vector<int32_t> allowedConfigs;
732 size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs);
733 if (result != NO_ERROR) {
734 return nullptr;
735 }
736
737 jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size());
738 if (allowedConfigsArray == nullptr) {
739 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
740 return nullptr;
741 }
742 jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0);
743 for (size_t i = 0; i < allowedConfigs.size(); i++) {
744 allowedConfigsArrayValues[i] = static_cast<jint>(allowedConfigs[i]);
745 }
746 env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0);
747 return allowedConfigsArray;
748}
749
Dan Stoza00101052014-05-02 15:23:40 -0700750static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
751 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
752 if (token == NULL) return -1;
753 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
754}
755
756static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
757 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
758 if (token == NULL) return JNI_FALSE;
759 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
760 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800761}
762
Michael Wright1c9977b2016-07-12 13:30:10 -0700763static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
764 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
765 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700766 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700767 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
768 colorModes.isEmpty()) {
769 return NULL;
770 }
771
772 jintArray colorModesArray = env->NewIntArray(colorModes.size());
773 if (colorModesArray == NULL) {
774 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
775 return NULL;
776 }
777 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
778 for (size_t i = 0; i < colorModes.size(); i++) {
779 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
780 }
781 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
782 return colorModesArray;
783}
784
Daniel Solomon10e3b332019-01-20 21:09:11 -0800785static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
786 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
787 if (token == NULL) return NULL;
788
789 ui::DisplayPrimaries primaries;
790 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
791 return NULL;
792 }
793
794 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
795 if (jred == NULL) {
796 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
797 return NULL;
798 }
799
800 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
801 if (jgreen == NULL) {
802 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
803 return NULL;
804 }
805
806 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
807 if (jblue == NULL) {
808 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
809 return NULL;
810 }
811
812 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
813 if (jwhite == NULL) {
814 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
815 return NULL;
816 }
817
818 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
819 gDisplayPrimariesClassInfo.ctor);
820 if (jprimaries == NULL) {
821 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
822 return NULL;
823 }
824
825 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
826 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
827 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
828 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
829 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
830 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
831 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
832 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
833 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
834 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
835 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
836 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
837 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
838 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
839 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
840 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
841
842 return jprimaries;
843}
844
Michael Wright1c9977b2016-07-12 13:30:10 -0700845static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
846 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
847 if (token == NULL) return -1;
848 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
849}
850
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800851static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
852 ui::Dataspace defaultDataspace, wcgDataspace;
853 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
854 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
855 &defaultPixelFormat,
856 &wcgDataspace,
857 &wcgPixelFormat) != NO_ERROR) {
858 return nullptr;
859 }
860 jintArray array = env->NewIntArray(2);
861 if (array == nullptr) {
862 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
863 return nullptr;
864 }
865 jint* arrayValues = env->GetIntArrayElements(array, 0);
866 arrayValues[0] = static_cast<jint>(defaultDataspace);
867 arrayValues[1] = static_cast<jint>(wcgDataspace);
868 env->ReleaseIntArrayElements(array, arrayValues, 0);
869 return array;
870}
871
Michael Wright1c9977b2016-07-12 13:30:10 -0700872static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
873 jobject tokenObj, jint colorMode) {
874 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
875 if (token == NULL) return JNI_FALSE;
876 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700877 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700878 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
879}
880
Prashant Malanic55929a2014-05-25 01:59:21 -0700881static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800882 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
883 if (token == NULL) return;
884
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700885 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700886 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700887 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800888}
889
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800890static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
891 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
892}
893
Svetoslav1376d602014-03-13 11:17:26 -0700894static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
895 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
896 status_t err = ctrl->clearLayerFrameStats();
897
898 if (err < 0 && err != NO_INIT) {
899 doThrowIAE(env);
900 }
901
902 // The other end is not ready, just report we failed.
903 if (err == NO_INIT) {
904 return JNI_FALSE;
905 }
906
907 return JNI_TRUE;
908}
909
910static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
911 jobject outStats) {
912 FrameStats stats;
913
914 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
915 status_t err = ctrl->getLayerFrameStats(&stats);
916 if (err < 0 && err != NO_INIT) {
917 doThrowIAE(env);
918 }
919
920 // The other end is not ready, fine just return empty stats.
921 if (err == NO_INIT) {
922 return JNI_FALSE;
923 }
924
925 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
926 size_t frameCount = stats.desiredPresentTimesNano.size();
927
928 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
929 if (postedTimesNanoDst == NULL) {
930 return JNI_FALSE;
931 }
932
933 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
934 if (presentedTimesNanoDst == NULL) {
935 return JNI_FALSE;
936 }
937
938 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
939 if (readyTimesNanoDst == NULL) {
940 return JNI_FALSE;
941 }
942
943 nsecs_t postedTimesNanoSrc[frameCount];
944 nsecs_t presentedTimesNanoSrc[frameCount];
945 nsecs_t readyTimesNanoSrc[frameCount];
946
947 for (size_t i = 0; i < frameCount; i++) {
948 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
949 if (postedTimeNano == INT64_MAX) {
950 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
951 }
952 postedTimesNanoSrc[i] = postedTimeNano;
953
954 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
955 if (presentedTimeNano == INT64_MAX) {
956 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
957 }
958 presentedTimesNanoSrc[i] = presentedTimeNano;
959
960 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
961 if (readyTimeNano == INT64_MAX) {
962 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
963 }
964 readyTimesNanoSrc[i] = readyTimeNano;
965 }
966
967 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
968 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
969 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
970
971 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
972 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
973
974 if (env->ExceptionCheck()) {
975 return JNI_FALSE;
976 }
977
978 return JNI_TRUE;
979}
980
981static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
982 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
983
984 if (err < 0 && err != NO_INIT) {
985 doThrowIAE(env);
986 }
987
988 // The other end is not ready, just report we failed.
989 if (err == NO_INIT) {
990 return JNI_FALSE;
991 }
992
993 return JNI_TRUE;
994}
995
996static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
997 FrameStats stats;
998
999 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1000 if (err < 0 && err != NO_INIT) {
1001 doThrowIAE(env);
1002 }
1003
1004 // The other end is not ready, fine just return empty stats.
1005 if (err == NO_INIT) {
1006 return JNI_FALSE;
1007 }
1008
1009 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1010 size_t frameCount = stats.desiredPresentTimesNano.size();
1011
1012 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1013 if (presentedTimesNanoDst == NULL) {
1014 return JNI_FALSE;
1015 }
1016
1017 nsecs_t presentedTimesNanoSrc[frameCount];
1018
1019 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -07001020 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -07001021 if (presentedTimeNano == INT64_MAX) {
1022 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1023 }
1024 presentedTimesNanoSrc[i] = presentedTimeNano;
1025 }
1026
1027 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1028
1029 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1030 presentedTimesNanoDst);
1031
1032 if (env->ExceptionCheck()) {
1033 return JNI_FALSE;
1034 }
1035
1036 return JNI_TRUE;
1037}
1038
Robert Carre13b58e2017-08-31 14:50:44 -07001039static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
1040 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +00001041 jobject handleObject, jlong frameNumber) {
1042 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1043 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
1044
Robert Carre13b58e2017-08-31 14:50:44 -07001045 {
1046 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001047 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -07001048 }
Rob Carr64e516f2015-10-29 00:20:45 +00001049}
1050
Robert Carre13b58e2017-08-31 14:50:44 -07001051static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1052 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001053 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001054 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1055
Robert Carrd5c7dd62017-03-08 10:39:30 -08001056 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1057 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1058
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001059 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001060}
1061
Robert Carre13b58e2017-08-31 14:50:44 -07001062static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1063 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001064 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001065
Robert Carrd5c7dd62017-03-08 10:39:30 -08001066 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1067 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
1068
Robert Carre13b58e2017-08-31 14:50:44 -07001069 {
1070 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1071 transaction->reparentChildren(ctrl, handle);
1072 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001073}
1074
Robert Carre13b58e2017-08-31 14:50:44 -07001075static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1076 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001077 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001078 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001079 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001080
1081 {
1082 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -08001083 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -07001084 }
chaviw63542382017-08-17 17:39:29 -07001085}
1086
Robert Carre13b58e2017-08-31 14:50:44 -07001087static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1088 jlong nativeObject) {
1089 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1090
Robert Carrd5c7dd62017-03-08 10:39:30 -08001091 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001092 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001093}
1094
Robert Carre13b58e2017-08-31 14:50:44 -07001095static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1096 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001097 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001098 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001099
Robert Carre13b58e2017-08-31 14:50:44 -07001100 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1101 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001102}
1103
Rob Carr64e516f2015-10-29 00:20:45 +00001104static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
1105 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +00001106 return javaObjectForIBinder(env, ctrl->getHandle());
1107}
1108
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001109static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1110 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1111 if (token == NULL) return NULL;
1112
1113 HdrCapabilities capabilities;
1114 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1115
1116 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001117 std::vector<int32_t> intTypes;
1118 for (auto type : types) {
1119 intTypes.push_back(static_cast<int32_t>(type));
1120 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001121 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001122 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001123
Michael Wright9ff94c02016-03-30 18:05:40 -07001124 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001125 typesArray, capabilities.getDesiredMaxLuminance(),
1126 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1127}
1128
Jorim Jaggi06975df2017-12-01 14:52:13 +01001129static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1130 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1131 if (parcel == NULL) {
1132 doThrowNPE(env);
1133 return 0;
1134 }
1135 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1136 if (surface == nullptr) {
1137 return 0;
1138 }
1139 surface->incStrong((void *)nativeCreate);
1140 return reinterpret_cast<jlong>(surface.get());
1141}
1142
chaviwbeb7a0c2018-12-05 13:49:54 -08001143static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1144 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1145 if (surface == nullptr) {
1146 return 0;
1147 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001148
1149 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1150 newSurface->incStrong((void *)nativeCreate);
1151 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001152}
1153
Jorim Jaggi06975df2017-12-01 14:52:13 +01001154static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1155 jlong nativeObject, jobject parcelObj) {
1156 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1157 if (parcel == NULL) {
1158 doThrowNPE(env);
1159 return;
1160 }
1161 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001162 if (self != nullptr) {
1163 self->writeToParcel(parcel);
1164 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001165}
1166
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001167// ----------------------------------------------------------------------------
1168
Daniel Micay76f6a862015-09-19 17:31:01 -04001169static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001170 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001171 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001172 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1173 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001174 {"nativeCopyFromSurfaceControl", "(J)J" ,
1175 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001176 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1177 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001178 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001179 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001180 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001181 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -08001182 {"nativeDisconnect", "(J)V",
1183 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001184 {"nativeCreateTransaction", "()J",
1185 (void*)nativeCreateTransaction },
1186 {"nativeApplyTransaction", "(JZ)V",
1187 (void*)nativeApplyTransaction },
1188 {"nativeGetNativeTransactionFinalizer", "()J",
1189 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001190 {"nativeMergeTransaction", "(JJ)V",
1191 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001192 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001193 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001194 {"nativeSetEarlyWakeup", "(J)V",
1195 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001196 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001197 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001198 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -07001199 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001200 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001201 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001202 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -07001203 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -07001204 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001205 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001206 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001207 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001208 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001209 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001210 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001211 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001212 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001213 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001214 {"nativeSetColorTransform", "(JJ[F[F)V",
1215 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001216 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1217 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001218 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001219 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001220 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001221 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001222 {"nativeSetCornerRadius", "(JJF)V",
1223 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001224 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001225 (void*)nativeSetLayerStack },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001226 {"nativeGetPhysicalDisplayIds", "()[J",
1227 (void*)nativeGetPhysicalDisplayIds },
1228 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1229 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001230 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1231 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001232 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1233 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001234 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001235 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001236 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001237 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001238 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001239 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001240 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001241 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001242 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1243 (void*)nativeGetDisplayConfigs },
1244 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1245 (void*)nativeGetActiveConfig },
1246 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1247 (void*)nativeSetActiveConfig },
Ady Abraham6070ce12019-01-24 18:48:58 -08001248 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1249 (void*)nativeSetAllowedDisplayConfigs },
Ady Abraham42f9a2fb2019-02-26 14:13:39 -08001250 {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
1251 (void*)nativeGetAllowedDisplayConfigs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001252 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1253 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001254 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1255 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001256 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1257 (void*)nativeGetActiveColorMode},
1258 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1259 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001260 {"nativeGetCompositionDataspaces", "()[I",
1261 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001262 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1263 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001264 {"nativeClearContentFrameStats", "(J)Z",
1265 (void*)nativeClearContentFrameStats },
1266 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1267 (void*)nativeGetContentFrameStats },
1268 {"nativeClearAnimationFrameStats", "()Z",
1269 (void*)nativeClearAnimationFrameStats },
1270 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1271 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001272 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1273 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001274 {"nativeGetProtectedContentSupport", "()Z",
1275 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001276 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001277 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001278 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001279 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001280 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001281 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001282 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001283 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001284 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001285 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001286 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001287 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001288 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001289 (void*)nativeGetHandle },
Robert Carr5c52b132019-02-15 15:48:11 -08001290 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)Landroid/graphics/GraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001291 (void*)nativeScreenshot },
Chavi Weingartenea2eb5a2017-11-29 21:26:24 +00001292 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001293 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001294 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001295 (void*)nativeSetInputWindowInfo },
1296 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1297 (void*)nativeTransferTouchFocus },
Evan Rosky485df202018-12-06 14:11:12 -08001298 {"nativeSetMetadata", "(JILandroid/os/Parcel;)V",
1299 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001300 {"nativeGetDisplayedContentSamplingAttributes",
1301 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1302 (void*)nativeGetDisplayedContentSamplingAttributes },
1303 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1304 (void*)nativeSetDisplayedContentSamplingEnabled },
1305 {"nativeGetDisplayedContentSample",
1306 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1307 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001308 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001309 (void*)nativeSetGeometry },
1310 {"nativeSyncInputWindows", "(J)V",
1311 (void*)nativeSyncInputWindows }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001312};
1313
1314int register_android_view_SurfaceControl(JNIEnv* env)
1315{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001316 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001317 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1318
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001319 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1320 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1321 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1322 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1323 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1324 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1325 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1326 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1327 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1328 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1329 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1330 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1331 clazz, "appVsyncOffsetNanos", "J");
1332 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1333 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001334
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001335 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1336 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1337 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1338 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1339 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001340
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001341 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1342 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1343 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001344 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1345
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001346 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1347 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1348 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001349 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1350
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001351 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1352 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1353 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001354 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1355
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001356 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1357 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1358 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1359 "([IFFF)V");
1360
Robert Carr6486d312017-01-09 19:48:29 -08001361 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1362 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1363 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1364 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1365
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001366 jclass displayedContentSampleClazz = FindClassOrDie(env,
1367 "android/hardware/display/DisplayedContentSample");
1368 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1369 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1370 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1371
1372 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1373 "android/hardware/display/DisplayedContentSamplingAttributes");
1374 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1375 displayedContentSamplingAttributesClazz);
1376 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1377 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001378
1379 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1380 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1381 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1382 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1383 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1384 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1385
1386 jclass displayPrimariesClazz = FindClassOrDie(env,
1387 "android/view/SurfaceControl$DisplayPrimaries");
1388 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1389 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1390 "<init>", "()V");
1391 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1392 "Landroid/view/SurfaceControl$CieXyz;");
1393 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1394 "Landroid/view/SurfaceControl$CieXyz;");
1395 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1396 "Landroid/view/SurfaceControl$CieXyz;");
1397 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1398 "Landroid/view/SurfaceControl$CieXyz;");
1399
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001400 return err;
1401}
1402
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001403} // namespace android