blob: 030d3be8a6707b7cce377d3e1a5f112942f8f687 [file] [log] [blame]
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceControl"
Robert Carr6486d312017-01-09 19:48:29 -080018#define LOG_NDEBUG 0
Mathias Agopian3866f0d2013-02-11 22:08:48 -080019
Mathias Agopian3866f0d2013-02-11 22:08:48 -080020#include "android_os_Parcel.h"
21#include "android_util_Binder.h"
Robert Carr788f5742018-07-30 17:46:45 -070022#include "android_hardware_input_InputWindowHandle.h"
John Reckf29ed282015-04-07 07:32:03 -070023#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080024#include "android/graphics/GraphicsJNI.h"
25#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080026#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040027
Tom Cherry8ed74bb2017-07-10 14:31:18 -070028#include <android-base/chrono_utils.h>
Steven Moreland2279b252017-07-19 09:50:45 -070029#include <nativehelper/JNIHelp.h>
30#include <nativehelper/ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080031#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080033#include <gui/Surface.h>
34#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040035#include <jni.h>
36#include <memory>
37#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070038#include <system/graphics.h>
Daniel Solomon10e3b332019-01-20 21:09:11 -080039#include <ui/ConfigStoreTypes.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080040#include <ui/DisplayInfo.h>
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070041#include <ui/DisplayedFrameStats.h>
Svetoslav1376d602014-03-13 11:17:26 -070042#include <ui/FrameStats.h>
Peiyong Linb88549e2018-03-28 12:03:45 -070043#include <ui/GraphicTypes.h>
Peiyong Lin371b98f2018-03-14 17:29:10 -070044#include <ui/HdrCapabilities.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080045#include <ui/Rect.h>
46#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080047#include <utils/Log.h>
48
Mathias Agopian3866f0d2013-02-11 22:08:48 -080049// ----------------------------------------------------------------------------
50
51namespace android {
52
53static const char* const OutOfResourcesException =
54 "android/view/Surface$OutOfResourcesException";
55
56static struct {
Dan Stoza00101052014-05-02 15:23:40 -070057 jclass clazz;
58 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080059 jfieldID width;
60 jfieldID height;
61 jfieldID refreshRate;
62 jfieldID density;
63 jfieldID xDpi;
64 jfieldID yDpi;
65 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070066 jfieldID appVsyncOffsetNanos;
67 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080068} gPhysicalDisplayInfoClassInfo;
69
Dan Stoza9890e3412014-05-22 16:12:54 -070070static struct {
71 jfieldID bottom;
72 jfieldID left;
73 jfieldID right;
74 jfieldID top;
75} gRectClassInfo;
76
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050077// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
78void DeleteScreenshot(void* addr, void* context) {
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050079 delete ((ScreenshotClient*) context);
80}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080081
Svetoslav1376d602014-03-13 11:17:26 -070082static struct {
83 nsecs_t UNDEFINED_TIME_NANO;
84 jmethodID init;
85} gWindowContentFrameStatsClassInfo;
86
87static struct {
88 nsecs_t UNDEFINED_TIME_NANO;
89 jmethodID init;
90} gWindowAnimationFrameStatsClassInfo;
91
Hangyu Kuang54ac2192016-04-25 13:22:02 -070092static struct {
93 jclass clazz;
94 jmethodID ctor;
95} gHdrCapabilitiesClassInfo;
96
Robert Carr6486d312017-01-09 19:48:29 -080097static struct {
98 jclass clazz;
99 jmethodID builder;
100} gGraphicBufferClassInfo;
101
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700102static struct {
103 jclass clazz;
104 jmethodID ctor;
105} gDisplayedContentSampleClassInfo;
106
107static struct {
108 jclass clazz;
109 jmethodID ctor;
110} gDisplayedContentSamplingAttributesClassInfo;
111
Daniel Solomon10e3b332019-01-20 21:09:11 -0800112static struct {
113 jclass clazz;
114 jmethodID ctor;
115 jfieldID X;
116 jfieldID Y;
117 jfieldID Z;
118} gCieXyzClassInfo;
119
120static struct {
121 jclass clazz;
122 jmethodID ctor;
123 jfieldID red;
124 jfieldID green;
125 jfieldID blue;
126 jfieldID white;
127} gDisplayPrimariesClassInfo;
128
Peiyong Line3e5efd2019-03-21 20:59:47 +0000129static struct {
130 jclass clazz;
131 jmethodID builder;
132} gScreenshotGraphicBufferClassInfo;
133
134class JNamedColorSpace {
135public:
136 // ColorSpace.Named.SRGB.ordinal() = 0;
137 static constexpr jint SRGB = 0;
138
Peiyong Line9133d52019-05-01 15:36:04 -0700139 // ColorSpace.Named.DISPLAY_P3.ordinal() = 7;
140 static constexpr jint DISPLAY_P3 = 7;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000141};
142
143constexpr jint fromDataspaceToNamedColorSpaceValue(const ui::Dataspace dataspace) {
144 switch (dataspace) {
145 case ui::Dataspace::DISPLAY_P3:
146 return JNamedColorSpace::DISPLAY_P3;
147 default:
148 return JNamedColorSpace::SRGB;
149 }
150}
151
152constexpr ui::Dataspace pickDataspaceFromColorMode(const ui::ColorMode colorMode) {
153 switch (colorMode) {
154 case ui::ColorMode::DISPLAY_P3:
155 case ui::ColorMode::BT2100_PQ:
156 case ui::ColorMode::BT2100_HLG:
157 case ui::ColorMode::DISPLAY_BT2020:
158 return ui::Dataspace::DISPLAY_P3;
159 default:
160 return ui::Dataspace::V0_SRGB;
161 }
162}
163
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800164// ----------------------------------------------------------------------------
165
Robert Carre13b58e2017-08-31 14:50:44 -0700166static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
167 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
168}
169
170static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
171 delete t;
172}
173
174static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
175 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
176}
177
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000178static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500179 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
Evan Rosky485df202018-12-06 14:11:12 -0800180 jobject metadataParcel) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800181 ScopedUtfChars name(env, nameStr);
Robert Carr76907ee2019-01-11 13:38:19 -0800182 sp<SurfaceComposerClient> client;
183 if (sessionObj != NULL) {
184 client = android_view_SurfaceSession_getClient(env, sessionObj);
185 } else {
186 client = SurfaceComposerClient::getDefault();
187 }
Robert Carr838120c2016-11-01 18:31:12 -0700188 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Robert Carrb0f39362018-03-14 13:52:25 -0700189 sp<SurfaceControl> surface;
Evan Rosky485df202018-12-06 14:11:12 -0800190 LayerMetadata metadata;
191 Parcel* parcel = parcelForJavaObject(env, metadataParcel);
192 if (parcel && !parcel->objectsCount()) {
193 status_t err = metadata.readFromParcel(parcel);
194 if (err != NO_ERROR) {
195 jniThrowException(env, "java/lang/IllegalArgumentException",
196 "Metadata parcel has wrong format");
197 }
198 }
199
Robert Carrb0f39362018-03-14 13:52:25 -0700200 status_t err = client->createSurfaceChecked(
Evan Rosky485df202018-12-06 14:11:12 -0800201 String8(name.c_str()), w, h, format, &surface, flags, parent, std::move(metadata));
Robert Carrb0f39362018-03-14 13:52:25 -0700202 if (err == NAME_NOT_FOUND) {
203 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
204 return 0;
205 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800206 jniThrowException(env, OutOfResourcesException, NULL);
207 return 0;
208 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500209
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800210 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000211 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800212}
213
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000214static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800215 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Robert Carrcc6d4832019-02-04 15:41:12 -0800216 ctrl->release();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800217 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800218}
219
Chong Zhang47e36a32016-02-29 16:44:33 -0800220static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
221 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
222 if (ctrl != NULL) {
223 ctrl->disconnect();
224 }
225}
226
Robert Carr6486d312017-01-09 19:48:29 -0800227static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
228 int left = env->GetIntField(rectObj, gRectClassInfo.left);
229 int top = env->GetIntField(rectObj, gRectClassInfo.top);
230 int right = env->GetIntField(rectObj, gRectClassInfo.right);
231 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
232 return Rect(left, top, right, bottom);
233}
234
chaviw08520a02018-09-10 16:44:56 -0700235static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800236 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Robert Carr5c52b132019-02-15 15:48:11 -0800237 bool useIdentityTransform, int rotation, bool captureSecureLayers) {
Robert Carr6486d312017-01-09 19:48:29 -0800238 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
239 if (displayToken == NULL) {
240 return NULL;
241 }
Peiyong Line3e5efd2019-03-21 20:59:47 +0000242 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
243 const ui::Dataspace dataspace = pickDataspaceFromColorMode(colorMode);
244
Robert Carr6486d312017-01-09 19:48:29 -0800245 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800246 sp<GraphicBuffer> buffer;
Robert Carr66b5664f2019-04-02 14:18:56 -0700247 bool capturedSecureLayers = false;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000248 status_t res = ScreenshotClient::capture(displayToken, dataspace,
Robert Carr5c52b132019-02-15 15:48:11 -0800249 ui::PixelFormat::RGBA_8888,
250 sourceCrop, width, height,
Robert Carr66b5664f2019-04-02 14:18:56 -0700251 useIdentityTransform, rotation, captureSecureLayers, &buffer, capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800252 if (res != NO_ERROR) {
253 return NULL;
254 }
255
Peiyong Line3e5efd2019-03-21 20:59:47 +0000256 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
257 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
258 gScreenshotGraphicBufferClassInfo.builder,
Robert Carr6486d312017-01-09 19:48:29 -0800259 buffer->getWidth(),
260 buffer->getHeight(),
261 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700262 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000263 (jlong)buffer.get(),
Robert Carr66b5664f2019-04-02 14:18:56 -0700264 namedColorSpace,
265 capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800266}
267
Peiyong Lin21e499a2019-04-03 16:37:46 -0700268static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
269 jobject layerHandleToken, jobject sourceCropObj, jfloat frameScale,
270 jobjectArray excludeArray) {
chaviwfbe47df2017-11-10 16:14:49 -0800271
272 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
273 if (layerHandle == NULL) {
274 return NULL;
275 }
276
277 Rect sourceCrop;
278 if (sourceCropObj != NULL) {
279 sourceCrop = rectFromObj(env, sourceCropObj);
280 }
281
Robert Carrffcdc512019-04-02 11:51:11 -0700282 std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
283 if (excludeArray != NULL) {
284 const jsize len = env->GetArrayLength(excludeArray);
285 excludeHandles.reserve(len);
286
287 for (jsize i = 0; i < len; i++) {
288 jobject obj = env->GetObjectArrayElement(excludeArray, i);
289 if (obj == nullptr) {
290 jniThrowNullPointerException(env, "Exclude layer is null");
291 return NULL;
292 }
293 sp<IBinder> excludeHandle = ibinderForJavaObject(env, obj);
294 excludeHandles.emplace(excludeHandle);
295 }
296 }
297
chaviwfbe47df2017-11-10 16:14:49 -0800298 sp<GraphicBuffer> buffer;
Peiyong Lin21e499a2019-04-03 16:37:46 -0700299 ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
300 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
301 if (displayToken != nullptr) {
302 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
303 dataspace = pickDataspaceFromColorMode(colorMode);
304 }
Peiyong Line3e5efd2019-03-21 20:59:47 +0000305 status_t res = ScreenshotClient::captureChildLayers(layerHandle, dataspace,
Peiyong Lin10a34d12018-09-19 13:56:12 -0700306 ui::PixelFormat::RGBA_8888, sourceCrop,
Robert Carrffcdc512019-04-02 11:51:11 -0700307 excludeHandles, frameScale, &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800308 if (res != NO_ERROR) {
309 return NULL;
310 }
311
Peiyong Line3e5efd2019-03-21 20:59:47 +0000312 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
313 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
314 gScreenshotGraphicBufferClassInfo.builder,
chaviwfbe47df2017-11-10 16:14:49 -0800315 buffer->getWidth(),
316 buffer->getHeight(),
317 buffer->getPixelFormat(),
318 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000319 (jlong)buffer.get(),
Robert Carrbf9298f2019-04-09 07:42:02 -0700320 namedColorSpace,
321 false /* capturedSecureLayers */);
chaviw1cda84c2017-10-23 16:47:10 -0700322}
323
Robert Carre13b58e2017-08-31 14:50:44 -0700324static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
325 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
326 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800327}
328
Robert Carrb1579c82017-09-05 14:54:47 -0700329static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
330 jlong transactionObj, jlong otherTransactionObj) {
331 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
332 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
333 otherTransactionObj);
334 transaction->merge(std::move(*otherTransaction));
335}
336
Robert Carre13b58e2017-08-31 14:50:44 -0700337static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
338 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
339 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800340}
341
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100342static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
343 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
344 transaction->setEarlyWakeup();
345}
346
Robert Carre13b58e2017-08-31 14:50:44 -0700347static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
348 jlong nativeObject, jint zorder) {
349 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800350
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800351 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700352 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800353}
354
Robert Carre13b58e2017-08-31 14:50:44 -0700355static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
356 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700357 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700358
Robert Carraf422a82017-04-10 18:34:33 -0700359 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
360 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
361
Robert Carre13b58e2017-08-31 14:50:44 -0700362 {
363 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
364 transaction->setRelativeLayer(ctrl, handle, zorder);
365 }
Robert Carraf422a82017-04-10 18:34:33 -0700366}
367
Robert Carre13b58e2017-08-31 14:50:44 -0700368static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
369 jlong nativeObject, jfloat x, jfloat y) {
370 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
371
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800372 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700373 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800374}
375
Robert Carr76907ee2019-01-11 13:38:19 -0800376static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
377 jobject sourceObj, jobject dstObj, jlong orientation) {
378 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
379 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
380
381 Rect source, dst;
382 if (sourceObj != NULL) {
383 source = rectFromObj(env, sourceObj);
Robert Carrced6f852019-04-08 16:58:49 -0700384 } else {
385 source.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800386 }
387 if (dstObj != NULL) {
388 dst = rectFromObj(env, dstObj);
Robert Carrced6f852019-04-08 16:58:49 -0700389 } else {
390 dst.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800391 }
392 transaction->setGeometry(ctrl, source, dst, orientation);
393}
394
Robert Carr6da3cc02016-06-16 15:17:07 -0700395static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700396jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700397 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700398 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
399
Robert Carra9408d42016-06-03 13:28:48 -0700400 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700401 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700402}
403
Robert Carre13b58e2017-08-31 14:50:44 -0700404static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
405 jlong nativeObject, jint w, jint h) {
406 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
407
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800408 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700409 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800410}
411
Robert Carre13b58e2017-08-31 14:50:44 -0700412static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
413 jlong nativeObject, jint flags, jint mask) {
414 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
415
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800416 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700417 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800418}
419
Robert Carre13b58e2017-08-31 14:50:44 -0700420static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
421 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800422 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
423 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
424 if (!region) {
425 doThrowIAE(env);
426 return;
427 }
428
429 const SkIRect& b(region->getBounds());
430 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
431 if (region->isComplex()) {
432 SkRegion::Iterator it(*region);
433 while (!it.done()) {
434 const SkIRect& r(it.rect());
435 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
436 it.next();
437 }
438 }
439
Robert Carre13b58e2017-08-31 14:50:44 -0700440 {
441 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
442 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800443 }
444}
445
Robert Carre13b58e2017-08-31 14:50:44 -0700446static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
447 jlong nativeObject, jfloat alpha) {
448 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
449
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800450 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700451 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800452}
453
Robert Carr788f5742018-07-30 17:46:45 -0700454static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
455 jlong nativeObject, jobject inputWindow) {
456 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
457
Riddle Hsucd958bc2019-01-23 15:40:26 +0800458 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700459 env, inputWindow);
460 handle->updateInfo();
461
462 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
463 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
464}
465
chaviw59f532e2018-12-26 15:34:59 -0800466static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
467 jobject fromTokenObj, jobject toTokenObj) {
468 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
469
470 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
471 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
472 transaction->transferTouchFocus(fromToken, toToken);
473}
474
chaviw319cd0782019-02-14 11:00:23 -0800475static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
476 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
477 transaction->syncInputWindows();
478}
479
Evan Rosky485df202018-12-06 14:11:12 -0800480static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
481 jlong nativeObject, jint id, jobject parcelObj) {
482 Parcel* parcel = parcelForJavaObject(env, parcelObj);
483 if (!parcel) {
484 jniThrowNullPointerException(env, "attribute data");
485 return;
486 }
487 if (parcel->objectsCount()) {
488 jniThrowException(env, "java/lang/RuntimeException",
489 "Tried to marshall a Parcel that contained Binder objects.");
490 return;
491 }
492
493 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
494
495 std::vector<uint8_t> byteData(parcel->dataSize());
496 memcpy(byteData.data(), parcel->data(), parcel->dataSize());
497
498 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
499 transaction->setMetadata(ctrl, id, std::move(byteData));
500}
501
Robert Carre13b58e2017-08-31 14:50:44 -0700502static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
503 jlong nativeObject, jfloatArray fColor) {
504 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700505 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700506
chaviw0dd03f52017-08-25 12:15:26 -0700507 float* floatColors = env->GetFloatArrayElements(fColor, 0);
508 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700509 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700510}
511
Robert Carre13b58e2017-08-31 14:50:44 -0700512static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
513 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800514 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700515 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
516
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800517 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700518 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800519}
520
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700521static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
522 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
523 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
524 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
525 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
526 mat3 matrix(static_cast<float const*>(floatMatrix));
527 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
528 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
529 transaction->setColorTransform(surfaceControl, matrix, translation);
530}
531
Peiyong Linf4f0f642019-03-01 14:36:05 -0800532static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
533 jlong nativeObject, jboolean agnostic) {
534 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
535 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
536 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
537}
538
Robert Carre13b58e2017-08-31 14:50:44 -0700539static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
540 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800541 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700542 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
543
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800544 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
545 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700546 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800547}
548
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700549static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
550 jlong nativeObject, jfloat cornerRadius) {
551 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
552
553 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
554 transaction->setCornerRadius(ctrl, cornerRadius);
555}
556
Robert Carre13b58e2017-08-31 14:50:44 -0700557static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
558 jlong nativeObject, jint layerStack) {
559 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
560
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800561 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700562 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800563}
564
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800565static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
566 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
567 jlongArray array = env->NewLongArray(displayIds.size());
568 if (array == nullptr) {
569 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
570 return nullptr;
571 }
572
573 if (displayIds.empty()) {
574 return array;
575 }
576
577 jlong* values = env->GetLongArrayElements(array, 0);
578 for (size_t i = 0; i < displayIds.size(); ++i) {
579 values[i] = static_cast<jlong>(displayIds[i]);
580 }
581
582 env->ReleaseLongArrayElements(array, values, 0);
583 return array;
584}
585
586static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
587 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800588 return javaObjectForIBinder(env, token);
589}
590
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700591static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
592 jobject tokenObj) {
593 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
594
595 ui::PixelFormat format;
596 ui::Dataspace dataspace;
597 uint8_t componentMask;
598 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
599 token, &format, &dataspace, &componentMask);
600 if (err != OK) {
601 return nullptr;
602 }
603 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
604 gDisplayedContentSamplingAttributesClassInfo.ctor,
605 format, dataspace, componentMask);
606}
607
608static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
609 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
610 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800611 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700612 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800613 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700614}
615
616static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
617 jlong maxFrames, jlong timestamp) {
618 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
619
620 DisplayedFrameStats stats;
621 status_t err = SurfaceComposerClient::getDisplayedContentSample(
622 token, maxFrames, timestamp, &stats);
623 if (err != OK) {
624 return nullptr;
625 }
626
627 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
628 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
629 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
630 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
631 if ((histogramComponent0 == nullptr) ||
632 (histogramComponent1 == nullptr) ||
633 (histogramComponent2 == nullptr) ||
634 (histogramComponent3 == nullptr)) {
635 return JNI_FALSE;
636 }
637
638 env->SetLongArrayRegion(histogramComponent0, 0,
639 stats.component_0_sample.size(),
640 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
641 env->SetLongArrayRegion(histogramComponent1, 0,
642 stats.component_1_sample.size(),
643 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
644 env->SetLongArrayRegion(histogramComponent2, 0,
645 stats.component_2_sample.size(),
646 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
647 env->SetLongArrayRegion(histogramComponent3, 0,
648 stats.component_3_sample.size(),
649 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
650 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
651 gDisplayedContentSampleClassInfo.ctor,
652 stats.numFrames,
653 histogramComponent0,
654 histogramComponent1,
655 histogramComponent2,
656 histogramComponent3);
657}
658
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800659static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
660 jboolean secure) {
661 ScopedUtfChars name(env, nameObj);
662 sp<IBinder> token(SurfaceComposerClient::createDisplay(
663 String8(name.c_str()), bool(secure)));
664 return javaObjectForIBinder(env, token);
665}
666
Jesse Hall6a6bc212013-08-08 12:15:03 -0700667static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
668 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
669 if (token == NULL) return;
670 SurfaceComposerClient::destroyDisplay(token);
671}
672
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800673static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700674 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000675 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800676 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
677 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800678 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800679 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800680 if (sur != NULL) {
681 bufferProducer = sur->getIGraphicBufferProducer();
682 }
Robert Carre13b58e2017-08-31 14:50:44 -0700683
684
685 status_t err = NO_ERROR;
686 {
687 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
688 err = transaction->setDisplaySurface(token,
689 bufferProducer);
690 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700691 if (err != NO_ERROR) {
692 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
693 " Surface created with singleBufferMode?");
694 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800695}
696
697static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700698 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800699 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700700
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800701 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
702 if (token == NULL) return;
703
Robert Carre13b58e2017-08-31 14:50:44 -0700704 {
705 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
706 transaction->setDisplayLayerStack(token, layerStack);
707 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800708}
709
710static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700711 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800712 jobject tokenObj, jint orientation,
713 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
714 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
715 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
716 if (token == NULL) return;
717 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
718 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700719
720 {
721 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
722 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
723 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800724}
725
Michael Wright01e840f2014-06-26 16:03:25 -0700726static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700727 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700728 jobject tokenObj, jint width, jint height) {
729 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
730 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700731
732 {
733 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
734 transaction->setDisplaySize(token, width, height);
735 }
Michael Wright01e840f2014-06-26 16:03:25 -0700736}
737
Dan Stoza00101052014-05-02 15:23:40 -0700738static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
739 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800740 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700741 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800742
Dan Stoza00101052014-05-02 15:23:40 -0700743 Vector<DisplayInfo> configs;
744 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
745 configs.size() == 0) {
746 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800747 }
748
Dan Stoza00101052014-05-02 15:23:40 -0700749 jobjectArray configArray = env->NewObjectArray(configs.size(),
750 gPhysicalDisplayInfoClassInfo.clazz, NULL);
751
752 for (size_t c = 0; c < configs.size(); ++c) {
753 const DisplayInfo& info = configs[c];
754 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
755 gPhysicalDisplayInfoClassInfo.ctor);
756 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
757 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
758 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
759 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
760 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
761 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
762 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700763 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
764 info.appVsyncOffset);
765 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
766 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700767 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
768 env->DeleteLocalRef(infoObj);
769 }
770
771 return configArray;
772}
773
Ady Abraham6070ce12019-01-24 18:48:58 -0800774static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
775 jobject tokenObj, jintArray configArray) {
776 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
777 if (token == nullptr) return JNI_FALSE;
778
779 std::vector<int32_t> allowedConfigs;
780 jsize configArraySize = env->GetArrayLength(configArray);
781 allowedConfigs.reserve(configArraySize);
782
783 jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
784 for (int i = 0; i < configArraySize; i++) {
785 allowedConfigs.push_back(configArrayElements[i]);
786 }
787 env->ReleaseIntArrayElements(configArray, configArrayElements, 0);
788
789 size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
790 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
791}
792
Ady Abraham42f9a2fb2019-02-26 14:13:39 -0800793static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
794 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
795 if (token == nullptr) return JNI_FALSE;
796
797 std::vector<int32_t> allowedConfigs;
798 size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs);
799 if (result != NO_ERROR) {
800 return nullptr;
801 }
802
803 jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size());
804 if (allowedConfigsArray == nullptr) {
805 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
806 return nullptr;
807 }
808 jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0);
809 for (size_t i = 0; i < allowedConfigs.size(); i++) {
810 allowedConfigsArrayValues[i] = static_cast<jint>(allowedConfigs[i]);
811 }
812 env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0);
813 return allowedConfigsArray;
814}
815
Dan Stoza00101052014-05-02 15:23:40 -0700816static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
817 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
818 if (token == NULL) return -1;
819 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
820}
821
822static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
823 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
824 if (token == NULL) return JNI_FALSE;
825 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
826 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800827}
828
Michael Wright1c9977b2016-07-12 13:30:10 -0700829static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
830 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
831 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700832 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700833 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
834 colorModes.isEmpty()) {
835 return NULL;
836 }
837
838 jintArray colorModesArray = env->NewIntArray(colorModes.size());
839 if (colorModesArray == NULL) {
840 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
841 return NULL;
842 }
843 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
844 for (size_t i = 0; i < colorModes.size(); i++) {
845 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
846 }
847 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
848 return colorModesArray;
849}
850
Daniel Solomon10e3b332019-01-20 21:09:11 -0800851static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
852 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
853 if (token == NULL) return NULL;
854
855 ui::DisplayPrimaries primaries;
856 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
857 return NULL;
858 }
859
860 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
861 if (jred == NULL) {
862 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
863 return NULL;
864 }
865
866 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
867 if (jgreen == NULL) {
868 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
869 return NULL;
870 }
871
872 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
873 if (jblue == NULL) {
874 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
875 return NULL;
876 }
877
878 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
879 if (jwhite == NULL) {
880 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
881 return NULL;
882 }
883
884 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
885 gDisplayPrimariesClassInfo.ctor);
886 if (jprimaries == NULL) {
887 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
888 return NULL;
889 }
890
891 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
892 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
893 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
894 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
895 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
896 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
897 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
898 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
899 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
900 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
901 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
902 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
903 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
904 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
905 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
906 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
907
908 return jprimaries;
909}
910
Michael Wright1c9977b2016-07-12 13:30:10 -0700911static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
912 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
913 if (token == NULL) return -1;
914 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
915}
916
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800917static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
918 ui::Dataspace defaultDataspace, wcgDataspace;
919 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
920 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
921 &defaultPixelFormat,
922 &wcgDataspace,
923 &wcgPixelFormat) != NO_ERROR) {
924 return nullptr;
925 }
926 jintArray array = env->NewIntArray(2);
927 if (array == nullptr) {
928 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
929 return nullptr;
930 }
931 jint* arrayValues = env->GetIntArrayElements(array, 0);
932 arrayValues[0] = static_cast<jint>(defaultDataspace);
933 arrayValues[1] = static_cast<jint>(wcgDataspace);
934 env->ReleaseIntArrayElements(array, arrayValues, 0);
935 return array;
936}
937
Michael Wright1c9977b2016-07-12 13:30:10 -0700938static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
939 jobject tokenObj, jint colorMode) {
940 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
941 if (token == NULL) return JNI_FALSE;
942 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700943 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700944 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
945}
946
Prashant Malanic55929a2014-05-25 01:59:21 -0700947static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800948 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
949 if (token == NULL) return;
950
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700951 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700952 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700953 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800954}
955
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800956static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
957 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
958}
959
Svetoslav1376d602014-03-13 11:17:26 -0700960static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
961 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
962 status_t err = ctrl->clearLayerFrameStats();
963
964 if (err < 0 && err != NO_INIT) {
965 doThrowIAE(env);
966 }
967
968 // The other end is not ready, just report we failed.
969 if (err == NO_INIT) {
970 return JNI_FALSE;
971 }
972
973 return JNI_TRUE;
974}
975
976static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
977 jobject outStats) {
978 FrameStats stats;
979
980 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
981 status_t err = ctrl->getLayerFrameStats(&stats);
982 if (err < 0 && err != NO_INIT) {
983 doThrowIAE(env);
984 }
985
986 // The other end is not ready, fine just return empty stats.
987 if (err == NO_INIT) {
988 return JNI_FALSE;
989 }
990
991 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
992 size_t frameCount = stats.desiredPresentTimesNano.size();
993
994 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
995 if (postedTimesNanoDst == NULL) {
996 return JNI_FALSE;
997 }
998
999 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1000 if (presentedTimesNanoDst == NULL) {
1001 return JNI_FALSE;
1002 }
1003
1004 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
1005 if (readyTimesNanoDst == NULL) {
1006 return JNI_FALSE;
1007 }
1008
1009 nsecs_t postedTimesNanoSrc[frameCount];
1010 nsecs_t presentedTimesNanoSrc[frameCount];
1011 nsecs_t readyTimesNanoSrc[frameCount];
1012
1013 for (size_t i = 0; i < frameCount; i++) {
1014 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
1015 if (postedTimeNano == INT64_MAX) {
1016 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1017 }
1018 postedTimesNanoSrc[i] = postedTimeNano;
1019
1020 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1021 if (presentedTimeNano == INT64_MAX) {
1022 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1023 }
1024 presentedTimesNanoSrc[i] = presentedTimeNano;
1025
1026 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
1027 if (readyTimeNano == INT64_MAX) {
1028 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1029 }
1030 readyTimesNanoSrc[i] = readyTimeNano;
1031 }
1032
1033 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
1034 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1035 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
1036
1037 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
1038 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
1039
1040 if (env->ExceptionCheck()) {
1041 return JNI_FALSE;
1042 }
1043
1044 return JNI_TRUE;
1045}
1046
1047static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
1048 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
1049
1050 if (err < 0 && err != NO_INIT) {
1051 doThrowIAE(env);
1052 }
1053
1054 // The other end is not ready, just report we failed.
1055 if (err == NO_INIT) {
1056 return JNI_FALSE;
1057 }
1058
1059 return JNI_TRUE;
1060}
1061
1062static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
1063 FrameStats stats;
1064
1065 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1066 if (err < 0 && err != NO_INIT) {
1067 doThrowIAE(env);
1068 }
1069
1070 // The other end is not ready, fine just return empty stats.
1071 if (err == NO_INIT) {
1072 return JNI_FALSE;
1073 }
1074
1075 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1076 size_t frameCount = stats.desiredPresentTimesNano.size();
1077
1078 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1079 if (presentedTimesNanoDst == NULL) {
1080 return JNI_FALSE;
1081 }
1082
1083 nsecs_t presentedTimesNanoSrc[frameCount];
1084
1085 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -07001086 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -07001087 if (presentedTimeNano == INT64_MAX) {
1088 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1089 }
1090 presentedTimesNanoSrc[i] = presentedTimeNano;
1091 }
1092
1093 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1094
1095 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1096 presentedTimesNanoDst);
1097
1098 if (env->ExceptionCheck()) {
1099 return JNI_FALSE;
1100 }
1101
1102 return JNI_TRUE;
1103}
1104
Robert Carre13b58e2017-08-31 14:50:44 -07001105static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
1106 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +00001107 jobject handleObject, jlong frameNumber) {
1108 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1109 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
1110
Robert Carre13b58e2017-08-31 14:50:44 -07001111 {
1112 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001113 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -07001114 }
Rob Carr64e516f2015-10-29 00:20:45 +00001115}
1116
Robert Carre13b58e2017-08-31 14:50:44 -07001117static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1118 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001119 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001120 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1121
Robert Carrd5c7dd62017-03-08 10:39:30 -08001122 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1123 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1124
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001125 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001126}
1127
Robert Carre13b58e2017-08-31 14:50:44 -07001128static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1129 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001130 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001131
Robert Carrd5c7dd62017-03-08 10:39:30 -08001132 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1133 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
1134
Robert Carre13b58e2017-08-31 14:50:44 -07001135 {
1136 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1137 transaction->reparentChildren(ctrl, handle);
1138 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001139}
1140
Robert Carre13b58e2017-08-31 14:50:44 -07001141static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1142 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001143 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001144 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001145 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001146
1147 {
1148 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -08001149 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -07001150 }
chaviw63542382017-08-17 17:39:29 -07001151}
1152
Robert Carre13b58e2017-08-31 14:50:44 -07001153static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1154 jlong nativeObject) {
1155 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1156
Robert Carrd5c7dd62017-03-08 10:39:30 -08001157 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001158 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001159}
1160
Robert Carre13b58e2017-08-31 14:50:44 -07001161static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1162 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001163 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001164 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001165
Robert Carre13b58e2017-08-31 14:50:44 -07001166 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1167 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001168}
1169
Rob Carr64e516f2015-10-29 00:20:45 +00001170static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
1171 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +00001172 return javaObjectForIBinder(env, ctrl->getHandle());
1173}
1174
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001175static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1176 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1177 if (token == NULL) return NULL;
1178
1179 HdrCapabilities capabilities;
1180 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1181
1182 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001183 std::vector<int32_t> intTypes;
1184 for (auto type : types) {
1185 intTypes.push_back(static_cast<int32_t>(type));
1186 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001187 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001188 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001189
Michael Wright9ff94c02016-03-30 18:05:40 -07001190 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001191 typesArray, capabilities.getDesiredMaxLuminance(),
1192 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1193}
1194
Jorim Jaggi06975df2017-12-01 14:52:13 +01001195static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1196 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1197 if (parcel == NULL) {
1198 doThrowNPE(env);
1199 return 0;
1200 }
1201 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1202 if (surface == nullptr) {
1203 return 0;
1204 }
1205 surface->incStrong((void *)nativeCreate);
1206 return reinterpret_cast<jlong>(surface.get());
1207}
1208
chaviwbeb7a0c2018-12-05 13:49:54 -08001209static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1210 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1211 if (surface == nullptr) {
1212 return 0;
1213 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001214
1215 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1216 newSurface->incStrong((void *)nativeCreate);
1217 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001218}
1219
Jorim Jaggi06975df2017-12-01 14:52:13 +01001220static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1221 jlong nativeObject, jobject parcelObj) {
1222 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1223 if (parcel == NULL) {
1224 doThrowNPE(env);
1225 return;
1226 }
1227 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001228 if (self != nullptr) {
1229 self->writeToParcel(parcel);
1230 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001231}
1232
Dan Gittik832b4972019-02-13 18:17:47 +00001233static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1234 jobject displayTokenObject) {
1235 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1236 if (displayToken == nullptr) {
1237 return JNI_FALSE;
1238 }
1239 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1240}
1241
1242static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1243 jfloat brightness) {
1244 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1245 if (displayToken == nullptr) {
1246 return JNI_FALSE;
1247 }
1248 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1249 return error == OK ? JNI_TRUE : JNI_FALSE;
1250}
1251
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001252// ----------------------------------------------------------------------------
1253
Daniel Micay76f6a862015-09-19 17:31:01 -04001254static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001255 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001256 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001257 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1258 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001259 {"nativeCopyFromSurfaceControl", "(J)J" ,
1260 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001261 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1262 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001263 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001264 (void*)nativeRelease },
Chong Zhang47e36a32016-02-29 16:44:33 -08001265 {"nativeDisconnect", "(J)V",
1266 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001267 {"nativeCreateTransaction", "()J",
1268 (void*)nativeCreateTransaction },
1269 {"nativeApplyTransaction", "(JZ)V",
1270 (void*)nativeApplyTransaction },
1271 {"nativeGetNativeTransactionFinalizer", "()J",
1272 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001273 {"nativeMergeTransaction", "(JJ)V",
1274 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001275 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001276 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001277 {"nativeSetEarlyWakeup", "(J)V",
1278 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001279 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001280 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001281 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -07001282 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001283 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001284 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001285 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -07001286 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -07001287 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001288 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001289 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001290 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001291 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001292 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001293 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001294 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001295 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001296 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001297 {"nativeSetColorTransform", "(JJ[F[F)V",
1298 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001299 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1300 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001301 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001302 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001303 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001304 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001305 {"nativeSetCornerRadius", "(JJF)V",
1306 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001307 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001308 (void*)nativeSetLayerStack },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001309 {"nativeGetPhysicalDisplayIds", "()[J",
1310 (void*)nativeGetPhysicalDisplayIds },
1311 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1312 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001313 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1314 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001315 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1316 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001317 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001318 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001319 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001320 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001321 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001322 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001323 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001324 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001325 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1326 (void*)nativeGetDisplayConfigs },
1327 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1328 (void*)nativeGetActiveConfig },
1329 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1330 (void*)nativeSetActiveConfig },
Ady Abraham6070ce12019-01-24 18:48:58 -08001331 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1332 (void*)nativeSetAllowedDisplayConfigs },
Ady Abraham42f9a2fb2019-02-26 14:13:39 -08001333 {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
1334 (void*)nativeGetAllowedDisplayConfigs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001335 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1336 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001337 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1338 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001339 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1340 (void*)nativeGetActiveColorMode},
1341 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1342 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001343 {"nativeGetCompositionDataspaces", "()[I",
1344 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001345 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1346 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001347 {"nativeClearContentFrameStats", "(J)Z",
1348 (void*)nativeClearContentFrameStats },
1349 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1350 (void*)nativeGetContentFrameStats },
1351 {"nativeClearAnimationFrameStats", "()Z",
1352 (void*)nativeClearAnimationFrameStats },
1353 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1354 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001355 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1356 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001357 {"nativeGetProtectedContentSupport", "()Z",
1358 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001359 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001360 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001361 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001362 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001363 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001364 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001365 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001366 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001367 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001368 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001369 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001370 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001371 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001372 (void*)nativeGetHandle },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001373 {"nativeScreenshot",
1374 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1375 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001376 (void*)nativeScreenshot },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001377 {"nativeCaptureLayers",
Peiyong Lin21e499a2019-04-03 16:37:46 -07001378 "(Landroid/os/IBinder;Landroid/os/IBinder;Landroid/graphics/Rect;"
1379 "F[Landroid/os/IBinder;)"
Peiyong Line3e5efd2019-03-21 20:59:47 +00001380 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001381 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001382 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001383 (void*)nativeSetInputWindowInfo },
1384 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1385 (void*)nativeTransferTouchFocus },
Evan Roskyb51e2462019-04-03 19:27:18 -07001386 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
Evan Rosky485df202018-12-06 14:11:12 -08001387 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001388 {"nativeGetDisplayedContentSamplingAttributes",
1389 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1390 (void*)nativeGetDisplayedContentSamplingAttributes },
1391 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1392 (void*)nativeSetDisplayedContentSamplingEnabled },
1393 {"nativeGetDisplayedContentSample",
1394 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1395 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001396 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001397 (void*)nativeSetGeometry },
1398 {"nativeSyncInputWindows", "(J)V",
Dan Gittik832b4972019-02-13 18:17:47 +00001399 (void*)nativeSyncInputWindows },
1400 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1401 (void*)nativeGetDisplayBrightnessSupport },
1402 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1403 (void*)nativeSetDisplayBrightness },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001404};
1405
1406int register_android_view_SurfaceControl(JNIEnv* env)
1407{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001408 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001409 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1410
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001411 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1412 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1413 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1414 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1415 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1416 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1417 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1418 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1419 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1420 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1421 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1422 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1423 clazz, "appVsyncOffsetNanos", "J");
1424 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1425 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001426
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001427 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1428 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1429 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1430 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1431 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001432
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001433 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1434 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1435 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001436 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1437
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001438 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1439 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1440 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001441 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1442
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001443 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1444 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1445 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001446 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1447
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001448 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1449 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1450 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1451 "([IFFF)V");
1452
Robert Carr6486d312017-01-09 19:48:29 -08001453 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1454 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1455 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1456 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1457
Peiyong Line3e5efd2019-03-21 20:59:47 +00001458 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1459 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1460 gScreenshotGraphicBufferClassInfo.clazz =
1461 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1462 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1463 screenshotGraphicsBufferClazz,
Robert Carr66b5664f2019-04-02 14:18:56 -07001464 "createFromNative", "(IIIIJIZ)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
Peiyong Line3e5efd2019-03-21 20:59:47 +00001465
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001466 jclass displayedContentSampleClazz = FindClassOrDie(env,
1467 "android/hardware/display/DisplayedContentSample");
1468 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1469 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1470 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1471
1472 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1473 "android/hardware/display/DisplayedContentSamplingAttributes");
1474 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1475 displayedContentSamplingAttributesClazz);
1476 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1477 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001478
1479 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1480 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1481 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1482 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1483 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1484 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1485
1486 jclass displayPrimariesClazz = FindClassOrDie(env,
1487 "android/view/SurfaceControl$DisplayPrimaries");
1488 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1489 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1490 "<init>", "()V");
1491 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1492 "Landroid/view/SurfaceControl$CieXyz;");
1493 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1494 "Landroid/view/SurfaceControl$CieXyz;");
1495 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1496 "Landroid/view/SurfaceControl$CieXyz;");
1497 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1498 "Landroid/view/SurfaceControl$CieXyz;");
1499
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001500 return err;
1501}
1502
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001503} // namespace android