blob: 13bcbf6625e2e5293597d82ea2aa55d05aa7b0c1 [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;
Robert Carr66b5664f2019-04-02 14:18:56 -0700253 bool capturedSecureLayers = false;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000254 status_t res = ScreenshotClient::capture(displayToken, dataspace,
Robert Carr5c52b132019-02-15 15:48:11 -0800255 ui::PixelFormat::RGBA_8888,
256 sourceCrop, width, height,
Robert Carr66b5664f2019-04-02 14:18:56 -0700257 useIdentityTransform, rotation, captureSecureLayers, &buffer, capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800258 if (res != NO_ERROR) {
259 return NULL;
260 }
261
Peiyong Line3e5efd2019-03-21 20:59:47 +0000262 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
263 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
264 gScreenshotGraphicBufferClassInfo.builder,
Robert Carr6486d312017-01-09 19:48:29 -0800265 buffer->getWidth(),
266 buffer->getHeight(),
267 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700268 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000269 (jlong)buffer.get(),
Robert Carr66b5664f2019-04-02 14:18:56 -0700270 namedColorSpace,
271 capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800272}
273
Chavi Weingartend7ec64c2017-11-30 01:52:01 +0000274static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
Robert Carrffcdc512019-04-02 11:51:11 -0700275 jobject sourceCropObj, jfloat frameScale, jobjectArray excludeArray) {
chaviwfbe47df2017-11-10 16:14:49 -0800276
277 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
278 if (layerHandle == NULL) {
279 return NULL;
280 }
281
282 Rect sourceCrop;
283 if (sourceCropObj != NULL) {
284 sourceCrop = rectFromObj(env, sourceCropObj);
285 }
286
Robert Carrffcdc512019-04-02 11:51:11 -0700287 std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
288 if (excludeArray != NULL) {
289 const jsize len = env->GetArrayLength(excludeArray);
290 excludeHandles.reserve(len);
291
292 for (jsize i = 0; i < len; i++) {
293 jobject obj = env->GetObjectArrayElement(excludeArray, i);
294 if (obj == nullptr) {
295 jniThrowNullPointerException(env, "Exclude layer is null");
296 return NULL;
297 }
298 sp<IBinder> excludeHandle = ibinderForJavaObject(env, obj);
299 excludeHandles.emplace(excludeHandle);
300 }
301 }
302
chaviwfbe47df2017-11-10 16:14:49 -0800303 sp<GraphicBuffer> buffer;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000304 const ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
305 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(),
320 namedColorSpace);
chaviw1cda84c2017-10-23 16:47:10 -0700321}
322
Robert Carre13b58e2017-08-31 14:50:44 -0700323static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
324 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
325 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800326}
327
Robert Carrb1579c82017-09-05 14:54:47 -0700328static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
329 jlong transactionObj, jlong otherTransactionObj) {
330 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
331 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
332 otherTransactionObj);
333 transaction->merge(std::move(*otherTransaction));
334}
335
Robert Carre13b58e2017-08-31 14:50:44 -0700336static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
337 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
338 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800339}
340
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100341static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
342 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
343 transaction->setEarlyWakeup();
344}
345
Robert Carre13b58e2017-08-31 14:50:44 -0700346static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
347 jlong nativeObject, jint zorder) {
348 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800349
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800350 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700351 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800352}
353
Robert Carre13b58e2017-08-31 14:50:44 -0700354static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
355 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700356 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700357
Robert Carraf422a82017-04-10 18:34:33 -0700358 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
359 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
360
Robert Carre13b58e2017-08-31 14:50:44 -0700361 {
362 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
363 transaction->setRelativeLayer(ctrl, handle, zorder);
364 }
Robert Carraf422a82017-04-10 18:34:33 -0700365}
366
Robert Carre13b58e2017-08-31 14:50:44 -0700367static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
368 jlong nativeObject, jfloat x, jfloat y) {
369 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
370
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800371 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700372 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800373}
374
Robert Carr76907ee2019-01-11 13:38:19 -0800375static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
376 jobject sourceObj, jobject dstObj, jlong orientation) {
377 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
378 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
379
380 Rect source, dst;
381 if (sourceObj != NULL) {
382 source = rectFromObj(env, sourceObj);
383 }
384 if (dstObj != NULL) {
385 dst = rectFromObj(env, dstObj);
386 }
387 transaction->setGeometry(ctrl, source, dst, orientation);
388}
389
Robert Carr6da3cc02016-06-16 15:17:07 -0700390static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700391jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700392 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700393 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
394
Robert Carra9408d42016-06-03 13:28:48 -0700395 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700396 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700397}
398
Robert Carre13b58e2017-08-31 14:50:44 -0700399static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
400 jlong nativeObject, jint w, jint h) {
401 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
402
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800403 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700404 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800405}
406
Robert Carre13b58e2017-08-31 14:50:44 -0700407static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
408 jlong nativeObject, jint flags, jint mask) {
409 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
410
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800411 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700412 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800413}
414
Robert Carre13b58e2017-08-31 14:50:44 -0700415static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
416 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800417 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
418 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
419 if (!region) {
420 doThrowIAE(env);
421 return;
422 }
423
424 const SkIRect& b(region->getBounds());
425 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
426 if (region->isComplex()) {
427 SkRegion::Iterator it(*region);
428 while (!it.done()) {
429 const SkIRect& r(it.rect());
430 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
431 it.next();
432 }
433 }
434
Robert Carre13b58e2017-08-31 14:50:44 -0700435 {
436 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
437 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800438 }
439}
440
Robert Carre13b58e2017-08-31 14:50:44 -0700441static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
442 jlong nativeObject, jfloat alpha) {
443 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
444
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800445 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700446 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800447}
448
Robert Carr788f5742018-07-30 17:46:45 -0700449static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
450 jlong nativeObject, jobject inputWindow) {
451 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
452
Riddle Hsucd958bc2019-01-23 15:40:26 +0800453 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700454 env, inputWindow);
455 handle->updateInfo();
456
457 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
458 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
459}
460
chaviw59f532e2018-12-26 15:34:59 -0800461static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
462 jobject fromTokenObj, jobject toTokenObj) {
463 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
464
465 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
466 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
467 transaction->transferTouchFocus(fromToken, toToken);
468}
469
chaviw319cd0782019-02-14 11:00:23 -0800470static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
471 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
472 transaction->syncInputWindows();
473}
474
Evan Rosky485df202018-12-06 14:11:12 -0800475static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
476 jlong nativeObject, jint id, jobject parcelObj) {
477 Parcel* parcel = parcelForJavaObject(env, parcelObj);
478 if (!parcel) {
479 jniThrowNullPointerException(env, "attribute data");
480 return;
481 }
482 if (parcel->objectsCount()) {
483 jniThrowException(env, "java/lang/RuntimeException",
484 "Tried to marshall a Parcel that contained Binder objects.");
485 return;
486 }
487
488 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
489
490 std::vector<uint8_t> byteData(parcel->dataSize());
491 memcpy(byteData.data(), parcel->data(), parcel->dataSize());
492
493 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
494 transaction->setMetadata(ctrl, id, std::move(byteData));
495}
496
Robert Carre13b58e2017-08-31 14:50:44 -0700497static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
498 jlong nativeObject, jfloatArray fColor) {
499 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700500 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700501
chaviw0dd03f52017-08-25 12:15:26 -0700502 float* floatColors = env->GetFloatArrayElements(fColor, 0);
503 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700504 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700505}
506
Robert Carre13b58e2017-08-31 14:50:44 -0700507static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
508 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800509 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700510 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
511
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800512 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700513 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800514}
515
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700516static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
517 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
518 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
519 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
520 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
521 mat3 matrix(static_cast<float const*>(floatMatrix));
522 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
523 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
524 transaction->setColorTransform(surfaceControl, matrix, translation);
525}
526
Peiyong Linf4f0f642019-03-01 14:36:05 -0800527static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
528 jlong nativeObject, jboolean agnostic) {
529 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
530 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
531 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
532}
533
Robert Carre13b58e2017-08-31 14:50:44 -0700534static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
535 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800536 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700537 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
538
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800539 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
540 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700541 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800542}
543
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700544static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
545 jlong nativeObject, jfloat cornerRadius) {
546 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
547
548 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
549 transaction->setCornerRadius(ctrl, cornerRadius);
550}
551
Robert Carre13b58e2017-08-31 14:50:44 -0700552static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
553 jlong nativeObject, jint layerStack) {
554 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
555
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800556 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700557 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800558}
559
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800560static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
561 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
562 jlongArray array = env->NewLongArray(displayIds.size());
563 if (array == nullptr) {
564 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
565 return nullptr;
566 }
567
568 if (displayIds.empty()) {
569 return array;
570 }
571
572 jlong* values = env->GetLongArrayElements(array, 0);
573 for (size_t i = 0; i < displayIds.size(); ++i) {
574 values[i] = static_cast<jlong>(displayIds[i]);
575 }
576
577 env->ReleaseLongArrayElements(array, values, 0);
578 return array;
579}
580
581static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
582 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800583 return javaObjectForIBinder(env, token);
584}
585
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700586static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
587 jobject tokenObj) {
588 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
589
590 ui::PixelFormat format;
591 ui::Dataspace dataspace;
592 uint8_t componentMask;
593 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
594 token, &format, &dataspace, &componentMask);
595 if (err != OK) {
596 return nullptr;
597 }
598 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
599 gDisplayedContentSamplingAttributesClassInfo.ctor,
600 format, dataspace, componentMask);
601}
602
603static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
604 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
605 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800606 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700607 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800608 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700609}
610
611static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
612 jlong maxFrames, jlong timestamp) {
613 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
614
615 DisplayedFrameStats stats;
616 status_t err = SurfaceComposerClient::getDisplayedContentSample(
617 token, maxFrames, timestamp, &stats);
618 if (err != OK) {
619 return nullptr;
620 }
621
622 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
623 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
624 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
625 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
626 if ((histogramComponent0 == nullptr) ||
627 (histogramComponent1 == nullptr) ||
628 (histogramComponent2 == nullptr) ||
629 (histogramComponent3 == nullptr)) {
630 return JNI_FALSE;
631 }
632
633 env->SetLongArrayRegion(histogramComponent0, 0,
634 stats.component_0_sample.size(),
635 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
636 env->SetLongArrayRegion(histogramComponent1, 0,
637 stats.component_1_sample.size(),
638 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
639 env->SetLongArrayRegion(histogramComponent2, 0,
640 stats.component_2_sample.size(),
641 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
642 env->SetLongArrayRegion(histogramComponent3, 0,
643 stats.component_3_sample.size(),
644 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
645 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
646 gDisplayedContentSampleClassInfo.ctor,
647 stats.numFrames,
648 histogramComponent0,
649 histogramComponent1,
650 histogramComponent2,
651 histogramComponent3);
652}
653
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800654static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
655 jboolean secure) {
656 ScopedUtfChars name(env, nameObj);
657 sp<IBinder> token(SurfaceComposerClient::createDisplay(
658 String8(name.c_str()), bool(secure)));
659 return javaObjectForIBinder(env, token);
660}
661
Jesse Hall6a6bc212013-08-08 12:15:03 -0700662static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
663 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
664 if (token == NULL) return;
665 SurfaceComposerClient::destroyDisplay(token);
666}
667
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800668static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700669 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000670 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800671 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
672 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800673 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800674 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800675 if (sur != NULL) {
676 bufferProducer = sur->getIGraphicBufferProducer();
677 }
Robert Carre13b58e2017-08-31 14:50:44 -0700678
679
680 status_t err = NO_ERROR;
681 {
682 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
683 err = transaction->setDisplaySurface(token,
684 bufferProducer);
685 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700686 if (err != NO_ERROR) {
687 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
688 " Surface created with singleBufferMode?");
689 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800690}
691
692static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700693 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800694 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700695
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800696 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
697 if (token == NULL) return;
698
Robert Carre13b58e2017-08-31 14:50:44 -0700699 {
700 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
701 transaction->setDisplayLayerStack(token, layerStack);
702 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800703}
704
705static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700706 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800707 jobject tokenObj, jint orientation,
708 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
709 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
710 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
711 if (token == NULL) return;
712 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
713 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700714
715 {
716 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
717 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
718 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800719}
720
Michael Wright01e840f2014-06-26 16:03:25 -0700721static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700722 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700723 jobject tokenObj, jint width, jint height) {
724 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
725 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700726
727 {
728 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
729 transaction->setDisplaySize(token, width, height);
730 }
Michael Wright01e840f2014-06-26 16:03:25 -0700731}
732
Dan Stoza00101052014-05-02 15:23:40 -0700733static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
734 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800735 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700736 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800737
Dan Stoza00101052014-05-02 15:23:40 -0700738 Vector<DisplayInfo> configs;
739 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
740 configs.size() == 0) {
741 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800742 }
743
Dan Stoza00101052014-05-02 15:23:40 -0700744 jobjectArray configArray = env->NewObjectArray(configs.size(),
745 gPhysicalDisplayInfoClassInfo.clazz, NULL);
746
747 for (size_t c = 0; c < configs.size(); ++c) {
748 const DisplayInfo& info = configs[c];
749 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
750 gPhysicalDisplayInfoClassInfo.ctor);
751 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
752 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
753 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
754 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
755 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
756 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
757 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700758 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
759 info.appVsyncOffset);
760 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
761 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700762 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
763 env->DeleteLocalRef(infoObj);
764 }
765
766 return configArray;
767}
768
Ady Abraham6070ce12019-01-24 18:48:58 -0800769static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
770 jobject tokenObj, jintArray configArray) {
771 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
772 if (token == nullptr) return JNI_FALSE;
773
774 std::vector<int32_t> allowedConfigs;
775 jsize configArraySize = env->GetArrayLength(configArray);
776 allowedConfigs.reserve(configArraySize);
777
778 jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
779 for (int i = 0; i < configArraySize; i++) {
780 allowedConfigs.push_back(configArrayElements[i]);
781 }
782 env->ReleaseIntArrayElements(configArray, configArrayElements, 0);
783
784 size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
785 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
786}
787
Ady Abraham42f9a2fb2019-02-26 14:13:39 -0800788static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
789 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
790 if (token == nullptr) return JNI_FALSE;
791
792 std::vector<int32_t> allowedConfigs;
793 size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs);
794 if (result != NO_ERROR) {
795 return nullptr;
796 }
797
798 jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size());
799 if (allowedConfigsArray == nullptr) {
800 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
801 return nullptr;
802 }
803 jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0);
804 for (size_t i = 0; i < allowedConfigs.size(); i++) {
805 allowedConfigsArrayValues[i] = static_cast<jint>(allowedConfigs[i]);
806 }
807 env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0);
808 return allowedConfigsArray;
809}
810
Dan Stoza00101052014-05-02 15:23:40 -0700811static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
812 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
813 if (token == NULL) return -1;
814 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
815}
816
817static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
818 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
819 if (token == NULL) return JNI_FALSE;
820 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
821 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800822}
823
Michael Wright1c9977b2016-07-12 13:30:10 -0700824static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
825 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
826 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700827 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700828 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
829 colorModes.isEmpty()) {
830 return NULL;
831 }
832
833 jintArray colorModesArray = env->NewIntArray(colorModes.size());
834 if (colorModesArray == NULL) {
835 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
836 return NULL;
837 }
838 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
839 for (size_t i = 0; i < colorModes.size(); i++) {
840 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
841 }
842 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
843 return colorModesArray;
844}
845
Daniel Solomon10e3b332019-01-20 21:09:11 -0800846static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
847 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
848 if (token == NULL) return NULL;
849
850 ui::DisplayPrimaries primaries;
851 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
852 return NULL;
853 }
854
855 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
856 if (jred == NULL) {
857 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
858 return NULL;
859 }
860
861 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
862 if (jgreen == NULL) {
863 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
864 return NULL;
865 }
866
867 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
868 if (jblue == NULL) {
869 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
870 return NULL;
871 }
872
873 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
874 if (jwhite == NULL) {
875 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
876 return NULL;
877 }
878
879 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
880 gDisplayPrimariesClassInfo.ctor);
881 if (jprimaries == NULL) {
882 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
883 return NULL;
884 }
885
886 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
887 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
888 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
889 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
890 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
891 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
892 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
893 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
894 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
895 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
896 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
897 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
898 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
899 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
900 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
901 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
902
903 return jprimaries;
904}
905
Michael Wright1c9977b2016-07-12 13:30:10 -0700906static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
907 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
908 if (token == NULL) return -1;
909 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
910}
911
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800912static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
913 ui::Dataspace defaultDataspace, wcgDataspace;
914 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
915 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
916 &defaultPixelFormat,
917 &wcgDataspace,
918 &wcgPixelFormat) != NO_ERROR) {
919 return nullptr;
920 }
921 jintArray array = env->NewIntArray(2);
922 if (array == nullptr) {
923 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
924 return nullptr;
925 }
926 jint* arrayValues = env->GetIntArrayElements(array, 0);
927 arrayValues[0] = static_cast<jint>(defaultDataspace);
928 arrayValues[1] = static_cast<jint>(wcgDataspace);
929 env->ReleaseIntArrayElements(array, arrayValues, 0);
930 return array;
931}
932
Michael Wright1c9977b2016-07-12 13:30:10 -0700933static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
934 jobject tokenObj, jint colorMode) {
935 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
936 if (token == NULL) return JNI_FALSE;
937 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700938 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700939 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
940}
941
Prashant Malanic55929a2014-05-25 01:59:21 -0700942static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800943 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
944 if (token == NULL) return;
945
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700946 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700947 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700948 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800949}
950
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800951static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
952 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
953}
954
Svetoslav1376d602014-03-13 11:17:26 -0700955static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
956 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
957 status_t err = ctrl->clearLayerFrameStats();
958
959 if (err < 0 && err != NO_INIT) {
960 doThrowIAE(env);
961 }
962
963 // The other end is not ready, just report we failed.
964 if (err == NO_INIT) {
965 return JNI_FALSE;
966 }
967
968 return JNI_TRUE;
969}
970
971static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
972 jobject outStats) {
973 FrameStats stats;
974
975 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
976 status_t err = ctrl->getLayerFrameStats(&stats);
977 if (err < 0 && err != NO_INIT) {
978 doThrowIAE(env);
979 }
980
981 // The other end is not ready, fine just return empty stats.
982 if (err == NO_INIT) {
983 return JNI_FALSE;
984 }
985
986 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
987 size_t frameCount = stats.desiredPresentTimesNano.size();
988
989 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
990 if (postedTimesNanoDst == NULL) {
991 return JNI_FALSE;
992 }
993
994 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
995 if (presentedTimesNanoDst == NULL) {
996 return JNI_FALSE;
997 }
998
999 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
1000 if (readyTimesNanoDst == NULL) {
1001 return JNI_FALSE;
1002 }
1003
1004 nsecs_t postedTimesNanoSrc[frameCount];
1005 nsecs_t presentedTimesNanoSrc[frameCount];
1006 nsecs_t readyTimesNanoSrc[frameCount];
1007
1008 for (size_t i = 0; i < frameCount; i++) {
1009 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
1010 if (postedTimeNano == INT64_MAX) {
1011 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1012 }
1013 postedTimesNanoSrc[i] = postedTimeNano;
1014
1015 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1016 if (presentedTimeNano == INT64_MAX) {
1017 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1018 }
1019 presentedTimesNanoSrc[i] = presentedTimeNano;
1020
1021 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
1022 if (readyTimeNano == INT64_MAX) {
1023 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1024 }
1025 readyTimesNanoSrc[i] = readyTimeNano;
1026 }
1027
1028 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
1029 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1030 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
1031
1032 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
1033 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
1034
1035 if (env->ExceptionCheck()) {
1036 return JNI_FALSE;
1037 }
1038
1039 return JNI_TRUE;
1040}
1041
1042static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
1043 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
1044
1045 if (err < 0 && err != NO_INIT) {
1046 doThrowIAE(env);
1047 }
1048
1049 // The other end is not ready, just report we failed.
1050 if (err == NO_INIT) {
1051 return JNI_FALSE;
1052 }
1053
1054 return JNI_TRUE;
1055}
1056
1057static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
1058 FrameStats stats;
1059
1060 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1061 if (err < 0 && err != NO_INIT) {
1062 doThrowIAE(env);
1063 }
1064
1065 // The other end is not ready, fine just return empty stats.
1066 if (err == NO_INIT) {
1067 return JNI_FALSE;
1068 }
1069
1070 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1071 size_t frameCount = stats.desiredPresentTimesNano.size();
1072
1073 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1074 if (presentedTimesNanoDst == NULL) {
1075 return JNI_FALSE;
1076 }
1077
1078 nsecs_t presentedTimesNanoSrc[frameCount];
1079
1080 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -07001081 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -07001082 if (presentedTimeNano == INT64_MAX) {
1083 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1084 }
1085 presentedTimesNanoSrc[i] = presentedTimeNano;
1086 }
1087
1088 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1089
1090 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1091 presentedTimesNanoDst);
1092
1093 if (env->ExceptionCheck()) {
1094 return JNI_FALSE;
1095 }
1096
1097 return JNI_TRUE;
1098}
1099
Robert Carre13b58e2017-08-31 14:50:44 -07001100static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
1101 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +00001102 jobject handleObject, jlong frameNumber) {
1103 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1104 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
1105
Robert Carre13b58e2017-08-31 14:50:44 -07001106 {
1107 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001108 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
Robert Carre13b58e2017-08-31 14:50:44 -07001109 }
Rob Carr64e516f2015-10-29 00:20:45 +00001110}
1111
Robert Carre13b58e2017-08-31 14:50:44 -07001112static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1113 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001114 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001115 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1116
Robert Carrd5c7dd62017-03-08 10:39:30 -08001117 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1118 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1119
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001120 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001121}
1122
Robert Carre13b58e2017-08-31 14:50:44 -07001123static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1124 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001125 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001126
Robert Carrd5c7dd62017-03-08 10:39:30 -08001127 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1128 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
1129
Robert Carre13b58e2017-08-31 14:50:44 -07001130 {
1131 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1132 transaction->reparentChildren(ctrl, handle);
1133 }
Robert Carrd5c7dd62017-03-08 10:39:30 -08001134}
1135
Robert Carre13b58e2017-08-31 14:50:44 -07001136static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1137 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001138 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001139 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001140 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001141
1142 {
1143 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr10584fa2019-01-14 15:55:19 -08001144 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
Robert Carre13b58e2017-08-31 14:50:44 -07001145 }
chaviw63542382017-08-17 17:39:29 -07001146}
1147
Robert Carre13b58e2017-08-31 14:50:44 -07001148static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1149 jlong nativeObject) {
1150 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1151
Robert Carrd5c7dd62017-03-08 10:39:30 -08001152 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001153 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001154}
1155
Robert Carre13b58e2017-08-31 14:50:44 -07001156static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1157 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001158 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001159 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001160
Robert Carre13b58e2017-08-31 14:50:44 -07001161 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1162 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001163}
1164
Rob Carr64e516f2015-10-29 00:20:45 +00001165static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
1166 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +00001167 return javaObjectForIBinder(env, ctrl->getHandle());
1168}
1169
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001170static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1171 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1172 if (token == NULL) return NULL;
1173
1174 HdrCapabilities capabilities;
1175 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1176
1177 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001178 std::vector<int32_t> intTypes;
1179 for (auto type : types) {
1180 intTypes.push_back(static_cast<int32_t>(type));
1181 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001182 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001183 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001184
Michael Wright9ff94c02016-03-30 18:05:40 -07001185 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001186 typesArray, capabilities.getDesiredMaxLuminance(),
1187 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1188}
1189
Jorim Jaggi06975df2017-12-01 14:52:13 +01001190static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1191 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1192 if (parcel == NULL) {
1193 doThrowNPE(env);
1194 return 0;
1195 }
1196 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1197 if (surface == nullptr) {
1198 return 0;
1199 }
1200 surface->incStrong((void *)nativeCreate);
1201 return reinterpret_cast<jlong>(surface.get());
1202}
1203
chaviwbeb7a0c2018-12-05 13:49:54 -08001204static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1205 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1206 if (surface == nullptr) {
1207 return 0;
1208 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001209
1210 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1211 newSurface->incStrong((void *)nativeCreate);
1212 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001213}
1214
Jorim Jaggi06975df2017-12-01 14:52:13 +01001215static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1216 jlong nativeObject, jobject parcelObj) {
1217 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1218 if (parcel == NULL) {
1219 doThrowNPE(env);
1220 return;
1221 }
1222 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001223 if (self != nullptr) {
1224 self->writeToParcel(parcel);
1225 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001226}
1227
Dan Gittik832b4972019-02-13 18:17:47 +00001228static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1229 jobject displayTokenObject) {
1230 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1231 if (displayToken == nullptr) {
1232 return JNI_FALSE;
1233 }
1234 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1235}
1236
1237static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1238 jfloat brightness) {
1239 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1240 if (displayToken == nullptr) {
1241 return JNI_FALSE;
1242 }
1243 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1244 return error == OK ? JNI_TRUE : JNI_FALSE;
1245}
1246
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001247// ----------------------------------------------------------------------------
1248
Daniel Micay76f6a862015-09-19 17:31:01 -04001249static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001250 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001251 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001252 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1253 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001254 {"nativeCopyFromSurfaceControl", "(J)J" ,
1255 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001256 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1257 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001258 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001259 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001260 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001261 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -08001262 {"nativeDisconnect", "(J)V",
1263 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001264 {"nativeCreateTransaction", "()J",
1265 (void*)nativeCreateTransaction },
1266 {"nativeApplyTransaction", "(JZ)V",
1267 (void*)nativeApplyTransaction },
1268 {"nativeGetNativeTransactionFinalizer", "()J",
1269 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001270 {"nativeMergeTransaction", "(JJ)V",
1271 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001272 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001273 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001274 {"nativeSetEarlyWakeup", "(J)V",
1275 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001276 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001277 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001278 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -07001279 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001280 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001281 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001282 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -07001283 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -07001284 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001285 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001286 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001287 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001288 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001289 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001290 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001291 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001292 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001293 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001294 {"nativeSetColorTransform", "(JJ[F[F)V",
1295 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001296 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1297 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001298 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001299 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001300 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001301 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001302 {"nativeSetCornerRadius", "(JJF)V",
1303 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001304 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001305 (void*)nativeSetLayerStack },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001306 {"nativeGetPhysicalDisplayIds", "()[J",
1307 (void*)nativeGetPhysicalDisplayIds },
1308 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1309 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001310 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1311 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001312 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1313 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001314 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001315 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001316 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001317 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001318 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001319 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001320 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001321 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001322 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1323 (void*)nativeGetDisplayConfigs },
1324 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1325 (void*)nativeGetActiveConfig },
1326 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1327 (void*)nativeSetActiveConfig },
Ady Abraham6070ce12019-01-24 18:48:58 -08001328 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1329 (void*)nativeSetAllowedDisplayConfigs },
Ady Abraham42f9a2fb2019-02-26 14:13:39 -08001330 {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
1331 (void*)nativeGetAllowedDisplayConfigs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001332 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1333 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001334 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1335 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001336 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1337 (void*)nativeGetActiveColorMode},
1338 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1339 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001340 {"nativeGetCompositionDataspaces", "()[I",
1341 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001342 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1343 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001344 {"nativeClearContentFrameStats", "(J)Z",
1345 (void*)nativeClearContentFrameStats },
1346 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1347 (void*)nativeGetContentFrameStats },
1348 {"nativeClearAnimationFrameStats", "()Z",
1349 (void*)nativeClearAnimationFrameStats },
1350 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1351 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001352 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1353 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001354 {"nativeGetProtectedContentSupport", "()Z",
1355 (void*)nativeGetProtectedContentSupport },
Robert Carre13b58e2017-08-31 14:50:44 -07001356 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001357 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001358 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001359 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001360 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001361 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001362 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001363 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001364 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001365 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001366 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001367 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001368 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001369 (void*)nativeGetHandle },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001370 {"nativeScreenshot",
1371 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1372 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001373 (void*)nativeScreenshot },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001374 {"nativeCaptureLayers",
Robert Carrffcdc512019-04-02 11:51:11 -07001375 "(Landroid/os/IBinder;Landroid/graphics/Rect;F[Landroid/os/IBinder;)"
Peiyong Line3e5efd2019-03-21 20:59:47 +00001376 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001377 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001378 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001379 (void*)nativeSetInputWindowInfo },
1380 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1381 (void*)nativeTransferTouchFocus },
Evan Roskyb51e2462019-04-03 19:27:18 -07001382 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
Evan Rosky485df202018-12-06 14:11:12 -08001383 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001384 {"nativeGetDisplayedContentSamplingAttributes",
1385 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1386 (void*)nativeGetDisplayedContentSamplingAttributes },
1387 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1388 (void*)nativeSetDisplayedContentSamplingEnabled },
1389 {"nativeGetDisplayedContentSample",
1390 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1391 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001392 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001393 (void*)nativeSetGeometry },
1394 {"nativeSyncInputWindows", "(J)V",
Dan Gittik832b4972019-02-13 18:17:47 +00001395 (void*)nativeSyncInputWindows },
1396 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1397 (void*)nativeGetDisplayBrightnessSupport },
1398 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1399 (void*)nativeSetDisplayBrightness },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001400};
1401
1402int register_android_view_SurfaceControl(JNIEnv* env)
1403{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001404 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001405 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1406
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001407 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1408 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1409 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1410 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1411 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1412 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1413 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1414 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1415 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1416 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1417 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1418 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1419 clazz, "appVsyncOffsetNanos", "J");
1420 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1421 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001422
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001423 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1424 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1425 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1426 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1427 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001428
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001429 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1430 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1431 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001432 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1433
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001434 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1435 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1436 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001437 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1438
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001439 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1440 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1441 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001442 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1443
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001444 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1445 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1446 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1447 "([IFFF)V");
1448
Robert Carr6486d312017-01-09 19:48:29 -08001449 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1450 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1451 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1452 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1453
Peiyong Line3e5efd2019-03-21 20:59:47 +00001454 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1455 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1456 gScreenshotGraphicBufferClassInfo.clazz =
1457 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1458 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1459 screenshotGraphicsBufferClazz,
Robert Carr66b5664f2019-04-02 14:18:56 -07001460 "createFromNative", "(IIIIJIZ)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
Peiyong Line3e5efd2019-03-21 20:59:47 +00001461
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001462 jclass displayedContentSampleClazz = FindClassOrDie(env,
1463 "android/hardware/display/DisplayedContentSample");
1464 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1465 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1466 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1467
1468 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1469 "android/hardware/display/DisplayedContentSamplingAttributes");
1470 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1471 displayedContentSamplingAttributesClazz);
1472 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1473 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001474
1475 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1476 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1477 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1478 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1479 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1480 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1481
1482 jclass displayPrimariesClazz = FindClassOrDie(env,
1483 "android/view/SurfaceControl$DisplayPrimaries");
1484 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1485 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1486 "<init>", "()V");
1487 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1488 "Landroid/view/SurfaceControl$CieXyz;");
1489 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1490 "Landroid/view/SurfaceControl$CieXyz;");
1491 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1492 "Landroid/view/SurfaceControl$CieXyz;");
1493 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1494 "Landroid/view/SurfaceControl$CieXyz;");
1495
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001496 return err;
1497}
1498
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001499} // namespace android