blob: f8a2744fdcb03765109c036a7ca70ce620e6864c [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);
chaviw0dd03f52017-08-25 12:15:26 -0700494}
495
Robert Carre13b58e2017-08-31 14:50:44 -0700496static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
497 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800498 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700499 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
500
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800501 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700502 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800503}
504
Peiyong Lin52bb6b42018-10-01 11:40:50 -0700505static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
506 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
507 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
508 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
509 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
510 mat3 matrix(static_cast<float const*>(floatMatrix));
511 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
512 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
513 transaction->setColorTransform(surfaceControl, matrix, translation);
514}
515
Peiyong Linf4f0f642019-03-01 14:36:05 -0800516static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
517 jlong nativeObject, jboolean agnostic) {
518 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
519 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
520 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
521}
522
Robert Carre13b58e2017-08-31 14:50:44 -0700523static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
524 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800525 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700526 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
527
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800528 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
529 Rect crop(l, t, r, b);
Marissa Wallcb32fdd2018-07-24 09:53:30 -0700530 transaction->setCrop_legacy(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800531}
532
Lucas Dupinff9d6ab2018-10-16 18:05:50 -0700533static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
534 jlong nativeObject, jfloat cornerRadius) {
535 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
536
537 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
538 transaction->setCornerRadius(ctrl, cornerRadius);
539}
540
Robert Carre13b58e2017-08-31 14:50:44 -0700541static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
542 jlong nativeObject, jint layerStack) {
543 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
544
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800545 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700546 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800547}
548
Vishnu Naird87984d2019-11-06 14:43:22 -0800549static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
550 jlong nativeObject, jfloat shadowRadius) {
551 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
552
553 const auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
554 transaction->setShadowRadius(ctrl, shadowRadius);
555}
556
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800557static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
558 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
559 jlongArray array = env->NewLongArray(displayIds.size());
560 if (array == nullptr) {
561 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
562 return nullptr;
563 }
564
565 if (displayIds.empty()) {
566 return array;
567 }
568
569 jlong* values = env->GetLongArrayElements(array, 0);
570 for (size_t i = 0; i < displayIds.size(); ++i) {
571 values[i] = static_cast<jlong>(displayIds[i]);
572 }
573
574 env->ReleaseLongArrayElements(array, values, 0);
575 return array;
576}
577
578static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
579 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800580 return javaObjectForIBinder(env, token);
581}
582
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700583static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
584 jobject tokenObj) {
585 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
586
587 ui::PixelFormat format;
588 ui::Dataspace dataspace;
589 uint8_t componentMask;
590 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
591 token, &format, &dataspace, &componentMask);
592 if (err != OK) {
593 return nullptr;
594 }
595 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
596 gDisplayedContentSamplingAttributesClassInfo.ctor,
597 format, dataspace, componentMask);
598}
599
600static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
601 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
602 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Kevin DuBois205a6802019-01-07 17:04:46 -0800603 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700604 token, enable, componentMask, maxFrames);
Kevin DuBois205a6802019-01-07 17:04:46 -0800605 return rc == OK;
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -0700606}
607
608static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
609 jlong maxFrames, jlong timestamp) {
610 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
611
612 DisplayedFrameStats stats;
613 status_t err = SurfaceComposerClient::getDisplayedContentSample(
614 token, maxFrames, timestamp, &stats);
615 if (err != OK) {
616 return nullptr;
617 }
618
619 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
620 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
621 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
622 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
623 if ((histogramComponent0 == nullptr) ||
624 (histogramComponent1 == nullptr) ||
625 (histogramComponent2 == nullptr) ||
626 (histogramComponent3 == nullptr)) {
627 return JNI_FALSE;
628 }
629
630 env->SetLongArrayRegion(histogramComponent0, 0,
631 stats.component_0_sample.size(),
632 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
633 env->SetLongArrayRegion(histogramComponent1, 0,
634 stats.component_1_sample.size(),
635 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
636 env->SetLongArrayRegion(histogramComponent2, 0,
637 stats.component_2_sample.size(),
638 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
639 env->SetLongArrayRegion(histogramComponent3, 0,
640 stats.component_3_sample.size(),
641 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
642 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
643 gDisplayedContentSampleClassInfo.ctor,
644 stats.numFrames,
645 histogramComponent0,
646 histogramComponent1,
647 histogramComponent2,
648 histogramComponent3);
649}
650
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800651static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
652 jboolean secure) {
653 ScopedUtfChars name(env, nameObj);
654 sp<IBinder> token(SurfaceComposerClient::createDisplay(
655 String8(name.c_str()), bool(secure)));
656 return javaObjectForIBinder(env, token);
657}
658
Jesse Hall6a6bc212013-08-08 12:15:03 -0700659static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
660 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
661 if (token == NULL) return;
662 SurfaceComposerClient::destroyDisplay(token);
663}
664
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800665static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700666 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000667 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800668 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
669 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800670 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800671 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800672 if (sur != NULL) {
673 bufferProducer = sur->getIGraphicBufferProducer();
674 }
Robert Carre13b58e2017-08-31 14:50:44 -0700675
676
677 status_t err = NO_ERROR;
678 {
679 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
680 err = transaction->setDisplaySurface(token,
681 bufferProducer);
682 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700683 if (err != NO_ERROR) {
684 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
685 " Surface created with singleBufferMode?");
686 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800687}
688
689static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700690 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800691 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700692
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800693 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
694 if (token == NULL) return;
695
Robert Carre13b58e2017-08-31 14:50:44 -0700696 {
697 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
698 transaction->setDisplayLayerStack(token, layerStack);
699 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800700}
701
702static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700703 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800704 jobject tokenObj, jint orientation,
705 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
706 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
707 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
708 if (token == NULL) return;
709 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
710 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700711
712 {
713 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
714 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
715 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800716}
717
Michael Wright01e840f2014-06-26 16:03:25 -0700718static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700719 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700720 jobject tokenObj, jint width, jint height) {
721 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
722 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700723
724 {
725 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
726 transaction->setDisplaySize(token, width, height);
727 }
Michael Wright01e840f2014-06-26 16:03:25 -0700728}
729
Dan Stoza00101052014-05-02 15:23:40 -0700730static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
731 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800732 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700733 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800734
Dan Stoza00101052014-05-02 15:23:40 -0700735 Vector<DisplayInfo> configs;
736 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
737 configs.size() == 0) {
738 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800739 }
740
Dan Stoza00101052014-05-02 15:23:40 -0700741 jobjectArray configArray = env->NewObjectArray(configs.size(),
742 gPhysicalDisplayInfoClassInfo.clazz, NULL);
743
744 for (size_t c = 0; c < configs.size(); ++c) {
745 const DisplayInfo& info = configs[c];
746 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
747 gPhysicalDisplayInfoClassInfo.ctor);
748 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
749 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
750 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
751 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
752 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
753 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
754 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700755 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
756 info.appVsyncOffset);
757 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
758 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700759 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
760 env->DeleteLocalRef(infoObj);
761 }
762
763 return configArray;
764}
765
Ady Abraham6070ce12019-01-24 18:48:58 -0800766static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
767 jobject tokenObj, jintArray configArray) {
768 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
769 if (token == nullptr) return JNI_FALSE;
770
771 std::vector<int32_t> allowedConfigs;
772 jsize configArraySize = env->GetArrayLength(configArray);
773 allowedConfigs.reserve(configArraySize);
774
775 jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
776 for (int i = 0; i < configArraySize; i++) {
777 allowedConfigs.push_back(configArrayElements[i]);
778 }
779 env->ReleaseIntArrayElements(configArray, configArrayElements, 0);
780
781 size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
782 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
783}
784
Ady Abraham42f9a2fb2019-02-26 14:13:39 -0800785static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
786 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
787 if (token == nullptr) return JNI_FALSE;
788
789 std::vector<int32_t> allowedConfigs;
790 size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs);
791 if (result != NO_ERROR) {
792 return nullptr;
793 }
794
795 jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size());
796 if (allowedConfigsArray == nullptr) {
797 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
798 return nullptr;
799 }
800 jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0);
801 for (size_t i = 0; i < allowedConfigs.size(); i++) {
802 allowedConfigsArrayValues[i] = static_cast<jint>(allowedConfigs[i]);
803 }
804 env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0);
805 return allowedConfigsArray;
806}
807
Dan Stoza00101052014-05-02 15:23:40 -0700808static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
809 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
810 if (token == NULL) return -1;
811 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
812}
813
814static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
815 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
816 if (token == NULL) return JNI_FALSE;
817 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
818 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800819}
820
Michael Wright1c9977b2016-07-12 13:30:10 -0700821static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
822 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
823 if (token == NULL) return NULL;
Peiyong Linb88549e2018-03-28 12:03:45 -0700824 Vector<ui::ColorMode> colorModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700825 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
826 colorModes.isEmpty()) {
827 return NULL;
828 }
829
830 jintArray colorModesArray = env->NewIntArray(colorModes.size());
831 if (colorModesArray == NULL) {
832 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
833 return NULL;
834 }
835 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
836 for (size_t i = 0; i < colorModes.size(); i++) {
837 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
838 }
839 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
840 return colorModesArray;
841}
842
Daniel Solomon10e3b332019-01-20 21:09:11 -0800843static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
844 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
845 if (token == NULL) return NULL;
846
847 ui::DisplayPrimaries primaries;
848 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
849 return NULL;
850 }
851
852 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
853 if (jred == NULL) {
854 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
855 return NULL;
856 }
857
858 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
859 if (jgreen == NULL) {
860 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
861 return NULL;
862 }
863
864 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
865 if (jblue == NULL) {
866 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
867 return NULL;
868 }
869
870 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
871 if (jwhite == NULL) {
872 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
873 return NULL;
874 }
875
876 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
877 gDisplayPrimariesClassInfo.ctor);
878 if (jprimaries == NULL) {
879 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
880 return NULL;
881 }
882
883 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
884 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
885 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
886 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
887 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
888 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
889 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
890 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
891 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
892 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
893 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
894 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
895 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
896 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
897 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
898 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
899
900 return jprimaries;
901}
902
Michael Wright1c9977b2016-07-12 13:30:10 -0700903static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
904 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
905 if (token == NULL) return -1;
906 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
907}
908
Peiyong Lin5f4a5682019-01-17 11:37:07 -0800909static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
910 ui::Dataspace defaultDataspace, wcgDataspace;
911 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
912 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
913 &defaultPixelFormat,
914 &wcgDataspace,
915 &wcgPixelFormat) != NO_ERROR) {
916 return nullptr;
917 }
918 jintArray array = env->NewIntArray(2);
919 if (array == nullptr) {
920 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
921 return nullptr;
922 }
923 jint* arrayValues = env->GetIntArrayElements(array, 0);
924 arrayValues[0] = static_cast<jint>(defaultDataspace);
925 arrayValues[1] = static_cast<jint>(wcgDataspace);
926 env->ReleaseIntArrayElements(array, arrayValues, 0);
927 return array;
928}
929
Michael Wright1c9977b2016-07-12 13:30:10 -0700930static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
931 jobject tokenObj, jint colorMode) {
932 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
933 if (token == NULL) return JNI_FALSE;
934 status_t err = SurfaceComposerClient::setActiveColorMode(token,
Peiyong Linb88549e2018-03-28 12:03:45 -0700935 static_cast<ui::ColorMode>(colorMode));
Michael Wright1c9977b2016-07-12 13:30:10 -0700936 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
937}
938
Prashant Malanic55929a2014-05-25 01:59:21 -0700939static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800940 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
941 if (token == NULL) return;
942
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700943 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700944 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700945 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800946}
947
Peiyong Lin0ddb7d42019-01-16 13:25:09 -0800948static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
949 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
950}
951
Svetoslav1376d602014-03-13 11:17:26 -0700952static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
953 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
954 status_t err = ctrl->clearLayerFrameStats();
955
956 if (err < 0 && err != NO_INIT) {
957 doThrowIAE(env);
958 }
959
960 // The other end is not ready, just report we failed.
961 if (err == NO_INIT) {
962 return JNI_FALSE;
963 }
964
965 return JNI_TRUE;
966}
967
968static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
969 jobject outStats) {
970 FrameStats stats;
971
972 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
973 status_t err = ctrl->getLayerFrameStats(&stats);
974 if (err < 0 && err != NO_INIT) {
975 doThrowIAE(env);
976 }
977
978 // The other end is not ready, fine just return empty stats.
979 if (err == NO_INIT) {
980 return JNI_FALSE;
981 }
982
983 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
984 size_t frameCount = stats.desiredPresentTimesNano.size();
985
986 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
987 if (postedTimesNanoDst == NULL) {
988 return JNI_FALSE;
989 }
990
991 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
992 if (presentedTimesNanoDst == NULL) {
993 return JNI_FALSE;
994 }
995
996 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
997 if (readyTimesNanoDst == NULL) {
998 return JNI_FALSE;
999 }
1000
1001 nsecs_t postedTimesNanoSrc[frameCount];
1002 nsecs_t presentedTimesNanoSrc[frameCount];
1003 nsecs_t readyTimesNanoSrc[frameCount];
1004
1005 for (size_t i = 0; i < frameCount; i++) {
1006 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
1007 if (postedTimeNano == INT64_MAX) {
1008 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1009 }
1010 postedTimesNanoSrc[i] = postedTimeNano;
1011
1012 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1013 if (presentedTimeNano == INT64_MAX) {
1014 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1015 }
1016 presentedTimesNanoSrc[i] = presentedTimeNano;
1017
1018 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
1019 if (readyTimeNano == INT64_MAX) {
1020 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1021 }
1022 readyTimesNanoSrc[i] = readyTimeNano;
1023 }
1024
1025 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
1026 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1027 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
1028
1029 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
1030 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
1031
1032 if (env->ExceptionCheck()) {
1033 return JNI_FALSE;
1034 }
1035
1036 return JNI_TRUE;
1037}
1038
1039static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
1040 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
1041
1042 if (err < 0 && err != NO_INIT) {
1043 doThrowIAE(env);
1044 }
1045
1046 // The other end is not ready, just report we failed.
1047 if (err == NO_INIT) {
1048 return JNI_FALSE;
1049 }
1050
1051 return JNI_TRUE;
1052}
1053
1054static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
1055 FrameStats stats;
1056
1057 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1058 if (err < 0 && err != NO_INIT) {
1059 doThrowIAE(env);
1060 }
1061
1062 // The other end is not ready, fine just return empty stats.
1063 if (err == NO_INIT) {
1064 return JNI_FALSE;
1065 }
1066
1067 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1068 size_t frameCount = stats.desiredPresentTimesNano.size();
1069
1070 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1071 if (presentedTimesNanoDst == NULL) {
1072 return JNI_FALSE;
1073 }
1074
1075 nsecs_t presentedTimesNanoSrc[frameCount];
1076
1077 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -07001078 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -07001079 if (presentedTimeNano == INT64_MAX) {
1080 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1081 }
1082 presentedTimesNanoSrc[i] = presentedTimeNano;
1083 }
1084
1085 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1086
1087 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1088 presentedTimesNanoDst);
1089
1090 if (env->ExceptionCheck()) {
1091 return JNI_FALSE;
1092 }
1093
1094 return JNI_TRUE;
1095}
1096
Robert Carre13b58e2017-08-31 14:50:44 -07001097static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001098 jlong nativeObject, jlong barrierObject, jlong frameNumber) {
Rob Carr64e516f2015-10-29 00:20:45 +00001099 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001100 auto barrier = reinterpret_cast<SurfaceControl *>(barrierObject);
1101 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1102 transaction->deferTransactionUntil_legacy(ctrl, barrier->getHandle(), frameNumber);
Rob Carr64e516f2015-10-29 00:20:45 +00001103}
1104
Robert Carre13b58e2017-08-31 14:50:44 -07001105static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1106 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -08001107 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -07001108 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1109
Robert Carrd5c7dd62017-03-08 10:39:30 -08001110 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1111 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1112
Marissa Wallcb32fdd2018-07-24 09:53:30 -07001113 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001114}
1115
Robert Carre13b58e2017-08-31 14:50:44 -07001116static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1117 jlong nativeObject,
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001118 jlong newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -07001119
Robert Carrd5c7dd62017-03-08 10:39:30 -08001120 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001121 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
1122 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1123 transaction->reparentChildren(ctrl, newParent->getHandle());
Robert Carrd5c7dd62017-03-08 10:39:30 -08001124}
1125
Robert Carre13b58e2017-08-31 14:50:44 -07001126static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1127 jlong nativeObject,
Robert Carr10584fa2019-01-14 15:55:19 -08001128 jlong newParentObject) {
chaviw63542382017-08-17 17:39:29 -07001129 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr10584fa2019-01-14 15:55:19 -08001130 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001131 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1132 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
chaviw63542382017-08-17 17:39:29 -07001133}
1134
Robert Carre13b58e2017-08-31 14:50:44 -07001135static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1136 jlong nativeObject) {
1137 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1138
Robert Carrd5c7dd62017-03-08 10:39:30 -08001139 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -07001140 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -08001141}
1142
Robert Carre13b58e2017-08-31 14:50:44 -07001143static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1144 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -07001145 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -07001146 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -07001147
Robert Carre13b58e2017-08-31 14:50:44 -07001148 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1149 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -07001150}
1151
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001152static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1153 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1154 if (token == NULL) return NULL;
1155
1156 HdrCapabilities capabilities;
1157 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1158
1159 const auto& types = capabilities.getSupportedHdrTypes();
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001160 std::vector<int32_t> intTypes;
1161 for (auto type : types) {
1162 intTypes.push_back(static_cast<int32_t>(type));
1163 }
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001164 auto typesArray = env->NewIntArray(types.size());
Peiyong Lin3a0c6e12018-04-16 11:05:29 -07001165 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001166
Michael Wright9ff94c02016-03-30 18:05:40 -07001167 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001168 typesArray, capabilities.getDesiredMaxLuminance(),
1169 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1170}
1171
Jorim Jaggi06975df2017-12-01 14:52:13 +01001172static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1173 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1174 if (parcel == NULL) {
1175 doThrowNPE(env);
1176 return 0;
1177 }
1178 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1179 if (surface == nullptr) {
1180 return 0;
1181 }
1182 surface->incStrong((void *)nativeCreate);
1183 return reinterpret_cast<jlong>(surface.get());
1184}
1185
chaviwbeb7a0c2018-12-05 13:49:54 -08001186static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1187 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1188 if (surface == nullptr) {
1189 return 0;
1190 }
Robert Carr5fea55b2018-12-10 13:05:52 -08001191
1192 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1193 newSurface->incStrong((void *)nativeCreate);
1194 return reinterpret_cast<jlong>(newSurface.get());
chaviwbeb7a0c2018-12-05 13:49:54 -08001195}
1196
Jorim Jaggi06975df2017-12-01 14:52:13 +01001197static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1198 jlong nativeObject, jobject parcelObj) {
1199 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1200 if (parcel == NULL) {
1201 doThrowNPE(env);
1202 return;
1203 }
1204 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
chaviwbeb7a0c2018-12-05 13:49:54 -08001205 if (self != nullptr) {
1206 self->writeToParcel(parcel);
1207 }
Jorim Jaggi06975df2017-12-01 14:52:13 +01001208}
1209
Dan Gittik832b4972019-02-13 18:17:47 +00001210static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1211 jobject displayTokenObject) {
1212 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1213 if (displayToken == nullptr) {
1214 return JNI_FALSE;
1215 }
1216 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1217}
1218
1219static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1220 jfloat brightness) {
1221 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1222 if (displayToken == nullptr) {
1223 return JNI_FALSE;
1224 }
1225 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1226 return error == OK ? JNI_TRUE : JNI_FALSE;
1227}
1228
Vishnu Nair629df2b2019-06-11 16:03:38 -07001229static void nativeWriteTransactionToParcel(JNIEnv* env, jclass clazz, jlong nativeObject,
1230 jobject parcelObj) {
1231 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1232 if (parcel == NULL) {
1233 doThrowNPE(env);
1234 return;
1235 }
1236 SurfaceComposerClient::Transaction* const self =
1237 reinterpret_cast<SurfaceComposerClient::Transaction *>(nativeObject);
1238 if (self != nullptr) {
1239 self->writeToParcel(parcel);
Vishnu Nairf7645aa2019-06-18 11:14:01 -07001240 self->clear();
Vishnu Nair629df2b2019-06-11 16:03:38 -07001241 }
1242}
1243
1244static jlong nativeReadTransactionFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1245 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1246 if (parcel == NULL) {
1247 doThrowNPE(env);
1248 return 0;
1249 }
1250 std::unique_ptr<SurfaceComposerClient::Transaction> transaction =
1251 SurfaceComposerClient::Transaction::createFromParcel(parcel);
1252
1253 return reinterpret_cast<jlong>(transaction.release());
1254}
1255
chaviwa51724f2019-09-19 09:50:11 -07001256static jlong nativeMirrorSurface(JNIEnv* env, jclass clazz, jlong mirrorOfObj) {
1257 sp<SurfaceComposerClient> client = SurfaceComposerClient::getDefault();
1258 SurfaceControl *mirrorOf = reinterpret_cast<SurfaceControl*>(mirrorOfObj);
1259 sp<SurfaceControl> surface = client->mirrorSurface(mirrorOf);
1260
1261 surface->incStrong((void *)nativeCreate);
1262 return reinterpret_cast<jlong>(surface.get());
1263}
1264
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001265// ----------------------------------------------------------------------------
1266
Daniel Micay76f6a862015-09-19 17:31:01 -04001267static const JNINativeMethod sSurfaceControlMethods[] = {
Evan Rosky485df202018-12-06 14:11:12 -08001268 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001269 (void*)nativeCreate },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001270 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1271 (void*)nativeReadFromParcel },
chaviwbeb7a0c2018-12-05 13:49:54 -08001272 {"nativeCopyFromSurfaceControl", "(J)J" ,
1273 (void*)nativeCopyFromSurfaceControl },
Jorim Jaggi06975df2017-12-01 14:52:13 +01001274 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1275 (void*)nativeWriteToParcel },
Ashok Bhat36bef0b2014-01-20 20:08:01 +00001276 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001277 (void*)nativeRelease },
Chong Zhang47e36a32016-02-29 16:44:33 -08001278 {"nativeDisconnect", "(J)V",
1279 (void*)nativeDisconnect },
Robert Carre13b58e2017-08-31 14:50:44 -07001280 {"nativeCreateTransaction", "()J",
1281 (void*)nativeCreateTransaction },
1282 {"nativeApplyTransaction", "(JZ)V",
1283 (void*)nativeApplyTransaction },
1284 {"nativeGetNativeTransactionFinalizer", "()J",
1285 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -07001286 {"nativeMergeTransaction", "(JJ)V",
1287 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -07001288 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001289 (void*)nativeSetAnimationTransaction },
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001290 {"nativeSetEarlyWakeup", "(J)V",
1291 (void*)nativeSetEarlyWakeup },
Robert Carre13b58e2017-08-31 14:50:44 -07001292 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001293 (void*)nativeSetLayer },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001294 {"nativeSetRelativeLayer", "(JJJI)V",
Robert Carraf422a82017-04-10 18:34:33 -07001295 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -07001296 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001297 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -07001298 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001299 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -07001300 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001301 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -07001302 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001303 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -07001304 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -07001305 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -07001306 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001307 (void*)nativeSetMatrix },
Peiyong Lin52bb6b42018-10-01 11:40:50 -07001308 {"nativeSetColorTransform", "(JJ[F[F)V",
1309 (void*)nativeSetColorTransform },
Peiyong Linf4f0f642019-03-01 14:36:05 -08001310 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1311 (void*)nativeSetColorSpaceAgnostic },
Robert Carre13b58e2017-08-31 14:50:44 -07001312 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001313 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -07001314 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001315 (void*)nativeSetWindowCrop },
Lucas Dupinff9d6ab2018-10-16 18:05:50 -07001316 {"nativeSetCornerRadius", "(JJF)V",
1317 (void*)nativeSetCornerRadius },
Robert Carre13b58e2017-08-31 14:50:44 -07001318 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001319 (void*)nativeSetLayerStack },
Vishnu Naird87984d2019-11-06 14:43:22 -08001320 {"nativeSetShadowRadius", "(JJF)V",
1321 (void*)nativeSetShadowRadius },
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001322 {"nativeGetPhysicalDisplayIds", "()[J",
1323 (void*)nativeGetPhysicalDisplayIds },
1324 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1325 (void*)nativeGetPhysicalDisplayToken },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001326 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1327 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -07001328 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1329 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -07001330 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001331 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001332 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001333 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -07001334 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001335 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -07001336 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -07001337 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -07001338 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1339 (void*)nativeGetDisplayConfigs },
1340 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1341 (void*)nativeGetActiveConfig },
1342 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1343 (void*)nativeSetActiveConfig },
Ady Abraham6070ce12019-01-24 18:48:58 -08001344 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1345 (void*)nativeSetAllowedDisplayConfigs },
Ady Abraham42f9a2fb2019-02-26 14:13:39 -08001346 {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
1347 (void*)nativeGetAllowedDisplayConfigs },
Michael Wright1c9977b2016-07-12 13:30:10 -07001348 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1349 (void*)nativeGetDisplayColorModes},
Daniel Solomon10e3b332019-01-20 21:09:11 -08001350 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1351 (void*)nativeGetDisplayNativePrimaries },
Michael Wright1c9977b2016-07-12 13:30:10 -07001352 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1353 (void*)nativeGetActiveColorMode},
1354 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1355 (void*)nativeSetActiveColorMode},
Peiyong Lin5f4a5682019-01-17 11:37:07 -08001356 {"nativeGetCompositionDataspaces", "()[I",
1357 (void*)nativeGetCompositionDataspaces},
Michael Wright9ff94c02016-03-30 18:05:40 -07001358 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1359 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -07001360 {"nativeClearContentFrameStats", "(J)Z",
1361 (void*)nativeClearContentFrameStats },
1362 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1363 (void*)nativeGetContentFrameStats },
1364 {"nativeClearAnimationFrameStats", "()Z",
1365 (void*)nativeClearAnimationFrameStats },
1366 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1367 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -07001368 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1369 (void*)nativeSetDisplayPowerMode },
Peiyong Lin0ddb7d42019-01-16 13:25:09 -08001370 {"nativeGetProtectedContentSupport", "()Z",
1371 (void*)nativeGetProtectedContentSupport },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001372 {"nativeDeferTransactionUntil", "(JJJJ)V",
Rob Carr64e516f2015-10-29 00:20:45 +00001373 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -07001374 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001375 (void*)nativeDeferTransactionUntilSurface },
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001376 {"nativeReparentChildren", "(JJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001377 (void*)nativeReparentChildren } ,
Robert Carr10584fa2019-01-14 15:55:19 -08001378 {"nativeReparent", "(JJJ)V",
chaviw76431402017-09-18 16:50:05 -07001379 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001380 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001381 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001382 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001383 (void*)nativeSetOverrideScalingMode },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001384 {"nativeScreenshot",
1385 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1386 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
chaviw08520a02018-09-10 16:44:56 -07001387 (void*)nativeScreenshot },
Peiyong Line3e5efd2019-03-21 20:59:47 +00001388 {"nativeCaptureLayers",
Vishnu Nairbc9beab2019-06-25 17:28:58 -07001389 "(Landroid/os/IBinder;JLandroid/graphics/Rect;"
Chiawei Wang02202d12019-01-03 18:12:13 +08001390 "F[JI)"
Peiyong Line3e5efd2019-03-21 20:59:47 +00001391 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
Chavi Weingartend7ec64c2017-11-30 01:52:01 +00001392 (void*)nativeCaptureLayers },
Robert Carr788f5742018-07-30 17:46:45 -07001393 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
chaviw59f532e2018-12-26 15:34:59 -08001394 (void*)nativeSetInputWindowInfo },
Evan Roskyb51e2462019-04-03 19:27:18 -07001395 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
Evan Rosky485df202018-12-06 14:11:12 -08001396 (void*)nativeSetMetadata },
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001397 {"nativeGetDisplayedContentSamplingAttributes",
1398 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1399 (void*)nativeGetDisplayedContentSamplingAttributes },
1400 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1401 (void*)nativeSetDisplayedContentSamplingEnabled },
1402 {"nativeGetDisplayedContentSample",
1403 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1404 (void*)nativeGetDisplayedContentSample },
Robert Carr76907ee2019-01-11 13:38:19 -08001405 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
chaviw319cd0782019-02-14 11:00:23 -08001406 (void*)nativeSetGeometry },
1407 {"nativeSyncInputWindows", "(J)V",
Dan Gittik832b4972019-02-13 18:17:47 +00001408 (void*)nativeSyncInputWindows },
1409 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1410 (void*)nativeGetDisplayBrightnessSupport },
1411 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1412 (void*)nativeSetDisplayBrightness },
Vishnu Nair629df2b2019-06-11 16:03:38 -07001413 {"nativeReadTransactionFromParcel", "(Landroid/os/Parcel;)J",
1414 (void*)nativeReadTransactionFromParcel },
1415 {"nativeWriteTransactionToParcel", "(JLandroid/os/Parcel;)V",
1416 (void*)nativeWriteTransactionToParcel },
chaviwa51724f2019-09-19 09:50:11 -07001417 {"nativeMirrorSurface", "(J)J",
1418 (void*)nativeMirrorSurface },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001419};
1420
1421int register_android_view_SurfaceControl(JNIEnv* env)
1422{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001423 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001424 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1425
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001426 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1427 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1428 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1429 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1430 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1431 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1432 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1433 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1434 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1435 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1436 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1437 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1438 clazz, "appVsyncOffsetNanos", "J");
1439 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1440 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001441
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001442 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1443 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1444 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1445 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1446 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001447
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001448 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1449 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1450 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001451 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1452
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001453 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1454 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1455 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001456 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1457
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001458 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1459 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1460 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001461 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1462
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001463 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1464 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1465 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1466 "([IFFF)V");
1467
Robert Carr6486d312017-01-09 19:48:29 -08001468 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1469 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1470 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1471 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1472
Peiyong Line3e5efd2019-03-21 20:59:47 +00001473 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1474 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1475 gScreenshotGraphicBufferClassInfo.clazz =
1476 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1477 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1478 screenshotGraphicsBufferClazz,
Robert Carr66b5664f2019-04-02 14:18:56 -07001479 "createFromNative", "(IIIIJIZ)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
Peiyong Line3e5efd2019-03-21 20:59:47 +00001480
Kevin DuBoisbf76b11b2018-09-04 09:14:15 -07001481 jclass displayedContentSampleClazz = FindClassOrDie(env,
1482 "android/hardware/display/DisplayedContentSample");
1483 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1484 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1485 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1486
1487 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1488 "android/hardware/display/DisplayedContentSamplingAttributes");
1489 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1490 displayedContentSamplingAttributesClazz);
1491 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1492 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
Daniel Solomon10e3b332019-01-20 21:09:11 -08001493
1494 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1495 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1496 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1497 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1498 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1499 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1500
1501 jclass displayPrimariesClazz = FindClassOrDie(env,
1502 "android/view/SurfaceControl$DisplayPrimaries");
1503 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1504 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1505 "<init>", "()V");
1506 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1507 "Landroid/view/SurfaceControl$CieXyz;");
1508 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1509 "Landroid/view/SurfaceControl$CieXyz;");
1510 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1511 "Landroid/view/SurfaceControl$CieXyz;");
1512 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1513 "Landroid/view/SurfaceControl$CieXyz;");
1514
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001515 return err;
1516}
1517
Dominik Laskowski3316a0a2019-01-25 02:56:41 -08001518} // namespace android