blob: b47080f787a1cd06c2ff80a2c96c64c67bfe8c64 [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"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080023#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040024
Derek Sollenberger40d78132019-08-12 11:06:08 -040025#include <android/graphics/region.h>
Derek Sollenberger8b994192019-07-16 13:23:29 -040026#include <android_runtime/AndroidRuntime.h>
Tom Cherry8ed74bb2017-07-10 14:31:18 -070027#include <android-base/chrono_utils.h>
Steven Moreland2279b252017-07-19 09:50:45 -070028#include <nativehelper/JNIHelp.h>
29#include <nativehelper/ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080030#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080031#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032#include <gui/Surface.h>
33#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040034#include <jni.h>
35#include <memory>
36#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070037#include <system/graphics.h>
Daniel Solomon10e3b332019-01-20 21:09:11 -080038#include <ui/ConfigStoreTypes.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080039#include <ui/DisplayInfo.h>
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070040#include <ui/DisplayedFrameStats.h>
Svetoslav1376d602014-03-13 11:17:26 -070041#include <ui/FrameStats.h>
Peiyong Linb88549e2018-03-28 12:03:45 -070042#include <ui/GraphicTypes.h>
Peiyong Lin371b98f2018-03-14 17:29:10 -070043#include <ui/HdrCapabilities.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080044#include <ui/Rect.h>
45#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080046#include <utils/Log.h>
47
Mathias Agopian3866f0d2013-02-11 22:08:48 -080048// ----------------------------------------------------------------------------
49
50namespace android {
51
Derek Sollenberger8b994192019-07-16 13:23:29 -040052static void doThrowNPE(JNIEnv* env) {
53 jniThrowNullPointerException(env, NULL);
54}
55
56static void doThrowIAE(JNIEnv* env, const char* msg = nullptr) {
57 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
58}
59
Mathias Agopian3866f0d2013-02-11 22:08:48 -080060static const char* const OutOfResourcesException =
61 "android/view/Surface$OutOfResourcesException";
62
63static struct {
Dan Stoza00101052014-05-02 15:23:40 -070064 jclass clazz;
65 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080066 jfieldID width;
67 jfieldID height;
68 jfieldID refreshRate;
69 jfieldID density;
70 jfieldID xDpi;
71 jfieldID yDpi;
72 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070073 jfieldID appVsyncOffsetNanos;
74 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080075} gPhysicalDisplayInfoClassInfo;
76
Dan Stoza9890e3412014-05-22 16:12:54 -070077static struct {
78 jfieldID bottom;
79 jfieldID left;
80 jfieldID right;
81 jfieldID top;
82} gRectClassInfo;
83
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050084// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
85void DeleteScreenshot(void* addr, void* context) {
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050086 delete ((ScreenshotClient*) context);
87}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080088
Svetoslav1376d602014-03-13 11:17:26 -070089static struct {
90 nsecs_t UNDEFINED_TIME_NANO;
91 jmethodID init;
92} gWindowContentFrameStatsClassInfo;
93
94static struct {
95 nsecs_t UNDEFINED_TIME_NANO;
96 jmethodID init;
97} gWindowAnimationFrameStatsClassInfo;
98
Hangyu Kuang54ac2192016-04-25 13:22:02 -070099static struct {
100 jclass clazz;
101 jmethodID ctor;
102} gHdrCapabilitiesClassInfo;
103
Robert Carr6486d312017-01-09 19:48:29 -0800104static struct {
105 jclass clazz;
106 jmethodID builder;
107} gGraphicBufferClassInfo;
108
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700109static struct {
110 jclass clazz;
111 jmethodID ctor;
112} gDisplayedContentSampleClassInfo;
113
114static struct {
115 jclass clazz;
116 jmethodID ctor;
117} gDisplayedContentSamplingAttributesClassInfo;
118
Daniel Solomon10e3b332019-01-20 21:09:11 -0800119static struct {
120 jclass clazz;
121 jmethodID ctor;
122 jfieldID X;
123 jfieldID Y;
124 jfieldID Z;
125} gCieXyzClassInfo;
126
127static struct {
128 jclass clazz;
129 jmethodID ctor;
130 jfieldID red;
131 jfieldID green;
132 jfieldID blue;
133 jfieldID white;
134} gDisplayPrimariesClassInfo;
135
Peiyong Line3e5efd2019-03-21 20:59:47 +0000136static struct {
137 jclass clazz;
138 jmethodID builder;
139} gScreenshotGraphicBufferClassInfo;
140
Ana Krulec52f12892019-11-18 03:57:20 -0800141static struct {
142 jclass clazz;
143 jmethodID ctor;
Ana Kruleca74a8642019-11-14 00:51:00 +0100144 jfieldID defaultConfig;
Ana Krulec52f12892019-11-18 03:57:20 -0800145 jfieldID minRefreshRate;
146 jfieldID maxRefreshRate;
147} gDesiredDisplayConfigSpecsClassInfo;
148
Peiyong Line3e5efd2019-03-21 20:59:47 +0000149class JNamedColorSpace {
150public:
151 // ColorSpace.Named.SRGB.ordinal() = 0;
152 static constexpr jint SRGB = 0;
153
Peiyong Line9133d52019-05-01 15:36:04 -0700154 // ColorSpace.Named.DISPLAY_P3.ordinal() = 7;
155 static constexpr jint DISPLAY_P3 = 7;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000156};
157
158constexpr jint fromDataspaceToNamedColorSpaceValue(const ui::Dataspace dataspace) {
159 switch (dataspace) {
160 case ui::Dataspace::DISPLAY_P3:
161 return JNamedColorSpace::DISPLAY_P3;
162 default:
163 return JNamedColorSpace::SRGB;
164 }
165}
166
167constexpr ui::Dataspace pickDataspaceFromColorMode(const ui::ColorMode colorMode) {
168 switch (colorMode) {
169 case ui::ColorMode::DISPLAY_P3:
170 case ui::ColorMode::BT2100_PQ:
171 case ui::ColorMode::BT2100_HLG:
172 case ui::ColorMode::DISPLAY_BT2020:
173 return ui::Dataspace::DISPLAY_P3;
174 default:
175 return ui::Dataspace::V0_SRGB;
176 }
177}
178
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800179// ----------------------------------------------------------------------------
180
Robert Carre13b58e2017-08-31 14:50:44 -0700181static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
182 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
183}
184
185static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
186 delete t;
187}
188
189static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
190 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
191}
192
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000193static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500194 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
Evan Rosky485df202018-12-06 14:11:12 -0800195 jobject metadataParcel) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800196 ScopedUtfChars name(env, nameStr);
Robert Carr76907ee2019-01-11 13:38:19 -0800197 sp<SurfaceComposerClient> client;
198 if (sessionObj != NULL) {
199 client = android_view_SurfaceSession_getClient(env, sessionObj);
200 } else {
201 client = SurfaceComposerClient::getDefault();
202 }
Robert Carr838120c2016-11-01 18:31:12 -0700203 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Robert Carrb0f39362018-03-14 13:52:25 -0700204 sp<SurfaceControl> surface;
Evan Rosky485df202018-12-06 14:11:12 -0800205 LayerMetadata metadata;
206 Parcel* parcel = parcelForJavaObject(env, metadataParcel);
207 if (parcel && !parcel->objectsCount()) {
208 status_t err = metadata.readFromParcel(parcel);
209 if (err != NO_ERROR) {
210 jniThrowException(env, "java/lang/IllegalArgumentException",
211 "Metadata parcel has wrong format");
212 }
213 }
214
Robert Carrb0f39362018-03-14 13:52:25 -0700215 status_t err = client->createSurfaceChecked(
Evan Rosky485df202018-12-06 14:11:12 -0800216 String8(name.c_str()), w, h, format, &surface, flags, parent, std::move(metadata));
Robert Carrb0f39362018-03-14 13:52:25 -0700217 if (err == NAME_NOT_FOUND) {
218 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
219 return 0;
220 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800221 jniThrowException(env, OutOfResourcesException, NULL);
222 return 0;
223 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500224
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800225 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000226 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800227}
228
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000229static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800230 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Robert Carrcc6d4832019-02-04 15:41:12 -0800231 ctrl->release();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800232 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800233}
234
Chong Zhang47e36a32016-02-29 16:44:33 -0800235static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
236 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
237 if (ctrl != NULL) {
238 ctrl->disconnect();
239 }
240}
241
Robert Carr6486d312017-01-09 19:48:29 -0800242static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
243 int left = env->GetIntField(rectObj, gRectClassInfo.left);
244 int top = env->GetIntField(rectObj, gRectClassInfo.top);
245 int right = env->GetIntField(rectObj, gRectClassInfo.right);
246 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
247 return Rect(left, top, right, bottom);
248}
249
chaviw08520a02018-09-10 16:44:56 -0700250static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800251 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Robert Carr5c52b132019-02-15 15:48:11 -0800252 bool useIdentityTransform, int rotation, bool captureSecureLayers) {
Robert Carr6486d312017-01-09 19:48:29 -0800253 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
254 if (displayToken == NULL) {
255 return NULL;
256 }
Peiyong Line3e5efd2019-03-21 20:59:47 +0000257 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
258 const ui::Dataspace dataspace = pickDataspaceFromColorMode(colorMode);
259
Robert Carr6486d312017-01-09 19:48:29 -0800260 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800261 sp<GraphicBuffer> buffer;
Robert Carr66b5664f2019-04-02 14:18:56 -0700262 bool capturedSecureLayers = false;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000263 status_t res = ScreenshotClient::capture(displayToken, dataspace,
Robert Carr5c52b132019-02-15 15:48:11 -0800264 ui::PixelFormat::RGBA_8888,
265 sourceCrop, width, height,
Dominik Laskowski2a3d9aa2019-11-18 20:26:39 -0800266 useIdentityTransform, ui::toRotation(rotation),
267 captureSecureLayers, &buffer, capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800268 if (res != NO_ERROR) {
269 return NULL;
270 }
271
Peiyong Line3e5efd2019-03-21 20:59:47 +0000272 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
273 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
274 gScreenshotGraphicBufferClassInfo.builder,
Robert Carr6486d312017-01-09 19:48:29 -0800275 buffer->getWidth(),
276 buffer->getHeight(),
277 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700278 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000279 (jlong)buffer.get(),
Robert Carr66b5664f2019-04-02 14:18:56 -0700280 namedColorSpace,
281 capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800282}
283
Peiyong Lin21e499a2019-04-03 16:37:46 -0700284static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700285 jlong layerObject, jobject sourceCropObj, jfloat frameScale,
Chiawei Wang02202d12019-01-03 18:12:13 +0800286 jlongArray excludeObjectArray, jint format) {
chaviwfbe47df2017-11-10 16:14:49 -0800287
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700288 auto layer = reinterpret_cast<SurfaceControl *>(layerObject);
289 if (layer == NULL) {
chaviwfbe47df2017-11-10 16:14:49 -0800290 return NULL;
291 }
292
293 Rect sourceCrop;
294 if (sourceCropObj != NULL) {
295 sourceCrop = rectFromObj(env, sourceCropObj);
296 }
297
Robert Carrffcdc512019-04-02 11:51:11 -0700298 std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700299 if (excludeObjectArray != NULL) {
300 const jsize len = env->GetArrayLength(excludeObjectArray);
Robert Carrffcdc512019-04-02 11:51:11 -0700301 excludeHandles.reserve(len);
302
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700303 const jlong* objects = env->GetLongArrayElements(excludeObjectArray, nullptr);
Robert Carrffcdc512019-04-02 11:51:11 -0700304 for (jsize i = 0; i < len; i++) {
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700305 auto excludeObject = reinterpret_cast<SurfaceControl *>(objects[i]);
306 if (excludeObject == nullptr) {
Robert Carrffcdc512019-04-02 11:51:11 -0700307 jniThrowNullPointerException(env, "Exclude layer is null");
308 return NULL;
309 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700310 excludeHandles.emplace(excludeObject->getHandle());
Robert Carrffcdc512019-04-02 11:51:11 -0700311 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700312 env->ReleaseLongArrayElements(excludeObjectArray, const_cast<jlong*>(objects), JNI_ABORT);
Robert Carrffcdc512019-04-02 11:51:11 -0700313 }
314
chaviwfbe47df2017-11-10 16:14:49 -0800315 sp<GraphicBuffer> buffer;
Peiyong Lin21e499a2019-04-03 16:37:46 -0700316 ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
317 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
318 if (displayToken != nullptr) {
319 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
320 dataspace = pickDataspaceFromColorMode(colorMode);
321 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700322 status_t res = ScreenshotClient::captureChildLayers(layer->getHandle(), dataspace,
Chiawei Wang02202d12019-01-03 18:12:13 +0800323 static_cast<ui::PixelFormat>(format),
324 sourceCrop, excludeHandles, frameScale,
325 &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800326 if (res != NO_ERROR) {
327 return NULL;
328 }
329
Peiyong Line3e5efd2019-03-21 20:59:47 +0000330 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
331 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
332 gScreenshotGraphicBufferClassInfo.builder,
chaviwfbe47df2017-11-10 16:14:49 -0800333 buffer->getWidth(),
334 buffer->getHeight(),
335 buffer->getPixelFormat(),
336 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000337 (jlong)buffer.get(),
Robert Carrbf9298f2019-04-09 07:42:02 -0700338 namedColorSpace,
339 false /* capturedSecureLayers */);
chaviw1cda84c2017-10-23 16:47:10 -0700340}
341
Robert Carre13b58e2017-08-31 14:50:44 -0700342static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
343 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
344 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800345}
346
Robert Carrb1579c82017-09-05 14:54:47 -0700347static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
348 jlong transactionObj, jlong otherTransactionObj) {
349 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
350 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
351 otherTransactionObj);
352 transaction->merge(std::move(*otherTransaction));
353}
354
Robert Carre13b58e2017-08-31 14:50:44 -0700355static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
356 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
357 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800358}
359
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100360static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
361 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
362 transaction->setEarlyWakeup();
363}
364
Robert Carre13b58e2017-08-31 14:50:44 -0700365static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
366 jlong nativeObject, jint zorder) {
367 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800368
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800369 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700370 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800371}
372
Robert Carre13b58e2017-08-31 14:50:44 -0700373static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
374 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700375 jlong relativeToObject, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700376
Robert Carraf422a82017-04-10 18:34:33 -0700377 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700378 auto relative = reinterpret_cast<SurfaceControl *>(relativeToObject);
379 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
380 transaction->setRelativeLayer(ctrl, relative->getHandle(), zorder);
Robert Carraf422a82017-04-10 18:34:33 -0700381}
382
Robert Carre13b58e2017-08-31 14:50:44 -0700383static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
384 jlong nativeObject, jfloat x, jfloat y) {
385 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
386
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800387 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700388 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800389}
390
Robert Carr76907ee2019-01-11 13:38:19 -0800391static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
392 jobject sourceObj, jobject dstObj, jlong orientation) {
393 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
394 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
395
396 Rect source, dst;
397 if (sourceObj != NULL) {
398 source = rectFromObj(env, sourceObj);
Robert Carrced6f852019-04-08 16:58:49 -0700399 } else {
400 source.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800401 }
402 if (dstObj != NULL) {
403 dst = rectFromObj(env, dstObj);
Robert Carrced6f852019-04-08 16:58:49 -0700404 } else {
405 dst.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800406 }
407 transaction->setGeometry(ctrl, source, dst, orientation);
408}
409
Robert Carre13b58e2017-08-31 14:50:44 -0700410static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
411 jlong nativeObject, jint w, jint h) {
412 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
413
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800414 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700415 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800416}
417
Robert Carre13b58e2017-08-31 14:50:44 -0700418static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
419 jlong nativeObject, jint flags, jint mask) {
420 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
421
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800422 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700423 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800424}
425
Robert Carre13b58e2017-08-31 14:50:44 -0700426static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
427 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800428 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Derek Sollenberger40d78132019-08-12 11:06:08 -0400429 graphics::RegionIterator iterator(env, regionObj);
430 if (!iterator.isValid()) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800431 doThrowIAE(env);
432 return;
433 }
434
Derek Sollenberger40d78132019-08-12 11:06:08 -0400435 ARect bounds = iterator.getTotalBounds();
436 Region reg({bounds.left, bounds.top, bounds.right, bounds.bottom});
437 if (iterator.isComplex()) {
438 while (!iterator.isDone()) {
439 ARect rect = iterator.getRect();
440 reg.addRectUnchecked(rect.left, rect.top, rect.right, rect.bottom);
441 iterator.next();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800442 }
443 }
444
Robert Carre13b58e2017-08-31 14:50:44 -0700445 {
446 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
447 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800448 }
449}
450
Robert Carre13b58e2017-08-31 14:50:44 -0700451static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
452 jlong nativeObject, jfloat alpha) {
453 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
454
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800455 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700456 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800457}
458
Robert Carr788f5742018-07-30 17:46:45 -0700459static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
460 jlong nativeObject, jobject inputWindow) {
461 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
462
Riddle Hsucd958bc2019-01-23 15:40:26 +0800463 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700464 env, inputWindow);
465 handle->updateInfo();
466
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700467 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr788f5742018-07-30 17:46:45 -0700468 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
469}
470
chaviw319cd0782019-02-14 11:00:23 -0800471static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
472 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
473 transaction->syncInputWindows();
474}
475
Evan Rosky485df202018-12-06 14:11:12 -0800476static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
477 jlong nativeObject, jint id, jobject parcelObj) {
478 Parcel* parcel = parcelForJavaObject(env, parcelObj);
479 if (!parcel) {
480 jniThrowNullPointerException(env, "attribute data");
481 return;
482 }
483 if (parcel->objectsCount()) {
484 jniThrowException(env, "java/lang/RuntimeException",
485 "Tried to marshall a Parcel that contained Binder objects.");
486 return;
487 }
488
489 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
490
Evan Rosky485df202018-12-06 14:11:12 -0800491 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
Garfield Tan67e479a2019-08-05 16:47:40 -0700492 transaction->setMetadata(ctrl, id, *parcel);
Evan Rosky485df202018-12-06 14:11:12 -0800493}
494
Robert Carre13b58e2017-08-31 14:50:44 -0700495static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
496 jlong nativeObject, jfloatArray fColor) {
497 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700498 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700499
chaviw0dd03f52017-08-25 12:15:26 -0700500 float* floatColors = env->GetFloatArrayElements(fColor, 0);
501 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700502 transaction->setColor(ctrl, color);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800503 env->ReleaseFloatArrayElements(fColor, floatColors, 0);
chaviw0dd03f52017-08-25 12:15:26 -0700504}
505
Robert Carre13b58e2017-08-31 14:50:44 -0700506static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
507 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800508 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700509 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
510
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800511 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700512 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800513}
514
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700515static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
516 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
517 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
518 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
519 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
520 mat3 matrix(static_cast<float const*>(floatMatrix));
Vishnu Nair4a067c52019-11-19 14:25:56 -0800521 env->ReleaseFloatArrayElements(fMatrix, floatMatrix, 0);
522
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700523 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
524 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800525 env->ReleaseFloatArrayElements(fTranslation, floatTranslation, 0);
526
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700527 transaction->setColorTransform(surfaceControl, matrix, translation);
528}
529
Peiyong Linf4f0f642019-03-01 14:36:05 -0800530static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
531 jlong nativeObject, jboolean agnostic) {
532 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
533 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
534 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
535}
536
Robert Carre13b58e2017-08-31 14:50:44 -0700537static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
538 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800539 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700540 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
541
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800542 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
543 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700544 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800545}
546
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700547static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
548 jlong nativeObject, jfloat cornerRadius) {
549 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
550
551 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
552 transaction->setCornerRadius(ctrl, cornerRadius);
553}
554
Robert Carre13b58e2017-08-31 14:50:44 -0700555static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
556 jlong nativeObject, jint layerStack) {
557 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
558
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800559 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700560 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800561}
562
Vishnu Naird87984d2019-11-06 14:43:22 -0800563static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
564 jlong nativeObject, jfloat shadowRadius) {
565 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
566
567 const auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
568 transaction->setShadowRadius(ctrl, shadowRadius);
569}
570
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800571static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
572 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
573 jlongArray array = env->NewLongArray(displayIds.size());
574 if (array == nullptr) {
575 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
576 return nullptr;
577 }
578
579 if (displayIds.empty()) {
580 return array;
581 }
582
583 jlong* values = env->GetLongArrayElements(array, 0);
584 for (size_t i = 0; i < displayIds.size(); ++i) {
585 values[i] = static_cast<jlong>(displayIds[i]);
586 }
587
588 env->ReleaseLongArrayElements(array, values, 0);
589 return array;
590}
591
592static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
593 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800594 return javaObjectForIBinder(env, token);
595}
596
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700597static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
598 jobject tokenObj) {
599 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
600
601 ui::PixelFormat format;
602 ui::Dataspace dataspace;
603 uint8_t componentMask;
604 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
605 token, &format, &dataspace, &componentMask);
606 if (err != OK) {
607 return nullptr;
608 }
609 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
610 gDisplayedContentSamplingAttributesClassInfo.ctor,
611 format, dataspace, componentMask);
612}
613
614static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
615 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
616 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800617 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700618 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800619 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700620}
621
622static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
623 jlong maxFrames, jlong timestamp) {
624 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
625
626 DisplayedFrameStats stats;
627 status_t err = SurfaceComposerClient::getDisplayedContentSample(
628 token, maxFrames, timestamp, &stats);
629 if (err != OK) {
630 return nullptr;
631 }
632
633 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
634 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
635 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
636 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
637 if ((histogramComponent0 == nullptr) ||
638 (histogramComponent1 == nullptr) ||
639 (histogramComponent2 == nullptr) ||
640 (histogramComponent3 == nullptr)) {
641 return JNI_FALSE;
642 }
643
644 env->SetLongArrayRegion(histogramComponent0, 0,
645 stats.component_0_sample.size(),
646 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
647 env->SetLongArrayRegion(histogramComponent1, 0,
648 stats.component_1_sample.size(),
649 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
650 env->SetLongArrayRegion(histogramComponent2, 0,
651 stats.component_2_sample.size(),
652 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
653 env->SetLongArrayRegion(histogramComponent3, 0,
654 stats.component_3_sample.size(),
655 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
656 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
657 gDisplayedContentSampleClassInfo.ctor,
658 stats.numFrames,
659 histogramComponent0,
660 histogramComponent1,
661 histogramComponent2,
662 histogramComponent3);
663}
664
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800665static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
666 jboolean secure) {
667 ScopedUtfChars name(env, nameObj);
668 sp<IBinder> token(SurfaceComposerClient::createDisplay(
669 String8(name.c_str()), bool(secure)));
670 return javaObjectForIBinder(env, token);
671}
672
Jesse Hall6a6bc212013-08-08 12:15:03 -0700673static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
674 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
675 if (token == NULL) return;
676 SurfaceComposerClient::destroyDisplay(token);
677}
678
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800679static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700680 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000681 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800682 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
683 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800684 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800685 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800686 if (sur != NULL) {
687 bufferProducer = sur->getIGraphicBufferProducer();
688 }
Robert Carre13b58e2017-08-31 14:50:44 -0700689
690
691 status_t err = NO_ERROR;
692 {
693 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
694 err = transaction->setDisplaySurface(token,
695 bufferProducer);
696 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700697 if (err != NO_ERROR) {
698 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
699 " Surface created with singleBufferMode?");
700 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800701}
702
703static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700704 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800705 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700706
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800707 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
708 if (token == NULL) return;
709
Robert Carre13b58e2017-08-31 14:50:44 -0700710 {
711 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
712 transaction->setDisplayLayerStack(token, layerStack);
713 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800714}
715
716static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700717 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800718 jobject tokenObj, jint orientation,
719 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
720 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
721 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
722 if (token == NULL) return;
723 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
724 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700725
726 {
727 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Dominik Laskowski2a3d9aa2019-11-18 20:26:39 -0800728 transaction->setDisplayProjection(token, static_cast<ui::Rotation>(orientation),
729 layerStackRect, displayRect);
Robert Carre13b58e2017-08-31 14:50:44 -0700730 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800731}
732
Michael Wright01e840f2014-06-26 16:03:25 -0700733static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700734 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700735 jobject tokenObj, jint width, jint height) {
736 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
737 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700738
739 {
740 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
741 transaction->setDisplaySize(token, width, height);
742 }
Michael Wright01e840f2014-06-26 16:03:25 -0700743}
744
Dan Stoza00101052014-05-02 15:23:40 -0700745static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
746 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800747 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700748 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800749
Dan Stoza00101052014-05-02 15:23:40 -0700750 Vector<DisplayInfo> configs;
751 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
752 configs.size() == 0) {
753 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800754 }
755
Dan Stoza00101052014-05-02 15:23:40 -0700756 jobjectArray configArray = env->NewObjectArray(configs.size(),
757 gPhysicalDisplayInfoClassInfo.clazz, NULL);
758
759 for (size_t c = 0; c < configs.size(); ++c) {
760 const DisplayInfo& info = configs[c];
761 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
762 gPhysicalDisplayInfoClassInfo.ctor);
763 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
764 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
765 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
766 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
767 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
768 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
769 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700770 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
771 info.appVsyncOffset);
772 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
773 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700774 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
775 env->DeleteLocalRef(infoObj);
776 }
777
778 return configArray;
779}
780
Ana Krulec52f12892019-11-18 03:57:20 -0800781static jboolean nativeSetDesiredDisplayConfigSpecs(JNIEnv* env, jclass clazz, jobject tokenObj,
782 jobject desiredDisplayConfigSpecs) {
Ana Krulec4f753aa2019-11-14 00:49:39 +0100783 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
784 if (token == nullptr) return JNI_FALSE;
785
Ana Kruleca74a8642019-11-14 00:51:00 +0100786 jint defaultConfig = env->GetIntField(desiredDisplayConfigSpecs,
787 gDesiredDisplayConfigSpecsClassInfo.defaultConfig);
Ana Krulec52f12892019-11-18 03:57:20 -0800788 jfloat minRefreshRate = env->GetFloatField(desiredDisplayConfigSpecs,
789 gDesiredDisplayConfigSpecsClassInfo.minRefreshRate);
790 jfloat maxRefreshRate = env->GetFloatField(desiredDisplayConfigSpecs,
791 gDesiredDisplayConfigSpecsClassInfo.maxRefreshRate);
792
Ana Krulec4f753aa2019-11-14 00:49:39 +0100793 size_t result = SurfaceComposerClient::setDesiredDisplayConfigSpecs(
Ana Kruleca74a8642019-11-14 00:51:00 +0100794 token, defaultConfig, minRefreshRate, maxRefreshRate);
Ana Krulec4f753aa2019-11-14 00:49:39 +0100795 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
796}
797
Ana Kruleca74a8642019-11-14 00:51:00 +0100798static jobject nativeGetDesiredDisplayConfigSpecs(JNIEnv* env, jclass clazz, jobject tokenObj) {
799 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
800 if (token == nullptr) return nullptr;
801
802 int32_t defaultConfig;
803 float minRefreshRate;
804 float maxRefreshRate;
805 if (SurfaceComposerClient::getDesiredDisplayConfigSpecs(token, &defaultConfig, &minRefreshRate,
806 &maxRefreshRate) != NO_ERROR) {
807 return nullptr;
808 }
809
810 return env->NewObject(gDesiredDisplayConfigSpecsClassInfo.clazz,
811 gDesiredDisplayConfigSpecsClassInfo.ctor, defaultConfig, minRefreshRate,
812 maxRefreshRate);
813}
814
Dan Stoza00101052014-05-02 15:23:40 -0700815static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
816 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
817 if (token == NULL) return -1;
818 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
819}
820
821static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
822 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
823 if (token == NULL) return JNI_FALSE;
824 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
825 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800826}
827
Michael Wright1c9977b2016-07-12 13:30:10 -0700828static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
829 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
830 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700831 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700832 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
833 colorModes.isEmpty()) {
834 return NULL;
835 }
836
837 jintArray colorModesArray = env->NewIntArray(colorModes.size());
838 if (colorModesArray == NULL) {
839 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
840 return NULL;
841 }
842 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
843 for (size_t i = 0; i < colorModes.size(); i++) {
844 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
845 }
846 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
847 return colorModesArray;
848}
849
Daniel Solomon10e3b332019-01-20 21:09:11 -0800850static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
851 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
852 if (token == NULL) return NULL;
853
854 ui::DisplayPrimaries primaries;
855 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
856 return NULL;
857 }
858
859 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
860 if (jred == NULL) {
861 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
862 return NULL;
863 }
864
865 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
866 if (jgreen == NULL) {
867 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
868 return NULL;
869 }
870
871 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
872 if (jblue == NULL) {
873 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
874 return NULL;
875 }
876
877 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
878 if (jwhite == NULL) {
879 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
880 return NULL;
881 }
882
883 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
884 gDisplayPrimariesClassInfo.ctor);
885 if (jprimaries == NULL) {
886 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
887 return NULL;
888 }
889
890 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
891 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
892 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
893 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
894 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
895 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
896 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
897 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
898 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
899 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
900 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
901 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
902 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
903 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
904 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
905 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
906
907 return jprimaries;
908}
909
Michael Wright1c9977b2016-07-12 13:30:10 -0700910static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
911 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
912 if (token == NULL) return -1;
913 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
914}
915
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800916static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
917 ui::Dataspace defaultDataspace, wcgDataspace;
918 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
919 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
920 &defaultPixelFormat,
921 &wcgDataspace,
922 &wcgPixelFormat) != NO_ERROR) {
923 return nullptr;
924 }
925 jintArray array = env->NewIntArray(2);
926 if (array == nullptr) {
927 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
928 return nullptr;
929 }
930 jint* arrayValues = env->GetIntArrayElements(array, 0);
931 arrayValues[0] = static_cast<jint>(defaultDataspace);
932 arrayValues[1] = static_cast<jint>(wcgDataspace);
933 env->ReleaseIntArrayElements(array, arrayValues, 0);
934 return array;
935}
936
Michael Wright1c9977b2016-07-12 13:30:10 -0700937static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
938 jobject tokenObj, jint colorMode) {
939 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
940 if (token == NULL) return JNI_FALSE;
941 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700942 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700943 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
944}
945
Prashant Malanic55929a2014-05-25 01:59:21 -0700946static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800947 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
948 if (token == NULL) return;
949
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700950 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700951 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700952 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800953}
954
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800955static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
956 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
957}
958
Svetoslav1376d602014-03-13 11:17:26 -0700959static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
960 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
961 status_t err = ctrl->clearLayerFrameStats();
962
963 if (err < 0 && err != NO_INIT) {
964 doThrowIAE(env);
965 }
966
967 // The other end is not ready, just report we failed.
968 if (err == NO_INIT) {
969 return JNI_FALSE;
970 }
971
972 return JNI_TRUE;
973}
974
975static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
976 jobject outStats) {
977 FrameStats stats;
978
979 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
980 status_t err = ctrl->getLayerFrameStats(&stats);
981 if (err < 0 && err != NO_INIT) {
982 doThrowIAE(env);
983 }
984
985 // The other end is not ready, fine just return empty stats.
986 if (err == NO_INIT) {
987 return JNI_FALSE;
988 }
989
990 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
991 size_t frameCount = stats.desiredPresentTimesNano.size();
992
993 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
994 if (postedTimesNanoDst == NULL) {
995 return JNI_FALSE;
996 }
997
998 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
999 if (presentedTimesNanoDst == NULL) {
1000 return JNI_FALSE;
1001 }
1002
1003 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
1004 if (readyTimesNanoDst == NULL) {
1005 return JNI_FALSE;
1006 }
1007
1008 nsecs_t postedTimesNanoSrc[frameCount];
1009 nsecs_t presentedTimesNanoSrc[frameCount];
1010 nsecs_t readyTimesNanoSrc[frameCount];
1011
1012 for (size_t i = 0; i < frameCount; i++) {
1013 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
1014 if (postedTimeNano == INT64_MAX) {
1015 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1016 }
1017 postedTimesNanoSrc[i] = postedTimeNano;
1018
1019 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1020 if (presentedTimeNano == INT64_MAX) {
1021 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1022 }
1023 presentedTimesNanoSrc[i] = presentedTimeNano;
1024
1025 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
1026 if (readyTimeNano == INT64_MAX) {
1027 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1028 }
1029 readyTimesNanoSrc[i] = readyTimeNano;
1030 }
1031
1032 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
1033 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1034 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
1035
1036 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
1037 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
1038
1039 if (env->ExceptionCheck()) {
1040 return JNI_FALSE;
1041 }
1042
1043 return JNI_TRUE;
1044}
1045
1046static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
1047 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
1048
1049 if (err < 0 && err != NO_INIT) {
1050 doThrowIAE(env);
1051 }
1052
1053 // The other end is not ready, just report we failed.
1054 if (err == NO_INIT) {
1055 return JNI_FALSE;
1056 }
1057
1058 return JNI_TRUE;
1059}
1060
1061static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
1062 FrameStats stats;
1063
1064 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1065 if (err < 0 && err != NO_INIT) {
1066 doThrowIAE(env);
1067 }
1068
1069 // The other end is not ready, fine just return empty stats.
1070 if (err == NO_INIT) {
1071 return JNI_FALSE;
1072 }
1073
1074 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1075 size_t frameCount = stats.desiredPresentTimesNano.size();
1076
1077 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1078 if (presentedTimesNanoDst == NULL) {
1079 return JNI_FALSE;
1080 }
1081
1082 nsecs_t presentedTimesNanoSrc[frameCount];
1083
1084 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -07001085 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -07001086 if (presentedTimeNano == INT64_MAX) {
1087 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1088 }
1089 presentedTimesNanoSrc[i] = presentedTimeNano;
1090 }
1091
1092 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1093
1094 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1095 presentedTimesNanoDst);
1096
1097 if (env->ExceptionCheck()) {
1098 return JNI_FALSE;
1099 }
1100
1101 return JNI_TRUE;
1102}
1103
Robert Carre13b58e2017-08-31 14:50:44 -07001104static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001105 jlong nativeObject, jlong barrierObject, jlong frameNumber) {
Rob Carr64e516f2015-10-29 00:20:45 +00001106 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001107 auto barrier = reinterpret_cast<SurfaceControl *>(barrierObject);
1108 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1109 transaction->deferTransactionUntil_legacy(ctrl, barrier->getHandle(), frameNumber);
Rob Carr64e516f2015-10-29 00:20:45 +00001110}
1111
Robert Carre13b58e2017-08-31 14:50:44 -07001112static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1113 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001114 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001115 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1116
Robert Carrd5c7dd62017-03-08 10:39:30 -08001117 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1118 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1119
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001120 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001121}
1122
Robert Carre13b58e2017-08-31 14:50:44 -07001123static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1124 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001125 jlong newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001126
Robert Carrd5c7dd62017-03-08 10:39:30 -08001127 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001128 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
1129 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1130 transaction->reparentChildren(ctrl, newParent->getHandle());
Robert Carrd5c7dd62017-03-08 10:39:30 -08001131}
1132
Robert Carre13b58e2017-08-31 14:50:44 -07001133static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1134 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001135 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001136 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001137 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001138 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1139 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
chaviw63542382017-08-17 17:39:29 -07001140}
1141
Robert Carre13b58e2017-08-31 14:50:44 -07001142static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1143 jlong nativeObject) {
1144 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1145
Robert Carrd5c7dd62017-03-08 10:39:30 -08001146 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001147 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001148}
1149
Robert Carre13b58e2017-08-31 14:50:44 -07001150static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1151 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001152 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001153 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001154
Robert Carre13b58e2017-08-31 14:50:44 -07001155 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1156 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001157}
1158
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001159static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1160 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1161 if (token == NULL) return NULL;
1162
1163 HdrCapabilities capabilities;
1164 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1165
1166 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001167 std::vector<int32_t> intTypes;
1168 for (auto type : types) {
1169 intTypes.push_back(static_cast<int32_t>(type));
1170 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001171 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001172 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001173
Michael Wright9ff94c02016-03-30 18:05:40 -07001174 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001175 typesArray, capabilities.getDesiredMaxLuminance(),
1176 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1177}
1178
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001179static jboolean nativeGetAutoLowLatencyModeSupport(JNIEnv* env, jclass clazz, jobject tokenObject) {
1180 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1181 if (token == NULL) return NULL;
1182
1183 return SurfaceComposerClient::getAutoLowLatencyModeSupport(token);
1184}
1185
1186static jboolean nativeGetGameContentTypeSupport(JNIEnv* env, jclass clazz, jobject tokenObject) {
1187 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1188 if (token == NULL) return NULL;
1189
1190 return SurfaceComposerClient::getGameContentTypeSupport(token);
1191}
1192
1193static void nativeSetAutoLowLatencyMode(JNIEnv* env, jclass clazz, jobject tokenObject, jboolean on) {
1194 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1195 if (token == NULL) return;
1196
1197 SurfaceComposerClient::setAutoLowLatencyMode(token, on);
1198}
1199
1200static void nativeSetGameContentType(JNIEnv* env, jclass clazz, jobject tokenObject, jboolean on) {
1201 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1202 if (token == NULL) return;
1203
1204 SurfaceComposerClient::setGameContentType(token, on);
1205}
1206
Jorim Jaggi06975df2017-12-01 14:52:13 +01001207static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1208 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1209 if (parcel == NULL) {
1210 doThrowNPE(env);
1211 return 0;
1212 }
1213 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1214 if (surface == nullptr) {
1215 return 0;
1216 }
1217 surface->incStrong((void *)nativeCreate);
1218 return reinterpret_cast<jlong>(surface.get());
1219}
1220
chaviwbeb7a0c2018-12-05 13:49:54 -08001221static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1222 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1223 if (surface == nullptr) {
1224 return 0;
1225 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001226
1227 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1228 newSurface->incStrong((void *)nativeCreate);
1229 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001230}
1231
Jorim Jaggi06975df2017-12-01 14:52:13 +01001232static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1233 jlong nativeObject, jobject parcelObj) {
1234 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1235 if (parcel == NULL) {
1236 doThrowNPE(env);
1237 return;
1238 }
1239 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001240 if (self != nullptr) {
1241 self->writeToParcel(parcel);
1242 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001243}
1244
Dan Gittik832b4972019-02-13 18:17:47 +00001245static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1246 jobject displayTokenObject) {
1247 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1248 if (displayToken == nullptr) {
1249 return JNI_FALSE;
1250 }
1251 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1252}
1253
1254static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1255 jfloat brightness) {
1256 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1257 if (displayToken == nullptr) {
1258 return JNI_FALSE;
1259 }
1260 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1261 return error == OK ? JNI_TRUE : JNI_FALSE;
1262}
1263
Vishnu Nair629df2b2019-06-11 16:03:38 -07001264static void nativeWriteTransactionToParcel(JNIEnv* env, jclass clazz, jlong nativeObject,
1265 jobject parcelObj) {
1266 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1267 if (parcel == NULL) {
1268 doThrowNPE(env);
1269 return;
1270 }
1271 SurfaceComposerClient::Transaction* const self =
1272 reinterpret_cast<SurfaceComposerClient::Transaction *>(nativeObject);
1273 if (self != nullptr) {
1274 self->writeToParcel(parcel);
Vishnu Nairf7645aa2019-06-18 11:14:01 -07001275 self->clear();
Vishnu Nair629df2b2019-06-11 16:03:38 -07001276 }
1277}
1278
1279static jlong nativeReadTransactionFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1280 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1281 if (parcel == NULL) {
1282 doThrowNPE(env);
1283 return 0;
1284 }
1285 std::unique_ptr<SurfaceComposerClient::Transaction> transaction =
1286 SurfaceComposerClient::Transaction::createFromParcel(parcel);
1287
1288 return reinterpret_cast<jlong>(transaction.release());
1289}
1290
chaviwa51724f2019-09-19 09:50:11 -07001291static jlong nativeMirrorSurface(JNIEnv* env, jclass clazz, jlong mirrorOfObj) {
1292 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1293 SurfaceControl *mirrorOf = reinterpret_cast<SurfaceControl*>(mirrorOfObj);
1294 sp<SurfaceControl> surface = client->mirrorSurface(mirrorOf);
1295
1296 surface->incStrong((void *)nativeCreate);
1297 return reinterpret_cast<jlong>(surface.get());
1298}
1299
Vishnu Nair4a067c52019-11-19 14:25:56 -08001300static void nativeSetGlobalShadowSettings(JNIEnv* env, jclass clazz, jfloatArray jAmbientColor,
1301 jfloatArray jSpotColor, jfloat lightPosY, jfloat lightPosZ, jfloat lightRadius) {
1302 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1303
1304 float* floatAmbientColor = env->GetFloatArrayElements(jAmbientColor, 0);
1305 half4 ambientColor = half4(floatAmbientColor[0], floatAmbientColor[1], floatAmbientColor[2],
1306 floatAmbientColor[3]);
1307 env->ReleaseFloatArrayElements(jAmbientColor, floatAmbientColor, 0);
1308
1309 float* floatSpotColor = env->GetFloatArrayElements(jSpotColor, 0);
1310 half4 spotColor = half4(floatSpotColor[0], floatSpotColor[1], floatSpotColor[2],
1311 floatSpotColor[3]);
1312 env->ReleaseFloatArrayElements(jSpotColor, floatSpotColor, 0);
1313
1314 client->setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ, lightRadius);
1315}
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001316// ----------------------------------------------------------------------------
1317
Daniel Micay76f6a862015-09-19 17:31:01 -04001318static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001319 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001320 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001321 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1322 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001323 {"nativeCopyFromSurfaceControl", "(J)J" ,
1324 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001325 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1326 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001327 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001328 (void*)nativeRelease },
Chong Zhang47e36a32016-02-29 16:44:33 -08001329 {"nativeDisconnect", "(J)V",
1330 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001331 {"nativeCreateTransaction", "()J",
1332 (void*)nativeCreateTransaction },
1333 {"nativeApplyTransaction", "(JZ)V",
1334 (void*)nativeApplyTransaction },
1335 {"nativeGetNativeTransactionFinalizer", "()J",
1336 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001337 {"nativeMergeTransaction", "(JJ)V",
1338 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001339 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001340 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001341 {"nativeSetEarlyWakeup", "(J)V",
1342 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001343 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001344 (void*)nativeSetLayer },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001345 {"nativeSetRelativeLayer", "(JJJI)V",
Robert Carraf422a82017-04-10 18:34:33 -07001346 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001347 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001348 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001349 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001350 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001351 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001352 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001353 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001354 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001355 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001356 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001357 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001358 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001359 {"nativeSetColorTransform", "(JJ[F[F)V",
1360 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001361 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1362 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001363 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001364 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001365 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001366 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001367 {"nativeSetCornerRadius", "(JJF)V",
1368 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001369 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001370 (void*)nativeSetLayerStack },
Vishnu Naird87984d2019-11-06 14:43:22 -08001371 {"nativeSetShadowRadius", "(JJF)V",
1372 (void*)nativeSetShadowRadius },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001373 {"nativeGetPhysicalDisplayIds", "()[J",
1374 (void*)nativeGetPhysicalDisplayIds },
1375 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1376 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001377 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1378 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001379 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1380 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001381 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001382 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001383 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001384 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001385 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001386 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001387 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001388 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001389 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1390 (void*)nativeGetDisplayConfigs },
1391 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1392 (void*)nativeGetActiveConfig },
1393 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1394 (void*)nativeSetActiveConfig },
Ana Krulec52f12892019-11-18 03:57:20 -08001395 {"nativeSetDesiredDisplayConfigSpecs",
1396 "(Landroid/os/IBinder;Landroid/view/SurfaceControl$DesiredDisplayConfigSpecs;)Z",
Ana Krulec4f753aa2019-11-14 00:49:39 +01001397 (void*)nativeSetDesiredDisplayConfigSpecs },
Ana Kruleca74a8642019-11-14 00:51:00 +01001398 {"nativeGetDesiredDisplayConfigSpecs",
1399 "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DesiredDisplayConfigSpecs;",
1400 (void*)nativeGetDesiredDisplayConfigSpecs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001401 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1402 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001403 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1404 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001405 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1406 (void*)nativeGetActiveColorMode},
1407 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1408 (void*)nativeSetActiveColorMode},
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001409 {"nativeGetAutoLowLatencyModeSupport", "(Landroid/os/IBinder;)Z",
1410 (void*)nativeGetAutoLowLatencyModeSupport },
1411 {"nativeSetAutoLowLatencyMode", "(Landroid/os/IBinder;Z)V",
1412 (void*)nativeSetAutoLowLatencyMode },
1413 {"nativeGetGameContentTypeSupport", "(Landroid/os/IBinder;)Z",
1414 (void*)nativeGetGameContentTypeSupport },
1415 {"nativeSetGameContentType", "(Landroid/os/IBinder;Z)V",
1416 (void*)nativeSetGameContentType },
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001417 {"nativeGetCompositionDataspaces", "()[I",
1418 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001419 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1420 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001421 {"nativeClearContentFrameStats", "(J)Z",
1422 (void*)nativeClearContentFrameStats },
1423 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1424 (void*)nativeGetContentFrameStats },
1425 {"nativeClearAnimationFrameStats", "()Z",
1426 (void*)nativeClearAnimationFrameStats },
1427 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1428 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001429 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1430 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001431 {"nativeGetProtectedContentSupport", "()Z",
1432 (void*)nativeGetProtectedContentSupport },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001433 {"nativeDeferTransactionUntil", "(JJJJ)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001434 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001435 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001436 (void*)nativeDeferTransactionUntilSurface },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001437 {"nativeReparentChildren", "(JJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001438 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001439 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001440 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001441 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001442 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001443 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001444 (void*)nativeSetOverrideScalingMode },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001445 {"nativeScreenshot",
1446 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1447 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001448 (void*)nativeScreenshot },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001449 {"nativeCaptureLayers",
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001450 "(Landroid/os/IBinder;JLandroid/graphics/Rect;"
Chiawei Wang02202d12019-01-03 18:12:13 +08001451 "F[JI)"
Peiyong Line3e5efd2019-03-21 20:59:47 +00001452 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001453 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001454 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001455 (void*)nativeSetInputWindowInfo },
Evan Roskyb51e2462019-04-03 19:27:18 -07001456 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
Evan Rosky485df202018-12-06 14:11:12 -08001457 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001458 {"nativeGetDisplayedContentSamplingAttributes",
1459 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1460 (void*)nativeGetDisplayedContentSamplingAttributes },
1461 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1462 (void*)nativeSetDisplayedContentSamplingEnabled },
1463 {"nativeGetDisplayedContentSample",
1464 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1465 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001466 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001467 (void*)nativeSetGeometry },
1468 {"nativeSyncInputWindows", "(J)V",
Dan Gittik832b4972019-02-13 18:17:47 +00001469 (void*)nativeSyncInputWindows },
1470 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1471 (void*)nativeGetDisplayBrightnessSupport },
1472 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1473 (void*)nativeSetDisplayBrightness },
Vishnu Nair629df2b2019-06-11 16:03:38 -07001474 {"nativeReadTransactionFromParcel", "(Landroid/os/Parcel;)J",
1475 (void*)nativeReadTransactionFromParcel },
1476 {"nativeWriteTransactionToParcel", "(JLandroid/os/Parcel;)V",
1477 (void*)nativeWriteTransactionToParcel },
chaviwa51724f2019-09-19 09:50:11 -07001478 {"nativeMirrorSurface", "(J)J",
1479 (void*)nativeMirrorSurface },
Vishnu Nair4a067c52019-11-19 14:25:56 -08001480 {"nativeSetGlobalShadowSettings", "([F[FFFF)V",
1481 (void*)nativeSetGlobalShadowSettings },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001482};
1483
1484int register_android_view_SurfaceControl(JNIEnv* env)
1485{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001486 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001487 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1488
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001489 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1490 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1491 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1492 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1493 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1494 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1495 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1496 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1497 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1498 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1499 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1500 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1501 clazz, "appVsyncOffsetNanos", "J");
1502 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1503 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001504
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001505 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1506 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1507 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1508 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1509 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001510
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001511 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1512 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1513 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001514 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1515
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001516 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1517 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1518 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001519 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1520
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001521 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1522 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1523 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001524 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1525
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001526 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1527 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1528 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1529 "([IFFF)V");
1530
Robert Carr6486d312017-01-09 19:48:29 -08001531 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1532 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1533 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1534 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1535
Peiyong Line3e5efd2019-03-21 20:59:47 +00001536 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1537 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1538 gScreenshotGraphicBufferClassInfo.clazz =
1539 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1540 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1541 screenshotGraphicsBufferClazz,
Robert Carr66b5664f2019-04-02 14:18:56 -07001542 "createFromNative", "(IIIIJIZ)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
Peiyong Line3e5efd2019-03-21 20:59:47 +00001543
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001544 jclass displayedContentSampleClazz = FindClassOrDie(env,
1545 "android/hardware/display/DisplayedContentSample");
1546 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1547 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1548 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1549
1550 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1551 "android/hardware/display/DisplayedContentSamplingAttributes");
1552 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1553 displayedContentSamplingAttributesClazz);
1554 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1555 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001556
1557 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1558 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1559 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1560 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1561 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1562 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1563
1564 jclass displayPrimariesClazz = FindClassOrDie(env,
1565 "android/view/SurfaceControl$DisplayPrimaries");
1566 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1567 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1568 "<init>", "()V");
1569 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1570 "Landroid/view/SurfaceControl$CieXyz;");
1571 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1572 "Landroid/view/SurfaceControl$CieXyz;");
1573 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1574 "Landroid/view/SurfaceControl$CieXyz;");
1575 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1576 "Landroid/view/SurfaceControl$CieXyz;");
1577
Ana Krulec52f12892019-11-18 03:57:20 -08001578 jclass desiredDisplayConfigSpecsClazz =
1579 FindClassOrDie(env, "android/view/SurfaceControl$DesiredDisplayConfigSpecs");
1580 gDesiredDisplayConfigSpecsClassInfo.clazz =
1581 MakeGlobalRefOrDie(env, desiredDisplayConfigSpecsClazz);
1582 gDesiredDisplayConfigSpecsClassInfo.ctor =
1583 GetMethodIDOrDie(env, gDesiredDisplayConfigSpecsClassInfo.clazz, "<init>", "(IFF)V");
Ana Kruleca74a8642019-11-14 00:51:00 +01001584 gDesiredDisplayConfigSpecsClassInfo.defaultConfig =
1585 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "defaultConfig", "I");
Ana Krulec52f12892019-11-18 03:57:20 -08001586 gDesiredDisplayConfigSpecsClassInfo.minRefreshRate =
Ana Kruleca74a8642019-11-14 00:51:00 +01001587 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "minRefreshRate", "F");
Ana Krulec52f12892019-11-18 03:57:20 -08001588 gDesiredDisplayConfigSpecsClassInfo.maxRefreshRate =
Ana Kruleca74a8642019-11-14 00:51:00 +01001589 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "maxRefreshRate", "F");
Ana Krulec52f12892019-11-18 03:57:20 -08001590
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001591 return err;
1592}
1593
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001594} // namespace android