blob: 1f010240d1b1b6a8f3e6227597fb52ba5faab6e5 [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
139 // ColorSpace.Named.DISPLAY_P3.ordinal() = 6;
140 static constexpr jint DISPLAY_P3 = 6;
141};
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
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000220static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800221 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Robert Carrcc6d4832019-02-04 15:41:12 -0800222 ctrl->destroy();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800223 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800224}
225
Chong Zhang47e36a32016-02-29 16:44:33 -0800226static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
227 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
228 if (ctrl != NULL) {
229 ctrl->disconnect();
230 }
231}
232
Robert Carr6486d312017-01-09 19:48:29 -0800233static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
234 int left = env->GetIntField(rectObj, gRectClassInfo.left);
235 int top = env->GetIntField(rectObj, gRectClassInfo.top);
236 int right = env->GetIntField(rectObj, gRectClassInfo.right);
237 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
238 return Rect(left, top, right, bottom);
239}
240
chaviw08520a02018-09-10 16:44:56 -0700241static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800242 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Robert Carr5c52b132019-02-15 15:48:11 -0800243 bool useIdentityTransform, int rotation, bool captureSecureLayers) {
Robert Carr6486d312017-01-09 19:48:29 -0800244 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
245 if (displayToken == NULL) {
246 return NULL;
247 }
Peiyong Line3e5efd2019-03-21 20:59:47 +0000248 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
249 const ui::Dataspace dataspace = pickDataspaceFromColorMode(colorMode);
250
Robert Carr6486d312017-01-09 19:48:29 -0800251 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800252 sp<GraphicBuffer> buffer;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000253 status_t res = ScreenshotClient::capture(displayToken, dataspace,
Robert Carr5c52b132019-02-15 15:48:11 -0800254 ui::PixelFormat::RGBA_8888,
255 sourceCrop, width, height,
256 useIdentityTransform, rotation, captureSecureLayers, &buffer);
Robert Carr6486d312017-01-09 19:48:29 -0800257 if (res != NO_ERROR) {
258 return NULL;
259 }
260
Peiyong Line3e5efd2019-03-21 20:59:47 +0000261 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
262 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
263 gScreenshotGraphicBufferClassInfo.builder,
Robert Carr6486d312017-01-09 19:48:29 -0800264 buffer->getWidth(),
265 buffer->getHeight(),
266 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700267 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000268 (jlong)buffer.get(),
269 namedColorSpace);
Robert Carr6486d312017-01-09 19:48:29 -0800270}
271
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000272static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
Robert Carrffcdc512019-04-02 11:51:11 -0700273 jobject sourceCropObj, jfloat frameScale, jobjectArray excludeArray) {
chaviwfbe47df2017-11-10 16:14:49 -0800274
275 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
276 if (layerHandle == NULL) {
277 return NULL;
278 }
279
280 Rect sourceCrop;
281 if (sourceCropObj != NULL) {
282 sourceCrop = rectFromObj(env, sourceCropObj);
283 }
284
Robert Carrffcdc512019-04-02 11:51:11 -0700285 std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
286 if (excludeArray != NULL) {
287 const jsize len = env->GetArrayLength(excludeArray);
288 excludeHandles.reserve(len);
289
290 for (jsize i = 0; i < len; i++) {
291 jobject obj = env->GetObjectArrayElement(excludeArray, i);
292 if (obj == nullptr) {
293 jniThrowNullPointerException(env, "Exclude layer is null");
294 return NULL;
295 }
296 sp<IBinder> excludeHandle = ibinderForJavaObject(env, obj);
297 excludeHandles.emplace(excludeHandle);
298 }
299 }
300
chaviwfbe47df2017-11-10 16:14:49 -0800301 sp<GraphicBuffer> buffer;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000302 const ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
303 status_t res = ScreenshotClient::captureChildLayers(layerHandle, dataspace,
Peiyong Lin10a34d12018-09-19 13:56:12 -0700304 ui::PixelFormat::RGBA_8888, sourceCrop,
Robert Carrffcdc512019-04-02 11:51:11 -0700305 excludeHandles, frameScale, &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800306 if (res != NO_ERROR) {
307 return NULL;
308 }
309
Peiyong Line3e5efd2019-03-21 20:59:47 +0000310 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
311 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
312 gScreenshotGraphicBufferClassInfo.builder,
chaviwfbe47df2017-11-10 16:14:49 -0800313 buffer->getWidth(),
314 buffer->getHeight(),
315 buffer->getPixelFormat(),
316 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000317 (jlong)buffer.get(),
318 namedColorSpace);
chaviw1cda84c2017-10-23 16:47:10 -0700319}
320
Robert Carre13b58e2017-08-31 14:50:44 -0700321static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
322 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
323 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800324}
325
Robert Carrb1579c82017-09-05 14:54:47 -0700326static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
327 jlong transactionObj, jlong otherTransactionObj) {
328 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
329 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
330 otherTransactionObj);
331 transaction->merge(std::move(*otherTransaction));
332}
333
Robert Carre13b58e2017-08-31 14:50:44 -0700334static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
335 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
336 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800337}
338
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100339static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
340 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
341 transaction->setEarlyWakeup();
342}
343
Robert Carre13b58e2017-08-31 14:50:44 -0700344static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
345 jlong nativeObject, jint zorder) {
346 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800347
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800348 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700349 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800350}
351
Robert Carre13b58e2017-08-31 14:50:44 -0700352static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
353 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700354 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700355
Robert Carraf422a82017-04-10 18:34:33 -0700356 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
357 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
358
Robert Carre13b58e2017-08-31 14:50:44 -0700359 {
360 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
361 transaction->setRelativeLayer(ctrl, handle, zorder);
362 }
Robert Carraf422a82017-04-10 18:34:33 -0700363}
364
Robert Carre13b58e2017-08-31 14:50:44 -0700365static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
366 jlong nativeObject, jfloat x, jfloat y) {
367 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
368
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800369 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700370 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800371}
372
Robert Carr76907ee2019-01-11 13:38:19 -0800373static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
374 jobject sourceObj, jobject dstObj, jlong orientation) {
375 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
376 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
377
378 Rect source, dst;
379 if (sourceObj != NULL) {
380 source = rectFromObj(env, sourceObj);
Robert Carrced6f852019-04-08 16:58:49 -0700381 } else {
382 source.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800383 }
384 if (dstObj != NULL) {
385 dst = rectFromObj(env, dstObj);
Robert Carrced6f852019-04-08 16:58:49 -0700386 } else {
387 dst.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800388 }
389 transaction->setGeometry(ctrl, source, dst, orientation);
390}
391
Robert Carr6da3cc02016-06-16 15:17:07 -0700392static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700393jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700394 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700395 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
396
Robert Carra9408d42016-06-03 13:28:48 -0700397 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700398 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700399}
400
Robert Carre13b58e2017-08-31 14:50:44 -0700401static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
402 jlong nativeObject, jint w, jint h) {
403 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
404
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800405 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700406 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800407}
408
Robert Carre13b58e2017-08-31 14:50:44 -0700409static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
410 jlong nativeObject, jint flags, jint mask) {
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->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800415}
416
Robert Carre13b58e2017-08-31 14:50:44 -0700417static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
418 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800419 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
420 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
421 if (!region) {
422 doThrowIAE(env);
423 return;
424 }
425
426 const SkIRect& b(region->getBounds());
427 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
428 if (region->isComplex()) {
429 SkRegion::Iterator it(*region);
430 while (!it.done()) {
431 const SkIRect& r(it.rect());
432 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
433 it.next();
434 }
435 }
436
Robert Carre13b58e2017-08-31 14:50:44 -0700437 {
438 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
439 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800440 }
441}
442
Robert Carre13b58e2017-08-31 14:50:44 -0700443static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
444 jlong nativeObject, jfloat alpha) {
445 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
446
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800447 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700448 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800449}
450
Robert Carr788f5742018-07-30 17:46:45 -0700451static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
452 jlong nativeObject, jobject inputWindow) {
453 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
454
Riddle Hsucd958bc2019-01-23 15:40:26 +0800455 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700456 env, inputWindow);
457 handle->updateInfo();
458
459 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
460 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
461}
462
chaviw59f532e2018-12-26 15:34:59 -0800463static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
464 jobject fromTokenObj, jobject toTokenObj) {
465 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
466
467 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
468 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
469 transaction->transferTouchFocus(fromToken, toToken);
470}
471
chaviw319cd0782019-02-14 11:00:23 -0800472static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
473 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
474 transaction->syncInputWindows();
475}
476
Evan Rosky485df202018-12-06 14:11:12 -0800477static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
478 jlong nativeObject, jint id, jobject parcelObj) {
479 Parcel* parcel = parcelForJavaObject(env, parcelObj);
480 if (!parcel) {
481 jniThrowNullPointerException(env, "attribute data");
482 return;
483 }
484 if (parcel->objectsCount()) {
485 jniThrowException(env, "java/lang/RuntimeException",
486 "Tried to marshall a Parcel that contained Binder objects.");
487 return;
488 }
489
490 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
491
492 std::vector<uint8_t> byteData(parcel->dataSize());
493 memcpy(byteData.data(), parcel->data(), parcel->dataSize());
494
495 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
496 transaction->setMetadata(ctrl, id, std::move(byteData));
497}
498
Robert Carre13b58e2017-08-31 14:50:44 -0700499static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
500 jlong nativeObject, jfloatArray fColor) {
501 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700502 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700503
chaviw0dd03f52017-08-25 12:15:26 -0700504 float* floatColors = env->GetFloatArrayElements(fColor, 0);
505 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700506 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700507}
508
Robert Carre13b58e2017-08-31 14:50:44 -0700509static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
510 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800511 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700512 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
513
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800514 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700515 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800516}
517
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700518static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
519 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
520 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
521 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
522 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
523 mat3 matrix(static_cast<float const*>(floatMatrix));
524 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
525 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
526 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
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800562static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
563 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
564 jlongArray array = env->NewLongArray(displayIds.size());
565 if (array == nullptr) {
566 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
567 return nullptr;
568 }
569
570 if (displayIds.empty()) {
571 return array;
572 }
573
574 jlong* values = env->GetLongArrayElements(array, 0);
575 for (size_t i = 0; i < displayIds.size(); ++i) {
576 values[i] = static_cast<jlong>(displayIds[i]);
577 }
578
579 env->ReleaseLongArrayElements(array, values, 0);
580 return array;
581}
582
583static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
584 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800585 return javaObjectForIBinder(env, token);
586}
587
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700588static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
589 jobject tokenObj) {
590 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
591
592 ui::PixelFormat format;
593 ui::Dataspace dataspace;
594 uint8_t componentMask;
595 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
596 token, &format, &dataspace, &componentMask);
597 if (err != OK) {
598 return nullptr;
599 }
600 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
601 gDisplayedContentSamplingAttributesClassInfo.ctor,
602 format, dataspace, componentMask);
603}
604
605static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
606 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
607 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800608 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700609 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800610 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700611}
612
613static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
614 jlong maxFrames, jlong timestamp) {
615 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
616
617 DisplayedFrameStats stats;
618 status_t err = SurfaceComposerClient::getDisplayedContentSample(
619 token, maxFrames, timestamp, &stats);
620 if (err != OK) {
621 return nullptr;
622 }
623
624 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
625 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
626 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
627 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
628 if ((histogramComponent0 == nullptr) ||
629 (histogramComponent1 == nullptr) ||
630 (histogramComponent2 == nullptr) ||
631 (histogramComponent3 == nullptr)) {
632 return JNI_FALSE;
633 }
634
635 env->SetLongArrayRegion(histogramComponent0, 0,
636 stats.component_0_sample.size(),
637 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
638 env->SetLongArrayRegion(histogramComponent1, 0,
639 stats.component_1_sample.size(),
640 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
641 env->SetLongArrayRegion(histogramComponent2, 0,
642 stats.component_2_sample.size(),
643 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
644 env->SetLongArrayRegion(histogramComponent3, 0,
645 stats.component_3_sample.size(),
646 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
647 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
648 gDisplayedContentSampleClassInfo.ctor,
649 stats.numFrames,
650 histogramComponent0,
651 histogramComponent1,
652 histogramComponent2,
653 histogramComponent3);
654}
655
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800656static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
657 jboolean secure) {
658 ScopedUtfChars name(env, nameObj);
659 sp<IBinder> token(SurfaceComposerClient::createDisplay(
660 String8(name.c_str()), bool(secure)));
661 return javaObjectForIBinder(env, token);
662}
663
Jesse Hall6a6bc212013-08-08 12:15:03 -0700664static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
665 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
666 if (token == NULL) return;
667 SurfaceComposerClient::destroyDisplay(token);
668}
669
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800670static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700671 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000672 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800673 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
674 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800675 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800676 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800677 if (sur != NULL) {
678 bufferProducer = sur->getIGraphicBufferProducer();
679 }
Robert Carre13b58e2017-08-31 14:50:44 -0700680
681
682 status_t err = NO_ERROR;
683 {
684 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
685 err = transaction->setDisplaySurface(token,
686 bufferProducer);
687 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700688 if (err != NO_ERROR) {
689 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
690 " Surface created with singleBufferMode?");
691 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800692}
693
694static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700695 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800696 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700697
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800698 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
699 if (token == NULL) return;
700
Robert Carre13b58e2017-08-31 14:50:44 -0700701 {
702 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
703 transaction->setDisplayLayerStack(token, layerStack);
704 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800705}
706
707static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700708 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800709 jobject tokenObj, jint orientation,
710 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
711 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
712 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
713 if (token == NULL) return;
714 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
715 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700716
717 {
718 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
719 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
720 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800721}
722
Michael Wright01e840f2014-06-26 16:03:25 -0700723static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700724 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700725 jobject tokenObj, jint width, jint height) {
726 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
727 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700728
729 {
730 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
731 transaction->setDisplaySize(token, width, height);
732 }
Michael Wright01e840f2014-06-26 16:03:25 -0700733}
734
Dan Stoza00101052014-05-02 15:23:40 -0700735static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
736 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800737 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700738 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800739
Dan Stoza00101052014-05-02 15:23:40 -0700740 Vector<DisplayInfo> configs;
741 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
742 configs.size() == 0) {
743 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800744 }
745
Dan Stoza00101052014-05-02 15:23:40 -0700746 jobjectArray configArray = env->NewObjectArray(configs.size(),
747 gPhysicalDisplayInfoClassInfo.clazz, NULL);
748
749 for (size_t c = 0; c < configs.size(); ++c) {
750 const DisplayInfo& info = configs[c];
751 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
752 gPhysicalDisplayInfoClassInfo.ctor);
753 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
754 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
755 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
756 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
757 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
758 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
759 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700760 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
761 info.appVsyncOffset);
762 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
763 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700764 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
765 env->DeleteLocalRef(infoObj);
766 }
767
768 return configArray;
769}
770
Ady Abraham6070ce12019-01-24 18:48:58 -0800771static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
772 jobject tokenObj, jintArray configArray) {
773 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
774 if (token == nullptr) return JNI_FALSE;
775
776 std::vector<int32_t> allowedConfigs;
777 jsize configArraySize = env->GetArrayLength(configArray);
778 allowedConfigs.reserve(configArraySize);
779
780 jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
781 for (int i = 0; i < configArraySize; i++) {
782 allowedConfigs.push_back(configArrayElements[i]);
783 }
784 env->ReleaseIntArrayElements(configArray, configArrayElements, 0);
785
786 size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
787 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
788}
789
Ady Abraham42f9a2fb2019-02-26 14:13:39 -0800790static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
791 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
792 if (token == nullptr) return JNI_FALSE;
793
794 std::vector<int32_t> allowedConfigs;
795 size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs);
796 if (result != NO_ERROR) {
797 return nullptr;
798 }
799
800 jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size());
801 if (allowedConfigsArray == nullptr) {
802 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
803 return nullptr;
804 }
805 jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0);
806 for (size_t i = 0; i < allowedConfigs.size(); i++) {
807 allowedConfigsArrayValues[i] = static_cast<jint>(allowedConfigs[i]);
808 }
809 env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0);
810 return allowedConfigsArray;
811}
812
Dan Stoza00101052014-05-02 15:23:40 -0700813static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
814 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
815 if (token == NULL) return -1;
816 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
817}
818
819static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
820 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
821 if (token == NULL) return JNI_FALSE;
822 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
823 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800824}
825
Michael Wright1c9977b2016-07-12 13:30:10 -0700826static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
827 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
828 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700829 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700830 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
831 colorModes.isEmpty()) {
832 return NULL;
833 }
834
835 jintArray colorModesArray = env->NewIntArray(colorModes.size());
836 if (colorModesArray == NULL) {
837 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
838 return NULL;
839 }
840 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
841 for (size_t i = 0; i < colorModes.size(); i++) {
842 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
843 }
844 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
845 return colorModesArray;
846}
847
Daniel Solomon10e3b332019-01-20 21:09:11 -0800848static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
849 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
850 if (token == NULL) return NULL;
851
852 ui::DisplayPrimaries primaries;
853 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
854 return NULL;
855 }
856
857 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
858 if (jred == NULL) {
859 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
860 return NULL;
861 }
862
863 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
864 if (jgreen == NULL) {
865 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
866 return NULL;
867 }
868
869 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
870 if (jblue == NULL) {
871 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
872 return NULL;
873 }
874
875 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
876 if (jwhite == NULL) {
877 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
878 return NULL;
879 }
880
881 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
882 gDisplayPrimariesClassInfo.ctor);
883 if (jprimaries == NULL) {
884 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
885 return NULL;
886 }
887
888 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
889 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
890 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
891 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
892 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
893 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
894 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
895 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
896 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
897 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
898 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
899 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
900 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
901 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
902 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
903 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
904
905 return jprimaries;
906}
907
Michael Wright1c9977b2016-07-12 13:30:10 -0700908static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
909 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
910 if (token == NULL) return -1;
911 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
912}
913
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800914static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
915 ui::Dataspace defaultDataspace, wcgDataspace;
916 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
917 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
918 &defaultPixelFormat,
919 &wcgDataspace,
920 &wcgPixelFormat) != NO_ERROR) {
921 return nullptr;
922 }
923 jintArray array = env->NewIntArray(2);
924 if (array == nullptr) {
925 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
926 return nullptr;
927 }
928 jint* arrayValues = env->GetIntArrayElements(array, 0);
929 arrayValues[0] = static_cast<jint>(defaultDataspace);
930 arrayValues[1] = static_cast<jint>(wcgDataspace);
931 env->ReleaseIntArrayElements(array, arrayValues, 0);
932 return array;
933}
934
Michael Wright1c9977b2016-07-12 13:30:10 -0700935static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
936 jobject tokenObj, jint colorMode) {
937 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
938 if (token == NULL) return JNI_FALSE;
939 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700940 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700941 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
942}
943
Prashant Malanic55929a2014-05-25 01:59:21 -0700944static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800945 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
946 if (token == NULL) return;
947
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700948 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700949 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700950 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800951}
952
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800953static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
954 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
955}
956
Svetoslav1376d602014-03-13 11:17:26 -0700957static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
958 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
959 status_t err = ctrl->clearLayerFrameStats();
960
961 if (err < 0 && err != NO_INIT) {
962 doThrowIAE(env);
963 }
964
965 // The other end is not ready, just report we failed.
966 if (err == NO_INIT) {
967 return JNI_FALSE;
968 }
969
970 return JNI_TRUE;
971}
972
973static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
974 jobject outStats) {
975 FrameStats stats;
976
977 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
978 status_t err = ctrl->getLayerFrameStats(&stats);
979 if (err < 0 && err != NO_INIT) {
980 doThrowIAE(env);
981 }
982
983 // The other end is not ready, fine just return empty stats.
984 if (err == NO_INIT) {
985 return JNI_FALSE;
986 }
987
988 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
989 size_t frameCount = stats.desiredPresentTimesNano.size();
990
991 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
992 if (postedTimesNanoDst == NULL) {
993 return JNI_FALSE;
994 }
995
996 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
997 if (presentedTimesNanoDst == NULL) {
998 return JNI_FALSE;
999 }
1000
1001 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
1002 if (readyTimesNanoDst == NULL) {
1003 return JNI_FALSE;
1004 }
1005
1006 nsecs_t postedTimesNanoSrc[frameCount];
1007 nsecs_t presentedTimesNanoSrc[frameCount];
1008 nsecs_t readyTimesNanoSrc[frameCount];
1009
1010 for (size_t i = 0; i < frameCount; i++) {
1011 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
1012 if (postedTimeNano == INT64_MAX) {
1013 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1014 }
1015 postedTimesNanoSrc[i] = postedTimeNano;
1016
1017 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1018 if (presentedTimeNano == INT64_MAX) {
1019 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1020 }
1021 presentedTimesNanoSrc[i] = presentedTimeNano;
1022
1023 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
1024 if (readyTimeNano == INT64_MAX) {
1025 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1026 }
1027 readyTimesNanoSrc[i] = readyTimeNano;
1028 }
1029
1030 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
1031 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1032 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
1033
1034 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
1035 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
1036
1037 if (env->ExceptionCheck()) {
1038 return JNI_FALSE;
1039 }
1040
1041 return JNI_TRUE;
1042}
1043
1044static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
1045 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
1046
1047 if (err < 0 && err != NO_INIT) {
1048 doThrowIAE(env);
1049 }
1050
1051 // The other end is not ready, just report we failed.
1052 if (err == NO_INIT) {
1053 return JNI_FALSE;
1054 }
1055
1056 return JNI_TRUE;
1057}
1058
1059static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
1060 FrameStats stats;
1061
1062 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1063 if (err < 0 && err != NO_INIT) {
1064 doThrowIAE(env);
1065 }
1066
1067 // The other end is not ready, fine just return empty stats.
1068 if (err == NO_INIT) {
1069 return JNI_FALSE;
1070 }
1071
1072 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1073 size_t frameCount = stats.desiredPresentTimesNano.size();
1074
1075 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1076 if (presentedTimesNanoDst == NULL) {
1077 return JNI_FALSE;
1078 }
1079
1080 nsecs_t presentedTimesNanoSrc[frameCount];
1081
1082 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -07001083 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -07001084 if (presentedTimeNano == INT64_MAX) {
1085 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1086 }
1087 presentedTimesNanoSrc[i] = presentedTimeNano;
1088 }
1089
1090 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1091
1092 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1093 presentedTimesNanoDst);
1094
1095 if (env->ExceptionCheck()) {
1096 return JNI_FALSE;
1097 }
1098
1099 return JNI_TRUE;
1100}
1101
Robert Carre13b58e2017-08-31 14:50:44 -07001102static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
1103 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +00001104 jobject handleObject, jlong frameNumber) {
1105 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1106 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
1107
Robert Carre13b58e2017-08-31 14:50:44 -07001108 {
1109 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001110 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -07001111 }
Rob Carr64e516f2015-10-29 00:20:45 +00001112}
1113
Robert Carre13b58e2017-08-31 14:50:44 -07001114static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1115 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001116 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001117 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1118
Robert Carrd5c7dd62017-03-08 10:39:30 -08001119 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1120 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1121
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001122 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001123}
1124
Robert Carre13b58e2017-08-31 14:50:44 -07001125static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1126 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001127 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001128
Robert Carrd5c7dd62017-03-08 10:39:30 -08001129 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1130 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
1131
Robert Carre13b58e2017-08-31 14:50:44 -07001132 {
1133 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1134 transaction->reparentChildren(ctrl, handle);
1135 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001136}
1137
Robert Carre13b58e2017-08-31 14:50:44 -07001138static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1139 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001140 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001141 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001142 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001143
1144 {
1145 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -08001146 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -07001147 }
chaviw63542382017-08-17 17:39:29 -07001148}
1149
Robert Carre13b58e2017-08-31 14:50:44 -07001150static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1151 jlong nativeObject) {
1152 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1153
Robert Carrd5c7dd62017-03-08 10:39:30 -08001154 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001155 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001156}
1157
Robert Carre13b58e2017-08-31 14:50:44 -07001158static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1159 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001160 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001161 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001162
Robert Carre13b58e2017-08-31 14:50:44 -07001163 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1164 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001165}
1166
Rob Carr64e516f2015-10-29 00:20:45 +00001167static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
1168 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +00001169 return javaObjectForIBinder(env, ctrl->getHandle());
1170}
1171
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001172static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1173 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1174 if (token == NULL) return NULL;
1175
1176 HdrCapabilities capabilities;
1177 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1178
1179 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001180 std::vector<int32_t> intTypes;
1181 for (auto type : types) {
1182 intTypes.push_back(static_cast<int32_t>(type));
1183 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001184 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001185 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001186
Michael Wright9ff94c02016-03-30 18:05:40 -07001187 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001188 typesArray, capabilities.getDesiredMaxLuminance(),
1189 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1190}
1191
Jorim Jaggi06975df2017-12-01 14:52:13 +01001192static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1193 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1194 if (parcel == NULL) {
1195 doThrowNPE(env);
1196 return 0;
1197 }
1198 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1199 if (surface == nullptr) {
1200 return 0;
1201 }
1202 surface->incStrong((void *)nativeCreate);
1203 return reinterpret_cast<jlong>(surface.get());
1204}
1205
chaviwbeb7a0c2018-12-05 13:49:54 -08001206static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1207 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1208 if (surface == nullptr) {
1209 return 0;
1210 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001211
1212 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1213 newSurface->incStrong((void *)nativeCreate);
1214 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001215}
1216
Jorim Jaggi06975df2017-12-01 14:52:13 +01001217static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1218 jlong nativeObject, jobject parcelObj) {
1219 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1220 if (parcel == NULL) {
1221 doThrowNPE(env);
1222 return;
1223 }
1224 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001225 if (self != nullptr) {
1226 self->writeToParcel(parcel);
1227 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001228}
1229
Dan Gittik832b4972019-02-13 18:17:47 +00001230static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1231 jobject displayTokenObject) {
1232 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1233 if (displayToken == nullptr) {
1234 return JNI_FALSE;
1235 }
1236 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1237}
1238
1239static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1240 jfloat brightness) {
1241 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1242 if (displayToken == nullptr) {
1243 return JNI_FALSE;
1244 }
1245 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1246 return error == OK ? JNI_TRUE : JNI_FALSE;
1247}
1248
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001249// ----------------------------------------------------------------------------
1250
Daniel Micay76f6a862015-09-19 17:31:01 -04001251static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001252 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001253 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001254 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1255 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001256 {"nativeCopyFromSurfaceControl", "(J)J" ,
1257 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001258 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1259 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001260 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001261 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001262 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001263 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -08001264 {"nativeDisconnect", "(J)V",
1265 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001266 {"nativeCreateTransaction", "()J",
1267 (void*)nativeCreateTransaction },
1268 {"nativeApplyTransaction", "(JZ)V",
1269 (void*)nativeApplyTransaction },
1270 {"nativeGetNativeTransactionFinalizer", "()J",
1271 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001272 {"nativeMergeTransaction", "(JJ)V",
1273 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001274 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001275 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001276 {"nativeSetEarlyWakeup", "(J)V",
1277 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001278 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001279 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001280 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -07001281 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001282 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001283 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001284 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -07001285 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -07001286 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001287 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001288 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001289 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001290 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001291 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001292 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001293 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001294 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001295 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001296 {"nativeSetColorTransform", "(JJ[F[F)V",
1297 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001298 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1299 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001300 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001301 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001302 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001303 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001304 {"nativeSetCornerRadius", "(JJF)V",
1305 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001306 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001307 (void*)nativeSetLayerStack },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001308 {"nativeGetPhysicalDisplayIds", "()[J",
1309 (void*)nativeGetPhysicalDisplayIds },
1310 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1311 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001312 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1313 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001314 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1315 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001316 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001317 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001318 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001319 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001320 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001321 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001322 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001323 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001324 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1325 (void*)nativeGetDisplayConfigs },
1326 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1327 (void*)nativeGetActiveConfig },
1328 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1329 (void*)nativeSetActiveConfig },
Ady Abraham6070ce12019-01-24 18:48:58 -08001330 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1331 (void*)nativeSetAllowedDisplayConfigs },
Ady Abraham42f9a2fb2019-02-26 14:13:39 -08001332 {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
1333 (void*)nativeGetAllowedDisplayConfigs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001334 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1335 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001336 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1337 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001338 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1339 (void*)nativeGetActiveColorMode},
1340 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1341 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001342 {"nativeGetCompositionDataspaces", "()[I",
1343 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001344 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1345 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001346 {"nativeClearContentFrameStats", "(J)Z",
1347 (void*)nativeClearContentFrameStats },
1348 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1349 (void*)nativeGetContentFrameStats },
1350 {"nativeClearAnimationFrameStats", "()Z",
1351 (void*)nativeClearAnimationFrameStats },
1352 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1353 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001354 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1355 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001356 {"nativeGetProtectedContentSupport", "()Z",
1357 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001358 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001359 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001360 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001361 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001362 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001363 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001364 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001365 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001366 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001367 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001368 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001369 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001370 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001371 (void*)nativeGetHandle },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001372 {"nativeScreenshot",
1373 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1374 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001375 (void*)nativeScreenshot },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001376 {"nativeCaptureLayers",
Robert Carrffcdc512019-04-02 11:51:11 -07001377 "(Landroid/os/IBinder;Landroid/graphics/Rect;F[Landroid/os/IBinder;)"
Peiyong Line3e5efd2019-03-21 20:59:47 +00001378 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001379 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001380 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001381 (void*)nativeSetInputWindowInfo },
1382 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1383 (void*)nativeTransferTouchFocus },
Evan Roskyb51e2462019-04-03 19:27:18 -07001384 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
Evan Rosky485df202018-12-06 14:11:12 -08001385 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001386 {"nativeGetDisplayedContentSamplingAttributes",
1387 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1388 (void*)nativeGetDisplayedContentSamplingAttributes },
1389 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1390 (void*)nativeSetDisplayedContentSamplingEnabled },
1391 {"nativeGetDisplayedContentSample",
1392 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1393 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001394 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001395 (void*)nativeSetGeometry },
1396 {"nativeSyncInputWindows", "(J)V",
Dan Gittik832b4972019-02-13 18:17:47 +00001397 (void*)nativeSyncInputWindows },
1398 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1399 (void*)nativeGetDisplayBrightnessSupport },
1400 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1401 (void*)nativeSetDisplayBrightness },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001402};
1403
1404int register_android_view_SurfaceControl(JNIEnv* env)
1405{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001406 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001407 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1408
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001409 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1410 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1411 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1412 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1413 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1414 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1415 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1416 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1417 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1418 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1419 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1420 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1421 clazz, "appVsyncOffsetNanos", "J");
1422 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1423 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001424
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001425 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1426 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1427 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1428 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1429 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001430
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001431 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1432 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1433 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001434 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1435
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001436 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1437 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1438 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001439 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1440
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001441 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1442 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1443 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001444 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1445
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001446 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1447 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1448 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1449 "([IFFF)V");
1450
Robert Carr6486d312017-01-09 19:48:29 -08001451 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1452 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1453 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1454 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1455
Peiyong Line3e5efd2019-03-21 20:59:47 +00001456 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1457 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1458 gScreenshotGraphicBufferClassInfo.clazz =
1459 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1460 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1461 screenshotGraphicsBufferClazz,
1462 "createFromNative", "(IIIIJI)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
1463
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001464 jclass displayedContentSampleClazz = FindClassOrDie(env,
1465 "android/hardware/display/DisplayedContentSample");
1466 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1467 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1468 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1469
1470 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1471 "android/hardware/display/DisplayedContentSamplingAttributes");
1472 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1473 displayedContentSamplingAttributesClazz);
1474 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1475 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001476
1477 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1478 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1479 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1480 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1481 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1482 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1483
1484 jclass displayPrimariesClazz = FindClassOrDie(env,
1485 "android/view/SurfaceControl$DisplayPrimaries");
1486 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1487 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1488 "<init>", "()V");
1489 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1490 "Landroid/view/SurfaceControl$CieXyz;");
1491 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1492 "Landroid/view/SurfaceControl$CieXyz;");
1493 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1494 "Landroid/view/SurfaceControl$CieXyz;");
1495 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1496 "Landroid/view/SurfaceControl$CieXyz;");
1497
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001498 return err;
1499}
1500
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001501} // namespace android