blob: f564d75588328e9cf2b1da205db26d34c48e8580 [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
Dominik Laskowski69b281d2019-11-22 14:13:12 -080025#include <memory>
26
27#include <android-base/chrono_utils.h>
Derek Sollenberger40d78132019-08-12 11:06:08 -040028#include <android/graphics/region.h>
Derek Sollenberger8b994192019-07-16 13:23:29 -040029#include <android_runtime/AndroidRuntime.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>
Dominik Laskowski69b281d2019-11-22 14:13:12 -080035#include <nativehelper/JNIHelp.h>
36#include <nativehelper/ScopedUtfChars.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040037#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>
Dominik Laskowski69b281d2019-11-22 14:13:12 -080040#include <ui/DisplayConfig.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080041#include <ui/DisplayInfo.h>
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070042#include <ui/DisplayedFrameStats.h>
Svetoslav1376d602014-03-13 11:17:26 -070043#include <ui/FrameStats.h>
Peiyong Linb88549e2018-03-28 12:03:45 -070044#include <ui/GraphicTypes.h>
Peiyong Lin371b98f2018-03-14 17:29:10 -070045#include <ui/HdrCapabilities.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080046#include <ui/Rect.h>
47#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080048#include <utils/Log.h>
49
Mathias Agopian3866f0d2013-02-11 22:08:48 -080050// ----------------------------------------------------------------------------
51
52namespace android {
53
Derek Sollenberger8b994192019-07-16 13:23:29 -040054static void doThrowNPE(JNIEnv* env) {
55 jniThrowNullPointerException(env, NULL);
56}
57
58static void doThrowIAE(JNIEnv* env, const char* msg = nullptr) {
59 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
60}
61
Mathias Agopian3866f0d2013-02-11 22:08:48 -080062static const char* const OutOfResourcesException =
63 "android/view/Surface$OutOfResourcesException";
64
65static struct {
Dan Stoza00101052014-05-02 15:23:40 -070066 jclass clazz;
67 jmethodID ctor;
Dominik Laskowski69b281d2019-11-22 14:13:12 -080068 jfieldID density;
69 jfieldID secure;
70} gDisplayInfoClassInfo;
71
72static struct {
73 jclass clazz;
74 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080075 jfieldID width;
76 jfieldID height;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080077 jfieldID xDpi;
78 jfieldID yDpi;
Dominik Laskowski69b281d2019-11-22 14:13:12 -080079 jfieldID refreshRate;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070080 jfieldID appVsyncOffsetNanos;
81 jfieldID presentationDeadlineNanos;
Dominik Laskowski69b281d2019-11-22 14:13:12 -080082} gDisplayConfigClassInfo;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080083
Dan Stoza9890e3412014-05-22 16:12:54 -070084static struct {
85 jfieldID bottom;
86 jfieldID left;
87 jfieldID right;
88 jfieldID top;
89} gRectClassInfo;
90
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050091// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
92void DeleteScreenshot(void* addr, void* context) {
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050093 delete ((ScreenshotClient*) context);
94}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080095
Svetoslav1376d602014-03-13 11:17:26 -070096static struct {
97 nsecs_t UNDEFINED_TIME_NANO;
98 jmethodID init;
99} gWindowContentFrameStatsClassInfo;
100
101static struct {
102 nsecs_t UNDEFINED_TIME_NANO;
103 jmethodID init;
104} gWindowAnimationFrameStatsClassInfo;
105
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700106static struct {
107 jclass clazz;
108 jmethodID ctor;
109} gHdrCapabilitiesClassInfo;
110
Robert Carr6486d312017-01-09 19:48:29 -0800111static struct {
112 jclass clazz;
113 jmethodID builder;
114} gGraphicBufferClassInfo;
115
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700116static struct {
117 jclass clazz;
118 jmethodID ctor;
119} gDisplayedContentSampleClassInfo;
120
121static struct {
122 jclass clazz;
123 jmethodID ctor;
124} gDisplayedContentSamplingAttributesClassInfo;
125
Daniel Solomon10e3b332019-01-20 21:09:11 -0800126static struct {
127 jclass clazz;
128 jmethodID ctor;
129 jfieldID X;
130 jfieldID Y;
131 jfieldID Z;
132} gCieXyzClassInfo;
133
134static struct {
135 jclass clazz;
136 jmethodID ctor;
137 jfieldID red;
138 jfieldID green;
139 jfieldID blue;
140 jfieldID white;
141} gDisplayPrimariesClassInfo;
142
Peiyong Line3e5efd2019-03-21 20:59:47 +0000143static struct {
144 jclass clazz;
145 jmethodID builder;
146} gScreenshotGraphicBufferClassInfo;
147
Ana Krulec52f12892019-11-18 03:57:20 -0800148static struct {
149 jclass clazz;
150 jmethodID ctor;
Ana Kruleca74a8642019-11-14 00:51:00 +0100151 jfieldID defaultConfig;
Ana Krulec52f12892019-11-18 03:57:20 -0800152 jfieldID minRefreshRate;
153 jfieldID maxRefreshRate;
154} gDesiredDisplayConfigSpecsClassInfo;
155
Peiyong Line3e5efd2019-03-21 20:59:47 +0000156class JNamedColorSpace {
157public:
158 // ColorSpace.Named.SRGB.ordinal() = 0;
159 static constexpr jint SRGB = 0;
160
Peiyong Line9133d52019-05-01 15:36:04 -0700161 // ColorSpace.Named.DISPLAY_P3.ordinal() = 7;
162 static constexpr jint DISPLAY_P3 = 7;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000163};
164
165constexpr jint fromDataspaceToNamedColorSpaceValue(const ui::Dataspace dataspace) {
166 switch (dataspace) {
167 case ui::Dataspace::DISPLAY_P3:
168 return JNamedColorSpace::DISPLAY_P3;
169 default:
170 return JNamedColorSpace::SRGB;
171 }
172}
173
174constexpr ui::Dataspace pickDataspaceFromColorMode(const ui::ColorMode colorMode) {
175 switch (colorMode) {
176 case ui::ColorMode::DISPLAY_P3:
177 case ui::ColorMode::BT2100_PQ:
178 case ui::ColorMode::BT2100_HLG:
179 case ui::ColorMode::DISPLAY_BT2020:
180 return ui::Dataspace::DISPLAY_P3;
181 default:
182 return ui::Dataspace::V0_SRGB;
183 }
184}
185
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800186// ----------------------------------------------------------------------------
187
Robert Carre13b58e2017-08-31 14:50:44 -0700188static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
189 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
190}
191
192static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
193 delete t;
194}
195
196static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
197 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
198}
199
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000200static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500201 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
Evan Rosky485df202018-12-06 14:11:12 -0800202 jobject metadataParcel) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800203 ScopedUtfChars name(env, nameStr);
Robert Carr76907ee2019-01-11 13:38:19 -0800204 sp<SurfaceComposerClient> client;
205 if (sessionObj != NULL) {
206 client = android_view_SurfaceSession_getClient(env, sessionObj);
207 } else {
208 client = SurfaceComposerClient::getDefault();
209 }
Robert Carr838120c2016-11-01 18:31:12 -0700210 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Robert Carrb0f39362018-03-14 13:52:25 -0700211 sp<SurfaceControl> surface;
Evan Rosky485df202018-12-06 14:11:12 -0800212 LayerMetadata metadata;
213 Parcel* parcel = parcelForJavaObject(env, metadataParcel);
214 if (parcel && !parcel->objectsCount()) {
215 status_t err = metadata.readFromParcel(parcel);
216 if (err != NO_ERROR) {
217 jniThrowException(env, "java/lang/IllegalArgumentException",
218 "Metadata parcel has wrong format");
219 }
220 }
221
Robert Carrb0f39362018-03-14 13:52:25 -0700222 status_t err = client->createSurfaceChecked(
Evan Rosky485df202018-12-06 14:11:12 -0800223 String8(name.c_str()), w, h, format, &surface, flags, parent, std::move(metadata));
Robert Carrb0f39362018-03-14 13:52:25 -0700224 if (err == NAME_NOT_FOUND) {
225 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
226 return 0;
227 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800228 jniThrowException(env, OutOfResourcesException, NULL);
229 return 0;
230 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500231
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800232 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000233 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800234}
235
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000236static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800237 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Robert Carrcc6d4832019-02-04 15:41:12 -0800238 ctrl->release();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800239 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800240}
241
Chong Zhang47e36a32016-02-29 16:44:33 -0800242static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
243 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
244 if (ctrl != NULL) {
245 ctrl->disconnect();
246 }
247}
248
Robert Carr6486d312017-01-09 19:48:29 -0800249static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
250 int left = env->GetIntField(rectObj, gRectClassInfo.left);
251 int top = env->GetIntField(rectObj, gRectClassInfo.top);
252 int right = env->GetIntField(rectObj, gRectClassInfo.right);
253 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
254 return Rect(left, top, right, bottom);
255}
256
chaviw08520a02018-09-10 16:44:56 -0700257static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800258 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Robert Carr5c52b132019-02-15 15:48:11 -0800259 bool useIdentityTransform, int rotation, bool captureSecureLayers) {
Robert Carr6486d312017-01-09 19:48:29 -0800260 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
261 if (displayToken == NULL) {
262 return NULL;
263 }
Peiyong Line3e5efd2019-03-21 20:59:47 +0000264 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
265 const ui::Dataspace dataspace = pickDataspaceFromColorMode(colorMode);
266
Robert Carr6486d312017-01-09 19:48:29 -0800267 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800268 sp<GraphicBuffer> buffer;
Robert Carr66b5664f2019-04-02 14:18:56 -0700269 bool capturedSecureLayers = false;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000270 status_t res = ScreenshotClient::capture(displayToken, dataspace,
Robert Carr5c52b132019-02-15 15:48:11 -0800271 ui::PixelFormat::RGBA_8888,
272 sourceCrop, width, height,
Dominik Laskowski2a3d9aa2019-11-18 20:26:39 -0800273 useIdentityTransform, ui::toRotation(rotation),
274 captureSecureLayers, &buffer, capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800275 if (res != NO_ERROR) {
276 return NULL;
277 }
278
Peiyong Line3e5efd2019-03-21 20:59:47 +0000279 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
280 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
281 gScreenshotGraphicBufferClassInfo.builder,
Robert Carr6486d312017-01-09 19:48:29 -0800282 buffer->getWidth(),
283 buffer->getHeight(),
284 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700285 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000286 (jlong)buffer.get(),
Robert Carr66b5664f2019-04-02 14:18:56 -0700287 namedColorSpace,
288 capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800289}
290
Peiyong Lin21e499a2019-04-03 16:37:46 -0700291static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700292 jlong layerObject, jobject sourceCropObj, jfloat frameScale,
Chiawei Wang02202d12019-01-03 18:12:13 +0800293 jlongArray excludeObjectArray, jint format) {
chaviwfbe47df2017-11-10 16:14:49 -0800294
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700295 auto layer = reinterpret_cast<SurfaceControl *>(layerObject);
296 if (layer == NULL) {
chaviwfbe47df2017-11-10 16:14:49 -0800297 return NULL;
298 }
299
300 Rect sourceCrop;
301 if (sourceCropObj != NULL) {
302 sourceCrop = rectFromObj(env, sourceCropObj);
303 }
304
Robert Carrffcdc512019-04-02 11:51:11 -0700305 std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700306 if (excludeObjectArray != NULL) {
307 const jsize len = env->GetArrayLength(excludeObjectArray);
Robert Carrffcdc512019-04-02 11:51:11 -0700308 excludeHandles.reserve(len);
309
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700310 const jlong* objects = env->GetLongArrayElements(excludeObjectArray, nullptr);
Robert Carrffcdc512019-04-02 11:51:11 -0700311 for (jsize i = 0; i < len; i++) {
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700312 auto excludeObject = reinterpret_cast<SurfaceControl *>(objects[i]);
313 if (excludeObject == nullptr) {
Robert Carrffcdc512019-04-02 11:51:11 -0700314 jniThrowNullPointerException(env, "Exclude layer is null");
315 return NULL;
316 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700317 excludeHandles.emplace(excludeObject->getHandle());
Robert Carrffcdc512019-04-02 11:51:11 -0700318 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700319 env->ReleaseLongArrayElements(excludeObjectArray, const_cast<jlong*>(objects), JNI_ABORT);
Robert Carrffcdc512019-04-02 11:51:11 -0700320 }
321
chaviwfbe47df2017-11-10 16:14:49 -0800322 sp<GraphicBuffer> buffer;
Peiyong Lin21e499a2019-04-03 16:37:46 -0700323 ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
324 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
325 if (displayToken != nullptr) {
326 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
327 dataspace = pickDataspaceFromColorMode(colorMode);
328 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700329 status_t res = ScreenshotClient::captureChildLayers(layer->getHandle(), dataspace,
Chiawei Wang02202d12019-01-03 18:12:13 +0800330 static_cast<ui::PixelFormat>(format),
331 sourceCrop, excludeHandles, frameScale,
332 &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800333 if (res != NO_ERROR) {
334 return NULL;
335 }
336
Peiyong Line3e5efd2019-03-21 20:59:47 +0000337 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
338 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
339 gScreenshotGraphicBufferClassInfo.builder,
chaviwfbe47df2017-11-10 16:14:49 -0800340 buffer->getWidth(),
341 buffer->getHeight(),
342 buffer->getPixelFormat(),
343 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000344 (jlong)buffer.get(),
Robert Carrbf9298f2019-04-09 07:42:02 -0700345 namedColorSpace,
346 false /* capturedSecureLayers */);
chaviw1cda84c2017-10-23 16:47:10 -0700347}
348
Robert Carre13b58e2017-08-31 14:50:44 -0700349static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
350 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
351 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800352}
353
Robert Carrb1579c82017-09-05 14:54:47 -0700354static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
355 jlong transactionObj, jlong otherTransactionObj) {
356 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
357 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
358 otherTransactionObj);
359 transaction->merge(std::move(*otherTransaction));
360}
361
Robert Carre13b58e2017-08-31 14:50:44 -0700362static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
363 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
364 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800365}
366
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100367static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
368 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
369 transaction->setEarlyWakeup();
370}
371
Robert Carre13b58e2017-08-31 14:50:44 -0700372static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
373 jlong nativeObject, jint zorder) {
374 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800375
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800376 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700377 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800378}
379
Robert Carre13b58e2017-08-31 14:50:44 -0700380static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
381 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700382 jlong relativeToObject, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700383
Robert Carraf422a82017-04-10 18:34:33 -0700384 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700385 auto relative = reinterpret_cast<SurfaceControl *>(relativeToObject);
386 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
387 transaction->setRelativeLayer(ctrl, relative->getHandle(), zorder);
Robert Carraf422a82017-04-10 18:34:33 -0700388}
389
Robert Carre13b58e2017-08-31 14:50:44 -0700390static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
391 jlong nativeObject, jfloat x, jfloat y) {
392 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
393
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800394 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700395 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800396}
397
Robert Carr76907ee2019-01-11 13:38:19 -0800398static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
399 jobject sourceObj, jobject dstObj, jlong orientation) {
400 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
401 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
402
403 Rect source, dst;
404 if (sourceObj != NULL) {
405 source = rectFromObj(env, sourceObj);
Robert Carrced6f852019-04-08 16:58:49 -0700406 } else {
407 source.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800408 }
409 if (dstObj != NULL) {
410 dst = rectFromObj(env, dstObj);
Robert Carrced6f852019-04-08 16:58:49 -0700411 } else {
412 dst.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800413 }
414 transaction->setGeometry(ctrl, source, dst, orientation);
415}
416
Robert Carre13b58e2017-08-31 14:50:44 -0700417static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
418 jlong nativeObject, jint w, jint h) {
419 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
420
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800421 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700422 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800423}
424
Robert Carre13b58e2017-08-31 14:50:44 -0700425static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
426 jlong nativeObject, jint flags, jint mask) {
427 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
428
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800429 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700430 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800431}
432
Ana Krulecfea97172019-11-02 23:11:02 +0100433static void nativeSetFrameRateSelectionPriority(JNIEnv* env, jclass clazz, jlong transactionObj,
434 jlong nativeObject, jint priority) {
435 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
436
437 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
438 transaction->setFrameRateSelectionPriority(ctrl, priority);
439}
440
Robert Carre13b58e2017-08-31 14:50:44 -0700441static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
442 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800443 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Derek Sollenberger40d78132019-08-12 11:06:08 -0400444 graphics::RegionIterator iterator(env, regionObj);
445 if (!iterator.isValid()) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800446 doThrowIAE(env);
447 return;
448 }
449
Derek Sollenberger40d78132019-08-12 11:06:08 -0400450 ARect bounds = iterator.getTotalBounds();
451 Region reg({bounds.left, bounds.top, bounds.right, bounds.bottom});
452 if (iterator.isComplex()) {
453 while (!iterator.isDone()) {
454 ARect rect = iterator.getRect();
455 reg.addRectUnchecked(rect.left, rect.top, rect.right, rect.bottom);
456 iterator.next();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800457 }
458 }
459
Robert Carre13b58e2017-08-31 14:50:44 -0700460 {
461 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
462 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800463 }
464}
465
Robert Carre13b58e2017-08-31 14:50:44 -0700466static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
467 jlong nativeObject, jfloat alpha) {
468 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
469
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800470 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700471 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800472}
473
Robert Carr788f5742018-07-30 17:46:45 -0700474static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
475 jlong nativeObject, jobject inputWindow) {
476 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
477
Riddle Hsucd958bc2019-01-23 15:40:26 +0800478 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700479 env, inputWindow);
480 handle->updateInfo();
481
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700482 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr788f5742018-07-30 17:46:45 -0700483 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
484}
485
chaviw319cd0782019-02-14 11:00:23 -0800486static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
487 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
488 transaction->syncInputWindows();
489}
490
Evan Rosky485df202018-12-06 14:11:12 -0800491static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
492 jlong nativeObject, jint id, jobject parcelObj) {
493 Parcel* parcel = parcelForJavaObject(env, parcelObj);
494 if (!parcel) {
495 jniThrowNullPointerException(env, "attribute data");
496 return;
497 }
498 if (parcel->objectsCount()) {
499 jniThrowException(env, "java/lang/RuntimeException",
500 "Tried to marshall a Parcel that contained Binder objects.");
501 return;
502 }
503
504 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
505
Evan Rosky485df202018-12-06 14:11:12 -0800506 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
Garfield Tan67e479a2019-08-05 16:47:40 -0700507 transaction->setMetadata(ctrl, id, *parcel);
Evan Rosky485df202018-12-06 14:11:12 -0800508}
509
Robert Carre13b58e2017-08-31 14:50:44 -0700510static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
511 jlong nativeObject, jfloatArray fColor) {
512 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700513 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700514
chaviw0dd03f52017-08-25 12:15:26 -0700515 float* floatColors = env->GetFloatArrayElements(fColor, 0);
516 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700517 transaction->setColor(ctrl, color);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800518 env->ReleaseFloatArrayElements(fColor, floatColors, 0);
chaviw0dd03f52017-08-25 12:15:26 -0700519}
520
Robert Carre13b58e2017-08-31 14:50:44 -0700521static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
522 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800523 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700524 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
525
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800526 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700527 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800528}
529
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700530static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
531 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
532 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
533 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
534 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
535 mat3 matrix(static_cast<float const*>(floatMatrix));
Vishnu Nair4a067c52019-11-19 14:25:56 -0800536 env->ReleaseFloatArrayElements(fMatrix, floatMatrix, 0);
537
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700538 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
539 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800540 env->ReleaseFloatArrayElements(fTranslation, floatTranslation, 0);
541
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700542 transaction->setColorTransform(surfaceControl, matrix, translation);
543}
544
Peiyong Linf4f0f642019-03-01 14:36:05 -0800545static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
546 jlong nativeObject, jboolean agnostic) {
547 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
548 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
549 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
550}
551
Robert Carre13b58e2017-08-31 14:50:44 -0700552static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
553 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800554 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700555 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
556
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800557 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
558 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700559 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800560}
561
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700562static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
563 jlong nativeObject, jfloat cornerRadius) {
564 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
565
566 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
567 transaction->setCornerRadius(ctrl, cornerRadius);
568}
569
Lucas Dupin991415e2019-11-25 17:48:58 -0800570static void nativeSetBackgroundBlurRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
571 jlong nativeObject, jint blurRadius) {
572 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
573
574 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
575 transaction->setBackgroundBlurRadius(ctrl, blurRadius);
576}
577
Robert Carre13b58e2017-08-31 14:50:44 -0700578static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
579 jlong nativeObject, jint layerStack) {
580 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
581
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800582 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700583 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800584}
585
Vishnu Naird87984d2019-11-06 14:43:22 -0800586static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
587 jlong nativeObject, jfloat shadowRadius) {
588 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
589
590 const auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
591 transaction->setShadowRadius(ctrl, shadowRadius);
592}
593
Steven Thomas6cf051e2020-01-14 11:37:21 -0800594static void nativeSetFrameRate(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
595 jfloat frameRate) {
596 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
597
598 const auto ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
599 transaction->setFrameRate(ctrl, frameRate);
600}
601
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800602static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
603 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
604 jlongArray array = env->NewLongArray(displayIds.size());
605 if (array == nullptr) {
606 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
607 return nullptr;
608 }
609
610 if (displayIds.empty()) {
611 return array;
612 }
613
614 jlong* values = env->GetLongArrayElements(array, 0);
615 for (size_t i = 0; i < displayIds.size(); ++i) {
616 values[i] = static_cast<jlong>(displayIds[i]);
617 }
618
619 env->ReleaseLongArrayElements(array, values, 0);
620 return array;
621}
622
623static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
624 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800625 return javaObjectForIBinder(env, token);
626}
627
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700628static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
629 jobject tokenObj) {
630 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
631
632 ui::PixelFormat format;
633 ui::Dataspace dataspace;
634 uint8_t componentMask;
635 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
636 token, &format, &dataspace, &componentMask);
637 if (err != OK) {
638 return nullptr;
639 }
640 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
641 gDisplayedContentSamplingAttributesClassInfo.ctor,
642 format, dataspace, componentMask);
643}
644
645static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
646 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
647 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800648 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700649 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800650 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700651}
652
653static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
654 jlong maxFrames, jlong timestamp) {
655 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
656
657 DisplayedFrameStats stats;
658 status_t err = SurfaceComposerClient::getDisplayedContentSample(
659 token, maxFrames, timestamp, &stats);
660 if (err != OK) {
661 return nullptr;
662 }
663
664 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
665 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
666 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
667 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
668 if ((histogramComponent0 == nullptr) ||
669 (histogramComponent1 == nullptr) ||
670 (histogramComponent2 == nullptr) ||
671 (histogramComponent3 == nullptr)) {
672 return JNI_FALSE;
673 }
674
675 env->SetLongArrayRegion(histogramComponent0, 0,
676 stats.component_0_sample.size(),
677 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
678 env->SetLongArrayRegion(histogramComponent1, 0,
679 stats.component_1_sample.size(),
680 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
681 env->SetLongArrayRegion(histogramComponent2, 0,
682 stats.component_2_sample.size(),
683 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
684 env->SetLongArrayRegion(histogramComponent3, 0,
685 stats.component_3_sample.size(),
686 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
687 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
688 gDisplayedContentSampleClassInfo.ctor,
689 stats.numFrames,
690 histogramComponent0,
691 histogramComponent1,
692 histogramComponent2,
693 histogramComponent3);
694}
695
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800696static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
697 jboolean secure) {
698 ScopedUtfChars name(env, nameObj);
699 sp<IBinder> token(SurfaceComposerClient::createDisplay(
700 String8(name.c_str()), bool(secure)));
701 return javaObjectForIBinder(env, token);
702}
703
Jesse Hall6a6bc212013-08-08 12:15:03 -0700704static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
705 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
706 if (token == NULL) return;
707 SurfaceComposerClient::destroyDisplay(token);
708}
709
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800710static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700711 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000712 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800713 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
714 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800715 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800716 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800717 if (sur != NULL) {
718 bufferProducer = sur->getIGraphicBufferProducer();
719 }
Robert Carre13b58e2017-08-31 14:50:44 -0700720
721
722 status_t err = NO_ERROR;
723 {
724 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
725 err = transaction->setDisplaySurface(token,
726 bufferProducer);
727 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700728 if (err != NO_ERROR) {
729 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
730 " Surface created with singleBufferMode?");
731 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800732}
733
734static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700735 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800736 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700737
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800738 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
739 if (token == NULL) return;
740
Robert Carre13b58e2017-08-31 14:50:44 -0700741 {
742 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
743 transaction->setDisplayLayerStack(token, layerStack);
744 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800745}
746
747static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700748 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800749 jobject tokenObj, jint orientation,
750 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
751 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
752 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
753 if (token == NULL) return;
754 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
755 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700756
757 {
758 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Dominik Laskowski2a3d9aa2019-11-18 20:26:39 -0800759 transaction->setDisplayProjection(token, static_cast<ui::Rotation>(orientation),
760 layerStackRect, displayRect);
Robert Carre13b58e2017-08-31 14:50:44 -0700761 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800762}
763
Michael Wright01e840f2014-06-26 16:03:25 -0700764static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700765 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700766 jobject tokenObj, jint width, jint height) {
767 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
768 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700769
770 {
771 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
772 transaction->setDisplaySize(token, width, height);
773 }
Michael Wright01e840f2014-06-26 16:03:25 -0700774}
775
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800776static jobject nativeGetDisplayInfo(JNIEnv* env, jclass clazz, jobject tokenObj) {
777 DisplayInfo info;
778 if (const auto token = ibinderForJavaObject(env, tokenObj);
779 !token || SurfaceComposerClient::getDisplayInfo(token, &info) != NO_ERROR) {
780 return nullptr;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800781 }
782
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800783 jobject object = env->NewObject(gDisplayInfoClassInfo.clazz, gDisplayInfoClassInfo.ctor);
784 env->SetFloatField(object, gDisplayInfoClassInfo.density, info.density);
785 env->SetBooleanField(object, gDisplayInfoClassInfo.secure, info.secure);
786 return object;
787}
788
789static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
790 Vector<DisplayConfig> configs;
791 if (const auto token = ibinderForJavaObject(env, tokenObj); !token ||
792 SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
793 configs.isEmpty()) {
794 return nullptr;
795 }
796
797 jobjectArray configArray =
798 env->NewObjectArray(configs.size(), gDisplayConfigClassInfo.clazz, nullptr);
Dan Stoza00101052014-05-02 15:23:40 -0700799
800 for (size_t c = 0; c < configs.size(); ++c) {
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800801 const DisplayConfig& config = configs[c];
802 jobject object =
803 env->NewObject(gDisplayConfigClassInfo.clazz, gDisplayConfigClassInfo.ctor);
804 env->SetIntField(object, gDisplayConfigClassInfo.width, config.resolution.getWidth());
805 env->SetIntField(object, gDisplayConfigClassInfo.height, config.resolution.getHeight());
806 env->SetFloatField(object, gDisplayConfigClassInfo.xDpi, config.xDpi);
807 env->SetFloatField(object, gDisplayConfigClassInfo.yDpi, config.yDpi);
808
809 env->SetFloatField(object, gDisplayConfigClassInfo.refreshRate, config.refreshRate);
810 env->SetLongField(object, gDisplayConfigClassInfo.appVsyncOffsetNanos,
811 config.appVsyncOffset);
812 env->SetLongField(object, gDisplayConfigClassInfo.presentationDeadlineNanos,
813 config.presentationDeadline);
814 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), object);
815 env->DeleteLocalRef(object);
Dan Stoza00101052014-05-02 15:23:40 -0700816 }
817
818 return configArray;
819}
820
Ana Krulec52f12892019-11-18 03:57:20 -0800821static jboolean nativeSetDesiredDisplayConfigSpecs(JNIEnv* env, jclass clazz, jobject tokenObj,
822 jobject desiredDisplayConfigSpecs) {
Ana Krulec4f753aa2019-11-14 00:49:39 +0100823 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
824 if (token == nullptr) return JNI_FALSE;
825
Ana Kruleca74a8642019-11-14 00:51:00 +0100826 jint defaultConfig = env->GetIntField(desiredDisplayConfigSpecs,
827 gDesiredDisplayConfigSpecsClassInfo.defaultConfig);
Ana Krulec52f12892019-11-18 03:57:20 -0800828 jfloat minRefreshRate = env->GetFloatField(desiredDisplayConfigSpecs,
829 gDesiredDisplayConfigSpecsClassInfo.minRefreshRate);
830 jfloat maxRefreshRate = env->GetFloatField(desiredDisplayConfigSpecs,
831 gDesiredDisplayConfigSpecsClassInfo.maxRefreshRate);
832
Ana Krulec4f753aa2019-11-14 00:49:39 +0100833 size_t result = SurfaceComposerClient::setDesiredDisplayConfigSpecs(
Ana Kruleca74a8642019-11-14 00:51:00 +0100834 token, defaultConfig, minRefreshRate, maxRefreshRate);
Ana Krulec4f753aa2019-11-14 00:49:39 +0100835 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
836}
837
Ana Kruleca74a8642019-11-14 00:51:00 +0100838static jobject nativeGetDesiredDisplayConfigSpecs(JNIEnv* env, jclass clazz, jobject tokenObj) {
839 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
840 if (token == nullptr) return nullptr;
841
842 int32_t defaultConfig;
843 float minRefreshRate;
844 float maxRefreshRate;
845 if (SurfaceComposerClient::getDesiredDisplayConfigSpecs(token, &defaultConfig, &minRefreshRate,
846 &maxRefreshRate) != NO_ERROR) {
847 return nullptr;
848 }
849
850 return env->NewObject(gDesiredDisplayConfigSpecsClassInfo.clazz,
851 gDesiredDisplayConfigSpecsClassInfo.ctor, defaultConfig, minRefreshRate,
852 maxRefreshRate);
853}
854
Dan Stoza00101052014-05-02 15:23:40 -0700855static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
856 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
857 if (token == NULL) return -1;
858 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
859}
860
Michael Wright1c9977b2016-07-12 13:30:10 -0700861static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
862 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
863 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700864 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700865 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
866 colorModes.isEmpty()) {
867 return NULL;
868 }
869
870 jintArray colorModesArray = env->NewIntArray(colorModes.size());
871 if (colorModesArray == NULL) {
872 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
873 return NULL;
874 }
875 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
876 for (size_t i = 0; i < colorModes.size(); i++) {
877 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
878 }
879 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
880 return colorModesArray;
881}
882
Daniel Solomon10e3b332019-01-20 21:09:11 -0800883static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
884 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
885 if (token == NULL) return NULL;
886
887 ui::DisplayPrimaries primaries;
888 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
889 return NULL;
890 }
891
892 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
893 if (jred == NULL) {
894 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
895 return NULL;
896 }
897
898 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
899 if (jgreen == NULL) {
900 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
901 return NULL;
902 }
903
904 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
905 if (jblue == NULL) {
906 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
907 return NULL;
908 }
909
910 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
911 if (jwhite == NULL) {
912 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
913 return NULL;
914 }
915
916 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
917 gDisplayPrimariesClassInfo.ctor);
918 if (jprimaries == NULL) {
919 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
920 return NULL;
921 }
922
923 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
924 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
925 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
926 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
927 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
928 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
929 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
930 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
931 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
932 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
933 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
934 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
935 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
936 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
937 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
938 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
939
940 return jprimaries;
941}
942
Michael Wright1c9977b2016-07-12 13:30:10 -0700943static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
944 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
945 if (token == NULL) return -1;
946 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
947}
948
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800949static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
950 ui::Dataspace defaultDataspace, wcgDataspace;
951 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
952 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
953 &defaultPixelFormat,
954 &wcgDataspace,
955 &wcgPixelFormat) != NO_ERROR) {
956 return nullptr;
957 }
958 jintArray array = env->NewIntArray(2);
959 if (array == nullptr) {
960 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
961 return nullptr;
962 }
963 jint* arrayValues = env->GetIntArrayElements(array, 0);
964 arrayValues[0] = static_cast<jint>(defaultDataspace);
965 arrayValues[1] = static_cast<jint>(wcgDataspace);
966 env->ReleaseIntArrayElements(array, arrayValues, 0);
967 return array;
968}
969
Michael Wright1c9977b2016-07-12 13:30:10 -0700970static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
971 jobject tokenObj, jint colorMode) {
972 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
973 if (token == NULL) return JNI_FALSE;
974 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700975 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700976 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
977}
978
Prashant Malanic55929a2014-05-25 01:59:21 -0700979static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800980 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
981 if (token == NULL) return;
982
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700983 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700984 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700985 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800986}
987
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800988static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
989 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
990}
991
Svetoslav1376d602014-03-13 11:17:26 -0700992static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
993 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
994 status_t err = ctrl->clearLayerFrameStats();
995
996 if (err < 0 && err != NO_INIT) {
997 doThrowIAE(env);
998 }
999
1000 // The other end is not ready, just report we failed.
1001 if (err == NO_INIT) {
1002 return JNI_FALSE;
1003 }
1004
1005 return JNI_TRUE;
1006}
1007
1008static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
1009 jobject outStats) {
1010 FrameStats stats;
1011
1012 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1013 status_t err = ctrl->getLayerFrameStats(&stats);
1014 if (err < 0 && err != NO_INIT) {
1015 doThrowIAE(env);
1016 }
1017
1018 // The other end is not ready, fine just return empty stats.
1019 if (err == NO_INIT) {
1020 return JNI_FALSE;
1021 }
1022
1023 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1024 size_t frameCount = stats.desiredPresentTimesNano.size();
1025
1026 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
1027 if (postedTimesNanoDst == NULL) {
1028 return JNI_FALSE;
1029 }
1030
1031 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1032 if (presentedTimesNanoDst == NULL) {
1033 return JNI_FALSE;
1034 }
1035
1036 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
1037 if (readyTimesNanoDst == NULL) {
1038 return JNI_FALSE;
1039 }
1040
1041 nsecs_t postedTimesNanoSrc[frameCount];
1042 nsecs_t presentedTimesNanoSrc[frameCount];
1043 nsecs_t readyTimesNanoSrc[frameCount];
1044
1045 for (size_t i = 0; i < frameCount; i++) {
1046 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
1047 if (postedTimeNano == INT64_MAX) {
1048 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1049 }
1050 postedTimesNanoSrc[i] = postedTimeNano;
1051
1052 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1053 if (presentedTimeNano == INT64_MAX) {
1054 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1055 }
1056 presentedTimesNanoSrc[i] = presentedTimeNano;
1057
1058 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
1059 if (readyTimeNano == INT64_MAX) {
1060 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1061 }
1062 readyTimesNanoSrc[i] = readyTimeNano;
1063 }
1064
1065 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
1066 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1067 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
1068
1069 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
1070 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
1071
1072 if (env->ExceptionCheck()) {
1073 return JNI_FALSE;
1074 }
1075
1076 return JNI_TRUE;
1077}
1078
1079static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
1080 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
1081
1082 if (err < 0 && err != NO_INIT) {
1083 doThrowIAE(env);
1084 }
1085
1086 // The other end is not ready, just report we failed.
1087 if (err == NO_INIT) {
1088 return JNI_FALSE;
1089 }
1090
1091 return JNI_TRUE;
1092}
1093
1094static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
1095 FrameStats stats;
1096
1097 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1098 if (err < 0 && err != NO_INIT) {
1099 doThrowIAE(env);
1100 }
1101
1102 // The other end is not ready, fine just return empty stats.
1103 if (err == NO_INIT) {
1104 return JNI_FALSE;
1105 }
1106
1107 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1108 size_t frameCount = stats.desiredPresentTimesNano.size();
1109
1110 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1111 if (presentedTimesNanoDst == NULL) {
1112 return JNI_FALSE;
1113 }
1114
1115 nsecs_t presentedTimesNanoSrc[frameCount];
1116
1117 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -07001118 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -07001119 if (presentedTimeNano == INT64_MAX) {
1120 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1121 }
1122 presentedTimesNanoSrc[i] = presentedTimeNano;
1123 }
1124
1125 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1126
1127 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1128 presentedTimesNanoDst);
1129
1130 if (env->ExceptionCheck()) {
1131 return JNI_FALSE;
1132 }
1133
1134 return JNI_TRUE;
1135}
1136
Robert Carre13b58e2017-08-31 14:50:44 -07001137static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001138 jlong nativeObject, jlong barrierObject, jlong frameNumber) {
Rob Carr64e516f2015-10-29 00:20:45 +00001139 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001140 auto barrier = reinterpret_cast<SurfaceControl *>(barrierObject);
1141 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1142 transaction->deferTransactionUntil_legacy(ctrl, barrier->getHandle(), frameNumber);
Rob Carr64e516f2015-10-29 00:20:45 +00001143}
1144
Robert Carre13b58e2017-08-31 14:50:44 -07001145static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1146 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001147 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001148 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1149
Robert Carrd5c7dd62017-03-08 10:39:30 -08001150 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1151 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1152
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001153 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001154}
1155
Robert Carre13b58e2017-08-31 14:50:44 -07001156static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1157 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001158 jlong newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001159
Robert Carrd5c7dd62017-03-08 10:39:30 -08001160 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001161 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
1162 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1163 transaction->reparentChildren(ctrl, newParent->getHandle());
Robert Carrd5c7dd62017-03-08 10:39:30 -08001164}
1165
Robert Carre13b58e2017-08-31 14:50:44 -07001166static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1167 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001168 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001169 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001170 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001171 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1172 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
chaviw63542382017-08-17 17:39:29 -07001173}
1174
Robert Carre13b58e2017-08-31 14:50:44 -07001175static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1176 jlong nativeObject) {
1177 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1178
Robert Carrd5c7dd62017-03-08 10:39:30 -08001179 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001180 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001181}
1182
Robert Carre13b58e2017-08-31 14:50:44 -07001183static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1184 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001185 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001186 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001187
Robert Carre13b58e2017-08-31 14:50:44 -07001188 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1189 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001190}
1191
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001192static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1193 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1194 if (token == NULL) return NULL;
1195
1196 HdrCapabilities capabilities;
1197 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1198
1199 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001200 std::vector<int32_t> intTypes;
1201 for (auto type : types) {
1202 intTypes.push_back(static_cast<int32_t>(type));
1203 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001204 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001205 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001206
Michael Wright9ff94c02016-03-30 18:05:40 -07001207 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001208 typesArray, capabilities.getDesiredMaxLuminance(),
1209 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1210}
1211
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001212static jboolean nativeGetAutoLowLatencyModeSupport(JNIEnv* env, jclass clazz, jobject tokenObject) {
1213 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1214 if (token == NULL) return NULL;
1215
1216 return SurfaceComposerClient::getAutoLowLatencyModeSupport(token);
1217}
1218
1219static jboolean nativeGetGameContentTypeSupport(JNIEnv* env, jclass clazz, jobject tokenObject) {
1220 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1221 if (token == NULL) return NULL;
1222
1223 return SurfaceComposerClient::getGameContentTypeSupport(token);
1224}
1225
1226static void nativeSetAutoLowLatencyMode(JNIEnv* env, jclass clazz, jobject tokenObject, jboolean on) {
1227 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1228 if (token == NULL) return;
1229
1230 SurfaceComposerClient::setAutoLowLatencyMode(token, on);
1231}
1232
1233static void nativeSetGameContentType(JNIEnv* env, jclass clazz, jobject tokenObject, jboolean on) {
1234 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1235 if (token == NULL) return;
1236
1237 SurfaceComposerClient::setGameContentType(token, on);
1238}
1239
Jorim Jaggi06975df2017-12-01 14:52:13 +01001240static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1241 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1242 if (parcel == NULL) {
1243 doThrowNPE(env);
1244 return 0;
1245 }
1246 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1247 if (surface == nullptr) {
1248 return 0;
1249 }
1250 surface->incStrong((void *)nativeCreate);
1251 return reinterpret_cast<jlong>(surface.get());
1252}
1253
chaviwbeb7a0c2018-12-05 13:49:54 -08001254static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1255 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1256 if (surface == nullptr) {
1257 return 0;
1258 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001259
1260 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1261 newSurface->incStrong((void *)nativeCreate);
1262 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001263}
1264
Jorim Jaggi06975df2017-12-01 14:52:13 +01001265static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1266 jlong nativeObject, jobject parcelObj) {
1267 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1268 if (parcel == NULL) {
1269 doThrowNPE(env);
1270 return;
1271 }
1272 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001273 if (self != nullptr) {
1274 self->writeToParcel(parcel);
1275 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001276}
1277
Dan Gittik832b4972019-02-13 18:17:47 +00001278static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1279 jobject displayTokenObject) {
1280 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1281 if (displayToken == nullptr) {
1282 return JNI_FALSE;
1283 }
1284 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1285}
1286
1287static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1288 jfloat brightness) {
1289 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1290 if (displayToken == nullptr) {
1291 return JNI_FALSE;
1292 }
1293 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1294 return error == OK ? JNI_TRUE : JNI_FALSE;
1295}
1296
Vishnu Nair629df2b2019-06-11 16:03:38 -07001297static void nativeWriteTransactionToParcel(JNIEnv* env, jclass clazz, jlong nativeObject,
1298 jobject parcelObj) {
1299 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1300 if (parcel == NULL) {
1301 doThrowNPE(env);
1302 return;
1303 }
1304 SurfaceComposerClient::Transaction* const self =
1305 reinterpret_cast<SurfaceComposerClient::Transaction *>(nativeObject);
1306 if (self != nullptr) {
1307 self->writeToParcel(parcel);
Vishnu Nairf7645aa2019-06-18 11:14:01 -07001308 self->clear();
Vishnu Nair629df2b2019-06-11 16:03:38 -07001309 }
1310}
1311
1312static jlong nativeReadTransactionFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1313 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1314 if (parcel == NULL) {
1315 doThrowNPE(env);
1316 return 0;
1317 }
1318 std::unique_ptr<SurfaceComposerClient::Transaction> transaction =
1319 SurfaceComposerClient::Transaction::createFromParcel(parcel);
1320
1321 return reinterpret_cast<jlong>(transaction.release());
1322}
1323
chaviwa51724f2019-09-19 09:50:11 -07001324static jlong nativeMirrorSurface(JNIEnv* env, jclass clazz, jlong mirrorOfObj) {
1325 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1326 SurfaceControl *mirrorOf = reinterpret_cast<SurfaceControl*>(mirrorOfObj);
1327 sp<SurfaceControl> surface = client->mirrorSurface(mirrorOf);
1328
1329 surface->incStrong((void *)nativeCreate);
1330 return reinterpret_cast<jlong>(surface.get());
1331}
1332
Vishnu Nair4a067c52019-11-19 14:25:56 -08001333static void nativeSetGlobalShadowSettings(JNIEnv* env, jclass clazz, jfloatArray jAmbientColor,
1334 jfloatArray jSpotColor, jfloat lightPosY, jfloat lightPosZ, jfloat lightRadius) {
1335 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1336
1337 float* floatAmbientColor = env->GetFloatArrayElements(jAmbientColor, 0);
1338 half4 ambientColor = half4(floatAmbientColor[0], floatAmbientColor[1], floatAmbientColor[2],
1339 floatAmbientColor[3]);
1340 env->ReleaseFloatArrayElements(jAmbientColor, floatAmbientColor, 0);
1341
1342 float* floatSpotColor = env->GetFloatArrayElements(jSpotColor, 0);
1343 half4 spotColor = half4(floatSpotColor[0], floatSpotColor[1], floatSpotColor[2],
1344 floatSpotColor[3]);
1345 env->ReleaseFloatArrayElements(jSpotColor, floatSpotColor, 0);
1346
1347 client->setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ, lightRadius);
1348}
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001349// ----------------------------------------------------------------------------
1350
Daniel Micay76f6a862015-09-19 17:31:01 -04001351static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001352 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001353 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001354 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1355 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001356 {"nativeCopyFromSurfaceControl", "(J)J" ,
1357 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001358 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1359 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001360 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001361 (void*)nativeRelease },
Chong Zhang47e36a32016-02-29 16:44:33 -08001362 {"nativeDisconnect", "(J)V",
1363 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001364 {"nativeCreateTransaction", "()J",
1365 (void*)nativeCreateTransaction },
1366 {"nativeApplyTransaction", "(JZ)V",
1367 (void*)nativeApplyTransaction },
1368 {"nativeGetNativeTransactionFinalizer", "()J",
1369 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001370 {"nativeMergeTransaction", "(JJ)V",
1371 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001372 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001373 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001374 {"nativeSetEarlyWakeup", "(J)V",
1375 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001376 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001377 (void*)nativeSetLayer },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001378 {"nativeSetRelativeLayer", "(JJJI)V",
Robert Carraf422a82017-04-10 18:34:33 -07001379 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001380 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001381 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001382 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001383 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001384 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001385 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001386 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001387 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001388 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001389 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001390 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001391 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001392 {"nativeSetColorTransform", "(JJ[F[F)V",
1393 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001394 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1395 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001396 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001397 (void*)nativeSetFlags },
Ana Krulecfea97172019-11-02 23:11:02 +01001398 {"nativeSetFrameRateSelectionPriority", "(JJI)V",
1399 (void*)nativeSetFrameRateSelectionPriority },
Robert Carre13b58e2017-08-31 14:50:44 -07001400 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001401 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001402 {"nativeSetCornerRadius", "(JJF)V",
1403 (void*)nativeSetCornerRadius },
Lucas Dupin991415e2019-11-25 17:48:58 -08001404 {"nativeSetBackgroundBlurRadius", "(JJI)V",
1405 (void*)nativeSetBackgroundBlurRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001406 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001407 (void*)nativeSetLayerStack },
Vishnu Naird87984d2019-11-06 14:43:22 -08001408 {"nativeSetShadowRadius", "(JJF)V",
1409 (void*)nativeSetShadowRadius },
Steven Thomas6cf051e2020-01-14 11:37:21 -08001410 {"nativeSetFrameRate", "(JJF)V",
1411 (void*)nativeSetFrameRate },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001412 {"nativeGetPhysicalDisplayIds", "()[J",
1413 (void*)nativeGetPhysicalDisplayIds },
1414 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1415 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001416 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1417 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001418 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1419 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001420 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001421 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001422 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001423 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001424 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001425 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001426 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001427 (void*)nativeSetDisplaySize },
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001428 {"nativeGetDisplayInfo", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayInfo;",
1429 (void*)nativeGetDisplayInfo },
1430 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$DisplayConfig;",
Dan Stoza00101052014-05-02 15:23:40 -07001431 (void*)nativeGetDisplayConfigs },
1432 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1433 (void*)nativeGetActiveConfig },
Ana Krulec52f12892019-11-18 03:57:20 -08001434 {"nativeSetDesiredDisplayConfigSpecs",
1435 "(Landroid/os/IBinder;Landroid/view/SurfaceControl$DesiredDisplayConfigSpecs;)Z",
Ana Krulec4f753aa2019-11-14 00:49:39 +01001436 (void*)nativeSetDesiredDisplayConfigSpecs },
Ana Kruleca74a8642019-11-14 00:51:00 +01001437 {"nativeGetDesiredDisplayConfigSpecs",
1438 "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DesiredDisplayConfigSpecs;",
1439 (void*)nativeGetDesiredDisplayConfigSpecs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001440 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1441 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001442 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1443 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001444 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1445 (void*)nativeGetActiveColorMode},
1446 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1447 (void*)nativeSetActiveColorMode},
Galia Peycheva056b3ee2019-06-26 14:05:12 +02001448 {"nativeGetAutoLowLatencyModeSupport", "(Landroid/os/IBinder;)Z",
1449 (void*)nativeGetAutoLowLatencyModeSupport },
1450 {"nativeSetAutoLowLatencyMode", "(Landroid/os/IBinder;Z)V",
1451 (void*)nativeSetAutoLowLatencyMode },
1452 {"nativeGetGameContentTypeSupport", "(Landroid/os/IBinder;)Z",
1453 (void*)nativeGetGameContentTypeSupport },
1454 {"nativeSetGameContentType", "(Landroid/os/IBinder;Z)V",
1455 (void*)nativeSetGameContentType },
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001456 {"nativeGetCompositionDataspaces", "()[I",
1457 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001458 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1459 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001460 {"nativeClearContentFrameStats", "(J)Z",
1461 (void*)nativeClearContentFrameStats },
1462 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1463 (void*)nativeGetContentFrameStats },
1464 {"nativeClearAnimationFrameStats", "()Z",
1465 (void*)nativeClearAnimationFrameStats },
1466 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1467 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001468 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1469 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001470 {"nativeGetProtectedContentSupport", "()Z",
1471 (void*)nativeGetProtectedContentSupport },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001472 {"nativeDeferTransactionUntil", "(JJJJ)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001473 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001474 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001475 (void*)nativeDeferTransactionUntilSurface },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001476 {"nativeReparentChildren", "(JJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001477 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001478 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001479 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001480 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001481 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001482 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001483 (void*)nativeSetOverrideScalingMode },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001484 {"nativeScreenshot",
1485 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1486 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001487 (void*)nativeScreenshot },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001488 {"nativeCaptureLayers",
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001489 "(Landroid/os/IBinder;JLandroid/graphics/Rect;"
Chiawei Wang02202d12019-01-03 18:12:13 +08001490 "F[JI)"
Peiyong Line3e5efd2019-03-21 20:59:47 +00001491 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001492 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001493 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001494 (void*)nativeSetInputWindowInfo },
Evan Roskyb51e2462019-04-03 19:27:18 -07001495 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
Evan Rosky485df202018-12-06 14:11:12 -08001496 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001497 {"nativeGetDisplayedContentSamplingAttributes",
1498 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1499 (void*)nativeGetDisplayedContentSamplingAttributes },
1500 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1501 (void*)nativeSetDisplayedContentSamplingEnabled },
1502 {"nativeGetDisplayedContentSample",
1503 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1504 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001505 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001506 (void*)nativeSetGeometry },
1507 {"nativeSyncInputWindows", "(J)V",
Dan Gittik832b4972019-02-13 18:17:47 +00001508 (void*)nativeSyncInputWindows },
1509 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1510 (void*)nativeGetDisplayBrightnessSupport },
1511 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1512 (void*)nativeSetDisplayBrightness },
Vishnu Nair629df2b2019-06-11 16:03:38 -07001513 {"nativeReadTransactionFromParcel", "(Landroid/os/Parcel;)J",
1514 (void*)nativeReadTransactionFromParcel },
1515 {"nativeWriteTransactionToParcel", "(JLandroid/os/Parcel;)V",
1516 (void*)nativeWriteTransactionToParcel },
chaviwa51724f2019-09-19 09:50:11 -07001517 {"nativeMirrorSurface", "(J)J",
1518 (void*)nativeMirrorSurface },
Vishnu Nair4a067c52019-11-19 14:25:56 -08001519 {"nativeSetGlobalShadowSettings", "([F[FFFF)V",
1520 (void*)nativeSetGlobalShadowSettings },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001521};
1522
1523int register_android_view_SurfaceControl(JNIEnv* env)
1524{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001525 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001526 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1527
Dominik Laskowski69b281d2019-11-22 14:13:12 -08001528 jclass infoClazz = FindClassOrDie(env, "android/view/SurfaceControl$DisplayInfo");
1529 gDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, infoClazz);
1530 gDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env, infoClazz, "<init>", "()V");
1531 gDisplayInfoClassInfo.density = GetFieldIDOrDie(env, infoClazz, "density", "F");
1532 gDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, infoClazz, "secure", "Z");
1533
1534 jclass configClazz = FindClassOrDie(env, "android/view/SurfaceControl$DisplayConfig");
1535 gDisplayConfigClassInfo.clazz = MakeGlobalRefOrDie(env, configClazz);
1536 gDisplayConfigClassInfo.ctor = GetMethodIDOrDie(env, configClazz, "<init>", "()V");
1537 gDisplayConfigClassInfo.width = GetFieldIDOrDie(env, configClazz, "width", "I");
1538 gDisplayConfigClassInfo.height = GetFieldIDOrDie(env, configClazz, "height", "I");
1539 gDisplayConfigClassInfo.xDpi = GetFieldIDOrDie(env, configClazz, "xDpi", "F");
1540 gDisplayConfigClassInfo.yDpi = GetFieldIDOrDie(env, configClazz, "yDpi", "F");
1541 gDisplayConfigClassInfo.refreshRate = GetFieldIDOrDie(env, configClazz, "refreshRate", "F");
1542 gDisplayConfigClassInfo.appVsyncOffsetNanos =
1543 GetFieldIDOrDie(env, configClazz, "appVsyncOffsetNanos", "J");
1544 gDisplayConfigClassInfo.presentationDeadlineNanos =
1545 GetFieldIDOrDie(env, configClazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001546
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001547 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1548 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1549 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1550 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1551 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001552
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001553 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1554 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1555 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001556 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1557
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001558 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1559 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1560 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001561 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1562
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001563 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1564 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1565 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001566 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1567
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001568 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1569 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1570 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1571 "([IFFF)V");
1572
Robert Carr6486d312017-01-09 19:48:29 -08001573 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1574 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1575 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1576 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1577
Peiyong Line3e5efd2019-03-21 20:59:47 +00001578 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1579 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1580 gScreenshotGraphicBufferClassInfo.clazz =
1581 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1582 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1583 screenshotGraphicsBufferClazz,
Robert Carr66b5664f2019-04-02 14:18:56 -07001584 "createFromNative", "(IIIIJIZ)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
Peiyong Line3e5efd2019-03-21 20:59:47 +00001585
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001586 jclass displayedContentSampleClazz = FindClassOrDie(env,
1587 "android/hardware/display/DisplayedContentSample");
1588 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1589 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1590 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1591
1592 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1593 "android/hardware/display/DisplayedContentSamplingAttributes");
1594 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1595 displayedContentSamplingAttributesClazz);
1596 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1597 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001598
1599 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1600 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1601 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1602 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1603 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1604 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1605
1606 jclass displayPrimariesClazz = FindClassOrDie(env,
1607 "android/view/SurfaceControl$DisplayPrimaries");
1608 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1609 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1610 "<init>", "()V");
1611 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1612 "Landroid/view/SurfaceControl$CieXyz;");
1613 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1614 "Landroid/view/SurfaceControl$CieXyz;");
1615 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1616 "Landroid/view/SurfaceControl$CieXyz;");
1617 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1618 "Landroid/view/SurfaceControl$CieXyz;");
1619
Ana Krulec52f12892019-11-18 03:57:20 -08001620 jclass desiredDisplayConfigSpecsClazz =
1621 FindClassOrDie(env, "android/view/SurfaceControl$DesiredDisplayConfigSpecs");
1622 gDesiredDisplayConfigSpecsClassInfo.clazz =
1623 MakeGlobalRefOrDie(env, desiredDisplayConfigSpecsClazz);
1624 gDesiredDisplayConfigSpecsClassInfo.ctor =
1625 GetMethodIDOrDie(env, gDesiredDisplayConfigSpecsClassInfo.clazz, "<init>", "(IFF)V");
Ana Kruleca74a8642019-11-14 00:51:00 +01001626 gDesiredDisplayConfigSpecsClassInfo.defaultConfig =
1627 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "defaultConfig", "I");
Ana Krulec52f12892019-11-18 03:57:20 -08001628 gDesiredDisplayConfigSpecsClassInfo.minRefreshRate =
Ana Kruleca74a8642019-11-14 00:51:00 +01001629 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "minRefreshRate", "F");
Ana Krulec52f12892019-11-18 03:57:20 -08001630 gDesiredDisplayConfigSpecsClassInfo.maxRefreshRate =
Ana Kruleca74a8642019-11-14 00:51:00 +01001631 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "maxRefreshRate", "F");
Ana Krulec52f12892019-11-18 03:57:20 -08001632
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001633 return err;
1634}
1635
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001636} // namespace android