blob: c6e678ab50b0bb4ef5484838ec587e0a72dfd2f9 [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;
144 jfieldID defaultModeId;
145 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,
Robert Carr66b5664f2019-04-02 14:18:56 -0700266 useIdentityTransform, rotation, captureSecureLayers, &buffer, capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800267 if (res != NO_ERROR) {
268 return NULL;
269 }
270
Peiyong Line3e5efd2019-03-21 20:59:47 +0000271 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
272 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
273 gScreenshotGraphicBufferClassInfo.builder,
Robert Carr6486d312017-01-09 19:48:29 -0800274 buffer->getWidth(),
275 buffer->getHeight(),
276 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700277 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000278 (jlong)buffer.get(),
Robert Carr66b5664f2019-04-02 14:18:56 -0700279 namedColorSpace,
280 capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800281}
282
Peiyong Lin21e499a2019-04-03 16:37:46 -0700283static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700284 jlong layerObject, jobject sourceCropObj, jfloat frameScale,
Chiawei Wang02202d12019-01-03 18:12:13 +0800285 jlongArray excludeObjectArray, jint format) {
chaviwfbe47df2017-11-10 16:14:49 -0800286
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700287 auto layer = reinterpret_cast<SurfaceControl *>(layerObject);
288 if (layer == NULL) {
chaviwfbe47df2017-11-10 16:14:49 -0800289 return NULL;
290 }
291
292 Rect sourceCrop;
293 if (sourceCropObj != NULL) {
294 sourceCrop = rectFromObj(env, sourceCropObj);
295 }
296
Robert Carrffcdc512019-04-02 11:51:11 -0700297 std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700298 if (excludeObjectArray != NULL) {
299 const jsize len = env->GetArrayLength(excludeObjectArray);
Robert Carrffcdc512019-04-02 11:51:11 -0700300 excludeHandles.reserve(len);
301
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700302 const jlong* objects = env->GetLongArrayElements(excludeObjectArray, nullptr);
Robert Carrffcdc512019-04-02 11:51:11 -0700303 for (jsize i = 0; i < len; i++) {
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700304 auto excludeObject = reinterpret_cast<SurfaceControl *>(objects[i]);
305 if (excludeObject == nullptr) {
Robert Carrffcdc512019-04-02 11:51:11 -0700306 jniThrowNullPointerException(env, "Exclude layer is null");
307 return NULL;
308 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700309 excludeHandles.emplace(excludeObject->getHandle());
Robert Carrffcdc512019-04-02 11:51:11 -0700310 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700311 env->ReleaseLongArrayElements(excludeObjectArray, const_cast<jlong*>(objects), JNI_ABORT);
Robert Carrffcdc512019-04-02 11:51:11 -0700312 }
313
chaviwfbe47df2017-11-10 16:14:49 -0800314 sp<GraphicBuffer> buffer;
Peiyong Lin21e499a2019-04-03 16:37:46 -0700315 ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
316 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
317 if (displayToken != nullptr) {
318 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
319 dataspace = pickDataspaceFromColorMode(colorMode);
320 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700321 status_t res = ScreenshotClient::captureChildLayers(layer->getHandle(), dataspace,
Chiawei Wang02202d12019-01-03 18:12:13 +0800322 static_cast<ui::PixelFormat>(format),
323 sourceCrop, excludeHandles, frameScale,
324 &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800325 if (res != NO_ERROR) {
326 return NULL;
327 }
328
Peiyong Line3e5efd2019-03-21 20:59:47 +0000329 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
330 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
331 gScreenshotGraphicBufferClassInfo.builder,
chaviwfbe47df2017-11-10 16:14:49 -0800332 buffer->getWidth(),
333 buffer->getHeight(),
334 buffer->getPixelFormat(),
335 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000336 (jlong)buffer.get(),
Robert Carrbf9298f2019-04-09 07:42:02 -0700337 namedColorSpace,
338 false /* capturedSecureLayers */);
chaviw1cda84c2017-10-23 16:47:10 -0700339}
340
Robert Carre13b58e2017-08-31 14:50:44 -0700341static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
342 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
343 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800344}
345
Robert Carrb1579c82017-09-05 14:54:47 -0700346static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
347 jlong transactionObj, jlong otherTransactionObj) {
348 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
349 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
350 otherTransactionObj);
351 transaction->merge(std::move(*otherTransaction));
352}
353
Robert Carre13b58e2017-08-31 14:50:44 -0700354static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
355 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
356 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800357}
358
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100359static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
360 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
361 transaction->setEarlyWakeup();
362}
363
Robert Carre13b58e2017-08-31 14:50:44 -0700364static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
365 jlong nativeObject, jint zorder) {
366 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800367
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800368 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700369 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800370}
371
Robert Carre13b58e2017-08-31 14:50:44 -0700372static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
373 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700374 jlong relativeToObject, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700375
Robert Carraf422a82017-04-10 18:34:33 -0700376 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700377 auto relative = reinterpret_cast<SurfaceControl *>(relativeToObject);
378 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
379 transaction->setRelativeLayer(ctrl, relative->getHandle(), zorder);
Robert Carraf422a82017-04-10 18:34:33 -0700380}
381
Robert Carre13b58e2017-08-31 14:50:44 -0700382static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
383 jlong nativeObject, jfloat x, jfloat y) {
384 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
385
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800386 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700387 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800388}
389
Robert Carr76907ee2019-01-11 13:38:19 -0800390static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
391 jobject sourceObj, jobject dstObj, jlong orientation) {
392 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
393 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
394
395 Rect source, dst;
396 if (sourceObj != NULL) {
397 source = rectFromObj(env, sourceObj);
Robert Carrced6f852019-04-08 16:58:49 -0700398 } else {
399 source.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800400 }
401 if (dstObj != NULL) {
402 dst = rectFromObj(env, dstObj);
Robert Carrced6f852019-04-08 16:58:49 -0700403 } else {
404 dst.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800405 }
406 transaction->setGeometry(ctrl, source, dst, orientation);
407}
408
Robert Carre13b58e2017-08-31 14:50:44 -0700409static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
410 jlong nativeObject, jint w, jint h) {
411 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
412
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800413 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700414 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800415}
416
Robert Carre13b58e2017-08-31 14:50:44 -0700417static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
418 jlong nativeObject, jint flags, jint mask) {
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->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800423}
424
Robert Carre13b58e2017-08-31 14:50:44 -0700425static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
426 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800427 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Derek Sollenberger40d78132019-08-12 11:06:08 -0400428 graphics::RegionIterator iterator(env, regionObj);
429 if (!iterator.isValid()) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800430 doThrowIAE(env);
431 return;
432 }
433
Derek Sollenberger40d78132019-08-12 11:06:08 -0400434 ARect bounds = iterator.getTotalBounds();
435 Region reg({bounds.left, bounds.top, bounds.right, bounds.bottom});
436 if (iterator.isComplex()) {
437 while (!iterator.isDone()) {
438 ARect rect = iterator.getRect();
439 reg.addRectUnchecked(rect.left, rect.top, rect.right, rect.bottom);
440 iterator.next();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800441 }
442 }
443
Robert Carre13b58e2017-08-31 14:50:44 -0700444 {
445 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
446 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800447 }
448}
449
Robert Carre13b58e2017-08-31 14:50:44 -0700450static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
451 jlong nativeObject, jfloat alpha) {
452 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
453
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800454 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700455 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800456}
457
Robert Carr788f5742018-07-30 17:46:45 -0700458static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
459 jlong nativeObject, jobject inputWindow) {
460 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
461
Riddle Hsucd958bc2019-01-23 15:40:26 +0800462 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700463 env, inputWindow);
464 handle->updateInfo();
465
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700466 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr788f5742018-07-30 17:46:45 -0700467 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
468}
469
chaviw319cd0782019-02-14 11:00:23 -0800470static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
471 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
472 transaction->syncInputWindows();
473}
474
Evan Rosky485df202018-12-06 14:11:12 -0800475static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
476 jlong nativeObject, jint id, jobject parcelObj) {
477 Parcel* parcel = parcelForJavaObject(env, parcelObj);
478 if (!parcel) {
479 jniThrowNullPointerException(env, "attribute data");
480 return;
481 }
482 if (parcel->objectsCount()) {
483 jniThrowException(env, "java/lang/RuntimeException",
484 "Tried to marshall a Parcel that contained Binder objects.");
485 return;
486 }
487
488 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
489
Evan Rosky485df202018-12-06 14:11:12 -0800490 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
Garfield Tan67e479a2019-08-05 16:47:40 -0700491 transaction->setMetadata(ctrl, id, *parcel);
Evan Rosky485df202018-12-06 14:11:12 -0800492}
493
Robert Carre13b58e2017-08-31 14:50:44 -0700494static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
495 jlong nativeObject, jfloatArray fColor) {
496 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700497 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700498
chaviw0dd03f52017-08-25 12:15:26 -0700499 float* floatColors = env->GetFloatArrayElements(fColor, 0);
500 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700501 transaction->setColor(ctrl, color);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800502 env->ReleaseFloatArrayElements(fColor, floatColors, 0);
chaviw0dd03f52017-08-25 12:15:26 -0700503}
504
Robert Carre13b58e2017-08-31 14:50:44 -0700505static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
506 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800507 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700508 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
509
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800510 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700511 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800512}
513
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700514static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
515 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
516 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
517 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
518 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
519 mat3 matrix(static_cast<float const*>(floatMatrix));
Vishnu Nair4a067c52019-11-19 14:25:56 -0800520 env->ReleaseFloatArrayElements(fMatrix, floatMatrix, 0);
521
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700522 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
523 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800524 env->ReleaseFloatArrayElements(fTranslation, floatTranslation, 0);
525
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700526 transaction->setColorTransform(surfaceControl, matrix, translation);
527}
528
Peiyong Linf4f0f642019-03-01 14:36:05 -0800529static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
530 jlong nativeObject, jboolean agnostic) {
531 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
532 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
533 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
534}
535
Robert Carre13b58e2017-08-31 14:50:44 -0700536static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
537 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800538 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700539 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
540
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800541 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
542 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700543 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800544}
545
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700546static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
547 jlong nativeObject, jfloat cornerRadius) {
548 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
549
550 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
551 transaction->setCornerRadius(ctrl, cornerRadius);
552}
553
Robert Carre13b58e2017-08-31 14:50:44 -0700554static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
555 jlong nativeObject, jint layerStack) {
556 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
557
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800558 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700559 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800560}
561
Vishnu Naird87984d2019-11-06 14:43:22 -0800562static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
563 jlong nativeObject, jfloat shadowRadius) {
564 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
565
566 const auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
567 transaction->setShadowRadius(ctrl, shadowRadius);
568}
569
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800570static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
571 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
572 jlongArray array = env->NewLongArray(displayIds.size());
573 if (array == nullptr) {
574 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
575 return nullptr;
576 }
577
578 if (displayIds.empty()) {
579 return array;
580 }
581
582 jlong* values = env->GetLongArrayElements(array, 0);
583 for (size_t i = 0; i < displayIds.size(); ++i) {
584 values[i] = static_cast<jlong>(displayIds[i]);
585 }
586
587 env->ReleaseLongArrayElements(array, values, 0);
588 return array;
589}
590
591static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
592 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800593 return javaObjectForIBinder(env, token);
594}
595
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700596static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
597 jobject tokenObj) {
598 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
599
600 ui::PixelFormat format;
601 ui::Dataspace dataspace;
602 uint8_t componentMask;
603 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
604 token, &format, &dataspace, &componentMask);
605 if (err != OK) {
606 return nullptr;
607 }
608 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
609 gDisplayedContentSamplingAttributesClassInfo.ctor,
610 format, dataspace, componentMask);
611}
612
613static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
614 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
615 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800616 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700617 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800618 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700619}
620
621static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
622 jlong maxFrames, jlong timestamp) {
623 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
624
625 DisplayedFrameStats stats;
626 status_t err = SurfaceComposerClient::getDisplayedContentSample(
627 token, maxFrames, timestamp, &stats);
628 if (err != OK) {
629 return nullptr;
630 }
631
632 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
633 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
634 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
635 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
636 if ((histogramComponent0 == nullptr) ||
637 (histogramComponent1 == nullptr) ||
638 (histogramComponent2 == nullptr) ||
639 (histogramComponent3 == nullptr)) {
640 return JNI_FALSE;
641 }
642
643 env->SetLongArrayRegion(histogramComponent0, 0,
644 stats.component_0_sample.size(),
645 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
646 env->SetLongArrayRegion(histogramComponent1, 0,
647 stats.component_1_sample.size(),
648 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
649 env->SetLongArrayRegion(histogramComponent2, 0,
650 stats.component_2_sample.size(),
651 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
652 env->SetLongArrayRegion(histogramComponent3, 0,
653 stats.component_3_sample.size(),
654 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
655 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
656 gDisplayedContentSampleClassInfo.ctor,
657 stats.numFrames,
658 histogramComponent0,
659 histogramComponent1,
660 histogramComponent2,
661 histogramComponent3);
662}
663
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800664static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
665 jboolean secure) {
666 ScopedUtfChars name(env, nameObj);
667 sp<IBinder> token(SurfaceComposerClient::createDisplay(
668 String8(name.c_str()), bool(secure)));
669 return javaObjectForIBinder(env, token);
670}
671
Jesse Hall6a6bc212013-08-08 12:15:03 -0700672static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
673 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
674 if (token == NULL) return;
675 SurfaceComposerClient::destroyDisplay(token);
676}
677
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800678static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700679 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000680 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800681 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
682 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800683 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800684 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800685 if (sur != NULL) {
686 bufferProducer = sur->getIGraphicBufferProducer();
687 }
Robert Carre13b58e2017-08-31 14:50:44 -0700688
689
690 status_t err = NO_ERROR;
691 {
692 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
693 err = transaction->setDisplaySurface(token,
694 bufferProducer);
695 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700696 if (err != NO_ERROR) {
697 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
698 " Surface created with singleBufferMode?");
699 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800700}
701
702static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700703 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800704 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700705
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800706 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
707 if (token == NULL) return;
708
Robert Carre13b58e2017-08-31 14:50:44 -0700709 {
710 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
711 transaction->setDisplayLayerStack(token, layerStack);
712 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800713}
714
715static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700716 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800717 jobject tokenObj, jint orientation,
718 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
719 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
720 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
721 if (token == NULL) return;
722 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
723 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700724
725 {
726 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
727 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
728 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800729}
730
Michael Wright01e840f2014-06-26 16:03:25 -0700731static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700732 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700733 jobject tokenObj, jint width, jint height) {
734 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
735 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700736
737 {
738 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
739 transaction->setDisplaySize(token, width, height);
740 }
Michael Wright01e840f2014-06-26 16:03:25 -0700741}
742
Dan Stoza00101052014-05-02 15:23:40 -0700743static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
744 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800745 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700746 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800747
Dan Stoza00101052014-05-02 15:23:40 -0700748 Vector<DisplayInfo> configs;
749 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
750 configs.size() == 0) {
751 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800752 }
753
Dan Stoza00101052014-05-02 15:23:40 -0700754 jobjectArray configArray = env->NewObjectArray(configs.size(),
755 gPhysicalDisplayInfoClassInfo.clazz, NULL);
756
757 for (size_t c = 0; c < configs.size(); ++c) {
758 const DisplayInfo& info = configs[c];
759 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
760 gPhysicalDisplayInfoClassInfo.ctor);
761 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
762 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
763 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
764 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
765 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
766 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
767 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700768 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
769 info.appVsyncOffset);
770 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
771 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700772 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
773 env->DeleteLocalRef(infoObj);
774 }
775
776 return configArray;
777}
778
Ady Abraham6070ce12019-01-24 18:48:58 -0800779static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
780 jobject tokenObj, jintArray configArray) {
781 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
782 if (token == nullptr) return JNI_FALSE;
783
784 std::vector<int32_t> allowedConfigs;
785 jsize configArraySize = env->GetArrayLength(configArray);
786 allowedConfigs.reserve(configArraySize);
787
788 jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
789 for (int i = 0; i < configArraySize; i++) {
790 allowedConfigs.push_back(configArrayElements[i]);
791 }
792 env->ReleaseIntArrayElements(configArray, configArrayElements, 0);
793
794 size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
795 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
796}
797
Ady Abraham42f9a2fb2019-02-26 14:13:39 -0800798static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
799 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
800 if (token == nullptr) return JNI_FALSE;
801
802 std::vector<int32_t> allowedConfigs;
803 size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs);
804 if (result != NO_ERROR) {
805 return nullptr;
806 }
807
808 jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size());
809 if (allowedConfigsArray == nullptr) {
810 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
811 return nullptr;
812 }
813 jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0);
814 for (size_t i = 0; i < allowedConfigs.size(); i++) {
815 allowedConfigsArrayValues[i] = static_cast<jint>(allowedConfigs[i]);
816 }
817 env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0);
818 return allowedConfigsArray;
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 Krulec52f12892019-11-18 03:57:20 -0800826 jint defaultModeId = env->GetIntField(desiredDisplayConfigSpecs,
827 gDesiredDisplayConfigSpecsClassInfo.defaultModeId);
828 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 Krulec52f12892019-11-18 03:57:20 -0800834 token, defaultModeId, minRefreshRate, maxRefreshRate);
Ana Krulec4f753aa2019-11-14 00:49:39 +0100835 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
836}
837
Dan Stoza00101052014-05-02 15:23:40 -0700838static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
839 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
840 if (token == NULL) return -1;
841 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
842}
843
844static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
845 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
846 if (token == NULL) return JNI_FALSE;
847 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
848 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800849}
850
Michael Wright1c9977b2016-07-12 13:30:10 -0700851static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
852 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
853 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700854 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700855 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
856 colorModes.isEmpty()) {
857 return NULL;
858 }
859
860 jintArray colorModesArray = env->NewIntArray(colorModes.size());
861 if (colorModesArray == NULL) {
862 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
863 return NULL;
864 }
865 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
866 for (size_t i = 0; i < colorModes.size(); i++) {
867 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
868 }
869 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
870 return colorModesArray;
871}
872
Daniel Solomon10e3b332019-01-20 21:09:11 -0800873static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
874 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
875 if (token == NULL) return NULL;
876
877 ui::DisplayPrimaries primaries;
878 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
879 return NULL;
880 }
881
882 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
883 if (jred == NULL) {
884 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
885 return NULL;
886 }
887
888 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
889 if (jgreen == NULL) {
890 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
891 return NULL;
892 }
893
894 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
895 if (jblue == NULL) {
896 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
897 return NULL;
898 }
899
900 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
901 if (jwhite == NULL) {
902 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
903 return NULL;
904 }
905
906 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
907 gDisplayPrimariesClassInfo.ctor);
908 if (jprimaries == NULL) {
909 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
910 return NULL;
911 }
912
913 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
914 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
915 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
916 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
917 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
918 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
919 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
920 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
921 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
922 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
923 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
924 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
925 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
926 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
927 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
928 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
929
930 return jprimaries;
931}
932
Michael Wright1c9977b2016-07-12 13:30:10 -0700933static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
934 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
935 if (token == NULL) return -1;
936 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
937}
938
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800939static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
940 ui::Dataspace defaultDataspace, wcgDataspace;
941 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
942 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
943 &defaultPixelFormat,
944 &wcgDataspace,
945 &wcgPixelFormat) != NO_ERROR) {
946 return nullptr;
947 }
948 jintArray array = env->NewIntArray(2);
949 if (array == nullptr) {
950 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
951 return nullptr;
952 }
953 jint* arrayValues = env->GetIntArrayElements(array, 0);
954 arrayValues[0] = static_cast<jint>(defaultDataspace);
955 arrayValues[1] = static_cast<jint>(wcgDataspace);
956 env->ReleaseIntArrayElements(array, arrayValues, 0);
957 return array;
958}
959
Michael Wright1c9977b2016-07-12 13:30:10 -0700960static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
961 jobject tokenObj, jint colorMode) {
962 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
963 if (token == NULL) return JNI_FALSE;
964 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700965 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700966 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
967}
968
Prashant Malanic55929a2014-05-25 01:59:21 -0700969static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800970 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
971 if (token == NULL) return;
972
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700973 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700974 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700975 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800976}
977
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800978static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
979 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
980}
981
Svetoslav1376d602014-03-13 11:17:26 -0700982static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
983 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
984 status_t err = ctrl->clearLayerFrameStats();
985
986 if (err < 0 && err != NO_INIT) {
987 doThrowIAE(env);
988 }
989
990 // The other end is not ready, just report we failed.
991 if (err == NO_INIT) {
992 return JNI_FALSE;
993 }
994
995 return JNI_TRUE;
996}
997
998static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
999 jobject outStats) {
1000 FrameStats stats;
1001
1002 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1003 status_t err = ctrl->getLayerFrameStats(&stats);
1004 if (err < 0 && err != NO_INIT) {
1005 doThrowIAE(env);
1006 }
1007
1008 // The other end is not ready, fine just return empty stats.
1009 if (err == NO_INIT) {
1010 return JNI_FALSE;
1011 }
1012
1013 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1014 size_t frameCount = stats.desiredPresentTimesNano.size();
1015
1016 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
1017 if (postedTimesNanoDst == NULL) {
1018 return JNI_FALSE;
1019 }
1020
1021 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1022 if (presentedTimesNanoDst == NULL) {
1023 return JNI_FALSE;
1024 }
1025
1026 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
1027 if (readyTimesNanoDst == NULL) {
1028 return JNI_FALSE;
1029 }
1030
1031 nsecs_t postedTimesNanoSrc[frameCount];
1032 nsecs_t presentedTimesNanoSrc[frameCount];
1033 nsecs_t readyTimesNanoSrc[frameCount];
1034
1035 for (size_t i = 0; i < frameCount; i++) {
1036 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
1037 if (postedTimeNano == INT64_MAX) {
1038 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1039 }
1040 postedTimesNanoSrc[i] = postedTimeNano;
1041
1042 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1043 if (presentedTimeNano == INT64_MAX) {
1044 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1045 }
1046 presentedTimesNanoSrc[i] = presentedTimeNano;
1047
1048 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
1049 if (readyTimeNano == INT64_MAX) {
1050 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1051 }
1052 readyTimesNanoSrc[i] = readyTimeNano;
1053 }
1054
1055 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
1056 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1057 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
1058
1059 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
1060 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
1061
1062 if (env->ExceptionCheck()) {
1063 return JNI_FALSE;
1064 }
1065
1066 return JNI_TRUE;
1067}
1068
1069static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
1070 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
1071
1072 if (err < 0 && err != NO_INIT) {
1073 doThrowIAE(env);
1074 }
1075
1076 // The other end is not ready, just report we failed.
1077 if (err == NO_INIT) {
1078 return JNI_FALSE;
1079 }
1080
1081 return JNI_TRUE;
1082}
1083
1084static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
1085 FrameStats stats;
1086
1087 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1088 if (err < 0 && err != NO_INIT) {
1089 doThrowIAE(env);
1090 }
1091
1092 // The other end is not ready, fine just return empty stats.
1093 if (err == NO_INIT) {
1094 return JNI_FALSE;
1095 }
1096
1097 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1098 size_t frameCount = stats.desiredPresentTimesNano.size();
1099
1100 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1101 if (presentedTimesNanoDst == NULL) {
1102 return JNI_FALSE;
1103 }
1104
1105 nsecs_t presentedTimesNanoSrc[frameCount];
1106
1107 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -07001108 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -07001109 if (presentedTimeNano == INT64_MAX) {
1110 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1111 }
1112 presentedTimesNanoSrc[i] = presentedTimeNano;
1113 }
1114
1115 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1116
1117 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1118 presentedTimesNanoDst);
1119
1120 if (env->ExceptionCheck()) {
1121 return JNI_FALSE;
1122 }
1123
1124 return JNI_TRUE;
1125}
1126
Robert Carre13b58e2017-08-31 14:50:44 -07001127static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001128 jlong nativeObject, jlong barrierObject, jlong frameNumber) {
Rob Carr64e516f2015-10-29 00:20:45 +00001129 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001130 auto barrier = reinterpret_cast<SurfaceControl *>(barrierObject);
1131 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1132 transaction->deferTransactionUntil_legacy(ctrl, barrier->getHandle(), frameNumber);
Rob Carr64e516f2015-10-29 00:20:45 +00001133}
1134
Robert Carre13b58e2017-08-31 14:50:44 -07001135static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1136 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001137 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001138 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1139
Robert Carrd5c7dd62017-03-08 10:39:30 -08001140 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1141 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1142
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001143 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001144}
1145
Robert Carre13b58e2017-08-31 14:50:44 -07001146static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1147 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001148 jlong newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001149
Robert Carrd5c7dd62017-03-08 10:39:30 -08001150 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001151 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
1152 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1153 transaction->reparentChildren(ctrl, newParent->getHandle());
Robert Carrd5c7dd62017-03-08 10:39:30 -08001154}
1155
Robert Carre13b58e2017-08-31 14:50:44 -07001156static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1157 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001158 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001159 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001160 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001161 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1162 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
chaviw63542382017-08-17 17:39:29 -07001163}
1164
Robert Carre13b58e2017-08-31 14:50:44 -07001165static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1166 jlong nativeObject) {
1167 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1168
Robert Carrd5c7dd62017-03-08 10:39:30 -08001169 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001170 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001171}
1172
Robert Carre13b58e2017-08-31 14:50:44 -07001173static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1174 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001175 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001176 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001177
Robert Carre13b58e2017-08-31 14:50:44 -07001178 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1179 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001180}
1181
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001182static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1183 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1184 if (token == NULL) return NULL;
1185
1186 HdrCapabilities capabilities;
1187 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1188
1189 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001190 std::vector<int32_t> intTypes;
1191 for (auto type : types) {
1192 intTypes.push_back(static_cast<int32_t>(type));
1193 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001194 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001195 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001196
Michael Wright9ff94c02016-03-30 18:05:40 -07001197 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001198 typesArray, capabilities.getDesiredMaxLuminance(),
1199 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1200}
1201
Jorim Jaggi06975df2017-12-01 14:52:13 +01001202static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1203 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1204 if (parcel == NULL) {
1205 doThrowNPE(env);
1206 return 0;
1207 }
1208 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1209 if (surface == nullptr) {
1210 return 0;
1211 }
1212 surface->incStrong((void *)nativeCreate);
1213 return reinterpret_cast<jlong>(surface.get());
1214}
1215
chaviwbeb7a0c2018-12-05 13:49:54 -08001216static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1217 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1218 if (surface == nullptr) {
1219 return 0;
1220 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001221
1222 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1223 newSurface->incStrong((void *)nativeCreate);
1224 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001225}
1226
Jorim Jaggi06975df2017-12-01 14:52:13 +01001227static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1228 jlong nativeObject, jobject parcelObj) {
1229 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1230 if (parcel == NULL) {
1231 doThrowNPE(env);
1232 return;
1233 }
1234 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001235 if (self != nullptr) {
1236 self->writeToParcel(parcel);
1237 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001238}
1239
Dan Gittik832b4972019-02-13 18:17:47 +00001240static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1241 jobject displayTokenObject) {
1242 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1243 if (displayToken == nullptr) {
1244 return JNI_FALSE;
1245 }
1246 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1247}
1248
1249static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1250 jfloat brightness) {
1251 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1252 if (displayToken == nullptr) {
1253 return JNI_FALSE;
1254 }
1255 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1256 return error == OK ? JNI_TRUE : JNI_FALSE;
1257}
1258
Vishnu Nair629df2b2019-06-11 16:03:38 -07001259static void nativeWriteTransactionToParcel(JNIEnv* env, jclass clazz, jlong nativeObject,
1260 jobject parcelObj) {
1261 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1262 if (parcel == NULL) {
1263 doThrowNPE(env);
1264 return;
1265 }
1266 SurfaceComposerClient::Transaction* const self =
1267 reinterpret_cast<SurfaceComposerClient::Transaction *>(nativeObject);
1268 if (self != nullptr) {
1269 self->writeToParcel(parcel);
Vishnu Nairf7645aa2019-06-18 11:14:01 -07001270 self->clear();
Vishnu Nair629df2b2019-06-11 16:03:38 -07001271 }
1272}
1273
1274static jlong nativeReadTransactionFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1275 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1276 if (parcel == NULL) {
1277 doThrowNPE(env);
1278 return 0;
1279 }
1280 std::unique_ptr<SurfaceComposerClient::Transaction> transaction =
1281 SurfaceComposerClient::Transaction::createFromParcel(parcel);
1282
1283 return reinterpret_cast<jlong>(transaction.release());
1284}
1285
chaviwa51724f2019-09-19 09:50:11 -07001286static jlong nativeMirrorSurface(JNIEnv* env, jclass clazz, jlong mirrorOfObj) {
1287 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1288 SurfaceControl *mirrorOf = reinterpret_cast<SurfaceControl*>(mirrorOfObj);
1289 sp<SurfaceControl> surface = client->mirrorSurface(mirrorOf);
1290
1291 surface->incStrong((void *)nativeCreate);
1292 return reinterpret_cast<jlong>(surface.get());
1293}
1294
Vishnu Nair4a067c52019-11-19 14:25:56 -08001295static void nativeSetGlobalShadowSettings(JNIEnv* env, jclass clazz, jfloatArray jAmbientColor,
1296 jfloatArray jSpotColor, jfloat lightPosY, jfloat lightPosZ, jfloat lightRadius) {
1297 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1298
1299 float* floatAmbientColor = env->GetFloatArrayElements(jAmbientColor, 0);
1300 half4 ambientColor = half4(floatAmbientColor[0], floatAmbientColor[1], floatAmbientColor[2],
1301 floatAmbientColor[3]);
1302 env->ReleaseFloatArrayElements(jAmbientColor, floatAmbientColor, 0);
1303
1304 float* floatSpotColor = env->GetFloatArrayElements(jSpotColor, 0);
1305 half4 spotColor = half4(floatSpotColor[0], floatSpotColor[1], floatSpotColor[2],
1306 floatSpotColor[3]);
1307 env->ReleaseFloatArrayElements(jSpotColor, floatSpotColor, 0);
1308
1309 client->setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ, lightRadius);
1310}
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001311// ----------------------------------------------------------------------------
1312
Daniel Micay76f6a862015-09-19 17:31:01 -04001313static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001314 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001315 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001316 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1317 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001318 {"nativeCopyFromSurfaceControl", "(J)J" ,
1319 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001320 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1321 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001322 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001323 (void*)nativeRelease },
Chong Zhang47e36a32016-02-29 16:44:33 -08001324 {"nativeDisconnect", "(J)V",
1325 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001326 {"nativeCreateTransaction", "()J",
1327 (void*)nativeCreateTransaction },
1328 {"nativeApplyTransaction", "(JZ)V",
1329 (void*)nativeApplyTransaction },
1330 {"nativeGetNativeTransactionFinalizer", "()J",
1331 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001332 {"nativeMergeTransaction", "(JJ)V",
1333 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001334 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001335 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001336 {"nativeSetEarlyWakeup", "(J)V",
1337 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001338 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001339 (void*)nativeSetLayer },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001340 {"nativeSetRelativeLayer", "(JJJI)V",
Robert Carraf422a82017-04-10 18:34:33 -07001341 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001342 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001343 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001344 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001345 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001346 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001347 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001348 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001349 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001350 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001351 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001352 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001353 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001354 {"nativeSetColorTransform", "(JJ[F[F)V",
1355 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001356 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1357 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001358 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001359 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001360 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001361 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001362 {"nativeSetCornerRadius", "(JJF)V",
1363 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001364 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001365 (void*)nativeSetLayerStack },
Vishnu Naird87984d2019-11-06 14:43:22 -08001366 {"nativeSetShadowRadius", "(JJF)V",
1367 (void*)nativeSetShadowRadius },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001368 {"nativeGetPhysicalDisplayIds", "()[J",
1369 (void*)nativeGetPhysicalDisplayIds },
1370 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1371 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001372 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1373 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001374 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1375 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001376 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001377 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001378 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001379 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001380 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001381 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001382 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001383 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001384 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1385 (void*)nativeGetDisplayConfigs },
1386 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1387 (void*)nativeGetActiveConfig },
1388 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1389 (void*)nativeSetActiveConfig },
Ady Abraham6070ce12019-01-24 18:48:58 -08001390 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1391 (void*)nativeSetAllowedDisplayConfigs },
Ady Abraham42f9a2fb2019-02-26 14:13:39 -08001392 {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
1393 (void*)nativeGetAllowedDisplayConfigs },
Ana Krulec52f12892019-11-18 03:57:20 -08001394 {"nativeSetDesiredDisplayConfigSpecs",
1395 "(Landroid/os/IBinder;Landroid/view/SurfaceControl$DesiredDisplayConfigSpecs;)Z",
Ana Krulec4f753aa2019-11-14 00:49:39 +01001396 (void*)nativeSetDesiredDisplayConfigSpecs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001397 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1398 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001399 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1400 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001401 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1402 (void*)nativeGetActiveColorMode},
1403 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1404 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001405 {"nativeGetCompositionDataspaces", "()[I",
1406 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001407 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1408 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001409 {"nativeClearContentFrameStats", "(J)Z",
1410 (void*)nativeClearContentFrameStats },
1411 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1412 (void*)nativeGetContentFrameStats },
1413 {"nativeClearAnimationFrameStats", "()Z",
1414 (void*)nativeClearAnimationFrameStats },
1415 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1416 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001417 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1418 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001419 {"nativeGetProtectedContentSupport", "()Z",
1420 (void*)nativeGetProtectedContentSupport },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001421 {"nativeDeferTransactionUntil", "(JJJJ)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001422 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001423 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001424 (void*)nativeDeferTransactionUntilSurface },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001425 {"nativeReparentChildren", "(JJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001426 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001427 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001428 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001429 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001430 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001431 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001432 (void*)nativeSetOverrideScalingMode },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001433 {"nativeScreenshot",
1434 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1435 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001436 (void*)nativeScreenshot },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001437 {"nativeCaptureLayers",
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001438 "(Landroid/os/IBinder;JLandroid/graphics/Rect;"
Chiawei Wang02202d12019-01-03 18:12:13 +08001439 "F[JI)"
Peiyong Line3e5efd2019-03-21 20:59:47 +00001440 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001441 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001442 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001443 (void*)nativeSetInputWindowInfo },
Evan Roskyb51e2462019-04-03 19:27:18 -07001444 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
Evan Rosky485df202018-12-06 14:11:12 -08001445 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001446 {"nativeGetDisplayedContentSamplingAttributes",
1447 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1448 (void*)nativeGetDisplayedContentSamplingAttributes },
1449 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1450 (void*)nativeSetDisplayedContentSamplingEnabled },
1451 {"nativeGetDisplayedContentSample",
1452 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1453 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001454 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001455 (void*)nativeSetGeometry },
1456 {"nativeSyncInputWindows", "(J)V",
Dan Gittik832b4972019-02-13 18:17:47 +00001457 (void*)nativeSyncInputWindows },
1458 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1459 (void*)nativeGetDisplayBrightnessSupport },
1460 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1461 (void*)nativeSetDisplayBrightness },
Vishnu Nair629df2b2019-06-11 16:03:38 -07001462 {"nativeReadTransactionFromParcel", "(Landroid/os/Parcel;)J",
1463 (void*)nativeReadTransactionFromParcel },
1464 {"nativeWriteTransactionToParcel", "(JLandroid/os/Parcel;)V",
1465 (void*)nativeWriteTransactionToParcel },
chaviwa51724f2019-09-19 09:50:11 -07001466 {"nativeMirrorSurface", "(J)J",
1467 (void*)nativeMirrorSurface },
Vishnu Nair4a067c52019-11-19 14:25:56 -08001468 {"nativeSetGlobalShadowSettings", "([F[FFFF)V",
1469 (void*)nativeSetGlobalShadowSettings },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001470};
1471
1472int register_android_view_SurfaceControl(JNIEnv* env)
1473{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001474 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001475 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1476
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001477 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1478 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1479 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1480 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1481 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1482 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1483 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1484 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1485 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1486 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1487 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1488 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1489 clazz, "appVsyncOffsetNanos", "J");
1490 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1491 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001492
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001493 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1494 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1495 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1496 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1497 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001498
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001499 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1500 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1501 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001502 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1503
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001504 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1505 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1506 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001507 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1508
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001509 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1510 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1511 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001512 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1513
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001514 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1515 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1516 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1517 "([IFFF)V");
1518
Robert Carr6486d312017-01-09 19:48:29 -08001519 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1520 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1521 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1522 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1523
Peiyong Line3e5efd2019-03-21 20:59:47 +00001524 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1525 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1526 gScreenshotGraphicBufferClassInfo.clazz =
1527 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1528 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1529 screenshotGraphicsBufferClazz,
Robert Carr66b5664f2019-04-02 14:18:56 -07001530 "createFromNative", "(IIIIJIZ)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
Peiyong Line3e5efd2019-03-21 20:59:47 +00001531
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001532 jclass displayedContentSampleClazz = FindClassOrDie(env,
1533 "android/hardware/display/DisplayedContentSample");
1534 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1535 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1536 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1537
1538 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1539 "android/hardware/display/DisplayedContentSamplingAttributes");
1540 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1541 displayedContentSamplingAttributesClazz);
1542 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1543 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001544
1545 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1546 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1547 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1548 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1549 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1550 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1551
1552 jclass displayPrimariesClazz = FindClassOrDie(env,
1553 "android/view/SurfaceControl$DisplayPrimaries");
1554 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1555 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1556 "<init>", "()V");
1557 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1558 "Landroid/view/SurfaceControl$CieXyz;");
1559 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1560 "Landroid/view/SurfaceControl$CieXyz;");
1561 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1562 "Landroid/view/SurfaceControl$CieXyz;");
1563 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1564 "Landroid/view/SurfaceControl$CieXyz;");
1565
Ana Krulec52f12892019-11-18 03:57:20 -08001566 jclass desiredDisplayConfigSpecsClazz =
1567 FindClassOrDie(env, "android/view/SurfaceControl$DesiredDisplayConfigSpecs");
1568 gDesiredDisplayConfigSpecsClassInfo.clazz =
1569 MakeGlobalRefOrDie(env, desiredDisplayConfigSpecsClazz);
1570 gDesiredDisplayConfigSpecsClassInfo.ctor =
1571 GetMethodIDOrDie(env, gDesiredDisplayConfigSpecsClassInfo.clazz, "<init>", "(IFF)V");
1572 gDesiredDisplayConfigSpecsClassInfo.defaultModeId =
1573 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "mDefaultModeId", "I");
1574 gDesiredDisplayConfigSpecsClassInfo.minRefreshRate =
1575 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "mMinRefreshRate", "F");
1576 gDesiredDisplayConfigSpecsClassInfo.maxRefreshRate =
1577 GetFieldIDOrDie(env, desiredDisplayConfigSpecsClazz, "mMaxRefreshRate", "F");
1578
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001579 return err;
1580}
1581
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001582} // namespace android