1 /*
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"
18 #define LOG_NDEBUG 0
19
20 #include "android_os_Parcel.h"
21 #include "android_util_Binder.h"
22 #include "android_hardware_input_InputWindowHandle.h"
23 #include "android/graphics/Bitmap.h"
24 #include "android/graphics/GraphicsJNI.h"
25 #include "android/graphics/Region.h"
26 #include "core_jni_helpers.h"
27
28 #include <android-base/chrono_utils.h>
29 #include <nativehelper/JNIHelp.h>
30 #include <nativehelper/ScopedUtfChars.h>
31 #include <android_runtime/android_view_Surface.h>
32 #include <android_runtime/android_view_SurfaceSession.h>
33 #include <gui/Surface.h>
34 #include <gui/SurfaceComposerClient.h>
35 #include <jni.h>
36 #include <memory>
37 #include <stdio.h>
38 #include <system/graphics.h>
39 #include <ui/ConfigStoreTypes.h>
40 #include <ui/DisplayInfo.h>
41 #include <ui/DisplayedFrameStats.h>
42 #include <ui/FrameStats.h>
43 #include <ui/GraphicTypes.h>
44 #include <ui/HdrCapabilities.h>
45 #include <ui/Rect.h>
46 #include <ui/Region.h>
47 #include <utils/Log.h>
48
49 // ----------------------------------------------------------------------------
50
51 namespace android {
52
53 static const char* const OutOfResourcesException =
54 "android/view/Surface$OutOfResourcesException";
55
56 static struct {
57 jclass clazz;
58 jmethodID ctor;
59 jfieldID width;
60 jfieldID height;
61 jfieldID refreshRate;
62 jfieldID density;
63 jfieldID xDpi;
64 jfieldID yDpi;
65 jfieldID secure;
66 jfieldID appVsyncOffsetNanos;
67 jfieldID presentationDeadlineNanos;
68 } gPhysicalDisplayInfoClassInfo;
69
70 static struct {
71 jfieldID bottom;
72 jfieldID left;
73 jfieldID right;
74 jfieldID top;
75 } gRectClassInfo;
76
77 // Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
DeleteScreenshot(void * addr,void * context)78 void DeleteScreenshot(void* addr, void* context) {
79 delete ((ScreenshotClient*) context);
80 }
81
82 static struct {
83 nsecs_t UNDEFINED_TIME_NANO;
84 jmethodID init;
85 } gWindowContentFrameStatsClassInfo;
86
87 static struct {
88 nsecs_t UNDEFINED_TIME_NANO;
89 jmethodID init;
90 } gWindowAnimationFrameStatsClassInfo;
91
92 static struct {
93 jclass clazz;
94 jmethodID ctor;
95 } gHdrCapabilitiesClassInfo;
96
97 static struct {
98 jclass clazz;
99 jmethodID builder;
100 } gGraphicBufferClassInfo;
101
102 static struct {
103 jclass clazz;
104 jmethodID ctor;
105 } gDisplayedContentSampleClassInfo;
106
107 static struct {
108 jclass clazz;
109 jmethodID ctor;
110 } gDisplayedContentSamplingAttributesClassInfo;
111
112 static struct {
113 jclass clazz;
114 jmethodID ctor;
115 jfieldID X;
116 jfieldID Y;
117 jfieldID Z;
118 } gCieXyzClassInfo;
119
120 static struct {
121 jclass clazz;
122 jmethodID ctor;
123 jfieldID red;
124 jfieldID green;
125 jfieldID blue;
126 jfieldID white;
127 } gDisplayPrimariesClassInfo;
128
129 static struct {
130 jclass clazz;
131 jmethodID builder;
132 } gScreenshotGraphicBufferClassInfo;
133
134 class JNamedColorSpace {
135 public:
136 // ColorSpace.Named.SRGB.ordinal() = 0;
137 static constexpr jint SRGB = 0;
138
139 // ColorSpace.Named.DISPLAY_P3.ordinal() = 7;
140 static constexpr jint DISPLAY_P3 = 7;
141 };
142
fromDataspaceToNamedColorSpaceValue(const ui::Dataspace dataspace)143 constexpr jint fromDataspaceToNamedColorSpaceValue(const ui::Dataspace dataspace) {
144 switch (dataspace) {
145 case ui::Dataspace::DISPLAY_P3:
146 return JNamedColorSpace::DISPLAY_P3;
147 default:
148 return JNamedColorSpace::SRGB;
149 }
150 }
151
pickDataspaceFromColorMode(const ui::ColorMode colorMode)152 constexpr ui::Dataspace pickDataspaceFromColorMode(const ui::ColorMode colorMode) {
153 switch (colorMode) {
154 case ui::ColorMode::DISPLAY_P3:
155 case ui::ColorMode::BT2100_PQ:
156 case ui::ColorMode::BT2100_HLG:
157 case ui::ColorMode::DISPLAY_BT2020:
158 return ui::Dataspace::DISPLAY_P3;
159 default:
160 return ui::Dataspace::V0_SRGB;
161 }
162 }
163
164 // ----------------------------------------------------------------------------
165
nativeCreateTransaction(JNIEnv * env,jclass clazz)166 static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
167 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
168 }
169
releaseTransaction(SurfaceComposerClient::Transaction * t)170 static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
171 delete t;
172 }
173
nativeGetNativeTransactionFinalizer(JNIEnv * env,jclass clazz)174 static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
175 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
176 }
177
nativeCreate(JNIEnv * env,jclass clazz,jobject sessionObj,jstring nameStr,jint w,jint h,jint format,jint flags,jlong parentObject,jobject metadataParcel)178 static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
179 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
180 jobject metadataParcel) {
181 ScopedUtfChars name(env, nameStr);
182 sp<SurfaceComposerClient> client;
183 if (sessionObj != NULL) {
184 client = android_view_SurfaceSession_getClient(env, sessionObj);
185 } else {
186 client = SurfaceComposerClient::getDefault();
187 }
188 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
189 sp<SurfaceControl> surface;
190 LayerMetadata metadata;
191 Parcel* parcel = parcelForJavaObject(env, metadataParcel);
192 if (parcel && !parcel->objectsCount()) {
193 status_t err = metadata.readFromParcel(parcel);
194 if (err != NO_ERROR) {
195 jniThrowException(env, "java/lang/IllegalArgumentException",
196 "Metadata parcel has wrong format");
197 }
198 }
199
200 status_t err = client->createSurfaceChecked(
201 String8(name.c_str()), w, h, format, &surface, flags, parent, std::move(metadata));
202 if (err == NAME_NOT_FOUND) {
203 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
204 return 0;
205 } else if (err != NO_ERROR) {
206 jniThrowException(env, OutOfResourcesException, NULL);
207 return 0;
208 }
209
210 surface->incStrong((void *)nativeCreate);
211 return reinterpret_cast<jlong>(surface.get());
212 }
213
nativeRelease(JNIEnv * env,jclass clazz,jlong nativeObject)214 static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
215 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
216 ctrl->release();
217 ctrl->decStrong((void *)nativeCreate);
218 }
219
nativeDestroy(JNIEnv * env,jclass clazz,jlong nativeObject)220 static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
221 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
222 ctrl->destroy();
223 ctrl->decStrong((void *)nativeCreate);
224 }
225
nativeDisconnect(JNIEnv * env,jclass clazz,jlong nativeObject)226 static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
227 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
228 if (ctrl != NULL) {
229 ctrl->disconnect();
230 }
231 }
232
rectFromObj(JNIEnv * env,jobject rectObj)233 static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
234 int left = env->GetIntField(rectObj, gRectClassInfo.left);
235 int top = env->GetIntField(rectObj, gRectClassInfo.top);
236 int right = env->GetIntField(rectObj, gRectClassInfo.right);
237 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
238 return Rect(left, top, right, bottom);
239 }
240
nativeScreenshot(JNIEnv * env,jclass clazz,jobject displayTokenObj,jobject sourceCropObj,jint width,jint height,bool useIdentityTransform,int rotation,bool captureSecureLayers)241 static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
242 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
243 bool useIdentityTransform, int rotation, bool captureSecureLayers) {
244 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
245 if (displayToken == NULL) {
246 return NULL;
247 }
248 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
249 const ui::Dataspace dataspace = pickDataspaceFromColorMode(colorMode);
250
251 Rect sourceCrop = rectFromObj(env, sourceCropObj);
252 sp<GraphicBuffer> buffer;
253 bool capturedSecureLayers = false;
254 status_t res = ScreenshotClient::capture(displayToken, dataspace,
255 ui::PixelFormat::RGBA_8888,
256 sourceCrop, width, height,
257 useIdentityTransform, rotation, captureSecureLayers, &buffer, capturedSecureLayers);
258 if (res != NO_ERROR) {
259 return NULL;
260 }
261
262 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
263 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
264 gScreenshotGraphicBufferClassInfo.builder,
265 buffer->getWidth(),
266 buffer->getHeight(),
267 buffer->getPixelFormat(),
268 (jint)buffer->getUsage(),
269 (jlong)buffer.get(),
270 namedColorSpace,
271 capturedSecureLayers);
272 }
273
nativeCaptureLayers(JNIEnv * env,jclass clazz,jobject displayTokenObj,jobject layerHandleToken,jobject sourceCropObj,jfloat frameScale,jobjectArray excludeArray)274 static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
275 jobject layerHandleToken, jobject sourceCropObj, jfloat frameScale,
276 jobjectArray excludeArray) {
277
278 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
279 if (layerHandle == NULL) {
280 return NULL;
281 }
282
283 Rect sourceCrop;
284 if (sourceCropObj != NULL) {
285 sourceCrop = rectFromObj(env, sourceCropObj);
286 }
287
288 std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
289 if (excludeArray != NULL) {
290 const jsize len = env->GetArrayLength(excludeArray);
291 excludeHandles.reserve(len);
292
293 for (jsize i = 0; i < len; i++) {
294 jobject obj = env->GetObjectArrayElement(excludeArray, i);
295 if (obj == nullptr) {
296 jniThrowNullPointerException(env, "Exclude layer is null");
297 return NULL;
298 }
299 sp<IBinder> excludeHandle = ibinderForJavaObject(env, obj);
300 excludeHandles.emplace(excludeHandle);
301 }
302 }
303
304 sp<GraphicBuffer> buffer;
305 ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
306 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
307 if (displayToken != nullptr) {
308 const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
309 dataspace = pickDataspaceFromColorMode(colorMode);
310 }
311 status_t res = ScreenshotClient::captureChildLayers(layerHandle, dataspace,
312 ui::PixelFormat::RGBA_8888, sourceCrop,
313 excludeHandles, frameScale, &buffer);
314 if (res != NO_ERROR) {
315 return NULL;
316 }
317
318 const jint namedColorSpace = fromDataspaceToNamedColorSpaceValue(dataspace);
319 return env->CallStaticObjectMethod(gScreenshotGraphicBufferClassInfo.clazz,
320 gScreenshotGraphicBufferClassInfo.builder,
321 buffer->getWidth(),
322 buffer->getHeight(),
323 buffer->getPixelFormat(),
324 (jint)buffer->getUsage(),
325 (jlong)buffer.get(),
326 namedColorSpace,
327 false /* capturedSecureLayers */);
328 }
329
nativeApplyTransaction(JNIEnv * env,jclass clazz,jlong transactionObj,jboolean sync)330 static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
331 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
332 transaction->apply(sync);
333 }
334
nativeMergeTransaction(JNIEnv * env,jclass clazz,jlong transactionObj,jlong otherTransactionObj)335 static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
336 jlong transactionObj, jlong otherTransactionObj) {
337 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
338 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
339 otherTransactionObj);
340 transaction->merge(std::move(*otherTransaction));
341 }
342
nativeSetAnimationTransaction(JNIEnv * env,jclass clazz,jlong transactionObj)343 static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
344 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
345 transaction->setAnimationTransaction();
346 }
347
nativeSetEarlyWakeup(JNIEnv * env,jclass clazz,jlong transactionObj)348 static void nativeSetEarlyWakeup(JNIEnv* env, jclass clazz, jlong transactionObj) {
349 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
350 transaction->setEarlyWakeup();
351 }
352
nativeSetLayer(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jint zorder)353 static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
354 jlong nativeObject, jint zorder) {
355 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
356
357 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
358 transaction->setLayer(ctrl, zorder);
359 }
360
nativeSetRelativeLayer(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jobject relativeTo,jint zorder)361 static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
362 jlong nativeObject,
363 jobject relativeTo, jint zorder) {
364
365 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
366 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
367
368 {
369 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
370 transaction->setRelativeLayer(ctrl, handle, zorder);
371 }
372 }
373
nativeSetPosition(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jfloat x,jfloat y)374 static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
375 jlong nativeObject, jfloat x, jfloat y) {
376 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
377
378 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
379 transaction->setPosition(ctrl, x, y);
380 }
381
nativeSetGeometry(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jobject sourceObj,jobject dstObj,jlong orientation)382 static 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);
390 } else {
391 source.makeInvalid();
392 }
393 if (dstObj != NULL) {
394 dst = rectFromObj(env, dstObj);
395 } else {
396 dst.makeInvalid();
397 }
398 transaction->setGeometry(ctrl, source, dst, orientation);
399 }
400
nativeSetGeometryAppliesWithResize(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject)401 static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
402 jlong transactionObj,
403 jlong nativeObject) {
404 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
405
406 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
407 transaction->setGeometryAppliesWithResize(ctrl);
408 }
409
nativeSetSize(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jint w,jint h)410 static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
411 jlong nativeObject, jint w, jint h) {
412 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
413
414 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
415 transaction->setSize(ctrl, w, h);
416 }
417
nativeSetFlags(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jint flags,jint mask)418 static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
419 jlong nativeObject, jint flags, jint mask) {
420 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
421
422 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
423 transaction->setFlags(ctrl, flags, mask);
424 }
425
nativeSetTransparentRegionHint(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jobject regionObj)426 static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
427 jlong nativeObject, jobject regionObj) {
428 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
429 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
430 if (!region) {
431 doThrowIAE(env);
432 return;
433 }
434
435 const SkIRect& b(region->getBounds());
436 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
437 if (region->isComplex()) {
438 SkRegion::Iterator it(*region);
439 while (!it.done()) {
440 const SkIRect& r(it.rect());
441 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
442 it.next();
443 }
444 }
445
446 {
447 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
448 transaction->setTransparentRegionHint(ctrl, reg);
449 }
450 }
451
nativeSetAlpha(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jfloat alpha)452 static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
453 jlong nativeObject, jfloat alpha) {
454 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
455
456 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
457 transaction->setAlpha(ctrl, alpha);
458 }
459
nativeSetInputWindowInfo(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jobject inputWindow)460 static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
461 jlong nativeObject, jobject inputWindow) {
462 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
463
464 sp<NativeInputWindowHandle> handle = android_view_InputWindowHandle_getHandle(
465 env, inputWindow);
466 handle->updateInfo();
467
468 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
469 transaction->setInputWindowInfo(ctrl, *handle->getInfo());
470 }
471
nativeTransferTouchFocus(JNIEnv * env,jclass clazz,jlong transactionObj,jobject fromTokenObj,jobject toTokenObj)472 static void nativeTransferTouchFocus(JNIEnv* env, jclass clazz, jlong transactionObj,
473 jobject fromTokenObj, jobject toTokenObj) {
474 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
475
476 sp<IBinder> fromToken(ibinderForJavaObject(env, fromTokenObj));
477 sp<IBinder> toToken(ibinderForJavaObject(env, toTokenObj));
478 transaction->transferTouchFocus(fromToken, toToken);
479 }
480
nativeSyncInputWindows(JNIEnv * env,jclass clazz,jlong transactionObj)481 static void nativeSyncInputWindows(JNIEnv* env, jclass clazz, jlong transactionObj) {
482 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
483 transaction->syncInputWindows();
484 }
485
nativeSetMetadata(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jint id,jobject parcelObj)486 static void nativeSetMetadata(JNIEnv* env, jclass clazz, jlong transactionObj,
487 jlong nativeObject, jint id, jobject parcelObj) {
488 Parcel* parcel = parcelForJavaObject(env, parcelObj);
489 if (!parcel) {
490 jniThrowNullPointerException(env, "attribute data");
491 return;
492 }
493 if (parcel->objectsCount()) {
494 jniThrowException(env, "java/lang/RuntimeException",
495 "Tried to marshall a Parcel that contained Binder objects.");
496 return;
497 }
498
499 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
500
501 std::vector<uint8_t> byteData(parcel->dataSize());
502 memcpy(byteData.data(), parcel->data(), parcel->dataSize());
503
504 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl*>(nativeObject);
505 transaction->setMetadata(ctrl, id, std::move(byteData));
506 }
507
nativeSetColor(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jfloatArray fColor)508 static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
509 jlong nativeObject, jfloatArray fColor) {
510 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
511 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
512
513 float* floatColors = env->GetFloatArrayElements(fColor, 0);
514 half3 color(floatColors[0], floatColors[1], floatColors[2]);
515 transaction->setColor(ctrl, color);
516 }
517
nativeSetMatrix(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jfloat dsdx,jfloat dtdx,jfloat dtdy,jfloat dsdy)518 static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
519 jlong nativeObject,
520 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
521 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
522
523 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
524 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
525 }
526
nativeSetColorTransform(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jfloatArray fMatrix,jfloatArray fTranslation)527 static void nativeSetColorTransform(JNIEnv* env, jclass clazz, jlong transactionObj,
528 jlong nativeObject, jfloatArray fMatrix, jfloatArray fTranslation) {
529 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
530 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
531 float* floatMatrix = env->GetFloatArrayElements(fMatrix, 0);
532 mat3 matrix(static_cast<float const*>(floatMatrix));
533 float* floatTranslation = env->GetFloatArrayElements(fTranslation, 0);
534 vec3 translation(floatTranslation[0], floatTranslation[1], floatTranslation[2]);
535 transaction->setColorTransform(surfaceControl, matrix, translation);
536 }
537
nativeSetColorSpaceAgnostic(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jboolean agnostic)538 static void nativeSetColorSpaceAgnostic(JNIEnv* env, jclass clazz, jlong transactionObj,
539 jlong nativeObject, jboolean agnostic) {
540 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
541 SurfaceControl* const surfaceControl = reinterpret_cast<SurfaceControl*>(nativeObject);
542 transaction->setColorSpaceAgnostic(surfaceControl, agnostic);
543 }
544
nativeSetWindowCrop(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jint l,jint t,jint r,jint b)545 static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
546 jlong nativeObject,
547 jint l, jint t, jint r, jint b) {
548 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
549
550 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
551 Rect crop(l, t, r, b);
552 transaction->setCrop_legacy(ctrl, crop);
553 }
554
nativeSetCornerRadius(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jfloat cornerRadius)555 static void nativeSetCornerRadius(JNIEnv* env, jclass clazz, jlong transactionObj,
556 jlong nativeObject, jfloat cornerRadius) {
557 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
558
559 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
560 transaction->setCornerRadius(ctrl, cornerRadius);
561 }
562
nativeSetLayerStack(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jint layerStack)563 static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
564 jlong nativeObject, jint layerStack) {
565 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
566
567 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
568 transaction->setLayerStack(ctrl, layerStack);
569 }
570
nativeGetPhysicalDisplayIds(JNIEnv * env,jclass clazz)571 static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
572 const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds();
573 jlongArray array = env->NewLongArray(displayIds.size());
574 if (array == nullptr) {
575 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
576 return nullptr;
577 }
578
579 if (displayIds.empty()) {
580 return array;
581 }
582
583 jlong* values = env->GetLongArrayElements(array, 0);
584 for (size_t i = 0; i < displayIds.size(); ++i) {
585 values[i] = static_cast<jlong>(displayIds[i]);
586 }
587
588 env->ReleaseLongArrayElements(array, values, 0);
589 return array;
590 }
591
nativeGetPhysicalDisplayToken(JNIEnv * env,jclass clazz,jlong physicalDisplayId)592 static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
593 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(physicalDisplayId);
594 return javaObjectForIBinder(env, token);
595 }
596
nativeGetDisplayedContentSamplingAttributes(JNIEnv * env,jclass clazz,jobject tokenObj)597 static jobject nativeGetDisplayedContentSamplingAttributes(JNIEnv* env, jclass clazz,
598 jobject tokenObj) {
599 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
600
601 ui::PixelFormat format;
602 ui::Dataspace dataspace;
603 uint8_t componentMask;
604 status_t err = SurfaceComposerClient::getDisplayedContentSamplingAttributes(
605 token, &format, &dataspace, &componentMask);
606 if (err != OK) {
607 return nullptr;
608 }
609 return env->NewObject(gDisplayedContentSamplingAttributesClassInfo.clazz,
610 gDisplayedContentSamplingAttributesClassInfo.ctor,
611 format, dataspace, componentMask);
612 }
613
nativeSetDisplayedContentSamplingEnabled(JNIEnv * env,jclass clazz,jobject tokenObj,jboolean enable,jint componentMask,jint maxFrames)614 static jboolean nativeSetDisplayedContentSamplingEnabled(JNIEnv* env, jclass clazz,
615 jobject tokenObj, jboolean enable, jint componentMask, jint maxFrames) {
616 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
617 status_t rc = SurfaceComposerClient::setDisplayContentSamplingEnabled(
618 token, enable, componentMask, maxFrames);
619 return rc == OK;
620 }
621
nativeGetDisplayedContentSample(JNIEnv * env,jclass clazz,jobject tokenObj,jlong maxFrames,jlong timestamp)622 static jobject nativeGetDisplayedContentSample(JNIEnv* env, jclass clazz, jobject tokenObj,
623 jlong maxFrames, jlong timestamp) {
624 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
625
626 DisplayedFrameStats stats;
627 status_t err = SurfaceComposerClient::getDisplayedContentSample(
628 token, maxFrames, timestamp, &stats);
629 if (err != OK) {
630 return nullptr;
631 }
632
633 jlongArray histogramComponent0 = env->NewLongArray(stats.component_0_sample.size());
634 jlongArray histogramComponent1 = env->NewLongArray(stats.component_1_sample.size());
635 jlongArray histogramComponent2 = env->NewLongArray(stats.component_2_sample.size());
636 jlongArray histogramComponent3 = env->NewLongArray(stats.component_3_sample.size());
637 if ((histogramComponent0 == nullptr) ||
638 (histogramComponent1 == nullptr) ||
639 (histogramComponent2 == nullptr) ||
640 (histogramComponent3 == nullptr)) {
641 return JNI_FALSE;
642 }
643
644 env->SetLongArrayRegion(histogramComponent0, 0,
645 stats.component_0_sample.size(),
646 reinterpret_cast<jlong*>(stats.component_0_sample.data()));
647 env->SetLongArrayRegion(histogramComponent1, 0,
648 stats.component_1_sample.size(),
649 reinterpret_cast<jlong*>(stats.component_1_sample.data()));
650 env->SetLongArrayRegion(histogramComponent2, 0,
651 stats.component_2_sample.size(),
652 reinterpret_cast<jlong*>(stats.component_2_sample.data()));
653 env->SetLongArrayRegion(histogramComponent3, 0,
654 stats.component_3_sample.size(),
655 reinterpret_cast<jlong*>(stats.component_3_sample.data()));
656 return env->NewObject(gDisplayedContentSampleClassInfo.clazz,
657 gDisplayedContentSampleClassInfo.ctor,
658 stats.numFrames,
659 histogramComponent0,
660 histogramComponent1,
661 histogramComponent2,
662 histogramComponent3);
663 }
664
nativeCreateDisplay(JNIEnv * env,jclass clazz,jstring nameObj,jboolean secure)665 static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
666 jboolean secure) {
667 ScopedUtfChars name(env, nameObj);
668 sp<IBinder> token(SurfaceComposerClient::createDisplay(
669 String8(name.c_str()), bool(secure)));
670 return javaObjectForIBinder(env, token);
671 }
672
nativeDestroyDisplay(JNIEnv * env,jclass clazz,jobject tokenObj)673 static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
674 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
675 if (token == NULL) return;
676 SurfaceComposerClient::destroyDisplay(token);
677 }
678
nativeSetDisplaySurface(JNIEnv * env,jclass clazz,jlong transactionObj,jobject tokenObj,jlong nativeSurfaceObject)679 static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
680 jlong transactionObj,
681 jobject tokenObj, jlong nativeSurfaceObject) {
682 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
683 if (token == NULL) return;
684 sp<IGraphicBufferProducer> bufferProducer;
685 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
686 if (sur != NULL) {
687 bufferProducer = sur->getIGraphicBufferProducer();
688 }
689
690
691 status_t err = NO_ERROR;
692 {
693 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
694 err = transaction->setDisplaySurface(token,
695 bufferProducer);
696 }
697 if (err != NO_ERROR) {
698 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
699 " Surface created with singleBufferMode?");
700 }
701 }
702
nativeSetDisplayLayerStack(JNIEnv * env,jclass clazz,jlong transactionObj,jobject tokenObj,jint layerStack)703 static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
704 jlong transactionObj,
705 jobject tokenObj, jint layerStack) {
706
707 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
708 if (token == NULL) return;
709
710 {
711 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
712 transaction->setDisplayLayerStack(token, layerStack);
713 }
714 }
715
nativeSetDisplayProjection(JNIEnv * env,jclass clazz,jlong transactionObj,jobject tokenObj,jint orientation,jint layerStackRect_left,jint layerStackRect_top,jint layerStackRect_right,jint layerStackRect_bottom,jint displayRect_left,jint displayRect_top,jint displayRect_right,jint displayRect_bottom)716 static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
717 jlong transactionObj,
718 jobject tokenObj, jint orientation,
719 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
720 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
721 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
722 if (token == NULL) return;
723 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
724 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
725
726 {
727 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
728 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
729 }
730 }
731
nativeSetDisplaySize(JNIEnv * env,jclass clazz,jlong transactionObj,jobject tokenObj,jint width,jint height)732 static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
733 jlong transactionObj,
734 jobject tokenObj, jint width, jint height) {
735 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
736 if (token == NULL) return;
737
738 {
739 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
740 transaction->setDisplaySize(token, width, height);
741 }
742 }
743
nativeGetDisplayConfigs(JNIEnv * env,jclass clazz,jobject tokenObj)744 static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
745 jobject tokenObj) {
746 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
747 if (token == NULL) return NULL;
748
749 Vector<DisplayInfo> configs;
750 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
751 configs.size() == 0) {
752 return NULL;
753 }
754
755 jobjectArray configArray = env->NewObjectArray(configs.size(),
756 gPhysicalDisplayInfoClassInfo.clazz, NULL);
757
758 for (size_t c = 0; c < configs.size(); ++c) {
759 const DisplayInfo& info = configs[c];
760 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
761 gPhysicalDisplayInfoClassInfo.ctor);
762 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
763 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
764 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
765 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
766 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
767 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
768 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
769 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
770 info.appVsyncOffset);
771 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
772 info.presentationDeadline);
773 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
774 env->DeleteLocalRef(infoObj);
775 }
776
777 return configArray;
778 }
779
nativeSetAllowedDisplayConfigs(JNIEnv * env,jclass clazz,jobject tokenObj,jintArray configArray)780 static jboolean nativeSetAllowedDisplayConfigs(JNIEnv* env, jclass clazz,
781 jobject tokenObj, jintArray configArray) {
782 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
783 if (token == nullptr) return JNI_FALSE;
784
785 std::vector<int32_t> allowedConfigs;
786 jsize configArraySize = env->GetArrayLength(configArray);
787 allowedConfigs.reserve(configArraySize);
788
789 jint* configArrayElements = env->GetIntArrayElements(configArray, 0);
790 for (int i = 0; i < configArraySize; i++) {
791 allowedConfigs.push_back(configArrayElements[i]);
792 }
793 env->ReleaseIntArrayElements(configArray, configArrayElements, 0);
794
795 size_t result = SurfaceComposerClient::setAllowedDisplayConfigs(token, allowedConfigs);
796 return result == NO_ERROR ? JNI_TRUE : JNI_FALSE;
797 }
798
nativeGetAllowedDisplayConfigs(JNIEnv * env,jclass clazz,jobject tokenObj)799 static jintArray nativeGetAllowedDisplayConfigs(JNIEnv* env, jclass clazz, jobject tokenObj) {
800 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
801 if (token == nullptr) return JNI_FALSE;
802
803 std::vector<int32_t> allowedConfigs;
804 size_t result = SurfaceComposerClient::getAllowedDisplayConfigs(token, &allowedConfigs);
805 if (result != NO_ERROR) {
806 return nullptr;
807 }
808
809 jintArray allowedConfigsArray = env->NewIntArray(allowedConfigs.size());
810 if (allowedConfigsArray == nullptr) {
811 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
812 return nullptr;
813 }
814 jint* allowedConfigsArrayValues = env->GetIntArrayElements(allowedConfigsArray, 0);
815 for (size_t i = 0; i < allowedConfigs.size(); i++) {
816 allowedConfigsArrayValues[i] = static_cast<jint>(allowedConfigs[i]);
817 }
818 env->ReleaseIntArrayElements(allowedConfigsArray, allowedConfigsArrayValues, 0);
819 return allowedConfigsArray;
820 }
821
nativeGetActiveConfig(JNIEnv * env,jclass clazz,jobject tokenObj)822 static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
823 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
824 if (token == NULL) return -1;
825 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
826 }
827
nativeSetActiveConfig(JNIEnv * env,jclass clazz,jobject tokenObj,jint id)828 static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
829 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
830 if (token == NULL) return JNI_FALSE;
831 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
832 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
833 }
834
nativeGetDisplayColorModes(JNIEnv * env,jclass,jobject tokenObj)835 static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
836 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
837 if (token == NULL) return NULL;
838 Vector<ui::ColorMode> colorModes;
839 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
840 colorModes.isEmpty()) {
841 return NULL;
842 }
843
844 jintArray colorModesArray = env->NewIntArray(colorModes.size());
845 if (colorModesArray == NULL) {
846 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
847 return NULL;
848 }
849 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
850 for (size_t i = 0; i < colorModes.size(); i++) {
851 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
852 }
853 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
854 return colorModesArray;
855 }
856
nativeGetDisplayNativePrimaries(JNIEnv * env,jclass,jobject tokenObj)857 static jobject nativeGetDisplayNativePrimaries(JNIEnv* env, jclass, jobject tokenObj) {
858 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
859 if (token == NULL) return NULL;
860
861 ui::DisplayPrimaries primaries;
862 if (SurfaceComposerClient::getDisplayNativePrimaries(token, primaries) != NO_ERROR) {
863 return NULL;
864 }
865
866 jobject jred = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
867 if (jred == NULL) {
868 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
869 return NULL;
870 }
871
872 jobject jgreen = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
873 if (jgreen == NULL) {
874 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
875 return NULL;
876 }
877
878 jobject jblue = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
879 if (jblue == NULL) {
880 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
881 return NULL;
882 }
883
884 jobject jwhite = env->NewObject(gCieXyzClassInfo.clazz, gCieXyzClassInfo.ctor);
885 if (jwhite == NULL) {
886 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
887 return NULL;
888 }
889
890 jobject jprimaries = env->NewObject(gDisplayPrimariesClassInfo.clazz,
891 gDisplayPrimariesClassInfo.ctor);
892 if (jprimaries == NULL) {
893 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
894 return NULL;
895 }
896
897 env->SetFloatField(jred, gCieXyzClassInfo.X, primaries.red.X);
898 env->SetFloatField(jred, gCieXyzClassInfo.Y, primaries.red.Y);
899 env->SetFloatField(jred, gCieXyzClassInfo.Z, primaries.red.Z);
900 env->SetFloatField(jgreen, gCieXyzClassInfo.X, primaries.green.X);
901 env->SetFloatField(jgreen, gCieXyzClassInfo.Y, primaries.green.Y);
902 env->SetFloatField(jgreen, gCieXyzClassInfo.Z, primaries.green.Z);
903 env->SetFloatField(jblue, gCieXyzClassInfo.X, primaries.blue.X);
904 env->SetFloatField(jblue, gCieXyzClassInfo.Y, primaries.blue.Y);
905 env->SetFloatField(jblue, gCieXyzClassInfo.Z, primaries.blue.Z);
906 env->SetFloatField(jwhite, gCieXyzClassInfo.X, primaries.white.X);
907 env->SetFloatField(jwhite, gCieXyzClassInfo.Y, primaries.white.Y);
908 env->SetFloatField(jwhite, gCieXyzClassInfo.Z, primaries.white.Z);
909 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.red, jred);
910 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.green, jgreen);
911 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.blue, jblue);
912 env->SetObjectField(jprimaries, gDisplayPrimariesClassInfo.white, jwhite);
913
914 return jprimaries;
915 }
916
nativeGetActiveColorMode(JNIEnv * env,jclass,jobject tokenObj)917 static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
918 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
919 if (token == NULL) return -1;
920 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
921 }
922
nativeGetCompositionDataspaces(JNIEnv * env,jclass)923 static jintArray nativeGetCompositionDataspaces(JNIEnv* env, jclass) {
924 ui::Dataspace defaultDataspace, wcgDataspace;
925 ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
926 if (SurfaceComposerClient::getCompositionPreference(&defaultDataspace,
927 &defaultPixelFormat,
928 &wcgDataspace,
929 &wcgPixelFormat) != NO_ERROR) {
930 return nullptr;
931 }
932 jintArray array = env->NewIntArray(2);
933 if (array == nullptr) {
934 jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
935 return nullptr;
936 }
937 jint* arrayValues = env->GetIntArrayElements(array, 0);
938 arrayValues[0] = static_cast<jint>(defaultDataspace);
939 arrayValues[1] = static_cast<jint>(wcgDataspace);
940 env->ReleaseIntArrayElements(array, arrayValues, 0);
941 return array;
942 }
943
nativeSetActiveColorMode(JNIEnv * env,jclass,jobject tokenObj,jint colorMode)944 static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
945 jobject tokenObj, jint colorMode) {
946 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
947 if (token == NULL) return JNI_FALSE;
948 status_t err = SurfaceComposerClient::setActiveColorMode(token,
949 static_cast<ui::ColorMode>(colorMode));
950 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
951 }
952
nativeSetDisplayPowerMode(JNIEnv * env,jclass clazz,jobject tokenObj,jint mode)953 static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
954 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
955 if (token == NULL) return;
956
957 android::base::Timer t;
958 SurfaceComposerClient::setDisplayPowerMode(token, mode);
959 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
960 }
961
nativeGetProtectedContentSupport(JNIEnv * env,jclass)962 static jboolean nativeGetProtectedContentSupport(JNIEnv* env, jclass) {
963 return static_cast<jboolean>(SurfaceComposerClient::getProtectedContentSupport());
964 }
965
nativeClearContentFrameStats(JNIEnv * env,jclass clazz,jlong nativeObject)966 static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
967 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
968 status_t err = ctrl->clearLayerFrameStats();
969
970 if (err < 0 && err != NO_INIT) {
971 doThrowIAE(env);
972 }
973
974 // The other end is not ready, just report we failed.
975 if (err == NO_INIT) {
976 return JNI_FALSE;
977 }
978
979 return JNI_TRUE;
980 }
981
nativeGetContentFrameStats(JNIEnv * env,jclass clazz,jlong nativeObject,jobject outStats)982 static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
983 jobject outStats) {
984 FrameStats stats;
985
986 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
987 status_t err = ctrl->getLayerFrameStats(&stats);
988 if (err < 0 && err != NO_INIT) {
989 doThrowIAE(env);
990 }
991
992 // The other end is not ready, fine just return empty stats.
993 if (err == NO_INIT) {
994 return JNI_FALSE;
995 }
996
997 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
998 size_t frameCount = stats.desiredPresentTimesNano.size();
999
1000 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
1001 if (postedTimesNanoDst == NULL) {
1002 return JNI_FALSE;
1003 }
1004
1005 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1006 if (presentedTimesNanoDst == NULL) {
1007 return JNI_FALSE;
1008 }
1009
1010 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
1011 if (readyTimesNanoDst == NULL) {
1012 return JNI_FALSE;
1013 }
1014
1015 nsecs_t postedTimesNanoSrc[frameCount];
1016 nsecs_t presentedTimesNanoSrc[frameCount];
1017 nsecs_t readyTimesNanoSrc[frameCount];
1018
1019 for (size_t i = 0; i < frameCount; i++) {
1020 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
1021 if (postedTimeNano == INT64_MAX) {
1022 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1023 }
1024 postedTimesNanoSrc[i] = postedTimeNano;
1025
1026 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1027 if (presentedTimeNano == INT64_MAX) {
1028 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1029 }
1030 presentedTimesNanoSrc[i] = presentedTimeNano;
1031
1032 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
1033 if (readyTimeNano == INT64_MAX) {
1034 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1035 }
1036 readyTimesNanoSrc[i] = readyTimeNano;
1037 }
1038
1039 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
1040 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1041 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
1042
1043 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
1044 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
1045
1046 if (env->ExceptionCheck()) {
1047 return JNI_FALSE;
1048 }
1049
1050 return JNI_TRUE;
1051 }
1052
nativeClearAnimationFrameStats(JNIEnv * env,jclass clazz)1053 static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
1054 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
1055
1056 if (err < 0 && err != NO_INIT) {
1057 doThrowIAE(env);
1058 }
1059
1060 // The other end is not ready, just report we failed.
1061 if (err == NO_INIT) {
1062 return JNI_FALSE;
1063 }
1064
1065 return JNI_TRUE;
1066 }
1067
nativeGetAnimationFrameStats(JNIEnv * env,jclass clazz,jobject outStats)1068 static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
1069 FrameStats stats;
1070
1071 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
1072 if (err < 0 && err != NO_INIT) {
1073 doThrowIAE(env);
1074 }
1075
1076 // The other end is not ready, fine just return empty stats.
1077 if (err == NO_INIT) {
1078 return JNI_FALSE;
1079 }
1080
1081 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
1082 size_t frameCount = stats.desiredPresentTimesNano.size();
1083
1084 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
1085 if (presentedTimesNanoDst == NULL) {
1086 return JNI_FALSE;
1087 }
1088
1089 nsecs_t presentedTimesNanoSrc[frameCount];
1090
1091 for (size_t i = 0; i < frameCount; i++) {
1092 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
1093 if (presentedTimeNano == INT64_MAX) {
1094 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
1095 }
1096 presentedTimesNanoSrc[i] = presentedTimeNano;
1097 }
1098
1099 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
1100
1101 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
1102 presentedTimesNanoDst);
1103
1104 if (env->ExceptionCheck()) {
1105 return JNI_FALSE;
1106 }
1107
1108 return JNI_TRUE;
1109 }
1110
nativeDeferTransactionUntil(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jobject handleObject,jlong frameNumber)1111 static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
1112 jlong nativeObject,
1113 jobject handleObject, jlong frameNumber) {
1114 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1115 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
1116
1117 {
1118 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1119 transaction->deferTransactionUntil_legacy(ctrl, handle, frameNumber);
1120 }
1121 }
1122
nativeDeferTransactionUntilSurface(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jlong surfaceObject,jlong frameNumber)1123 static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
1124 jlong nativeObject,
1125 jlong surfaceObject, jlong frameNumber) {
1126 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1127
1128 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1129 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
1130
1131 transaction->deferTransactionUntil_legacy(ctrl, barrier, frameNumber);
1132 }
1133
nativeReparentChildren(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jobject newParentObject)1134 static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1135 jlong nativeObject,
1136 jobject newParentObject) {
1137
1138 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1139 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
1140
1141 {
1142 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1143 transaction->reparentChildren(ctrl, handle);
1144 }
1145 }
1146
nativeReparent(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jlong newParentObject)1147 static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
1148 jlong nativeObject,
1149 jlong newParentObject) {
1150 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1151 auto newParent = reinterpret_cast<SurfaceControl *>(newParentObject);
1152
1153 {
1154 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1155 transaction->reparent(ctrl, newParent != NULL ? newParent->getHandle() : NULL);
1156 }
1157 }
1158
nativeSeverChildren(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject)1159 static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
1160 jlong nativeObject) {
1161 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1162
1163 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1164 transaction->detachChildren(ctrl);
1165 }
1166
nativeSetOverrideScalingMode(JNIEnv * env,jclass clazz,jlong transactionObj,jlong nativeObject,jint scalingMode)1167 static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
1168 jlong nativeObject,
1169 jint scalingMode) {
1170 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
1171
1172 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1173 transaction->setOverrideScalingMode(ctrl, scalingMode);
1174 }
1175
nativeGetHandle(JNIEnv * env,jclass clazz,jlong nativeObject)1176 static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
1177 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
1178 return javaObjectForIBinder(env, ctrl->getHandle());
1179 }
1180
nativeGetHdrCapabilities(JNIEnv * env,jclass clazz,jobject tokenObject)1181 static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
1182 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
1183 if (token == NULL) return NULL;
1184
1185 HdrCapabilities capabilities;
1186 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
1187
1188 const auto& types = capabilities.getSupportedHdrTypes();
1189 std::vector<int32_t> intTypes;
1190 for (auto type : types) {
1191 intTypes.push_back(static_cast<int32_t>(type));
1192 }
1193 auto typesArray = env->NewIntArray(types.size());
1194 env->SetIntArrayRegion(typesArray, 0, intTypes.size(), intTypes.data());
1195
1196 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
1197 typesArray, capabilities.getDesiredMaxLuminance(),
1198 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
1199 }
1200
nativeReadFromParcel(JNIEnv * env,jclass clazz,jobject parcelObj)1201 static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
1202 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1203 if (parcel == NULL) {
1204 doThrowNPE(env);
1205 return 0;
1206 }
1207 sp<SurfaceControl> surface = SurfaceControl::readFromParcel(parcel);
1208 if (surface == nullptr) {
1209 return 0;
1210 }
1211 surface->incStrong((void *)nativeCreate);
1212 return reinterpret_cast<jlong>(surface.get());
1213 }
1214
nativeCopyFromSurfaceControl(JNIEnv * env,jclass clazz,jlong surfaceControlNativeObj)1215 static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
1216 sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
1217 if (surface == nullptr) {
1218 return 0;
1219 }
1220
1221 sp<SurfaceControl> newSurface = new SurfaceControl(surface);
1222 newSurface->incStrong((void *)nativeCreate);
1223 return reinterpret_cast<jlong>(newSurface.get());
1224 }
1225
nativeWriteToParcel(JNIEnv * env,jclass clazz,jlong nativeObject,jobject parcelObj)1226 static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
1227 jlong nativeObject, jobject parcelObj) {
1228 Parcel* parcel = parcelForJavaObject(env, parcelObj);
1229 if (parcel == NULL) {
1230 doThrowNPE(env);
1231 return;
1232 }
1233 SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
1234 if (self != nullptr) {
1235 self->writeToParcel(parcel);
1236 }
1237 }
1238
nativeGetDisplayBrightnessSupport(JNIEnv * env,jclass clazz,jobject displayTokenObject)1239 static jboolean nativeGetDisplayBrightnessSupport(JNIEnv* env, jclass clazz,
1240 jobject displayTokenObject) {
1241 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1242 if (displayToken == nullptr) {
1243 return JNI_FALSE;
1244 }
1245 return static_cast<jboolean>(SurfaceComposerClient::getDisplayBrightnessSupport(displayToken));
1246 }
1247
nativeSetDisplayBrightness(JNIEnv * env,jclass clazz,jobject displayTokenObject,jfloat brightness)1248 static jboolean nativeSetDisplayBrightness(JNIEnv* env, jclass clazz, jobject displayTokenObject,
1249 jfloat brightness) {
1250 sp<IBinder> displayToken(ibinderForJavaObject(env, displayTokenObject));
1251 if (displayToken == nullptr) {
1252 return JNI_FALSE;
1253 }
1254 status_t error = SurfaceComposerClient::setDisplayBrightness(displayToken, brightness);
1255 return error == OK ? JNI_TRUE : JNI_FALSE;
1256 }
1257
1258 // ----------------------------------------------------------------------------
1259
1260 static const JNINativeMethod sSurfaceControlMethods[] = {
1261 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJLandroid/os/Parcel;)J",
1262 (void*)nativeCreate },
1263 {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
1264 (void*)nativeReadFromParcel },
1265 {"nativeCopyFromSurfaceControl", "(J)J" ,
1266 (void*)nativeCopyFromSurfaceControl },
1267 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
1268 (void*)nativeWriteToParcel },
1269 {"nativeRelease", "(J)V",
1270 (void*)nativeRelease },
1271 {"nativeDestroy", "(J)V",
1272 (void*)nativeDestroy },
1273 {"nativeDisconnect", "(J)V",
1274 (void*)nativeDisconnect },
1275 {"nativeCreateTransaction", "()J",
1276 (void*)nativeCreateTransaction },
1277 {"nativeApplyTransaction", "(JZ)V",
1278 (void*)nativeApplyTransaction },
1279 {"nativeGetNativeTransactionFinalizer", "()J",
1280 (void*)nativeGetNativeTransactionFinalizer },
1281 {"nativeMergeTransaction", "(JJ)V",
1282 (void*)nativeMergeTransaction },
1283 {"nativeSetAnimationTransaction", "(J)V",
1284 (void*)nativeSetAnimationTransaction },
1285 {"nativeSetEarlyWakeup", "(J)V",
1286 (void*)nativeSetEarlyWakeup },
1287 {"nativeSetLayer", "(JJI)V",
1288 (void*)nativeSetLayer },
1289 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
1290 (void*)nativeSetRelativeLayer },
1291 {"nativeSetPosition", "(JJFF)V",
1292 (void*)nativeSetPosition },
1293 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
1294 (void*)nativeSetGeometryAppliesWithResize },
1295 {"nativeSetSize", "(JJII)V",
1296 (void*)nativeSetSize },
1297 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
1298 (void*)nativeSetTransparentRegionHint },
1299 {"nativeSetAlpha", "(JJF)V",
1300 (void*)nativeSetAlpha },
1301 {"nativeSetColor", "(JJ[F)V",
1302 (void*)nativeSetColor },
1303 {"nativeSetMatrix", "(JJFFFF)V",
1304 (void*)nativeSetMatrix },
1305 {"nativeSetColorTransform", "(JJ[F[F)V",
1306 (void*)nativeSetColorTransform },
1307 {"nativeSetColorSpaceAgnostic", "(JJZ)V",
1308 (void*)nativeSetColorSpaceAgnostic },
1309 {"nativeSetFlags", "(JJII)V",
1310 (void*)nativeSetFlags },
1311 {"nativeSetWindowCrop", "(JJIIII)V",
1312 (void*)nativeSetWindowCrop },
1313 {"nativeSetCornerRadius", "(JJF)V",
1314 (void*)nativeSetCornerRadius },
1315 {"nativeSetLayerStack", "(JJI)V",
1316 (void*)nativeSetLayerStack },
1317 {"nativeGetPhysicalDisplayIds", "()[J",
1318 (void*)nativeGetPhysicalDisplayIds },
1319 {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
1320 (void*)nativeGetPhysicalDisplayToken },
1321 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
1322 (void*)nativeCreateDisplay },
1323 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
1324 (void*)nativeDestroyDisplay },
1325 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
1326 (void*)nativeSetDisplaySurface },
1327 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
1328 (void*)nativeSetDisplayLayerStack },
1329 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
1330 (void*)nativeSetDisplayProjection },
1331 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
1332 (void*)nativeSetDisplaySize },
1333 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
1334 (void*)nativeGetDisplayConfigs },
1335 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
1336 (void*)nativeGetActiveConfig },
1337 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
1338 (void*)nativeSetActiveConfig },
1339 {"nativeSetAllowedDisplayConfigs", "(Landroid/os/IBinder;[I)Z",
1340 (void*)nativeSetAllowedDisplayConfigs },
1341 {"nativeGetAllowedDisplayConfigs", "(Landroid/os/IBinder;)[I",
1342 (void*)nativeGetAllowedDisplayConfigs },
1343 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
1344 (void*)nativeGetDisplayColorModes},
1345 {"nativeGetDisplayNativePrimaries", "(Landroid/os/IBinder;)Landroid/view/SurfaceControl$DisplayPrimaries;",
1346 (void*)nativeGetDisplayNativePrimaries },
1347 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
1348 (void*)nativeGetActiveColorMode},
1349 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
1350 (void*)nativeSetActiveColorMode},
1351 {"nativeGetCompositionDataspaces", "()[I",
1352 (void*)nativeGetCompositionDataspaces},
1353 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
1354 (void*)nativeGetHdrCapabilities },
1355 {"nativeClearContentFrameStats", "(J)Z",
1356 (void*)nativeClearContentFrameStats },
1357 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
1358 (void*)nativeGetContentFrameStats },
1359 {"nativeClearAnimationFrameStats", "()Z",
1360 (void*)nativeClearAnimationFrameStats },
1361 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
1362 (void*)nativeGetAnimationFrameStats },
1363 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
1364 (void*)nativeSetDisplayPowerMode },
1365 {"nativeGetProtectedContentSupport", "()Z",
1366 (void*)nativeGetProtectedContentSupport },
1367 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
1368 (void*)nativeDeferTransactionUntil },
1369 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
1370 (void*)nativeDeferTransactionUntilSurface },
1371 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
1372 (void*)nativeReparentChildren } ,
1373 {"nativeReparent", "(JJJ)V",
1374 (void*)nativeReparent },
1375 {"nativeSeverChildren", "(JJ)V",
1376 (void*)nativeSeverChildren } ,
1377 {"nativeSetOverrideScalingMode", "(JJI)V",
1378 (void*)nativeSetOverrideScalingMode },
1379 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
1380 (void*)nativeGetHandle },
1381 {"nativeScreenshot",
1382 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)"
1383 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
1384 (void*)nativeScreenshot },
1385 {"nativeCaptureLayers",
1386 "(Landroid/os/IBinder;Landroid/os/IBinder;Landroid/graphics/Rect;"
1387 "F[Landroid/os/IBinder;)"
1388 "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
1389 (void*)nativeCaptureLayers },
1390 {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
1391 (void*)nativeSetInputWindowInfo },
1392 {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
1393 (void*)nativeTransferTouchFocus },
1394 {"nativeSetMetadata", "(JJILandroid/os/Parcel;)V",
1395 (void*)nativeSetMetadata },
1396 {"nativeGetDisplayedContentSamplingAttributes",
1397 "(Landroid/os/IBinder;)Landroid/hardware/display/DisplayedContentSamplingAttributes;",
1398 (void*)nativeGetDisplayedContentSamplingAttributes },
1399 {"nativeSetDisplayedContentSamplingEnabled", "(Landroid/os/IBinder;ZII)Z",
1400 (void*)nativeSetDisplayedContentSamplingEnabled },
1401 {"nativeGetDisplayedContentSample",
1402 "(Landroid/os/IBinder;JJ)Landroid/hardware/display/DisplayedContentSample;",
1403 (void*)nativeGetDisplayedContentSample },
1404 {"nativeSetGeometry", "(JJLandroid/graphics/Rect;Landroid/graphics/Rect;J)V",
1405 (void*)nativeSetGeometry },
1406 {"nativeSyncInputWindows", "(J)V",
1407 (void*)nativeSyncInputWindows },
1408 {"nativeGetDisplayBrightnessSupport", "(Landroid/os/IBinder;)Z",
1409 (void*)nativeGetDisplayBrightnessSupport },
1410 {"nativeSetDisplayBrightness", "(Landroid/os/IBinder;F)Z",
1411 (void*)nativeSetDisplayBrightness },
1412 };
1413
register_android_view_SurfaceControl(JNIEnv * env)1414 int register_android_view_SurfaceControl(JNIEnv* env)
1415 {
1416 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
1417 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1418
1419 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1420 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1421 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1422 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1423 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1424 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1425 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1426 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1427 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1428 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1429 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1430 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1431 clazz, "appVsyncOffsetNanos", "J");
1432 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1433 clazz, "presentationDeadlineNanos", "J");
1434
1435 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1436 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1437 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1438 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1439 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
1440
1441 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1442 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1443 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
1444 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1445
1446 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1447 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1448 contFrameStatsClazz, "init", "(J[J[J[J)V");
1449 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1450
1451 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1452 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1453 animFrameStatsClazz, "init", "(J[J)V");
1454 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1455
1456 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1457 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1458 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1459 "([IFFF)V");
1460
1461 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1462 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1463 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1464 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1465
1466 jclass screenshotGraphicsBufferClazz = FindClassOrDie(env,
1467 "android/view/SurfaceControl$ScreenshotGraphicBuffer");
1468 gScreenshotGraphicBufferClassInfo.clazz =
1469 MakeGlobalRefOrDie(env, screenshotGraphicsBufferClazz);
1470 gScreenshotGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env,
1471 screenshotGraphicsBufferClazz,
1472 "createFromNative", "(IIIIJIZ)Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;");
1473
1474 jclass displayedContentSampleClazz = FindClassOrDie(env,
1475 "android/hardware/display/DisplayedContentSample");
1476 gDisplayedContentSampleClassInfo.clazz = MakeGlobalRefOrDie(env, displayedContentSampleClazz);
1477 gDisplayedContentSampleClassInfo.ctor = GetMethodIDOrDie(env,
1478 displayedContentSampleClazz, "<init>", "(J[J[J[J[J)V");
1479
1480 jclass displayedContentSamplingAttributesClazz = FindClassOrDie(env,
1481 "android/hardware/display/DisplayedContentSamplingAttributes");
1482 gDisplayedContentSamplingAttributesClassInfo.clazz = MakeGlobalRefOrDie(env,
1483 displayedContentSamplingAttributesClazz);
1484 gDisplayedContentSamplingAttributesClassInfo.ctor = GetMethodIDOrDie(env,
1485 displayedContentSamplingAttributesClazz, "<init>", "(III)V");
1486
1487 jclass cieXyzClazz = FindClassOrDie(env, "android/view/SurfaceControl$CieXyz");
1488 gCieXyzClassInfo.clazz = MakeGlobalRefOrDie(env, cieXyzClazz);
1489 gCieXyzClassInfo.ctor = GetMethodIDOrDie(env, gCieXyzClassInfo.clazz, "<init>", "()V");
1490 gCieXyzClassInfo.X = GetFieldIDOrDie(env, cieXyzClazz, "X", "F");
1491 gCieXyzClassInfo.Y = GetFieldIDOrDie(env, cieXyzClazz, "Y", "F");
1492 gCieXyzClassInfo.Z = GetFieldIDOrDie(env, cieXyzClazz, "Z", "F");
1493
1494 jclass displayPrimariesClazz = FindClassOrDie(env,
1495 "android/view/SurfaceControl$DisplayPrimaries");
1496 gDisplayPrimariesClassInfo.clazz = MakeGlobalRefOrDie(env, displayPrimariesClazz);
1497 gDisplayPrimariesClassInfo.ctor = GetMethodIDOrDie(env, gDisplayPrimariesClassInfo.clazz,
1498 "<init>", "()V");
1499 gDisplayPrimariesClassInfo.red = GetFieldIDOrDie(env, displayPrimariesClazz, "red",
1500 "Landroid/view/SurfaceControl$CieXyz;");
1501 gDisplayPrimariesClassInfo.green = GetFieldIDOrDie(env, displayPrimariesClazz, "green",
1502 "Landroid/view/SurfaceControl$CieXyz;");
1503 gDisplayPrimariesClassInfo.blue = GetFieldIDOrDie(env, displayPrimariesClazz, "blue",
1504 "Landroid/view/SurfaceControl$CieXyz;");
1505 gDisplayPrimariesClassInfo.white = GetFieldIDOrDie(env, displayPrimariesClazz, "white",
1506 "Landroid/view/SurfaceControl$CieXyz;");
1507
1508 return err;
1509 }
1510
1511 } // namespace android
1512