blob: fad2fe0d384520054b7ca4636dc2ae5a3d653a93 [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));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800181 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800182}
183
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000184static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800185 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
186 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800187 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800188}
189
Chong Zhang47e36a32016-02-29 16:44:33 -0800190static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
191 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
192 if (ctrl != NULL) {
193 ctrl->disconnect();
194 }
195}
196
Robert Carr6486d312017-01-09 19:48:29 -0800197static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
198 int left = env->GetIntField(rectObj, gRectClassInfo.left);
199 int top = env->GetIntField(rectObj, gRectClassInfo.top);
200 int right = env->GetIntField(rectObj, gRectClassInfo.right);
201 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
202 return Rect(left, top, right, bottom);
203}
204
chaviw08520a02018-09-10 16:44:56 -0700205static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800206 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
chaviw08520a02018-09-10 16:44:56 -0700207 bool useIdentityTransform, int rotation) {
Robert Carr6486d312017-01-09 19:48:29 -0800208 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
209 if (displayToken == NULL) {
210 return NULL;
211 }
212 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800213 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700214 status_t res = ScreenshotClient::capture(displayToken, ui::Dataspace::V0_SRGB,
215 ui::PixelFormat::RGBA_8888,
216 sourceCrop, width, height,
217 useIdentityTransform, rotation, &buffer);
Robert Carr6486d312017-01-09 19:48:29 -0800218 if (res != NO_ERROR) {
219 return NULL;
220 }
221
222 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
223 gGraphicBufferClassInfo.builder,
224 buffer->getWidth(),
225 buffer->getHeight(),
226 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700227 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100228 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800229}
230
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000231static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
chaviwfbe47df2017-11-10 16:14:49 -0800232 jobject sourceCropObj, jfloat frameScale) {
233
234 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
235 if (layerHandle == NULL) {
236 return NULL;
237 }
238
239 Rect sourceCrop;
240 if (sourceCropObj != NULL) {
241 sourceCrop = rectFromObj(env, sourceCropObj);
242 }
243
244 sp<GraphicBuffer> buffer;
Peiyong Lin10a34d12018-09-19 13:56:12 -0700245 status_t res = ScreenshotClient::captureChildLayers(layerHandle, ui::Dataspace::V0_SRGB,
246 ui::PixelFormat::RGBA_8888, sourceCrop,
247 frameScale, &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800248 if (res != NO_ERROR) {
249 return NULL;
250 }
251
252 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
253 gGraphicBufferClassInfo.builder,
254 buffer->getWidth(),
255 buffer->getHeight(),
256 buffer->getPixelFormat(),
257 (jint)buffer->getUsage(),
258 (jlong)buffer.get());
chaviw1cda84c2017-10-23 16:47:10 -0700259}
260
Robert Carre13b58e2017-08-31 14:50:44 -0700261static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
262 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
263 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800264}
265
Robert Carrb1579c82017-09-05 14:54:47 -0700266static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
267 jlong transactionObj, jlong otherTransactionObj) {
268 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
269 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
270 otherTransactionObj);
271 transaction->merge(std::move(*otherTransaction));
272}
273
Robert Carre13b58e2017-08-31 14:50:44 -0700274static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
275 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
276 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800277}
278
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100279static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
280 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
281 transaction->setEarlyWakeup();
282}
283
Robert Carre13b58e2017-08-31 14:50:44 -0700284static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
285 jlong nativeObject, jint zorder) {
286 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800287
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800288 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700289 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800290}
291
Robert Carre13b58e2017-08-31 14:50:44 -0700292static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
293 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700294 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700295
Robert Carraf422a82017-04-10 18:34:33 -0700296 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
297 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
298
Robert Carre13b58e2017-08-31 14:50:44 -0700299 {
300 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
301 transaction->setRelativeLayer(ctrl, handle, zorder);
302 }
Robert Carraf422a82017-04-10 18:34:33 -0700303}
304
Robert Carre13b58e2017-08-31 14:50:44 -0700305static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
306 jlong nativeObject, jfloat x, jfloat y) {
307 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
308
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800309 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700310 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800311}
312
Robert Carr76907ee2019-01-11 13:38:19 -0800313static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
314 jobject sourceObj, jobject dstObj, jlong orientation) {
315 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
316 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
317
318 Rect source, dst;
319 if (sourceObj != NULL) {
320 source = rectFromObj(env, sourceObj);
321 }
322 if (dstObj != NULL) {
323 dst = rectFromObj(env, dstObj);
324 }
325 transaction->setGeometry(ctrl, source, dst, orientation);
326}
327
Robert Carr6da3cc02016-06-16 15:17:07 -0700328static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700329jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700330 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700331 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
332
Robert Carra9408d42016-06-03 13:28:48 -0700333 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700334 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700335}
336
Robert Carre13b58e2017-08-31 14:50:44 -0700337static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
338 jlong nativeObject, jint w, jint h) {
339 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
340
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800341 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700342 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800343}
344
Robert Carre13b58e2017-08-31 14:50:44 -0700345static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
346 jlong nativeObject, jint flags, jint mask) {
347 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
348
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800349 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700350 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800351}
352
Robert Carre13b58e2017-08-31 14:50:44 -0700353static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
354 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800355 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
356 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
357 if (!region) {
358 doThrowIAE(env);
359 return;
360 }
361
362 const SkIRect& b(region->getBounds());
363 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
364 if (region->isComplex()) {
365 SkRegion::Iterator it(*region);
366 while (!it.done()) {
367 const SkIRect& r(it.rect());
368 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
369 it.next();
370 }
371 }
372
Robert Carre13b58e2017-08-31 14:50:44 -0700373 {
374 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
375 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800376 }
377}
378
Robert Carre13b58e2017-08-31 14:50:44 -0700379static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
380 jlong nativeObject, jfloat alpha) {
381 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
382
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800383 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700384 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800385}
386
Robert Carr788f5742018-07-30 17:46:45 -0700387static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
388 jlong nativeObject, jobject inputWindow) {
389 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
390
Riddle Hsucd958bc2019-01-23 15:40:26 +0800391 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700392 env, inputWindow);
393 handle->updateInfo();
394
395 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
396 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
397}
398
chaviw59f532e2018-12-26 15:34:59 -0800399static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
400 jobject fromTokenObj, jobject toTokenObj) {
401 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
402
403 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
404 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
405 transaction->transferTouchFocus(fromToken, toToken);
406}
407
Evan Rosky485df202018-12-06 14:11:12 -0800408static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
409 jlong nativeObject, jint id, jobject parcelObj) {
410 Parcel* parcel = parcelForJavaObject(env, parcelObj);
411 if (!parcel) {
412 jniThrowNullPointerException(env, "attribute data");
413 return;
414 }
415 if (parcel->objectsCount()) {
416 jniThrowException(env, "java/lang/RuntimeException",
417 "Tried to marshall a Parcel that contained Binder objects.");
418 return;
419 }
420
421 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
422
423 std::vector<uint8_t> byteData(parcel->dataSize());
424 memcpy(byteData.data(), parcel->data(), parcel->dataSize());
425
426 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
427 transaction->setMetadata(ctrl, id, std::move(byteData));
428}
429
Robert Carre13b58e2017-08-31 14:50:44 -0700430static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
431 jlong nativeObject, jfloatArray fColor) {
432 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700433 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700434
chaviw0dd03f52017-08-25 12:15:26 -0700435 float* floatColors = env->GetFloatArrayElements(fColor, 0);
436 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700437 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700438}
439
Robert Carre13b58e2017-08-31 14:50:44 -0700440static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
441 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800442 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700443 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
444
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800445 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700446 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800447}
448
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700449static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
450 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
451 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
452 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
453 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
454 mat3 matrix(static_cast<float const*>(floatMatrix));
455 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
456 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
457 transaction->setColorTransform(surfaceControl, matrix, translation);
458}
459
Robert Carre13b58e2017-08-31 14:50:44 -0700460static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
461 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800462 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700463 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
464
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800465 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
466 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700467 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800468}
469
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700470static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
471 jlong nativeObject, jfloat cornerRadius) {
472 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
473
474 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
475 transaction->setCornerRadius(ctrl, cornerRadius);
476}
477
Robert Carre13b58e2017-08-31 14:50:44 -0700478static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
479 jlong nativeObject, jint layerStack) {
480 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
481
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800482 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700483 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800484}
485
486static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
487 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
488 return javaObjectForIBinder(env, token);
489}
490
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700491static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
492 jobject tokenObj) {
493 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
494
495 ui::PixelFormat format;
496 ui::Dataspace dataspace;
497 uint8_t componentMask;
498 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
499 token, &format, &dataspace, &componentMask);
500 if (err != OK) {
501 return nullptr;
502 }
503 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
504 gDisplayedContentSamplingAttributesClassInfo.ctor,
505 format, dataspace, componentMask);
506}
507
508static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
509 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
510 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800511 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700512 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800513 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700514}
515
516static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
517 jlong maxFrames, jlong timestamp) {
518 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
519
520 DisplayedFrameStats stats;
521 status_t err = SurfaceComposerClient::getDisplayedContentSample(
522 token, maxFrames, timestamp, &stats);
523 if (err != OK) {
524 return nullptr;
525 }
526
527 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
528 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
529 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
530 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
531 if ((histogramComponent0 == nullptr) ||
532 (histogramComponent1 == nullptr) ||
533 (histogramComponent2 == nullptr) ||
534 (histogramComponent3 == nullptr)) {
535 return JNI_FALSE;
536 }
537
538 env->SetLongArrayRegion(histogramComponent0, 0,
539 stats.component_0_sample.size(),
540 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
541 env->SetLongArrayRegion(histogramComponent1, 0,
542 stats.component_1_sample.size(),
543 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
544 env->SetLongArrayRegion(histogramComponent2, 0,
545 stats.component_2_sample.size(),
546 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
547 env->SetLongArrayRegion(histogramComponent3, 0,
548 stats.component_3_sample.size(),
549 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
550 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
551 gDisplayedContentSampleClassInfo.ctor,
552 stats.numFrames,
553 histogramComponent0,
554 histogramComponent1,
555 histogramComponent2,
556 histogramComponent3);
557}
558
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800559static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
560 jboolean secure) {
561 ScopedUtfChars name(env, nameObj);
562 sp<IBinder> token(SurfaceComposerClient::createDisplay(
563 String8(name.c_str()), bool(secure)));
564 return javaObjectForIBinder(env, token);
565}
566
Jesse Hall6a6bc212013-08-08 12:15:03 -0700567static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
568 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
569 if (token == NULL) return;
570 SurfaceComposerClient::destroyDisplay(token);
571}
572
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800573static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700574 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000575 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800576 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
577 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800578 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800579 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800580 if (sur != NULL) {
581 bufferProducer = sur->getIGraphicBufferProducer();
582 }
Robert Carre13b58e2017-08-31 14:50:44 -0700583
584
585 status_t err = NO_ERROR;
586 {
587 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
588 err = transaction->setDisplaySurface(token,
589 bufferProducer);
590 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700591 if (err != NO_ERROR) {
592 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
593 " Surface created with singleBufferMode?");
594 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800595}
596
597static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700598 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800599 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700600
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800601 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
602 if (token == NULL) return;
603
Robert Carre13b58e2017-08-31 14:50:44 -0700604 {
605 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
606 transaction->setDisplayLayerStack(token, layerStack);
607 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800608}
609
610static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700611 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800612 jobject tokenObj, jint orientation,
613 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
614 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
615 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
616 if (token == NULL) return;
617 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
618 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700619
620 {
621 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
622 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
623 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800624}
625
Michael Wright01e840f2014-06-26 16:03:25 -0700626static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700627 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700628 jobject tokenObj, jint width, jint height) {
629 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
630 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700631
632 {
633 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
634 transaction->setDisplaySize(token, width, height);
635 }
Michael Wright01e840f2014-06-26 16:03:25 -0700636}
637
Dan Stoza00101052014-05-02 15:23:40 -0700638static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
639 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800640 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700641 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800642
Dan Stoza00101052014-05-02 15:23:40 -0700643 Vector<DisplayInfo> configs;
644 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
645 configs.size() == 0) {
646 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800647 }
648
Dan Stoza00101052014-05-02 15:23:40 -0700649 jobjectArray configArray = env->NewObjectArray(configs.size(),
650 gPhysicalDisplayInfoClassInfo.clazz, NULL);
651
652 for (size_t c = 0; c < configs.size(); ++c) {
653 const DisplayInfo& info = configs[c];
654 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
655 gPhysicalDisplayInfoClassInfo.ctor);
656 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
657 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
658 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
659 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
660 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
661 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
662 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700663 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
664 info.appVsyncOffset);
665 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
666 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700667 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
668 env->DeleteLocalRef(infoObj);
669 }
670
671 return configArray;
672}
673
674static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
675 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
676 if (token == NULL) return -1;
677 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
678}
679
680static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
681 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
682 if (token == NULL) return JNI_FALSE;
683 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
684 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800685}
686
Michael Wright1c9977b2016-07-12 13:30:10 -0700687static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
688 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
689 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700690 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700691 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
692 colorModes.isEmpty()) {
693 return NULL;
694 }
695
696 jintArray colorModesArray = env->NewIntArray(colorModes.size());
697 if (colorModesArray == NULL) {
698 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
699 return NULL;
700 }
701 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
702 for (size_t i = 0; i < colorModes.size(); i++) {
703 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
704 }
705 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
706 return colorModesArray;
707}
708
Daniel Solomon10e3b332019-01-20 21:09:11 -0800709static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
710 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
711 if (token == NULL) return NULL;
712
713 ui::DisplayPrimaries primaries;
714 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
715 return NULL;
716 }
717
718 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
719 if (jred == NULL) {
720 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
721 return NULL;
722 }
723
724 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
725 if (jgreen == NULL) {
726 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
727 return NULL;
728 }
729
730 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
731 if (jblue == NULL) {
732 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
733 return NULL;
734 }
735
736 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
737 if (jwhite == NULL) {
738 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
739 return NULL;
740 }
741
742 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
743 gDisplayPrimariesClassInfo.ctor);
744 if (jprimaries == NULL) {
745 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
746 return NULL;
747 }
748
749 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
750 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
751 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
752 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
753 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
754 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
755 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
756 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
757 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
758 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
759 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
760 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
761 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
762 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
763 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
764 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
765
766 return jprimaries;
767}
768
Michael Wright1c9977b2016-07-12 13:30:10 -0700769static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
770 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
771 if (token == NULL) return -1;
772 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
773}
774
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800775static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
776 ui::Dataspace defaultDataspace, wcgDataspace;
777 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
778 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
779 &defaultPixelFormat,
780 &wcgDataspace,
781 &wcgPixelFormat) != NO_ERROR) {
782 return nullptr;
783 }
784 jintArray array = env->NewIntArray(2);
785 if (array == nullptr) {
786 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
787 return nullptr;
788 }
789 jint* arrayValues = env->GetIntArrayElements(array, 0);
790 arrayValues[0] = static_cast<jint>(defaultDataspace);
791 arrayValues[1] = static_cast<jint>(wcgDataspace);
792 env->ReleaseIntArrayElements(array, arrayValues, 0);
793 return array;
794}
795
Michael Wright1c9977b2016-07-12 13:30:10 -0700796static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
797 jobject tokenObj, jint colorMode) {
798 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
799 if (token == NULL) return JNI_FALSE;
800 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700801 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700802 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
803}
804
Prashant Malanic55929a2014-05-25 01:59:21 -0700805static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800806 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
807 if (token == NULL) return;
808
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700809 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700810 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700811 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800812}
813
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800814static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
815 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
816}
817
Svetoslav1376d602014-03-13 11:17:26 -0700818static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
819 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
820 status_t err = ctrl->clearLayerFrameStats();
821
822 if (err < 0 && err != NO_INIT) {
823 doThrowIAE(env);
824 }
825
826 // The other end is not ready, just report we failed.
827 if (err == NO_INIT) {
828 return JNI_FALSE;
829 }
830
831 return JNI_TRUE;
832}
833
834static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
835 jobject outStats) {
836 FrameStats stats;
837
838 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
839 status_t err = ctrl->getLayerFrameStats(&stats);
840 if (err < 0 && err != NO_INIT) {
841 doThrowIAE(env);
842 }
843
844 // The other end is not ready, fine just return empty stats.
845 if (err == NO_INIT) {
846 return JNI_FALSE;
847 }
848
849 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
850 size_t frameCount = stats.desiredPresentTimesNano.size();
851
852 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
853 if (postedTimesNanoDst == NULL) {
854 return JNI_FALSE;
855 }
856
857 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
858 if (presentedTimesNanoDst == NULL) {
859 return JNI_FALSE;
860 }
861
862 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
863 if (readyTimesNanoDst == NULL) {
864 return JNI_FALSE;
865 }
866
867 nsecs_t postedTimesNanoSrc[frameCount];
868 nsecs_t presentedTimesNanoSrc[frameCount];
869 nsecs_t readyTimesNanoSrc[frameCount];
870
871 for (size_t i = 0; i < frameCount; i++) {
872 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
873 if (postedTimeNano == INT64_MAX) {
874 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
875 }
876 postedTimesNanoSrc[i] = postedTimeNano;
877
878 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
879 if (presentedTimeNano == INT64_MAX) {
880 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
881 }
882 presentedTimesNanoSrc[i] = presentedTimeNano;
883
884 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
885 if (readyTimeNano == INT64_MAX) {
886 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
887 }
888 readyTimesNanoSrc[i] = readyTimeNano;
889 }
890
891 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
892 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
893 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
894
895 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
896 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
897
898 if (env->ExceptionCheck()) {
899 return JNI_FALSE;
900 }
901
902 return JNI_TRUE;
903}
904
905static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
906 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
907
908 if (err < 0 && err != NO_INIT) {
909 doThrowIAE(env);
910 }
911
912 // The other end is not ready, just report we failed.
913 if (err == NO_INIT) {
914 return JNI_FALSE;
915 }
916
917 return JNI_TRUE;
918}
919
920static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
921 FrameStats stats;
922
923 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
924 if (err < 0 && err != NO_INIT) {
925 doThrowIAE(env);
926 }
927
928 // The other end is not ready, fine just return empty stats.
929 if (err == NO_INIT) {
930 return JNI_FALSE;
931 }
932
933 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
934 size_t frameCount = stats.desiredPresentTimesNano.size();
935
936 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
937 if (presentedTimesNanoDst == NULL) {
938 return JNI_FALSE;
939 }
940
941 nsecs_t presentedTimesNanoSrc[frameCount];
942
943 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700944 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700945 if (presentedTimeNano == INT64_MAX) {
946 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
947 }
948 presentedTimesNanoSrc[i] = presentedTimeNano;
949 }
950
951 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
952
953 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
954 presentedTimesNanoDst);
955
956 if (env->ExceptionCheck()) {
957 return JNI_FALSE;
958 }
959
960 return JNI_TRUE;
961}
962
Robert Carre13b58e2017-08-31 14:50:44 -0700963static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
964 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +0000965 jobject handleObject, jlong frameNumber) {
966 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
967 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
968
Robert Carre13b58e2017-08-31 14:50:44 -0700969 {
970 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700971 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -0700972 }
Rob Carr64e516f2015-10-29 00:20:45 +0000973}
974
Robert Carre13b58e2017-08-31 14:50:44 -0700975static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
976 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800977 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -0700978 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
979
Robert Carrd5c7dd62017-03-08 10:39:30 -0800980 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
981 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
982
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700983 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800984}
985
Robert Carre13b58e2017-08-31 14:50:44 -0700986static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
987 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800988 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700989
Robert Carrd5c7dd62017-03-08 10:39:30 -0800990 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
991 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
992
Robert Carre13b58e2017-08-31 14:50:44 -0700993 {
994 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
995 transaction->reparentChildren(ctrl, handle);
996 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800997}
998
Robert Carre13b58e2017-08-31 14:50:44 -0700999static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1000 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001001 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001002 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001003 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001004
1005 {
1006 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -08001007 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -07001008 }
chaviw63542382017-08-17 17:39:29 -07001009}
1010
Robert Carre13b58e2017-08-31 14:50:44 -07001011static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1012 jlong nativeObject) {
1013 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1014
Robert Carrd5c7dd62017-03-08 10:39:30 -08001015 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001016 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001017}
1018
Robert Carre13b58e2017-08-31 14:50:44 -07001019static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1020 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001021 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001022 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001023
Robert Carre13b58e2017-08-31 14:50:44 -07001024 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1025 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001026}
1027
Rob Carr64e516f2015-10-29 00:20:45 +00001028static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
1029 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +00001030 return javaObjectForIBinder(env, ctrl->getHandle());
1031}
1032
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001033static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1034 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1035 if (token == NULL) return NULL;
1036
1037 HdrCapabilities capabilities;
1038 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1039
1040 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001041 std::vector<int32_t> intTypes;
1042 for (auto type : types) {
1043 intTypes.push_back(static_cast<int32_t>(type));
1044 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001045 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001046 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001047
Michael Wright9ff94c02016-03-30 18:05:40 -07001048 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001049 typesArray, capabilities.getDesiredMaxLuminance(),
1050 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1051}
1052
Jorim Jaggi06975df2017-12-01 14:52:13 +01001053static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1054 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1055 if (parcel == NULL) {
1056 doThrowNPE(env);
1057 return 0;
1058 }
1059 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1060 if (surface == nullptr) {
1061 return 0;
1062 }
1063 surface->incStrong((void *)nativeCreate);
1064 return reinterpret_cast<jlong>(surface.get());
1065}
1066
chaviwbeb7a0c2018-12-05 13:49:54 -08001067static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1068 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1069 if (surface == nullptr) {
1070 return 0;
1071 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001072
1073 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1074 newSurface->incStrong((void *)nativeCreate);
1075 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001076}
1077
Jorim Jaggi06975df2017-12-01 14:52:13 +01001078static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1079 jlong nativeObject, jobject parcelObj) {
1080 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1081 if (parcel == NULL) {
1082 doThrowNPE(env);
1083 return;
1084 }
1085 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001086 if (self != nullptr) {
1087 self->writeToParcel(parcel);
1088 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001089}
1090
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001091// ----------------------------------------------------------------------------
1092
Daniel Micay76f6a862015-09-19 17:31:01 -04001093static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001094 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001095 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001096 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1097 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001098 {"nativeCopyFromSurfaceControl", "(J)J" ,
1099 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001100 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1101 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001102 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001103 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001104 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001105 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -08001106 {"nativeDisconnect", "(J)V",
1107 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001108 {"nativeCreateTransaction", "()J",
1109 (void*)nativeCreateTransaction },
1110 {"nativeApplyTransaction", "(JZ)V",
1111 (void*)nativeApplyTransaction },
1112 {"nativeGetNativeTransactionFinalizer", "()J",
1113 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001114 {"nativeMergeTransaction", "(JJ)V",
1115 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001116 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001117 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001118 {"nativeSetEarlyWakeup", "(J)V",
1119 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001120 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001121 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001122 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -07001123 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001124 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001125 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001126 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -07001127 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -07001128 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001129 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001130 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001131 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001132 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001133 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001134 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001135 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001136 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001137 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001138 {"nativeSetColorTransform", "(JJ[F[F)V",
1139 (void*)nativeSetColorTransform },
Robert Carre13b58e2017-08-31 14:50:44 -07001140 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001141 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001142 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001143 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001144 {"nativeSetCornerRadius", "(JJF)V",
1145 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001146 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001147 (void*)nativeSetLayerStack },
1148 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
1149 (void*)nativeGetBuiltInDisplay },
1150 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1151 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001152 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1153 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001154 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001155 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001156 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001157 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001158 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001159 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001160 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001161 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001162 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1163 (void*)nativeGetDisplayConfigs },
1164 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1165 (void*)nativeGetActiveConfig },
1166 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1167 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -07001168 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1169 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001170 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1171 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001172 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1173 (void*)nativeGetActiveColorMode},
1174 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1175 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001176 {"nativeGetCompositionDataspaces", "()[I",
1177 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001178 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1179 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001180 {"nativeClearContentFrameStats", "(J)Z",
1181 (void*)nativeClearContentFrameStats },
1182 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1183 (void*)nativeGetContentFrameStats },
1184 {"nativeClearAnimationFrameStats", "()Z",
1185 (void*)nativeClearAnimationFrameStats },
1186 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1187 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001188 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1189 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001190 {"nativeGetProtectedContentSupport", "()Z",
1191 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001192 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001193 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001194 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001195 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001196 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001197 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001198 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001199 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001200 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001201 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001202 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001203 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001204 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001205 (void*)nativeGetHandle },
chaviw08520a02018-09-10 16:44:56 -07001206 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZI)Landroid/graphics/GraphicBuffer;",
1207 (void*)nativeScreenshot },
Chavi Weingartenea2eb5a2017-11-29 21:26:24 +00001208 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001209 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001210 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001211 (void*)nativeSetInputWindowInfo },
1212 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1213 (void*)nativeTransferTouchFocus },
Evan Rosky485df202018-12-06 14:11:12 -08001214 {"nativeSetMetadata", "(JILandroid/os/Parcel;)V",
1215 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001216 {"nativeGetDisplayedContentSamplingAttributes",
1217 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1218 (void*)nativeGetDisplayedContentSamplingAttributes },
1219 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1220 (void*)nativeSetDisplayedContentSamplingEnabled },
1221 {"nativeGetDisplayedContentSample",
1222 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1223 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001224 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
1225 (void*)nativeSetGeometry }
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001226};
1227
1228int register_android_view_SurfaceControl(JNIEnv* env)
1229{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001230 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001231 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1232
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001233 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1234 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1235 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1236 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1237 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1238 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1239 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1240 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1241 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1242 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1243 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1244 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1245 clazz, "appVsyncOffsetNanos", "J");
1246 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1247 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001248
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001249 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1250 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1251 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1252 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1253 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001254
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001255 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1256 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1257 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001258 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1259
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001260 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1261 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1262 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001263 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1264
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001265 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1266 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1267 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001268 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1269
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001270 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1271 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1272 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1273 "([IFFF)V");
1274
Robert Carr6486d312017-01-09 19:48:29 -08001275 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1276 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1277 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1278 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1279
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001280 jclass displayedContentSampleClazz = FindClassOrDie(env,
1281 "android/hardware/display/DisplayedContentSample");
1282 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1283 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1284 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1285
1286 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1287 "android/hardware/display/DisplayedContentSamplingAttributes");
1288 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1289 displayedContentSamplingAttributesClazz);
1290 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1291 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001292
1293 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1294 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1295 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1296 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1297 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1298 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1299
1300 jclass displayPrimariesClazz = FindClassOrDie(env,
1301 "android/view/SurfaceControl$DisplayPrimaries");
1302 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1303 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1304 "<init>", "()V");
1305 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1306 "Landroid/view/SurfaceControl$CieXyz;");
1307 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1308 "Landroid/view/SurfaceControl$CieXyz;");
1309 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1310 "Landroid/view/SurfaceControl$CieXyz;");
1311 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1312 "Landroid/view/SurfaceControl$CieXyz;");
1313
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001314 return err;
1315}
1316
1317};