blob: 9f2038840c8ae95920c8757efc1f7b6d3032306c [file] [log] [blame]
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceControl"
Robert Carr6486d312017-01-09 19:48:29 -080018#define LOG_NDEBUG 0
Mathias Agopian3866f0d2013-02-11 22:08:48 -080019
Mathias Agopian3866f0d2013-02-11 22:08:48 -080020#include "android_os_Parcel.h"
21#include "android_util_Binder.h"
Robert Carr788f5742018-07-30 17:46:45 -070022#include "android_hardware_input_InputWindowHandle.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080023#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040024
Derek Sollenberger40d78132019-08-12 11:06:08 -040025#include <android/graphics/region.h>
Derek Sollenberger8b994192019-07-16 13:23:29 -040026#include <android_runtime/AndroidRuntime.h>
Tom Cherry8ed74bb2017-07-10 14:31:18 -070027#include <android-base/chrono_utils.h>
Steven Moreland2279b252017-07-19 09:50:45 -070028#include <nativehelper/JNIHelp.h>
29#include <nativehelper/ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080030#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080031#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032#include <gui/Surface.h>
33#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040034#include <jni.h>
35#include <memory>
36#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070037#include <system/graphics.h>
Daniel Solomon10e3b332019-01-20 21:09:11 -080038#include <ui/ConfigStoreTypes.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080039#include <ui/DisplayInfo.h>
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -070040#include <ui/DisplayedFrameStats.h>
Svetoslav1376d602014-03-13 11:17:26 -070041#include <ui/FrameStats.h>
Peiyong Linb88549e2018-03-28 12:03:45 -070042#include <ui/GraphicTypes.h>
Peiyong Lin371b98f2018-03-14 17:29:10 -070043#include <ui/HdrCapabilities.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080044#include <ui/Rect.h>
45#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080046#include <utils/Log.h>
47
Mathias Agopian3866f0d2013-02-11 22:08:48 -080048// ----------------------------------------------------------------------------
49
50namespace android {
51
Derek Sollenberger8b994192019-07-16 13:23:29 -040052static void doThrowNPE(JNIEnv* env) {
53 jniThrowNullPointerException(env, NULL);
54}
55
56static void doThrowIAE(JNIEnv* env, const char* msg = nullptr) {
57 jniThrowException(env, "java/lang/IllegalArgumentException", msg);
58}
59
Mathias Agopian3866f0d2013-02-11 22:08:48 -080060static const char* const OutOfResourcesException =
61 "android/view/Surface$OutOfResourcesException";
62
63static struct {
Dan Stoza00101052014-05-02 15:23:40 -070064 jclass clazz;
65 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080066 jfieldID width;
67 jfieldID height;
68 jfieldID refreshRate;
69 jfieldID density;
70 jfieldID xDpi;
71 jfieldID yDpi;
72 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070073 jfieldID appVsyncOffsetNanos;
74 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080075} gPhysicalDisplayInfoClassInfo;
76
Dan Stoza9890e3412014-05-22 16:12:54 -070077static struct {
78 jfieldID bottom;
79 jfieldID left;
80 jfieldID right;
81 jfieldID top;
82} gRectClassInfo;
83
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050084// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
85void DeleteScreenshot(void* addr, void* context) {
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050086 delete ((ScreenshotClient*) context);
87}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080088
Svetoslav1376d602014-03-13 11:17:26 -070089static struct {
90 nsecs_t UNDEFINED_TIME_NANO;
91 jmethodID init;
92} gWindowContentFrameStatsClassInfo;
93
94static struct {
95 nsecs_t UNDEFINED_TIME_NANO;
96 jmethodID init;
97} gWindowAnimationFrameStatsClassInfo;
98
Hangyu Kuang54ac2192016-04-25 13:22:02 -070099static struct {
100 jclass clazz;
101 jmethodID ctor;
102} gHdrCapabilitiesClassInfo;
103
Robert Carr6486d312017-01-09 19:48:29 -0800104static struct {
105 jclass clazz;
106 jmethodID builder;
107} gGraphicBufferClassInfo;
108
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700109static struct {
110 jclass clazz;
111 jmethodID ctor;
112} gDisplayedContentSampleClassInfo;
113
114static struct {
115 jclass clazz;
116 jmethodID ctor;
117} gDisplayedContentSamplingAttributesClassInfo;
118
Daniel Solomon10e3b332019-01-20 21:09:11 -0800119static struct {
120 jclass clazz;
121 jmethodID ctor;
122 jfieldID X;
123 jfieldID Y;
124 jfieldID Z;
125} gCieXyzClassInfo;
126
127static struct {
128 jclass clazz;
129 jmethodID ctor;
130 jfieldID red;
131 jfieldID green;
132 jfieldID blue;
133 jfieldID white;
134} gDisplayPrimariesClassInfo;
135
Peiyong Line3e5efd2019-03-21 20:59:47 +0000136static struct {
137 jclass clazz;
138 jmethodID builder;
139} gScreenshotGraphicBufferClassInfo;
140
141class JNamedColorSpace {
142public:
143 // ColorSpace.Named.SRGB.ordinal() = 0;
144 static constexpr jint SRGB = 0;
145
Peiyong Line9133d52019-05-01 15:36:04 -0700146 // ColorSpace.Named.DISPLAY_P3.ordinal() = 7;
147 static constexpr jint DISPLAY_P3 = 7;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000148};
149
150constexpr jint fromDataspaceToNamedColorSpaceValue(const ui::Dataspace dataspace) {
151 switch (dataspace) {
152 case ui::Dataspace::DISPLAY_P3:
153 return JNamedColorSpace::DISPLAY_P3;
154 default:
155 return JNamedColorSpace::SRGB;
156 }
157}
158
159constexpr ui::Dataspace pickDataspaceFromColorMode(const ui::ColorMode colorMode) {
160 switch (colorMode) {
161 case ui::ColorMode::DISPLAY_P3:
162 case ui::ColorMode::BT2100_PQ:
163 case ui::ColorMode::BT2100_HLG:
164 case ui::ColorMode::DISPLAY_BT2020:
165 return ui::Dataspace::DISPLAY_P3;
166 default:
167 return ui::Dataspace::V0_SRGB;
168 }
169}
170
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800171// ----------------------------------------------------------------------------
172
Robert Carre13b58e2017-08-31 14:50:44 -0700173static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
174 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
175}
176
177static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
178 delete t;
179}
180
181static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
182 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
183}
184
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000185static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500186 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
Evan Rosky485df202018-12-06 14:11:12 -0800187 jobject metadataParcel) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800188 ScopedUtfChars name(env, nameStr);
Robert Carr76907ee2019-01-11 13:38:19 -0800189 sp<SurfaceComposerClient> client;
190 if (sessionObj != NULL) {
191 client = android_view_SurfaceSession_getClient(env, sessionObj);
192 } else {
193 client = SurfaceComposerClient::getDefault();
194 }
Robert Carr838120c2016-11-01 18:31:12 -0700195 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Robert Carrb0f39362018-03-14 13:52:25 -0700196 sp<SurfaceControl> surface;
Evan Rosky485df202018-12-06 14:11:12 -0800197 LayerMetadata metadata;
198 Parcel* parcel = parcelForJavaObject(env, metadataParcel);
199 if (parcel && !parcel->objectsCount()) {
200 status_t err = metadata.readFromParcel(parcel);
201 if (err != NO_ERROR) {
202 jniThrowException(env, "java/lang/IllegalArgumentException",
203 "Metadata parcel has wrong format");
204 }
205 }
206
Robert Carrb0f39362018-03-14 13:52:25 -0700207 status_t err = client->createSurfaceChecked(
Evan Rosky485df202018-12-06 14:11:12 -0800208 String8(name.c_str()), w, h, format, &surface, flags, parent, std::move(metadata));
Robert Carrb0f39362018-03-14 13:52:25 -0700209 if (err == NAME_NOT_FOUND) {
210 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
211 return 0;
212 } else if (err != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800213 jniThrowException(env, OutOfResourcesException, NULL);
214 return 0;
215 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500216
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800217 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000218 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800219}
220
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000221static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800222 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Robert Carrcc6d4832019-02-04 15:41:12 -0800223 ctrl->release();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800224 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800225}
226
Chong Zhang47e36a32016-02-29 16:44:33 -0800227static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
228 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
229 if (ctrl != NULL) {
230 ctrl->disconnect();
231 }
232}
233
Robert Carr6486d312017-01-09 19:48:29 -0800234static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
235 int left = env->GetIntField(rectObj, gRectClassInfo.left);
236 int top = env->GetIntField(rectObj, gRectClassInfo.top);
237 int right = env->GetIntField(rectObj, gRectClassInfo.right);
238 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
239 return Rect(left, top, right, bottom);
240}
241
chaviw08520a02018-09-10 16:44:56 -0700242static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
Robert Carr6486d312017-01-09 19:48:29 -0800243 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Robert Carr5c52b132019-02-15 15:48:11 -0800244 bool useIdentityTransform, int rotation, bool captureSecureLayers) {
Robert Carr6486d312017-01-09 19:48:29 -0800245 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
246 if (displayToken == NULL) {
247 return NULL;
248 }
Peiyong Line3e5efd2019-03-21 20:59:47 +0000249 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
250 const ui::Dataspace dataspace = pickDataspaceFromColorMode(colorMode);
251
Robert Carr6486d312017-01-09 19:48:29 -0800252 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Robert Carr6486d312017-01-09 19:48:29 -0800253 sp<GraphicBuffer> buffer;
Robert Carr66b5664f2019-04-02 14:18:56 -0700254 bool capturedSecureLayers = false;
Peiyong Line3e5efd2019-03-21 20:59:47 +0000255 status_t res = ScreenshotClient::capture(displayToken, dataspace,
Robert Carr5c52b132019-02-15 15:48:11 -0800256 ui::PixelFormat::RGBA_8888,
257 sourceCrop, width, height,
Robert Carr66b5664f2019-04-02 14:18:56 -0700258 useIdentityTransform, rotation, captureSecureLayers, &buffer, capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800259 if (res != NO_ERROR) {
260 return NULL;
261 }
262
Peiyong Line3e5efd2019-03-21 20:59:47 +0000263 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
264 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
265 gScreenshotGraphicBufferClassInfo.builder,
Robert Carr6486d312017-01-09 19:48:29 -0800266 buffer->getWidth(),
267 buffer->getHeight(),
268 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700269 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000270 (jlong)buffer.get(),
Robert Carr66b5664f2019-04-02 14:18:56 -0700271 namedColorSpace,
272 capturedSecureLayers);
Robert Carr6486d312017-01-09 19:48:29 -0800273}
274
Peiyong Lin21e499a2019-04-03 16:37:46 -0700275static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700276 jlong layerObject, jobject sourceCropObj, jfloat frameScale,
Chiawei Wang02202d12019-01-03 18:12:13 +0800277 jlongArray excludeObjectArray, jint format) {
chaviwfbe47df2017-11-10 16:14:49 -0800278
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700279 auto layer = reinterpret_cast<SurfaceControl *>(layerObject);
280 if (layer == NULL) {
chaviwfbe47df2017-11-10 16:14:49 -0800281 return NULL;
282 }
283
284 Rect sourceCrop;
285 if (sourceCropObj != NULL) {
286 sourceCrop = rectFromObj(env, sourceCropObj);
287 }
288
Robert Carrffcdc512019-04-02 11:51:11 -0700289 std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700290 if (excludeObjectArray != NULL) {
291 const jsize len = env->GetArrayLength(excludeObjectArray);
Robert Carrffcdc512019-04-02 11:51:11 -0700292 excludeHandles.reserve(len);
293
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700294 const jlong* objects = env->GetLongArrayElements(excludeObjectArray, nullptr);
Robert Carrffcdc512019-04-02 11:51:11 -0700295 for (jsize i = 0; i < len; i++) {
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700296 auto excludeObject = reinterpret_cast<SurfaceControl *>(objects[i]);
297 if (excludeObject == nullptr) {
Robert Carrffcdc512019-04-02 11:51:11 -0700298 jniThrowNullPointerException(env, "Exclude layer is null");
299 return NULL;
300 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700301 excludeHandles.emplace(excludeObject->getHandle());
Robert Carrffcdc512019-04-02 11:51:11 -0700302 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700303 env->ReleaseLongArrayElements(excludeObjectArray, const_cast<jlong*>(objects), JNI_ABORT);
Robert Carrffcdc512019-04-02 11:51:11 -0700304 }
305
chaviwfbe47df2017-11-10 16:14:49 -0800306 sp<GraphicBuffer> buffer;
Peiyong Lin21e499a2019-04-03 16:37:46 -0700307 ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
308 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
309 if (displayToken != nullptr) {
310 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
311 dataspace = pickDataspaceFromColorMode(colorMode);
312 }
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700313 status_t res = ScreenshotClient::captureChildLayers(layer->getHandle(), dataspace,
Chiawei Wang02202d12019-01-03 18:12:13 +0800314 static_cast<ui::PixelFormat>(format),
315 sourceCrop, excludeHandles, frameScale,
316 &buffer);
chaviwfbe47df2017-11-10 16:14:49 -0800317 if (res != NO_ERROR) {
318 return NULL;
319 }
320
Peiyong Line3e5efd2019-03-21 20:59:47 +0000321 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
322 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
323 gScreenshotGraphicBufferClassInfo.builder,
chaviwfbe47df2017-11-10 16:14:49 -0800324 buffer->getWidth(),
325 buffer->getHeight(),
326 buffer->getPixelFormat(),
327 (jint)buffer->getUsage(),
Peiyong Line3e5efd2019-03-21 20:59:47 +0000328 (jlong)buffer.get(),
Robert Carrbf9298f2019-04-09 07:42:02 -0700329 namedColorSpace,
330 false /* capturedSecureLayers */);
chaviw1cda84c2017-10-23 16:47:10 -0700331}
332
Robert Carre13b58e2017-08-31 14:50:44 -0700333static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
334 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
335 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800336}
337
Robert Carrb1579c82017-09-05 14:54:47 -0700338static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
339 jlong transactionObj, jlong otherTransactionObj) {
340 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
341 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
342 otherTransactionObj);
343 transaction->merge(std::move(*otherTransaction));
344}
345
Robert Carre13b58e2017-08-31 14:50:44 -0700346static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
347 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
348 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800349}
350
Jorim Jaggiaa763cd2018-03-22 23:20:36 +0100351static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
352 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
353 transaction->setEarlyWakeup();
354}
355
Robert Carre13b58e2017-08-31 14:50:44 -0700356static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
357 jlong nativeObject, jint zorder) {
358 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800359
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800360 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700361 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800362}
363
Robert Carre13b58e2017-08-31 14:50:44 -0700364static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
365 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700366 jlong relativeToObject, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700367
Robert Carraf422a82017-04-10 18:34:33 -0700368 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700369 auto relative = reinterpret_cast<SurfaceControl *>(relativeToObject);
370 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
371 transaction->setRelativeLayer(ctrl, relative->getHandle(), zorder);
Robert Carraf422a82017-04-10 18:34:33 -0700372}
373
Robert Carre13b58e2017-08-31 14:50:44 -0700374static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
375 jlong nativeObject, jfloat x, jfloat y) {
376 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
377
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800378 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700379 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800380}
381
Robert Carr76907ee2019-01-11 13:38:19 -0800382static void nativeSetGeometry(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
383 jobject sourceObj, jobject dstObj, jlong orientation) {
384 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
385 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
386
387 Rect source, dst;
388 if (sourceObj != NULL) {
389 source = rectFromObj(env, sourceObj);
Robert Carrced6f852019-04-08 16:58:49 -0700390 } else {
391 source.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800392 }
393 if (dstObj != NULL) {
394 dst = rectFromObj(env, dstObj);
Robert Carrced6f852019-04-08 16:58:49 -0700395 } else {
396 dst.makeInvalid();
Robert Carr76907ee2019-01-11 13:38:19 -0800397 }
398 transaction->setGeometry(ctrl, source, dst, orientation);
399}
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);
Derek Sollenberger40d78132019-08-12 11:06:08 -0400420 graphics::RegionIterator iterator(env, regionObj);
421 if (!iterator.isValid()) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800422 doThrowIAE(env);
423 return;
424 }
425
Derek Sollenberger40d78132019-08-12 11:06:08 -0400426 ARect bounds = iterator.getTotalBounds();
427 Region reg({bounds.left, bounds.top, bounds.right, bounds.bottom});
428 if (iterator.isComplex()) {
429 while (!iterator.isDone()) {
430 ARect rect = iterator.getRect();
431 reg.addRectUnchecked(rect.left, rect.top, rect.right, rect.bottom);
432 iterator.next();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800433 }
434 }
435
Robert Carre13b58e2017-08-31 14:50:44 -0700436 {
437 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
438 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800439 }
440}
441
Robert Carre13b58e2017-08-31 14:50:44 -0700442static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
443 jlong nativeObject, jfloat alpha) {
444 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
445
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800446 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700447 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800448}
449
Robert Carr788f5742018-07-30 17:46:45 -0700450static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
451 jlong nativeObject, jobject inputWindow) {
452 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
453
Riddle Hsucd958bc2019-01-23 15:40:26 +0800454 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
Robert Carr788f5742018-07-30 17:46:45 -0700455 env, inputWindow);
456 handle->updateInfo();
457
Vishnu Nairbc9beab2019-06-25 17:28:58 -0700458 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr788f5742018-07-30 17:46:45 -0700459 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
460}
461
chaviw319cd0782019-02-14 11:00:23 -0800462static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
463 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
464 transaction->syncInputWindows();
465}
466
Evan Rosky485df202018-12-06 14:11:12 -0800467static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
468 jlong nativeObject, jint id, jobject parcelObj) {
469 Parcel* parcel = parcelForJavaObject(env, parcelObj);
470 if (!parcel) {
471 jniThrowNullPointerException(env, "attribute data");
472 return;
473 }
474 if (parcel->objectsCount()) {
475 jniThrowException(env, "java/lang/RuntimeException",
476 "Tried to marshall a Parcel that contained Binder objects.");
477 return;
478 }
479
480 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
481
Evan Rosky485df202018-12-06 14:11:12 -0800482 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
Garfield Tan67e479a2019-08-05 16:47:40 -0700483 transaction->setMetadata(ctrl, id, *parcel);
Evan Rosky485df202018-12-06 14:11:12 -0800484}
485
Robert Carre13b58e2017-08-31 14:50:44 -0700486static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
487 jlong nativeObject, jfloatArray fColor) {
488 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700489 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700490
chaviw0dd03f52017-08-25 12:15:26 -0700491 float* floatColors = env->GetFloatArrayElements(fColor, 0);
492 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700493 transaction->setColor(ctrl, color);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800494 env->ReleaseFloatArrayElements(fColor, floatColors, 0);
chaviw0dd03f52017-08-25 12:15:26 -0700495}
496
Robert Carre13b58e2017-08-31 14:50:44 -0700497static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
498 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800499 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700500 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
501
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800502 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700503 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800504}
505
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700506static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
507 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
508 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
509 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
510 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
511 mat3 matrix(static_cast<float const*>(floatMatrix));
Vishnu Nair4a067c52019-11-19 14:25:56 -0800512 env->ReleaseFloatArrayElements(fMatrix, floatMatrix, 0);
513
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700514 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
515 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
Vishnu Nair4a067c52019-11-19 14:25:56 -0800516 env->ReleaseFloatArrayElements(fTranslation, floatTranslation, 0);
517
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700518 transaction->setColorTransform(surfaceControl, matrix, translation);
519}
520
Peiyong Linf4f0f642019-03-01 14:36:05 -0800521static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
522 jlong nativeObject, jboolean agnostic) {
523 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
524 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
525 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
526}
527
Robert Carre13b58e2017-08-31 14:50:44 -0700528static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
529 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800530 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700531 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
532
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800533 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
534 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700535 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800536}
537
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700538static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
539 jlong nativeObject, jfloat cornerRadius) {
540 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
541
542 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
543 transaction->setCornerRadius(ctrl, cornerRadius);
544}
545
Robert Carre13b58e2017-08-31 14:50:44 -0700546static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
547 jlong nativeObject, jint layerStack) {
548 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
549
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800550 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700551 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800552}
553
Vishnu Naird87984d2019-11-06 14:43:22 -0800554static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
555 jlong nativeObject, jfloat shadowRadius) {
556 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
557
558 const auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
559 transaction->setShadowRadius(ctrl, shadowRadius);
560}
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,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001103 jlong nativeObject, jlong barrierObject, jlong frameNumber) {
Rob Carr64e516f2015-10-29 00:20:45 +00001104 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001105 auto barrier = reinterpret_cast<SurfaceControl *>(barrierObject);
1106 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1107 transaction->deferTransactionUntil_legacy(ctrl, barrier->getHandle(), frameNumber);
Rob Carr64e516f2015-10-29 00:20:45 +00001108}
1109
Robert Carre13b58e2017-08-31 14:50:44 -07001110static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1111 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001112 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001113 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1114
Robert Carrd5c7dd62017-03-08 10:39:30 -08001115 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1116 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1117
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001118 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001119}
1120
Robert Carre13b58e2017-08-31 14:50:44 -07001121static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1122 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001123 jlong newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001124
Robert Carrd5c7dd62017-03-08 10:39:30 -08001125 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001126 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
1127 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1128 transaction->reparentChildren(ctrl, newParent->getHandle());
Robert Carrd5c7dd62017-03-08 10:39:30 -08001129}
1130
Robert Carre13b58e2017-08-31 14:50:44 -07001131static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1132 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001133 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001134 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001135 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001136 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1137 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
chaviw63542382017-08-17 17:39:29 -07001138}
1139
Robert Carre13b58e2017-08-31 14:50:44 -07001140static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1141 jlong nativeObject) {
1142 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1143
Robert Carrd5c7dd62017-03-08 10:39:30 -08001144 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001145 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001146}
1147
Robert Carre13b58e2017-08-31 14:50:44 -07001148static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1149 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001150 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001151 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001152
Robert Carre13b58e2017-08-31 14:50:44 -07001153 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1154 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001155}
1156
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001157static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1158 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1159 if (token == NULL) return NULL;
1160
1161 HdrCapabilities capabilities;
1162 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1163
1164 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001165 std::vector<int32_t> intTypes;
1166 for (auto type : types) {
1167 intTypes.push_back(static_cast<int32_t>(type));
1168 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001169 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001170 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001171
Michael Wright9ff94c02016-03-30 18:05:40 -07001172 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001173 typesArray, capabilities.getDesiredMaxLuminance(),
1174 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1175}
1176
Jorim Jaggi06975df2017-12-01 14:52:13 +01001177static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1178 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1179 if (parcel == NULL) {
1180 doThrowNPE(env);
1181 return 0;
1182 }
1183 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1184 if (surface == nullptr) {
1185 return 0;
1186 }
1187 surface->incStrong((void *)nativeCreate);
1188 return reinterpret_cast<jlong>(surface.get());
1189}
1190
chaviwbeb7a0c2018-12-05 13:49:54 -08001191static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1192 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1193 if (surface == nullptr) {
1194 return 0;
1195 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001196
1197 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1198 newSurface->incStrong((void *)nativeCreate);
1199 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001200}
1201
Jorim Jaggi06975df2017-12-01 14:52:13 +01001202static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1203 jlong nativeObject, jobject parcelObj) {
1204 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1205 if (parcel == NULL) {
1206 doThrowNPE(env);
1207 return;
1208 }
1209 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001210 if (self != nullptr) {
1211 self->writeToParcel(parcel);
1212 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001213}
1214
Dan Gittik832b4972019-02-13 18:17:47 +00001215static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1216 jobject displayTokenObject) {
1217 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1218 if (displayToken == nullptr) {
1219 return JNI_FALSE;
1220 }
1221 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1222}
1223
1224static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1225 jfloat brightness) {
1226 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1227 if (displayToken == nullptr) {
1228 return JNI_FALSE;
1229 }
1230 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1231 return error == OK ? JNI_TRUE : JNI_FALSE;
1232}
1233
Vishnu Nair629df2b2019-06-11 16:03:38 -07001234static void nativeWriteTransactionToParcel(JNIEnv* env, jclass clazz, jlong nativeObject,
1235 jobject parcelObj) {
1236 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1237 if (parcel == NULL) {
1238 doThrowNPE(env);
1239 return;
1240 }
1241 SurfaceComposerClient::Transaction* const self =
1242 reinterpret_cast<SurfaceComposerClient::Transaction *>(nativeObject);
1243 if (self != nullptr) {
1244 self->writeToParcel(parcel);
Vishnu Nairf7645aa2019-06-18 11:14:01 -07001245 self->clear();
Vishnu Nair629df2b2019-06-11 16:03:38 -07001246 }
1247}
1248
1249static jlong nativeReadTransactionFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1250 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1251 if (parcel == NULL) {
1252 doThrowNPE(env);
1253 return 0;
1254 }
1255 std::unique_ptr<SurfaceComposerClient::Transaction> transaction =
1256 SurfaceComposerClient::Transaction::createFromParcel(parcel);
1257
1258 return reinterpret_cast<jlong>(transaction.release());
1259}
1260
chaviwa51724f2019-09-19 09:50:11 -07001261static jlong nativeMirrorSurface(JNIEnv* env, jclass clazz, jlong mirrorOfObj) {
1262 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1263 SurfaceControl *mirrorOf = reinterpret_cast<SurfaceControl*>(mirrorOfObj);
1264 sp<SurfaceControl> surface = client->mirrorSurface(mirrorOf);
1265
1266 surface->incStrong((void *)nativeCreate);
1267 return reinterpret_cast<jlong>(surface.get());
1268}
1269
Vishnu Nair4a067c52019-11-19 14:25:56 -08001270static void nativeSetGlobalShadowSettings(JNIEnv* env, jclass clazz, jfloatArray jAmbientColor,
1271 jfloatArray jSpotColor, jfloat lightPosY, jfloat lightPosZ, jfloat lightRadius) {
1272 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1273
1274 float* floatAmbientColor = env->GetFloatArrayElements(jAmbientColor, 0);
1275 half4 ambientColor = half4(floatAmbientColor[0], floatAmbientColor[1], floatAmbientColor[2],
1276 floatAmbientColor[3]);
1277 env->ReleaseFloatArrayElements(jAmbientColor, floatAmbientColor, 0);
1278
1279 float* floatSpotColor = env->GetFloatArrayElements(jSpotColor, 0);
1280 half4 spotColor = half4(floatSpotColor[0], floatSpotColor[1], floatSpotColor[2],
1281 floatSpotColor[3]);
1282 env->ReleaseFloatArrayElements(jSpotColor, floatSpotColor, 0);
1283
1284 client->setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ, lightRadius);
1285}
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001286// ----------------------------------------------------------------------------
1287
Daniel Micay76f6a862015-09-19 17:31:01 -04001288static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001289 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001290 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001291 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1292 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001293 {"nativeCopyFromSurfaceControl", "(J)J" ,
1294 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001295 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1296 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001297 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001298 (void*)nativeRelease },
Chong Zhang47e36a32016-02-29 16:44:33 -08001299 {"nativeDisconnect", "(J)V",
1300 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001301 {"nativeCreateTransaction", "()J",
1302 (void*)nativeCreateTransaction },
1303 {"nativeApplyTransaction", "(JZ)V",
1304 (void*)nativeApplyTransaction },
1305 {"nativeGetNativeTransactionFinalizer", "()J",
1306 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001307 {"nativeMergeTransaction", "(JJ)V",
1308 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001309 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001310 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001311 {"nativeSetEarlyWakeup", "(J)V",
1312 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001313 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001314 (void*)nativeSetLayer },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001315 {"nativeSetRelativeLayer", "(JJJI)V",
Robert Carraf422a82017-04-10 18:34:33 -07001316 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001317 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001318 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001319 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001320 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001321 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001322 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001323 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001324 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001325 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001326 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001327 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001328 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001329 {"nativeSetColorTransform", "(JJ[F[F)V",
1330 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001331 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1332 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001333 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001334 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001335 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001336 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001337 {"nativeSetCornerRadius", "(JJF)V",
1338 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001339 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001340 (void*)nativeSetLayerStack },
Vishnu Naird87984d2019-11-06 14:43:22 -08001341 {"nativeSetShadowRadius", "(JJF)V",
1342 (void*)nativeSetShadowRadius },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001343 {"nativeGetPhysicalDisplayIds", "()[J",
1344 (void*)nativeGetPhysicalDisplayIds },
1345 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1346 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001347 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1348 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001349 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1350 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001351 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001352 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001353 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001354 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001355 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001356 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001357 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001358 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001359 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1360 (void*)nativeGetDisplayConfigs },
1361 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1362 (void*)nativeGetActiveConfig },
1363 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1364 (void*)nativeSetActiveConfig },
Ady Abraham6070ce12019-01-24 18:48:58 -08001365 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1366 (void*)nativeSetAllowedDisplayConfigs },
Ady Abraham42f9a2fb2019-02-26 14:13:39 -08001367 {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
1368 (void*)nativeGetAllowedDisplayConfigs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001369 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1370 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001371 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1372 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001373 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1374 (void*)nativeGetActiveColorMode},
1375 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1376 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001377 {"nativeGetCompositionDataspaces", "()[I",
1378 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001379 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1380 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001381 {"nativeClearContentFrameStats", "(J)Z",
1382 (void*)nativeClearContentFrameStats },
1383 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1384 (void*)nativeGetContentFrameStats },
1385 {"nativeClearAnimationFrameStats", "()Z",
1386 (void*)nativeClearAnimationFrameStats },
1387 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1388 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001389 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1390 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001391 {"nativeGetProtectedContentSupport", "()Z",
1392 (void*)nativeGetProtectedContentSupport },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001393 {"nativeDeferTransactionUntil", "(JJJJ)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001394 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001395 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001396 (void*)nativeDeferTransactionUntilSurface },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001397 {"nativeReparentChildren", "(JJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001398 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001399 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001400 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001401 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001402 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001403 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001404 (void*)nativeSetOverrideScalingMode },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001405 {"nativeScreenshot",
1406 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1407 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001408 (void*)nativeScreenshot },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001409 {"nativeCaptureLayers",
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001410 "(Landroid/os/IBinder;JLandroid/graphics/Rect;"
Chiawei Wang02202d12019-01-03 18:12:13 +08001411 "F[JI)"
Peiyong Line3e5efd2019-03-21 20:59:47 +00001412 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001413 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001414 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001415 (void*)nativeSetInputWindowInfo },
Evan Roskyb51e2462019-04-03 19:27:18 -07001416 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
Evan Rosky485df202018-12-06 14:11:12 -08001417 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001418 {"nativeGetDisplayedContentSamplingAttributes",
1419 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1420 (void*)nativeGetDisplayedContentSamplingAttributes },
1421 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1422 (void*)nativeSetDisplayedContentSamplingEnabled },
1423 {"nativeGetDisplayedContentSample",
1424 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1425 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001426 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001427 (void*)nativeSetGeometry },
1428 {"nativeSyncInputWindows", "(J)V",
Dan Gittik832b4972019-02-13 18:17:47 +00001429 (void*)nativeSyncInputWindows },
1430 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1431 (void*)nativeGetDisplayBrightnessSupport },
1432 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1433 (void*)nativeSetDisplayBrightness },
Vishnu Nair629df2b2019-06-11 16:03:38 -07001434 {"nativeReadTransactionFromParcel", "(Landroid/os/Parcel;)J",
1435 (void*)nativeReadTransactionFromParcel },
1436 {"nativeWriteTransactionToParcel", "(JLandroid/os/Parcel;)V",
1437 (void*)nativeWriteTransactionToParcel },
chaviwa51724f2019-09-19 09:50:11 -07001438 {"nativeMirrorSurface", "(J)J",
1439 (void*)nativeMirrorSurface },
Vishnu Nair4a067c52019-11-19 14:25:56 -08001440 {"nativeSetGlobalShadowSettings", "([F[FFFF)V",
1441 (void*)nativeSetGlobalShadowSettings },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001442};
1443
1444int register_android_view_SurfaceControl(JNIEnv* env)
1445{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001446 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001447 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1448
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001449 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1450 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1451 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1452 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1453 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1454 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1455 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1456 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1457 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1458 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1459 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1460 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1461 clazz, "appVsyncOffsetNanos", "J");
1462 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1463 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001464
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001465 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1466 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1467 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1468 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1469 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001470
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001471 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1472 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1473 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001474 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1475
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001476 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1477 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1478 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001479 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1480
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001481 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1482 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1483 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001484 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1485
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001486 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1487 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1488 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1489 "([IFFF)V");
1490
Robert Carr6486d312017-01-09 19:48:29 -08001491 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1492 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1493 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1494 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1495
Peiyong Line3e5efd2019-03-21 20:59:47 +00001496 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1497 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1498 gScreenshotGraphicBufferClassInfo.clazz =
1499 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1500 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1501 screenshotGraphicsBufferClazz,
Robert Carr66b5664f2019-04-02 14:18:56 -07001502 "createFromNative", "(IIIIJIZ)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
Peiyong Line3e5efd2019-03-21 20:59:47 +00001503
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001504 jclass displayedContentSampleClazz = FindClassOrDie(env,
1505 "android/hardware/display/DisplayedContentSample");
1506 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1507 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1508 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1509
1510 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1511 "android/hardware/display/DisplayedContentSamplingAttributes");
1512 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1513 displayedContentSamplingAttributesClazz);
1514 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1515 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001516
1517 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1518 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1519 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1520 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1521 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1522 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1523
1524 jclass displayPrimariesClazz = FindClassOrDie(env,
1525 "android/view/SurfaceControl$DisplayPrimaries");
1526 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1527 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1528 "<init>", "()V");
1529 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1530 "Landroid/view/SurfaceControl$CieXyz;");
1531 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1532 "Landroid/view/SurfaceControl$CieXyz;");
1533 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1534 "Landroid/view/SurfaceControl$CieXyz;");
1535 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1536 "Landroid/view/SurfaceControl$CieXyz;");
1537
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001538 return err;
1539}
1540
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001541} // namespace android